akhauriyash/Code-Regression huggingface dataset:
N, M, C = map(int, input().split())
b = [int(i) for i in input().split()]
a = []
for i in range(N):
    a.append([int(i) for i in input().split()])

count = 0
for i in range(N):
    tmp = 0
    for j in range(M):
        tmp += b[j] * a[i][j]
    if tmp + C > 0:
        count += 1

print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans=0;
    for(int i=1;i<n-1;i++){
        if(s[i-1]=='A'&&s[i]=='B'&&s[i+1]=='C')
        ans++;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll a,b,c;

    //input
    cin>>a>>b>>c;

    //calculation answer
    ll answer=0;
    if(a%2&&b%2&&c%2) answer=min({a*b,b*c,c*a});
    cout<<answer<<endl;
    return 0;
}

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

def solve():
    r, D, x2000 = list(map(int, input().split()))
    x = [0] * 11
    x[0] = x2000
    for i in range(1, 11):
        x[i] = r*x[i-1] - D
        print(x[i])

if __name__ == "__main__":
    solve()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  string S,T;
  cin >> S >> T;
  ll ans = 0;
  rep(i,S.size() - T.size() + 1){
    ll check = 0;
    rep(j,T.size()){
      if(T[j] == S[j+i]){
        check++;
      }
    }
    ans = max(ans,check);
  }
  cout << T.size() - ans;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int n , a  , b;
    cin>>n>>a>>b;
    cout<<min(a * n , b )<<endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

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

using namespace std;
using ll = long long;
vector<pair<int,int>> jiko;
vector<int> imo;
bool solve(){
    int n;
    cin>>n;
    if(n==0)return false;

    jiko.clear();

    for(int i = 0;i < n;++i) {
        int h,m,s;
        scanf("%d:%d:%d",&h,&m,&s);
        int l=h*3600+m*60+s;

        scanf("%d:%d:%d",&h,&m,&s);
        int r=h*3600+m*60+s;

        jiko.emplace_back(l,r);
    }

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

    imo.assign(3600*24+1,0);
    for(int i = 0;i < n;++i) {
        imo[jiko[i].first]++;
        imo[jiko[i].second]--;
    }
    int ans=imo[0];
    for(int i = 0;i < 3600*24;++i) {
        imo[i+1]+=imo[i];
        ans=max(ans,imo[i+1]);
    }

    cout<<ans<<endl;


    return true;
}

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



Measured memory_bytes: 3336
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define repd(i,a,b) for (ll i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 10000007
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(void)
{
	int C, J;
	cin >> C >> J;
	int m=0;
	if(C==3) m += 100000;
	else if(C==2) m += 200000;
	else if(C==1)m += 300000;
	
	if(J==3) m += 100000;
	else if(J==2) m += 200000;
	else if(J==1)m += 300000;
	
	if(C==1 && J==1) m += 400000;
	
	cout << m << endl;
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    ll n;cin>>n;
    map<ll,ll>a;
    set<ll>b;
    for(ll i=2;i*i<=n;++i){
        if(n%i==0){
            b.insert(i);
            while(n%i==0){
                n/=i;
                a[i]++;
            }
        }
    }
    if(n>1){b.insert(n);a[n]++;}
    ll ans=0;
    for(auto x : b){
        int c=1;
        while(a[x]>=c){
            ans++;
            a[x]-=c;
            c++;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

const int N = 15;

int mat[N][N], n, m, r, c, size, o, angle;
bool vis[N][N];

void rotate(int y, int x, int size){
	static int tmp[N][N];
	for(int i=0;i<N;i++) for(int j=0;j<N;j++) tmp[i][j] = mat[i][j];
	for(int i=0;i<size;i++){
		for(int j=0;j<size;j++){
			mat[y+i][x+j] = tmp[y+size-1-j][x+i];
		}
	}
}

void reversal(int y, int x, int size){
	for(int i=0;i<size;i++){
		for(int j=0;j<size;j++){
			mat[y+i][x+j] = 1 - mat[y+i][x+j];
		}
	}
}

void left_shift(int y){
	int tmp = mat[y][0];
	for(int i=0;i+1<n;i++) mat[y][i] = mat[y][i+1];
	mat[y][n-1] = tmp;
}

void right_shift(int y){
	int tmp = mat[y][n-1];
	for(int i=n-1;i>0;i--) mat[y][i] = mat[y][i-1];
	mat[y][0] = tmp;
}

void island_reversal(int y, int x, int col){
	static int dy[4] = {-1, 0, 1, 0};
	static int dx[4] = {0, 1, 0, -1};
	vis[y][x] = true;
	mat[y][x] = 1 - mat[y][x];
	for(int i=0;i<4;i++){
		int ny = y + dy[i];
		int nx = x + dx[i];
		if(min(ny, nx) < 0 || max(ny, nx) >= n) continue;
		if(mat[ny][nx] != col) continue;
		island_reversal(ny, nx, col);
	}
}

void print(){
	for(int i=0;i<n;i++){
		cout << mat[i][0];
		for(int j=1;j<n;j++){
			cout << " " << mat[i][j];
		}
		cout << endl;
	}
}

int main(){
	cin >> n >> m;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin >> mat[i][j];
	for(int i=0;i<m;i++){
		//print(); cout << endl;
		cin >> o;
		if(o == 0){//rotate
			cin >> r >> c >> size >> angle;
			r--; c--;
			for(int j=0;j<angle/90;j++) rotate(r, c, size);
		}else if(o == 1){//reversal
			cin >> r >> c >> size;
			r--; c--;
			reversal(r, c, size);
		}else if(o == 2){//left-shift
			cin >> r;
			r--;
			left_shift(r);
		}else if(o == 3){//right-shift
			cin >> r;
			r--;
			right_shift(r);
		}else if(o == 4){//island reversal
			cin >> r >> c;
			r--; c--;
			fill(vis[0], vis[3], false);
			island_reversal(r, c, mat[r][c]);
		}
	}
	print();
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

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

struct dat{
	int x1, y1, x2, y2;
};

int h, w;

void putroot(pii p1, pii p2, vector<dat>& v){
	int a1, b1, a2, b2;
	a1 = p1.first;
	b1 = p1.second;
	a2 = p2.first;
	b2 = p2.second;

	while(a1 != a2 || b1 != b2){
		int s1, t1;
		s1 = a1;
		t1 = b1;
		if(a1 & 1){
			if(b1 == w) s1++;
			else t1++;
		}else{
			if(b1 == 1) s1++;
			else t1--;
		}
		v.push_back((dat){a1, b1, s1, t1});
		a1 = s1;
		b1 = t1;
	}
}

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


	cin >> h >> w;

	int a[h+1][w+1];
	vector<pii> ps;
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++) {
			cin >> a[i][j];
		}
	}

	for(int i = 1; i <= h; i++){
		if(i & 1){
			for(int j = 1; j <= w; j++) {
				if(a[i][j] & 1) ps.push_back((pii){i, j});
			}
		}else{
			for(int j = w; j >= 1; j--) {
				if(a[i][j] & 1) ps.push_back((pii){i, j});
			}
		}
	}

	int n = ps.size();
	vector<dat> ans;
	for(int i = 0; i < n; i += 2){
		if(i+1 >= n) break;
		putroot(ps[i], ps[i+1], ans);
	}

	cout << ans.size() << endl;
	rep(i, ans.size()){
		dat d = ans[i];
		cout << d.x1 << " " << d.y1 << " " << d.x2 << " " << d.y2 << endl;
	}
}


Measured memory_bytes: 7152
#include <stdio.h>

int temp[5000000], a=0;   

void MergeSort(int x[ ], int left, int right);

  /* 配列 x[ ] の left から right の要素のマージソートを行う */
void MergeSort(int x[ ], int left, int right)
{
    int mid, i, j, k;
	
    if (left >= right)              /* 配列の要素がひとつなら */
        return;                     /* 何もしないで戻る */

                                    /* ここでは分割しているだけ */
    mid = (left + right) / 2;       /* 中央の値より */
    MergeSort(x, left, mid);        /* 左を再帰呼び出し */
    MergeSort(x, mid + 1, right);   /* 右を再帰呼び出し */

      /* x[left] から x[mid] を作業領域にコピー */
    for (i = left; i <= mid; i++)
        temp[i] = x[i];

      /* x[mid + 1] から x[right] は逆順にコピー */
    for (i = mid + 1, j = right; i <= right; i++, j--)
        temp[i] = x[j];

    i = left;         /* i とj は作業領域のデーターを */
    j = right;        /* k は配列の要素を指している */

    for (k = left; k <= right; k++)    /* 小さい方から配列に戻す */
      if (temp[i] <= temp[j]) {       /* ここでソートされる */
	x[k] = temp[i++];
	a++;
      }
      else{
	x[k] = temp[j--];
	a++;
      }
}

int main()
{
  int i, n;
  /* ソートされるデータ */
  int x[500000];

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

  MergeSort(x, 0, n - 1);

  /* ソート後のデータを表示 */
  for (i = 0; i < n; i++){
    if(i !=0 ) printf(" ");
    printf("%d", x[i]);
  }
  printf("\n%d\n", a);
  
  return 0;   
}



Measured memory_bytes: 5600
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<cmath>
#include<algorithm>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=1e3+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
int main()
{
	char s[maxn];
	scanf("%s",s);
	int i,len=strlen(s);
	for(i=0;i<len;i++)cout<<'x';
	cout<<endl;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int N;
        long[] Q;
        long[] V;
        long[] C;
        {
            string[] str = Console.ReadLine().Split(' ');
            long[] stack = new long[int.Parse(str[1])+1];
            int p = 1;
            N = int.Parse(str[0]);
            stack[0] = N;
            for (int i=0;i<int.Parse(str[1]);i++){
                long q = long.Parse(Console.ReadLine());
                while(p > 0 && stack[p-1] >= q){
                    p--;
                }
                stack[p] = q;
                p++;
            }
            Q = new long[p];
            Array.Copy(stack,0,Q,0,p);
        }
        int N2 = (int)Q[0];
        int l = Q.Length+N2-1;
        V = new long[l];
        C = new long[l];
        C[l-1] = 1;
        for(int i=0;i<N2;i++){
            V[i] = i+1;
        }
        for(int i=N2;i<l;i++){
            V[i] = Q[i-N2+1];
        }
        for(int i=l-1;i>=N2;i--){
            if(C[i] != 0){
                long v = V[i];
                C[i-1] += v/V[i-1]*C[i];
                v %= V[i-1];
                int p = i-2;
                while(v > N2){
                    int f = 0;
                    int t = p;
                    while(f != t){
                        int c = (f+t+1)/2;
                        if(v >= V[c]){
                            f = c;
                        }
                        else{
                            t = c-1;
                        }
                    }
                    C[f] += v/V[f]*C[i];
                    v %= V[f];
                    p = f-1;
                }
                if(v != 0){
                    C[v-1] += C[i];
                }
            }
        }
        long count = 0;
        for(int i=0;i<N2;i++){
            count += C[i];
        }
        for(int i=0;i<N2;i++){
            sb.Append(count+"\n");
            count -= C[i];
        }
        for(int i=N2;i<N;i++){
            sb.Append("0\n");
        }
    }
}

Measured memory_bytes: 27216
#include <iostream>
#include <vector>

using namespace std;

const int dh[8]={1, 0, -1, 0, 1, 1, -1, -1};
const int dw[8]={0, 1, 0, -1, 1, -1, 1, -1};

int main() {
    int H, W;
    cin >> H >> W;
    
    vector<string> field(H);
    for(int h=0; h<H; h++) {
        cin >> field[h];
    }
    
    for(int h=0; h<H; h++) {
        for(int w=0; w<W; w++) {
            if(field[h][w]!='.') continue;
            
            int cnt=0;
            for(int dir=0; dir<8; dir++) {
                int curh=h+dh[dir];
                int curw=w+dw[dir];
                
                if(curh<0 || curh>=H || curw<0 || curw>=W) continue;
                if(field[curh][curw]=='#') cnt++;
            }
            field[h][w] = (char)('0'+cnt);
        }
    }
    
    for(int h=0; h<H; h++) {
        cout << field[h] << endl;
    }
    

    return 0;
    
}

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

typedef long long ll;
typedef tuple<ll, ll, ll> tlll;
typedef pair<ll, ll> Pll;

ll N, M, S;
vector<vector<tlll>> graph;
vector<Pll> excha;

constexpr ll INF = 1e14;
constexpr ll MAXCOST = 2600;

int main() {
    cin >> N >> M >> S;
    graph.resize(N);
    for (int i = 0; i < M; i++) {
        ll U, V, A, B; cin >> U >> V >> A >> B;
        U--; V--;
        graph[U].push_back(tlll(V, A, B));
        graph[V].push_back(tlll(U, A, B));
    }
    excha.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> excha[i].first >> excha[i].second;
    }

    vector<vector<ll>> ans(N, vector<ll>(MAXCOST+1, INF));
    // time, node, money;
    priority_queue<tlll, vector<tlll>, greater<tlll>> pq;
    pq.push(tlll(0, 0, min(S, MAXCOST)));

    while (!pq.empty()) {
        ll t, n, m; tie(t, n, m) = pq.top(); pq.pop();
        if (ans[n][m] != INF) continue;

        ans[n][m] = t;
        ll nxt = m + excha[n].first;
        ll tt = t + excha[n].second;
        if (nxt <= MAXCOST) {
            if (ans[n][nxt] > tt) pq.push(tlll(tt, n, nxt));
        }
        for (auto x : graph[n]) {
            ll u, a, b; tie(u, a, b) = x;
            if (m >= a) {
                if (ans[u][m-a] > t+b) pq.push(tlll(t+b, u, m-a));
            }
        }
    }
    for (int i = 1; i < N; i++) {
        ll a = INF;
        for (int j = 0; j <= MAXCOST; j++) {
            a = min(a, ans[i][j]);
        }
        cout << a << endl;
    }
}


Measured memory_bytes: 10392
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N = int(input())
A  = factorization(N) 

count = 0
for i in A:
  judge = 1
  temp = i[1]
  while temp >= judge:
    count += 1
    temp -=judge
    judge += 1

if N == 1:
  count = 0

print(count)

Measured memory_bytes: 9492
#include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;
int main(){
    double x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    double d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    printf("%.4f\n", d);
}


Measured memory_bytes: 3284
from collections import Counter
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

def solve():
    INF = 10**10

    # Union-Findデータ構造
    class UnionFind:
        def __init__(self, numV):
            self.pars = list(range(numV))
            self.ranks = [0] * numV
        def getRoot(self, x):
            par = self.pars[x]
            if par != x:
                self.pars[x] = par = self.getRoot(par)
            return par
        def merge(self, x, y):
            x, y = self.getRoot(x), self.getRoot(y)
            if x == y: return
            if self.ranks[x] < self.ranks[y]:
                self.pars[x] = y
            else:
                self.pars[y] = x
                if self.ranks[x] == self.ranks[y]:
                    self.ranks[x] += 1
        def isSame(self, x, y):
            return self.getRoot(x) == self.getRoot(y)
        def updatePars(self):
            for v in range(len(self.pars)):
                self.getRoot(v)

    N = int(input())
    #pts = [tuple(map(lambda x: int(x)-1, input().split())) for _ in range(N)]
    pts = []
    for i in range(N):
        x, y = map(int, input().split())
        x, y = x-1, y-1
        pts.append((x, y, i))

    UF = UnionFind(N)

    # x昇順
    pts.sort(key=lambda x: x[0])
    stack = [(INF, INF, -1)]
    for x, y, i in pts:
        while stack[-1][1] < y:
            x0, y0, i0 = stack.pop()
            UF.merge(i0, i)
        stack.append((x, y, i))

    # x降順
    #pts.sort(key=lambda x: x[0])
    stack = [(-INF, -INF, -1)]
    for x, y, i in reversed(pts):
        while stack[-1][1] > y:
            x0, y0, i0 = stack.pop()
            UF.merge(i0, i)
        stack.append((x, y, i))

    # y昇順
    pts.sort(key=lambda x: x[1])
    stack = [(INF, INF, -1)]
    for x, y, i in pts:
        while stack[-1][0] < x:
            x0, y0, i0 = stack.pop()
            UF.merge(i0, i)
        stack.append((x, y, i))

    # y降順
    #pts.sort(key=lambda x: x[1])
    stack = [(-INF, -INF, -1)]
    for x, y, i in reversed(pts):
        while stack[-1][0] > x:
            x0, y0, i0 = stack.pop()
            UF.merge(i0, i)
        stack.append((x, y, i))


    UF.updatePars()
    #print('# UF.pars:', UF.pars, file=sys.stderr)

    cnt = Counter(UF.pars)
    #print('# cnt:', cnt, file=sys.stderr)

    anss = [0] * N
    for i in range(N):
        anss[i] = cnt[UF.pars[i]]

    print('\n'.join(map(str, anss)))


solve()


Measured memory_bytes: 147836
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int a[1010], b[1010];
int c[1010][15];
ll dp[1010][(1 << 12)];
int main()
{
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i];
		for (int j = 0; j < b[i]; j++) {
			int C;
			cin >> C;
			C--;
			c[i][C] = 1;
		}
	}
	for (int i = 0; i <= M; i++) {
		for (int j = 0; j < (1 << N); j++) {
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	for (int i = 0; i < M; i++) {
		for (int bit = 0; bit < (1 << N); bit++) {
			dp[i + 1][bit] = min(dp[i + 1][bit], dp[i][bit]);
			int num = 0;
			int tmp = bit;
			ll power = 1;
			for (int j = 0; j < N; j++) {
				if (c[i][j] == 1 || tmp % 2 == 1) {
					num += power;
				}
				tmp /= 2;
				power *= 2;
			}
			//cout << num << endl;
			dp[i + 1][num] = min(dp[i + 1][num], dp[i][bit] + a[i]);
		}
	}
	if (dp[M][(1 << N) - 1] != INF) cout << dp[M][(1 << N) - 1] << endl;
	else cout << -1 << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  int n,m;
  cin >> n >> m;
  int ans = 0;
  for(int i = 1; i * i <= m; i++){
    if(m%i!=0)continue;
    if(m/i >= n)chmax(ans,i);
    if(m/(m/i) >= n)chmax(ans,m/i);
  }
  cout << ans << endl;
}



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

int main() {
	string s, t;
	cin>>s;
	cin.ignore();
	cin>>t;
	int l = (int) s.length();
	for(int i = 0; i < l; i++){
		if(s[i] != t[i]){
			printf("No\n");
			return 0;
		}
	}printf("Yes\n");
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
#define F first
#define S second
int main()
{
    Hello
    int n, mx = 0;
    cin >> n;
    string s[n + 5];
    map<string, int> mp;
    pair<int, string> pr[n + 5];
    for(int i = 0; i < n; i++)
    {
        cin >> s[i];
        mp[s[i]]++;
        mx = max(mx, mp[s[i]]);
    }
    map<string, int> :: iterator it;
    int idx = 0;
    for(it = mp.begin(); it != mp.end(); it++)
    {
        pr[idx].first = it->second;
        pr[idx].second =  it->first;
        idx++;
    }
    sort(pr, pr + idx);
    for(int i = 0; i < idx; i++)
        if(pr[i].first == mx)
            cout << pr[i].second << endl;
    return 0;
}


Measured memory_bytes: 28544
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    
	    Scanner sc = new Scanner(System.in);  //標準入力の宣言
      	int N = sc.nextInt(); //入力数
    
        int x = 800*N;
        int y = 200*(N/15);
    
        System.out.println((x-y));  //答えの確認(提出時には削除)

  }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define mREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
	int n;
    cin >> n;
    rep1(i,n+3244){
        if(i*i > n){
            cout << (i-1) * (i-1) << endl;
            return 0;
        }
    }
	return 0;
}

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

using namespace std;

static const int kMaxN = 1000000;
static int prime[kMaxN];
static bool is_prime[kMaxN + 1];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; i++) {
    is_prime[i] = true;
  }
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime[p++] = i;
      // cout << "found prime:" << prime[p-1] << endl;
      for (int j = 2 * i; j <= n; j += i) {
        is_prime[j] = false;
      }
    }
  }

  return p;
}

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

  sieve(N);
  // cout << "sieve" << endl;

  long long ans = 0;

  for (int c = 1; c < N; c++) {
    int n = N - c;
    if (is_prime[n]) {
      // cout << n << " is a prime" << endl;
      ans += 2;
      continue;
    }

    int half = floor(sqrt(n));
    for (int a = 1; a <= half; a++) {
      int b = n / a;
      if (a * b == n) {
        if (a == b) {
          ans++;
        } else {
          //        cout << " found an anser" << endl;
          ans += 2;
        }
      }
    }
  }

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


Measured memory_bytes: 4232
n = int(input())
dic = {}
for i in range(2, n+1):
    num = i
    for j in range(2, num+1):
        c = 0
        while num%j==0:
            c += 1
            num //= j
        if c > 0:
            if j in dic:
                dic[j] += c
            else:
                dic[j] = c
t, f, ft, tw = 0,0,0,0
end = 0
for _i, j in dic.items():
    if j >= 2:
        t += 1
        if j >= 4:
            f += 1
            if j >= 14:
                ft += 1
                if j >= 24:
                    tw += 1
                    if j >= 74:
                        end += 1

result = 0

result += end

result += tw*(t-1)

result += ft*(f-1)

result += f*(f-1)*(t-2)//2

print(result)

Measured memory_bytes: 3064
#include <stdio.h>

typedef struct {
	int a;
	int	v;
} REC;

void sort_a( REC *, int );
void sort_v( REC *, int );

int main( void ) {
	int i, n;
	REC rec[ 20 ];

	scanf( "%d", &n );

	for ( i = 0; i < n; i++ )
		scanf( "%d %d", &rec[ i ].a, &rec[ i ].v );

	sort_a( rec, n );
	sort_v( rec, n );

	printf( "%d %d\n", rec[ 0 ].a, rec[ 0 ].v );

	return 0;
}

void sort_a( REC *data, int n ) {
	int i, j;
	REC tmp;

	for ( i = 1; i < n; i++ ) {
		tmp = data[ i ];

		if ( data[ i - 1 ].a > tmp.a ) {
			j = i;
			do {
				data[ j ] = data[ j - 1 ];

				j--;
			} while ( j && data[ j - 1 ].a > tmp.a );

			data[ j ] = tmp;
		}
	}
}

void sort_v( REC *data, int n ) {
	int i, j;
	REC tmp;

	for ( i = 1; i < n; i++ ) {
		tmp = data[ i ];

		if ( data[ i - 1 ].v < tmp.v ) {
			j = i;
			do {
				data[ j ] = data[ j - 1 ];

				j--;
			} while ( j && data[ j - 1 ].v < tmp.v );

			data[ j ] = tmp;
		}
	}
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int a[5];
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
  REP(i, 5) {
    if (a[i] == 0) {
      cout << i + 1 << endl;
    }
  }
}

Measured memory_bytes: 3620
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#include<limits>
#include<bitset>
#include<ctype.h>
#include<set>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
int dp[5010][5010];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    string s;cin>>s;
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(s[i]==s[j]){
                if(i>0){
                    dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
                }else{
                    dp[i][j]=max(dp[i][j],1);
                }
            }
            ans=max(ans,min(j-i,dp[i][j]));
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 96896
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i=s;i<n;++i)
#define drep(i,s,n) for (int i=n;i>=s;--i)
#define all(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define print(x) cout<<(x)<<endl
using namespace std;
typedef long long ll;

int gcd(int a,int b)
{if (a%b == 0) return(b);
 else          return(gcd(b,a%b));}
int lcm(int a,int b)
{return a*b/gcd(a,b);}
void printv(vector<auto> v) {cout<<'[';rep(i,0,v.size()){cout<<v[i]<<',';}cout<<']'<<endl;}
void printvv(vector<vector<auto>> vv)
{
  cout<<'['<<endl;
  rep(q,0,vv.size()){cout<<'[';rep(p,0,vv.at(q).size())cout<<vv.at(q).at(p)<<',';cout <<']'<<endl;}
  cout<<']'<<endl;
}
void solve(); int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}
int step_x[] = {-1,0,0,1};
int step_y[] = {0,-1,1,0};
ll INF=10e12;
//------------------------------------------------------------
ll A,B,H,M,ans=0;
string S;
void solve() {
  cin>>A>>B>>H>>M;

  // 角度の正規化
  float long_deg  = 30*H + 0.5*M;
  float short_deg = 6*M;
  // 角度
  float deg = abs(long_deg-short_deg);
  if(deg>180) deg = 360-deg;

  cout << setprecision(15) << sqrt(A*A+B*B - 2*A*B*cos(M_PI*deg/180.0)) << endl;

  return;
}

Measured memory_bytes: 4208
n,x=[int(i) for i in input().split()]

a_list=[int(i) for i in input().split()]

a_list.sort()

if x>sum(a_list):
    print(n-1)

#全員喜ぶ    
elif x==sum(a_list):
    print(n)
    
else:
    sum=0
    count=0
    for i in range(n):
        sum+=a_list[i]
        if sum<=x:
            count+=1
        else:
            break
    print(count)
    
    

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

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

signed main(){
    int K;cin>>K;
    int ans=0;
    for(int i=1;i<=K;i++){
        for(int j=1;j<=K;j++){
            for(int c=1;c<=K;c++){
                ans+=gcd(i,gcd(j,c));
            }
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

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

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  string s;
  cin >> s;

  map<char, bool> exist;
  for (auto e : s) {
    if (exist[e]) {
      cout << "no" << "\n";
      return 0;
    }
    exist[e] = true;
  }

  cout << "yes" << "\n";
  return 0;
}

Measured memory_bytes: 256
from collections import deque
h, w = map(int, input().split())
MAZE = ['#'*(w+2)]
for _ in range(h):
    MAZE.append("#"+input()+"#")
else:
    MAZE.append('#'*(w+2))

INF = 10**3
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]


def bfs(init_x, init_y):
    dist = [[INF]*(w+2) for _ in range(h+2)]
    q = deque([(init_x, init_y)])
    dist[init_x][init_y] = 0
    MAX = 0
    while q:
        x, y = q.popleft()
        for i, j in directions:
            if MAZE[x+i][y+j] == '#':
                continue
            if dist[x+i][y+j] <= dist[x][y]+1:
                continue
            dist[x+i][y+j] = dist[x][y]+1
            q.append((x+i, y+j))

        MAX = max(MAX, dist[x][y])
    return MAX


ans = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        if MAZE[i][j] == '#':
            continue
        ans = max(ans, bfs(i, j))
print(ans)


Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main(){
	int windows[10000], n, h, w, x, openw=0;
	
	cin >> n >> h >> w;
	for (int i=0; i<n*w; i++){
		windows[i] = 1;
	}
	for (int i=0; i<n; i++){
		cin >> x;
		if ((i+1)%2==1){
			// odd
			for (int k=w*i; k<w*i+x; k++){
				windows[k]--;
				windows[k+w]++;
			}
		}else{
			// even
			for (int k=w*i-x; k<w*i; k++){
				windows[k]++;
				windows[k+w]--;
			}
		}
	}
	
	for (int i=0; i<n*w; i++){
		if (windows[i]==0){
			openw++;
		}
	}
	cout << openw*h << endl;
}


Measured memory_bytes: 3136
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    S = input().strip()
    cnt = Counter(S)

    A = cnt['a']
    B = cnt['b']
    C = cnt['c']

    if abs(A - B) <= 1 and abs(B - C) <= 1 and abs(C - A) <= 1:
        print('YES')
    else:
        print('NO')


sol()

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
using namespace std;

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = 0; i < k; i++) {
		if (i + a <= b) {
			cout << i + a << endl;
		}
	}
	for (int i = k - 1; i >= 0; i--) {
		if (b - i > a + k - 1) {
			cout << b - i<<endl;
		}
	}
	return 0;

}

Measured memory_bytes: 256
#!/usr/bin/env python3


def solve(n, aa):

    opa = []

    a_max = max(aa)

    if a_max <= 0:
        print(a_max)
        x = aa.index(a_max) + 1
        for i in range(n, x, -1):
            opa.append(i)
        for i in range(1, x):
            opa.append(1)
    else:
        sum0 = 0
        sum1 = 0
        for i in range(n):
            a = aa[i]
            if 0 < a:
                if i % 2 == 0:
                    sum0 += a
                else:
                    sum1 += a
        print(max(sum0, sum1))

        used = [False] * n
        i0 = 1 if sum0 < sum1 else 0
        for i in range(i0, n, 2):
            if 0 < aa[i]:
                used[i] = True

        k = n
        for i in range(n - 1, -1, -1):
            if not used[i]:
                opa.append(i + 1)
                k -= 1
            else:
                break
        j = 0
        for i in range(k):
            if not used[i]:
                opa.append(1)
                j += 1
            else:
                break

        c = 0
        for i in range(k - 1, j - 1, -1):
            if used[i]:
                c = 0
            else:
                c += 1
                if c == 3:
                    opa.append(i - j + 2)
                    k -= 2
                    c = 1

        for i in range((k - j) // 2):
            opa.append(2)


    print(len(opa))
    for v in opa:
        print(v)


def main():
    n = input()
    n = int(n)
    aa = list(map(int, input().split()))

    solve(n, aa)


if __name__ == '__main__':
    main()



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

int main(){
  int a,b;
  cin >> a >> b;
  string s;
  int count = 0;
  for(int i = a;i <= b;++i){
    s = to_string(i);
    if(s[0] == s[4] && s[1] == s[3]){
      ++count;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		int n = Integer.parseInt(bf.readLine());
 		long[][] coords = new long[n][2];
 		for(int j = 0;j<n;j++){
 			StringTokenizer st = new StringTokenizer(bf.readLine());
 			coords[j][0] = Integer.parseInt(st.nextToken());
 			coords[j][1] = Integer.parseInt(st.nextToken());
 		}
 		int i1 = 0;
 		long m1 = 0;
 		for(int j = 0;j<n;j++){
 			if (coords[j][0] + coords[j][1] > m1){
 				m1 = coords[j][0] + coords[j][1];
 				i1 = j;
 			}
 		}
 		
 		
 		int i2 = 0;
 		long m2 = 0;
 		for(int j = 0;j<n;j++){
 			if (-coords[j][0] + coords[j][1] > m2){
 				m2 = -coords[j][0] + coords[j][1];
 				i2 = j;
 			}
 		}
 		
 		int i3 = 0;
 		long m3 = 0;
 		for(int j = 0;j<n;j++){
 			if (coords[j][0]  -coords[j][1] > m3){
 				m3 = coords[j][0] - coords[j][1];
 				i3 = j;
 			}
 		}
 		
 		int i4 = 0;
 		long m4 = 0;
 		for(int j = 0;j<n;j++){
 			if (-coords[j][0] - coords[j][1] > m4){
 				m4 = -coords[j][0] - coords[j][1];
 				i4 = j;
 			}
 		}
	 	long amax = 0;
 		for(int j = 0 ;j<n;j++){
 			if ((long)(Math.abs(coords[j][0] - coords[i1][0])) + (long)(Math.abs(coords[j][1] - coords[i1][1])) > amax){
 				amax = (long)(Math.abs(coords[j][0] - coords[i1][0])) + (long)(Math.abs(coords[j][1] - coords[i1][1])) ;
 			}
 			if ((long)(Math.abs(coords[j][0] - coords[i2][0])) + (long)(Math.abs(coords[j][1] - coords[i2][1])) > amax){
 				amax = (long)(Math.abs(coords[j][0] - coords[i2][0])) + (long)(Math.abs(coords[j][1] - coords[i2][1])) ;
 			}
 			if ((long)(Math.abs(coords[j][0] - coords[i3][0])) + (long)(Math.abs(coords[j][1] - coords[i3][1])) > amax){
 				amax = (long)(Math.abs(coords[j][0] - coords[i3][0])) + (long)(Math.abs(coords[j][1] - coords[i3][1])) ;
 			}
 			if ((long)(Math.abs(coords[j][0] - coords[i4][0])) + (long)(Math.abs(coords[j][1] - coords[i4][1])) > amax){
 				amax = (long)(Math.abs(coords[j][0] - coords[i4][0])) + (long)(Math.abs(coords[j][1] - coords[i4][1])) ;
 			}
 		}
 		
 		out.println(amax);
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 54960
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
#define r register
using namespace std;
inline void rd(int &x)
{
    int f=1;x=0;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    x*=f;
}
void pt(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)pt(x/10);putchar(x%10+48);
}
int main()
{
    int n,m=0,i,j;
    cin>>n;
    for(i=0;i<=100;i++)
    {
    	for(j=0;j<=100;j++)
    	{
	    	if(i*4+j*7==n)m=1;
	    }
    }
    if(m)cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
program main
    implicit none
    integer(8) k
    integer(8) i, j, l, m
    integer(8) a, b, c, d
    integer(8), dimension(100) :: t,s
    integer(8) sum
    read(*,*) k

    do i = 1, 100
        t(i) = 0
        s(i) = 0
    end do
    
    sum = 0

    do i = 1, k
        do j = 1, k
            do l = 1, k
                if(i >= j) then
                    a = i
                    b = j
                else
                    a = j
                    b = i
                end if
                t(1) = b
                t(2) = mod(a,t(1))
                if(t(2) /= 0) then
                    m = 2
                    do while (t(m) /= 0)
                        t(m+1) = mod(t(m-1),t(m))
                        m = m + 1
                    end do
                else
                    m = 2
                end if

                if(l >= t(m-1)) then
                    c = l
                    d = t(m-1)
                else
                    c = t(m-1)
                    d = l
                end if

                s(1) = d
                s(2) = mod(c,s(1))
                if(s(2) /= 0) then
                    m = 2
                    do while (s(m) /= 0)
                        s(m+1) = mod(s(m-1),s(m))
                        m = m + 1
                    end do
                else
                    m = 2
                end if
                
                sum = sum + s(m-1)
            
            end do
        end do
    end do
    
    write(*,*) sum

end program

Measured memory_bytes: 2792
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
int n,f[100010],x[100010],w[100010];
vector<int> a[100010],p;
inline bool cmp(int a,int b)
{
    return w[a]<w[b];
}
int main()
{
	//freopen("stone.in","r",stdin);
	//freopen("stone.out","w",stdout);
	int i,j,k;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	  scanf("%d",&w[i]);
	for(i=1;i<n;i++)
	  {
       scanf("%d%d",&j,&k);
       a[j].push_back(k);
       a[k].push_back(j);
      }
    for(i=1;i<=n;i++)
      x[i]=i;
    sort(x+1,x+n+1,cmp);
    for(i=1;i<=n;i++)
      for(j=0;j<a[x[i]].size();j++)
        if(w[a[x[i]][j]]<w[x[i]] && !f[a[x[i]][j]])
          {
           f[x[i]]=1;
           p.push_back(x[i]);
           break;
          }
    sort(&p[0],&p[0]+p.size());
    for(i=0;i<p.size();i++)
      printf("%d ",p[i]);
	return 0;
}


Measured memory_bytes: 2816
#include <stdio.h>

int main(void){
	int H, W, i, j;

	do{
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0){
			
			break;
		
		}else{
			
			for(i = 0; H > i; i++){
				for(j = 0; W > j; j++){

					if(i % 2 == 0){

						if(j % 2 == 0){
							printf("#");
						}else{
							printf(".");
						}

					}else{
						
						if(j % 2 == 1){
							printf("#");
						}else{
							printf(".");
						}

					}

				}
				printf("\n");
			}
			
			printf("\n");

		}
	
	}while(H != 0 && W != 0);
	
	return(0);

}

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

using namespace std;
using ll = long long;

int main(void) {
  ll k;
  cin >> k;
  ll a = 7;
  for (int i = 0; i <= k; i++) {
    a = a % k;
    if (a == 0) {
      cout << i + 1 << endl;
      return 0;
    }
    a = a * 10 + 7;
  }
  cout << "-1" << endl;
  return 0;
}

Measured memory_bytes: 3620
<?php
fscanf(STDIN, "%d", $n);
$array = array();

$array = explode(" ", fgets(STDIN));

$nxt = 1; $ans = 0;

for($i=0;$i<$n;$i++){
  if($array[$i] == $nxt){
    $nxt++;
  }else{
    $ans++;
  }
}
if($ans === $n) $ans = -1;
echo $ans;

?>

Measured memory_bytes: 18936
from collections import Counter

N = int(input())
A = list(map(int, input().split(" ")))
m = Counter(A)
def nck(n, k): 
    C = [[0 for x in range(k+1)] for x in range(n+1)] 
  
    # Calculate value of Binomial Coefficient in bottom up manner 
    for i in range(n+1): 
        for j in range(min(i, k)+1): 
            # Base Cases 
            if j == 0 or j == i: 
                C[i][j] = 1
  
            # Calculate value using previously stored values 
            else: 
                C[i][j] = C[i-1][j-1] + C[i-1][j] 
  
    return C

most_common,num_most_common = m.most_common(1)[0]
CHOOSE_MATRIX = nck(num_most_common, 2)
total = 0
for key, value in m.items():
        # if key == A[i]:
        #     continue
        # else:
    total += CHOOSE_MATRIX[value][2]


for i in range(len(A)):
    newtotal = total
    # m[A[i]] -= 1
    # for key, value in m.items():
    #     # if key == A[i]:
    #     #     continue
    #     # else:
    #     total += CHOOSE_MATRIX[value][2]
    # m[A[i]] += 1
    tosubtract = CHOOSE_MATRIX[m[A[i]]][2]
    newtotal -= tosubtract
    newtotal += CHOOSE_MATRIX[m[A[i]]- 1][2]
    print(newtotal)
    # print(uniquethings*(uniquethings)//2)
    # print(total)



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

int main () {
    //int A, B;
    int N,M;
    //int cnt = 0;
    cin >> N >> M;
    /*int keta = 0;
    int X = 0;
    */
    int ans = 0;
    ans = (N * (N-1)) / 2 + (M * (M-1)) / 2;
    /*rep (i,N+1) {
        keta = i % 10;
        X = i / 10;
        keta += X % 10;
        X /= 10;
        keta += X % 10;
        X /= 10;
        keta += X % 10;
        X /= 10;
        keta += X % 10;
        if (A <= keta && keta <= B) {
           ans = ans + i;
        }
        else {
            continue;
        }
    }*/
    cout << ans << endl;

}

Measured memory_bytes: 256
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_098_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(10).
    01 maxlen PIC 9(1)  VALUE 2.
    01 cur    PIC 9(2)  VALUE 1.
    01 i      PIC 9(18) VALUE 1.
    01 j      PIC 9(18).
    01 len    PIC 9(2).
    01 ans    PIC -(8)9.
    01 AB1.
        03 AB11 OCCURS 2.
            05 AB PIC S9(8).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    PERFORM maxlen TIMES

        PERFORM VARYING j FROM cur BY 1
            UNTIL INP(j:1) = SPACE
        END-PERFORM

        COMPUTE len = j - cur

        MOVE INP(cur:len) TO AB(i)

        COMPUTE cur = j + 1

        ADD 1 TO i

    END-PERFORM.

    MOVE FUNCTION MAX(
         AB(1) + AB(2),AB(1) - AB(2),AB(1) * AB(2)) TO ans.

    DISPLAY ans.
    STOP RUN.


Measured memory_bytes: 1016
n = int(raw_input())
A = map(int, raw_input().split())
A.sort(reverse=True)
success = True
el = n - 1
for i in range(0, len(A)-1, 2):
    if A[i] != el or A[i+1] != el:
        success = False
        break
    el -= 2
if n % 2 == 1:
    if A[-1] != 0:
        success = False
else:
    if A[-1] != 1 or A[-2] != 1:
        success = False
if success:
    print pow(2, n/2, 10**9+7)
else:
    print 0


Measured memory_bytes: 11304
//In the name of God

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

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

const int N = 1e2+10 , mod = 1e9+7;

#define int ll

int w[N] , v[N] , dp[N][N * N * N / 10];

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n , W;
   cin >> n >> W;
   for(int i = 1 ; i <= n ; i++){
      cin >> w[i] >> v[i];
   }
   int ans = 0;
   for(int i = 0 ; i < N ; i++)
      for(int j = 0 ; j < N * N * N / 10 ; j++)
         dp[i][j] = 1ll * mod * mod;
   dp[0][0] = 0;
   for(int i = 1 ; i <= n ; i++){
      for(int j = 0 ; j < N * N * N / 10 ; j++){
         dp[i][j] = dp[i - 1][j];
         if(j >= v[i] && dp[i - 1][j - v[i]] + w[i] <= W)
            dp[i][j] = min(dp[i][j] , dp[i - 1][j - v[i]] + w[i]);
         if(dp[i][j] <= W)
            ans = max(ans , j);
      }
   }
   cout << ans;
   return 0;
}


Measured memory_bytes: 114688
<?php
/**
 * ABC121
 * D - XOR World
 */

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

fscanf(STDIN, "%d %d", $A, $B);

echo F($A - 1) ^ F($B), PHP_EOL;

function F($a) {
    $pair_num = intdiv($a + 1, 2);
    $is_odd = ($a + 1) % 2;
    $result = $pair_num % 2 ? 1 : 0;
    if ($is_odd) {
        $result ^= $a;
    }
    return $result;
}


Measured memory_bytes: 4856
using System;

namespace ConsoleApplication10
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ') ;

            int n = int.Parse(s[0]);
            int o = int.Parse(s[1]);
            Console.WriteLine(n*o +" "+ (n*2+o*2));
        }
    }
}

Measured memory_bytes: 9156
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int a = in.nextInt();
        int b = in.nextInt();

        out.println((a - 1) * (b - 1));
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

Measured memory_bytes: 20948