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

using namespace std;
using ll = long long;

template<class T>
vector<T> subvector(vector<T> a, int l, int num) {
   vector<T> ret;
   for(int i = l; i < l + num && i < (int)a.size(); i++)ret.emplace_back(a[i]);
   return ret;
}

vector<vector<ll>> f(vector<ll> a) {
    int n = a.size();
    vector<vector<ll>> res(n + 1);
    for(int i = 0; i < (1<<n); i++) {
        ll sum = 0;
        int c = 0;
        for(int j = 0; j < n; j++) if(i & (1<<j))sum += a[j], c++;
        res[c].emplace_back(sum);
    }
    for(auto &i : res)sort(i.begin(), i.end());
    return res;
}


int main()
{
    int n, k; ll l, r;
    cin >> n >> k >> l >> r;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    int fn = n / 2, bn = n - (n / 2);
    vector<vector<ll>> fr, bc; // fr[i] := i個の集合
    fr = f(subvector(a, 0, fn));
    bc = f(subvector(a, fn, bn));


    ll sum = 0;
    for(int i = 0; i <= fn; i++) {
        if(k - i < 0 || (k - i) > bn)continue;
        for(ll j : fr[i]) {
            sum += upper_bound(bc[k - i].begin(), bc[k - i].end(), r - j) - lower_bound(bc[k - i].begin(), bc[k - i].end(), l - j);
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 23496
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}





int main(){
  ll ans = 1;
  ll K;
  cin >> K;
  vector<bool> seen(K,false); 
  ll mod = 7 % K;
  if (K % 2 == 0 || K % 5 == 0) {
	cout << -1 << endl;
    return 0;
  }
  while(1) {
	if(mod == 0) {
	  cout << ans << endl;
	  return 0;
	}
	else {
	  seen[mod] = true;
	  mod = mod*10 + 7;
	  mod %= K;
	  ans++;
	}
	// cout << mod << endl;
  }

  return 0;
}


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

int main(){
    int N,K;
    cin >> N >> K;
    int ans = 1;
    bool res = true;
    while(res){
        if(N/K > 0){
            N = N/K;
            ans++;
        }
        else{
            res = false;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int R,C;
string grid[10];

int main() {
    ios::sync_with_stdio(0);
    cin >> R >> C;
    for(int i = 0; i < R; ++i)
        cin >> grid[i];
    if(grid[0][0] != '#' || grid[R-1][C-1] != '#')
        grid[R-1][C-1] = 'X';
    int r=0,c=0;
    grid[0][0] = '.';
    while(r != R-1 || c != C-1) {
        if(r+1 < R && grid[r+1][c] == '#') {
            r+=1;
        } else if(c+1 < C && grid[r][c+1] == '#') {
            c+=1;
        } else {
            break;
        }
        grid[r][c] = '.';
    }
    for(int i = 0; i < R; ++i) {
        for(int j = 0; j < C; ++j) {
            if(grid[i][j] != '.') {
                cout << "Impossible\n";
                return 0;
            }
        }
    }
    cout << "Possible\n";
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())

sc=[list(map(int,input().split())) for _ in range(m)]

def main():
  for i in range(10**n):
    scstr = str(i)
    f = True
    if len(scstr) == n:
      for j in range(m):
        if scstr[sc[j][0]-1] != str(sc[j][1]):
          f = False
      if f:
        print(i)
        return
  print('-1')

main()

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	/**
	 * 引数で与えられた2つの数値を足し、計算後の桁数を出力する。
	 *
	 * @param args
	 *            利用しない
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {

		// 入力値を受け取る
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = null;
		while ((line = br.readLine()) != null) {

			// 引数を足した後の桁数を出力する
			String[] number = line.split(" ");
			System.out.println(String
					.valueOf(
							(Integer.parseInt(number[0]) + Integer
									.parseInt(number[1]))).length());

		}
	}
}

Measured memory_bytes: 17000
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] str = stdR.readLine().split(" ");
        int N = Integer.parseInt(str[0]);
        int M = Integer.parseInt(str[1]);
        
        int[] st = new int[M];
        int[] en = new int[M];
        for(int i = 0 ; i < M ; i++){
            str = stdR.readLine().split(" ");
            st[i] = Integer.parseInt(str[0]) - 1;
            en[i] = Integer.parseInt(str[1]) - 1;
        }
        
        int[] number = new int[N];
        int[] rank = new int[N];
        for(int i = 0 ; i < N ; i++){
            number[i] = i;
        }
        
        for(int i = 0 ; i < M ; i++){
            int a = numberuni(number, st[i]);
            int b = numberuni(number, en[i]);
            if(a == b)continue;
            if(rank[a] < rank[b]){
                number[a] = b;
            }else{
                number[b] = a;
                if(rank[a] == rank[b])rank[a]++;
            }
        }
        
        int count = 0;
        for(int i = 0 ; i < N ; i++){
            if(number[i] == i){
                count++;
            }
        }
        System.out.println(count);
    }
    
    public static int numberuni(int[] nums,int x){
        if(nums[x] == x){
            return x;
        }else{
            return numberuni(nums,nums[x]);
        }
    }
}


Measured memory_bytes: 47704
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>

using namespace std;
using P = pair<int64_t, int64_t>;
struct Edge {
    int64_t to, cost;
};

int64_t V = 100;
constexpr int MAX_V = 1000010;
constexpr int64_t INF = 100000000000000000;
vector<Edge> G[MAX_V];
int64_t d[MAX_V];

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); ++i){
            Edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(){
    int N, M, s, t;
    cin >> N >> M >> s >> t;
    --s, --t;
    V = N * 3;
    for(int i = 0; i < N; ++i) d[i] = INF;

    for(int i = 0; i < M; ++i){
        int a, b, c, cost;
        cin >> a >> b >> c >> cost;
        --a, --b, --c;
        G[a].push_back(Edge{b, cost});
        G[b].push_back(Edge{a, cost});
        G[a].push_back(Edge{c, cost});
        G[c].push_back(Edge{a, cost});
        G[b].push_back(Edge{c, cost});
        G[c].push_back(Edge{b, cost});
    }

    dijkstra(s);/*
    for(int i = 0; i < N; ++i){
        cout << d[i] << " ";
    }
    cout << endl;*/
    cout << d[t] << endl;
}


Measured memory_bytes: 46116
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}
int main()
{
    int R, G;
    cin >> R;
    cin >> G;

    cout << 2 * G - R << endl;

}

Measured memory_bytes: 256
N,W = map(int,input().split())
wv = []
for i in range(N):
    wv.append(list(map(int,input().split())))

dp = [[ 0 for i in range(W+1)] for j in range(N+2)]

for i in range(N):
    for w in range(1,W+1):
        if w - wv[i][0] >= 0:
            dp[i+1][w] = max(dp[i][w] , dp[i][w - wv[i][0]] + wv[i][1])
        else:
            dp[i+1][w] = dp[i][w]
print(dp[N][W])


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

int main(){
int i=1;
    while(1){
        int a,b,m;
        cin>>a>>b;
        if(a==0 && b==0) break;
        if(a>b)cout<<b<<" "<<a<<endl;
        else cout<<a<<" "<<b<<endl;
    }
    return 0;
}


Measured memory_bytes: 3092
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 20 16:07:45 2019

@author: Yamazaki Kenichi
"""

x = int(input())

ans=0

ans += 2*(x//11)
if x%11 == 0:
    ans +=0
else:
    ans += 2 if x%11 >6 else 1

print (ans)

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

int main() {
  int h, a, ans;
  cin >> h >> a;
  ans = h/a ;
  if (h%a != 0 ) {
    ans++;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
#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(v) v.begin(), v.end()


int main(){
    int S, W;
    cin >> S >> W;
    if(S > W){
        cout << "safe" << endl;
    } else {
        cout << "unsafe" << endl;
    }
}

Measured memory_bytes: 3572
/*ॐॐ*/
/* I have already deleted My old account because somebody stole my code
and i have no idea how. If you are copying this code atleast make it look different.
Change variable names or change some Data structres or anything just make sure MOSS do not
Detect Anything.
Yours Faithfully
Shobhit Yadav */

/* I do not fear this new challenge. Rather like a true warrior I will rise to meet it. 
                                       -Prince Vegeta  */

 /* “Strength is the only thing that matters in this world. Everything else is just a delusion for the weak.” – Vegeta */

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

ll M,N;
/*ll freq[200005];*/
void solve(){
	 /*memset(freq,0,sizeof(freq));*/
  cin>>N;
  ll K = N/1000;
  
  if(N%1000 !=0){
   K = floor(K) +1;
    cout<<K*1000 - N<<'\n';}
    
    else
    cout<<0<<'\n';   
   
 


}



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

	return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int Len[10],a[10];
bool vis[10];
int n,m;
long long ans;
int Min(int x,int y){
	return x<y?x:y;
}
void solve(){
	static int dp[310][1<<5][310];
	memset(dp,0,sizeof(dp));
	dp[0][0][0]=1;
	for(int i=1;i<=(n+1)*m;i++){
		for(int j=0;j<(1<<n);j++)
			for(int k=0;k<=i;k++){
				dp[i][j][k]+=dp[i-1][j][k];
				if(i%(n+1)&&!(j&(1<<(i%(n+1)-1))))
					dp[i][j|(1<<(i%(n+1)-1))][Min((n+1)*m,k<i-a[i%(n+1)-1]*(n+1)+1?k:i)]+=dp[i-1][j][k];
			}
	}
	int st=0;
	for(int i=(n+1)*m-Len[n]*(n+1)+1;i<=(n+1)*m;i++){
		ans=ans+dp[(n+1)*m][(1<<n)-1][i];
		st+=dp[(n+1)*m][(1<<n)-1][i];
	}
}
void dfs(int p){
	if(p>n){
		solve();
		return;
	}
	for(int i=0;i<n;i++){
		if(!vis[i]){
			vis[i]=1;
			a[p-1]=Len[i];
			dfs(p+1);
			vis[i]=0;
		}
	}
}
int main(){
//	freopen("F.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
		scanf("%d",&Len[i]);
	sort(Len,Len+n);
	n--;
	dfs(1);
	long long cnt=1;
	for(int i=1;i<=n;i++)
		cnt=cnt*m;
	for(int i=1;i<=n;i++)
		cnt=cnt*i;
	printf("%.14f\n",ans/(double)cnt);
	return 0;
}


Measured memory_bytes: 12416
// #include<iostream>
// #include<vector>
// #include<algorithm>
// #include<map>
// #include<cstring>
// #include<math.h>
// #include<bitset>
// #include<queue>
// #include<set>
// #include<iomanip>
// #include<math.h>
// #include<assert.h>
// #include<string>
// #include<cstdlib>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int INF = 1LL << 31;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}
// ----------------------------------------------------------------------------

int main(){
  int L;
  cin >> L;
  int N=0;
  while(1<<N <= L) N++;

  vector<vector<int>> ans;
  for(int i=1; i<N; i++){
    ans.push_back({i,i+1,1<<(i-1)});
    ans.push_back({i,i+1,0});
  }
  int now = (1<<(N-1))-1;
  for(int i=N-1; i>=1; i--){
    if(now == L-1) break;

    int gain = 1<<(i-1);
    if(now + gain + 1 <= L){
      ans.push_back({i,N,now+1});
      now += gain;
    }
  }
  int M = ans.size();
  cout << N << " " << M << endl;
  for(auto v: ans){
    cout << v[0] << " " << v[1] << " " << v[2] << 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;
using P = pair<int, int>;

int main() {
    int a, b;
    cin >> a >> b;
    if ((a%2 == 1) && (b%2 == 1)) cout << "Odd" << endl;
    else cout << "Even" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>

using namespace std;

#define ll long long

int n,k;

int main(){
	cin >> n >> k;
	cout << n-k+1 << endl;
}

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

int main() {
  int a,b,c;
  cin >>a >>b>>c;
  if((a+b==c)||(a+c==b)||(c+b==a)){
    cout <<"Yes"<<endl;
  }
  else{
    cout <<"No"<<endl;
  }
      
}


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

static long long Fac[300010], MOD = 998244353;

void FacInit(int n) {
	Fac[0] = 1;
	for (int i = 1; i <= n; i++) {
		Fac[i] = Fac[i - 1] * i;
		Fac[i] = Fac[i] % MOD;
	}
}

long long Calc(long long a, long long b) {
	if (b == 0) return 1;
	if (b % 2 == 0) {
		long long c = Calc(a, b / 2);
		return (c * c) % MOD;
	}
	return (a * Calc(a, b - 1)) % MOD;
}

int main() {
	long long N, A, B, K, ans = 0;
	cin >> N >> A >> B >> K;
	FacInit(N);
	for (long long a = 0; a <= N; a++) {
		if (K - A * a < 0) break;
		if ((K - A * a) % B != 0) continue;
		long long b = (K - A * a) / B;
		if (b > N) continue;
		long long nCa = 1, nCb = 1;
		nCa *= Calc(Fac[a], MOD - 2); nCa = nCa % MOD;
		nCa *= Calc(Fac[N - a], MOD - 2); nCa = nCa % MOD;
		nCa *= Fac[N]; nCa = nCa % MOD;
		nCb *= Calc(Fac[b], MOD - 2); nCb = nCb % MOD;
		nCb *= Calc(Fac[N - b], MOD - 2); nCb = nCb % MOD;
		nCb *= Fac[N]; nCb = nCb % MOD;
		ans += (nCa * nCb) % MOD;
		ans = ans % MOD;
	}
	cout << ans;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> price(N);
  int answer =0;
  for (int i=0; i<N; i++){
    cin >> price.at(i);
  }
  sort (price.begin(),price.end());
  for (int i=0; i<K; i++){
    answer += price.at(i);
  }
  cout << answer << endl;
}


Measured memory_bytes: 3604
S = input()
ans = 0
tmp2 = 0
for i in range(0,len(S)):
  tmp = S[i]
  if(tmp == "A" or tmp == "G" or tmp == "C" or tmp == "T"):
    ans += 1
  else:
    ans = 0
  tmp2 = max(ans,tmp2)
print(str(tmp2))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if ( a == b && b == c && c == d){
    cout << "No" << endl;
  }
  
  else if( a == b && c == d ){
    cout << "Yes" << endl;
  }
  else if( a == c && b == d ){
    cout << "Yes" << endl;
  }
  else if( a == d && b == c ){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int A[2][N];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A[i][j];
    }
  }
  int dp[2][N];
  dp[0][0] = A[0][0];
  dp[1][0] = A[0][0] + A[1][0];
  for (int i = 1; i < N; i++) {
    dp[0][i] = dp[0][i - 1] + A[0][i];
    dp[1][i] = dp[1][i - 1] + A[1][i];
  }
  for (int i = 1; i < N; i++) {
    dp[1][i] = max(dp[1][i - 1], dp[0][i]) + A[1][i];
  }
  cout << dp[1][N - 1];
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 520
#define maxm 20020
#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define inf 0x3f3f3f3f
typedef long long ll;
typedef pair<int,int> pr;

int prime[maxm],cnt,tag[maxm];
int n,tag1[maxn][maxn],tag2[maxn][maxn],tot;
ll a[maxn][maxn];
map <ll,int> num;
vector <pr> vec;
ll tmp = 1e15;

void init(){
	rep(i,2,10000){
		if ( !tag[i] ) prime[++cnt] = i;
		rep(j,1,cnt){
			if ( prime[j] * i > 10000 ) break;
			tag[prime[j] * i] = 1;
			if ( i % prime[j] == 0 ) break;
		}
	}
}
ll gcd(ll a,ll b){
	if ( !b ) return a;
	return gcd(b,a % b);
}
inline ll lcm(ll a,ll b){
	ll d = gcd(a,b);
	return a / d * b;
}
bool check(int x,int y){
	if ( x > 1 && max(a[x][y],a[x - 1][y]) % min(a[x][y],a[x - 1][y]) != 1 ) return 0;

	if ( y > 1 && max(a[x][y],a[x][y - 1]) % min(a[x][y],a[x][y - 1]) != 1 ) return 0;
	return 1;	
}
int main(){
	init();
	scanf("%d",&n);
		
	if ( n == 2 ){
		printf("4 7\n23 10\n");
		return 0;
	}
	rep(i,1,n){
		rep(j,1,n){
			if ( ((i + j) & 1 ) ){
				if ( i > 1 && j > 1 && tag1[i - 1][j - 1] ) tag1[i][j] = tag1[i - 1][j - 1];
				if ( i < n && j < n && tag1[i + 1][j + 1] ) tag1[i][j] = tag1[i + 1][j + 1];
				if ( !tag1[i][j] ) tag1[i][j] = ++tot; 
			
			}
		}
	}
	rep(i,1,n){
		rep(j,1,n){
			if ( ((i + j) & 1 ) ){
				if ( i > 1 && j < n && tag2[i - 1][j + 1] ) tag2[i][j] = tag2[i - 1][j + 1];
				if ( i < n && j > 1 && tag2[i + 1][j - 1] ) tag2[i][j] = tag2[i + 1][j - 1];
				if ( !tag2[i][j] ) tag2[i][j] = ++tot;
			}
		}
	}
	rep(i,1,n){
		rep(j,1,n){
			if ( ((i + j) & 1) ){
				a[i][j] = prime[tag1[i][j]] * prime[tag2[i][j]];
			}
		}
	}
	rep(i,1,n){
		rep(j,1,n){
			if ( !a[i][j] ){
				ll cur = 1;
				if ( i > 1 ) cur = lcm(cur,a[i - 1][j]);
				if ( i < n ) cur = lcm(cur,a[i + 1][j]);
				if ( j > 1 ) cur = lcm(cur,a[i][j - 1]);
				if ( j < n ) cur = lcm(cur,a[i][j + 1]);
				a[i][j] = cur + 1;
			}
		}
	}
	rep(i,1,n){
		rep(j,1,n){
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
}


Measured memory_bytes: 7296
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class C { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long K = GetLong();
		long r = 0;
		for(long i = 0; i < K; i++)
		{
			r = ((r * 10) + 7) % K;
			if(r == 0)
			{
				WriteLine(i + 1);
				return;
			}
		}
		WriteLine(-1);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


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

bool check(vector<int>& s){
	int crt = 0;
	bool res = true;
	for(int i = 0;i < s.size();++i){
		if(s[i] > crt) crt = s[i];
		else{
			res = false;
			break;
		}
	}
	return res;
}

int main(){
	int n;cin >> n;
	cin.get();
	while(n--){
		vector<int> nums(10);
		for(int i = 0;i < 10;++i) cin >> nums[i];
		int size = 10;
		bool res = false;
		for(int i = 0;i < (1<<size);++i){
			vector<int> num1,num2;
			for(int j = 0;j < size;++j){
				if((i>>j)&1) num1.push_back(nums[j]);
				else num2.push_back(nums[j]);
			}
			if(check(num1) && check(num2)){
				res = true;
				break;
			}
		}
		if(res) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


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

int main(){
  string s; cin>>s;
  int n=s.size();

  int ans=0;
  for(int i=0; i<n/2; ++i){
    if(s[i]!=s[n-1-i])++ans;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
int uf[(int)1e5+1];
int p[(int)1e5+1];
vector<int>edge[(int)1e5+1];
vector<int>cc[(int)1e5+1];
vector<int>dc[(int)1e5+1];
bool vst[(int)1e5+1];
void dfs(int k,int id){
    cc[id].push_back(k);
    dc[id].push_back(p[k]);
    vst[k]=true;
    int l=edge[k].size();
    for(int i=0;i<l;i++){
        if(!vst[edge[k][i]])dfs(edge[k][i],id);
    }
}
int main(){
    int n;
    scanf("%d",&n);
    int m;
    scanf("%d",&m);
    for(int i=0;i<n;i++){
        scanf("%d",&p[i]);
        p[i]--;
    }
    int x,y;
    for(int i=0;i<m;i++){
        scanf("%d%d",&x,&y);
        x--;
        y--;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    int id=0;
    for(int i=0;i<n;i++){
        if(!vst[i]){
            dfs(i,id);
            id++;
        }
    }
    int ans=0;
    for(int i=0;i<id;i++){
        sort(cc[i].begin(),cc[i].end());
        sort(dc[i].begin(),dc[i].end());
        int l=cc[i].size();
        int j1=0,j2=0;
        while(j1<l&&j2<l){
            if(cc[i][j1]>dc[i][j2]){
                j2++;
                continue;
            }
            else if(cc[i][j1]<dc[i][j2]){
                j1++;
                continue;
            }
            else{
                ans++;
                j2++;
                j1++;
            }
        }
    }
    printf("%d\n",ans);
}

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

int main() {
  string c ;
  bool check = false ;
  cin >> c ;
  for ( int i = 0 ; i < c.size() ; i++ ){
    if (c.at(i)!='a' && c.at(i)!='i' && c.at(i)!='u' && c.at(i)!='e' && c.at(i)!='o' ){
      check = true ;
      break;
    }
  }
  if (check)
    cout << "consonant" << endl;
  else
    cout << "vowel" << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int h, w;
    cin >> h >> w;
    auto dp = make_v(h, w, 0);
    int sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    sx--; sy--; gx--; gy--;
    for (int i = 0; i < h; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < w; ++j) {
            dp[i][j] = (s[j] == '.');
        }
    }

    auto visited = make_v(h, w, INF<int>);
    visited[sx][sy] = 0;
    deque<pair<int, int>> Q;
    Q.emplace_front(sx, sy);
    array<int, 4> dy{-1, 1, 0, 0}, dx{0, 0, -1, 1};
    auto in = [&](int x, int y){
        return 0 <= x && x < h && 0 <= y && y < w;
    };
    while(!Q.empty()){
        int x, y; tie(x, y) = Q.front(); Q.pop_front();
        for (int i = 0; i < 4; ++i) {
            if(in(x+dx[i], y+dy[i]) && dp[x+dx[i]][y+dy[i]] && visited[x+dx[i]][y+dy[i]] > visited[x][y]){
                Q.emplace_front(x+dx[i], y+dy[i]);
                visited[x+dx[i]][y+dy[i]] = visited[x][y];
            }
        }
        for (int yy = -2; yy <= 2; ++yy) {
            for (int xx = -2; xx <= 2; ++xx) {
                if(in(x+xx, y+yy) && dp[x+xx][y+yy] && visited[x+xx][y+yy] > visited[x][y]+1){
                    Q.emplace_back(x+xx, y+yy);
                    visited[x+xx][y+yy] = visited[x][y]+1;
                }
            }
        }
    }
    if(visited[gx][gy] == INF<int>){
        puts("-1");
    }else {
        cout << visited[gx][gy] << "\n";
    }
    return 0;
}

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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)

struct node{
  string name;
  int ide;
  struct node *par;
  struct vector<node*>child; 
};
node root;

vector<string> split(string s, char c)
{
  vector<string>ret;
  int i=0;
  for(;i<s.size();i++){
    for(int j=i;j<s.size();j++){
      if(s[j] == c){
	if(i!=j){
	  ret.push_back(s.substr(i,j-i));
	  i = j;
	}
	break;
      }
      if(j == s.size()-1){
	ret.push_back(s.substr(i));
	i = j;
      }
    }
  }
  return ret;
}

string default_file = "index.html";
string par_dir = "..";
string cur_dir = ".";
string root_dir = "/";

int search(string s)
{
  vector<string>V = split(s, '/');
  node *n = &root;
  if(s.size() == 1){
    for(auto c: n->child)
      if(c->name == default_file && c->child.size() == 0)
	return c->ide;
    return -1;
  }
  for(auto v: V){
    if(n->child.size() == 0) return -1;
    if(v == par_dir){
      if(n->par != (node*)-1) n = n->par;
      else return -1;
      continue;
    }
    if(v == cur_dir) continue;
    int flag = 0;
    for(auto c: n->child){
      if(c->name == v){
	flag = 1;
	n = c;
	break;
      }
    }
    if(!flag) return -1;
  }
  if(s[s.size()-1] == '/' && n->child.size() == 0) return -1;
  if(n->child.size()){
    int flag= 0;
    for(auto c: n->child)
      if(c->name == default_file){
	n = c;
	flag = 1;
	break;
      }
    if(!flag) return -1;
  }
  
  return n->ide;
}

int main()
{
  int N, M;
  while(1){
    cin >> N >> M;
    if(N == 0 && M == 0) return 0;
    int idecnt = 0;

    root.ide = idecnt;
    root.par = (node*)-1;
    root.name = "/";
    root.child.clear();

    rep(i, N){
      string s; cin >> s;
      vector<string>V = split(s, '/');
      node *n = &root;
      for(auto v: V){
	int flag = 0;
	rep(i, n->child.size()){
	  if(n->child[i]->name == v){
	    n = n->child[i];
	    flag = 1;
	    break;
	  }
	}
	if(!flag){
	  node *nn = new node;
	  nn->name = v;
	  nn->par = n;
	  nn->ide = ++idecnt;
	  n->child.push_back(nn);
	  n = nn;
	}
      }
    }

    rep(i, M){
      string s; cin >> s;
      int id1 = search(s);
      cin >> s;
      int id2 = search(s);
      if(id1 == -1 || id2 == -1) cout << "not found\n";
      else if(id1 == id2) cout << "yes\n";
      else cout << "no\n";
    }
  }
  return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	cout << n*n*n << endl;

}



Measured memory_bytes: 256
n, m = map(int, input().split())

def readlines():
    for _ in range(m):
        s, c = map(int, input().split())
        yield s, c

sc = list(readlines())

def check(x):
    for s, c in sc:
        if len(x) < s:
            yield False
        else:
            yield x[s-1] == str(c)

if n == 1:
    r = range(10)
elif n == 2:
    r = range(10, 100)
else:
    r = range(100, 1000)

for i in r:
    x = str(i)
    if all(check(x)):
        print(x)
        exit()

print(-1)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> v(n);
    for(auto& i : v){
        cin >> i;
    }

    vector<ll> cost(n, 0);
    for(int i=1; i<n; i++){
        cost[i] = INF;
        for(int j=1; j<=k; j++){
            if(i - j < 0){
                continue;
            }
            cost[i] = min(cost[i], cost[i-j] + abs(v[i] - v[i-j]));
        }
    }
    
    cout << cost[n-1] << endl;
    
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    int a, b;
    cin >> a;
    cin >> b;
    if (a > b) {
        cout << "a > b" << endl;
    } else if(a < b) {
        cout << "a < b" << endl;
    } else {
        cout << "a == b" << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3096
//集めるDP

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

int dp[110000];


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

	dp[0] = 0;

	for (int n = 1; n <= N; n++) {
		for (int i = 1; i <= n; i*=6) {
			dp[n] = min(dp[n], dp[n-i] + 1);
		}
		for (int j = 1; j <= n; j *= 9) {
			dp[n] = min(dp[n], dp[n-j] + 1);
		}
	}

	cout << dp[N] << endl;

	return 0;
}

Measured memory_bytes: 640
def combination(n, k):
    ret = 1
    for i in range(k):
        ret *= (n - i)
    for i in reversed(range(2, k + 1)):
        ret //= i
    return ret


N, K = map(int, input().split())
r = N - K
MOD = 10**9 + 7
for i in range(1, K + 1):
    if i > r + 1:
        print(0)
        continue
    blue = combination(K - 1, i - 1) % MOD
    red = combination(r + 1, i) % MOD
    print((blue * red) % MOD)

Measured memory_bytes: 3316
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

string w;
int cnt[256];

int main(int argc, char **argv) {
	CLEAR(cnt);
	cin >> w;
	REP(i, w.length()) ++cnt[w[i]];
	REP(i, 256) if (cnt[i] % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int A,B;
	cin >>A >>B;
	
	int ct = 0;
	int pg = 1;
	if(B==1) ct = 0;
	else {
		while(B>pg) {
			pg = pg+A-1;
			ct += 1;
		}
	}
	
	cout << ct << endl;
    return 0;
}


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

char s[100005];
int n, sum[100005], idx;

int main() {
	cin >> (s+1);
	for (n = 1; s[n] != '\0'; ++n);
	int ansl=-1, ansr=-1;
	sum[0] = 0;
	for (char ch = 'a'; ch <= 'z'; ++ch) {
		idx = 0;
		if (ch == s[1]) sum[1] = 1;
		else sum[1] = 0;
		for (int i = 2; i <= n; ++i) {
			if (ch == s[i]) sum[i] = sum[i-1] + 1;
			else sum[i] = sum[i-1];
			if (2*sum[i]-i > 2*sum[idx]-idx) {
				ansl = idx+1;
				ansr = i;
				break;
			}
			if (2*sum[i-1]-i+1 < 2*sum[idx]-idx) idx = i-1;
		}
		if (ansl > -1) break;
	}
	cout << ansl << " " << ansr << endl;
	return 0;
}

Measured memory_bytes: 768
# https://atcoder.jp/contests/abc118/tasks/abc118_d


def main():
    N, M = map(int, input().split())

    A = list(map(int, input().split()))  # 使っていい数字

    costs = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]  # 各数字のマッチの数

    dp = [-1 for _ in range(N + 1)]
    dp[0] = 0
    for i in range(1, N + 1):
        for a in A:
            if i < costs[a]:
                continue
            dp[i] = max(dp[i], dp[i - costs[a]] * 10 + a)
    print(dp[N])


main()


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

ll l1[10];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x=0,s2=0,k;
    cin>>n>>k;
    ll l1[n+1];
    map<ll,ll>m;
    map<ll,ll>m2;
    vector<ll>v;
    vector<ll>v2;
    set<ll>s;
    for(int i=1;i<=n;i++){
        cin>>x;m2[x]++;
        if(m[x]==0){
            m[x]=1;
            v.push_back(x);
        }
        s.insert(x);
    }
    if(k>=s.size())cout<<0<<endl;
    else{
        for(int i=0;i<v.size();i++){
            v2.push_back(m2[v[i]]);
        }
        sort(v2.begin(),v2.end());
        for(int i=0;i<s.size()-k;i++){
            s2+=v2[i];
        }
        cout<<s2<<endl;
    }
}


Measured memory_bytes: 42188
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
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;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 

vll dp(100100);

ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll a,b;	
  ci(a>>b);
  for(int i=b-a+1;i<=b+a-1;i++){
    cout<<i<<" ";
  }
  cout<<" "<<endl;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B == C + D){
    cout << "Balanced" << endl;
  }
  else if (A + B < C + D){
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    char x[1003];
    int sum,i;

    while(1){
        scanf("%s",x);
        if(x[0] ==  '0' && x[1] == '\0')
            break;
        sum = 0;i = 0;
        while(x[i] != '\0')
            sum += x[i++] - '0';
        printf("%d\n",sum);
    }
    return 0;
}



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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> mii;
typedef map<ll,int> mli;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;  ///1e9+7

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=2;ii<=mx;ii++)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///


ll n,a[100005],dp[100005],k;
ll rec(ll m)
{
    if(m>=n-1) return 0;
    if(dp[m]!=-1) return dp[m];
    ll opt1=INT_MAX;
    for(ll j=1;j<=k;j++){
        if(m+j<n) opt1=min(opt1,abs(a[m]-a[m+j])+rec(m+j));
        else break;
    }
    dp[m]=opt1;
    return dp[m];
}

main()
{
    fastio();
    cin>>n>>k;
    mem(dp,-1);
    ll i;
    forn(i,n) cin>>a[i];
    cout<<rec(0) el;
}





///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 11388
A,B,C,D;main(i){i=8;scanf("%1d%1d%1d%1d",&A,&B,&C,&D);while(i--)if(A+(i/4%2?-B:B)+(i/2%2?-C:C)+(i%2?-D:D)==7){char p[]={'+','-'};printf("%d%c%d%c%d%c%d=7\n",A,p[i/4%2],B,p[i/2%2],C,p[i%2],D);break;}}

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int cnt = 0;
  bool flag_a = true;
  int first, last;
  for (int i = 0; i < n; i++) {
    if (flag_a) {
      if (s.at(i) == 'A') {
        first = i;
        flag_a = false;
      }
    }
    if (s.at(i) == 'Z') {
      last = max(last, i);
    }
  }
  cout << last - first +1 << endl;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

bool canPut[100] = {false};

signed main() {
  int n = read(), ans = 0;
  REP(i, n) {
    int tmp = read();
    if (canPut[tmp] == false)
      ans++;
    canPut[tmp] = true;
  }
  print(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;


int main(){
    int n;
    cin >> n;
    int now = 1;
    int ans = 0;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        if(a==now){
            ans++;
            now++;
        }
    }
    if(ans == 0)
        cout << -1 << endl;
    else
        cout << n-ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define sort(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())

using namespace std;

int main() {
	string s;
	cin >> s;
	ff(i, 0, s.size()) {
		if (i % 2 == 0) {
			if (s[i] == 'L') {
				cout << "No" << endl;
				return 0;
			}
		}
		if (i % 2 == 1) {
			if (s[i] == 'R') {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import itertools as it

N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))

l=[n for n in range(1,N+1)]
for i,t in enumerate(it.permutations(l)):
    if t==P:
        a=i+1
    if t==Q:
        b=i+1
ans=abs(b-a)

print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int count( const string& str, bool isStartOne)
{
    char c = isStartOne ? '1' : '0';
    string mask = "";
    mask += c;
    for(int ii = 0; ii < str.size()-1; ++ii){
        if(c == '1'){
            c = '0';
        }
        else{
            c = '1';
        }
        mask += c;
    }
    
    int cnt = 0;
    for(int ii = 0; ii < str.size(); ++ii){
        if(str[ii] != mask[ii]){
            ++cnt;
        }
    }
    
    return cnt;
}

int main()
{
    string str;
    cin >> str;
    
    int min = 100001;
    for(int ii = 0; ii < 2; ++ii){
        bool isStartOne = (ii==0) ? false : true;
        int val = count(str, isStartOne);
        if(val < min){
            min = val;
        }
    }
    
    cout << min << endl;
    
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

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

  if(A >= 13) printf("%d\n", B);
  else if(A <= 12 && A >= 6) printf("%d\n", B / 2);
  else printf("%d\n", 0);
  
  return 0;
}


Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
wa_x = 0
x = 0
for i in range(n-1):
    if a[i]+x>=a[i+1]:
        x = a[i]+x-a[i+1]
    else: x=0
    wa_x += x
print(wa_x)

Measured memory_bytes: 32192
#include<stdio.h>

int main()
{
  int N,A,B,a[100],i,j,k,b[100],X;
 
  scanf("%d",&N);

  for(i=0;i<100;i++)
  {
    a[i]=0;
    b[i]=0;    
  }
  
  for(i=0;i<N;i++)
  {
    scanf("%d",&a[i]);
  }
  
  for(i=0;i<N;i++)
  {
    X=a[i];
    for(j=i+1;j<N;j++)
    {
      if(X==a[j])
      {
        a[j]=0;
      }
      
    }
  }
  
  X=0;
  
  for(i=0;i<N;i++)
  {
    if(a[i]>0)
    {
      X++;
    }    
  }
  
  printf("%d",X);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
using P = pair<int,int>;

struct edge{int to,idx;};
vector<edge> G[100100];

vector<int> dijkstra(int s,vector<int>& cost){
    vector<int> dist(100100,1e18); dist[s] = 0;
    priority_queue<P,vector<P>,greater<P>> Q;
    Q.push({0,s});
    while(!Q.empty()){
        P p = Q.top(); Q.pop();
        if(dist[p.second] < p.first) continue;
        for(auto &e : G[p.second]){
            if(dist[e.to] > dist[p.second] + cost[e.idx]){
                dist[e.to] = dist[p.second] + cost[e.idx];
                Q.push({dist[e.to],e.to});
            }
        }
    }
    return dist;
}

signed main(){
    int N,M,S,T;
    cin>>N>>M>>S>>T;
    vector<int> A(M),B(M);
    for(int i=0;i<M;++i){
        int u,v; cin>>u>>v>>A[i]>>B[i];
        G[u].push_back({v,i});
        G[v].push_back({u,i});
    }

    auto yen = dijkstra(S,A);
    auto snuuk = dijkstra(T,B);

    int ans = 0;
    vector<int> res;

    for(int i=N;i>0;--i){
        ans = max(ans,(int)1e15-yen[i]-snuuk[i]);
        res.push_back(ans);
    }

    for(int i=N-1;i>=0;--i) cout<<res[i]<<endl;
}

Measured memory_bytes: 14200