akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
typedef long long ll;
ll f[100][2];
int main() {
	ll L,R,ans=0;
	scanf("%lld%lld",&L,&R); 
	if(L==R) {puts("1");return 0;}
	dwn(i,59,0) if((L>>i&1)!=(R>>i&1)) {
		ans+=(1ll<<i)-(L-((L>>i)<<i));
		ll mx=0;int is=0;
		dwn(j,i-1,0) {
			if(R>>j&1) is=1;
			mx=mx*2+is;
		}
		ll mn=(L-((L>>i)<<i));
		if(mx>=mn) {
			ans+=(1ll<<i);
			break;
		}
		f[i][0]=1;
		for(;i;i--) rep(c,0,1) {
			ll& ans=f[i][c];if(!ans) continue;
			f[i-1][c|(!((L>>i-1)&1))]+=ans; // Add 1
			if(c|(!((L>>i-1)&1))) f[i-1][c]+=ans;// Add 0
		}
		ans+=f[0][0]+f[0][1]+mx+1;
		break;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "NO" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    string N;
    int K;
    cin >> N >> K;
    
    int dp[104][11][5]={};
    REP(j,10){
        if(j==0){
            dp[0][j][0]=1;
        }else{
            dp[0][j][1]=1;
        }
    }
    
    REP(k,K+1){
        REP(i,N.size()){
            if(i==0)continue;
            REP(j,10){
                if(j==0){
                    REP(l,10){
                        dp[i][j][k]+=dp[i-1][l][k];
                    }
                }else if(k!=0){
                    REP(l,10){
                        dp[i][j][k]+=dp[i-1][l][k-1];
                    }
                }
            }
        }
    }
    
    /*REP(k,K+1){
        REP(i,N.size()){
            REP(j,10){
                cout << dp[i][j][k] << " ";
            }cout << endl;
        }cout << endl;
    }*/
    
    int Ans=0;
    int k=K;
    RREP(i,N.size()){
        int D=N[N.size()-1-i]-'0';
        if(i==0)D++;
        REP(j,D){
            Ans+=dp[i][j][k];
        }
        //cout << D MM Ans << endl;
        if(D!=0)k--;
        if(k<0)break;
    }
    cout << Ans << endl;
    
    return 0;
}



Measured memory_bytes: 256
import math

def main():

    n = int(input())
    tax = 1.08
    
    ans = math.ceil(n / tax)
    ans_check = ans * tax
    if math.floor(ans * tax) == n:
        print(ans)
    else:
        print(":(")
    
if __name__ == "__main__":
    main()

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

int main(){
    ll n,m; cin >> n >> m;
    ll total_days = 0;
    for(int i=0; i<m; i++){
        ll homework_days; cin >> homework_days;
        total_days += homework_days;
    }

    ll ans = n-total_days;
    if(ans < 0) ans = -1;

    cout << ans << endl;
}

Measured memory_bytes: 3664
#include<stdio.h>
int main(){
  int H;
  int A[260];
  int i;
  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i/2>0) printf("parent key = %d, ",A[i/2]);
    if(i*2<=H) printf("left key = %d, ",A[i*2]);
    if(i*2+1<=H) printf("right key = %d, ",A[i*2+1]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2052
#include<iostream>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int w[10],k[10];
	rep(i,10)cin>>w[i];
	rep(i,10)cin>>k[i];
	sort(w,w+10,greater<int>() );
	sort(k,k+10,greater<int>() );
	int wpoint=0,kpoint=0;
	rep(i,3){
		wpoint+=w[i];
		kpoint+=k[i];
	}
	cout<<wpoint<<" "<<kpoint<<endl;
	return 0;
}

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

int main()
{
  int h, w;
  cin >> h >> w;
  vector<string> s(h*w);
  int i;
  for(i = 0; i < h*w; i++)
  {
    cin >> s.at(i);
  }
  for(i = 0; i < h*w; i++)
  {
    if(s.at(i) == "snuke")
    {
      int hh = i/w+1;
      char ww = i%w+65;
      cout << ww;
      cout << hh << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def main():
    sx, sy, tx, ty = map(int, input().split())
    ans = ""
    for _ in range(ty-sy):
        ans += "U"
    for _ in range(tx-sx):
        ans += "R"

    for _ in range(ty-sy):
        ans += "D"
    for _ in range(tx-sx):
        ans += "L"

    ans += "L"
    for _ in range(ty-sy+1):
        ans += "U"
    for _ in range(tx-sx+1):
        ans += "R"
    ans += "D"

    ans += "R"
    for _ in range(ty-sy+1):
        ans += "D"
    for _ in range(tx-sx+1):
        ans += "L"
    ans += "U"

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
use proconio::input;
//use proconio::marker::{Bytes, Chars};

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}

// nCk の組み合わせを列挙する
pub fn combination(n: usize, k: usize) -> Vec<Vec<usize>> {
    let mut ans = Vec::new();
    if k == 1 {
        for i in 1..n+1 {
            let mut tmp = Vec::new();
            tmp.push(i);
            ans.push(tmp);
        }
    }
    else {
        for iter in combination(n-1, k-1) {
            let max = iter.iter().max().unwrap();
            for j in *max+1..n+1 {
                let mut tmp = iter.clone();
                tmp.push(j);
                ans.push(tmp);
            }
        }
    }
    ans
}


fn main() {
    input!{
        n: usize,
        k: usize,
        a: [usize; n],
    }
//    let mut max = a.iter().max().unwrap();
    let mut max = 1000000001;
    let mut min = 0;
    let mut ans = 0;
    
    while max - min > 1 {
        let div = (max + min) / 2;
        let mut count = 0;
        for i in 0..n {
            count += (a[i] as f64 / div as f64).ceil() as usize - 1;
//            count += (a[i] + (div - 1)) / div - 1;
        }
        if count <= k {
            max = div;
            ans = div
        }
        else {
            min = div;
        }
    }
    println!("{}", ans);
    return;
}


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

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

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

    sort(D,D+N);

    int min = 0;
    int total = 0;

    for(int i = 0;i<N;i++){
        if(D[i] != min){
            total++;
            min = D[i];
        }
    }

    cout << total << endl;

    return 0;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  n = readline() |> parseInt
  a = readline() |> split |> parseArray

  ans=1/sum(1/a[i] for i in 1:n)

  println(ans)
end

main()


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

struct Trie{
    int next[100][26];
    int cnt[100];
    int root,sz;
    void init()
    {
        memset(next,-1,sizeof(next));
        memset(cnt,0,sizeof(cnt));
        root = sz = 0;
    }

    void insert(char *str)
    {
        int now = root,index;
        while(*str)
        {
            index = *(str++) - 'a';
            if(next[now][index] == -1)
                next[now][index] = ++sz;
            now = next[now][index];
        }
        cnt[now]++;
    }

    bool query(char*& str)
    {
        int now = root,index;
        while(*str)
        {
            index = *(str++) - 'a';
            if(next[now][index] == -1)
            {
                str -= 1;
                if(cnt[now] == 0)
                    return false;
                return true;
            }
            now = next[now][index];
            if(cnt[now] != 0)
                return true;
        }
        return false;
    }
}TT;
const int MAXN = 1e5+10;
char str[MAXN];

int main()
{
    TT.init();
    TT.insert("maerd");
    TT.insert("remaerd");
    TT.insert("esare");
    TT.insert("resare");
    scanf("%s",str);
    int len = strlen(str);
    for(int i = 0; i < len/2; ++i)
        swap(str[i],str[len-i-1]);
    char *s = str;
    while(*s)
    {
        if(TT.query(s) == false)
        {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
#define SZ(x) ((ll).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}
template<class T>bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll n, a, b;
  cin >> n >> a >> b;
  cout << min(b, n*a) << endl;
  
  return 0;
}

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

#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef long double ld;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};





int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int a,b,v,w,t;
    cin>>a>>v>>b>>w>>t;

    if(w >= v){
    }else{
        ld cap = fabs(b-a)/(v-w);
        if(cap <= t)flag=true;
    }
    //cout <<fixed<<setprecision(16)<< << endl;
    if(flag)cout << "YES" <<endl;
    else cout << "NO" <<endl;

    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>

char S[5];

int check_month(int v) {
  if ((v > 0) && (v < 13)) {
    return 1;
  }
  return 0;
}

int check_year(int v) {
  if ((v >= 0) && (v <= 99)) {
    return 1;
  }
  return 0;
}

int main()
{
  int cnt;
  int left;
  int right;
  int i;
  
  cnt = scanf("%s", S);

  for (i=0; i<4; i++) {
    if ((S[i] < '0') ||
        (S[i] > '9') ) {
      printf("NA");
      return 0;
    }
  }

  left  = (S[0] - '0') * 10 + (S[1] - '0');
  right = (S[2] - '0') * 10 + (S[3] - '0');

  if (check_month(left) && check_month(right)) {
    printf("AMBIGUOUS");
    return 0;
  }

  if (check_month(left) && check_year(right)) {
    printf("MMYY");
    return 0;
  }

  if (check_month(right) && check_year(left)) {
    printf("YYMM");
    return 0;
  }

  printf("NA");
  return 0;
}



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





int main()
{
  string S;
  string T;
  cin >> S;
  cin >> T;

  // cout << S.at(0) << endl;

  int count = 0;
  for (int i=0; i<S.size(); i++)
  {
    if (S.at(i) != T.at(i))
    {
      count++;
    }
  }

  cout << count << endl;

}


Measured memory_bytes: 3860
# x = iB + j とすると
# floor(A(iB + j) / B) - A * floor((iB + j/)B)
#   = A * i + floor(A * j / B) - A * i - A * floor(j / B)
#   = floor(A * j / B)
# なので, A * j が最大の時, floor(Ax/B) - A * floor(x/B) は最大となる.
# 0 <= j < B なので, x の値は
#   N < B の時, x = N, N >= B の時 x = B - 1
# となる.


from math import floor


def solve():
    A, B, N = map(int, input().split())
    x = min(N, B - 1)
    print(floor(A * x / B) - A * floor(x / B))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9156
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
    int n,x[100],y[100];
    double sum[4];
    cin >> n;
    for(int i=0;i<n;i++) cin >> x[i];
    for(int j=0;j<n;j++) cin >> y[j];
    for(int k=0;k<4;k++) sum[k] = 0.0;
    for(int p=1;p<4;p++){
        for(int i=0;i<n;i++){
            sum[p] += pow(fabs(x[i]-y[i]),p);
        }
        sum[p] = pow(sum[p],1.0/p);
    }
    for(int i=0;i<n;i++){
        sum[0] = (sum[0]<fabs(x[i]-y[i])?fabs(x[i]-y[i]):sum[0]);
    }
    printf("%.5f\n%.5f\n%.5f\n%.5f\n",sum[1],sum[2],sum[3],sum[0]);
    return 0;
}


Measured memory_bytes: 3340
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;



int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,a,b,k;
    cin>>n;
    a=1;b=n;
    k=sqrt(n);
    for (int i=2;i<=k;++i)
    {
        if (n%i==0)
        {
            a=i;
            b=n/i;
        }
    }
    cout<<a+b-2;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
	long long int a, b, c, n;
	scanf("%lld%lld%lld%lld", &a, &b, &c, &n);
	if (a >= n)
	{
		printf("%lld", n);
	}
	else if (a + b >= n)
	{
		printf("%lld", a);
	}
	else
	{
		printf("%lld", a - (n - a - b));
	}
	return 0;
}

Measured memory_bytes: 1736
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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


int lcs(string X, string Y){
    int m = X.length(), n = Y.length();
    vector<VI> dp(m+1, VI(n+1, 0));

    FORS(i, 1, m){
        FORS(j, 1, n){
            if(X[i-1] == Y[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    return dp[m][n];
}

int main(){
    int q; cin >> q;
    REP(i, q){
        string X, Y;
        cin >> X >> Y;
        cout << lcs(X, Y) << "\n";
    }
    return 0;
}



Measured memory_bytes: 6908
#include <cstdio>
#include <algorithm>
#include <queue>

using namespace std;

const int INFTY=1<<29;

int grid[1000][1000],vis[1000][1000];
int xs[1000],ys[1000];
int w,h;
int di[]={-1,1,0,0},dj[]={0,0,-1,1};

bool ok(int time)
{
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			vis[i][j]=0;
	
	queue<pair<int,int> > q;
	q.push(make_pair(0,0));
	while(q.size()){
		int i=q.front().first,j=q.front().second;
		q.pop();
		if(vis[i][j])
			continue;
		vis[i][j]=1;
		if(grid[i][j]==-1)
			return true;
		
		for(int k=0;k<4;k++){
			int ni=i+di[k],nj=j+dj[k];
			if(0<=ni && ni<h && 0<=nj && nj<w && grid[ni][nj]<=time)
				q.push(make_pair(ni,nj));
		}
	}
	return false;
}

int main()
{
	while(~scanf("%d%d ",&w,&h) && w|h){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				int c=getchar();
				if(c=='t') grid[i][j]=-1;
				if(c=='#') grid[i][j]=INFTY;
				if(c=='.') grid[i][j]=0;
			}
			getchar();
		}
		int n; scanf("%d",&n);
		for(int i=0;i<n;i++)
			scanf("%d%d",xs+i,ys+i);
		
		for(int i=0;i<n;i++)
			grid[ys[i]][xs[i]]=min(grid[ys[i]][xs[i]],i+1);
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
				grid[i][j]=min(grid[i][j],n+1);
		
		int lo=-1,hi=n+1;
		while(hi-lo>1){
			int mi=(lo+hi)/2;
			if(ok(mi))
				hi=mi;
			else
				lo=mi;
		}
		printf("%d\n",hi==n+1?-1:hi);
	}
	return 0;
}

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

int main(){

    int n,k,tmp,length,ans = 0;
    cin >> n >> k;
    for(int i = 0;i < n;i++){
        cin >> tmp;
        length = min(2*tmp,2*(k-tmp));
        ans += length;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
inline int read() {
    char c = getchar();
    int x = 0;
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9') x = x*10+c-'0', c = getchar();
    return x;
}
using namespace std;
int n, m;
int a[(int)1e7+10];
int main() {
    int ans = 0;
    n = read(), m = read();
    for(int i = 1; i <= n; ++i) a[i] = n+1;
    for(int t = 1, x, y; t <= m; ++t)
        x = read(), y = read(), a[x] = min(a[x], y);
    for(int i = 1, t = n+1; i <= n; ++i) {
        t = min(t, a[i]);
        if(t == i) ans++, t = a[i];
    }
    printf("%d", ans);
    return 0;
}

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

set<int> SE, NG;

bool f(int n) {
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) if (SE.count(i) || SE.count(n / i)) return false;
  }
  return true;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  for (int i = 0; i < N; i++) {
    if (SE.count(A.at(i))) {
      NG.insert(A.at(i));
      continue;
    }
    if (f(A.at(i))) SE.insert(A.at(i));
  }
  cout << SE.size() - NG.size() << "\n";
}

Measured memory_bytes: 13408
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define pb push_back

#define mod 1000000007
#define maxn 500005

ll frac[maxn];


// 解 (ax == 1) mod p 。p 必須是質數，a 是正整數。
ll modinv(ll a) {
	ll p = mod;
    ll pp = p, y = 0, x = 1;
    while (a > 1) {
        ll q = a / p, t = p;
        p = a % p, a = t, t = y, y = x - q * y, x = t;
    }
    if (x < 0) x += pp;
    return x;
}

inline void f(int n) {
	frac[0] = 1;
	for (ll i = 1; i <= n; i++)
		frac[i] = frac[i - 1] * i % mod;
}

inline ll C(int a, int b) {
	return frac[a] * modinv(frac[a - b]) % mod * modinv(frac[b]) % mod;
}

inline ll P(int a, int b) {
	return frac[a] * modinv(frac[a - b]) % mod;
}

void add(ll &ans, ll a) {
	ans = (ans + mod + a) % mod;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> m >> n;
	f(n);
	ll ans = 0;
	for (int i = 0; i <= m; i++) {
		add(ans, C(m, i) * P(n - i, m - i) % mod * (i % 2 ? -1 : 1));
	}
	ans = ans * P(n, m) % mod;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 7472
import sys
input = sys.stdin.readline
N,A,B,C=map(int,input().rstrip().split())
l=[int(input().rstrip()) for _ in range(N)]
inf=10**9+7
def resolve():
    print(rect(0,0,0,0))

def rect(i,a,b,c):
    if i==N:
        if(a==0 or b==0 or c==0):
            return inf
        return abs(A-a)+abs(B-b)+abs(C-c)



    ans=rect(i+1,a,b,c)

    costa=10 if a!=0 else 0
    costb=10 if b!=0 else 0
    costc=10 if c!=0 else 0

    ans=min(ans,rect(i+1,a+l[i],b,c)+costa)
    ans=min(ans,rect(i+1,a,b+l[i],c)+costb)
    ans=min(ans,rect(i+1,a,b,c+l[i])+costc)


    return ans


import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5 100 90 80
98
40
30
21
80"""
        output = """23"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """8 100 90 80
100
100
90
90
90
80
80
80"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """8 1000 800 100
300
333
400
444
500
555
600
666"""
        output = """243"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Measured memory_bytes: 5820
n = int(input())
A = list(map(int, input().split()))
Alice = [0] * n
Bob = Alice[:]

A.sort(reverse = True)

for i in range(n):
    if i % 2 == 0:
        Alice[i] = A[i]
    else:
        Bob[i] = A[i]

print(sum(Alice) - sum(Bob))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  map<int,int>mp;
  for(int i=0; i<n; i++){
    int k;
    cin>>k;
    for(int j=0; j<k; j++){
      int x;
      cin>>x;
      mp[x]++;
    }
  }
  int cnt=0;
  for(auto p:mp){
    if(p.second==n)cnt++;
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;
const int maxn = 105;
int xx[maxn], yy[maxn];

int main()
{
    int x, y, n, a = 0, b = 0;
    cin >> x >> y >> n;
    for(int i = 0; i < x; i++){
        xx[i] = 1;
    }
    for(int i = 0; i < y; i++){
        yy[i] = 1;
    }
    for(int i =0; i < n; i++){
        int x1, y1, order;
        cin >> x1 >> y1 >> order;
        if(order == 1) for(int i = 0; i < x1; i++) xx[i] = 0;
        else if(order == 2) for(int i = x1; i < x; i++) xx[i] = 0;
        else if(order == 3) for(int i = 0; i < y1; i++) yy[i] = 0;
        else if(order == 4) for(int i = y1; i < y; i++) yy[i] = 0;
    }
    for(int i = 0; i < x; i++) if(xx[i] == 1) a++;
    for(int i = 0; i < y; i++) if(yy[i] == 1) b++;
    cout << a*b;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<tuple>
#include<sstream>
#include<functional>
#include<list>
#include<queue>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> p;
typedef vector<int> vec;
using Graph = vector<vector<int>>;
using graph = vector<vector<ll>>;

const long long INF = 1LL << 60;
const ll inf = 1e9;
const long long MOD = 1000000007;



int main() {
    long double t = acos(-1);
    long double ans = 0;
    ll n;
    cin >> n;
    vector<ll> x, y;
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        x.push_back(a); y.push_back(b);
    }
    vector<pair<long double,ll>> vx(n*2),vy(n*2);
    rep(i, n) {
        vx[i].first = atan2(y[i], x[i]); vx[i].second = x[i];
        vy[i].first = atan2(y[i], x[i]); vy[i].second = y[i];
    }
    rep(i, n) {
        vx[i+n].first = atan2(y[i], x[i])+t*2; vx[i+n].second = x[i];
        vy[i+n].first = atan2(y[i], x[i])+t*2; vy[i+n].second = y[i];
    }
    sort(all(vx)); sort(all(vy));
    vector<long double> rad(n*2);
    vector<ll> X(n*2), Y(n*2);
    X[0] = vx[0].second; Y[0] = vy[0].second;
    rep(i, n*2) {
        rad[i] = vx[i].first;
        if (i != 0) {
            X[i] = X[i - 1] + vx[i].second; Y[i] = Y[i - 1] + vy[i].second;
        }
    }
    rep(i, n) {
        int a = lower_bound(all(rad), rad[i]+t-1)-rad.begin();
        int b= lower_bound(all(rad), rad[i] + t + 1) - rad.begin();
        repd(j, a, b + 1) {
            if (i != 0)ans = max((long double)sqrt((X[j - 1] - X[i - 1]) * (X[j - 1] - X[i - 1]) + (Y[j - 1] - Y[i - 1]) * (Y[j - 1] - Y[i - 1])), ans);
            else ans = max(ans, (long double)sqrt(X[j - 1] * X[j - 1] + Y[j - 1] * Y[j - 1]));
        }
    }
    printf("%0.20Lf\n", ans);
    return 0;
}

Measured memory_bytes: 4168
#include <stdio.h>
 
int isPrime(int x){
	if(x==1){
		return -1;
	}
	int i;
	for(i=2;i<x;i++){
		if(x%i==0){
			return -1;
		}
	}
	return 1;
}
 
int main(void){
	int N;
	scanf("%d",&N);
 
	int i;
	int ans[55];
	printf("31 ");
	for(i=31; i<=55555; i+=30){
		if(isPrime(i) == 1){
			if(i != 31)	printf("%d ",i);
			N--;
			if(N==0)	break;
		}
	}
	
	
	return 0;}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <cmath>
#define N 100005
using namespace std;

typedef long long ll;
int n, s, a[N], mx, v[N];
int main()
{
	int i;
	cin >> n;
	for (i = 1; i <= n; i++) {
		scanf ("%d", &a[i]);
	}
	for (i = 1; i <= n; i++) {
		if (a[i] == i) {
			s++;
			swap(a[i], a[i + 1]);
		}
	}
	cout << s;
    return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>




using namespace std;
int main() {
	
	int a,b;
	cin >> a >> b;
	if (a <= b)cout << a << endl;
	else cout << a-1 << endl;

	return 0;
}

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

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

  double l = 0;
  const double PI=3.14159265358979323846;
  l = 2*n*PI;

  cout << fixed << setprecision(15)<< l << endl;
}

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

typedef long long ll;
  
int main(){
  int m, d;
  cin>> m >> d;
  int ans=0;
  for(int i=1; i<=d; i++){
   for(int j=1; j<=m; j++){
      int d1=i%10;
      int d10=(i-d1)/10;
      if(d1>=2 && d10>=2){
	if (d1*d10 == j) ans++;
      }
    }
  }
  cout<< ans << endl;
}


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

int n=3, x, y, cnt, c[5];
int main() {
	while(n--) {
		cin>> x>> y;
		c[x]++, c[y]++;
	}
	for(int i=1; i<=4; i++) if(c[i]%2) cnt++;
	cout<< (cnt==2? "YES": "NO");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    return a.second > b.second;
}

int main() {
    // source
    int n, m;
    cin >> n >> m;
    int a[n], b[n];
    rep(i, n) { cin >> a[i] >> b[i]; }

    vector<vector<int>> v(m + 1);
    rep(i, n) {
        if (a[i] <= m) {
            v[a[i]].push_back(b[i]);
        }
    }

    priority_queue<int> ans_vector;

    ll ans = 0;
    repd(i, 1, m + 1) {
        rep(j, v[i].size()) { ans_vector.push(v[i][j]); }
        if (ans_vector.size() != 0) {
            ans += ans_vector.top();
            ans_vector.pop();
        }
    }

    cout << ans << endl;

    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 6400
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {  
    int n;
    cin >> n;
    vector<int> v(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end(), greater<int>());
    int res = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            res += v[i];
        } else {
            res -=v[i];
        }
    }
    cout << res << endl;
}




Measured memory_bytes: 3616
N = int(input())
L = list(map(int, input().split(" ")))
cnt =0 

for i in range(len(L)):
    for j in range(len(L) - (i+1)):
        for k in range(len(L) - (i+1+j+1)):
            if L[i] != L[j+i+1] and L[i] != L[k+i+j+2] and L[j+i+1] != L[k+i+j+2]:
                if L[i]+L[j+i+1] > L[k+i+j+2] and L[i]+L[k+i+j+2] > L[j+i+1] and L[k+i+j+2]+L[j+i+1] > L[i]:
                    cnt += 1
print(cnt)

Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct UF{
    int n;
    //正だったらその頂点の親,負だったら根で連結成分の個数
    vector<int> d;
    UF() {}
    UF(int N):n(N), d(N,-1){}
    int root(int v){
        if(d[v]<0) return v;
        return d[v]=root(d[v]);
    }
    bool unite(int X,int Y){
        X=root(X); Y=root(Y);
        if(X==Y) return false;
        if(size(X) < size(Y)) swap(X,Y);
        d[X]+=d[Y];
        d[Y]=X;
        return true;
    }
    int size(int v){ return -d[root(v)]; }
    bool same(int X,int Y){ return root(X)==root(Y); }
};

using pi = pair<int,int>;

const int N = 100010;

vector<int> G[N];
int idx[N];
ll max_s[N];
ll s[N];

vector<int> Q[N];
vector<int> U[N];

int main(){
    int n;
    scanf(" %d", &n);

    vector<pi> v(n);

    rep(i,n){
        int c;
        scanf(" %d", &c);
        v[i] = {c,i};
    }
    sort(all(v));

    vector<int> c(n), f(n);
    rep(i,n){
        c[i] = v[i].fi;
        f[v[i].se] = i;
    }
    rep(i,n) Q[c[i]].pb(i);

    int m;
    scanf(" %d", &m);
    rep(i,m){
        int a,b;
        scanf(" %d %d", &a, &b);
        a = f[a-1];
        b = f[b-1];

        G[a].pb(b);
        G[b].pb(a);
        U[c[a]].pb(b);
        U[c[b]].pb(a);
    }

    rep(i,N){
        sort(all(G[i]));
        sort(all(U[i]));
        U[i].erase(unique(all(U[i])), U[i].end());
    }

    UF uf(n);
    vector<ll> umx(n);

    rep(i,N){
        // printf(" --- i = %d --- \n", i);

        // calc salary
        for(int j:Q[i]){
            s[j] = max_s[j];
            for(int e:G[j]){
                s[j] = max(s[j], max_s[e]);
            }
            ++s[j];
            // printf(" s[%d] = %lld\n", j,s[j]);
        }

        // check salary for same contibution
        for(int j:Q[i]){
            int tt = idx[j];
            int root = j;
            while(tt<G[j].size() && c[G[j][tt]]==i){
                uf.unite(root, G[j][tt]);
                ++tt;
            }
        }

        for(int j:U[i]){
            int tt = idx[j];
            assert(c[G[j][tt]]==i);
            int root = G[j][tt];
            ++tt;
            while(tt<G[j].size() && c[G[j][tt]]==i){
                uf.unite(root, G[j][tt]);
                ++tt;
            }
        }

        for(int j:Q[i]) umx[uf.root(j)] = max(umx[uf.root(j)], s[j]);
        for(int j:Q[i]) s[j] = umx[uf.root(j)];

        // update
        for(int j:U[i]){
            while(idx[j]<G[j].size() && c[G[j][idx[j]]]<=i){
                max_s[j] = max(max_s[j], s[G[j][idx[j]]]);
                ++idx[j];
            }
            // printf(" UPD %d : %lld\n", j,max_s[j]);
        }
    }

    ll ans = 0;
    rep(i,n) ans += s[i];
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 25716
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll unsigned long long
#define ld long double
#define ui unsigned int
#define ull unsigned ll
#define foi(n) for(ll i=0;i<n;i++)
#define foj(n) for(ll j=0;j<n;j++)
#define fok(n) for(ll k=0;k<n;k++)
#define fom(n) for(ll m=0;m<n;m++)
#pragma GCC optimize("O3", "unroll-loops")
#define fixed(); cout << fixed << setprecision(20);
#define fast(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

/*****************************************************************************/


#define graph          vector<vector<int>>
#define V              vector
typedef pair<int, int> pii;
typedef pair<ll, ll>   pll;
typedef V<int>         vi;
typedef V<ll>          vll;
typedef V<string>      vs;
typedef V<double>      vd;
typedef V<pii>         vpii;             
typedef V<pll>         vpll;             
typedef pair<int,pii>  piii;             
typedef priority_queue<pii, vector<pii>, greater<pii> > pqq;   

/*****************************************************************************/

#define mp                   make_pair
#define eb                   emplace_back
#define pb                   push_back
#define pf                   push_front
#define popb                 pop_back
#define popf                 pop_front
#define hashmap              unordered_map
#define hashset              unordered_set
#define lb                   lower_bound
#define ub                   upper_bound
#define all(a)               (a).begin(), (a).end()
#define rall(a)              (a).rbegin(), (a).rend()
#define ff                   first
#define ss                   second
#define lbpos(v,x)           (int)(lower_bound(all(v),x)-v.begin())//=v.size()==>No LB 
#define ubpos(v,x)           (int)(upper_bound(all(v),x)-v.begin())//=v.size()==>No UB

//*****************UVAISH ZAFRI(Rush_For_AC)**********************
#define mod 1000000007

int32_t main() {
    fast();fixed();
    #ifndef ONLINE_JUDGE
    freopen("tad.txt","r",stdin);
    freopen("tada.txt","w",stdout);
    #endif
    
    string s;
    cin>>s;
    ll res=0;
    foi(s.length()){
      res+=s[i]-48;

    }
    if(res%9==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  
    
}



Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll n, a, b;
  cin >> n >> a >> b;
  if(n % (a+b) >= a) cout << n / (a+b) * a + a << endl;
  else cout << n / (a+b) * a + n % (a+b) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,h,w;
  cin >> n >>h >>w;
  int ans =0;
  for(int i=0;i<n;i++){
    int H,W;
    cin >>H>>W;
    if(H>=h&&W>=w){
      ans++;
    }
  }
  cout <<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i,n){
        cin >> vec.at(i);
    }
    int sum = 0;
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            if(i==j) continue;
            sum += vec.at(i)*vec.at(j); 
            //cout << sum << endl;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = (ll)1e9;

int main(){
	int a,b,c;
	cin >> a>>b>>c;
  	int ans = b/a;
  	cout << (ans>c?c:ans)<<endl;
  	return 0;
}

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

int main() {
    int n, m, result = 0;
    
    cin >> n;
    vector<string> blue(n);
    for (int i = 0; i < n; i++) {
        cin >> blue.at(i);
    }
    
    cin >> m;
    vector<string> red(m);
    for (int i = 0; i < m; i++) {
        cin >> red.at(i);
    }
    
    result = 0;
    for (int i = 0; i < n; i++) {
        int buf = 0;
        string bufstr = blue.at(i);
        for (int j = 0; j < n; j++) {
            if (bufstr == blue.at(j)) {
                buf++;
            }
        }
        for (int j = 0; j < m; j++) {
            if (bufstr == red.at(j)) {
                buf--;
            }
        }
        result = max(result,buf);
    }
    
    cout << result << endl;
}


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

a = 7
ans = 1
if k == 1 or k == 7:
    print(1)
    exit()
for i in range(1,10**6+1):
    a += (7*pow(10,i,k))%k
    a %= k
    ans += 1
    if a == 0:
        break
    elif i == 10**6:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 63680
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
double ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll x,y,z;sc(x);sc(y);sc(z);
 rep(i,1,x){
  //pr(y*i+z*(i+1));
  if(y*i+z*(i+1)>x){
   pr(i-1);
   return 0;
  }
 }
return 0;}

Measured memory_bytes: 3644
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <deque>

int main() {
  char buf[131072];
  scanf("%s", buf);
  std::string s = buf;
  std::deque<char> d(s.begin(), s.end());

  bool rev = false;

  size_t q;
  scanf("%zu", &q);

  while (q--) {
    int t;
    scanf("%d", &t);

    if (t == 1) {
      rev = !rev;
      continue;
    }

    if (t == 2) {
      int f;
      char c;
      scanf("%d %c", &f, &c);

      bool front = (!rev && f == 1) || (rev && f == 2);
      if (front) {
        d.push_front(c);
      } else {
        d.push_back(c);
      }
    }
  }

  if (rev) std::reverse(d.begin(), d.end());
  s.assign(d.begin(), d.end());
  printf("%s\n", s.c_str());
}


Measured memory_bytes: 1368
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

#include<bits/stdc++.h>
using namespace std;

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define dloop(i,n) for(int i=n-1;i>=0;i--)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

const int mxn = 1e5+10;
vi g[mxn];
bool vis[mxn];
int dp[mxn];
int n,m;

void dfs(int v){
	vis[v] = 1;
	for(auto u : g[v]){
		if(!vis[u]) dfs(u);
		dp[v] = max(dp[v],1+dp[u]);
	}
}

int32_t main(){
	NINJA;

	cin >> n >> m;
	fo(i,m){
		int f,s; cin >> f >> s;
		g[f].pb(s);
	}

	for1(i,n){
		if(!vis[i]){
			dfs(i);
		}
	}

	int mx = -inf;
	for1(i,n) mx = max(mx,dp[i]);

	cout << mx << endl;
	
	return 0;
}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int ans;
  if(S == "SUN")ans = 7;
  else if(S == "MON")ans =6 ;
  else if(S == "TUE")ans =5 ;
  else if(S == "WED")ans =4 ;
  else if(S == "THU")ans =3 ;
  else if(S == "FRI")ans =2 ;
  else if(S == "SAT")ans =1 ;
  cout << ans;
  
}

Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let x1: i32 = sc.cin();
    let y1: i32 = sc.cin();
    let x2: i32 = sc.cin();
    let y2: i32 = sc.cin();
    let mut v = (x2 - x1, y2 - y1);
    {
        v = (-v.1, v.0);
    }
    let x3 = x2 + v.0;
    let y3 = y2 + v.1;
    {
        v = (-v.1, v.0);
    }
    let x4 = x3 + v.0;
    let y4 = y3 + v.1;
    put!(x3, y3, x4, y4);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 4352
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
    class ProgramC
    {
        struct Info
        {
            public int a;
            public int b;
            public int c;
            public int d;
        }

        static int _depth, _count;
        static Info[] _list;
        static List<int> _result;

        // 深さ優先探索
        static void dfs(List<int> g)
        {
            if (g.Count == _depth)
            {
                // Console.WriteLine(string.Join("", g));
                _result.Add(calc(g));
                return;
            }

            for (var i = g.Last(); i <= _count; i++)
            {
                g.Add(i);
                dfs(g);
                g.RemoveAt(g.Count - 1);
            }
        }

        static int calc(List<int> g)
        {
            var result = 0;
            foreach (var l in _list)
            {
                if (g[l.b] - g[l.a] == l.c)
                {
                    result += l.d;
                }
            }
            return result;
        }

        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var n = int.Parse(inputs[0]);
            var m = int.Parse(inputs[1]);
            var q = int.Parse(inputs[2]);

            _depth = n;
            _count = m;

            _list = new Info[q];
            for (var i = 0; i < q; i++)
            {
                var inputs1 = Console.ReadLine().Split(" ");
                _list[i].a = int.Parse(inputs1[0]) - 1;
                _list[i].b = int.Parse(inputs1[1]) - 1;
                _list[i].c = int.Parse(inputs1[2]);
                _list[i].d = int.Parse(inputs1[3]);
            }

            _result = new List<int>();
            for (var i = 1; i <= m; i++)
            {
                dfs(new List<int>() { i });
            }

            Console.WriteLine(_result.Count > 0 ? _result.Max() : 0);
        }
    }
}


Measured memory_bytes: 29028