akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		long mod = (long)(1e9+7);
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		long[] heights = new long[N+1];
		long cnt = 0;
		for (int i = 1; i <= N; i++) {
			heights[i] = input.nextLong();
		}
		ArrayList<Integer>[] graph = new ArrayList[N+1];
		for (int i = 1; i <= N; i++) {
			ArrayList<Integer> x = new ArrayList<Integer>();
			graph[i] = x;
		}
		for (int i = 0; i < M; i++) {
			int A = input.nextInt();
			int B = input.nextInt();
			graph[A].add(B);
			graph[B].add(A);
		}
		for (int i = 1; i <= N; i++) {
			long height = heights[i];
			boolean good = true;
			for (int j = 0; j < graph[i].size(); j++) {
				long altheight = heights[graph[i].get(j)];
				if (altheight>=height) {
					good = false;
					break;
				} 
			}
			if (good) cnt++;
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 62108
#include <iostream>

using namespace std;


int main(){
	int h=0;
	int w=0;
	int n=0;
	int data[100][100]={};
	int nColor=0;
	int updown=1;
	int nX=0;
	int nY=0;
	cin >> h >> w;
	cin >> n;
	for(int i=0;i<n;i++){
		int temp;
		cin >> temp;
		for(int j=0;j<temp;j++){
			data[nX][nY]=i+1;
			nY+=updown;
			if(nY<0){
				updown*=-1;
				nX++;
				nY=0;
			}else if(nY>=h){
				updown*=-1;
				nX++;
				nY=h-1;
			}
		}
	}
	for(int i=0;i<h;i++){
		cout << data[0][i];
		for(int j=1;j<w;j++){
			cout << " " << data[j][i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
while 1:
    n = input()
    if n == 0:
        break
    status = {}
    god_st = -1
    res = {}
    for i in xrange(n):
        s = raw_input().split()
        #M, D = map(int, s[0].split("/"))
        h, m = map(int, s[1].split(":"))
        mi = 60*h + m
        st = s[2] == 'I'
        ID = s[3]

        if ID == '000':
            # goddness
            if st == 1:
                god_st = mi
            else:
                for k in status:
                    if k != ID and status[k] != -1:
                        res[k] = res.get(k, 0) + (mi - max(god_st, status[k]))
                god_st = -1
        else:
            if st == 1:
                status[ID] = mi
            else:
                if god_st != -1:
                    res[ID] = res.get(ID, 0) + (mi - max(god_st, status[ID]))
                status[ID] = -1
    print max(res.values()) if res else 0

Measured memory_bytes: 6520
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<string>
#include<map>
#include<set>

#define INF 100000001
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k;
	string s;
	cin >> s >> k;
	vector<string> x;
	for (int i = 0; i<s.size(); i++) {
		for (int j = 1; j < k + 1; j++) {
			if (i + j == 1 + s.size()) {
				break;
			}
	//		cout << s.substr(i, j) << endl;
			x.push_back(s.substr(i, j));
		}
	}
	sort(x.begin(), x.end());
	x.erase(unique(x.begin(), x.end()), x.end());
	cout <<x[k-1];
	return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define print(a) cout<<a<<endl;
typedef long long int ll;

int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int s,w;
	cin>>s>>w;
	if(w>=s) {
		print("unsafe");
	}
	else{
		print("safe");
	}

	return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
//1~n個のノードのダイクストラ
long long inf=10000000000007;
class Edge{
public:
//int s;
int t;
long long len;
};
class Node{
    public:
    int num;//node番号
    long long dist;//startからの距離
    vector<Edge> edge;//自分から生えている辺
    bool comp;//dijkstra中で到達しているかどうか
    void in_edge(Edge &edge_in){
        edge.push_back(edge_in);
    }  
};
bool operator >(const Node& a,const Node &r){
        return a.dist > r.dist;
    }
void dijkstra(vector<Node> &node,int s,int t,int n){
    //n個のノードでできたグラフのsからtまでの最短距離を計算する
    //この時各要素のdistの値はsからの最短距離となる
    for(int i=1;i<=n;i++){
        //初期化
        node[i].dist=inf;
        node[i].num=i;
        node[i].comp=true;
    }
    node[s].dist=0;
    priority_queue<Node,vector<Node>,greater<Node>> que;
    que.push(node[s]);
    while(!que.empty()){
        Node buf;
        buf=que.top();//
        que.pop();
        int k=buf.num;
        if(node[k].comp){
            node[k].comp=false;
            int edge_num=buf.edge.size();
            for(int i=0;i<edge_num;i++){
                int buf_t=node[k].edge[i].t;
                int buf_len=node[k].edge[i].len;
                if(node[buf_t].dist>node[k].dist+buf_len){
                node[buf_t].dist=node[k].dist+buf_len;
                que.push(node[buf_t]);
                }
            }
        }
    }
}
int main(){
    int n,s,t,m;//n:node_num,s:start_node,t:goal_node,m:edge_num
    cin>>n>>m;
    n=n*3;
    m=m;
    vector<Node> node1(n+1);
//    vector<Node> node2(n+1);
    for(int i=0;i<m;i++){
        int a,b;
        long long l;
        cin>>a>>b;
        a=a*3;
        b=b*3;
        int a1,a2,b1,b2;
        a1=a-2;
        a2=a-1;
        b1=b-2;
        b2=b-1;
        l=1;
        Edge in;
//        in.s=a1;
        in.t=b2;
        in.len=l;
        node1[a1].in_edge(in);//有向グラフの場合ここまで
//        in.s=a2;
        in.t=b;
        node1[a2].in_edge(in);//有向グラフの場合ここまで
//        in.s=a;
        in.t=b1;
        node1[a].in_edge(in);//有向グラフの場合ここまで
    }
    cin>>s>>t;
    dijkstra(node1,s*3-2,t*3-2,n);
//    dijkstra(node2,t,s,n);
    long long min=inf;
    long long ans=node1[t*3-2].dist;
    if(ans==inf)ans=-3;
    cout<<ans/3<<endl;
    return 0;
}


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

int a[110];

int main()
{
    int n;
    cin>>n;
    for (int i = 1;i<=n;i++) cin>>a[i];

    int minn = 2147483647;

    for (int x = 1;x <= 100;x++)
    {
        int ans = 0;
        for (int i = 1;i<=n;i++)
        {
            ans += (a[i] - x) * (a[i] - x);
        }
        minn = min(minn,ans);
    }
    cout<<minn;   
    return 0;
}

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

int main(){
  string s;
  int    i, start, end;

  cin >> s;
  for (i = 0; i < s.length(); i++) {
    if (s[i] == 'A') {
      start = i;
      break;
    }
  }
  for (i = s.length() - 1; i > -1; i--) {
    if (s[i] == 'Z') {
      end = i;
      break;
    }
  }
  cout << end - start + 1 << endl;

}


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

using namespace std;

int main()
{
    int N, X;

    scanf("%d %d", &N, &X);
    int min = X, buf;
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &buf);
        X -= buf;
        if (buf < min)
            min = buf;
    }

    printf("%d\n", N + X / min);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int main(){
	int a,b,k;
	cin>>a>>b>>k;
	int cnt=0;
	for(int i=min(a,b);i>=1;i--){
		if(a%i==0&&b%i==0)cnt++;
		if(cnt==k){
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
        import java.util.ArrayList;
        import java.util.Collections;
        import java.util.List;
        import java.util.Scanner;

public class Main {
    static private Scanner scan = new Scanner(System.in);
    public static void main(String args[]) {
        int int1 = Integer.parseInt(scan.next());
        int int2 = Integer.parseInt(scan.next());
//        String str1 = scan.next();
//        String str2 = scan.next();
//        String str3 = scan.next();
        int ans_int = 0;
        String ans = "";
        if((int1%500) <= int2){
            ans = "Yes";
        }else{
            ans = "No";
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(ans);
        out.flush();
        scan.close();
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
 
#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n;

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

    cin >> n;
    if(__builtin_popcount(n) == 1){
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n";
    cout << "1 2\n2 3\n1 " << 3+n << "\n" << 3+n << " " << 2+n << "\n" << 2+n << " " << 1+n << "\n";
    int mx = n-1+n%2;
    for(int i=4; i<mx; i+=2){
        cout << "1 " << i << "\n" << i << " " << i+1 << "\n";
        cout << "1 " << n+i+1 << "\n" << n+i+1 << " " << n+i << "\n";
    }
    if(n % 2 == 0){
        int mx = 1;
        while(mx*2 < n) mx *= 2;
        int o = n ^ mx ^ 1;
        cout << mx << " " << n << "\n";
        cout << n+o << " " << 2*n << "\n";
    }

    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
  string S;
  cin >> S;
  string ans;
  for(int i = 0; i < S.size(); i++) {
    if(S[i] == 'B') {
      if(!ans.empty()) ans.pop_back();
      continue;
    }
    ans.push_back(S[i]);
  }
  cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323;
typedef long long ll;
int main(){
    ll n,m,sum;
    cin>>n>>m;
    if(n%2==1){
        if(m%2==1){
            sum=n*(m/2)+(n/2+1);
        }
        else sum=n*(m/2);
    }
    else {
        sum=n/2*m;
    }
    if(n==1||m==1) sum=1;
    cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
int main(){
    int a,b,c;
    std::string s;
    std::cin >> a >> b >> c;
    if(a < b){
        if(a < c && c < b){
            s = "Yes";
        }else{
            s = "No";
        }
    }
    if(a > b){
        if(b < c && c < a){
            s = "Yes";
        }else{
            s = "No";
        }
    }
    std::cout << s << std::endl;

    return 0;
}

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

int N, t, K;
map<int, int>m;
int ans;

bool compare(pair<int,int> a, pair<int,int>b) {
    return a.first > b.first;
}

vector<pair<int,int>> f(map<int,int> &target) {
    vector<pair<int,int>> vt;
    vector<pair<int,int>> ::iterator it_vt;
    map<int, int> ::iterator it_map;
    
    for (it_map =target.begin(); it_map != target.end(); it_map++) {
        vt.push_back(make_pair(it_map->second, it_map->first));
    }
    sort(vt.rbegin(), vt.rend(),compare);
    
    target.clear();
    
    return vt;
}


int main() {
    ios::sync_with_stdio(false);
    
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> t;
        auto ret = m.insert({t, 1});
        if (!ret.second) {//duplicate
            m.find(t)->second++;
        }
    }
    
    vector<pair<int, int>> s = f(m);

    for (int i = 0; i < s.size()-K && (int)s.size()-K >= 0; i++) {
        //out << s[i].first << ":" << s[i].second << endl;
        ans += s[i].first;
    }
    cout << ans << endl;
    
    /*
    
    for(std::map<int, int>::const_iterator it = m.begin(); it != m.end(); it++)
    {
        int key = it->first;
        int value = it->second;
        cout << key << ":" << value << endl;
    }
    cout << ans << '\n';
    */
    return 0;
}


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

int main(void) {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  cout << toupper(s1[0], locale::classic()) << toupper(s2[0], locale::classic())
       << toupper(s3[0], locale::classic()) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

namespace MyMod {
  typedef long long ll;
  constexpr ll mod = 1e9+7;
  constexpr ll premax = 200020; std::array<ll, premax> f, rf;
  bool flag = false;

  ll power (ll e, ll x){
    if (x == 0) return 1LL; if (x % 2 != 0) return ((power(e, x-1) * e) % mod);
    ll temp = power(e, x / 2); return (temp * temp) % mod;
  }
  ll add ( ll a, ll b ) { return ((a%mod) + (b%mod))%mod; }
  ll sub ( ll a, ll b ) { return ( a%mod + mod - b%mod)%mod; }
  ll mul ( ll a, ll b ) { return ((a%mod) * (b%mod)) % mod; }
  ll div ( ll a, ll b ) { return ((a%mod) * power(b,mod-2)) % mod; }
  ll nCk (int n, int k) {
    if ( !flag ) {
      f[0] = 1; for(int i=1; i<premax; i++) f[i] = mul(f[i - 1],i);
      rf[premax-1] = power(f[premax-1], mod-2); for(int i=premax-2; i>=0; i--) rf[i] = mul(rf[i + 1], (i + 1));
      flag = true;
    }
    return mul(f[n], mul(rf[n-k], rf[k]));
  }
};

int main (void) {

  ll N, M; std::cin >> N >> M;
  ll tmp = M, ans = 1;
  for(int i=2; i<=tmp; i++) {
    ll cnt = 0;
    while(tmp%i==0){
      cnt++;
      tmp /= i;
    }
    ans = MyMod::mul(ans, MyMod::nCk(cnt+N-1, cnt));
  }

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

Measured memory_bytes: 3328
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    int ans = 0;
    reverse(all(s));
    s += '0';

    rep(i, n+1) {
        if(s[i] >= 6+'0' || s[i] == 5+'0' && s[i+1] >= 5+'0') {
            ans += 10-s[i]+'0';
            while(s[++i] == '9');
            ++s[i--];
        } else {
            ans += s[i] - '0';
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1412
n = gets.to_i

ha, hb, hc = 0, 0, 0
n.times do
	a, b, c = gets.split.map(&:to_i)
	_ha = [hb + a, hc + a].max
	_hb = [ha + b, hc + b].max
	_hc = [ha + c, hb + c].max
	ha, hb, hc = _ha, _hb, _hc
end

p [ha, hb, hc].max


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

#define ll long long
#define pi (acos(-1))
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);

int main()
{
    int n;
    cin >> n;
    ll evens=0;ll t;
    rep(i, n) { cin >> t;if(t%2==0){++evens;} }
    cout << pow(3, n) - (pow(2,evens
			    )) << endl;

    return 0;
}

/*author  https://qiita.com/drken/items/0c88a37eec520f82b788*/
ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}


Measured memory_bytes: 4028
#include <stdio.h>
int dif(int a,int b)
{
	int difference;
	if(a<=b)	difference=b-a;
	if(a>b)		difference=a-b;
	return difference;
}

int main(void)
{
	int a,b,c,d,ab,ac,bc,z;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	ab=dif(a,b);	ac=dif(a,c);	bc=dif(b,c);
	if(ac<=d){
		z=1;
	}else if(ab<=d && bc<=d){
		z=1;
	}else{
		z=0;
	}
	if(z==0)	printf("No\n");
	if(z==1)	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <utility>
#include <tuple>
#include <map>
#include <stack>
#include <queue>
#include <ctype.h>
#include <iomanip>
#include <bitset>
#include <set>
#include <ios>
#include <cstdlib>
using namespace std;
using ll = long long;
int main() {
    int N; cin >> N;
    for(int i = 1; i <= 9; i++) {
        for(int j = i; j <= 9; j++) {
            if (i*j==N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Summer Vacation
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

pii ps[MAX_N];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++)
    scanf("%d%d", &ps[i].first, &ps[i].second);
  sort(ps, ps + n);

  priority_queue<int> q;
  int sum = 0;
  for (int d = 1, i = 0; d <= m; d++) {
    while (i < n && ps[i].first <= d) q.push(ps[i++].second);

    if (! q.empty()) {
      sum += q.top(); q.pop();
    }
  }

  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 1660
import java.io.*
import java.util.*

val pw = PrintWriter(System.out)
fun solve(N: Int, a: IntArray) {
    val b = IntArray(N + 1)
    var left = N / 2 + 1
    var right = N
    for (i in left..right) b[i] = a[i - 1]
    right = left - 1
    for (i in right downTo 1) {
        b[i] = (a[i - 1] - (2 * i..N step i).map { b[it] }.sum()) % 2
    }
    val ans = b.withIndex().filter { it.value != 0 }.map { Math.abs(it.index) }
    println(ans.size)
    if (ans.size > 0) { pw.println(ans.joinToString(separator = " ")) }
    pw.flush()
    return
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val a = IntArray(N)
    for (i in 0 until N) {
        a[i] = sc.next().toInt()
    }
    solve(N, a)
}


Measured memory_bytes: 70752
import Data.List

factor 1 = []
factor n = let divisors = dropWhile ((/= 0) . mod n) [2 .. ceiling $ sqrt $ fromIntegral n]
           in let prime = if null divisors then n else head divisors
              in (prime :) $ factor $ div n prime

main :: IO ()
main = do
  [a, b] <- map read . words <$> getLine
  print . (+1). length . group . factor $ gcd a b

Measured memory_bytes: 892
# import atexit
# import io
# import sys
#
# _INPUT_LINES = sys.stdin.read().splitlines()
# input = iter(_INPUT_LINES).__next__
# _OUTPUT_BUFFER = io.StringIO()
# sys.stdout = _OUTPUT_BUFFER
#
#
# @atexit.register
# def write():
#     sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

import math
R = lambda : map(int,input().split())
import math

N, D = map(int, input().split())
Xs = [list(map(int, input().split())) for _ in range(N)]


def dist(y, z):
    return math.sqrt(sum([(y[i] - z[i]) * (y[i] - z[i]) for i in range(D)]))


count = 0
for i in range(N):
    for j in range(i + 1, N):
        d = dist(Xs[i], Xs[j])
        if int(d) == d:
            count += 1

print(count)

Measured memory_bytes: 3064
from collections import Counter

n = int(input())
alist = [int(v) for v in input().split()]
dup_set = {k for k, v in Counter(alist).items() if v >= 2}
alist = sorted(set(alist))
adict = {a: False for a in alist}
a_max = alist[-1]
max_ind = -1

count = 0
if 1 in adict:
    count = 0 if 1 in dup_set else 1
else:
    for a, f in adict.items():
        if f:
            continue
        if a not in dup_set:
            count += 1
        for k in range(a, a_max + 1, a):
            if k in adict:
                adict[k] = True
                if k == a_max:
                    max_ind -= 1
                    if abs(max_ind) <= len(alist):
                        a_max = alist[max_ind]

print(count)


Measured memory_bytes: 147552
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto f = new long[](N);
    foreach (x; 1 .. N + 1)
    {
        foreach (y; factorize(x))
            f[y]++;
    }
    auto dp = new long[][](N, 77);
    dp[0][1] = 1;
    foreach (i; 1 .. N)
    {
        foreach (j; 0 .. f[i] + 1)
        {
            foreach (k; 0 .. 77)
            {
                long cnt = k * (j + 1);
                dp[i][min(cnt, 76)] += dp[i - 1][k];
            }
        }
    }
    writeln(dp[$ - 1][75]);
}

/// 素因数分解
long[] factorize(long x)
{
    assert(0 < x, "x is negative");
    long[] result;
    while ((x & 1) == 0)
    {
        x /= 2;
        result ~= 2;
    }
    for (long i = 3; i * i <= x; i += 2)
        while (x % i == 0)
        {
            x /= i;
            result ~= i;
        }
    if (x != 1)
        result ~= x;
    return result;
}


Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(z) for(int i=1;i<=z;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define mod  1000000007
#define cl(n,m) (n-1)/m  + 1 ;
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N = 3e5 ;
int a[N] ;
signed main(){
	int n ,x , ans =  0;
	cin >> n ;
	f(n) cin >>x , a[i] = x - i ;
	sort( a+1 , a+n+1) ;
	int idx = n/2 + 1 ;
	f(n) ans += ( abs( a[i] - a[idx])) ;
	cout << ans ;
}

Measured memory_bytes: 1792
import java.io.BufferedReader
import java.io.BufferedWriter

fun main() = Case().exec(::solve)
//fun main() = TestExecutor.assert(testCase) { Case(it.r, it.w).exec(::solve) }

/** https://atcoder.jp/contests/abc178/tasks/abc178_b **/
fun solve(case: Case) {
    val (a, b, c, d) = case.longList()
    case.println(listOf(a * c, a * d, b * c, b * d).max()!!.toString())
}

class Case(
    private val input: BufferedReader = System.`in`.bufferedReader(),
    private val out: BufferedWriter = System.out.bufferedWriter()
) {
    fun exec(fn: (Case) -> Unit) = input.use { out.use { execInThread(fn) } }
    private fun execInThread(fn: (Case) -> Unit) =
        Thread(null, { fn(this) }, "solve", 64 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
            .apply { start() }.join()

    fun println(c: CharSequence?) = out.appendln(c)
    fun string(): String = input.readLine().trimEnd()
    fun long(): Long = input.readLine().toLong()
    fun intList(): List<Int> = input.readLine().split(" ").map { it.toInt() }
    fun longList(): List<Long> = input.readLine().split(" ").map { it.toLong() }
}

Measured memory_bytes: 39284
X = int(input())
ans = [False] * (X+1)
ans[1] = True
for i in range(2, X):
    for j in range(2, X):
        if i**j <= X:
            ans[i**j] = True
        else:
            break
for i in range(X, 0, -1):
    if ans[i]:
        print(i)
        break


Measured memory_bytes: 62312
#include <iostream>

int main()
{
    std::uint64_t N, M;
    std::cin >> N >> M;

    std::uint64_t A = 0;
    for(std::size_t i=0; i<M; ++i)
    {
        std::uint64_t a;
        std::cin >> a;
        A += a;
    }

    if(N < A)
    {
        std::cout << "-1" << std::endl;
    }
    else
    {
        std::cout << N - A << std::endl;
    }

    return 0;


}


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


int main()
{
  int N;
  int h;
  cin >> N;
  vector<int> h_list(N);

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

  vector<int> dp(N);
  dp.at(0) = 0;
  dp.at(1) = abs(h_list.at(1) - h_list.at(0));

  for (int i = 2; i < N; i++)
  {
    dp.at(i) = min(dp.at(i - 2) + abs(h_list.at(i - 2) - h_list.at(i)), dp.at(i - 1) + abs(h_list.at(i - 1) - h_list.at(i)));
  }
  cout << dp.at(N - 1);
}



Measured memory_bytes: 1024
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int H,W;

for(;;){
H = scan.nextInt();
W = scan.nextInt();
if(H == 0 && W == 0)break;
else {
  for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
         System.out.print("#");}
         System.out.println();}
    System.out.println();}}}}

Measured memory_bytes: 37672
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;

i64 get_min_p(i64 n) {
    for (i64 i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return i;
        }
    }
    return n;
}

int main() {
    i64 n;
    cin >> n;
    i64 k = n;
    while (n > 1) {
        int p = get_min_p(n);
        k = k / p * (p - 1);
        while (n % p == 0) {
            n /= p;
        }
    }
    cout << k << endl;
}


Measured memory_bytes: 3100
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int N = scn.nextInt();
    ArrayList<Integer> A = new ArrayList<>();

    for (int i = 0; i < N; i++) {
      A.add(scn.nextInt());
    }

    System.out.println(gcd(A));

  }

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

  public static int gcd(ArrayList<Integer> a) {
    int ans = a.get(0);
    for (int i = 1; i < a.size(); i++) {
      ans = gcd(ans, a.get(i));
    }

    return ans;
  }

}


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

int main() {
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n,m;
	cin>>n>>m;
	if (n==1||m==1) {
		if (n==1&&m==1) cout<<1;
		else if (n==1) cout<<m-2;
		else cout<<n-2;
		return 0;
	}
	cout<<1ll*(n-2)*(m-2);
	return 0;
}


Measured memory_bytes: 256
def comb(n,k): #nCkを出力する関数
    ans = [[1]]
    tem = []
    for i in range(1,n+1):
        tem = []
        for j in range(i+1):
            if(j==0 or j==i):
                tem.append(1)
            else:
                tem.append(ans[i-1][j-1]+ans[i-1][j])
        ans.append(tem)
    return ans[n][k] 

n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse = True)
sum = 0
for i in range(a):
    sum+=v[i]
print(sum/a)
count = v.count(v[0])
if count<a:
    count = v.count(v[a-1])
    check = 0
    for i in range(a,n):
        if v[i]!=v[a-1]:
            break
        check+=1
    print(comb(count,check))
else:
    ans = 0
    for i in range(a,min(b+1,count+1)):
        ans += comb(count,i)
    print(ans)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
 
 
typedef long long ll;
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

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

  vi t(n);
  rep (i, n) cin >> t[i];

  double sumx = 0, sumy = 0;
  rep (i, n) {
    for (int j = i + 1; j < n; j++) {
      if (i == j) continue;
      double t1 = t[i], t2 = t[j];
      double tt = (double)(t1 + t2) / 2;
      // DEBUG(tt);
      // DEBUG(2*pi*tt/l);
      // DEBUG(cos(2*pi*tt/l));
      // DEBUG(sin(2*pi*tt/l));

      sumx += cos(2*pi*tt/l + pi) * (j - i - 1);
      sumy += sin(2*pi*tt/l + pi) * (j - i - 1);

      sumx += cos(2*pi*tt/l) * (n - 2 - (j - i - 1));
      sumy += sin(2*pi*tt/l) * (n - 2 - (j - i - 1));
    }
  }
  //DEBUG(sumx);
  //DEBUG(sumy);

  sumx /= ((double)n * (n - 1) * (n - 2) / 6);
  sumy /= ((double)n * (n - 1) * (n - 2) / 6);

  cout << setprecision(15) << fixed << sumx << " " << sumy << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int len = s.size();
  if(s.substr(len-7,7)=="keyence"){
    cout << "YES" << endl;
    return 0;
  }
  if(s.substr(0,1) == "k" && s.substr(len-6,6)=="eyence"){
    cout << "YES" << endl;
    return 0;
  }
  if(s.substr(0,2) == "ke" && s.substr(len-5,5)=="yence"){
    cout << "YES" << endl;
    return 0;
  }
  if(s.substr(0,3) == "key" && s.substr(len-4,4)=="ence"){
    cout << "YES" << endl;
    return 0;
  }
  if(s.substr(0,4) == "keye" && s.substr(len-3,3)=="nce"){
    cout << "YES" << endl;
    return 0;
  }
  if(s.substr(0,5) == "keyen" && s.substr(len-2,2)=="ce"){
    cout << "YES" << endl;
    return 0;
  }
  if(s.substr(0,6) == "keyenc" && s.substr(len-1,1)=="e"){
    cout << "YES" << endl;
    return 0;
  }
  if(s.substr(0,7) == "keyence"){
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
}

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

bool isPalindrome(string s)
{
    for(int i=0,j=s.length()-1;i<s.length(),j>=0;i++,j--)
    {
        if(s[i]!=s[j]) return false;
    }
    
    return true;
}

int main()
{
  string s;cin>>s;
  int n=s.length();
  if(s.length()&1)
  {
      string pre=s.substr(0,(n-1)/2);
      string suff=s.substr((n+1)/2,(n-1)/2);
      if(isPalindrome(s)&&isPalindrome(pre)&&isPalindrome(suff)) cout<<"Yes\n";
      else cout<<"No\n";
  }
  else cout<<"No\n";
  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

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

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;


void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main() {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	rep(i, n)
	{
		int h;
		cin >> h;
		if(h >= k)
			ans++;
	}
	cout << ans << endl;

	return 0;
}

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

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

	auto f = []( long long n ) -> int
	{
		int d = 0;
		while( n > 0 ) {
			d++;
			n /= 10;
		}
		return d;
	};
	int ans = f( N );
	for( long long i = 2; i * i <= N; i++ ) {
		if( N % i ) continue;
		long long A = i;
		long long B = N / A;
		ans = min( ans, max( f( A ), f( B ) ) );
	}

	cout << ans << endl;
}


Measured memory_bytes: 3604
#include <stdio.h>
int main(){
    long double a, ans=0;
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++){
        scanf("%Lf",&a);
        ans += (1.0 / a);
    }
    printf("%.10Lf\n", 1.0 / ans);
    return 0;
} 

Measured memory_bytes: 1744
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n, k;
    cin >> n >> k;
    vector<long long>h(n);
    for(int i = 0; i < n; i++) cin >> h[i];
    sort(h.begin(), h.end(), greater<long long>());
    long long ans = 1000000000;
    for(int i = 0; i <= n-k; i++){
        long long res = h[i] - h[i+k-1];
        ans = min(res, ans);
    }
    cout << ans;
}


Measured memory_bytes: 1024
use std::iter::once;
use std::str::Chars;
use std::iter::Iterator;

#[derive(Clone, Debug)]
pub struct Scan2<I, St, F> {
    iter: I,
    f: F,
    state: St,
}

impl<I, St, F> Scan2<I, St, F> {
    fn new(iter: I, state: St, f: F) -> Scan2<I, St, F> {
        Scan2 { iter: iter, state: state, f: f }
    }
}

impl<I, St, F> Iterator for Scan2<I, St, F>
where
    I: Iterator + Iterator2,
    F: Fn(&St, I::Item) -> St,
    St: Clone,
{
    type Item = St;

    #[inline]
    fn next(&mut self) -> Option<St> {
        let o = self.iter.next();
        if let Some(a) = o {
            self.state = (self.f)(&self.state, a);
            Some(self.state.clone())
        } else {
            None
        }
    }
}

pub trait Iterator2 : Iterator {
    fn scan2<St, F>(self, initial_state: St, f: F) -> Scan2<Self, St, F>
    where
        F: Fn(&St, Self::Item) -> St,
        Self: std::marker::Sized,
    {
        Scan2::new(self, initial_state, f)
    }
}

impl<'a> Iterator2 for Chars<'a> {
}

fn solve(n: usize, s: String) -> i32 {
    let v = once(0)
        .chain(s.chars().scan2(0, |s, c| s + if c == 'E' { 1 }  else { 0 }))
        .collect::<Vec<usize>>();
    (0..(n+1))
        .map(|i| i - v[i] + v[n] - v[i])
        .min()
        .map(|i| i as i32)
        .unwrap()
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let n = s.trim().parse().ok().unwrap();
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s = s.trim().to_string();
    let res = solve(n, s);
    println!("{}", res);
}


Measured memory_bytes: 10568
#include <iostream>

using namespace std;

int main(){
    int x,y,s,i,j,k,ans,a,b,sum;
    cin >> x >> y >> s;
    
    while(x!=0){
        ans=0;

        for(i=1;i<s/2+1;i++){
            a=i*(100+x)/100;
            b=(s-a)*100/(100+x);

            while((b+1)*(100+x)/100+a<=s) b++;
                sum = i*(100+y)/100+b*(100+y)/100;
                if(b*(100+x)/100+a==s&&sum>ans) {
	            ans=sum;
            }
            
        }

        cout << ans << endl;
        cin >> x >> y >> s;
    }

    return 0;
}


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

#define REP(i,j,k) for( int i=j; i<k; i++ )
#define rep(i,j) REP(i,0,j)

using namespace std;

typedef long long LI;

int main(){
	
	int n;
	cin >> n;
	
	LI temp,abstemp, psum = 0, mmin = 1000000000;
	
	int mcnt = 0;
	
	rep(i,n){
		
		cin >> temp;
		
		if( temp > 0 ){
			psum += temp;
			abstemp = temp;
		}else{
			psum -= temp;
			abstemp = -temp;
			mcnt++;
		}
		mmin = min(mmin, abstemp);
	}
	
	if(mcnt%2) psum -= 2*mmin;
	
	
	cout << psum << endl;
	
	return 0;
	
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < n; i++)

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

    int A, B;
    cin >> A >> B;

    if (A >= 13) {
        cout << B << endl;
    } else if (A >= 6) {
        cout << B /2 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    N, Q = parseMap(split(readline()))
    S = collect(chomp(readline()))
    A = zeros(Int, length(S))
    for i in 1:N-1
        if S[i:i+1] == ['A', 'C']
            A[i + 1] = A[i] + 1
        else
            A[i + 1] = A[i]
        end
    end
    for _ in 1:Q
        l, r = parseMap(split(readline()))
        println(A[r] - A[l])
    end
end



main()

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

using namespace std;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef pair<int,int> pii;
typedef long long ll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}

using pll = pair<ll,ll>;
ll mod = 1000000007;

void reduce(ll &x, ll &y){
    if(x < 0){
        x *= -1;
        y *= -1;
    }
    //x >= 0
    if(x == 0){
        y = 1;
    }else if(y == 0){
        x = 1;
    }else{
        auto g = __gcd(abs(x),abs(y));
        x /= g;
        y /= g;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, nz = 0;
    int i;
    cin >> n;
    vl pot2; ll p2 = 1;
    for(i=0;i<=n;i++){
        pot2.push_back(p2);
        p2 = (p2*2)%mod;
    }

    map<pll, int> cnt;
    ll x, y;
    for(i=0;i<n;i++){
        cin >> x >> y;
        if(x == 0 && y == 0){
            nz++;
            continue;
        }
        reduce(x,y);
        cnt[{x,y}]++;
    }
    ll ans = 1;
    set<pll> used;
    for(auto kv : cnt){
        tie(x,y) = kv.first;
        int n1 = kv.second;
        ll x2 = y;
        ll y2 = -x;
        reduce(x2,y2);
        int n2 = 0;
        if(cnt.count({x2,y2}) != 0)
            n2 += cnt[{x2,y2}];

        ll tmp = pot2[n1];
        if(n2 > 0){
            tmp += pot2[n2] - 1;
            tmp %= mod;
            if(tmp < 0) tmp += mod;
            cnt.erase({x2,y2});
        }
        ans *= tmp;
        ans %= mod;
    }
    ans = (ans + nz - 1)%mod;
    if(ans < 0) ans += mod;
    
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 17200
#include <iostream>
#include <algorithm>
#include <string>

static bool Input(std::string &W, std::string &T)
{
	if (0x00 == &W || 0x00 == &T) {
		return false;
	}

	std::getline(std::cin, W);
	if (0 >= W.size() || 10 < W.size()) {
		return false;
	}

	std::string tmp;
	while (true) {
		std::getline(std::cin, tmp);
		if (0 >= tmp.size() || 1000 < T.size()) {
			return false;
		}
		if (0 == tmp.compare("END_OF_TEXT")) {
			break;
		}
		T.append(tmp + "\n");
	}

	transform(W.begin(), W.end(), W.begin(), tolower);
	transform(T.begin(), T.end(), T.begin(), tolower);

	return true;


}

static bool countSameWord(const std::string W, const std::string T, int &num)
{
	std::string keyWord;
	int spos = 0;
	int epos = 0;

	num = 0;

	if (0x00 == &num) {
		return false;
	}

	while (true) {
		if (0 > epos) {
			break;
		}
		epos = T.find_first_of(" \n", spos);
		keyWord = T.substr(spos, epos - spos);
		if (0 == keyWord.compare(W)) {
			num++;
		}
		spos = epos + 1;
	}

	if (0 < num) {
		return true;
	}

	return false;

}
int main()
{
	std::string W, T;
	int num = 0;

	if (true == Input(W, T)) {
		(void) countSameWord(W, T, num);
		std::cout << num << std::endl;
	}

	return (0);
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const 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; }
signed main(void){
    int n,k; cin>>n>>k;
    vector <bool> kirai(10); 
    int ans = INF;
    rep(i,k) {int a; cin>>a; kirai[a] = true;}
    for(int i = 0;i<=9;i++){
        rep(j,10)rep(k,10)rep(l,10)rep(m,10){
            string s; s = to_string(i*10000 + j*1000 + k*100 + l*10 + m);
            bool bad = false;
            rep(z, s.size()) if(kirai[s[z]-'0']) {bad = true; break;}
            if(bad) continue;
            
            if(i*10000 + j*1000 + k*100 + l*10 + m>=n) ans = min(ans, i*10000 + j*1000 + k*100 + l*10 + m);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

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

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

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

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

    llong N, W;
    cin >> N >> W;

    llong maxValue = N * 1000;

    vecllong weight(N + 1, 0);
    vecllong value(N + 1, 0);

    FOR(i, N) {
        cin >> weight[i] >> value[i];
    }

    vvecllong dp(N + 1, vecllong(maxValue + 1, INF));  // dp[i][value] = minWeight
    dp[0][0] = 0;

    FOR(i, N) {
        FOR(v, maxValue + 1) {
            if(v - value[i] >= 0 and dp[i][v - value[i]] != INF) {
                dp[i + 1][v] = min(
                    dp[i][v - value[i]] + weight[i],
                    dp[i][v]
                );
            } else {
                dp[i + 1][v] = dp[i][v];
            }
        }
    }

    llong ans = 0;

    FOR(v, maxValue + 1) {
        if(dp[N][v] <= W) {
            ans = v;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 80256
#include <stdio.h>
int main(){
  int H,W,i,j;
  while(1){
    scanf("%d %d",&H,&W);
  if(H==0&&W==0){
    break;
  }
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      printf("#");
    }
    printf("\n");
  }
  printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2044
import numpy as np
import itertools
h, w, k = list(map(int, input().split()))
C = list(list(input()) for _ in range(h))
c = np.array(C)
l1, l2 = [()], [()]
H = [i for i in range(h-1, -1, -1)]
W = [i for i in range(w-1, -1, -1)]
cnt = 0

for i in range(h-1):
    l1+=list(itertools.combinations(H, i+1))
for i in range(w-1):
    l2+=list(itertools.combinations(W, i+1))

for i in l1:
    for j in l2:
        c2 = c
        for a in i:
            c2 = np.delete(c2, a, 0)
        for b in j:
            c2 = np.delete(c2, b, 1)
        if np.count_nonzero(c2 == '#') == k:
            cnt += 1

print(cnt)

Measured memory_bytes: 26700
N, A, B = map(int, input().split())

a = A; b = B
used = set()
while 1:
    if a < b:
        if a + 1 < b:
            a += 1
        else:
            if a > 1:
                a -= 1
            else:
                print('Borys')
                break
        if a < b-1:
            b -= 1
        else:
            if b < N:
                b += 1
            else:
                print('Alice')
                break
    if (a, b) in used:
        print('Draw')
        break
    used.add((a, b))

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

void solve(long long N, std::vector<long long> A) {
    ll ans = 0;
    ll before = A[0];
    for (ll i = 1; i < N; i++) {
        if (before > A[i]) {
            ans += before - A[i];
            A[i] += before - A[i];
        }
        before = A[i];
    }
    cout << ans << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 4848
import itertools


n, m = map(int, input().split())

path = [[False] * n for i in range(n)]
for i in range(m):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  path[a][b] = True
  path[b][a] = True
  
ans = 0

for i in itertools.permutations(range(n), n):
  if i[0] == 0:
    for j in range(n):
      if j == n-1:
        ans += 1
        break
      if not path[i[j]][i[j+1]]:
        break
print(ans)

Measured memory_bytes: 9216