akhauriyash/Code-Regression huggingface dataset:
/*
 * Author:heroming
 * File:heroming.cpp
 * Time:2017/01/07 08:12:29
 */
#include <vector>
#include <list>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <string>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <unordered_map>
using namespace std;

#define px first
#define py second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define clr(v, e) memset(v, e, sizeof(v))
#define rep(it, v) for (auto it : v)
#define forn(i, n) for (int i = 0; i < (n); ++ i)
#define rforn(i, n) for (int i = (n) - 1; i >= 0; -- i)
#define form(i, a, b) for (int i = (a); i <= (b); ++ i)
#define rform(i, a, b) for (int i = (b); i >= (a); -- i)
#define forv(i, v) for (int i = 0; i < sz(v); ++ i)
#define iter(it, v) for (auto it = v.begin(); it != v.end(); ++ it)

typedef long long lint;
typedef vector<int> vint;
typedef vector<string> vstring;
typedef pair<int, int> pint;
typedef vector<lint> vlint;
typedef vector<pint> vpint;

int main() {
    int a, b, c, d;
    while (cin >> a >> b >> c >> d) {
        int x = c - a, y = d - b;
        string ans = "";
        forn (i, y) ans += 'U';
        forn (i, x) ans += 'R';
        forn (i, y) ans += 'D';
        forn (i, x + 1) ans += 'L';
        forn (i, y + 1) ans += 'U';
        forn (i, x + 1) ans += 'R';
        ans += "DR";
        forn (i, y + 1) ans += 'D';
        forn (i, x + 1) ans += 'L';
        ans += 'U';
        cout << ans << endl;
    }
    return 0;
}


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

const int MAX = 2100;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  // 前処理
  COMinit();

  int n,k;
  cin >> n >> k;

  vector<ll> ans(k+1,0);
  for(int i=1; i<=min(k,n-k+1); i++){
    ll blue,red,both;
    blue = COM(k-1,i-1);
    red = COM(n-k+1,i);
    both = blue*red%MOD;
    ans[i] = both;
  }
  for(int i=1; i<=k; i++){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<vector<int>> inp(n, vector<int>(3));
  for(auto &x: inp)
	for(auto &y: x)
		cin>>y;
  vector<vector<int>> dp(n + 1, vector<int>(3));
  for(int i{1}; i <= n; ++i){
    for(int j{0}; j <= 2; ++j){
    	dp[i][j] = max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) + inp[i - 1][j];
    }
  }
  cout<<max({dp[n][0], dp[n][1], dp[n][2]});
}


Measured memory_bytes: 13964
def nCr(n, r):
    mod=10**9+7
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod
   
n,a,b=map(int,input().split())
s=pow(2,n,10**9+7)
ans=s-1-nCr(n,a)-nCr(n,b)
while ans<0:
   ans+=10**9+7
print(ans)

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define loop(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v,n) rep(i,n) cin >> v[i]

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 gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x) (+ 1 2)) => [](int x) -> int { return 1+2; }

int ten(int n){
  rep(i,10)
    if((n+i)%10==0) return n+i;
}

int main(){
  int ans=0,m=INF;
  vint v(5); vin(v,5);
  vfsort(v,[](int x,int y) -> int {
      if(x%10==0) return false;
      if(y%10==0) return true;
      return x%10<y%10; });
  ans+=v[0];
  loop(i,1,5) ans+=ten(v[i]);

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


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

LL n, a[2020];
LL dp[2020][2020];

LL calc(LL a) {
	if (a < 0)return a + n;
	if (a >= n)return a - n;
	return a;
}

LL solve(int l, int r, int turn) {
	if (dp[l][r] != -1)return dp[l][r];
	if (l == r) {
		if (turn)return dp[l][r] = 0;
		return dp[l][r] = a[l];
	}
	if (turn) {
		if (a[l] > a[r])return dp[l][r] = solve(calc(l + 1), r, 0);
		else return dp[l][r] = solve(l, calc(r - 1), 0);
	}
	else return dp[l][r] = max(solve(calc(l + 1), r, 1) + a[l], solve(l, calc(r - 1), 1) + a[r]);
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	LL ans = 0;
	for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)dp[i][j] = -1;
	for (int i = 0; i < n; i++) {
		ans = max(ans, solve(calc(i + 1), calc(i - 1), 1) + a[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 34768
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;


//足場i+1にたどり着くまでのコストの最小値
ll dp[110000];




int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll>A(n, 0);
	rep(i, 0, n)cin >> A[i];

	
	rep(i, 0, n) {
		dp[i] = inf;
	}
	dp[0] = 0;

	rep(i, 0, n) {
		if (dp[i] == inf)continue;
		rep(j, 1, k + 1) {
			if (i + j < n) {
				dp[i + j] = min(dp[i+j],dp[i] + abs(A[i + j] - A[i]));
			}
		}
	}

	cout << dp[n - 1] << endl;
	


	return 0;
}

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

int main() {
    int n,k,z;
    int d;
    int nc[200] = {0};
    cin >> n >> k;
    for (int i2=0; i2<k; i2++) {
        cin >> d;
        for (int i3=0; i3<d; i3++) {
            cin >> z;
            nc[z - 1] = 1;
        }
    }
    for (int i1 = 0; i1 < 100; i1++) {
        if (nc[i1] == 1) {
            n--;
        }
    }
    cout << n;
    return 0;
}

Measured memory_bytes: 3640
#ALDS_1_3_B Queue
# input = IO
# input = DATA
procs = []
completed = []
qtime = 0
n,q = gets.chomp.split.map(&:to_i)
n.times do
  name,time = gets.split
  procs.push(Hash[name,time.to_i])
end

while(procs.any?) do
  prok = procs.shift
  v = prok.first[-1]
  if (v > q) then
    prok[prok.first[0]]= v - q
    procs.push(prok)
    # binding.pry
    qtime += q
  else
    qtime += v
    puts "#{prok.first[0]} #{qtime}"
  end
end


Measured memory_bytes: 20088
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n,p;

int main(void){
    scanf("%lld%lld",&n,&p);
    ll ans=1;
    for(ll i=2;i*i<=p;i++){
        ll cnt=0;
        while(p%i==0LL){
            cnt++;
            p/=i;
        }
        ll p1=cnt/n;
        for(ll j=0;j<p1;j++){
            ans*=i;
        }
        //printf("%lld %lld %lld\n",p1,cnt,ans);
    }
    if(n==1LL && p>0LL){
        ans*=p;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int h,w,k;
string s[300];
int ans[300][300];
bool f[300][300];

int main(){
	cin>>h>>w>>k;
	memset(ans,-1,sizeof(ans));
	zero(f);
	int cnt=0;
	for(int i=0;i<h;i++){
		cin>>s[i];
		for(int j=0;j<w;j++){
			if(s[i][j]=='#'){
				f[i][j]=1;
				ans[i][j]=++cnt;
			}
		}
	}
	for(int i=0;i<h;i++)
	for(int j=0;j<w;j++){
		if(!f[i][j])
		continue;
		if(j>0)
		for(int k=j-1;k>=0;k--){
			if(ans[i][k]!=-1)
			break;
			ans[i][k]=ans[i][j];
		}
		if(j<w-1)
		for(int k=j+1;k<w;k++){
			if(ans[i][k]!=-1)
			break;
			ans[i][k]=ans[i][j];
		}
	}
	for(int k=0;k<h;k++){
		for(int i=0;i<h;i++){
			if(ans[i][0]==-1)
			continue;
			if(i>0&&ans[i-1][0]==-1){
				for(int j=0;j<w;j++)
				ans[i-1][j]=ans[i][j];
			}
			if(i<h-1&&ans[i+1][0]==-1)
			for(int j=0;j<w;j++)
			ans[i+1][j]=ans[i][j];
		}
	}
	rep(i,h){
		rep(j,w)
		cout<<ans[i][j]<<" ";
		cout<<"\n";
	}
	
	re 0;
}


Measured memory_bytes: 1408
def five_dishes(li):

    ans = 0
    count = 10
    for i in li:
        ans += -(-i//10)*10
        if i%10 != 0:
            count = min(count, i%10)
    return ans-(10-count) if count != 10 else ans

def main():
    li = [int(input())for i in range(5)]
    print(five_dishes(li))

if __name__ == '__main__':
    main()

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;
const ll INF_ = 1000000000000000000;

map< int64_t, int > prime_factor(int64_t n) {
    map< int64_t, int > ret;
    for (int64_t i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

int main() {
    map<int64_t, int> m;
    auto aa = prime_factor(1000000007);
    ll n;
    int cnt = 0;
    cin >> n;
    set<ll>s;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            s.insert(i);
            if (i * i != n)s.insert(n / i);
        }
    }
    s.erase(1);
    for (auto itr : s) {
        if (n == 1)break;
        if (itr < 0)continue;
        m.clear();
        m = prime_factor(itr);
        if (m.size() != 1)continue;
        if (n % itr == 0) {
            n /= itr;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define s_cin(X) scanf("%s",%X)

#define  i_cout(X) printf("%d\n",X)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

int main(void) {
	int a, b,c;
	i_cin3(a,b,c);
	c -= (a - b);
	if (c < 0)c = 0;
	i_cout(c);
	return 0;
}


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

int main(){

    string S;
    int K;
    cin>>S>>K;
    bool ans=true;
    for(int i=0;i<K;i++){
        if(S.at(i)!='1'){
            cout<<S.at(i)<<endl;
            ans=false;
            break;
        }
    }
    if(ans) cout<<1<<endl;
}



Measured memory_bytes: 256
while True:
    num_str = input().split()
    m, f, r = [int(i) for i in num_str]
    if m == -1 and f == -1 and r == -1:
        break
    if m == -1 or f == -1:
        print("F")
    elif m + f >= 80:
        print("A")
    elif 65 <= m + f < 80:
        print("B")
    elif 50 <= m + f < 65:
        print("C")
    elif 30 <= m + f < 50:
        if r < 50:
            print("D")
        else:
            print("C")
    else:
        print("F")



Measured memory_bytes: 5600
#include <iostream>
using namespace std;
char judge(int a,int b,int c)
{
	if(a==100||b==100||c==100)return 'A';
	if(a+b>=180)return 'A';
	if(a+b+c>=240)return 'A';
	if(a+b+c>=210)return 'B';
	if((a+b+c>=150)&&(a>=80||b>=80))return 'B';
	return 'C';
}
int main()
{
	while(1)
	{
		int n;
		cin >> n;
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			int a,b,c;
			cin >> a >> b >> c;
			cout << judge(a,b,c) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1156
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func solve(in string) bool {
	return in[2] == in[3] && in[4] == in[5]
}

func solveStr(in string) string {
	if solve(in) {
		return "Yes"
	}
	return "No"
}

func main() {
	s := nextLine()
	fmt.Println(solveStr(s))
}


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

using namespace std;
typedef long long int lld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> V={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin>>K;
  K--;
  cout<<V[K]<<endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var X int
	fmt.Scan(&X)

	if X == 1 {
		fmt.Println(1)
		return
	}

	result := 0
	Limit := sqrt(X)
	for i := 2; i <= Limit; i++ {
		n := i * i
		for {
			if result < n && X >= n {
				result = n
				if result == X-1 {
					goto end
				}
			}
			if n > X {
				break
			}
			n *= i
		}
	}

end:
	fmt.Println(result)
}

func sqrt(i int) int {
	t := math.Sqrt(float64(i))
	return int(t) + 1
}


Measured memory_bytes: 512
/*
17/10/2017
*/
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
map<pair<int,int>,int> ans;
int mx;
void dfs(vector<int> adj[],int s,int e=-1,int c=-1)
{
//cout<<c<<endl;
if(c!=-1)
{
ans[{s,e}]=c;
}
if(c==-1)
{
c=0;
}
//if(s==2)
//{
//cout<<c<<" "<<adj[s].size()<<endl;
//}
for(int i=0;i<adj[s].size();i++)
{
if(e!=adj[s][i])
{
c++;
if(c>mx)
{
c=1;
}
dfs(adj,adj[s][i],s,c);
}
}
}

int main()
{
int n;
cin>>n;
int x,y;
vector<int> adj[n+1];
vector<pair<int,int> > vc; 
for(int i=0;i<n-1;i++)
{
cin>>x>>y;
adj[x].push_back(y);
adj[y].push_back(x);
vc.push_back({x,y});
}
for(int i=1;i<=n;i++)
{
mx=max(mx,(int)adj[i].size());
}
dfs(adj,1);
cout<<mx<<endl;
for(int i=0;i<n-1;i++)
{
if(ans.count({vc[i].first,vc[i].second}))
{
cout<<ans[{vc[i].first,vc[i].second}]<<endl;
}
else
{
cout<<ans[{vc[i].second,vc[i].first}]<<endl;
}
}
}

Measured memory_bytes: 15904
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;

             
        
int main() {
			   fast
            //    #ifndef ONLINE_JUDGE
            //    freopen("input.txt","r",stdin);
            //    freopen("output.txt","w",stdout);
            //    #endif
               
                  ll n;
                  cin>>n;
                  map<ll,ll>id;
                  id[n]=0;
                  id[n+1]=0;
                  for(ll i=1;i<n;i++)
                  {
                      id[i]=0;
                      ll a;
                      cin>>a;
                      id[a]+=1;
                  }
                  for(ll i=1;i<=n;i++)
                  {
                      if(i==1)
                      {
                          cout<<id[1]<<endl;
                      }
                      else
                      cout<<id[i]<<endl;
                  }
                  

                return 0;
            }


Measured memory_bytes: 16124
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int exit=0;
		double x=0;
		double y=0;
		int sum=0;
		while(exit==0){
			String s = sc.next();
			int j=0;
			while(s.substring(j, j+1).compareTo(",")!=0){
				j++;
			}
			int n = Integer.valueOf(s.substring(0, j));
			int m = Integer.valueOf(s.substring(j+1, s.length()));
			if(n==0 && m==0)exit=1;
			if(exit==0){
				x += n*Math.sin(sum*Math.PI/180);
				y += n*Math.cos(sum*Math.PI/180);
				sum += m;
			}
		}
		System.out.println((int)x);
		System.out.println((int)y);
	}
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    long long N, K;
    cin >> N >> K;
    vector <long long> A(N+1);
    for (int i=1; i<=N; i++)
        cin >> A[i];
    vector <bool> vis(N+1, false);
    long long curr = 1;
    vector <long long> order;
    int cycle_start = -1;
    while (true) {
        vis[curr] = true;
        order.push_back(curr);
        curr = A[curr];
        if (vis[curr]) {
            cycle_start = curr;
            break;
        }
    }
    vector <long long> cycle;
    cycle.push_back(cycle_start);
    curr = A[cycle_start];
    while (curr!=cycle_start) {
        cycle.push_back(curr);
        curr = A[curr];
    }

    if (K < order.size())
        cout << order[K%order.size()];
    else {
        cout << cycle[(K-order.size())%cycle.size()];
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 9280
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod=1000000007;

ll fac[200007],finv[200007],inv[200007];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<200007;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll com(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll h,w,a,b;
    cin>>h>>w>>a>>b;
    h--;w--;
    cominit();
    ll ans=com(h+w,w);
    for(ll i=0LL;i<a;i++){
        ans-=((com(b-1+h-i,b-1))*(com(w-b+i,i)))%mod;
        ans%=mod;
    }
    cout <<(ans+mod)%mod<<endl;
    return 0;
}

Measured memory_bytes: 4992
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

void main()
{
	auto S = split(readln())[0];
	//if (S == "zyxwvutsrqponmlkjihgfedcba") { writeln("-1"); return; }
	
	if (S.length < 26) { writeln(solve1(S)); }
	else { writeln(solve2(S)); }
}

string solve1(string S) {
	
	bool[26] list;
	foreach (c; S) list[c-'a'] = true;
	
	foreach (i, f; list) {
		if (!f) { return S ~ ( to!char('a'+i) ); }
	}
	return "-1";
	
}

string solve2(string S) {
	int index = 25;
	while (index >= 0) {
		foreach ( c;  S[index] + 1 .. 'z'+1 ) {
			if (S[index+1..$].find(to!char(c)).length!=0) return S[0..index] ~ to!char(c);
		}
		
		--index;
	}
	return "-1";
}


Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const arr = input.split('\n');
let str = '';
for(let i = 0; i < arr.length; i++){
  const elm = arr[i].split(" ").map(Number);
  const h = elm[0];
  const w = elm[1];
  if(h === 0 && w === 0) break;
  if(i !== 0) str += '\n';
  let evenLine = [];
  let oddLine = [];
  for(let j = 0; j < w; j++) evenLine.push(j % 2 === 0 ? '#':'.');
  for(let k = 0; k < w; k++) oddLine.push(k % 2 === 0 ? '.':'#');
  evenLine = evenLine.join('') + '\n';
  oddLine = oddLine.join('') + '\n';
  for(let l = 0; l < h; l++) str += l % 2 === 0 ? evenLine : oddLine;
}
console.log(str);


Measured memory_bytes: 15892
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	string s;
	cin >> s;

	ll n = s.length();

	if (n == 1)
	{
		println(1);
	}
	else if (n == 2)
	{
		if (s[0] == s[1])
		{
			println(1);
		}
		else
		{
			println(2);
		}
	}

	vector<ll> dp(n);

	dp[0] = 1;
	if (s[0] == s[1])
	{
		dp[1] = 1;
	}
	else
	{
		dp[1] = 2;
	}

	if (s[0] != s[1] && s[1] != s[2])
	{
		dp[2] = 3;
	}
	else
	{
		dp[2] = 2;
	}

	for (ll i = 3; i < n; i++)
	{
		if (s[i - 1] == s[i])
		{
			dp[i] = dp[i - 3] + 2;
		}
		else
		{
			dp[i] = dp[i - 1] + 1;
		}
	}

	println(dp[n - 1]);
}

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

int main(){
  string S;
  cin >> S;

  if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3]){
    cout << "Bad"<< endl;
  } else {
    cout << "Good" << endl;
  }
}

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

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

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

int main() {
	int n; cin >> n;
	vi a(n);
	rep(i, n)cin >> a.at(i);
	sort(all(a));
	cout << a.at(n - 1) - a.at(0) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int64 powmod(int64 n, int64 count, int64 mod) {
    if (count == 0) return 1;
    if (count % 2 == 0) {
        int64 t = powmod(n, count / 2, mod);
        return t * t % mod;
    }
    return n * powmod(n, count - 1, mod) % mod;
}

int64 ncr(int64 n, int64 r, int64 mod) {
    int64 a;
    if (n < r) a = min(n, r - n);
    else a = min(n - r, r);

    int64 res = 1;
    rep(i, a) {
        res = res * (n - i) % mod;
        res = res * powmod(i + 1, mod - 2, mod) % mod;
    }

    return res;
}

int main() {
    int64 x;
    cin >> x;

    int64 a = 100;
    int ans = 0;
    while (a < x) {
        ans++;
        a = a * 1.01;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3616
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);



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

	vector<int>tower(999);
	tower[0] = 1;
	REP(i, 1, 999)tower[i] = tower[i - 1] + i + 1;

	int a, b;
	cin >> a >> b;
	int diff = b - a;
	REP(i, 1, 999)if (tower[i] - tower[i - 1] == diff) {
		cout << tower[i - 1] - a << endl;
	}


	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

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

ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	ll A, B; cin >> A >> B;
	ll g = gcd(A, B);
	vector<ll>ans;
	for (ll i = 2;i <= sqrt(g);++i) {
		if (g % i == 0) {
			while (g % i == 0) {
				g /= i;
			}
			ans.push_back(i);
		}
	}
	if (g != 1) {
		ans.push_back(g);
	}
	cout << ans.size() + 1 << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	long long ma=b*d;
	ma=max(ma,b*c);
	ma=max(ma,a*c);
	ma=max(ma,a*d);
	cout<<ma;
}


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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n;
  cin >> n;

  int cnt[n + 1] = {0};
  for (int i = 1; i < n; ++i) {
    int x;
    cin >> x;

    cnt[x]++;
  }

  for (int i = 1; i <= n; ++i) {
    cout << cnt[i] << " \n";
  }

}

Measured memory_bytes: 4444
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64
#define INF 10000

int main(){
    int n;
    cin >> n;
    int max=-INF,min=INF;
    int tmp;
    REP(i,n){
        cin >> tmp;
        if( tmp < min) min=tmp;
        if( max < tmp) max = tmp;
    }
    cout << max- min << endl;


}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll N,A,B,C;
string q[100005];
string ans[100005];

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

    cin >> N >> A >> B >> C;

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

    for (int i = 0;i < N;i++){
        if(q[i] == "AB"){
            if(A == 0 && B == 0){
                cout << "No" << endl;
                return 0 ;
            }
            if(A > B){
                ans[i] = "B";
                A--; B++;
            }else if(A < B){
                ans[i] = "A";
                A++; B--;
            }else{
                if(i == N-1){
                    ans[i] = "A";
                }else if(q[i+1] == "AB" || q[i+1] == "AC"){
                    ans[i] = "A";
                    A++; B--;
                }else{
                    ans[i] = "B";
                    A--; B++;
                }
            }
        }else if(q[i] == "AC"){
            if(A == 0 && C == 0){
                cout << "No" << endl;
                return 0 ;
            }
            if(A > C){
                ans[i] = "C";
                A--; C++;
            }else if(A < C){
                ans[i] = "A";
                A++; C--;
            }else{
                if(i == N-1){
                    ans[i] = "A";
                }else if(q[i+1] == "AB" || q[i+1] == "AC"){
                    ans[i] = "A";
                    A++; C--;
                }else{
                    ans[i] = "C";
                    A--; C++;
                }
            }
        }else if(q[i] == "BC"){
            if(C == 0 && B == 0){
                cout << "No" << endl;
                return 0 ;
            }
            if(C > B){
                ans[i] = "B";
                C--; B++;
            }else if(C < B){
                ans[i] = "C";
                C++; B--;
            }else{
                if(i == N-1){
                    ans[i] = "C";
                }else if(q[i+1] == "BC" || q[i+1] == "AC"){
                    ans[i] = "C";
                    C++; B--;
                }else{
                    ans[i] = "B";
                    C--; B++;
                }
            }
        }
    }

    cout << "Yes" << endl;

    for (int i = 0;i < N;i++){
        cout << ans[i] << endl;
    }

    return 0;

}

Measured memory_bytes: 9904
#include<bits/stdc++.h>
using namespace std;
using lld = long long int;
using ld = long int;
int main()
{
    int a,b,c,k,co=0;
    cin >> a >> b >> c >> k;
    while(b<=a)
    {
        b = b*2;
        co++;
    }
    while(c<=b)
    {
        c = c*2;
        co++;
    }
    if(co<=k)
    {
        cout << "Yes";
    }
    else
        cout << "No";
}


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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    string a;
    cin >> a;
    int n = a.size();

    int left = 0, right = n - 1;
    int tot = 0;

    while(left < right){
        if(a[left] == a[right]){
            left++;
            right--;
        } else if(a[left] == 'x'){
            left++;
            tot++;
        } else if(a[right] == 'x'){
            right--;
            tot++;
        } else {
            cout << -1;
            return 0;
        }
    }

    cout << tot;

    return 0;
}


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

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

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 998244353;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
	x += y;
	if( x >= m )
		x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
	x -= y;
	if( x < 0 )
		x += m;
}

vector<ll>seg;
int N;
ll dp[200005];

void update( int pos, ll val )
{
	pos += N;
	seg[pos] = val;
	for(; pos > 1 ; pos >>= 1 )
	{
		seg[pos/2] = seg[pos];
		add( seg[pos/2], seg[pos^1] );
	}
}

ll query( int l, int r )
{
	ll ans = 0;
	l += N;
	r += N+1;
	for(; l < r ; l >>= 1, r >>= 1 )
	{
		if( l&1 )
			add( ans, seg[l++] );
		if( r&1 )
			add( ans, seg[--r] );
	}
	return ans;
}

int main() 
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	fastio();

	int n,k;
	cin>>n>>k;

	vector<array<int,2>>step(k);
	for(int i=0;i<k;i++)
	{
		cin>>step[i][0]>>step[i][1];
	}
	sort(step.begin(),step.end());

	N = n;
	seg.resize(2*N);
	dp[0] = 1;
	update(0,1);

	for(int i=1;i<n;i++)
	{
		for(int j=0;j<k;j++)
		{
			// x -> valid move
			// dp[i] = dp[i-x] + 1;
			int l = i - step[j][1];
			int r = i - step[j][0];
			int f = 0;
			if( l < 0 && r < 0 )
				break;
			if( l < 0 )
			{
				l = 0;
			}
			else if( r < 0 )
			{
				assert(false);
			}

			ll range_sum = query(l,r);
			add( dp[i], range_sum );
			update(i,dp[i]);

			if( f )
				break;
		}
	}
	cout<<dp[n-1],nl;


	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}


Measured memory_bytes: 8016
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
#define pi 3.141592653589793283462
int main(){
    int a,b;
	double f,aa,bb;
	cin>>a>>b;
	f=a/b;
	aa=a;
	bb=b;
	cout<<a/b<<" "<<a%b<<" ";
	cout<< fixed << setprecision(10) << aa/bb << "\n";
	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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; }
ll mod = 1e9+7;


int main(){
    string s,t; cin >> s >> t;
    string ans;
    ans = t + s;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  string s,t;cin>>s>>t;
  int a,b;cin>>a>>b;
  string u;cin>>u;
  if(u==s){
    a--;
  }else if(u==t){
    b--;
  }
  int ans=0;
  cout << a <<" "<< b << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdbool.h>

int main(){
    bool a[8]={};
    int buf,sum=0;
    int n,top=0;
    int max=0,min=0;

    scanf("%d",&n);

    int i;
    for(i=0;i<n;i++){
            scanf("%d",&buf);

            if(buf<3200)
                a[buf/400]++;
            else
                top++;
    }


    for(i=0;i<8;i++){
        if(a[i]==1)
            sum++;
    }

    max=sum+top;

    if(sum==0)
        min=1;
    else
        min=sum;

    printf("%d %d\n",min,max);

    return 0;
}


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

int Board[102][102];    //Board[j, x, w][i, y, h]
bool isOK;
int xs, ys, xg, yg;

void DFS(int c, int x, int y){
    if(Board[x][y] != c){
        return;
    }
    else if(x==xg && y==yg){
        isOK = true;
        return;
    }

    Board[x][y] = 0;

    DFS(c, x+1, y  );
    DFS(c, x  , y+1);
    DFS(c, x-1, y  );
    DFS(c, x  , y-1);
}

// void Showboard(int w, int h){
//     for(int i=0;i<=h;i++){
//         for(int j=0;j<=w;j++)
//             cout << Board[j][i] << " ";
//         cout << endl;
//     }
//     cout << endl;
// }

int main(){
    int w,h;
    while(true){
        cin >> w >> h;
        if(w==0 && h==0)
            break;
        
        isOK = false;
        for(int i=0;i<102;i++){
            for(int j=0;j<102;j++)
                Board[j][i] = 9;
        }
        cin >> xs >> ys >> xg >> yg;

        int n, c, d, x, y;
        cin >> n;
        for(int t=0;t<n;t++){
            cin >> c >> d >> x >> y;
            int wb = 2+(!d*2);  
            int hb = 2+(d*2);
            for(int i=0;i<hb;i++){
                for(int j=0;j<wb;j++)
                    Board[x+j][y+i] = c;
            }
        }

        // Showboard(w, h);

        DFS(Board[xs][ys], xs, ys);

        // Showboard(w, h);

        if(isOK)
            cout << "OK" << endl;
        else
            cout << "NG" << endl;

    }

    return 0;
}



Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <bitset>
#define N 1005
using namespace std;
int n, s, x[N], y[N];
vector<int> a[N];
bitset<5005> bs;

int main() {
	int i, j, t;
	cin>>n;
	for(i=2; i<=n; i++) cin>>t, a[t].push_back(i);
	for(i=1; i<=n; i++) cin>>x[i];
	for(i=n; i>=1; i--) {
		bs = 1;
		s = 0;
		for(j=0; j<a[i].size(); j++) {
			t = a[i][j];
			bs = bs<<x[t] | bs<<y[t];
			s += x[t] + y[t];
		}
		for(j=x[i]; j>=0 && !bs[j]; j--);
		if(j<0) {cout<<"IMPOSSIBLE"; return 0;}
		else y[i] = s - j;
	}
	cout<<"POSSIBLE";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)

/* exchange */
#define chmin(a, b) (a) = min((ll)(a), (ll)(b))
#define chmax(a, b) (a) = max((ll)(a), (ll)(b))

/* output */
#define I(x) cin >> x;
#define D(x) cerr << (x) << " ";
#define BR cerr << "\n";
#define P(x) cout << (x) << endl;
#define FIX cout << fixed << setprecision(10);

/* const */
const int ARRAY = 1000005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;
vl table(ARRAY, 0);

int main(void){
  
  I(N);
  REP(i, N) {
    ll tmp;
    I(tmp);
    table[tmp] += 1;
  }

  FOR(i, 1, ARRAY) {
    if (table[i] == 0) continue;
    ll x = i + i;
    while (x < ARRAY) {
      table[x] = 0;
      x += i;
    }
    if (table[i] == 1) ret++;
  }


  P(ret);

}


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

int main(void){
    int n;
    cin >> n;
    string s[n];
    for(int i=0;i<n;i++)
         cin >> s[i];

    int num = 0;
    int tmp1 = 0, tmp2=0, tmp3=0;
    for(int i=0;i<n;i++){
        size_t size = s[i].length();
        for (int j=0;j<size-1;j++){
          if (s[i][j] == 'A' && s[i][j+1] == 'B') num++;
        }   

        if(s[i][0] == 'B' && s[i][size-1] == 'A')
          tmp1++;
        if(s[i][0] == 'B')
          tmp2++;
        if(s[i][size-1] == 'A')
          tmp3++;

    }   
    //cout << "num" << num << endl;
    //cout << tmp1 << ' ' << tmp2 << ' ' << tmp3 << endl;
    num += min(tmp2, tmp3);
    if (tmp2==tmp3 && tmp3==tmp1 && tmp2>0)
      num--;

    cout << num << endl;
    return 0;
}

Measured memory_bytes: 768
from sys import stdin
import sys
##  input functions for me
def ria(sep = ''):
    if sep == '' :
        return list(map(int, input().split())) 
    else: return list(map(int, input().split(sep)))
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    N = ri()
    if N % 2 == 0:
        print(N // 2 - 1)
    else:
        print(N // 2)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,sum=0;
  cin>>n;
  int a[n-1];
  for(i=0;i<n-1;i++)
    cin>>a[i];
  sum+=a[0]+a[n-2];
  for(i=1;i<n-1;i++)
  {
    sum+=min(a[i-1],a[i]);
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 256
// AOJ 0531: Paint Color
// 2017.12.2 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define QMAX 4000000
typedef struct { int r, c; } Q;
Q q[QMAX+2]; int top, end;

typedef struct { int x1, y1, x2, y2; } T;
T mk[1002];
int x[2002], xs;
int y[2002], ys;

char map[2004][2004];
int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};

int cmp(int *a, int *b) { return *a - *b; }

char buf[50], *p;

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	p++;
	return n;
}

int uniq(int *a, int n)
{
	int i, j;
	
	for (i = 0, j = 1; j < n; j++) {
		while (j < n && a[j] == a[i]) j++;
		if (j < n) if (++i != j) a[i] = a[j];
	}
	return i+1;
}

int bsch(int *a, int x, int r)
{
	int m, l = 0;

    while (l < r) {
        m = (l + r) >> 1;
		if (a[m] == x) return m;
        if (a[m] < x) l = m + 1; else r = m;
    }
	return l-1;
}

int main()
{
	int w, h, n, i, r, c, r1, c1, r2, c2, ans;
	T *tp;

	while (fgets(p=buf, 50, stdin) && *p != '0') {
		w = getint(), h = getint();
		fgets(p=buf, 10, stdin), n = getint();
		x[0] = 0, y[0] = 0, xs = ys = 1;
		for (tp = mk, i = 0; i < n; i++, tp++) {
			fgets(p=buf, 50, stdin);
			x[xs++] = tp->x1 = getint(), y[ys++] = tp->y1 = getint();
			x[xs++] = tp->x2 = getint(), y[ys++] = tp->y2 = getint();
		}
		x[xs++] = w, y[ys++] = h;
		qsort(x, xs, sizeof(int), cmp); xs = uniq(x, xs);
		qsort(y, ys, sizeof(int), cmp); ys = uniq(y, ys);
		for (tp = mk, i = 0; i < n; i++, tp++) {
			tp->x1 = bsch(x, tp->x1, xs);
			tp->y1 = bsch(y, tp->y1, ys);
			tp->x2 = bsch(x, tp->x2, xs);
			tp->y2 = bsch(y, tp->y2, ys);
		}
		w = xs-1, h = ys-1;

		memset(map, 0, sizeof(map));
		for (tp = mk, i = 0; i < n; i++, tp++) {
			for (r = tp->y1; r < tp->y2; r++) memset(map[r]+tp->x1, 1, tp->x2 - tp->x1);
		}

		ans = 0;
		for (r = 0; r < h; r++) for (c = 0; c < w; c++) {
			if (map[r][c]) continue;
			ans++;

			map[r][c] = 1;
			q[0].r = r, q[0].c = c, top = 0, end = 1;
			while (top != end) {
				r1 = q[top].r, c1 = q[top].c; if (++top == QMAX) top = 0;
				for (i = 0; i < 4; i++) {
					r2 = r1 + mv[i][0], c2 = c1 + mv[i][1];
					if (r2 < 0 || r2 >= h || c2 < 0 || c2 >= w || map[r2][c2]) continue;
					q[end].r = r2, q[end].c = c2; if (++end == QMAX) end = 0;
					map[r2][c2] = 1;
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int count = 0;
    String[] s = in.readLine().split("");
    for(int i=0; i<n-1; i++){
      if(s[i].equals(s[i+1])){
        count += 1;
      }
    }
    System.out.println(n-count);
  }
}

Measured memory_bytes: 30676
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a, b;
		while (true) {
			a = sc.nextInt();
			b = sc.nextInt();
			if (a == 0 && b == 0)
				break;
			for (int i = 0; i < a; i++) {
				for (int c = 0; c < b; c++) {
					System.out.printf("#");
				}
				System.out.println();
			}
		    System.out.println();
		}
     }
}


Measured memory_bytes: 60208
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define maxn 3003
#include <bits/stdc++.h>
using namespace std;

vector<ll> v;

int main() {
    ll k, n, mx = 0;
    cin >> k >> n;
    for(int i=1;i<=n;i++){
        ll x;
        cin >> x;
        v.pb(x);
    }
    ll sum = 0;
    for(int i=1;i<n;i++){
        ll x = v[i] - v[i-1];
        sum += x;
        mx = max(mx, x);
    }
    ll x = k - v[n-1] + v[0];
    sum +=  x;
    mx = max(mx, x);
    cout << sum-mx << endl;
    return 0;
}


Measured memory_bytes: 2420
N = int(input())
l = list(map(int, input().split()))
result = 0
for i in range(len(l)):
    num_1 =  i + 1
    num_2 = l[i]
    
    if  (num_1 * num_2)  % 2 != 0:
        result += 1
print(result)
    

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

#define int long long 
#define dou  double 
#define endl "\n"

const int MOD=1e9+7;

void solve()
{
	int n;
	cin >> n;
	if(n%1000==0)
		cout << 0 << endl;
	else
	 cout << 1000 - n %1000 << endl;
}

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

Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
int main(void){
    char a[102],b[102];
    int A,B,i;
    scanf("%s\n%s",a,b);
    A=strlen(a);
    B=strlen(b);
    if(A>B)
    printf("GREATER");
    else if (A<B)
    printf("LESS");
    else{
        for(i=0;i<=A-1;i++){
            if(a[i]>b[i]){
            printf("GREATER");
            break;
            }
            if(a[i]<b[i]){
            printf("LESS");
            break;
            }
            if(i==A-1)
            printf("EQUAL");
        }
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
const int MOD = 1e9 + 7;
void work() {
    int n, m;
    cin >> n >> m;
    int ansn = 1, ansm = 1;
    int lefn = n, lefm = m;
    for (int i = 1; i <= n + m; ++i) {
        if (i & 1) {
            ansn = 1LL * ansn * lefn % MOD;
            lefn--;
        } else {
            ansn = 1LL * ansn * lefm % MOD;
            lefm--;
        }
    }
    lefn = n, lefm = m;
    for (int i = 1; i <= n + m; ++i) {
        if (i & 1) {
            ansm = 1LL * ansm * lefm % MOD;
            lefm--;
        } else {
            ansm = 1LL * ansm * lefn % MOD;
            lefn--;
        }
    }
    cout << (ansn + ansm) % MOD << endl;
}

int main() {
#ifdef local
    freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
    work();
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  double a;
  double ans = 0;
  string s;
  
  for(int i=0; i<n; i++) {
    cin >> a >> s;
    if(s == "JPY") {
      ans += a;
    }
    else {
      ans += a * 380000;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
<?php
  //fscanf(STDIN,"%d",$r);
  for($i=1;$i<=9;$i++){
  	for($j=1;$j<=9;$j++){
  	print $i."x";
  	print $j."=";
  	print $i*$j."\n";
   } 
  }
  ?>

Measured memory_bytes: 6480