akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = numeric_limits<ll>::max()/3;

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


bool solve(){
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  if(b > d || a < b || c < (a % b)){
    return false;
  }
  if(b == d || c >= b){
    return true;
  }
  ll diff = d - b;
  ll g = gcd(b,diff);
  ll a0 = a % b;
  ll largest = a0 + (b - a0 - 1) / g * g;
  return largest <= c;
}

int main(void){
  int t;
  cin >> t;
  for(int i = 0;i < t;++i){
    cout << (solve() ? "Yes" : "No") << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
while(1){
  string s{};int y,m,d;
  cin>>s;
  if(s=="#")return 0;
  cin>>y>>m>>d;
  if(y>31){
	  cout<<'?'<<" ";
	  y-=30;
  }
  else if(y==31){
	  if(m>=5){
		  cout<<'?'<<" ";
		  y-=30;
	  }
	  else cout<<s<<" ";
  }
  else cout<<s<<" ";
  cout<<y<<" "<<m<<" "<<d<<endl;
}
}



Measured memory_bytes: 3216
#include<iostream>
using namespace std;
#define MAX 10000

void countingSort(int A[], int B[], int n){
  int C[MAX];

  for ( int i = 0; i <= MAX; i++) C[i] = 0;
  // A[i]の個数をCのA[i]番目に記録
  for ( int i = 0; i < n; i++){
    C[A[i]]++;
  }

  // A[i]以下の数の個数をCのA[i]番目に記録
  for ( int i = 0; i <= MAX; i++){
    C[i+1] += C[i];
  }

  for ( int i = n-1; i >= 0; i--){
    // C[i]=0になることがないので、B[0]は空になる
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }
}

int main(){
  int n;
  cin >> n;
  int A[n+1], B[n+1];
  for ( int i = 0; i < n; i++){
    cin >> A[i];
  }

  countingSort(A, B, n);

  for ( int i = 1; i <= n; i++){
    if( i-1 ) cout << " ";
    cout << B[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 18748
#include <iostream>
#include <string>

using namespace std;

#define ll long long

int main()
{
	string s;
	ll k;
	cin >> s >> k;
	int n = s.length();
	int i = 0;
	while (i < n && s[i] == '1')
	{
		i++;
	}

	if (i >= k || i == n)
	{
		cout << 1 << endl;
	}
	else
	{
		cout << s[i] << endl;
	}
}

Measured memory_bytes: 256
while n = gets.split.map(&:to_i)
  break if n.all?{ |v| v == 0 }
  m = Array.new
  3.times { |i| m << n[i]+n[i+3] }
  ret = 0
  3.times do |i|
    break if m.any?{ |v| v - i < 0 }
    ret = [ret, m.reduce(0){ |sum, v| sum += (v - i) / 3 } + i].max
  end
  p ret
end

Measured memory_bytes: 8932
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
#define bool    _Bool
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }



int main() {
	int A, B;
	scanf("%d%d", &A, &B);
	int f[1000];
	int i;
	int x = 0;
	int ans = 0;
	x = B - A;
	f[0] = 0;
	for (i = 1; i < x; i++) {
		f[i] = f[i-1] + i;
	}
	ans = f[i - 1] - A;
	printf("%d\n", ans);




#ifdef DEBUGF
	getch();
#endif
	return 0;
	}


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

class A
{
	static void Main()
	{
		var s = Console.ReadLine();

		long t = 0, r = 0;
		foreach (var g in s.GroupBySeq(x => x).Select(g => new { g.Key, c = g.LongCount() }))
			r += g.Key == '<' ? (t = g.c) * (t + 1) / 2 : Math.Max(0, g.c - t) + g.c * (g.c - 1) / 2;
		Console.WriteLine(r);
	}
}

static class GE
{
	public static IEnumerable<IGrouping<TK, TS>> GroupBySeq<TS, TK>(this IEnumerable<TS> source, Func<TS, TK> toKey)
	{
		var c = EqualityComparer<TK>.Default;
		var k = default(TK);
		var l = new List<TS>();

		foreach (var o in source)
		{
			var kt = toKey(o);
			if (!c.Equals(kt, k))
			{
				if (l.Count > 0) yield return new G<TK, TS>(k, l.ToArray());
				k = kt;
				l.Clear();
			}
			l.Add(o);
		}
		if (l.Count > 0) yield return new G<TK, TS>(k, l.ToArray());
	}

	class G<TK, TE> : IGrouping<TK, TE>
	{
		public TK Key { get; }
		IEnumerable<TE> Values;
		public G(TK key, TE[] values) { Key = key; Values = values; }

		public IEnumerator<TE> GetEnumerator() => Values.GetEnumerator();
		IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
	}
}


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

int main() {
    int h, w;
    cin >> h >> w;
    string s;
    for (int i = 0; i < h; i++) {
        cin >> s;
        cout << s << '\n';
        cout << s << '\n';
    }
    cout << flush;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int i,j,n,M[101][101],u,k,v;
  scanf("%d",&n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      M[i][j] = 0;
    }
  }
  for (i = 0; i < n; i++) {
    scanf("%d%d",&u,&k);
    u--;
    for (j = 0; j < k; j++) {
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if( j ) printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (j > i + 1) cout << ' ';
			int b = 0;
			for (int k = 0; k < 15; ++k) {
				if (((i ^ j) >> k) & 1) b = k + 1;
			}
			cout << b;
		}
		cout << '\n';
	}
	return 0;
}

Measured memory_bytes: 512
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()] + [0]
ans = 0
j = 0
for i in range(n+1):
    ans += min(j + b[i], a[i])
    j = max(0, b[i] - max(0, a[i] - j))
print(ans)


Measured memory_bytes: 82788
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    pair<long long int,int> p[n];
    long long int ans=0;
    long long int a;
    int b;
    for(int i=0;i<n;i++){
        cin >> a >> b;
        p[i]=make_pair(a,b);
    }
    sort(p,p+n);
    int tmp=0;
    for(int i=0;i<n;i++){
        tmp+=p[i].second;
        if(tmp>=m){
            ans+=(p[i].second-(tmp-m))*p[i].first;
            break;
        }
        else ans+=p[i].second*p[i].first;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
int judge(int i)
{
  int sum=0;
  while(i>0){
    sum+=i%10;
    i/=10;
  }
  return sum;
}
int main()
{
  int i,sum=0,n,a,b,max=0;
  scanf("%d %d %d",&n,&a,&b);

  for(i=1; i<=n; i++){
    sum=judge(i);
    if(sum>=a && sum<=b){
      max+=i;
      //      printf("%d %d\n",i,sum);
    }
  }
  printf("%d\n",max);


  return 0;
}

Measured memory_bytes: 128
#coding:utf-8
s = input()
#print(int(s[0:3]))
ans = abs(int(s[0:3]) - 753)

for i in range(0, len(s)-2):
    #print(int(s[i:i+3]))
    ans = min(ans, abs(int(s[i:i+3]) - 753))

print(ans)

Measured memory_bytes: 2940
#include <iostream>
#include <cmath>
// Boost Multiprecision Library を include
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
namespace mp = boost::multiprecision;

int main()
{
     mp::cpp_dec_float_100 a,b;cin>>a>>b;
  cout<<fixed<<(long long)floor(a*b)<<endl;
}

Measured memory_bytes: 3844
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;
 
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
 
#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
 
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD=998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);
 
double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };
 
const int N=200005;


void solve()
{
int n;
cin>>n;
int h[n+1];
for(int i=1;i<=n;i++)
cin>>h[i];
h[0]= -INF;
int ans=1;
int k=0;
for(int i=1;i<=n;i++)
{
    if(h[i]>h[i-1])
    {
      ans=max(ans,k+1);
      k=0;
    }
    else
    {
        k++;
    }   
}
ans=max(ans,k+1);
cout<<ans-1<<endl;


}
 
int32_t main()
{
    IOS;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        
        solve();
    }
    return 0;
}

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

int s[11][11];
int k[11];
int p[11];
int on[11];

int main(){

  int n,m,num,ans=0;
  cin>>n>>m;
  
  rep(i,m){
    cin>>k[i];
    rep(j,k[i])cin>>s[i][j];
  }
  
  rep(i,m)cin>>p[i];
  bool ok;

  for(int bit=0;bit<(1<<n);++bit){
    rep(i,n)on[i]=0;
    ok=true;
    
    rep(i,n)if(bit&(1<<i))on[i]=1;//onのスイッチを調べる
    
    rep(i,m){//m個の電球について、ついているか調べる
      num=0;
      rep(j,10)num+=on[s[i][j]];
      if(num%2!=p[i]){ok=false;break;}
    }
    if(ok)ans++;//全てついていたらans++;
  } 
    cout<<ans<<endl;
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N,K;
  cin >> N >> K;
  map<int,int> mp;
  rep(i,N){
    int n = (i+1) % K;
    mp[n]++;
  }
  if(K % 2 == 0) {
    cout << (ll)(mp[K/2]) * (ll)(mp[K/2]) * (ll)(mp[K/2]) + (ll)(mp[0]) * (ll)(mp[0]) * (ll)(mp[0]) << endl;
  } else {
    cout << (ll)(mp[0]) * (ll)(mp[0]) * (ll)(mp[0]) << endl;
  }
  return 0;
}

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

using namespace std;

int a[10][10][10],c[10][10],N;
bool visited[10][10][10];

bool valid(int x,int y,int z){
  if(0 > x || N <= x) return false;
  if(0 > y || N <= y) return false;
  if(0 > z || N <= z) return false;
  if(a[y][x][z] == -1) return false;
  return true;
}

int check(int x,int y,int z,int p){
  int max = 0,l[2] = {0};
  int dx[] = {-1,1,0,0,-1,1,-1,1,-1,1,0,0,-1,1,-1,1,-1,1,0,0,-1,1,-1,1,0,0};
  int dy[] = {0,0,-1,1,-1,1,1,-1,0,0,-1,1,-1,1,1,-1,0,0,-1,1,-1,1,1,-1,0,0};
  int dz[] = {0,0,0,0,0,0,0,0,-1,1,-1,1,-1,1,-1,1,1,-1,1,-1,1,-1,1,-1,-1,1};
  for(int i = 0 ; i < 26 ; i++){
    int nx = x + dx[i],ny = y + dy[i],nz = z + dz[i];
    while(valid(nx,ny,nz) && a[ny][nx][nz] == p){
      l[i%2]++;
      nx += dx[i];
      ny += dy[i];
      nz += dz[i];
    }
    if(i % 2){
      max = std::max(max,l[0]+l[1]+1);
      l[0] = l[1] = 0;
    }
  }
  return max;
}

int main(){
  int M,P;
  while(cin >> N >> M >> P, N){
    memset(a,-1,sizeof(a));
    memset(c,0,sizeof(c));
    int win = -1, turn = -1;
    for(int i = 0 ; i < P ; i++){
      int x,y;
      cin >> x >> y;
      x--; y--;
      a[y][x][c[y][x]] = i%2;
      if(win == -1){
        if(check(x,y,c[y][x],i%2) >= M){
          win = i%2;
          turn = i+1;
        }
      }
      c[y][x]++;
    }
    if(win == -1){
      cout << "Draw" << endl;
    }else{
      if(win == 1){
        cout << "White " << turn << endl;
      }else{
        cout << "Black " << turn << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1172
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;



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

	cin >> N;
	vector<pair<long long int, int>>v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i].first;
		v[i].second = i;
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	set<int>s;
	s.insert(-1);
	s.insert(N);
	s.insert(v[0].second);
	long long int ans = 0;
	for (int i = 1; i < N; i++) {
		auto rl = s.lower_bound(v[i].second);
		auto rr = next(rl);
		auto lr = prev(rl);
		auto ll = prev(lr);
		if ((*rl) != N) {
			ans += v[i].first*(((*rr) - (*rl))*(v[i].second - (*lr)));
		}
		if ((*lr) != -1) {
			ans += v[i].first*(((*rl) - v[i].second)*((*lr) - (*ll)));
		}
		s.insert(v[i].second);
		//cout << ans << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6528
N, M = map(int, input().split())

A = []
B = []

for _ in range(M):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

P = [[] for _ in range(N + 1)]

for a, b in zip(A, B):
    P[b].append(a)
    P[a].append(b)

ans = [0] * (N + 1)
ans[1] = 1
next_numbers = [1]

while next_numbers:
    check_number = next_numbers[:]
    next_numbers = []
    for number in check_number:
        for x in P[number]:
            if ans[x] == 0:
                ans[x] = number
                next_numbers.append(x)

print('Yes')
for i in range(2, N + 1):
    print(ans[i])

Measured memory_bytes: 37280
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){
  char buf[32] = { 0 };
  int N,A,B;
  int n = 0; //桁数
  int sum = 0; //位の和
  int total = 0;
  
  //入力読み込み
  fgets(buf, sizeof(buf), stdin);
  sscanf(buf, "%d %d %d", &N, &A, &B);
  
  n = log10((double)N);
  
  for(int num = 1; num <= N; num++){
    int n_tmp = n;
    int num_tmp = num;
    sum = 0;
    while(n_tmp >= 0){
      sum += num_tmp / (int)pow(10, n_tmp);
      num_tmp = num_tmp % (int)pow(10, n_tmp);
      n_tmp--;
    }
    if(sum >= A && sum <= B) total += num;
  }
  
  printf("%d\n", total);
  return 0;
}

Measured memory_bytes: 2620
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[11000];
int main(){
	scanf("%s",str);
	int at=0;
	int last=-1;
	int ret=0;
	int len=0;
	int now=0;
	while(str[at]){
		if(str[at]=='e'){
			if(last==0){
				if(len<now){
					len=now;
					ret=0;
				}
				now=1;
			}else{
				now++;
			}
			last=0;
			at+=3;
		}else{
			if(last==1){
				if(len<now){
					len=now;
					ret=1;
				}
				now=1;
			}else{
				now++;
			}
			last=1;
			at+=7;
		}
	}
	if(len<now){
		ret=last;
	}
	if(ret)printf("chicken\n");
	else printf("egg\n");
}

Measured memory_bytes: 952
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
int k[26];
int main() {
	int c = 0, g;
	cin >> g;
	while (1) {
		c++;
		if (c * (c + 1) >= 2 * g)break;
	}
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    h_list = list(map(int, input().split()))

    max_count = 0
    count = 0
    for i in range(n-1):
        if h_list[i] >= h_list[i+1]:
            count += 1
        else:
            max_count = max(max_count, count)
            count = 0
    max_count = max(max_count, count)

    print(max_count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define eb emplace_back
#define PF pop_front
#define PB pop_back
#define mp make_pair
#define s second
#define f first
#define mt make_tuple
#define foreach(it, a) for(__typeof(a.begin()) it=a.begin(); it!=a.end(); it++)
#define forn(i, a) for(int i=0; i<a; i++)
#define INF 1e9
#define all(x) x.begin(), x.end()
#define MOD 1e9+7 

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;

int N, M, a, b;
vector<int> e[100005];
deque<int> q;
bool vis[100005];

void Init()
{
	memset(vis, false, sizeof(vis));
	scanf("%d %d", &N, &M);
	while(M--)
	{
		scanf("%d %d", &a, &b);
		e[a].eb(b);
		e[b].eb(a);
	}
	q.pf(a), q.pb(b);
}
int main() 
{
	Init();
	while(!q.empty())
	{
		set<int> s1, s2;
		int st=q.front(), ed=q.back();
		vis[st]=vis[ed]=true;
		foreach(it, e[st])
			if(!vis[*it])
				s1.insert(*it);
		foreach(it, e[ed])
			if(!vis[*it]&&!s1.count(*it))
				s2.insert(*it);
		
		if(s1.size()||s2.size())
		{
			if(s1.size())
				q.pf(*s1.begin());
			if(s2.size())
				q.pb(*s2.begin());
		}
		
		else
		{
			printf("%d\n", q.size());
			foreach(it, q)
				printf("%d ", *it);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 6784
from collections import deque
n, u, v = map(int, input().split())
u-=1; v-=1;
a = []; b = [];
dist = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    dist[a].append(b)
    dist[b].append(a)

def bfs(u):
    d = [-1]*n
    stack = deque([u])
    d[u] = 0
    while len(stack)!=0:
        s = stack.popleft()
        for t in dist[s]:
            if d[t]==-1:
                d[t] = d[s]+1
                stack.append(t)
    return d

A = bfs(v)
T = bfs(u)
ans=0
for i in range(n):
    if A[i]>T[i]:
        ans = max(A[i]-1, ans)
print(ans)

Measured memory_bytes: 64492
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node{
    int key;
    struct node *parent,*left,*right;
}node;
#define N 500000

int m;
node *NIL,*root;

void insert(node *z){
    node *y=NIL;
    node *x=root;
    while(x!=NIL){
        y=x;
        if(z->key<x->key)x=x->left;
        else x=x->right;
        z->parent=y;
    }
    if(y==NIL)root=z;
    else if(z->key<y->key)y->left=z;
    else y->right=z;

}

void inparse(node *u){
  if(u==NIL)return;
  inparse(u->left);
  printf(" %d",u->key);
  inparse(u->right);
}

void preparse(node *u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preparse(u->left);
  preparse(u->right);
}

node* find(int k){
    node *x=root;
    while(x!=NIL&&k!=x->key){
        if(k<x->key)x=x->left;
        else x=x->right;
    }
    return x;
}

node* get(node* z){
    node *y;
    if(z->right!=NIL){
        z=z->right;
        while(z->left!=NIL)z=z->left;
        return z;
    }
    y=z->parent;
    while(y!=NIL&&z==y->right){
        z=y;
        y=y->parent;
    }
    return y;
}

void delete(int k){
    node *z,*y,*x;
    z=find(k);
    if(z->left==NIL||z->right==NIL) y=z;
    else y=get(z);

    if(y->left!=NIL)x=y->left;
    else x=y->right;
    if(x!=NIL)x->parent=y->parent;
    if(y==NIL)x=root;
    else if(y->parent->left==y)y->parent->left=x;
    else y->parent->right=x;
    if(y!=z)z->key=y->key;

}

int main(){
    int i,n;
    char str[6];
    node *z,*a;

    scanf("%d",&m);
    for(i=0;i<m;i++){
        scanf("%s",str);
        if(strcmp(str,"insert")==0){
        
            scanf("%d",&n);
            
            z=(node*)malloc(sizeof(node));
            z->key=n;
            
            z->left=NIL;
            z->right=NIL;
            insert(z);
        }
        else if(strcmp(str,"print")==0){
            inparse(root); 
            printf("\n"); 
            preparse(root);
            printf("\n");  
        }
        else if(strcmp(str,"find")==0){
            scanf("%d",&n);
            a=find(n);
            if(a==NIL)printf("no\n");
            else printf("yes\n");
        }
        else if(strcmp(str,"delete")==0){
            scanf("%d",&n);
            delete(n);
        }
    }
    return 0;
}



Measured memory_bytes: 20548
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let remain = s.map(|a| a.parse().unwrap()).fold((0, 0), |r, a|{
		if r.1 + 1 == a {
			(r.0 + 1, a)
		} else {
			r
		}
	}).0;
	if remain == 0 {
		println!("-1");
	} else {
		println!("{}", n - remain);
	}
}


Measured memory_bytes: 6396
#include<iostream>
#include<bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define md 1000000007
#define ll long long int 
double PI=3.1415926535;
const int N =  (int)(1 * 1e6 + 10);
using namespace std;

int main()
{
    ll n , k ;
    cin>>n>>k;

    ll a[n];

    for(ll i = 0 ; i < n ; i++)cin>>a[i];

    bool dp[k+1];
    memset(dp,false,sizeof(dp));
    for(ll i = 1 ; i < k+1 ; i++)
    {
        for(ll j = 0 ; j < n ; j++)
        {
            if(i-a[j]<0) break;
            if(dp[i-a[j]]==false)
            {
                dp[i]=true;
                break;
            }
        }
    }
    if(dp[k])
    {
        cout<<"First"<<endl;
    }
    else
    {
        cout<<"Second"<<endl;
    }

}

Measured memory_bytes: 3736
//atcoder ARC? C
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define mo 1000000007
using namespace std;
long long n,m,i,j,k,cf[200005],now,a[200005],ans=1,sum,p1,p2;
char s[200005];
long long read(){
	char ch=getchar();
	long long xx=0;
	while(ch<'0'||ch>'9')
		ch=getchar();
	while(ch>='0'&&ch<='9'){
		xx=xx*10+ch-'0';
		ch=getchar();
	}
	return xx;
}
void pus(long long xx,int flagg){
	if(xx>=10)
		pus(xx/10,0);
	putchar(xx%10+'0');
	if(flagg==1)
		putchar(' ');
	if(flagg==2)
		putchar('\n');
	return;
}
int main(){
	n=read();
	scanf("%s",s+1);
	for(i=1;i<=2*n;i++)
		if(s[i]=='W'&&(now&1)==0||s[i]=='B'&&(now&1)==1){
			a[i]=2;
			now^=1;
			p1++;
		}
		else{
			a[i]=1;
			now^=1;
			p2++;
		}
	for(i=1;i<=2*n;i++){
		if(a[i]==1)
			sum++;
		else{
			ans=ans*sum%mo;
			sum--;
		}
	}
	if(p1!=p2){
		cout<<0<<endl;
		return 0;
	}
	for(i=1;i<=n;i++)
		ans=ans*i%mo;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

char s[200][200];
int dx[]{1,-1,0,0},dy[]{0,0,1,-1};
signed main(){
	int h,w;scanf("%d%d",&h,&w);
	rep(i,h)scanf("%s",s[i]);
	rep(i,h)rep(j,w){
		if(s[i][j]=='.')continue;
		bool flag=false;
		rep(k,4){
			int nx=i+dx[k],ny=j+dy[k];
			if(0<=nx&&nx<h&&0<=ny&&ny<w&&s[nx][ny]=='#'){
				flag=true;
			}
		}
		if(!flag){
			puts("No");return 0;
		}
	}
	puts("Yes");
}

Measured memory_bytes: 256
S = input()

count_A = 0
count_B = 0

for i in range(len(S)):
  if i%2 == 0:
    if(S[i] == '0'):
      count_A += 1
    else:
      count_B += 1
  else:
    if(S[i] == '1'):
      count_A += 1
    else:
      count_B += 1
print(min(count_A, count_B))

Measured memory_bytes: 3188
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;
long long int num[500001];


int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	int box[3] = {};
	for (int i = 0; i < N; i++) {
		cin >> num[i];
		num[i] %= 4;
		if (num[i] == 0)box[0]++;
		if (num[i] == 1 || num[i] == 3)box[1]++;
		if (num[i] == 2)box[2]++;
	}
	if (!box[2]) {
		if (box[0] + 1 >= box[1]) {
			cout << "Yes\n";
			return 0;
		}
		cout << "No\n";
		return 0;
	}
	if (box[0] >= box[1]) {
		cout << "Yes\n";
		return 0;
	}
	cout << "No\n";
	return 0;
}



Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;

public class Main {
    static long count=0;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = ip(br);
        int[] list = createListInt(br);
        // System.out.println(bubbleSort(list));
        mergeSort(list, 0, n);
        System.out.println(count);
    }

    static void merge(int[] a, int left, int mid, int right) {
        int n1 = mid - left;
        int n2 = right - mid;
        int[] l = new int[n1 + 1];
        int[] r = new int[n2 + 1];
        System.arraycopy(a, left, l, 0, n1);
        System.arraycopy(a, mid, r, 0, n2);
        l[n1] = Integer.MAX_VALUE;
        r[n2] = Integer.MAX_VALUE;

        for (int i = 0, j = 0, k = left; k < right; k++) {
            if (l[i] <= r[j]) {
                a[k] = l[i];
                i++;
            } else {
                a[k] = r[j];
                j++;
                count += n1 - i;
            }
        }
    }

    static void mergeSort(int[] a, int left, int right) {
        if (left + 1 < right) {
            int mid = (left + right) / 2;
            mergeSort(a, left, mid);
            mergeSort(a, mid, right);
            merge(a, left, mid, right);
        }
    }

    static long inversion(int[] list) {
        long count = 0;
        for (int i = 0; i < list.length - 1; i++) {
            for (int j = i + 1; j < list.length; j++) {
                if (list[i] > list[j]) {
                    count++;
                }
            }
        }
        return count;
    }

    static int bubbleSort(int[] list) {
        int cnt = 0;
        for (int i = 0; i < list.length - 1; i++) {
            for (int j = list.length - 1; j >= i + 1; j--) {
                if (list[j] < list[j - 1]) {
                    swap(list, j, j - 1);
                    cnt++;
                }
            }
        }
        return cnt;
    }

    static void swap(int[] list, int a, int b) {
        int temp = list[a];
        list[a] = list[b];
        list[b] = temp;
    }

    static boolean isNumber(String num) {
        return Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find();
    }

    static int[] createListInt(BufferedReader br) throws IOException {
        String[] lines = br.readLine().split(" ");
        int n = lines.length;
        int[] list = new int[n];
        while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        }
        return list;
    }

    static int ip(BufferedReader s) throws IOException {
        return Integer.parseInt(s.readLine());
    }
}

class Point {
    double x;
    double y;

    Point(double x, double y) {
        this.x = x;
        this.y = y;
    }
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}


int main()
{
	int n,m;
	cin>>n>>m;
	vector<vector<int>> g(3*n,vector<int>());
	rep(i,m){
		int u,v;
		cin>>u>>v;
		u--;v--;
		rep(j,3){
			g[u+j*n].push_back(v+((j+1)%3)*n);
		}
	}

	int S,T;
	cin>>S>>T;
	S--;T--;

	vector<int> dist(3*n,-1);
	queue<int> que;
	que.push(S);
	dist[S]=0;
	while(!que.empty()){
		int node = que.front();que.pop();
		for(auto x:g[node]){
			if(dist[x]<0){
				dist[x] = dist[node]+1;
				que.push(x);
			}
		}
	}

	cout<<(dist[T]<0?-1:dist[T]/3)<<endl;

	return 0;
}

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

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cerr << #v "=" << (v) << endl;
#define ppa(v) cerr << "- " << #v << endl; rep(i,v.size()) cerr << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define INF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define MOD 1000000007
#define TIME system("date +%M:%S.%N")
using Graph = vector<vector<int>>;
using ll = long long;
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

int main() {
  int n,k;cin>>n>>k;
  int ans = div_ceil(n-1,k-1);
  cout << ans << endl;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N=in(),X=in()-1,Y=in()-1;
	vector<int> D(N-1,0);

	REP(i,N){
		for(int j=i+1;j<N;j++){
			int D1,D2,D3,D4,D5;
			D1 = j-i;
			D2 = abs(X-i)+abs(j-X);
			D3 = abs(X-i)+1+abs(j-Y);
			D4 = abs(Y-i)+abs(j-Y);
			D5 = abs(Y-i)+1+abs(j-X);
			int minD = min({D1,D2,D3,D4,D5});
			D[minD-1]++;
		}
	}

	for(auto& x:D) out(x);
	return 0;
}


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

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> h(n);
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
    }

    int total = 0;
    int start = 0;
    while (1) {
        int w = 0;
        int stop = n-1;
        for (int i = start; i < n; i++) {
            stop = i;
            if (h[i] > 0) {
                if (w == 0 || w > h[i])
                    w = h[i];
            } else {
                if (w == 0)
                    start = i + 1;
                break;
            }
        }

        total += w;

        for (int i = 0; i <= stop; i++) {
            if (h[i] > 0)
                h[i]-=w;
        }

    // for (int i = 0; i < n; i++) { std::cout << h[i] << ","; } std::cout << std::endl;

    if (start >= n)
        break;
    }

    std::cout << total << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N, C;
	cin >> N >> C;

	int D[C][C];
	rep(i, C) rep(j, C) cin >> D[i][j];
	int c[N][N];
	rep(i, N) rep(j, N) cin >> c[i][j];
	int t[3][30];
	rep(i, 3) rep(j, 30) t[i][j] = 0;
	rep(i, N) rep(j, N) t[(i + j) % 3][c[i][j] - 1]++;

	int ans = INF;

	rep(i, C) {
		rep(j, C) {
			if (i == j) continue;
			rep(k, C) {
				if (i == k || j == k) continue;
				int tmp = 0;

				// (s + t) % 3 == 0 → i色
				// (s + t) % 3 == 1 → j色
				// (s + t) % 3 == 2 → k色

				// これだとTLE
				/*
				rep(s, N) {
					rep(t, N) {
						if ((s + t) % 3 == 0) tmp += D[c[s][t] - 1][i];
						if ((s + t) % 3 == 1) tmp += D[c[s][t] - 1][j];
						if ((s + t) % 3 == 2) tmp += D[c[s][t] - 1][k];
					}
				}
				*/

				rep(l, C) tmp += D[l][i] * t[0][l];
				rep(l, C) tmp += D[l][j] * t[1][l];
				rep(l, C) tmp += D[l][k] * t[2][l];

				ans = min(ans, tmp);


			}
		}
	}
	cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1280
import java.util.*;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    int k = sc.nextInt();
    
    long stack;
   	
    for(int i = 0; i < k;i++){
    	if(i%2 == 0){
        	a /= 2;
          	b += a;
        } else {
          	b /= 2;
          	a += b;
        }
    }
    
  	System.out.println(a + " " + b);

  }
}


Measured memory_bytes: 38972
import java.util.*;

public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 入力の取得
      	int r = sc.nextInt();
      	String s = sc.next();
      	String[] p = s.split("");
      	int half = r / 2;
      	boolean flg = true;
      	if (r % 2 == 1) {
      	    System.out.println("No");
      	    return;
      	}
      	for(int i=1; i<=half; i++) {
      	    if (!p[i].equals(p[half+i])) flg = false;
      	}

        if (flg) System.out.println("Yes");
      	else System.out.println("No");
    }
}



Measured memory_bytes: 22612
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll,ll>
#define pint pair<int,int>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define MAX 500010
#define endl '\n'
#define mp make_pair
#define INF INT_MAX
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ff first
#define ss second
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)            //counts no of ones in binary representation
#define w(t)     int t; cin>>t; while(t--)
#define pi 3.141592653589793238
#define sortt(v)  sort(v.begin(),v.end())
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;

bool isprime(ll n){			//to check whteher no is prime or not
	if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

int main(){
	fast;
	ll k;
	cin>>k;
	if(k%2==0||k%5==0){
		cout<<-1;
		return 0;
	}
	vector<ll> v;
	ll rem=0;
	ll cnt=0;
	ll k2=k;
	while(k2){
		rem=rem*10+7;
		k2/=10;
		cnt++;
	}
	if(k>rem){
		rem=rem*10+7;
		cnt++;
	}
	while(rem){
		cnt++;
		rem%=k;
		if(rem==0)	break;
		else	rem=rem*10+7;
	}
	cout<<cnt-1;
	//cout<<"Case #"<<x<<": "<<y<<endl;
}

/*for(int i=2;i<=n;i++){
			if(v[i].size()==0)	break;
			for(int j=0;j<v[i].size();j++){
				cout<<v[i-1][0]<<' '<<v[i][j]<<endl;
			}
		}*/

Measured memory_bytes: 3652
M,N = gets.chomp.split(' ').map(&:to_i)
if N == 1 
  puts 0
else
a =gets.chomp.split(' ').map(&:to_i)
a = a.sort
b = []
(N-1).times do |i|
  b.push((a[i]-a[i+1]).abs)
end
b=b.sort
(M-1).times{b.pop}
sum = 0
 b.each{|i| sum+=i}
 puts sum
end

Measured memory_bytes: 11888
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

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

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

bool compareP(pair<int, int> a, pair<int, int> b) {
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

int main() { int n;
    cin >> n;
    double dn = (double)n;
    dn = ceil(dn / 1.08);
    if(floor(dn * 1.08) == n)
        cout << dn << endl;
    else
        cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

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

    set<int> st;
    for(int i = 0; i < N; i++)
    {
        st.insert(d[i]);
    }
    cout << st.size() << endl;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  const int N = 1e5 + 10;
  
  int k;
  while (cin >> k) {
    const lli inf = 1LL << 60;
        
    priority_queue<pair<int, int>> q;

    lli cost[N];
    cost[0] = inf;
    for (int i = 1; i < N; ++i) {
      cost[i] = i;
      q.push({-i, i});
    }

    while (q.size()) {
      pair<int, int> p = q.top();
      q.pop();
      int c = -1 * p.first;
      int curr = p.second;
      // cout << curr << ' ' << c << ' ' << cost[curr] << endl;
      if (cost[curr] != c) continue;
      for (int i = 0; i <= 9; ++i) {
        int next = (curr * 10 + i) % k;
        lli d = c + i;
        if (cost[next] > d) {
          cost[next] = d;
          q.push({-d, next});
        }
      }
    }
    cout << cost[0] << endl;
  }
  
  return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  int N; cin >> N;
  map<ll, ll> m;
  for(int i = 0; i < N; i++){
    ll tmp; cin >> tmp;
    m[tmp]++;
  }
  ll ans = 0;
  for(auto x: m){
    if(x.second >= x.first){
      ans += x.second - x.first;
    } else { 
      ans += x.second;
    }
  }
  cout << ans << endl;
}



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

int a[100005];
int main()
{
		int n;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
		}
		int ans=0;
		for(int i=1;i<=n;i++)
		{
			if(a[a[i]]==i)
				ans++;
		}
		ans/=2;
		cout<<ans<<endl;
		return 0;
}

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

int *count;

void plus(int n){
	int i;
	for(i = 2; n > 1; i++){
		while(n % i == 0){
			count[i]++;
			n /= i;
		}
	}
}

int main(){
	int N, i, j, k, ans = 0;
	scanf("%d", &N);
	count = (int *)malloc(sizeof(int) * (N + 1));
	for(i = 0; i <= N; i++){
		count[i] = 0;
	}
	for(i = 1; i <= N; i++){
		plus(i);
	}
	for(i = 2; i <= N; i++){
		if(count[i] >= 74){
//			printf("1:i = %d\n", i);
			ans++;
		}
	}
	for(i = 2; i <= N; i++){
		for(j = 2; j <= N; j++){
			if(i == j){
				continue;
			}
			if(count[i] >= 2 && count[j] >= 24){
//				printf("2:(i, j) = (%d, %d)\n", i, j);
				ans++;
			}
			if(count[i] >= 4 && count[j] >= 14){
//				printf("3:(i, j) = (%d, %d)\n", i, j);
				ans++;
			}
		}
	}
	for(i = 2; i <= N; i++){
		for(j = 2; j <= N; j++){
			for(k = 2; k <= N; k++){
				if(i == j || j == k || k == i || j < k){
					continue;
				}
				if(count[i] >= 2 && count[j] >= 4 && count[k] >= 4){
//					printf("4:(i, j, k) = (%d, %d, %d)\n", i, j, k);
					ans++;
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;

#define int long long

#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define rrep(i, n) for (int i=(int)n-1;i>=0;--i)
#define rrep1(i, n) for (int i=n;i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)r;++i)
#define rrange(i, l, r) for (int i=(int)r-1;i>=(int)l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

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

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}

const int mod = TEN(9)+7;
const int inf = TEN(18) * 3 + 10;

char a[105][105];

signed main()
{
	int h, w; cin >> h >> w;
	rep(i, h + 2) rep(j, w + 2) a[i][j] = '#';
	rep1(i, h) rep1(j, w) cin >> a[i][j];
	rep(i, h + 2) {
		rep(j, w + 2) printf("%c", a[i][j]);
		puts("");
	}
}



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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
ll h, w;
int dx[]={-1,0,0,1};
int dy[]={0,1,-1,0};
char maze[21][21];
int cnt[21][21];
ll bfs(pair<int,int> s){
    queue<pair<int,int>> que;
    for(int i=0;i<21;i++){
        for(int j=0;j<21;j++)cnt[i][j] = -1;
    }
    que.push(s);
    cnt[s.first][s.second] = 0;
    while(!que.empty()){
        auto now = que.front();
        que.pop();
        for(int i=0;i<4;i++){
            if(now.first + dx[i]>=0 && now.first+dx[i]<h && now.second+dy[i]>=0 && now.second+dy[i]<w){
                if(maze[now.first+dx[i]][now.second+dy[i]]=='.'&&cnt[now.first+dx[i]][now.second+dy[i]]==-1){
                    cnt[now.first + dx[i]][now.second + dy[i]] = cnt[now.first][now.second]+1;
                    que.push({now.first + dx[i], now.second + dy[i]});
                }
            }
        }
    }
    int ret = 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(cnt[i][j]!=-1)ret = max(ret,cnt[i][j]);
        }
    }
    return ret;
}

int main() {
    ll n, m, i, j, k;
    cin >> h >> w;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            cin >> maze[i][j];
        }
    }
    ll ret = 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            pair<int, int> s = {i, j};
            if(maze[i][j] == '.') ret = max(ret, bfs(s));
            /*for(k=0;k<h;k++){
                for(ll l=0;l<w;l++){
                    pair<ll,ll> s={i,j},t={k,l};
                    if(maze[i][j]=='.' && maze[k][l]=='.')ret = max(ret,bfs(s,t));
                }
            }*/
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        if (n == 1) {
            System.out.println(Math.abs(w - scanner.nextInt()));
            return;
        }

        for (int i = 0; i < n - 2; i++) {
            scanner.nextInt();
        }

        final int preLast = scanner.nextInt();
        final int last = scanner.nextInt();
        System.out.println(Math.max(Math.abs(w - last), Math.abs(last - preLast)));
    }
}


Measured memory_bytes: 25172