akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

using namespace std;

int main(){
  int a,b;
  cin>>a>>b;
  if(a%3==0)
    cout<<"Possible"<<endl;
  else if(b%3==0)
    cout<<"Possible"<<endl;
  else if((a+b)%3==0)
    cout<<"Possible"<<endl;
  else
    cout<<"Impossible"<<endl;
  
  return 0;
}

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

int main(void){
    string S,C;
    ll Q;
    ll T,F;
    ll count=0;
    cin >> S >> Q;

    REP(i,Q){
        cin >> T;
        if(T==1) count++;
        else{
            cin >> F >> C;
            if(count%2==0){
                if(F==1) S=S.insert(0,C);
                else S=S.insert(S.size(),C);
            }
            else{
                if(F==2) S=S.insert(0,C);
                else S=S.insert(S.size(),C);
            }
        }
    }
    if(count%2==1) reverse(S.begin(), S.end());
    cout << S << endl;
    return 0;
}

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

const int MAX = 200001;

const ll mod = 1000000007;

ll n, k;

ll ans[MAX];

ll fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    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;
    }
}

ll rui(ll a, ll b){
    ll ans=1;
    while (b > 0) {
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod ;
        b /= 2;
    }
    return ans;
}
 
 
ll comb(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;
}
 
void solve() {
    
    ans[0] = 1;
    ans[1] = (n * (n - 1)) % mod;
    ans[2] = (1 + n * (n - 1) + comb(n, 2) * comb(n - 1, n - 3)) % mod;
    for (int i = 2; i < n - 1; i++) {
        ans[i + 1] = (ans[i] + comb(n, i + 1) * comb(n - 1, n - i - 2)) % mod;
    }

    if (n <= k) printf("%lld\n", ans[n - 1]);
    else printf("%lld\n", ans[k]);
}

int main() {
    cin >> n >> k;
    COMinit();
    solve();
}

Measured memory_bytes: 6528
S = input()
K = int(input())
N = len(S)

subs = set()

for i in range(1, min(N,K)+1):
    for j in range(N-i+1):
        subs.add(S[j:j+i])

#print(subs)
subs = list(subs)
subs.sort()
#print(subs)
print(subs[K-1])
#print(subs)

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

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

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

	int ans; cin >> ans;
	ans = abs(ans - X);
	for(int i=1; i<N; ++i){
		int b; cin >> b;
		ans = func(ans, abs(b-X));
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
### main

loop do
  n = gets.strip.to_i
  break if n == 0

  str = gets.strip
  if str.empty?
    puts ''
    next
  end

  n.times do
    ds = str.split('')
    d0 = ds.shift
    k = 1
    str0 = ''

    while ! ds.empty?
      d = ds.shift

      if d != d0
        str0 += k.to_s + d0.to_s
        d0 = d
        k = 1
      else
        k += 1
      end
    end

    str = str0 + k.to_s + d0.to_s
  end

  puts str
end

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

using namespace std;

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

  int n;
  cin >> n;

  vector<int> x(n);
  vector<int> y(n);
  vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
    v[i] = i;
  }

  vector<vector<double>> dist(n, vector<double>(n, 0.0));
  for (int i = 0; i < n - 1; ++i)
    for (int j = i + 1; j < n; ++j) {
      double d = sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
      dist[i][j] = d;
      dist[j][i] = d;
    }

  double sum = 0.0;
  do {
    for (int i = 0; i < n - 1; ++i) {
      sum += dist[v[i]][v[i + 1]];
      // cerr << v[i] << " ";
    }
    // cerr << '\n';
  } while (next_permutation(v.begin(), v.end()));

  int Factorial = 1;
  for (int i = 2; i <= n; ++i) Factorial *= i;
  cout << sum / Factorial << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef long long li;

const int maxn = 200000;

int n;
char s[maxn + 1];

int main(void) {
  scanf("%s", s);
  n = strlen(s);
  li ans = 0, cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'B') {
      ++cnt;
    } else {
      ans += cnt;
    }
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll i,n,sum=0;
  map <ll, ll> m;
  cin>>n;
  ll a[n];
  for(i=0;i<n;i++)
  cin>>a[i];
  for (i=0; i<n; i++) 
    m[a[i]]++;
  map <ll,ll>::iterator it;
  for(it=m.begin();it!=m.end();it++)
  {
    ll x=it->second;
    sum=sum+(x*(x-1))/2;
  }
  for(it=m.begin();it!=m.end();it++)
    it->second=sum-(it->second-1);
  for(i=0;i<n;i++)
  cout<<m[a[i]]<<endl;
}
  

Measured memory_bytes: 11008
# abc160_a.py
# https://atcoder.jp/contests/abc160/tasks/abc160_a

# A - Coffee /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# ある長さ 6の英小文字からなる文字列がcoffeeに似ているとは、3 文字目と 4 文字目が等しく、
# 5 文字目と 6 文字目も等しいことを言います。
# 与えられる文字列 Sがcoffeeに似ているか判定してください。

# 制約
#     Sは長さ 6の英小文字からなる文字列である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# S

# 出力
# Sがcoffeeに似ている場合 Yes を、そうでない場合 Noを出力せよ。

# 入力例 1
# sippuu

# 出力例 1
# Yes

# sippuu は 3文字目と 4 文字目が等しく、5 文字目と 6文字目も等しいです。

# 入力例 2
# iphone

# 出力例 2
# No

# 入力例 3
# coffee

# 出力例 3
# Yes


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    S = lines[0]
    # N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = 'Yes'
    if S[2] != S[3]:
        result = 'No'
    elif S[4] != S[5]:
        result = 'No'

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['sippuu']
        lines_export = ['Yes']
    if pattern == 2:
        lines_input = ['iphone']
        lines_export = ['No']
    if pattern == 3:
        lines_input = ['coffee']
        lines_export = ['Yes']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


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

int main(){
	ll n;
	cin >> n;
	ll ans = n*(n-1)/2;
	cout << ans << endl;
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  int cnt = 0, N = 1;
  rep(i,n) {
    int a;
    cin >> a;
    if(a == N) N++;
    else cnt++;
  }
  if(cnt == n) cout << -1 << endl;
  else cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3632
pointTarou = 0;
pointHanako = 0;
 
count = gets.to_i;
 
for index in 0..count-1 do
 
	aryCards = gets.split(' ');
 
	cardTarou = aryCards[0];
	cardHanako = aryCards[1];
 
	if cardTarou == cardHanako then
 
		pointTarou = pointTarou + 1;
		pointHanako = pointHanako + 1;
 
	elsif cardTarou > cardHanako then
 
		pointTarou = pointTarou +3;
 
	elsif cardTarou < cardHanako then
 
		pointHanako = pointHanako + 3;
 
	end
 
end
 
puts pointTarou.to_s + " " + pointHanako.to_s;

Measured memory_bytes: 8772
import sys
n,a,b = map(int,input().split())
if a == 0:
    print(0)
    sys.exit()
if (a+b) >= n:
    print(min(n,a))
    sys.exit()
x = n//(a+b)
y = n % (a+b)
if y > a:
    print(x*a + a)
elif y == 0:
    print(x*a)
else:
    print(x*a + y)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 0;										/* デバッグプリント 提出時は0 */
	int		bill[5][4][11] = {0};

int main()
{
	int		i,j,k,N;
	int		b,f,r,v;

	scanf("%d", &N);
	for(i=1;i<=N;i++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);
		bill[b][f][r] += v;
	}
	for(i=1;i<=4;i++) {
		for(j=1;j<=3;j++) {
			for(k=1;k<=10;k++) {
				printf(" %d",bill[i][j][k]);
			}
			ENTER;
		}
		if (i!=4) printf("####################\n");
	}


	return 0;
}



Measured memory_bytes: 2108
#include<stdio.h>
#define ll long long
ll gcd(ll a,ll b){
   if(b==0)
   return a;
   else return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll p;
    p=(a*b)/gcd(a,b);
    return p;
}
int main(void){
    ll a,b;
    scanf("%lld%lld",&a,&b);
    printf("%lld\n",lcm(a,b));
    return 0;

}

Measured memory_bytes: 128
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class BIT:
	def __init__(self, N):
		self.size = N
		self.tree = [0] * (N + 1)

	def sum(self, t):
		s = 0
		while t > 0:
			s += self.tree[t]
			t -= t & -t
		return s

	def add(self, t, x):
		while t <= self.size:
			self.tree[t] += x
			t += t & -t

def Binary_Search(A, B, N):
	#初期化
	left = 0
	right = N - 1
	ans = 0
	
	#二分探索
	while left <= right:
		mid = (left + right) // 2
		var = B[mid]
		newlist = [None] * N
		#境界判定して1,-1で構成されるリストの構築
		for i in range(N):
			if A[i] >= var:
				newlist[i] = 1
			else:
				newlist[i] = -1
		#累積和
		newlistsum = [0]
		for i in range(N):
			newlistsum.append(newlistsum[-1] + newlist[i])
		cnt = 0
		bit = BIT(2 * N + 1)
		for i in range(N + 1):
			bit.add(newlistsum[i] + N, 1)
			cnt += bit.sum(newlistsum[i] + N) - 1

		if 4 * cnt >= N * (N + 1):
			ans = max(ans, B[mid])
			left = mid + 1
		else:
			right = mid - 1

	return ans

#処理内容
def main():
	N = int(input())
	A = getlist()
	B = sorted(A)
	ans = Binary_Search(A, B, N)
	print(ans)

if __name__ == '__main__':
	main()

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

const int maxn = 1e5 + 5;

struct numbers {
	int index;
	int C;
};

bool operator < (numbers a, numbers b)
{
	return a.C < b.C;
}

struct cmp
{
	bool operator ()(int a, int b)
	{
		return a > b;
	}
};

priority_queue<numbers> q;
priority_queue<int,vector<int>,cmp> A;

int B[maxn];

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

	int n, m, a, b, c;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		A.push(a);
	}
	for (int i = 0; i < m; i++)
	{
		cin >> b >> c;
		q.push({ i,c });
		B[i] = b;
	}

	ll ans = 0;
	while (n > 0 && !q.empty() && !A.empty())
	{
		if (q.top().C > A.top())
		{
			ans += q.top().C;
#ifdef DEBUG
			cout << q.top().C << "+";
#endif // DEBUG
			A.pop();
			if ((--B[q.top().index]) == 0)
				q.pop();
		}
		else
		{
			break;
		}
		n--;
	}
	while (n != 0)
	{
		ans += A.top();
#ifdef DEBUG
cout << A.top() << "+";
#endif // DEBUG

		A.pop();
		n--;
	}
	cout << ans;
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
int ans[26];
int main(){
char a;
int b;
while(1)
{
//cin>>a;
if(scanf("%c", &a)==EOF) break;
	if('A'<=a&&a<='Z') a+=32;
	if('a'<=a&&a<='z')
		{
		b=a - 'a';
		ans[b]++;
		}
	
}
a='a';
for(int i=0; i<26;i++)
	{printf("%c : %d\n",a,ans[i]);
	a++;
	}
return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=1e9+7;
const ll ms=2e5+5;
const ll inf=1e17;



int main(){
    idfc;

    int n;
    cin>>n;

    int f=0;
    int a=0;
    int x,y;

    while(n--)
    {
        cin>>x>>y;
        if(x==y)
        {
            a++;
        }
        else a=0;
        if(a>=3){f=1;}
    }
    if(f)cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"
//#include <intrin.h>  //AtCoder (gcc) 上ではこれがあると動かない。__popcnt用のincludeファイル。
using namespace std;

typedef long long ll;
typedef long double ld;


#define int long long
#define rep(i, n) for(long long i = 0; i < (n); i++)
#define sqrt(d) pow((long double) (d), 0.50)

const int INF = 2000000000; //2e9
const long long INF2 = 1000000000000000000; //1e18
const long double PI = acos(-1);

const int large_P = 1000000007; //1e9 + 7
//const int large_P = 1000000009; //1e9 + 9
//const int large_P = 998244353;




int dfs2(const vector<int>& parent, const vector<int>& pos, vector<int>& res, vector<bool>& seen, int v) {
	seen.at(v) = true;
	//cout << v << endl;

	if (parent.at(v) == v) {
		res.at(v) = pos.at(v);
		return pos.at(v);
	}

	if (seen.at(parent.at(v))) {
		res.at(v) = res.at(parent.at(v));
		return res.at(v);
	}

	
	return res.at(v) = dfs2(parent, pos, res, seen, parent.at(v));
}




signed main() {
	int N; cin >> N;
	long double res = 0.50;

	if (N % 2 == 1) {
		int tempo = N / 2 + 1;
		res = (long double)tempo / (long double)N;
	}

	printf("%.12Lf\n", (long double)res);

}

Measured memory_bytes: 256
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 03/28/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int N; cin>>N;
  cout << 0 << endl;
  string res;
  cin>>res;
  if (res == "Vacant") {
    return 0;
  }
  bool man_bit = res != "Male";
  int l = 1, r = N;
  int q = 0;
  auto is_man = [man_bit](string& res) -> bool {
    return (res == "Male") ? man_bit : !man_bit;
  };
  while (q < 20) {
    q++;
    auto id = (l+r)/2;
    cout << id << endl;
    cin>>res;
    if (res == "Vacant") {
      break;
    }
    if (id%2 == is_man(res)) {
      l = id;
    } else {
      r = id;
    }
  }

  return 0;
}


Measured memory_bytes: 852
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
int main(){
  int A,B,C,D;
  str S1,S2,S3;
  str N;
  cin>>A;
  cout<<A/3<<endl;
}


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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 998244353;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

PII p[maxn];

int main() {
    stack<PII> s;
    int n, res = 1;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d%d", &p[i].fi, &p[i].se);
    sort(p + 1, p + 1 + n, [](PII &x, PII &y) {
        return x.fi > y.fi;
    });
    s.push({inf, res});
    for (int i = 1, r; i <= n; i++) {
        r = p[i].fi + p[i].se;
        while (r > s.top().fi) s.pop();
        res = (res + s.top().se) % MOD;
        s.push({p[i].fi, res});
    }
    printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 2560
using DataStructures
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  W,H,x,y = readint() 

  print(W*H/2, " ")
  if x == W/2 && y == H/2
    println("1")
  else
    println("0")
  end
  
end



main()

Measured memory_bytes: 213904
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF INT32_MAX / 2
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

template <class T>
vector<T> divisor(T n) {
    vector<T> r;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            r.push_back(i);
            if (i * i != n)
                r.push_back(n / i);
        }
    }
    sort(r.begin(), r.end());
    return r;
}

signed main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int g = GCD(a[0], a[1]);
    for (int i = 2; i < n; i++) {
        g = GCD(g, a[i]);
    }
    if (g != 1) {
        cout << "not coprime" << endl;
        return 0;
    }
    set<int> s;
    rep(i, n) {
        auto v = divisor(a[i]);
        rep(j, v.size()) {
            if (v[j] == 1)
                continue;
            if (s.find(v[j]) == s.end())
                s.insert(v[j]);
            else {
                cout << "setwise coprime" << endl;
                return 0;
            }
        }
    }
    cout << "pairwise coprime" << endl;
}

Measured memory_bytes: 7280
#pragma GCC optimize("O3")
#pragma G++ optimize("O3")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/priority_queue.hpp>

//using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long
#define mst(a, b) memset((a), (b), sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define endl '\n'
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define lson root << 1, l, mid
#define rson root << 1 | 1, mid + 1, r
#define ls t[root << 1]
#define rs t[root << 1 | 1]
#define tr t[root]
#define lowbit(x) x &(-x)
#define all(x) (x).begin(), (x).end()
#define sf(x) scanf("%d", &x)
#define pf(x) printf("%d", x)
#define debug(x) cout << x << endl
#define mod(x) (x % mod + mod) % mod

template <typename T>
void read(T &x)
{
    x = 0;
    char ch = getchar();
    ll f = 1;
    while (!isdigit(ch))
    {
        if (ch == '-')
            f *= -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        x = x * 10 + ch - 48;
        ch = getchar();
    }
    x *= f;
}

const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 5e5 + 7;
const int maxm = 1e3 + 7;
const int mod = 1e9 + 7;

#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//template<typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

int main()
{
    string s,t;
    cin>>s>>t;
    int lens=s.length();
    int lent=t.length();
    int ans=INF;
    for (int i=0;i<=lens-lent;++i)
    {
        int num=0;
        for (int j=0;j<lent;++j)
        {
            if (s[i+j]!=t[j])
            num++;
        }
        ans=min(ans,num);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<=(end);i++)
#define REP(i, n) FOR(i,1,n)
#define IFOR(i, begin, end) for(int i=(end);i>=(begin);i--)
#define IREP(i, n) IFOR(i,1,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())

#define ll long long
using namespace std;

int main()
{
	stringstream ss;
    // 入力
    int N;
    cin>>N;
    ll A[N+1];
    FOR(i,1,N){
        cin>>A[i];
    }

    sort(A+1,A+N+1);
    ll ans=0;
    if(N==2){
    	ans=A[2]-A[1];
    } else if(N==3){
    	ans=max(A[3]*2-A[2]-A[1],A[3]+A[2]-2*A[1]);
    }
    else if(N%2==0){
    	FOR(i,1,N/2-1){
    		ans-=2*A[i];
    	}
    	ans-=A[N/2];
    	ans+=A[N/2+1];
    	FOR(i,N/2+2,N){
    		ans+=2*A[i];
    	}
    } else {
    	FOR(i,1,(N-3)/2){
    		ans-=2*A[i];
    	}
    	FOR(i,(N+5)/2,N){
    		ans+=2*A[i];
    	}
    	ans+=max(A[(N+3)/2]*2-A[(N-1)/2]-A[(N+1)/2],A[(N+3)/2]-2*A[(N-1)/2]+A[(N+1)/2]);

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

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {

    int N, M;
    cin >> N >> M;

    vector<int> L(M);
    vector<int> R(M);

    int Lmax = 1;
    int Rmin = 100000;

    for (int i = 0; i < M; i++) {
        
        cin >> L[i] >> R[i];

        if (L[i] > Lmax) Lmax = L[i];
        if (R[i] < Rmin) Rmin = R[i];
        
    }

    int cnt;
    if(Rmin >= Lmax)
        cnt = Rmin - Lmax + 1;
    else {
        cout << 0;
        return 0;
    }

    if (cnt <= N) cout << cnt;
    if (cnt > N) cout << N;

    return 0;   


}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	//~ cout.tie(0);
	int n, d, a;
	scanf("%d%d%d", &n, &d, &a);
	vii monsters(n);
	for (int i = 0; i < n; i++)
		scanf("%d%d", &(monsters[i].first), &(monsters[i].second));

	sort(all(monsters));
	vector<pair<int,ll>> bombs;
	int bi = 0;
	ll ans = 0, prv = 0;
	for (auto m : monsters) {
		while (bi < sz(bombs) && bombs[bi].first + d < m.first) {
			prv -= bombs[bi].second;
			++bi;
		}
		assert(prv >= 0);
		m.second -= prv;
		if (m.second > 0) {
			int k = (m.second + a - 1) / a;
			ans += k;
			bombs.emplace_back(m.first + d, (ll)k * a);
			prv += (ll)k * a;
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 6896
#include<bits/stdc++.h>
using namespace std;
bool vis[30];
int a[30][30][2];
int n;
int ans;
void check() {
	bool qaq=1;
	int qwq=0;
	for(int i=1;i<=n;i++) {
		if(vis[i]==0) continue;
		for(int j=1;j<=a[i][0][0];j++) if(a[i][j][1]!=vis[a[i][j][0]]) qaq=0;
	}
	for(int i=1;i<=n;i++) if(vis[i]) qwq++;
	if(qaq) ans=max(ans,qwq);
}
void dfs(int step) {
	if(step==n+1) check();
	if(step==n+1) return ;
	vis[step]=1;
	dfs(step+1);
	vis[step]=0;
	dfs(step+1);
	return ;
}
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) {
    	scanf("%d",&a[i][0][0]);
    	for(int j=1;j<=a[i][0][0];j++) scanf("%d%d",&a[i][j][0],&a[i][j][1]);
	}
	dfs(1);
	cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INT INT_MAX
#define LONG LLONG_MAX
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
typedef long long ll;
using namespace std;

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

ll LCM(ll a, ll b) {
	return a / GCD(a, b)*b;
}

ll mypow(ll a, ll b, ll c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	else return mypow(a, b / 2, c)*mypow(a, b / 2, c) % c;
}

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

ll longmin(ll a,ll b){
	if(a<b) return a;
	else return b;
}

signed main(){
	ll a,b,c,ans;
	cin>>a>>b;
	ans=pow(2,a-1);
	f(i,a){
		cin>>c;
		if(c%2){
			cout<<ans<<endl;
			return 0;
		}
	}
	if(b) puts("0");
	else cout<<ans*2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int MN = 200200;
int p[MN];
ll rel[MN];
vvi v;
bool un(int a, int b, ll off) {
	if(p[a] == p[b]) {
		return rel[a]+off == rel[b];
	}
	off += rel[a]-rel[b];
	a = p[a];b = p[b];
	if(v[a].size() < v[b].size()) {
		swap(a,b);
		off *= -1;
	}
	for(int i=0;i<v[b].size();i++) {
		int u = v[b][i];
		v[a].push_back(u);
		p[u] = a;
		rel[u] += off;
	}
	v[b].clear();
	return true;
}
int main() {
	int n,m;
	scanf("%d %d",&n,&m);
	v.assign(n,vi());
	memset(rel,0,sizeof(rel));
	for(int i=0;i<n;i++) {
		p[i] = i;
		v[i].push_back(i);
	}
	bool po = true;
	for(int i=0;i<m;i++) {
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);a--;b--;
		po = po && un(a,b,c);
	}
	printf("%s\n",po?"Yes":"No");
}

Measured memory_bytes: 11388
import java.util.Scanner;
 
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int w = sc.nextInt();
      	int h = sc.nextInt();
      	int x = sc.nextInt();
      	int y = sc.nextInt();
      
      	double area = (double)w*h/2.0;
      	int d = 0;
      	if(w==2*x && h==2*y)
          d = 1;
      	System.out.print(area);
      	System.out.println(" " + d);
    }
}

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

int x;

int main()
{
    cin>>x;
    int happy=0;
    for(; x>=500; x-=500) happy+=1000;
    for(; x>=5; x-=5) happy+=5;
    cout<<happy<<endl;
    return 0;
}


Measured memory_bytes: 256
#Ruby

s= gets.chomp.to_i

former=s/100
latter=s-former*100
if former>0&&former<=12&&latter>0&&latter<=12
puts "AMBIGUOUS"
elsif former>0&&former<=12
puts "MMYY"
elsif latter>0&&latter<=12
puts "YYMM"
else
puts"NA"
end

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#define int long long
using namespace std;

const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int Q;
	cin >> Q;
	vector<pair<int,int>> vec(Q);
	for(int i = 0;i < Q;i++) {
		int A,B;
		cin >> A >> B;
		vec.at(i) = make_pair(A,B);
	}
	bool count[100010];
	for(int i = 0;i < 100010;i++) {
		count[i] = true;
	}
	count[1] = false;
	count[2] = true;
	for(int i = 3;i < 100010;i++) {
		for(int j = 2;j * j <= i;j++) {
			if(i % j == 0) {
				count[i] = false;
			}
		}
	}
	int cnt[100010];
	for(int i = 3;i < 100010;i = i + 2) {
		if(count[i] == true && count[(i + 1) / 2] == true) {
			cnt[i] = cnt[i - 2] + 1;
		}
		else {
			cnt[i] = cnt[i - 2];
		}
	}
	for(int i = 0;i < Q;i++) {
		cout << cnt[vec[i].second] - cnt[vec[i].first - 2] << endl;
	}
}


Measured memory_bytes: 3072
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Solver().solve(new Scanner(System.in));
//        new Solver().solve(new Scanner(ex));
    }

    private static final String ex = "7 7 5";
}

class Solver {
    Solver() {}

    void solve(Scanner scanner) {
        String[] split = scanner.nextLine().split(" ");
        int count5 = 0;
        int count7 = 0;
        for (int i = 0; i < split.length; i ++) {
            if (split[i].equals("5")) count5 ++;
            if (split[i].equals("7")) count7 ++;
        }

        if (count5 == 2 && count7 == 1) System.out.println("YES");
        else System.out.println("NO");
    }
}


Measured memory_bytes: 23124
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int n;
	while (cin >> n, n) {
		vector<vector<int> >v(n);
		for (int i = 0; i < n; i++) {
			int m;
			cin >> m;
			for (int j = 0; j < m; j++) {
				int p;
				cin >> p;
				v[i].push_back(p);
			}
		}
		int k;
		cin >> k;
		vector<bool>f(n, true);
		for (int i = 0; i < k; i++) {
			int l;
			cin >> l;
			for (int j = 0; j < n; j++) {
				bool g = false;
				for (int k = 0; k < v[j].size(); k++) {
					if (v[j][k] == l) {
						g = true;
					}
					
				}
				if (!g)f[j] = false;
			}

		}
		
		int acc=accumulate(f.begin(), f.end(),0);
		if (acc != 1)cout << -1 << endl;
		else {
			for (int i = 0; i < f.size(); i++) {
				if (f[i])cout << i+1 << endl;
			}
		}



	}
	return 0;
}

Measured memory_bytes: 3176
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>

using namespace std;

typedef long long LL;
const LL N = 2e5 + 10;
LL a[N];
LL h[N];
LL n;

int main() {
	cin >> n;
	for (LL i = 1; i < n; i++) {
		LL x;
		cin >> x;
		h[x]++;
	}

	for (int i = 1; i <= n; i++)
		cout << h[i] << endl;

	return 0;
}

Measured memory_bytes: 5148
// 食べるものを選んだ場合、その中で最後に食べるのは必ず一番時間がかかるものになる。
// それを利用し、Aiをソートしておいて、ナップサックDPすると、
// DP[i][] が 0～i-1 までの食べ物を選んで食べた場合の最大値になっているはず。
//  例えば 0,1,5,i-1 を選ぶのがベストだったとしても、0,1,2,10,i-5 がベストだったとしても
//  結局は DP[i][] にそのベストの値が入っている。
// なので、DP[i][] + i+1～N-1 のどれか が i 以上が最後に食べるものだった場合のMAX
// それを i を振って全部みたら、答えが出てくる。

#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPI(i,f,n) for(int i=(f);i<(n);++i)
using namespace std;
typedef long long ll;

ll dp[3005][3005];

int main() {
  ll N, T;
  cin >> N >> T;
  vector<pair<int,int> > AB(N);
  REP(i,N) {
    int a,b;
    cin >> a >> b;
    AB[i] = make_pair(a,b);
  }
  sort( AB.begin(), AB.end() ) ;
//  REP(i,N) cout << AB[i].first << " " << AB[i].second << endl;
  REP(i,N) {
    REP( ti, T ) {
      if ( ti >= AB[i].first) dp[i+1][ti] = max(dp[i][ti-AB[i].first] + AB[i].second, dp[i][ti] );
      else dp[i+1][ti] = dp[i][ti];
    }
  }
  ll ans = 0;
  REPI(i,0,N-1) {
    REPI(j,i+1,N) {
      ans = max( ans, dp[i+1][T-1] + AB[j].second );
    }
  }
//  REP(i,T) {
//    REP(j,N+1) {
//      printf("%3d ",dp[j][i]);
//    }
//    cout << endl;
//  }

  cout << ans << endl;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define pii pair <int, int>
#define all(vv) (vv).begin(), (vv).end()
#define time cerr << '\n' << (double)clock()/CLOCKS_PER_SEC << '\n'; return 0

int n;
vector <int> x;
vector <int> y;

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; ++i) {
		int a; cin >> a;
		x.pb(a);
		y.pb(a);
	}
	sort(all(y));
	int lm = y[n/2-1];
	int rm = y[n/2];
	for(int i = 0; i < n; ++i) {
		if (x[i] <= lm) {
			cout << rm;
		}
		else {
			cout << lm;
		}
		cout << '\n';
	}
	time;
}

Measured memory_bytes: 6580
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int N;
	int a;
	int ans = 0;
	bool color[8];
	int colorfree = 0;
	for (int i = 0; i < 8; i++)
		color[i] = false;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> a;
		if (a >= 3200)
		{
			colorfree++;
		}
		else
		{
			if (!color[a / 400])
			{
				ans++;
				color[a / 400] = true;
			}
		}
	}

	if (ans == 0)
	{
		cout << "1 " << (ans + colorfree) << endl;
		return 0;
	}

	cout << ans << " " << (ans + colorfree) << endl;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  int64_t ans=0;
  for(int i=1;i<=N;i++){
    if(to_string(i).size()%2!=0){
      ans++;
    }
  }
  cout << ans << endl;
}


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

#define ll long long
#define ar array

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    for (int i = 1; i < s.size(); i++) {
        if (s[i] != s[i - 1]) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool vis[110];
int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= k; ++i) {
		int d;
		cin >> d;
		for (int j = 1; j <= d; ++j) {
			int x;
			cin >> x;
			vis[x] = true;
		}
	}
	int cnt = 0;
	for (int i = 1; i <= n; ++i) {
		if (vis[i] == false) {
			++cnt;
		}
	}
	cout << cnt;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

string latte="MARCH";

int cnt[10];

signed main(){
    int N;cin>>N;
    rep(i,N){
        string s;cin>>s;
        cnt[find(all(latte),s[0])-latte.begin()]++;
    }

    int ans=0;
    rep(i,5)rep(j,i)rep(k,j)ans+=cnt[i]*cnt[j]*cnt[k];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
a, b, c, d = map(int, input().split())

for i in range(1, 10000):
    c1=c-b*i
    if (c1 <= 0):
        print ('Yes')
        sys.exit()
    a1=a-d*i
    if (a1 <= 0):
        print ('No')
        sys.exit()

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

x = input().rstrip()
y = input().rstrip()

lx = len(x)
ly = len(y)
c1 = [[0 for _ in range(lx+1)] for _ in range(ly+1)]
for i in range(1,ly+1):
    e1 = y[i-1]
    for j in range(1,lx+1):
        if (e1 == x[j-1]):
            c1[i][j] = c1[i-1][j-1] + 1
        else:
            c1[i][j] = max(c1[i-1][j],c1[i][j-1])
i = ly
j = lx
s = ''
m = c1[i][j]
di = -1
dj = 0
while c1[i][j] > 0:
    if c1[i][j] > c1[i-1][j] and c1[i][j] > c1[i][j-1] and c1[i][j] > c1[i-1][j-1]:
        s = x[j-1] + s
        m = m - 1
        i = i - 1
        j = j - 1
    else:
        ni = i + di
        nj = j + dj
        if c1[ni][nj] == m:
            i = ni
            j = nj
        else:
            di, dj = dj, di

print (s)


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

class Program
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var D = new int[N][];
        for (int i = 0; i < N; i++)
        {
            D[i] = new int[2];
            D[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
        }
        var count = 0;
        var result = "No";
        for (int i = 0; i < N; i++)
        {
            if (D[i][0] == D[i][1])
            {
                count++;
            }
            else
            {
                count = 0;
            }
            if (count == 3)
            {
                result = "Yes";
                break;
            }
        }
        Console.WriteLine(result);
    }
}

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

ll a[1234567];

int main()
{
    ll n;
    double ans;
    while(cin>>n){
      if(n&1)ans=(n/2)+1;
      else ans=n/2;
      double res=(double)ans/n;
      printf("%.10lf\n",res);
    }

}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){

  string s;
  cin >> s;
  bool flag = false;
  if(s[2] == s[3] && s[4] == s[5])flag = true;
  if(flag)cout << "Yes" << endl;
  else cout << "No" << endl;



  return 0;
}


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

#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define matrix(x) vector<vector<x>>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a)   scanf("%d",&a)
#define sfl(a)  scanf("%lld",&a)
#define sff(a,b)    scanf("%d %d",&a,&b)
#define sffl(a,b)   scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff  first
#define ss  second
#define lcm(a, b)   ((a)*((b)/__gcd(a,b)))
#define all(a)  a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 1000000007
#define MOD(a,b) (a%b + b)%b

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


int main()
{
    //fastio
    ll x;
    sfl(x);
    ll val = 7%x;
    for(ll i=1;i<=1e6;i++)
    {
        if(val==0)
        {
            cout<<i<<endl;
            return 0;
        }
        //cout<<"value = "<<val<<endl;
        val = ((val*10)+7)%x;
        
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 3768
let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let ans = Array.make (n + 1) 0 in
  for i = n downto 1 do
    ans.(i) <- Array.fold_left ( lxor ) as_.(i - 1) @@
      Array.init (n / i - 1) @@ fun j -> ans.(i * (j + 2))
  done;
  match Array.fold_left ( + ) 0 ans with
  | 0 -> print_endline "0"
  | x ->
      Printf.printf "%d\n" x;
      for i = 1 to n do
        if ans.(i) = 1 then Printf.printf "%d " i
      done;
      print_newline ()
  


Measured memory_bytes: 13016
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]
ans=["X"]*n
if m==0:
  if n==1:
    print(0)
  elif n==2:
    print(10)
  elif n==3:
    print(100)
  exit()

for s,c in sc:
  if s>n:
    print(-1)
    exit()
  if ans[s-1]=="X" or ans[s-1]==str(c):
    ans[s-1]=str(c)
  else:
    print(-1)
    exit()
if ans[0]=="X":
  ans[0]="1"
if ans[0]=="0" and n!=1:
  print(-1)
  exit()
ans="".join(ans)
ans=ans.replace("X", "0")
print(int(ans))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  std::vector<int>V(n);
  for(int i =0;i<n;i++){
      cin>>V[i];
  }
  vector<vector<int> > dp(k+1,vector<int>(2));
  dp[0][0] = 1;
  dp[0][1] = 0;
  if(V[0]!=1){
      dp[1][0] = 1;
      dp[0][1] = 0;
  }
  else{
      dp[1][0] = 0;
      dp[1][1] = 1;
  }
  for(int i =2; i<=k;i++){
      dp[i][0] = 1;
      dp[i][1] =0;
      for(int j = 0;j<n;j++){
          if(i>=V[j]){
          dp[i][0] = min(dp[i][0],dp[i-V[j]][1]);
          dp[i][1] = max(dp[i][1],dp[i-V[j]][0]);
          }
      }
  }
  string ans;
  if(dp[k][1]==1){
      ans = "First";
  }
  else{
      ans = "Second";
  }
  //cout<<dp[5][1]<<dp[3][0]<<dp[2][0];
  //for(int i=0;i<=k;i++){
    //cout<<dp[i][0]<<dp[i][1]<<"\n";
  //}
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 8784
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int all = 0;
int start=1;
int a[2000000];
void insert(int key) {
	all++;
	a[all] = key;
	int parent = all / 2;
	int j = all;
	while (parent>=start && a[j] > a[parent])
	{
		swap(a[j], a[parent]);
		j = parent;
		parent = j / 2;
	}
}
void extract() {
	cout << a[1]<<endl;
	swap(a[1], a[all]);
	all--;
	
	int j = 1;
	while (1)
	{
		int left = 2 * j;
		int right = 2 * j + 1;
		int max=j;
		if (left <= all && a[left] > a[j]) max = left;
		if (right <= all && a[right] > a[max]) max = right;
		if (max != j) {
			swap(a[max], a[j]);
			j = max;
		}
		else {
			break;
		}
	}
}
int main(void) {
	while (1)
	{
		char c[20];
		scanf("%s", c);
		if (c[0] == 'i') {
			int key;
			cin >> key;
			insert(key);
		}
		else if(c[1] == 'x'){
			extract();
		}
		else {
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 7068
import itertools

n,m=map(int, input().split())
lst=sorted(list(map(int, input().split())))
sub_lst=[]
for i in range(1, m):
  sub_lst.append(lst[i]-lst[i-1])
if n==1:
  print(sum(sub_lst))
else:
	print(sum(sorted(sub_lst)[:-n+1]))


Measured memory_bytes: 13696
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
	int N,T;
	int c,t;
	cin>>N>>T;
	int mn=0x3f3f3f;
	for(int i=1;i<=N;i++){
		cin>>c>>t;
		if(t<=T){
			mn=min(mn,c);
		}
	}
	if(mn==0x3f3f3f) cout<<"TLE";
	else cout<<mn;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<utility>

using namespace std;

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

    int a[100];
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }

    int cnt = 0;
    bool flag = true;
    while(flag){
        flag = false;
        for(int i = n - 1; i > 0; i--){
            if(a[i-1] > a[i]){
                swap(a[i-1], a[i]);
                flag = true;
                cnt++;
            }
        }
    }

    for(int i = 0; i < n - 1; i++){
        printf("%d ", a[i]);
    }
    printf("%d\n", a[n-1]);
    printf("%d\n", cnt);
}


Measured memory_bytes: 2752
#include <bits/stdc++.h>
#define ll long long
#define ri register int
using namespace std;
int read()
{
	int num=0;
	char c=getchar();
	while(c>'9'||c<'0')
	{
		c=getchar();
	}
	while(c<='9'&&c>='0')
	{
		num=(num<<3)+(num<<1)+(c^48);
		c=getchar();
	}
	return num;
}
const int maxn=5e5+5;
int l[maxn<<2],r[maxn<<2];
int a[maxn<<2];
int main()
{
	int n=read();
	for (ri i=1; i<=n; ++i)
	{
		a[i]=read();
	}
	for (ri i=1; i<=n; ++i)
	{
		l[i]=i;
		while(l[i]>1&&a[l[i]-1]>a[i])
		{
			l[i]=l[l[i]-1];
		}
	}
	for (ri i=n;i>=1;i--)
	{
		r[i]=i;
		while(r[i]<=n&&a[r[i]+1]>a[i])
		{
			r[i]=r[r[i]+1];
		}
	}
	ll llx=0;
	for (ri i=1; i<=n; ++i)
	{
		llx+=(ll)a[i]*(i-l[i]+1)*(r[i]-i+1);
	}
	cout<<llx;
}


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

void print(const vector<int>& xs) {
  for (const auto& x : xs) cout << x << ", ";
  cout << endl;
}

int N, M, X, Y;
vector<int> x, y;

main() {
  cin >> N >> M >> X >> Y;
  x = vector<int>(N);
  y = vector<int>(M);
  for (int n = 1; n <= N; n++) {
    cin >> x[n - 1];
  }
  for (int m = 1; m <= M; m++) {
    cin >> y[m - 1];
  }
  bool war = true;
  for (int Z = X + 1; Z <= Y; Z++) {
    bool b1 = true;
    bool b2 = true;
    for (const auto& i : x) {
      if (! (i < Z)) b1 = false;
    }
    for (const auto& i : y) {
      if (! (i >= Z)) b2 = false;
    }
    // printf("%d %d %d\n", Z, b1, b2);
    if (b1 && b2) war = false;
  }
  puts(war ? "War" : "No War");
}

Measured memory_bytes: 256
// Author := Abhishek Giri

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define V(type) vector<(type)>
#define all(c) ((c).begin(),(c).end())
#define in(var) cin>>(var)
#define out(var) cout<<(var)
#define on(var) cout<<var<<"\n"
#define f(i,n) for(ll i = 0 ; i < n ;i++)
#define mfor(i,init,n,b) for(ll i = (init) ; i < (n) ; i+= (b))
#define cfor(i,c) for(auto i = (c).begin() ; i!= (c).end(); i++)
#define el "\n"

/*##################################################################################*/


int prime[1000000] ;
vector < int > pr;
void calculateprime()
{
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; i <= 1000000 ; i++)
    {
        if(prime[i] == 0)
        {
            pr.pb(i);
            for(ll j = i*2 ; j <= 1000000 ; j += i )
            {
                prime[j] = 1 ;
            }
        }
    }
}


void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool isprime(ll n)
{
    for(ll i = 2 ; (ll) i*i <= n ; i++)
    {
        if(n % i == 0){
            return false;
        }
    }
    return true;
}

ll fib(int n)
{
    ll a = 0, b = 1, c, i;
    if( n == 0)
        return a;
    for (i = 2; i <= n; i++)
    {
        c = (a + b);
        a = b;
        b = c;
    }
    return b;
}


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

ll extendedgcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = extendedgcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

ll findgrouplcm(vector<int> &arr, int n)
{
    ll ans = arr[0];

    for (ll i = 1; i < n; i++)
        ans = (arr[i] * (ans/(gcd(arr[i], ans))));

    return ans;
}


ll powerwithmod(ll x, unsigned ll y, ll p)
{
    ll res = 1;

    x = x % p;

    if (x == 0) return 0;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;

        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}


bool comp(const pair<long long,ll> &a , const pair<ll ,ll > &b){
    if(a.first == b.first)  return a.second < b.second;
    return a.first > b.first;

    return false;
}

void solve(){
    ll n;
    in(n);
    if(n % 1000 == 0){
        out(0);
        return ;
    }

    out( 1000 - n%1000 );
}


int main() {
    fast();
    ll t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3648
N = int(input())
S = "MARCH"
dic = {s:0 for s in S}
for _ in range(N):
    s = input()[0]
    if s in S:
        dic[s] += 1
        
print(sum([dic[a] * dic[b] * dic[c] for a in S for b in S for c in S if a < b < c]))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
struct edge{int from, to;};

ll func(ll n, ll x){
    if(n<0) return 0;
    else return  n/x+1;
}

int main(){
    ll a,b,x;
    cin>>a>>b>>x;
    
    cout<<func(b,x)-func(a-1,x)<<endl;
    return 0;
}


Measured memory_bytes: 256