akhauriyash/Code-Regression huggingface dataset:
function Main(input) {
    input = input.split("\n");
    tmp = input[0].split(" ");
    n = tmp[0];
    k = tmp[1];
    p = input[1].split(" ");

    let q = [];
    for(let i = 0; i < n; i++ ){
        q[i] = parseInt(p[i], 10);
    }

    q.sort(
        function(a,b){
            return (a < b ? -1 : 1);
        }
    );

    let sum = 0;
    for(let i = 0; i < k; i++){
        sum += q[i];
    }

    console.log(sum);
}

 
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29540
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		FastScanner fs = new FastScanner();
		int A  = fs.nextInt();
		int B  = fs.nextInt();
		int C  = fs.nextInt();
		int K  = fs.nextInt();
		int max = 0;
		max = Math.min(A, K);
		if(A < K) {
			if(B < (K -A)) {
				max -= (K-A) - B;
			}
		}
		System.out.println(max);
	}

}


Measured memory_bytes: 25344
a,b,c=map(int,input().split())
l=[]
l.append(a)
l.append(b)
l.append(c)
l.sort()
ans=0
if (3*l[2])%2==(sum(l))%2:
    print((3*l[2]-sum(l))//2)
else:
    print((3*(l[2]+1)-sum(l))//2)
'''
while max(l[0],l[1])<l[2]:
    l[0]+=1
    l[1]+=1
    ans+=1
if (l[2]-l[0])%2==0:
    ans+=(l[2]-l[0])//2
    print(ans)
else:
    print(ans+2)
'''


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
/*メモ 
*/
int main(){
    string s;
    std::cin >> s;
    int k;
    std::cin >> k;
    int n=s.size();
    
    std::set<string> se;
    rep(i,n)rrep(j,i,n){
        se.insert(s.substr(i,j-i+1));
        if(j-i>6)break;
    }
    
    for(auto itr = se.begin(); itr != se.end(); ++itr) {
        if(distance(se.begin(),itr)==k-1){
            std::cout << *itr<< std::endl;
            exit(0);
        }
    }
    
}

Measured memory_bytes: 3072
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
string ma[30];
int d[410][410];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int main()
{
	int h,w,out=0,inf=555;
	cin>>h>>w;
	rep(i,h) cin>>ma[i];
	rep(i,405) rep(j,405) d[i][j]=inf;
	rep(i,405) d[i][i]=0;
	rep(i,h) rep(j,w){
		if(ma[i][j]=='#') continue;
		rep(k,4){
			int x=i+dx[k],y=j+dy[k];
			if(x<0 || y<0 || x>=h || y>=w || ma[x][y]=='#') continue;
			d[i*w+j][x*w+y]=1;
		}
	}
	rep(k,h*w) rep(i,h*w) rep(j,h*w) d[i][j]=min(d[i][k]+d[k][j],d[i][j]);
	rep(i,h*w) rep(j,h*w){
		if(ma[i/w][i%w]!='#' && ma[j/w][j%w]!='#') out=max(out,d[i][j]);
	}
	cout<<out<<endl;
}


Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

	static int h, w;
	static char[][] board;
	
	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		h=fs.nextInt(); w=fs.nextInt();
		int sy=fs.nextInt()-1, sx=fs.nextInt()-1;
		int ey=fs.nextInt()-1, ex=fs.nextInt()-1;
		ArrayDeque<Integer> xs=new ArrayDeque<>(), ys=new ArrayDeque<>();
		board=new char[w][h];
		for (int y=0; y<h; y++) {
			char[] line=fs.next().toCharArray();
			for (int x=0; x<w; x++) {
				board[x][y]=line[x];
			}
		}
		xs.add(sx);
		ys.add(sy);
		int[][] dist=new int[w][h];
		for (int x=0; x<w; x++) Arrays.fill(dist[x], 1_000_000_000);
		dist[sx][sy]=0;
		int[] dx= {-1, 1, 0, 0};
		int[] dy= {0, 0, -1, 1};
		while (!xs.isEmpty()) {
			int curX=xs.removeFirst(), curY=ys.removeFirst();
			for (int d=0; d<4; d++) {
				int nx=curX+dx[d], ny=curY+dy[d];
				if (!legal(nx, ny)) continue;
				if (dist[nx][ny]>dist[curX][curY]) {
					dist[nx][ny]=dist[curX][curY];
					xs.addFirst(nx);
					ys.addFirst(ny);
				}
			}
			for (int x=curX-2; x<=curX+2; x++) {
				for (int y=curY-2; y<=curY+2; y++) {
					if (!legal(x, y)) continue;
					if (dist[x][y]>dist[curX][curY]+1) {
						dist[x][y]=dist[curX][curY]+1;
						xs.addLast(x);
						ys.addLast(y);
					}
				}
			}
		}
		System.out.println(dist[ex][ey]>1e7?-1:dist[ex][ey]);
	}

	static boolean legal(int x, int y) {
		if (x<0||y<0||x>=w||y>=h || board[x][y]=='#') return false;
		return true;
	}
	
	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


Measured memory_bytes: 65764
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;
	cin >> n >> k;
	vector<int> a(n),cnt(200005);
	set<int> se;
	rep(i,n){
		cin >> a[i];
		++cnt[a[i]];
		se.insert(a[i]);
	}
	int m = se.size();
	sort(all(cnt),greater<int>());
	sort(cnt.begin(),cnt.begin()+m);
	int sum = 0;
	rep(i,m-k){
		sum += cnt[i];
	}
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 12800
n, m = map(int, raw_input().split())
a = map(int, raw_input().split())
s = [0] * (2 * m + 1)
cnt = [0] * (m + 1)
for i in xrange(n - 1):
    cnt[a[i + 1]] += (a[i + 1] + m - a[i]) % m - 1
for i in xrange(n - 1):
    s[a[i] + 1] += 1
    if a[i + 1] < a[i]:
        s[a[i + 1] + m] -= 1
    else:
        s[a[i + 1]] -= 1

for i in xrange(2 * m):
    s[i + 1] += s[i]
for i in xrange(1, m + 1):
    s[i] = s[i] + s[i + m]

tmp = 0
for i in xrange(n - 1):
    if a[i + 1] < a[i]:
        tmp += (a[i + 1] - 1) + 1
    else:
        tmp += (a[i + 1] - a[i])
ans = tmp
for i in xrange(2, m + 1):
    tmp = tmp + cnt[i - 1] - s[i - 1]
    ans = min(ans, tmp)
print ans


Measured memory_bytes: 15060
import math

n,m = map(int, input().split())

rev= 10**9+7

if (n - m ==0):
    ans = 2 * math.factorial(n) * math.factorial(m)
elif (abs(n - m) == 1):
    ans = 1 * math.factorial(n) * math.factorial(m)
else:
    ans = 0
print(ans%rev)

Measured memory_bytes: 5100
N,D,A = map(int,input().split())
XH = []
X = []

for i in range(N):
    x,h = map(int,input().split())
    XH.append([x,h,0])
    X.append(x)
    
XH.sort(key = lambda a:a[0])
XH.append([float('inf'),0,0])
X.sort()
X.append(float('inf'))

import bisect
ans = 0

for i in range(N):
    x,h,k = XH[i]
    dk = max(-(-(h-k*A)//A),0)
    #print(x,h,k,dk)
    ans += dk
    
    XH[i][2] += dk
    j = bisect.bisect_right(X,x+2*D)
    XH[j][2] -= dk

    XH[i+1][2] += XH[i][2]
    
print(ans)

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

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var p = new bool[n];
            GeneratePrime(p);
            var count = 0;
            for (int i = 0; i <= n / 2; i++)
                if (p[i] && p[n - i]) count++;
            Console.WriteLine(count);
        }
    }
    public static void GeneratePrime(bool[] p)
    {
        int prime;
        var m = p.Length;
        var sqrtMax = Math.Sqrt(m);
        var searchList = Enumerable.Range(2, m - 1).ToList();
        do
        {
            prime = searchList.First();
            p[prime] = true;
            searchList.RemoveAll(n => n % prime == 0);
        }
        while (prime < sqrtMax);
        foreach (var x in searchList)
            p[x] = true;
    }
}

Measured memory_bytes: 25688
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int h,w;
int c[10][10];
int a[300][300];
int main(){
	cin >> h >> w;
	REP(i,10) {
		REP(j,10) {
			cin >> c[i][j];
		}
	}
	REP(i,h) {
		REP(j,w) {
			cin >> a[i][j];
		}
	}

	REP(k,10) {
		REP(i,10) {
			REP(j,10) {
				c[i][j] = min(c[i][j],c[i][k] + c[k][j]);
			}
		}
	}

	ll ans = 0;
	REP(i,h) {
		REP(j,w) {
			if(a[i][j] >= 0) {
				ans += c[a[i][j]][1];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
import Data.Maybe
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    [n, k, x, y] <- map strToInt . lines <$> getContents
    -- 出力
    putStrLn . show $ (min k n) * x + (max 0 (n-k)) * y


Measured memory_bytes: 508
s = list(input())
n = len(s)
ans = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        ans+=1
        if s[i] == '0':
            s[i+1] = '1'
        if s[i] == '1':
            s[i+1] = '0'
print(ans)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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 (b<a) { a=b; return 1; } return 0; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    string s;
    cin >> s;
    ll N = s.size();
    string ans = "";
    rep(i, N) ans += "x";
    cout << ans << endl;
}

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

const int mod = 1000*1000*1000 + 7;

int mul(int a, int b) {
	return (1LL * a * b) % mod;
}

int mpow(int a, int n) {
	if(n == 0) return 1;
	int x = mpow(a, n/2);
	x = mul(x, x);
	if(n % 2) x = mul(a, x);
	return x;
}

void add_self(int& a, int b) {
	a += b;
	if(a >= mod) a -= mod;
}

void sub_self(int& a, int b) {
	a -= b;
	if(a < 0) a += mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	vector<int> arr(n);
	for(int& x : arr) cin >> x;
	
	int ans = 0;
	
	vector<int> less(n), less_left(n);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(arr[j] < arr[i]) {
				less[i]++;
				if(j < i) less_left[i]++;
			}
		}
	}
	
	for(int i = 0; i < n; i++) {
		int sum = mul(k, k+1);
		sum = mul(sum, mpow(2, mod-2));
		add_self(ans, mul(sum, less[i]));
		sub_self(ans, mul(k, less_left[i]));
	}
	
	cout << ans << endl;
}


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

bool contain(string &str, char c) {
  return str.find(c) != string::npos;
}

int main() {
  string n, s;
  getline(cin, n);
  getline(cin, s);
  cout << (contain(s, 'Y') ? "Four" : "Three") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int A[100001];
int main()
{
    map <int, int> mp;
    int n, x, y, i, j, z, cnt = 0;
    cin >> x >> n;
    for(i = 0; i < n; i++)
    {
        cin >> y;
        for(j = 0; j < y; j++)
        {
            cin >> z;
            mp[z]++;
        }
    }
    for(i = 1; i <= x; i++)
    {
        ///cout << mp[i] << endl;
            if(mp[i] == 0)
            {
                cnt++;
            }
    }
    cout << cnt << endl;
}



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

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 f(ll x, int c, int d) {
  ll res = x;
  res -= x/c;
  res -= x/d;
  res += x/lcm(c,d);
  return res;
}

int main() {
  ll a, b;
  int c, d;
  cin >> a >> b >> c >> d;
  ll ans = f(b,c,d) - f(a-1,c,d);
  cout << ans << endl;
  return 0;
}


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

int main(){
  long n,inf = 1000000007;
  cin >> n;
  string s,t;
  cin >> s >> t;
  long i = 0;
  bool wakare = false;
  long kekka = 1;
  while(i < n){
    if(wakare == false && s.at(i) != t.at(i)){
      wakare = true;
      if(i == 0){
        kekka *= 6;
      }
      else{
        kekka = (kekka*2)%inf;
      }
      i += 2;
    }
    else if(wakare == true && s.at(i) != t.at(i)){
      wakare = true;
      i += 2;
      kekka = (kekka*3)%inf;
    }
    else if(wakare == true && s.at(i) == t.at(i)){
      wakare = false;
      i++;
    }
    else{
      wakare = false;
      if(i == 0){
        kekka *= 3;
      }
      else{
        kekka = (kekka*2)%inf;
      }
      i++;
    }
  }
  cout << kekka << endl;
}

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


N = int(input())

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

if min(As) >= 0:
    print(len(As)-1)
    for i in range(len(As)-1):
        print(i+1, i+2)
elif max(As) <= 0:
    print(len(As)-1)
    for i in range(len(As)-1,0,-1):
        print(i+1, i)
elif abs(max(As)) >= abs(min(As)):
    max_index = As.index(max(As))
    print(len(As)*2-1)
    for i in range(len(As)):
        print(max_index+1, i+1)
    for i in range(len(As)-1):
        print(i+1, i+2)
else:
    min_index = As.index(min(As))
    print(len(As)*2-1)
    for i in range(len(As)):
        print(min_index+1, i+1)
    for i in range(len(As)-1,0,-1):
        print(i+1, i)


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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


int main(){
  int a;
  string s;
  cin>>a>>s;
  if(a>=3200){
    cout<<s<<endl;
  }else{
    cout<<"red"<<endl;
  }
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#define MOD 1000000007
#define md 998244353
#define INF LLONG_MAX
#define F first
#define S second
#define sz(x) (long long)x.size()
#define vi vector<int>
#define vll vector<long long>
#define vpl vector<pair<long long,long long> >
#define vpi vector<pair<int,int> >
#define pb push_back
#define debug(x) cerr<<#x<<"= "<<x<<endl
#define all(v) v.begin(),v.end()
#define TT ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define endl '\n'
#define MAXN 100005
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll k;
    cin>>k;
    ll ans=-1,sum=0;
    for (int i = 1; i <= k; ++i)
    {
        sum=(sum*10+7)%k;
        if(sum==0){ans=i;break;}
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3648
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	a := readInt()
	b := readInt()
	println(solve(a, b))
}

func solve(a, b int) string {
	if 0 < a {
		return "Positive"
	}
	if b < 0 {
		if (b-a+1)%2 == 0 {
			return "Positive"
		} else {
			return "Negative"
		}
	}
	return "Zero"
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]

T, A = 0, 0
for t, a in TA:
    if T == 0 and A == 0:
        T = t
        A = a
        continue
    if t == a:
        M = max(T, A)
        T = M
        A = M
    elif t < a:
        n = max((T // t) * t, (A // a) * t)
        while n < T or a * (n // t) < A:
            n += t
        T = n
        A = a * (T // t)
    else:
        n = max((A // a) * a, (T // t) * a)
        while n < A or t * (n // a) < T:
            n += a
        A = n
        T = t * (A // a)
print(A + T)

Measured memory_bytes: 9184
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int N, T;

//1-idx
int dp1[3000 + 10][3000 + 10];//dp1[i][j] := [1, i]品目まで食べるかを選んで、jの時間がかかったときのおいしさの最大値 
int dp2[3000 + 10][3000 + 10];//dp2[i][j] := [i, N]品目まで食べるかを選んで、jの時間がかかったときのおいしさの最大値
vector<int> A, B;

int main() {
	cin >> N >> T;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		A.push_back(a), B.push_back(b);
	}
	
	dp1[0][0] = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= T - 1; j++) {
			dp1[i][j] = dp1[i - 1][j];
			if (j - A[i - 1] >= 0)dp1[i][j] = max(dp1[i][j], dp1[i - 1][j - A[i - 1]] + B[i - 1]);
		}
	}

	dp2[N + 1][0] = 0;
	for (int i = N; i >= 1; i--) {
		for (int j = 0; j <= T - 1; j++) {
			dp2[i][j] = dp2[i + 1][j];
			if (j - A[i - 1] >= 0)dp2[i][j] = max(dp2[i][j], dp2[i + 1][j - A[i - 1]] + B[i - 1]);
		}
	}

	int ans = max(dp1[N][T - 1], dp2[1][T - 1]);
	for (int i = 0; i <= N - 1; i++) {
		for (int j = 0; j <= T - 1; j++) {
			ans = max(ans, dp1[i][j] + B[i] + dp2[i + 2][T - 1 - j]);
		}
	}
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 5e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, x[maxn], a[maxn];
bool alpha[maxn], valid = true;

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

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i], x[i]--;

	for (int i = 0; i < n; i++)
	{
		if (a[x[i]])
			valid = false;
		a[x[i]] = i + 1;
		alpha[x[i]] = true;
	}
	int pos = 0;
	for (int i = 0; i < n * n; i++)
	{
		if (a[i])
		{
			int cnt = a[i] - 1;
			while (cnt && pos <= i)
			{
				if (a[pos])
					pos++;
				else
					a[pos] = a[i], cnt--, pos++;
			}
			if (cnt)
				valid = false;
		}
	}

	pos = n * n - 1;
	for (int i = n * n - 1; i >= 0; i--)
	{
		if (alpha[i])
		{
			int cnt = n - a[i];
			while (cnt && pos >= i)
			{
				if (a[pos])
					pos--;
				else
					a[pos] = a[i], cnt--, pos--;
			}
			if (cnt)
				valid = false;
		}
	}

	if (valid)
	{
		cout << "Yes" << endl;
		for (int i = 0; i < n * n; i++)
			cout << a[i] << ' ';
		cout << endl;
	}
	else
		cout << "No" << endl;
}



Measured memory_bytes: 4352
#include<iostream>

int main(){
    int c1,c5,c10,c50,c100,c500,sum,c1000=0;
    std::cin>>c1>>c5>>c10>>c50>>c100>>c500;
    sum=c1+5*c5+10*c10+50*c50+100*c100+500*c500;
    if(sum>=1000){
        c1000++;
    }
    std::cout<<c1000<<std::endl;
    return 0;
}

Measured memory_bytes: 1164
#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;}

ll solve()
{
    int n;
    cin >>n;

    map<ll,int> ct;
    rep(i,n)
    {
        ll a;
        cin >>a;
        ++ct[a];
    }

    vector<ll> t;
    ll ret = 0;
    for(const auto &p:ct)
    {
        if(p.se>=2) t.pb(p.fi);
        if(p.se>=4) ret = max(ret,p.fi*p.fi);
    }

    sort(all(t));
    int T = t.size();

    if(T>=2) ret = max(ret,t[T-1]*t[T-2]);
    return ret;
}

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


Measured memory_bytes: 6528
def main():
    N = int(input())

    p = 1
    for i in range(1, N + 1):
        # TLE
        # p *= i
        p = (p * i) % (10 ** 9 + 7)

    ans = p % (10 ** 9 + 7)
    print(ans)

if __name__ == '__main__':
    main()


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

using namespace std ;

long long a [ 200001 ] , c , d , e , f , g , h , k , l , m , n ;

int mn = 1e9 ;

int mx = -1e9 , x ;

string s , t , s1 , s2 ;

int main ()
{
    cin >> s >> t ;
    for ( int i = 0 ; i < s . size () ; ++ i ){
        if ( s == t ){
            cout << "Yes" << endl ;
            return 0 ;
        }
        s = s [ s . size () - 1 ] + s . substr ( 0 , s . size ( ) - 1 ) ;
    }
    cout << "No" ;
    return 0 ;
}
    

Measured memory_bytes: 256
# -*- coding utf-8 -*-
from scipy.misc import comb
MOD = int(1e9 + 7)

d = {}

def mycomb(n, r):
    if (n, r) not in d:
        d[(n, r)] = int(comb(n, r, exact=True)) % MOD
    return d[(n, r)]

N, K = map(int, input().split())
R = N - K

for i in range(1, K + 1):
    ans = mycomb(K - 1, i - 1) * mycomb(R + 1, i)
    print(ans % MOD)

Measured memory_bytes: 14348
#include<iostream>
using namespace std;
int main(){
  int n,card[4][13],x;
  char c;
  
  cin >> n;

  for(int i = 0;i < 4;i++){
    for(int j = 0 ;j < 13;j++){
      
      card[i][j] = 0;
    }
  }
  
  
  for(int i = 0;i < n;i++){
   
    cin >> c >> x;

    if(c == 'S') {card[0][x-1] = x;}
    else if (c == 'H') {card[1][x-1] = x;}
    else if (c == 'C') {card[2][x-1] = x;}
    else {card[3][x-1] = x;}


  }

  for(int i = 0;i < 4;i++){
    for(int j = 0 ;j < 13;j++){
      
      if(card[i][j] == false && i == 0) {
	cout << "S" << " " <<  j+1 << endl;
	  }
       if(card[i][j] == false && i == 1) {
	 cout << "H" << " " <<  j+1 << endl;
	  }
        if(card[i][j] == false && i == 2) {
	  cout << "C" << " " << j+1 << endl;
	  }
	 if(card[i][j] == false && i == 3) {
	   cout << "D" << " " << j+1 << endl;
	  }
    }
  }
  
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>


#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int64_t x; cin >> x;

	cout << (x / 500) * 1000 + ((x % 500) / 5) * 5 << endl;

	return 0;
}

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

int main(void)
{
    string S;
    cin >> S;
    if (S <= "2019/04/30")
    {
        cout << "Heisei" << endl;
    }
    else
    {
        cout << "TBD" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
use std::io;
fn main() {
    solve_a();
}

fn solve_a() {
    loop {
        let mut line = String::new();
        io::stdin().read_line(&mut line).unwrap();
        let line: Vec<_> = line.trim()
            .split(' ')
            .map(|s| s.parse::<i32>().unwrap())
            .collect();

        let m = line[0];
        let f = line[1];
        let r = line[2];

        if m == -1 && f == -1 && r == -1 {
            break;
        } else {
            if m == -1 || f == -1 {
                println!("F");
                continue;
            }
            match m + f {
                total if 80 <= total => println!("A"),
                total if 65 <= total && total < 80 => println!("B"),
                total if 50 <= total && total < 65 => println!("C"),
                total if 30 <= total && total < 50 => {
                    if 50 <= r {
                        println!("C");
                    } else {
                        println!("D");
                    }
                }
                _ => println!("F"),
            }
        }
    }
}



Measured memory_bytes: 5028
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


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

vector<vector<edge>> g;

vector<bool> see;


int main() {

	ll H, W;
	cin >> H >> W;

	vector<string> s(H);

	rep(i, H) cin >> s[i];

	vector<vector<char>> a(H, vector<char>(W));

	rep(i, H)rep(j, W) {
		if (s[i][j] == '#') { a[i][j] = '#'; }
		else {
			ll v = 0;
			rep(k, H)rep(l, W) {
				if (abs(k - i) <= 1 && abs(l - j) <= 1 && s[k][l] == '#') { v++; }
			}
			a[i][j] = '0' + v;
		}
	}

	rep(i, H) {
		rep(j, W) { cout << a[i][j]; }
		cout << endl;
	}

	system("PAUSE");

	

}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int f[n],a;
    memset(f,0,sizeof(f));
    int p[n][11];
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            cin>>a;
            f[i]+=(a<<j);
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<=10;j++){
            cin>>p[i][j];
        }
    }
    int num,sum;
    int ans=-1e9;
    for(int bit=1;bit<1024;bit++){
        sum=0;
        for(int i=0;i<n;i++){
            num=0;
            a=bit&f[i];
            while(a){
                if(a&1)num++;
                a/=2;
            }
            sum+=p[i][num];
        }
        ans=max(ans,sum);
    }
    cout << ans<<endl;
    return 0;
}


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

# 这个就不行。涉及深浅复制？
# table = [['0']*V]*V
table = [['0']*V for _ in range(V)]

for _ in range(V):
    # split 只能用于string
    # map returns a map object
    temp = list(map(int,input().split()))
    if len(temp) >= 2:
        for nei in temp[2:]:
            # print(temp[0]-1,nei-1)
            table[temp[0]-1][nei-1]='1'

for line in table:
    # join 也只能用于string
    print (" ".join(line))



Measured memory_bytes: 5668
//---------- Begin IO utilities ----------
// Thanks to https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:tt : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! p {
    ($v:ident) => {
        println!("{}", $v);
    };
    ($v:ident, $($t:ident),*) => {
        print!("{}", $v);
        ($(print!(" {}", $t)),*);
        println!();
    }
}
#[allow(unused_macros)]
macro_rules! ps {
    ($v:ident) => {
        println!("{}", $v.iter().collect::<String>());
    };
    ($v:ident, $($t:ident),*) => {
        print!("{}", $v.iter().collect::<String>());
        ($(print!(" {}", $t.iter().collect::<String>())),*);
        println!();
    }
}
#[allow(dead_code)]
fn pv<T: std::string::ToString>(v: &[T], sep: &str) {
    let s = v.iter().map(|e| e.to_string()).collect::<Vec<String>>().join(sep);
    println!("{}", s);
}
#[allow(dead_code)]
fn pvs(v: &[Vec<char>], sep:&str) {
    let s = v.iter().map(|e| e.iter().collect::<String>()).collect::<Vec<String>>().join(sep);
    println!("{}", s);
}
//---------- End IO utilities ----------

fn main() {
    input!{
        s: u32,
        w: u32,
    }
    if s <= w {
        println!("unsafe");
    } else {
        println!("safe");
    }
}


Measured memory_bytes: 2104
#include <cstdio>
#include <iostream>

using namespace std;

int n , m , mod;

const int N = 305;

int f[N][N][N];

#define add(x , y) x = (x + y >= mod ? x + y - mod : x + y)

int main() {
	cin >> n >> m >> mod;
	f[0][1][0] = 1;
	for (int i = 0; i <= n; i++)
		for (int j = 1; j <= m; j++)
			for (int k = i; k >= 0; k--) {
				if (k) 
					add(f[i][j][k - 1] , f[i][j][k]);
				else 
					add(f[i][j + 1][i] , f[i][j][k]);
				add(f[i + 1][j][k] , 1ll * f[i][j][k] * (k + 1) % mod);
	}
	cout << f[n][m][0];
	return 0;
}

Measured memory_bytes: 110848
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var w = int.Parse(line[0]);
        var h = int.Parse(line[1]);
        Console.WriteLine(getAns(w, h) ? "yes" : "no");
    }
    static bool checkRev(string[] a, int w)
    {
        for (int i = 0; i < w; i++)
            if (a[0][i] == a[1][i]) return false;
        return true;
    }
    static bool getAns(int w, int h)
    {
        var hs = new HashSet<string>();
        for (int i = 0; i < h; i++)
        {
            var s = Console.ReadLine().Trim().Replace(" ", "");
            var c1 = w - s.Replace("1", "").Length;
            var c0 = w - c1;
            if (Abs(c1 - c0) > 1) return false;
            hs.Add(s);
            if (hs.Count() > 2) return false;
        }
        if (hs.Count() != 2) return false;
        var a2 = new string[2];
        var p = 0;
        foreach (var x in hs)
            a2[p++] = x;
        return checkRev(a2, w);
    }
}


Measured memory_bytes: 22508
use std::io;
use std::cmp;


fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();

    buf.split(' ')
        .map(|s| s.trim().parse().unwrap())
        .collect()
}


fn main() {

    let (n, k) = {
        let val = read::<isize>();
        (val[0], val[1])
    };

    /*
    let mut cnt = (n - k) * (n - k + 1) / 2;

    'outer: for i in (k * 2)..(n + 1) {
        'inner: for j in 1..i {
            if i % j >= k {
                cnt += 1;
            }
        }
    }
    */

    // after saw the editorial
    let mut cnt = 0;
    for b in 1..(n + 1) {
        let p = n / b;
        let q = n % b;
        cnt += p * cmp::max(0, b - k) + cmp::max(0, q - k + 1);

        if k == 0 { cnt -= 1; }
    }

    println!("{}", cnt);
}

Measured memory_bytes: 4352
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<cctype>
#include<string.h>
#include <stdlib.h>

#define PI 3.1415926
void swap(int* x, int* y) {
	int a = *x;
	int b = *y;
	*x = b;
	*y = a;
}
void dainyu(int X[], int Y[ ],int n,int m) {
	for (int i = n; i <= m; i++) {
		Y[i] = X[i];
	}
}
void Dscanf(int X[], int n, int m) {
	for (int i = n; i <= m;i++) {
		scanf("%d", &X[i]);
	}
}
void Dprintf(int X[], int n, int m) {
	for (int i = n; i <= m; i++) {
		printf("%d\n", X[i]);
	}
}
void reverse(int X[], int Y[],int n,int m) {
	for (int i = n; i <= m; i++) {
		Y[i] = X[n + m - i];
	}
}

int factorial(int n);
int sum(int n, int*);
int ave(int n, int*);
int min(int n, int*), min(int n, int m);
int max(int n, int*), max(int n, int m);

int main() {
	int N, M, A[4000], B[4000];
	scanf("%d %d", &N, &M);
	for (int i = 1; i <= M; i++) {
		scanf("%d %d", &A[i], &B[i]);
	}
	for (int i = 1; i <= M; i++) {
		if (B[i] == max(M, B)) {
			B[i] = N;
			break;
		}
	}
	int x = 0;
	for (int i = 1; i <= M; i++) {
		if (B[i] > N) {
			x -= N - B[i];
		}
	}
	printf("%d\n", x);

	return 0;
}

int factorial(int n) {
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else {
		return 1;
	}
}
int sum(int n, int *all) {
	int total = 0;
	for (int i = 0; i < n; ++i) {
		total += all[i];
	}
	return total;
}
int ave(int n, int *all) {
	int total = 0;
	for (int i = 0; i<n; ++i) {
		total += all[i];
	}
	return total / n;
}
int min(int n, int *all) {

	int min = all[1];
	for (int i = 2; i <= n; ++i) {
		if (min > all[i]) {
			min = all[i];
		}
	}
	return min;
}
int max(int n, int *all) {
	int max = all[1];
	for (int i = 2; i<=n; ++i) {
		if (max<all[i]) {
			max = all[i];
		}
	}
	return max;
}
int max(int n, int m) {
	if (n >= m) {
		return n;
	}
	else {
		return m;
	}
}
int min(int n, int m) {
	if (n >= m) {
		return m;
	}
	else {
		return n;
	}
}

Measured memory_bytes: 2764
n,m=map(int, input().split())
p=list(map(lambda x: int(x)-1, input().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf=UnionFind(n)
for _ in range(m):
    x,y=map(lambda x: int(x)-1, input().split())
    uf.union(x,y)

ans=0
for i in range(len(p)):
    if uf.is_same(i, p[i]):
        ans+=1
print(ans)


Measured memory_bytes: 20360
import bisect
# from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# 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, C, K = map(int, input().split())
    T = sorted([int(input()) for i in range(N)])

    TT = [i + K for i in T]

    cnt = 0
    i = 0
    temp = -1
    while True:
        i = bisect.bisect_right(T, TT[i])
        if i - temp > C:
            i = temp + C + 1
            temp += C
        cnt += 1
        temp=i-1
        if i >= N:
            break
    print(cnt)


resolve()

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

int main() {
  int n;
  cin>>n;
  bool t=true;
  long long a[n],k=1,big=1000000000000000000;
  for(int i=0;i<n;i++){
    long long l;
    cin>>l;
    a[i]=l;
  }
    sort(a,a+n);
  for(int i=0;i<n;i++){
    if(k!=0){
      if(big/k<a[i]){
      t=false;
      break;
    }
    }
    k*=a[i];
  }
  if(!t||k>big)cout<<-1<<endl;
  else cout<<k<<endl;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int h1 = input[0], m1 = input[1], h2 = input[2], m2 = input[3], k = input[4];
            Console.WriteLine((h2 - h1) * 60 + (m2 - m1) - k);
        }
    }
}

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

int main(){
	int i, j, n;
	cin >> n;
	
	for(i=0; i<=n/4; i++){
	   if( (n-i*4)%7==0 ){
	      cout << "Yes";
	      return 0;
	   } 
	}
	
	cout << "No";
	return 0;
}
  

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

int main() {
	int a,b,c;
	cin>>a>>b>>c;

	if (a>c) {
		cout << "NO" << endl;
	}
	else if (c-a<=b) {
		cout<<"YES"<<endl;
}
	
	else {
		cout<<"NO"<<endl;
	}
}

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
int people[100003] = {};

int main(){
  REP(i, 100003) people[i]++;

  int n;
  cin >> n;

  REP(i,n){
      int a, b;
      cin >> a >> b;

      FOR(j,a,(b+1)) people[j]++;
    }

    REPB(i, 100001){
        if(people[i] >= i){
            cout << (i - 1) << endl;
            return 0;
          }
      }
}


Measured memory_bytes: 3512
n = int(input())
p = [i for i in map(int,input().split())]
res = 0
for i in range(1,n-1):
  if p[i-1] < p[i] < p[i+1]: res+=1
  if p[i-1] > p[i] > p[i+1]: res+=1
print(res)

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

int main(){
    int n;
    int k;
    cin >> n >> k;
    set<int> d;
    for(int i=0; i<k; i++){
        int a;
        cin >> a;
        d.insert(a);
    }
    while(1){
        string s;
        s = to_string(n);
        bool ok=true;
        for(int i=0; i<s.size(); i++){
            if(d.count(s.at(i)-'0')) ok=false;
        }
        if(ok){
            cout << n << endl;
            return 0;
        }
        n++;
    }
}

Measured memory_bytes: 3644
N = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0

for i in range(N):
    S = list(input())
    if S[0] == 'M':
        m += 1
    elif S[0] == 'A':
        a += 1
    elif S[0] == 'R':
        r += 1
    elif S[0] == 'C':
        c += 1
    elif S[0] == 'H':
        h += 1

ans = m * a * (r + c + h) + m * r * (c + h) + m * c * h + a * r * (c + h) + a * c * h + r * c * h

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <iomanip>
#define EPS (1e-10)
using namespace std;
class Point{
public:
    double x,y;
    Point(double x=0, double y=0):x(x),y(y){}
    Point operator +(const Point &p){
        return Point(x+p.x,y+p.y);
    }
    Point operator -(const Point &p){
        return Point(x-p.x,y-p.y);
    }
    Point operator *(double k){
        return Point(k*x,k*y);
    }
    Point operator /(double k){
        return Point(x/k,y/k);
    }

    double norm(){
        return x*x+y*y;
    }
    double abs(){
        return sqrt(norm());
    }
};
typedef Point Vector;
double dot(const Vector &v1,const Vector &v2){
    return v1.x*v2.x+v1.y*v2.y;
}
double cross(const Vector &v1,const Vector &v2){
    return v1.x*v2.y-v1.y*v2.x;
}
bool isParallel(const Vector &v1,const Vector &v2){
    if(fabs(cross(v1,v2)-0.0)<EPS)return true;
    return false;
}
bool isOrthogonal(const Vector &v1,const Vector &v2){
    if(fabs(dot(v1,v2)-0.0)<EPS)return true;
    return false;
}
Point projection( Point &p, Point &p1, Point &p2){
    Vector a=p-p1;
    Vector b=p2-p1;
    double r=dot(a,b);
    double pro_abs=r/b.norm();
    Vector res=b*pro_abs;
    return Point(res.x+p1.x,res.y+p1.y);
}
Point reflection(Point &p, Point &p1, Point &p2){
    Point pro=projection(p,p1,p2);
    Vector v=pro-p;
    v=v*2;
    return Point(v.x+p.x,v.y+p.y);
}
int main()
{
//    int q,p0x,p0y,p1x,p1y,p2x,p2y,p3x,p3y;
//    cin>>q;
//    while(q>0){
//        cin>>p0x>>p0y>>p1x>>p1y>>p2x>>p2y>>p3x>>p3y;
//        Point P0(p0x,p0y);
//        Point P1(p1x,p1y);
//        Point P2(p2x,p2y);
//        Point P3(p3x,p3y);
//        Vector v1=P1-P0;
//        Vector v2=P3-P2;
//        //cout<<'('<<v1.x<<','<<v1.y<<')'<<' ';
//        //cout<<'('<<v2.x<<','<<v2.y<<')'<<' '<<endl;
//        if(isOrthogonal(v1,v2))cout<<1<<endl;
//        else if(isParallel(v1,v2))cout<<2<<endl;
//        else cout<<0<<endl;
//        q--;
//    }
    int p1x,p1y,p2x,p2y,q,x,y;
    cin>>p1x>>p1y>>p2x>>p2y;
    Point p1(p1x,p1y);
    Point p2(p2x,p2y);
    //Vector a=p2-p1;
    cin>>q;
    while(q>0){
        cin>>x>>y;
        Point p(x,y);
        //Vector b=p-p1;
        Point res=reflection(p,p1,p2);
        cout<<fixed<<setprecision(8)<<res.x<<' '<<res.y<<endl;
        //printf("%.8f %.8f\n",res.x,res.y);
        q--;
    }
    return 0;
}


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

int main(){
  int N, K[100], P[100], rem;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>K[i]>>P[i];
    rem = K[i] % P[i];
    if (rem){
      cout<<rem<<endl;
    }else{cout<<P[i]<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3096