akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main()
{
	
	while(true){
		int N;
		int M[100];int A[100];int B[100];
		int Sum[500];
		for(int i=0;i<500;i++)Sum[i]=0;
		scanf("%d",&N);
		if(N==0)break;
		for(int i=0;i<N;i++){
			scanf("%d%d%d",&M[i],&A[i],&B[i]);
		}
		vector<int>X;
		for(int i=0;i<N;i++){
			X.push_back(A[i]);
			X.push_back(B[i]);
		}
		sort(X.begin(),X.end());
		for(int i=0;i<X.size()-1;i++){
			if(X[i]==X[i+1]){
				X.erase(X.begin()+i+1);i--;
			}
		}
		for(int i=0;i<N;i++){
			for(int j=0;j<2*N;j++){
				if(A[i]==X[j])A[i]=j;
				if(B[i]==X[j])B[i]=j;
			}
		}
		for(int i=0;i<N;i++){
			for(int j=A[i];j<B[i];j++){
				Sum[j]+=M[i];
			}
		}
		for(int i=0;i<500;i++){
			if(Sum[i]>150){
				printf("NG\n");goto a;
			}
		}
		printf("OK\n");a:;
	}
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N;

void solve() {
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    int acc = 0;
    for (int i = 0; i < N-2; ++i) {
        acc = -(A[i] + acc);
    }
    int x = A[N-2] + acc;
    int x_last = (A[N-1] + x) / 2;
    vector<int> B(N);
    B[N-1] = x_last*2;
    for (int i = N-2; i >= 0; --i) {
        x_last = A[i] - x_last;
        B[i] = x_last*2;
    }
    for (int i = 0; i < N; ++i) {
        printf("%d ", B[i]);
    }
    cout << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 2048
import collections 

N = int(input())
a_list = list(map(int, input().split()))

num_count = collections.Counter()
for a in a_list:
    num_count[a] += 1
    
total_count = 0
for n in num_count:
    total_count += num_count[n] * (num_count[n]-1) / 2

def count(a):
    return int(total_count - (num_count[a]-1))

for n in range(N):
    print(count(a_list[n]))

Measured memory_bytes: 26780
#include<iostream>

int calcArea(int h, int w);
int calcAround(int h, int w);

int main()
{
	int hight, width, area, around;

	std::cin >> hight >> width;

	area = calcArea(hight, width);
	around = calcAround(hight, width);

	std::cout << area << ' ' << around << std::endl;

	return 0;
}

int calcArea(int h, int w)
{
	int area = h * w;
	return area;
}

int calcAround(int h, int w)
{
	int around = 2 * h + 2 * w;
	return around;
}


Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include <vector>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e8, cnt;


int main(){
	ll a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	ll flag=a[0]*a[1];
	if(a[2]%2==0) cout<<0;
	else {
		ll b=(a[2]/2)+1;
		ll c=(a[2]/2);
		cout<<(flag*b)-(flag*c)<<endl;
	}
}



Measured memory_bytes: 256
s=input()
l=len(s)
ans=int(s[l-1])*(2**(l-1))
ak=1
sk=0

for i in range(2**(l-1)):
    for j in range(l-2,-1,-1):
        if (i>>j)&1==1:
            ak=1
        else:
            ak*=10
        sk=int(s[j])*ak
        ans+=sk
    ak=1

print(ans)

Measured memory_bytes: 9100
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]

####

def solve(K, S):
    MOD = 10 ** 9 + 7
    N = len(S)
    N2 = N + K

    BIG =N2
    fac = [1, 1]
    for x in xrange(2, BIG+1):
        fac.append(fac[-1] * x  %MOD)
    inv = [1] * (BIG + 1)
    inv[BIG] = pow(fac[-1], MOD-2, MOD)
    for x in xrange(BIG-1, -1, -1):
        inv[x] = inv[x+1] * (x+1) % MOD

    def binom(n, k):
        ans = fac[n]
        ans *= inv[n-k]
        ans %= MOD
        
        ans *= inv[k]
        ans %= MOD
        return ans

    pow25 = [1]
    for x in xrange(1, BIG + 1):
        pow25.append(pow25[-1] * 25  %MOD)

    ans = 0
    for n in xrange(N, N2 + 1):
        ans += binom(N2, n)   * pow25[N2- n] % MOD
        ans %= MOD
    return ans

print solve(rri(), rr())


Measured memory_bytes: 187076
/*
g++ -std=c++14 -o2 -Wall ABC113C.cpp -o .\out\ABC113C.out
.\out\ABC113C.out
*/

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

typedef long long ll;

int p[100005];
int y[100005];

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int>> tpl;
  for (int i = 0; i < m; ++i) {
    int pp, yy;
    cin >> pp >> yy;
    tpl.push_back(make_tuple(pp, yy, i));
  }
  sort(begin(tpl), end(tpl));
  int prev_ken = 0;
  int count = 1;
  int now_ken;
  vector<tuple<int, int, int>> ans;
  for (int i = 0; i < m; ++i) {
    now_ken = get<0>(tpl[i]);
    if (now_ken != prev_ken) {
      count = 1;
    }
    ans.push_back(make_tuple((int)get<2>(tpl[i]), now_ken, count));
    prev_ken = now_ken;
    ++count;
  }
  sort(begin(ans), end(ans));
  for (int i = 0; i < m; ++i) {
    printf("%06d%06d\n", get<1>(ans[i]), get<2>(ans[i]));
  }
}


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

int main() {
 int n,m;
 cin >> n >> m;
 vector<int> a(n);
 rep(i,n) cin >> a[i];
 int sum = 0;
 rep(i,n) sum+=a[i];
 float toku = (float) sum/(m*4);
 int count  = 0;
 rep(i,n) {
     if(a[i] >= toku){
         count++;
     }
 }
 if(count >= m){
     cout << "Yes" << endl;
 }
 else{
     cout << "No" << endl;
 }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

int N;

void solve()
{
	string s = to_string(N);
	if(s[0]=='7'||s[1]=='7'||s[2]=='7') cout << "Yes\n";
	else cout << "No\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	solve();
	return 0;
}

Measured memory_bytes: 3716
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

typedef long long ll;

int main(){
    int x;
    cin >> x;
    if(x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
struct node{
    int value;
    node *parent,*l,*r;
    node(){
        value=-2000000001;
        parent=l=r=NULL;
    }
};

void insert(node*,int);
void Preorder(node*);
void Inorder(node*);
void del(node*,int);
bool find(node*,int);
node *f_in(node*);
int main(void){
    int n,num;
    node *t=new node;
    string str;
    
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>str;
        if(str=="insert"){
            cin>>num;
            insert(t,num);
        }
        else if(str=="find"){
            cin>>num;
            if(find(t,num)==true) cout<<"yes"<<endl;
            else cout<<"no"<<endl;
        }
        else if(str=="delete"){
            cin>>num;
            del(t,num);
        }
        else{
            Inorder(t);
            cout<<endl;
            Preorder(t);
            cout<<endl;
        }
    }
    
    return 0;
}
void insert(node *t,int num){
    node *z=new node;
    
    z->value=num;
    if(t->parent==NULL && t->l==NULL && t->r==NULL && t->value==-2000000001){
        t->value=num;
        return;
    }
    while(z->parent==NULL){
        if(num > t->value){
            if(t->r==NULL){
                t->r=z;
                z->parent=t;
            }
            else    t=t->r;
        }
        else{
            if(t->l==NULL){
                t->l=z;
                z->parent=t;
            }
            else    t=t->l;
        }
    }
}
void Preorder(node *t){
	cout<<" "<<t->value;
	if(t->l!=NULL) Preorder(t->l);
	if(t->r!=NULL) Preorder(t->r);
}
void Inorder(node *t){
	if(t->l!=NULL) Inorder(t->l);
	cout<<" "<<t->value;
	if(t->r!=NULL) Inorder(t->r);
}
bool find(node *t,int num){
    if(t->value==num)   return true;
    if(t->value>num && t->l!=NULL)   return find(t->l,num);
    if(t->value<num && t->r!=NULL)  return find(t->r,num);
    return false;
}
void del(node *t,int num){
    node *x=new node,*y=new node;
    if(t->value==num){
        if(t->l==NULL && t->r==NULL){
            if(t->parent->l==t) t->parent->l=NULL;
            else t->parent->r=NULL;
            delete t;
        }
        else if(t->l!=NULL&&t->r!=NULL){
            x=f_in(t->r);
            t->value=x->value;
            del(x,x->value);
        }
        else{
            if(t->l!=NULL)  y=t->l;
            else y=t->r;
            x=t->parent;
            if(x->l==t) x->l=y;
            else x->r=y;
            y->parent=x;
            delete t;
        }
    }
    else{
        if(num < t->value&&t->l!=NULL)    del(t->l,num);
        else if(num > t->value&&t->r!=NULL) del(t->r,num);
    }
}
node *f_in(node* t){
    if(t->l==NULL)  return t;
    return f_in(t->l);
}

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

int main() {
  int64_t N, t, a, b, c, k, t1;
  cin >> N;
  cin >> t;
  k = 0;
  for ( int i = 0; i < N; i++){
    cin >> a;
    cin >> b;
    c = a*a + b*b;
    t1 = t*t;
    if ( c <= t1 ){
      k++;
    }
  }
  
  cout << k << endl;

  
  
}

Measured memory_bytes: 3624
n=int(input())
Ns=list(map(int, input().split() ) ) 
ans=0
for i in range(n):
  for j in range(i,n):
    for k in range(j,n):
      a , b , c = sorted([Ns[i] , Ns[j] , Ns[k]])
      if a+b>c and a!=b and b!=c:
        ans+=1
print(ans)


Measured memory_bytes: 74340
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		int[] ord = new int[N];
		for(int i=0;i<N;i++) ord[i] = i;
		Array.Sort(ord, (i,j) => -1 * (A[i].CompareTo(A[j])));
		//Console.WriteLine("ord:{0}",String.Join(" ",ord));
		var sl = new SortedList<int,int>();
		sl.Add(-2,-2);
		sl.Add(-1,-1);
		sl.Add(N,N);
		sl.Add(N+1,N+1);
		long tot = 0;
		for(int i=0;i<N;i++){
			int k = ord[i];
			long v = A[k];
			sl.Add(k,k);
			var idx = sl.IndexOfKey(k);
			var l1 = sl.Keys[idx - 2];
			var l0 = sl.Keys[idx - 1];
			var r0 = sl.Keys[idx + 1];
			var r1 = sl.Keys[idx + 2];
			// #...#...x...#...#
			//  L......RRRR.....
			//     L...RRRR.....
			//      L......RRRR.
			//         L...RRRR.
			//Console.WriteLine("{0} {1} {2} {3} {4}",l1,l0,k,r0,r1);
			if(l1 != -2){
				long rs = r0 - k;
				long ls = l0 - l1;
				tot += rs * ls * v;
			}
			if(r1 != N + 1){
				long rs = r1 - r0;
				long ls = k - l0;
				tot += rs * ls * v;
			}
		}
		Console.WriteLine(tot);


	}
	int N;
	long[] A;
	public Sol(){
		N = ri();
		A = rla();		
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
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;}

int cnt[1111];
signed main(){
    int N;
    cin>>N;
    for(int i=1;i<=N;i++){
        int n=i;
        for(int j=2;j<=N;j++){
            while(n%j==0){
                cnt[j]++;
                n/=j;
            }
        }
    }

    int ans=1;
    for(int i=2;i<=N;i++)ans=ans*(cnt[i]+1)%1000000007;
    cout<<ans<<endl;
    return 0;
}


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

const int N = 1e2 + 5;
const int W = 1e5 + 5;

long long dp [W];

int main () {
  int n, w;
  cin >> n >> w;
  for (int i = 0; i < n; i++) {
    int tempo, lucro;
    cin >> tempo >> lucro;
    vector<long long> cache (W);
    for (int j = tempo; j <= w; j++) {
      cache[j] = dp[j - tempo] + lucro;
    }
    for (int j = tempo; j <= w; j++) {
      dp[j] = max (dp[j], cache[j]);
    }
  }
  cout << dp[w] << '\n';
  return 0;
}

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

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

    vector<int> h(n);

    for(int i=0; i<n; i++) cin>>h[i];

    sort(h.begin(),h.end());

    int mi = 10000000000;

    for(int i=0; i<n+1-k; i++){

        if(h[k+i-1] -h[i] < mi){
            mi = h[k+i-1] - h[i];
        }
    }

    cout<<mi<<endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 998244353;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  int n;
  cin >> n;
  using psp = pair<string, pii>;
  vector<psp> v;
  rep(i, n) {
    string s;
    cin >> s;
    int p;
    cin >> p;
    v.eb(s, pii(p, i + 1));
  }
  sort(all(v), [](psp a, psp b) { if (a.F != b.F) return a.F < b.F; return a.S > b.S; });
  rep(i, n) cout << v[i].S.S << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

int main(){
	int n, x[100], y[100];
	
	scanf(" %d", &n);
	for(int i=0; i<n; ++i)
		scanf(" %d", &x[i]); 
	for(int i=0; i<n; ++i)
		scanf(" %d", &y[i]); 
		
	for(int p=1; p<=3; ++p){
		double d=0;
		for(int i=0; i<n; ++i)
			d += pow( fabs(x[i]-y[i]), p);
		
		printf("%lf\n", pow(d,1.0/p));
	}		
	
	double max=0;	
	for(int i=0; i<n; ++i)
		if(max < fabs(x[i]-y[i])) max = fabs(x[i]-y[i]);
	
	printf("%lf\n", max);	
	
	return 0;
}



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

n = int(input())
arr = list(map(int, input().split()))

res = [0] * (n + 1)

for i in range(1, n + 1)[::-1]:
    sum_res = sum(res[x] for x in range(i, n + 1, i))
    if sum_res % 2 != arr[i - 1]:
        res[i] = 1

print(sum(res))

if sum(res):
    ans = []
    for i, ele in enumerate(res):
        if ele:
            ans.append(i)
    print(*ans)


Measured memory_bytes: 14136
let () = Scanf.scanf "%d %d\n" @@ fun h w ->
  let ss = Array.init h @@ fun _ -> Scanf.scanf "%s\n" @@ fun s -> s in
  let lacc = Array.make_matrix h w 0 in
  let racc = Array.make_matrix h w 0 in
  let uacc = Array.make_matrix h w 0 in
  let dacc = Array.make_matrix h w 0 in
  for i = 0 to h - 1 do
    for j = 1 to w - 1 do
      if ss.(i).[j - 1] = '.' then
        lacc.(i).(j) <- lacc.(i).(j - 1) + 1
    done
  done;
  for i = h - 1 downto 0 do
    for j = w - 2 downto 0 do
      if ss.(i).[j + 1] = '.' then
        racc.(i).(j) <- racc.(i).(j + 1) + 1
    done
  done;
  for i = 1 to h - 1 do
    for j = 0 to w - 1 do
      if ss.(i - 1).[j] = '.' then
        uacc.(i).(j) <- uacc.(i - 1).(j) + 1
    done
  done;
  for i = h - 2 downto 0 do
    for j = w - 1 downto 0 do
      if ss.(i + 1).[j] = '.' then
        dacc.(i).(j) <- dacc.(i + 1).(j) + 1
    done
  done;
  Printf.printf "%d\n" @@
  Array.fold_left (Array.fold_left max) min_int @@
  Array.init h @@ fun i ->
    Array.init w @@ fun j ->
      if ss.(i).[j] = '#'
      then 0
      else 1 + lacc.(i).(j) + racc.(i).(j) + uacc.(i).(j) + dacc.(i).(j)


Measured memory_bytes: 166388
//#include<cstdio>
//#include<cstdlib>
#include <iostream>
#include <vector>
#include <queue>
//#include<bitset>
//#include<string>
//#include<stack>
//#include<set>
//#include<unordered_set>
//#include<map>
//#include<unordered_map>
//#include<cstring>
//#include<complex>
//#include<cmath>
//#include<iomanip>
//#include<numeric>
#include <algorithm>
#include <stdio.h>
//#include<list>
//#include<functional>
//#include<cassert>
using namespace std;
#define ll long long int
#define llu unsigned long long int
void pv(vector<ll> arr, ll size)
{

    for (ll i = 0; i < size; i++)
    {
        cout << arr[i] << ' ';
    }
}
void gv(vector<ll> &arr)
{
    ll size = arr.size();
    for (ll i = 0; i < size; i++)
    {
        cin >> arr[i];
    }
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, w;
    cin >> n >> w;
    vector<ll> val(n + 1), weight(n + 1);
    for (ll i = 1; i <= n; i++)
    {
        cin >> weight[i] >> val[i];
    }
    ll arr[n + 1][w + 1];
    ll curw = 0;
    for (ll i = 0; i <= n; i++)
    {
        for (ll j = 0; j <= w; j++)
        {
            if (i == 0 || j == 0)
                arr[i][j] = 0;
            else if (j - weight[i] < 0)
            {
                arr[i][j] = arr[i - 1][j];
            }
            else
            {
                arr[i][j] = max(arr[i - 1][j], val[i] + arr[i - 1][j - weight[i]]);
            }
            // cout << arr[i][j] << " ";
        }
        // cout << '\n';
    }
    cout << arr[n][w];
    return 0;
}

Measured memory_bytes: 79232
import java.util.*;

public class Main{
//public class abc167_a{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		String t = scan.next();	

		String ts = s + t.charAt(t.length() - 1);

		boolean flag = true;
		
		
		for(int i=0; i<t.length(); i++){
			if( Character.isUpperCase( t.charAt( i ) ) ) flag = false;
		}

		if( !(s.length()>0 && s.length() < 11) ) flag = false;

		if( !t.equals(ts) ) flag = false;


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

}

Measured memory_bytes: 26924
#include <stdio.h>
#include <iostream>
#include <math.h>


using namespace std;




int main() {
	char a;
	int n[4];
	int kari;
	int counter;
	int l;
	int s;
	int count;
	while (1) {
		counter = 0;
		count = 0;
		for (int i = 0; i < 4; i++) {
			cin >> a;
			n[i] = a - '0';
			if (n[i] == 0) {
				counter++;
			}
		}
		if (counter == 4) {
			break;
		}

		if (n[0] == n[1] && n[1] == n[2] && n[2] == n[3]) {
			cout << "NA" << endl;
			continue;
		}
		
		while (1) {
			if (n[0] == 6 && n[1] == 1 && n[2] == 7 && n[3] == 4) {
				break;
			}
			for (int i = 3; i > 0; i--) {
				for (int j = 0; j < i; j++) {
					if (n[j] < n[j+1]) {
						kari = n[j];
						n[j] = n[j+1];
						n[j+1] = kari;
					}
				}
			}
			l = n[0] * 1000 + n[1] * 100 + n[2] * 10 + n[3];
			s = n[3] * 1000 + n[2] * 100 + n[1] * 10 + n[0];
			kari = l - s;
			for (int i = 0; i < 4; i++) {
				n[i] = kari / (int)pow(10,3-i);
				kari = kari % (int)pow(10,3-i);
			}
			count++;
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1188
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    int res = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        while (x != 0 && x % 2 == 0) {
            x >>= 1;
            ++res;
        }
    }

    cout << res << '\n';
  

    return 0;
}

Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,a[200111];
int t[200111],ans[200111];
bool check(int x)
{
	for(int i=1;i<n+n;i++)if(a[i]>=x)t[i]=1;else t[i]=0;
	t[0]=t[1];t[n+n]=t[n+n-1];
	if(t[n]==t[n-1]||t[n]==t[n+1])return t[n];
	int l,r;
	for(l=n-1;l>=1&&t[l]!=t[l-1];l--);l++;
	for(r=n+1;r<n+n&&t[r]!=t[r+1];r++);r--;
	if(r-n>n-l)return t[l]^1;
	else return t[r]^1;
}
int main()
{
	get1(n);
	for(int i=1;i<n+n;i++)get1(a[i]);
	int l=1,r=n+n,mid;
	while(l<r-1)
	{
		mid=(l+r)>>1;
		if(check(mid))l=mid;
		else r=mid;
	}
	printendl(l);
	return 0;
}

Measured memory_bytes: 1792
void main() {
	auto r = ri;
	writeln(r*r);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
  var a []int
  a = scanNums(2)
  if (a[0]+a[1])%2 == 0{
    fmt.Printf("%d\n",int((a[0]+a[1])/2))
  }else{
    fmt.Println("IMPOSSIBLE")
  }
}

func scanNums(len int) (nums []int) {
    var num int
    for i := 0; i < len; i++ {
        fmt.Scan(&num)
        nums = append(nums, num)
    }
    return
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define Fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long

int32_t main() {
	Fast_IO

	int n; cin >> n;
	int steps = 0;
	int nc = n;
	int pp = 1;
	for (int i = 2; i * i <= nc; i++) {
		int j = i;

		while (n % j == 0) {
			n /= j;
			steps++;
			j *= i;
		}
		while (n % i == 0) {
			n /= i;
		}
	}
	// if (n != 1)
	// 	steps++;
	if (n != 1)
		steps++;
	cout << steps;
}

Measured memory_bytes: 3692
#include <stdio.h>
 
int main(void)
 
{
 
  char in[1001];
 
 
  int out,i;
 
 
  for(;;)
 
 
  {
 
 
    scanf("%s",in);
 
 
    if(in[0]=='0')
 
 
    {
 
 
      return 0;
 
 
    }
 
 
    out=0;
 
 
    for(i=0;in[i]!='\0';i++)
 
 
    {
 
 
      out +=in[i] - '0';
 
 
    }
 
 
    printf("%d\n",out);
 
 
  }
 
 
}

Measured memory_bytes: 536
from math import atan, pi, degrees
a, b, x = map(int, input().split())
ans = 0
if x > a*a*b/2:
    ans = atan(2*(a*a*b-x)/a**3)
else:
    ans = pi/2 - atan((2*x)/(a*b*b))
print(degrees(ans))

Measured memory_bytes: 38896
N = int(input())
S = list(str(input()))

min = 3*10**5
cnt = 0

cnt = S.count("E")
min = cnt

for i in S:
  if i == "E":
    cnt -= 1
  elif i == "W":
    cnt += 1
  if min >= cnt:
    min = cnt

print(min)

Measured memory_bytes: 5792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  for(int i=0;i<n;i++) cin >> s.at(i);
  sort(s.begin(),s.end());
  for(int i=0;i<n;i++) cout << s.at(i);
  cout << endl;
}

Measured memory_bytes: 256
#b
a,b,c=map(int,input().split())
k=int(input())
for i in range(k):
    if a>=b:
        b*=2
    else:
        if b>=c:
            c*=2
        else:
            break

if a<b<c:
    print('Yes')
else:
    print('No')

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

using namespace std;

typedef long long ll;

const ll maxn = 100;
const ll ZERO = 0;
const ll SADAT = 7.84e-17;
const ll INF = 1e10;
const ll mod = 1e9+7;

#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);

int a[maxn];
int b[maxn];
int n;

int main(){
	cin >> n;
	for(int i = 0 ; i < n-1 ;i ++){
		cin >> b[i];
	}
	fill (a, a+ n , 1e8);
	for (int i = 0 ; i < n-1; i ++){
		if (a[i] > b[i]){
			a[i] = b[i];
		}
		if (a[i+1] > b[i]){
			a[i+1] = b[i];
		}
	}
	ll ans  = 0 ;
	for (int  i = 0 ; i < n ; i ++){
		ans += a[i];
	}
	cout << ans;

	return(0);
}
//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, l is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
#include <atcoder/all>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

vector<ll> yakusu(ll n){
  vector<ll> ret;
  for(ll p = 1; p*p <= n; p++){
    if(n%p == 0){
      ret.push_back(p);
      if(p*p != n){
        ret.push_back(n/p);
      }
    }
  }
  sort(all(ret));
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  int n,m;
  cin>>n>>m;
  atcoder::scc_graph G(n);
  rep(i,m){
    int a,b;cin>>a>>b;
    G.add_edge(a,b);
  }
  auto result = G.scc();
  cout<<result.size()<<endl;
  rep(i,result.size()){
    int num = result[i].size();
    auto row = result[i];
    cout<<num<<" ";
    rep(j,num){
      cout<<row[j]<<" ";
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 40628
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int count = 0;
  for(char j:s){
    if(j=='A'){
      count++;
    }
  }
    if(count==0 || count == 3){
      cout<<"No";
    }
      else{
        cout<<"Yes";
      }
  }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>	// tansform??¨

using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;

int main() {

	string a;
	string scin;
	int sum[26] = { 0 };

	// ??\???????????????????????????
	
	while (cin >> a)
	{
		scin += a;
	}
	
	// ???????????????????????????????????????????????£?????????
	//scin = "AaBbCcdDeE";
	// ??????????°????????????????
	transform(scin.begin(), scin.end(), scin.begin(), ::tolower);

	// ????????????
	for (size_t i = 0; i < scin.size(); i++)
	{
		sum[scin[i] - 'a'] += 1;
	}

	// ??????
	char c;
	for (size_t i = 0; i < 26; i++)
	{
		c = i + 'a';
		cout << c << " : " << sum[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3172
import sys
sys.setrecursionlimit(10**9)
 
 
N, M = map(int, input().split())
 
G = [[] for _ in range(N + 1)]
for i in range(M):
    x, y = map(int, input().split())
    G[x] += [y]
# print(G)
 
dp = [-1] * (N + 1)
 
 
def func(n):
    if dp[n] != -1:
        return dp[n]
    cnt = 0
	# 先にノードが存在する場合
	# ノードが存在しない場合は、cnt=0のままforをすっ飛ばす
    for m in G[n]:
        cnt = max(cnt, func(m) + 1)
    dp[n] = cnt
    return cnt
 
 
for i in range(1, N + 1):
    func(i)
 
# print(dp)
print(max(dp))

Measured memory_bytes: 61120
#include <iostream>
using namespace std;
int main(void)
{
	int a, b, t;
	cin >> a >> b;
	if (a < b)
		t = a, a = b, b = t;
	while (b != 0)
	{
		t = b;
		b = a % b;
		a = t;
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(void) {

    int N, K;
    scanf("%d %d", &N, &K);

    int rest = 1;
    for (int i = 0; i < N - 1; ++i) {
        rest *= K - 1;
    }

    printf("%d\n", K * rest);

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#include<iomanip>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
using lll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
void swap(ll &a, ll &b) {
    ll tmp = a;
    a = b;
    b = tmp;
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}
int main() {
  ll M1,D1;
  ll M2,D2;
  cin>>M1>>D1>>M2>>D2;
  if(M1!=M2){
    cout<<1<<endl;
  }else{
    cout<<0<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        int x, y, z, m, min, e;

        Scanner scan = new Scanner(System.in);
        while((e = scan.nextInt()) != 0){
            min = Integer.MAX_VALUE;
            for(z = 0; z*z*z <= e; ++z){
                int z3 = z*z*z;
                for(y = 0; y*y + z3 <= e; ++y){
                    int y2 = y*y;
                    x = e - y2 - z3;
                    m = x + y + z;
                    min = Math.min(m, min);
                }
            }
            System.out.println(min);
        }
    }
}

Measured memory_bytes: 26552
/** Author: Nicklaus **/
 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
#define PI 3.14159265358979324

int main(){
	int a, b;
	cin>>a>>b;
	if(b%a==0) cout<<a+b;
	else cout<<b-a;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main{
    public static void main(String[] args) throws Exception{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String num1 = br.readLine();
        String[] num2 = num1.split(" ");

        int a = Integer.parseInt(num2[0]);
        int b = Integer.parseInt(num2[1]);

        int d = a / b;
        int r = a % b;
        double n = (double)a / b;
        String f = String.format("%.6f", n);

        System.out.println(d + " " + r + " " + f);
    }
}

Measured memory_bytes: 24740
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int x = sc.nextInt();
		System.out.println((n*1.0)/(x*1.0));
		
	}
	
	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 20308
from scipy.optimize import fmin
l=[list(map(int, input().split()))for i in range(int(input()))]
def g(s):
    a,b=s
    d=0
    for i,j in l:
        d=max(d,(i-a)**2+(j-b)**2)
    return d
x,y=fmin(g,[500,500],ftol=10**-7,disp=0)
print(g((x,y))**0.5)

Measured memory_bytes: 27456
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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

// 1 つの証言を表す構造体
using pint = pair<int, int>; // 「人」と「0 or 1」

 // 入力
int N;
vector<vector<pint>> v;

// 整数 bit に対応する「決め打ち」が整合しているかを判定
bool judge(int bit) {

	// i 人目の証言を検証する
	for (int i = 0; i < N; ++i) {

		// i 人目が「不親切」だったら、証言はすべて無意味
		if (!(bit & (1 << i))) continue;

		// それぞれ確認
		for (pint xy : v[i]) {
			int x = xy.first; // x が
			int y = xy.second; // y = 1: 正直、y = 0: 不親切

							   // y = 1 なのに「不親切」だったらダメ
			if (y == 1 && !(bit & (1 << x))) return false;

			// y = 0 なのに「正直者」だったらダメ
			if (y == 0 && (bit & (1 << x))) return false;
		}
	}
	return true;
}

int main() {
	cin >> N;
	v.resize(N);
	for (int i = 0; i < N; ++i) {
		int A; cin >> A;
		v[i].resize(A);
		for (int j = 0; j < A; ++j) {
			cin >> v[i][j].first >> v[i][j].second;
			--v[i][j].first; // 0-indexed に
		}
	}


	int res = 0;
	for (int bit = 0; bit < (1 << N); ++bit) {

		// 矛盾 check
		if (judge(bit)) {

			// bit に含まれる人数を数える
			int count = 0;
			for (int i = 0; i < N; ++i) {
				if (bit & (1 << i)) ++count;
			}
			res = max(res, count);
		}
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
    if p[i] == i + 1:
        tmp = p[i]
        p[i] = p[i + 1]
        p[i + 1] = tmp
        ans += 1
if p[n - 1] == n:
    tmp = p[n - 1]
    p[n - 1] = p[n - 2]
    p[n - 2] = tmp
    ans += 1
print(ans)


Measured memory_bytes: 13880
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int k;
int main(){
    scanf("%d",&k);
    if(k==1){
        printf("1\n");
        return 0;
    }
    int now=0,now2=0;
    for(int i=1;i<=1000000;i++){
        now2=(10*now2%k+7)%k;
        if(now2==0){
            printf("%d\n",i);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}

Measured memory_bytes: 3820
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()
n, m = [int(x) for x in input().split()]
s = [[int(x) - 1 for x in input().split()][1:] for i in range(m)]
p = [int(x) for x in input().split()]
print(sum(1 for mask in range(1 << n) if all(sum((mask >> bulb) & 1 for bulb in s[i]) % 2 == p[i] for i in range(m))))

Measured memory_bytes: 9168
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T>
struct BIT{
    int n;
    vector<T> d;
    BIT(int n = 0):n(n), d(n+1){}
    void add(int i, T x = 1){
        for(i++; i <= n; i += i&-i){
            d[i] += x;
        }
    }
    T sum(int i){
        T x = 0;
        for(i++; i; i -= i&-i){
            x += d[i];
        }
        return x;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    BIT<ll> bit(n+1);
    vector<ll> a(n);
    ll ans = 0;
    rep(i,n){
        cin >> a[i];
        bit.add(i, a[i]);
        ll sum = bit.sum(i);
        if(i%2 == 1){
            if(sum >= 0){
                ans += 1 + sum;
                bit.add(i, -(1 + sum));
            }
        }
        else{
            if(sum <= 0){
                ans += 1 - sum;
                bit.add(i, 1 - sum);
            }
        }
    }
    ll cmp = 0;
    BIT<ll> bit2(n+1);
    rep(i,n){
        bit2.add(i, a[i]);
        ll sum = bit2.sum(i);
        if(i%2 == 0){
            if(sum >= 0){
                cmp += 1 + sum;
                bit2.add(i, -(1 + sum));
            }
        }
        else{
            if(sum <= 0){
                cmp += 1 - sum;
                bit2.add(i, 1 - sum);
            }
        }
    }
    chmin(ans, cmp);
    cout << ans << endl;
    return 0;
}

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

#define x first
#define y second

using namespace std;

const int maxn = (1 << 17) + 10;

int n, ans, tag, f[maxn], g[maxn];
vector<pair<int, int> > a, b;

int F(int i) {
	return f[i] == i ? i : f[i] = F(f[i]);
}

int main() {
	scanf("%d", &n);
	for (int i = 0, s = 0; i < n; ++i) {
		int x;
		scanf("%d", &x);
		a.push_back(make_pair(x, i));
		s ^= x;
		if(i == n - 1) {
			a.push_back(make_pair(s, n));
		}
	}
	for (int i = 0, s = 0; i < n; ++i) {
		int x;
		scanf("%d", &x);
		b.push_back(make_pair(x, i));
		s ^= x;
		if(i == n - 1) {
			b.push_back(make_pair(s, n));
		}
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	for(int i = 0; i <= n; ++i) {
		if(a[i].x != b[i].x) {
			return !puts("-1");
		}
		g[a[i].x = (i ? a[i - 1].x + (b[i].x != b[i - 1].x) : 0)] = 1;
		f[a[i].x] = a[i].x;
	}
	for (int i = 0; i <= n; ++i) {
		b[i].x = a[i].x;
	}
	auto cmp = [&](pair<int, int> x, pair<int, int> y) {
		return x.y < y.y;
	};
	sort(a.begin(), a.end(), cmp);
	sort(b.begin(), b.end(), cmp);
	for (int i = 0; i < n; ++i) {
		if(a[i] != b[i]) {
			++ans;
			f[F(a[i].x)] = F(b[i].x);
		}
	}
	for (int i = 0; i < n; ++i) {
		if(a[i] != b[i] && F(a[i].x) != F(a[n].x) && F(a[i].x) != F(b[n].x)) {
			ans += g[F(a[i].x)];
			g[F(a[i].x)] = 0;
		}
	}
	return !printf("%d\n", ans);
}

Measured memory_bytes: 4340
#include <stdio.h>
#define N 100000
struct Card
{
  char suit;
  int value;
  int key;
};

struct Card A[N];

int Partition(int p, int r)
{
  int x, i, j;
  struct Card tmp;
  x = A[r].value;
  i = p - 1;

  for(j = p;j <= r - 1;j++)
    {
      if(A[j].value <= x)
	{
	  i++;
	  tmp = A[i];
	  A[i] = A[j];
	  A[j] = tmp;
	}
    }

  tmp = A[i + 1];
  A[i + 1] = A[r];
  A[r] = tmp;

  return i + 1;
}


void Quicksort(int p, int r)
{
  int q;

  if(p < r)
    {
      q = Partition(p, r);
      Quicksort(p, q - 1);
      Quicksort(q + 1, r);
    }
}


int main()
{
  int n, i;
  char ch;

  scanf("%d%c",&n,&ch);

  for(i = 1;i <= n;i++)
    {
      scanf("%c%c%d%c",&A[i].suit,&ch,&A[i].value,&ch);
      A[i].key = i;
    }

  Partition(1, n);
  Quicksort(1, n);

  for(i = 1;i <= n;i++)
    {
      if(A[i].value == A[i + 1].value && A[i].key > A[i + 1].key)
	{
	  printf("Not stable\n");
	  break;
	}
    }

      if(i == n + 1)
	{
	  printf("Stable\n");
	}

      for(i = 1;i <= n;i++)
	{
	  printf("%c %d\n",A[i].suit,A[i].value);
	}

      return 0;
}

Measured memory_bytes: 1780
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> Edge;
typedef pair<int, P> State;
const int INF = 1 << 30;
vector<Edge> G[100];
int cost[100][101];
int main() {
	int N, M, L;
	while (cin >> N >> M >> L, N) {
		for (int i = 0; i < N; i++) G[i].clear();
		for (int i = 0; i < M; i++) {
			int A, B, D, E;
			cin >> A >> B >> D >> E;
			A--; B--;
			G[A].push_back(Edge(B, P(D, E)));
			G[B].push_back(Edge(A, P(D, E)));
		}
		for (int i = 0; i < N; i++) {
			for (int j = 0; j <= L; j++) cost[i][j] = INF;
		}
		cost[0][L] = 0;
		priority_queue<State, vector<State>, greater<State> > Q;
		Q.push(State(0, P(0, L)));
		while (!Q.empty()) {
			State s = Q.top(); Q.pop();
			int d = s.first;
			int from = s.second.first;
			int budget = s.second.second;
			if (cost[from][budget] < d) continue;
			for (int i = 0; i < G[from].size(); i++) {
				int to = G[from][i].first;
				int D = G[from][i].second.first;
				int E = G[from][i].second.second;
				if (cost[to][budget] > cost[from][budget] + E) {
					cost[to][budget] = cost[from][budget] + E;
					Q.push(State(cost[to][budget], P(to, budget)));
				}
				if (D <= budget) {
					if (cost[to][budget - D] > cost[from][budget]) {
						cost[to][budget - D] = cost[from][budget];
						Q.push(State(cost[to][budget - D], P(to, budget - D)));
					}
				}
			}
		}
		int ans = INF;
		for (int i = 0; i <= L; i++) {
			ans = min(ans, cost[N - 1][i]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3484
/*
	Copyright: razouq (c)
	Author: Anass BENDARSI
	Date: 07-Mar-20 1:02:05 PM
	flamers will **** you
*/
//#include<flamers.h>

#include "bits/stdc++.h"
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define PB push_back
#define POB pop_back

using namespace std;

int main(){
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie();
	string s;
	cin>>s;
	int a = 0, b = 0;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == 'A') a++;
		else b++;
	}
	if(a == 3 || b == 3) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256