akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
#include <stdio.h>


int main(void)
{
  for(;;){
    int a,b,d;
    cin >> a >> b >> d;
    if(!a) return 0;

    tuple<int,int,int,int> cost=make_tuple(1048576,0,0,0);
    // x+y,ax+by,x,y;
    REP(i,2){
      int tmp,x=0,y=0;
      tmp=(i?d:-d);
      while(tmp!=0){
	if(tmp>0){
	  ++x;
	  tmp-=a;
	}else{
	  ++y;
	  tmp+=b;
	}
      }
      auto tmpc=make_tuple(x+y,a*x+b*y,x,y);
      cost=min(cost,tmpc);
    }
    REP(i,d){
      tuple<int,int,int,int> tmpc;
      if(i%a==0&&(d-i)%b==0){
	tmpc=make_tuple(i/a+(d-i)/b,d,i/a,(d-i)/b);
	cost=min(cost,tmpc);
      }
    }
    int ansx,ansy;
    tie(ignore,ignore,ansx,ansy)=cost;
    cout << ansx << ' ' << ansy << endl;
  }
}

Measured memory_bytes: 2988
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author HARSHAD
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265358979323846;

#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

class CKthSubstring {
public:
	void solve(std::istream& in, std::ostream& out) {
		string s; in>>s;
		int k; in>>k;
		map<char, vi> Map;
		set<string> Set;
		int n = s.length();
		f(i, n){
			Map[s[i]].push_back(i);
		}
		for(char c = 'a'; c<='z'; ++c){
			rep(len, 1, k){
				for(int i: Map[c]){
					if(i+len-1>=n) break;
					Set.insert(s.substr(i, len));
				}
			}
            if((int)Set.size() >=k){
                int cnt = 0;
                for(string w: Set){
                    ++cnt;
                    if(cnt==k){
                        out<<w;
                        return;
                    }
                }
            }
		}
	}
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	CKthSubstring solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pie acos(-1)
#define loop(i,a,n) for(ll i=a;i<n;i++)
#define trav(a,x) for(auto &a:x)
#define vi vector<int>
#define vl vector<ll>
#define pii pair<ll,ll>
#define endl "\n"
#define w 1e5
const ll q=1e5+2;
vector<ll> dp(q,1e12);
//dp[i] be minimium cost for reaching ith stone
ll k;
void solve()
{
    ll n;
    cin>>n>>k;
    vl a(n+1);
    loop(i,1,n+1)
    cin>>a[i];
    dp[1]=0;
    loop(i,1,n+1)
    {
        for(ll j=1;j<=k;j++)
        {
            if(i+j<=n)
            dp[i+j]=min(dp[i+j],abs(a[j+i]-a[i])+dp[i]);
        }
    }
    cout<<dp[n];
}
int main() {
	// your code goes here
	io;
    solve();
	return 0;
}


Measured memory_bytes: 1792
n, a, b, c = map(int, input().split())
Bmb = [int(input()) for _ in range(n)]
ans = 10**9
for i in range(4**n):
    aa, bb, cc = 0, 0, 0
    cnt = 0
    for j in range(n):
        k = ( i >> (2*j) ) & 3
        if k == 1:
            if aa > 0:
                cnt += 10
            aa += Bmb[j]
        elif k == 2:
            if bb > 0:
                cnt += 10
            bb += Bmb[j]
        elif k == 3:
            if cc > 0:
                cnt += 10
            cc += Bmb[j]
    if aa == 0 or bb == 0 or cc == 0:
        continue
    cnt += abs(a-aa) + abs(b-bb) + abs(c-cc)
    ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 46060
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <string.h>
int main(){
    int n,d[20],sum=0;
    scanf("%d",&n);
    for(int uu=0;uu<n;uu++){
        scanf("%d",&d[uu]);
    }
    std::sort(d,d+n);
    d[n-1]=d[n-1]/2;
    for(int u=0;u<n-1;u++){
        sum=sum+d[u];
    }
    printf("%d",sum+d[n-1]);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << endl;
#else
#define DBG(X)
#endif
 
using namespace std;

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

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const ll mod = 1e9 + 7;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }

void solve()
{
	int n;
	ll answ = 0;

	cin >> n;

	vector<ll> a(n), b(n);

	for(auto& el: a)
		cin >> el;

	for(auto& el: b)
		cin >> el;

	for(int i = 0; i < n; ++i)
		answ += max(a[i] - b[i], 0LL);

	cout << answ << endl;
}

int main()
{
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long long int n,a[510],b[510],c[510],i,ans,j;
  scanf("%lld\n",&n);
  for(i=0;i<n-1;i++){
    scanf("%lld %lld %lld\n",&a[i],&b[i],&c[i]);
  }
  for(i=0;i<n-1;i++){
    ans=b[i];
    for(j=i;j<n-1;j++){
      if(ans<b[j]){
        ans=b[j]+a[j];
      }
      else if((ans-b[j])%c[j]==0){
        ans=ans+a[j];
      }
      else{
        ans=b[j]+((ans-b[j])/c[j]+1)*c[j]+a[j];
      }
    }
    printf("%lld\n",ans);
  }
  printf("0\n");
  return 0;
}

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

int main()
{
  int N;

  cin >> N;

  vector<string> S(N);
  vector<int> count(N);
  vector<string> result;

  for (int i = 0; i < N; i++)
  {
    cin >> S.at(i);
  }

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

  int index = 0;

  for (int i = 0; i < N - 1; i++)
  {
    if (S.at(i).compare(S.at(i + 1)) == 0)
    {
      count.at(index)++;
    }
    else
    {
      index = i + 1;
    }
  }

  int max = *max_element(count.begin(), count.end());

  for (int i = 0; i < N; i++)
  {
    if (count.at(i) == max)
    {
      result.push_back(S.at(i));
    }
  }

  for (int i = 0; i < result.size(); i++)
  {
    cout << result.at(i) << endl;
  }
}


Measured memory_bytes: 18164
#include<algorithm>
#include<cmath>
#include<cstdint>
#include<cstdio>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;

#define loop(i,a,b) for(int i=(a); i<(b); ++i)
#define rep(i,n) for(int i=0; i<n; ++i)
#define all(v) begin(v), end(v)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

const double PI = acos(-1.0);

int main() {
  std::ios::sync_with_stdio(false);

  int n, d, x;
  cin >> n >> d >> x;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  int ans = x;
  rep(i, d) rep(j, n) if (i % a[j] == 0) ans++;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class nv {
public:
    int a;
    int x,y;
    bool operator < (const nv& obj) const{
        return a < obj.a;
    }
};

int h,w,d,q;
unsigned long long int s[300*300 + 1];
vector<nv> p;

void input() {
    nv temp;
    cin >> h >> w >> d;
    for(int y = 0;y < h;y++) {
        for(int x = 0;x < w;x++) {
            cin >> temp.a;
            temp.x = x;
            temp.y = y;
            p.push_back(temp);
        }
    }
    cin >> q;
}

void prepare_query(void) {
    sort(p.begin(), p.end());
    for(int i = 1;i <= d;i++) {
        for(int ii = i + d;ii <= h * w;ii = ii + d) {
            nv cmp;
            cmp.a = ii - d;
            auto i_b = lower_bound(p.begin(), p.end(), cmp);
            cmp.a = ii;
            auto i_a = lower_bound(p.begin(), p.end(), cmp);
            s[ii] = s[ii - d] + abs(i_a->x - i_b->x) + abs(i_a->y - i_b->y);
        }
    }
}

unsigned long long int proc_query(int l,int r) {
    return s[r] - s[l];
}

int main(void) {
    input();
    prepare_query();
    int l,r;
    for(int i = 0;i < q;i++) {
        cin >> l >> r;
        cout << proc_query(l, r) << endl;
    }
}


Measured memory_bytes: 3060
n,m,c = map(int, input().split())
b = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for a in A:
    if sum([x*y for (x,y) in zip(a,b)])+c > 0: ans += 1
print(ans)

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

using namespace std;
vector<int>adj[100005];
int col[100005];
int c[100005][11];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		a--,b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		int v,d;
		cin>>v>>d>>col[i+1];
		v--;
		c[v][d]=i+1;
	} 
	for(int i=9;i>=0;i--){
		for(int v=0;v<n;v++){
			for(int u=0;u<adj[v].size();u++){
				c[adj[v][u]][i]=max(c[adj[v][u]][i],c[v][i+1]);
			}
		}
	}
	for(int v=0;v<n;v++){
		int res=0;
		for(int d=0;d<11;d++){
			res=max(res,c[v][d]);
		}
		cout<<col[res]<<endl;
	}
	return 0;
}

Measured memory_bytes: 11128
#include<stdio.h>
#include<stdlib.h>
int main() {
	int i, j, k, f = 0, n, t, m, a, b, c;
	char x[110];
	a = 0;
	b = 0;
	scanf("%d", &n);
	scanf("%s", x);
	for (i = 0;i < n;i++) {

		if (x[i] == 'R') {
			a = a + 1;
		}
		else {
			b = b + 1;
		}
	}
	if (a > b) {
		printf("Yes");
	}
	else {
		printf("No");
	}

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;

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

	int cnt = 0;
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			int z = s - x - y;
			if (0 <= z and z <= k) { 
				cnt++;
				//printf("%d %d %d\n", x, y, z);
			}
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

const uint64_t MOD = 1000 * 1000 * 1000 + 7;

template <uint8_t max_value, uint8_t mod_value>
struct index_mod {
  uint8_t mod[max_value];
  constexpr index_mod() : mod() {
    for (size_t i = 0; i < max_value; ++i) {
      mod[i] = i % mod_value;
    }
  }
};

template <uint8_t mod_value>
struct sub_index {
  uint8_t index[mod_value][mod_value - 10];
  constexpr sub_index() : index() {
    auto value = 0;
    for (size_t i = 0; i < mod_value; ++i) {
      value += 10;
      for (size_t j = 0; j < mod_value - 10; ++j) {
        index[i][j] = (value + j) % mod_value;
      }
    }
  }
};

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

  // i番目の文字を見た時に13との剰余がnになる個数を数え上げる
  std::vector<uint64_t> dp(2 * 13);

  constexpr index_mod<13 * 10, 13> imod;
  constexpr sub_index<13> sindex;

  uint64_t row_sum = 0;

  {  // テーブル初期化
    int val = -1;
    if (s[0] != '?') val = s[0] - '0';
    if (val == -1) {
      for (size_t i = 0; i < 10; ++i) {
        dp[i % 13] = 1;
      }
      row_sum = 10;
    } else {
      dp[val % 13] = 1;
      row_sum = 1;
    }
    // % 13は不要だけど定義に帰るため
  }

  for (size_t i = 1, e = s.length(); i < e; ++i) {
    int val = -1;
    if (s[i] != '?') val = s[i] - '0';
    if (val == -1) {
      for (size_t here = 0; here < 13; ++here) {
        dp[13 + here] = row_sum;
      }
      for (size_t here = 0; here < 13; ++here) {
        const auto &sub = sindex.index[here];
        for (size_t j = 0; j < 3; ++j) {
          dp[13 + sub[j]] = dp[13 + sub[j]] + MOD - dp[here];
        }
      }

    } else {
      for (size_t pre = 0; pre < 13; ++pre) {
        auto &here_dp = dp[13 + imod.mod[pre * 10 + val]];
        const auto &pre_dp = dp[pre];
        here_dp = pre_dp;
      }
    }
    //
    //    for (int i = 0; i < 2; ++i) {
    //      for (int j = 0; j < 13; ++j) {
    //        std::cout << dp[i * 13 + j] << ",";
    //      }
    //      std::cout << std::endl;
    //    }

    row_sum = 0;
    for (size_t i = 0; i < 13; ++i) {
      dp[i] = dp[13 + i] % MOD;
      row_sum += dp[i];
      // dp[i] = dp[13 + i];
      dp[13 + i] = 0;
    }
    row_sum %= MOD;
  }

  std::cout << dp[5] % MOD << std::endl;
  return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace app02
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NL = Console.ReadLine().Split(' ');
            int N = int.Parse(NL[0]);
            int L = int.Parse(NL[1]);
            int[] taste = new int[N];
            int maxApplePi = 0;
            int resultApplePi = 0;
            int abs = 10000;

            for (int i = 0; i < N; i++)
            {
                taste[i] = L + (i + 1) - 1;
            }
            for(int i = 0; i < N; i++)
            {
                maxApplePi += taste[i];
            }
            for(int i = 0; i < N; i++)
            {
                int applePi = 0;
                for (int j = 0; j < N; j++)
                {
                    if(i == j)
                    {
                        continue;
                    }
                    applePi += taste[j];
                }
                int newAbs = Math.Abs(maxApplePi - applePi);
                if ( newAbs< abs)
                {
                    resultApplePi = applePi;
                    abs = newAbs;
                }
            }
            Console.WriteLine($"{resultApplePi}");
        }
    }
}


Measured memory_bytes: 13140
n, m = gets.split.map(&:to_i)
if m > 0
  a = m.times.map{gets.to_i}
end
spls = Array.new(0)
fib = Array.new(n+1)
fib[0] = fib[1] = 1
for i in 2..n
  fib[i] = fib[i-1] + fib[i-2]
end

flag = 0
if m > 0
  for i in 0..(m-1)
    if i == 0
      if a[i] == 1
        spls.push(1)
      else
        spls.push(a[i] - 1)
      end
    else
      if a[i] - a[i-1] == 1
        flag = 1
        break
      else
        spls.push(a[i] - a[i-1] - 2)
      end
    end
  end
  if n - a[i] > 1
    spls.push(n - a[i] - 1)
  end
else
  spls.push(n)
end

sum = 1
if flag > 0
  puts 0
else
  spls.each do |sp|
    sum *= fib[sp]
  end
  puts sum % 1000000007
end

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

int main() {
  int A,B,j,i;
  cin >> A >> B;
  j=0;
  for (int i = A; i <= B; i++) {
     if ( i / 10000 == i % 10 && (i/1000)%10==(i/10)%10)
        j++;
  }
  cout << j << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    if(n+m>x+y) cout<<"Left"<<endl;
    else if(n+m==x+y) cout<<"Balanced"<<endl;
    else cout<<"Right"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long N; cin >> N;
	string S; cin >> S;
	long K; cin >> K;
	char it = S[K - 1];

	for (int i = 0; i <= N - 1; i++) if (S[i] != it) S[i] = '*';

	cout << S << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	while(n--){
		int a,b,c; cin >> a >> b >> c;
		int res=0;
		for(int i=0;i<c;i++){
			int e,g; double f; cin >> e >> f >> g;
			if(!e){
				int h=a;
				int v=0;
				for(int j=0;j<b;j++){
					v+=f*h;
					h-=g;
				}
				res=max(res,h+v);
			}
			else{
				int h=a;
				for(int j=0;j<b;j++){
					h=h+f*h-g;
				}
				res=max(res,h);
			}
		}
		printf("%d\n",res);
	}
}



Measured memory_bytes: 3164
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getLine >> readInts >>= putStrLn . which "YES" "NO" . ( <= 2 ) . length . filter id . zipWith (/=) [ 1 .. ]

Measured memory_bytes: 508
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(){
  int N;
  cin >> N;
  map<int , int> m;
  for(int i = 0; i < N; i++) {
    int a = 0;
    cin >> a;
    m[a]++;
  }
  
  int ans = 0;
  for(auto iter = m.begin(); iter != m.end(); iter++){
    int idx = iter-> first;
    int tmp = m[idx];
    if(m.count(idx - 1)) tmp += m[idx - 1];
    if(m.count(idx + 1)) tmp += m[idx + 1];
    if(tmp > ans) ans = tmp;
  }
  cout << ans;
}


Measured memory_bytes: 3200
n,d=map(int,input().split())
x=[[0]*d]*n
for i in range(n):
    x[i]=list(map(int, input().split()))
import math
cnt=0
for i, p in enumerate(x):
    for q in range(i+1, n):
        dist=0
        sum=0
        for j in range(d):
            sum+=(p[j]-x[q][j])**2
        dist=math.sqrt(sum)
        if dist.is_integer():
            cnt+=1
print(cnt)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = Integer.parseInt(sc.next());

    long ans = 1;
    for (int i = 0; i < n; i++) {
      ans = lcm(Long.parseLong(sc.next()), ans);
    }

    System.out.println(ans);
    sc.close();
  }

  public static long lcm(long a, long b) {
    return a / gcd(a, b) * b;
  }

  public static long gcd(long a, long b) {
    if (a < b)
      return gcd(b, a);
    if (b == 0)
      return a;
    return gcd(b, a % b);
  }
}

Measured memory_bytes: 23760
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <utility>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define MOD 1000000007

int main(int argc, char const *argv[]) {
  int numOfOdd = 0;
  int N;
  cin >> N;
  REP(i,N){
    int num;
    cin >> num;
    if(num % 2 == 1) numOfOdd++;
  }
  if(numOfOdd % 2 == 0) cout << "YES" << endl;
  if(numOfOdd % 2 == 1) cout << "NO" << endl;
}


Measured memory_bytes: 888
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
cin >> n;
vector<ll> a(n);
vector<bool> isprime(1000001,1);
map<ll,ll> mp;
for(ll i = 0; i < n; i++){
    cin >> a[i];
    mp[a[i]]++;
}
for(ll i = 2; i <= 1000000; i++){
    if(!isprime[i])continue;
    for(ll j = 2 * i; j <= 1000000; j += i){
        isprime[j] = 0;
    }
    for(ll j = 1; i * j <= 1000000; j++){
        mp[i * j] += mp[j];
    }
}
ll ans = 0;
for(ll i = 0; i < n; i++){
    if(mp[a[i]] == 1)
        ans++;
}
cout << ans << endl;
}

Measured memory_bytes: 67348
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for (int i = (a); i < (int)(n); i++)
#define repc(i, a, n) for (int i = (a); i <= (int)(n); i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init)                                              \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
#define DBG(str) cerr << (str) << endl;
ll modpow(ll n, ll p, ll M) {
  ll ans = 1;
  rep(i, 0, p) { ans = (ans * n) % M; }
  return ans;
}

int main() {
  int n;
  cin >> n;
  map<int, int> m;
  rep(i, 0, n) {
    int a;
    cin >> a;
    m[a]++;
  }
  bool valid = true;
  if (n % 2 == 0) {
    for (int k = 1; k < n; k += 2) {
      if (m[k] != 2) {
        valid = false;
        break;
      }
    }
  } else {
    for (int k = 2; k < n; k += 2) {
      if (m[k] != 2) {
        valid = false;
        break;
      }
    }
    if (m[0] != 1)
      valid = false;
  }

  ll M = 1e9 + 7;
  if (valid) {
    cout << modpow(2, n / 2, M) << endl;
  } else
    cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 3200
s = list(input())
m = []
ls = len(s)

for i in range(ls-2):
    t = (100*int(s[i]) + 10*int(s[i+1]) +int(s[i+2]) - 753)
    if t < 0:
        t = -1 * t
    m.append(t)

m.sort()
print(m[0])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;


int main() {
    ll N,M,cnt=0;cin>>N>>M;
    vel H(N);
    rep0(i,N){cin>>H[i];}
    map<ll,ll> data;
    rep1(i,N){data[i]=0;}
    rep0(i,M){
        ll a,b;cin>>a>>b;
        if(H[a-1]<H[b-1]){data[a]++;}
        else if(H[a-1]>H[b-1]){data[b]++;}
        else{data[a]++;data[b]++;}
    }
    rep1(i,N){
        if(data[i]==0){cnt++;}
    }
    cout<<cnt<<endl;
}



Measured memory_bytes: 10364
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String str;
        double a,b,c,d;
        str = scan.nextLine();
        String[] num = str.split(" ", 0);
        a = Double.valueOf(num[0]);
        b = Double.valueOf(num[1]);
        c = Double.valueOf(num[2]);
        c = c/180 * Math.PI;
        //y2 = Double.valueOf(num[3]);
        d = Math.sqrt(a*a+b*b-2*a*b*Math.cos(c));
        System.out.println(a*b*Math.sin(c)/2);
        System.out.println(a+b+d);
        System.out.println(b*Math.sin(c));
        scan.close();
    }
}



Measured memory_bytes: 26260
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

int p[24][3] = {{1, 2, 3}, {1, 3, 5}, {1, 5, 4}, {1, 4, 2}, {2, 1, 4}, {2, 4, 6}, //
                {2, 6, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 6}, {3, 6, 5}, {3, 5, 1}, //
                {4, 1, 5}, {4, 5, 6}, {4, 6, 2}, {4, 2, 1}, {5, 1, 3}, {5, 3, 6}, //
                {5, 6, 4}, {5, 4, 1}, {6, 2, 4}, {6, 4, 5}, {6, 5, 3}, {6, 3, 2}};

main {
  auto v = in(vector<int>(6));
  auto w = in(vector<int>(6));
  bool f = false;
  rep(i, 24) {
    bool g = true;
    rep(j, 3) g &= v[j] == w[p[i][j] - 1] && v[j + 3] == w[6 - p[i][2 - j]];
    f |= g;
  }
  cout << (f ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3120
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#include<bits/stdc++.h>
using ll = long long;
using pii = std::pair<int,int>;
using namespace std;
template<class T>T chmin(T a,T b){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template<class T>T chmax(T b,T a){if(a<b){a^=b;b^=a;a^=b;return 1;}return 0;}

int a,b;
void input(){
    cin>>a>>b;
}
void src(){
    int count=0;
    if(b>1){
        count++;
        b-=a;
        while(b>0){
            count++;
            b-=(a-1);
        }
    }
    cout<<count;
    return;
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int count(int n, int f) {
    int cnt = 0;
    while (n) {
        cnt += n/f;
        n /= f;
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int n, M = 1e9+7;
    cin >> n;
    vector<int> primes, mark(n+1, 1);
    fore(i,2,n+1) if (mark[i]) {
        primes.pb(i);
        for (int j = i*i; j <= n; j += i) {
            mark[j] = false;
        }
    }
    ll ans = 1;
    for (auto &p : primes) {
        ans = (ans * (count(n, p)+1)) % M;
    }
    cout << ans << endl;
}


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

int main() {
  char a;
  cin >> a;

  char ans = 'a';
  for (char i = 'A'; i <= 'Z'; ++i) {
    if (i == a) ans = 'A';
  }

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


Measured memory_bytes: 3592
#include <iostream>

int main() {
    int W, H, x, y ,r;
    std::cin >> W >> H >> x >> y >> r;

    if (r <= x && x <= W - r && r <= y && y <= H - r) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    return 0;
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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 N, Q, M;
vector<int> a(50),b(50),c(50),d(50);
int maxi = -1;

void dfs(int i, int fuga, vector<int>& hoge) {
	int res = 0;
	if(i == N) {
		rep(i,Q) {
			if(hoge[b[i]] - hoge[a[i]] == c[i]) {
				res += d[i];
			}
		}
		chmax(maxi, res);
	}
	else {
		for(int j=fuga; j<=M; j++) {
			vector<int> piyo = hoge;
			piyo.pb(j);
			dfs(i+1, j, piyo);
		}
	}
	return;
}

int main() {
	cin >> N >> M >> Q;
	rep(i,Q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}
	for(int i=1; i<=M; i++) {
		vector<int> a(1,i);
		dfs(1, i, a);
	}
	cout << maxi << endl;

  return 0;
}


Measured memory_bytes: 3628
S=input()
L=("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")
for l in L:
    if S.count(l)>0:
        pass
    else:
        print(l)
        exit()
else:
    print("None")

Measured memory_bytes: 3188
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb emplace_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define ll long long
#define INF 2000000000
int main(){
        int a,b,c;
        while(cin>>a>>b>>c){
                if(a==b&&b!=c) puts("Yes");
                else if(a==c&&b!=c) puts("Yes");
                else if(b==c&&a!=b) puts("Yes");
                else puts("No");
        }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=1e5+5;
int a[MAXN];
int G[105][105];

int main()
{
    int b,w;
    while(scanf("%d%d",&b,&w)!=EOF)
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;++i)
            scanf("%d",&a[i]);
        int cnt=1;
        for(int i=1;i<=b;++i)
        {
            if(i&1)
            {
                for(int j=1;j<=w;++j)
                {
                   if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                   else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }else
            {
                for(int j=w;j>=1;--j)
                {
                    if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                    else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }
        }
        for(int i=1;i<=b;++i)
        {
            for(int j=1;j<=w;++j)
            {
                if(j!=w) printf("%d ",G[i][j]);
                else printf("%d\n",G[i][j]);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 384
s=list(input())

even=s[::2]
odd =s[1::2]

a = len(even) - even.count("0") + len(odd) - odd.count("1")
b = len(even) - even.count("1") + len(odd) - odd.count("0")

if a > b:
  print(b)
else:
  print(a)

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

int main(){
  int n;
  cin >> n;
  
  vector<int> vec(n);
  vector<int> kekka(n);
  
  for(int i = 0;i < n;i ++){
    cin >> vec.at(i);
  }
  
  for(int i = 0;i < n;i ++){
    kekka.at(vec.at(i) - 1) = i + 1;
  }
  
  for(int i = 0;i < n;i ++){
    cout << kekka.at(i) << ' ';
  }
}

Measured memory_bytes: 3876
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

func main() {
	N := readi()
	Y := readi()

	for x := 0; x <= N; x++ {
		for y := N - x; y >= 0; y-- {
			z := N - x - y
			if Y == (10000*x + 5000*y + 1000*z) {
				fmt.Printf("%d %d %d\n", x, y, z)
				return
			}
		}
	}

	fmt.Println("-1 -1 -1")
}

/*-------------------utilities-------------------*/

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

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

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

func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

func isPrime(n int) bool {
	if n == 1 {
		return false
	}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func divisor(n int) (res []int) {
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i*i != n {
				res = append(res, n/i)
			}
		}
	}
	sort.Ints(res)
	return
}

// func searchInts(a []int, k int) int {
// 	return binarySearch(len(a), func(i int) bool {
// 		return a[i] >= k
// 	})
// }

func binarySearch(n int, f func(int) bool) int {
	i, j := 0, n
	for i < j {
		h := int(uint(i+j) >> 1)
		if !f(h) {
			i = h + 1
		} else {
			j = h
		}
	}
	return i
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7
)

var (
	readString func() string
)

func init() {
	readString = newReadString(os.Stdin)
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

func readi64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readf() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


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

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if (abs(a-c)<=d) {
    cout << "Yes" << endl;
    } else if (abs(a-b)<=d && abs(b-c)<=d) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
constexpr ll INF = numeric_limits<ll>::max() / 2;
    
int N;
ll A[200100], B[200100];

tuple<ll, ll> f(int n, ll (&A)[200100]){
    ll total = A[n - 1];    
    int idx = lower_bound(A, A + n, (total + 1) / 2) - A;

    ll mn = -INF;
    if(idx < n - 1){
        mn = A[n - 1] - A[idx];
    }
    --idx;
    if(idx >= 0){
        mn = max(mn, A[idx]);
    }

    ll mx = total - mn;
    
    return std::make_tuple(mn, mx);
}

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

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

    copy(A, A+N, B);
    reverse(B, B+N);

    for(int i=0;i<N;++i){
        A[i + 1] += A[i];
    }

    for(int i=0;i<N;++i){
        B[i + 1] += B[i];
    }

    ll res = INF;
    for(int n=2;n<=N-2;++n){
        ll mn1, mx1, mn2, mx2;
        tie(mn1, mx1) = f(n, A);
        tie(mn2, mx2) = f(N - n, B);

        ll diff = abs(max(mx1, mx2) - min(mn1, mn2));
        res = min(res, diff);
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> f(m);
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      f[a - 1]++;
    }
  }
  cout << count(all(f), n) << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
	cin>>a;
	cin>>b;
	if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
h, w, k = map(int, input().split())

c = []
for _ in range(h):
	c.append([c for c in input()])

ans = 0

for i in range(1 << h):
	for j in range(1 << w):
		cnt = 0
		for n in range(h):
			for m in range(w):
				if i >> n & 1:
					continue
				if j >> m & 1:
					continue
				if c[n][m] == '#':
					cnt += 1
		if cnt == k:
			ans += 1
print(ans)

Measured memory_bytes: 9092
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    ll H, W;
    cin >> H >> W;

    ll ans = H * W;
    ll s[3];
    rep(i, 2) {
        for (ll h = 1; h < H; ++h) {
            s[0] = h * W;
            s[1] = (H - h) * (W / 2);
            s[2] = H * W - (s[0] + s[1]);
            sort(s, s + 3);
            ans = min(ans, s[2] - s[0]);

            s[0] = h * W;
            s[1] = ((H - h) / 2) * W;
            s[2] = H * W - (s[0] + s[1]);
            sort(s, s + 3);
            ans = min(ans, s[2] - s[0]);
        }
        swap(H, W);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def a(q)
puts"? "+q.join(" ")
STDOUT.flush
gets
end
N=gets.to_i
s="! "
I=(0..2*N).to_a
f=a I[1..N]
l,r=1,N+1
9.times{
m=(l+r)/2
q=I[m,N]
f==a(q)?l=m:r=m
}
x=I[r,N-1]
y=I-[0]-I[l,N+1]
1.upto(2*N){|i|
t=x.index(i)?y:x
r=a t+[i]
s+=r[0]
}
puts s

Measured memory_bytes: 2380
#include <bits/stdc++.h> 
using namespace std; 
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
map<string,set<int>>gg;
int main()
{
  //flash;
	int n;
	cin>>n;
	string hey;
	cin>>hey;
	int low=0;
	int high=hey.size()-1;
	int ans=0;
	while(low<=high)
	{
		int mid=(low+high)/2;
		gg.clear();
		string init = hey.substr(0,mid);
		gg[init].insert(0);
		bool ka=false;	
		for (int i = 1; i < (hey.size()-mid+1); ++i)
		{
			string dal = hey.substr(i,mid);
			//debug(dal);
			if(i>=((*gg[dal].begin())+mid) && (!gg[dal].empty())){ka=true;break;}
			gg[dal].insert(i);	
		}
		//debugs(mid,ka);
		//debugs(low,high);
		if(ka)
		{
			low=mid+1;
			ans=max(ans,mid);
		}
		else
		{
			high=mid-1;
		}
	}
	cout<<ans;
  return 0;
}
//code the AC sol !
// BS/queue/map


Measured memory_bytes: 6784
def main():
    d,g = map(int, input().split())
    P,C = [], []
    for i in range(d):
        p,c = map(int, input().split())
        P.append(p)
        C.append(c)

    ans = 1000
    for i in range(2**d):
        sum = 0
        tmp = 0
        bin_array = list(format(i, 'b').rjust(d,'0'))
        for j in range(d):
            if bin_array[j] == '1':
                sum += 100*(j+1)*P[j]+C[j]
                tmp += P[j]
        for j in range(d):
            if bin_array[d-j-1] == '0':
                for k in range(P[d-j-1]-1):
                    if sum >= g:
                        break
                    sum += 100*(d-j)
                    tmp += 1
        if sum >= g:
            ans = min(ans,tmp)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42736
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  ll n, k, x, y;
  cin >> n >> k >> x >> y;
  ll ans = 0;
  if (k >= n){
    ans = n * x;
  }
  else{
    ans = k * x + (n - k) * y;
  }
  print(ans);
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
	int n;scanf(" %d",&n);
  	char che[n+1];
 	scanf(" %s",che);
  	if(n&1){puts("No");return 0;}
  	int ye = 1;
  	for(int i = 0,j = (n>>1); j < n && ye;++i,++j){
    	if(che[i] != che[j]) ye = 0;
    }
  	if(ye) puts("Yes");
  	else puts("No");
  	return 0; 
}

Measured memory_bytes: 128
using System;
class c
{
    static void Main()
    {
        var nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        double ans = 0;
        for (int i = 1; i <= nk[0]; i++)
        {
            int temp = i;
            double p = 1.0 / nk[0];
            while (temp < nk[1])
            {
                temp *= 2;
                p /= 2;
            }
            ans += p;
        }
        Console.WriteLine(ans);
    }
}

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

int main(){
	int n;
	cin>>n;
	vector<long long int> a(n),b(n);
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	long long int pushed=0;
	for(int i=n-1;i>=0;i--){
		a[i]+=pushed;
		if(a[i]%b[i]!=0){
			pushed+=(b[i]-a[i]%b[i]);
		}
	}
	cout<<pushed<<endl;
	return 0;
}


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

using namespace std;

int h, w;
int Map[103][103];
int ans;
const int Posx[2][6] = {{ 1,1,1,0,-1,0 },{0, 1, 0, -1, -1, -1}};
const int Posy[6] = { -1,0,1,1,0,-1 };

void dfs(int x, int y) {
	Map[x][y] = 2;
	for (int i = 0; i < 6; i++) {
		int Nx = x+Posx[(y + 1) % 2][i], Ny =y+ Posy[i];
		if (0 <= Nx&&Nx <= w+1 && 0 <= Ny&&Ny <= h+1) {
			if (Map[Nx][Ny] == 1)ans++;
			else if (Map[Nx][Ny] == 0)dfs(Nx,Ny);
		}
	}
}

int main() {
	cin >> w >> h;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> Map[j][i];
		}
	}
	dfs(0, 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1480
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    int A,B,C,D,E;
    cin>>A>>B>>C>>D>>E;
    int F[5];
    F[0]=10-A%10;
    if(F[0]==10)F[0]=0;
    F[1]=10-B%10;
    if(F[1]==10)F[1]=0;
    F[2]=10-C%10;
    if(F[2]==10)F[2]=0;
    F[3]=10-D%10;
    if(F[3]==10)F[3]=0;
    F[4]=10-E%10;
    if(F[4]==10)F[4]=0;
    int G[5];
    G[0]=A+B+C+D+E+F[1]+F[2]+F[3]+F[4];
    G[1]=A+B+C+D+E+F[0]+F[2]+F[3]+F[4];
    G[2]=A+B+C+D+E+F[0]+F[1]+F[3]+F[4];
    G[3]=A+B+C+D+E+F[0]+F[1]+F[2]+F[4];
    G[4]=A+B+C+D+E+F[0]+F[1]+F[2]+F[3];
    sort(G,G+5);
    int ans=G[0];

    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main  implements Runnable {
    public static void main(String[] args) {

        new Thread(null, new Main(), "", 16 * 1024 * 1024).start();

    }

    public void run() {
    	FastScanner sc = new FastScanner(System.in);
/*		FastScanner sc = new FastScanner("6 6 \r\n" +
				"..#..#\r\n" +
				"......\r\n" +
				"#..#..\r\n" +
				"......\r\n" +
				".#....\r\n" +
				"....#.");*/
    	//FastScanner sc = new FastScanner("1000000000000");
		//long n = Long.parseLong(sc.next());
		int r = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int x2000 = Integer.parseInt(sc.next());
		//int t = Integer.parseInt(sc.next());
		//int k = 0;
		//int k = Integer.parseInt(sc.next());
		//String str = sc.next();
		//char c[] = str.toCharArray();
		//char a[][] = new char[n];
		//int atmp[] = new int[h];
		//int max= 0;
		//int blackar[][] = new int[h*w][2];
		//int p=0;
		PrintWriter out = new PrintWriter(System.out);
		//for(long i = 1; i < n; i++)
		//{
		//	if(n/i==n%i)
		//	{
		//		out.println(n + ":" + i + ":" + n/i + ":" + n%i+":"+ (n/(n%i)-1));
		//	}
		//}
		for (int i = 0; i < 10; i++)
		{
			x2000 = r*x2000-d;
			out.println(x2000);
		}

		//out.println(ans);
		out.flush();
	}

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        public FastScanner(String in) {
        	StringReader sr = new StringReader(in);
            reader = new BufferedReader(new BufferedReader(sr));
            tokenizer = null;
        }
        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

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

        public long nextInt() {
            return Integer.parseInt(next());
        }

    }

}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string str;
	cin >> str;
	if(str=="SUN"){
		cout << 7 << "\n";
	}
	if(str=="MON"){
		cout << 6 << "\n";
	}
	if(str=="TUE"){
		cout << 5 << "\n";
	}
	if(str=="WED"){
		cout << 4 << "\n";
	}
	if(str=="THU"){
		cout << 3 << "\n";
	}
	if(str=="FRI"){
		cout << 2 << "\n";
	}
	if(str=="SAT"){
		cout << 1 << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 256