akhauriyash/Code-Regression huggingface dataset:
#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()

int main (void) {

  int X, A; std::cin >> X >> A;
  if ( X < A ) std::cout << 0 << std::endl;
  else std::cout << 10 << std::endl;

  return 0;
}

Measured memory_bytes: 256
# include <stdio.h>
int a[500000];
int n;
int number;
int l[500000];
int r[500000];
void solve(int left,int right,int middle);
void sort(int left,int right);

int main(){
	number = 0;
	scanf("%d",&n);
	for(int i = 0; i < n ; i++)
			scanf("%d",&a[i]);
	sort(0,n);
	for(int i = 0; i < n-1 ; i++)
		printf("%d ",a[i]);
	printf("%d\n%d\n",a[n-1],number);
}

void sort(int left,int right)
{

	if(left < right - 1)
	{
	
		int	middle = (right + left)/2;
		sort(left,middle);
		sort(middle,right);
		solve(left,right,middle);
	}
}

void solve(int left,int right,int middle)
{
	int n1 = middle - left;
	int n2 = right - middle;
	for(int i = 0; i < n1;++i)	l[i] = a[left+i];
	for(int i = 0; i < n2;++i)	r[i] = a[middle+i];
	l[n1] = r[n2] = 10000000000;
	int j = 0;int k = 0;
	for(int i =left;i<right;i++)
	{
		if(l[j]<r[k])
		{
		
			a[i] = l[j];
			j++;
		}else{
			a[i] = r[k];
			k++;
		}
		number++;
	
	}
}



Measured memory_bytes: 5672
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	double x,h;
	for(;x=in(),h=in();){
		printf("%.10f\n",x*x+2*x*sqrt(h*h+x*x/4));
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void){
	int n,i,j,v,flag,temp,cnt;
	int a[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	cnt=0;
	flag=1;
	while(flag){
		flag=0;
		for(j=n-1;j!=0;j--){
			if(a[j]<a[j-1]){
				temp=a[j];
				a[j]=a[j-1];
				a[j-1]=temp;
				cnt++;
				flag=1;
			}
		}
	}
	for(i=0;i<n-1;i++){
		printf("%d ",a[i]);
	}
	printf("%d\n",a[n-1]);
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < (int)(x); i++)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll a,b,c; cin >> a >> b >> c;
    ll d,e,f; cin >> d >> e >> f;

    pair<ld,pair<ll,ll>> res = make_pair(0,make_pair(a*100,0));

    for(ll x = a;x <= (f/100);x++){
        rep(j,x/a+1){
            ll re = x-j*a;
            if(re%b != 0)continue;
            ll sugar = min(x*e, f - x*100);
            rep(k,sugar/c+1){
                ll re_sug = sugar - k*c;
                re_sug = (re_sug/d)*d;
                ll all_sug = re_sug + k*c;
                if(f < x*100 + all_sug)continue;
                ld con = 100.0*all_sug/(x*100+all_sug);
                if(res.first < con)res = make_pair(con,make_pair(x*100+all_sug,all_sug));
            }
        }
    }

    cout << res.second.first << " " << res.second.second << endl;
}

Measured memory_bytes: 256
<?php

$stdin = trim(fgets(STDIN));  
$stdin1 = trim(fgets(STDIN));  

if (substr($stdin, 0, strlen($stdin)) === substr($stdin1, 0, strlen($stdin))
 && strlen($stdin1) - strlen($stdin) === 1
   ) {
  echo 'Yes';
} else {
  echo 'No';
}


Measured memory_bytes: 16192
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Your code here!
 
const gcdArr = function(arr) {
  let gcdres = gcd(arr[0], arr[1])
  for (let i=2; i<arr.length; i++) {
    gcdres = gcd(gcdres, arr[i])
  }
  return gcdres
}
 
function gcd_impl(n,m) {
        for( let i = 0; i < 10; ++i ) {
                let t = n - m;
                let q = m > t;
                n = q ? m : t;
                m = q ? t : m;
                if( m == 0 ) { return n; }
        }
        return gcd_impl( m, n % m );
}
 
function gcd( n, m ) {
        return n > m ? gcd_impl( n, m ) : gcd_impl( m, n );
}
 
const Main = (p)=>{
	// 1行目がinput[0], 2行目がinput[1], …に入る
	p = p.split("\n");
	let N = parseInt(p[0].split(" ")[0]);
	//let M = parseInt(p[0].split(" ")[1]);
	let A = p[1].split(" ").map(Number);
	//文字列から10進数に変換するときはparseIntを使います
	//出力
	let sum = new Array(N).fill(0);
	A.map(e=>{sum[e-1]++;});
	sum.map(e=>console.log(e));
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

ll getSize(ll n) {
    return n * (n-1) / 2;
}

int main(void) {
    int tmp;
    ll ans = 0;
    string s;
    vector<ll> alp(26,0);
    cin >> s;
    for (ll i=0; i<s.size(); i++) {
        tmp = (int)s[i] - (int)'a';
        alp[tmp]++;
    }
    for (int i=0; i<26; i++) {
        ans += getSize(alp[i]);
    }
    cout << getSize(s.size()) - ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>


void test_case()
{
    ll n,k;
    cin>>n>>k;
    n%=k;
    cout<<min(n, k-n);
}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}


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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s,t;
  cin>>s>>t;
  bool ok = size(s) + 1 == size(t);
  if (t.substr(0,size(s)) != s) ok=false;
  cout<<(ok?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <map>

using namespace std;

typedef long long LL;

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ALL(a)  (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define dump(x)  cerr << #x << " = " << (x) << endl;

int main() {
  int n;
  int *v;
  cin >> n;

  v = new int[n];
  REP(i,n) {
    cin >> v[i];
  }
  
  map<int, int> count_odd, count_even;
  REP(i,n) {
    if (i % 2 == 0) {
      count_odd[v[i]] += 1;
    } else {
      count_even[v[i]] += 1;
    }
  }

  auto max_odd_pair = max_element(ALL(count_odd), [](auto p1, auto p2) {
    return p1.second < p2.second;
  });
  auto max_even_pair = max_element(ALL(count_even), [](auto p1, auto p2) {
    return p1.second < p2.second;
  });
  int key_odd = (*max_odd_pair).first;
  int value_odd = (*max_odd_pair).second;
  int key_even = (*max_even_pair).first;
  int value_even = (*max_even_pair).second;

  if (key_odd == key_even) {
    count_odd.erase(max_odd_pair);
    count_even.erase(max_even_pair);

    int v1, v2;
    if (count_odd.empty()) v1 = 0;
    else {
      max_odd_pair = max_element(ALL(count_odd), [](auto p1, auto p2) {
        return p1.second < p2.second;
      });
      v1 = (*max_odd_pair).second;
    }

    if (count_even.empty()) v2 = 0;
    else {
      max_even_pair = max_element(ALL(count_even), [](auto p1, auto p2) {
        return p1.second < p2.second;
      });
      v2 = (*max_even_pair).second;
    }

    if (v1 >= v2) {
      value_odd = v1;
    } else {
      value_even = v2;
    }
  }

  cout << (n/2 - value_odd) + (n/2 - value_even) << endl;

  delete[] v;
  return 0;
}

Measured memory_bytes: 5376
import java.util.*;
 
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        Long N = sc.nextLong();
        Long K = sc.nextLong();
        Long a = N % K;

        if(a<=K/2){
            System.out.println(a);
        }
        else{
            System.out.println(K - a);
        }
    }
}

Measured memory_bytes: 21844
#include<cstdio>
#include<algorithm>
using namespace std;
struct arr
{
	long long cnt;
	int num;
}x[100010];
int i,n;
long long k;
bool cmp(arr A,arr B){return A.num<B.num;}
int main()
{
	scanf("%d%lld",&n,&k);
	for (i=1;i<=n;i++) scanf("%d%lld",&x[i].num,&x[i].cnt);
	sort(x+1,x+n+1,cmp);
	for (i=1;i<=n;i++)
	{
		if (k<=x[i].cnt)
		{
			printf("%d\n",x[i].num);
			return 0;
		}
		else k-=x[i].cnt;
	}
}

Measured memory_bytes: 1664
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static int Main(string[] args) {
        List<string> list = new List<string>();

        while (true) {
            string s = Console.ReadLine();
            if (s == "-") { break; }

            int m = int.Parse(Console.ReadLine());

            for (int i = 0; i < m; i++) {
                int h = int.Parse(Console.ReadLine());

                s = Shuffle(s, h);
            }

            list.Add(s);
        }

        for (int i = 0; i < list.Count; i++) {
            Console.WriteLine(list[i]);
        }

        return 0;
    }

    static string Shuffle(string s, int h) {
        return s.Substring(h) + s.Substring(0, h);
    }
}


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

int main(void)
{
	stack<int> car;
	int n;

	while(cin >> n) {
		if(n)
			car.push(n);
		else {
			cout << car.top() << endl;
			car.pop();
		}
	}

	return 0;
}

Measured memory_bytes: 1200
import java.util.*;

class Walker {
    private static int w;
    private static int h;
    private static int[][] walls;
    private static LinkedList<Walker> ret = new LinkedList<>();
    private static int[] dy = {-1, 0, 1, 0};
    private static int[] dx = {0, 1, 0, -1};
    private static int[] dwy = {0, 1, 2, 1};
    private static int[] dwx = {0, 1, 0, 0};

    int y, x, walks;

    Walker(int _w, int _h, int[][] _walls, int _y, int _x, int _walks) {
        w = _w;
        h = _h;
        walls = new int[h*2+1][w+1];
        for (int i=0; i<h*2+1; i++) System.arraycopy(_walls[i], 0, walls[i], 0, w+1);
        y = _y;
        x = _x;
        walks = _walks;
    }

    Walker(int _y, int _x, int _walks) {
        y = _y;
        x = _x;
        walks = _walks;
    }

    @Override
    public int hashCode() {
        return y*w + x;
    }

    LinkedList<Walker> next() {
        ret.clear();

        for (int i=0; i<4; i++) {
            if (walls[y*2+dwy[i]][x+dwx[i]] == 0) {
                ret.add(new Walker(y+dy[i], x+dx[i], walks+1));
            }

        }

        return ret;
    }
}

public class Main {
    public static void main(String[] args) {
        Set<Integer> set = new HashSet<>();
        Queue<Walker> queue = new LinkedList<>();
        Scanner sc = new Scanner(System.in);

        int w, h;
        int[][] walls;

        while (true) {
            set.clear();
            queue.clear();

            w = sc.nextInt();
            h = sc.nextInt();

            if (w == 0 && h == 0) break;

            walls = new int[h*2+1][w+1];
            for (int i=0; i<2*h+1; i++) {
                if (i == 0 || i == 2*h) Arrays.fill(walls[i], 1);
                else if (i % 2 == 1) {
                    walls[i][0] = walls[i][w] = 1;
                    for (int j=1; j<w; j++) {
                        walls[i][j] = sc.nextInt();
                    }
                } else if (i % 2 == 0) {
                    for (int j=0; j<w; j++) {
                        walls[i][j] = sc.nextInt();
                    }
                }
            }

            Walker rootWalker = new Walker(w, h, walls, 0, 0, 1);

            set.add(rootWalker.hashCode());
            queue.add(rootWalker);

            while (!queue.isEmpty()) {
                Walker nowWalker = queue.poll();
                if (nowWalker.x == w-1 && nowWalker.y == h-1) {
                    System.out.println(nowWalker.walks);
                    break;
                }
                for (Walker nextWalker : nowWalker.next()) {
                    if (!set.contains(nextWalker.hashCode())) {
                        set.add(nextWalker.hashCode());
                        queue.add(nextWalker);
                    }
                }
            }
            if (!set.contains(h*w-1)) System.out.println(0);
        }
    }
}

Measured memory_bytes: 70712
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>

using namespace std;

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

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

int D[2010][2010]; // Map
int E[2010][2010]; // sum[i][:]
int F[2010][2010]; // sum[:][i]
int G[2010][2010]; // sum[i~i+1][:]
int H[2010][2010]; // sum[:][i~i+1]
int DP[2010][2010]; // 

int main() {
    ios::sync_with_stdio(false);
    int N, M, Q;
    cin >> N >> M >> Q;
    for (int i = 1;i <= N;i++) {
    	for (int j = 1;j <= M;j++) {
    		char c;
    		cin >> c;
    		if (c == '1') D[i][j] = 1;
    		else D[i][j] = 0;
    	}
    }
    for (int i = 1;i <= N;i++) {
    	E[i][0] = 0;
    	int tmp = 0;
    	bool ok = 0;
    	for (int j = 1;j <= M;j++) {
    		if (D[i][j] == 1 && ok == 0) {
    			ok = 1;
    			tmp++;
    		}
    		else if (D[i][j] == 0) ok = 0;
    		E[i][j] = tmp;
    	}
    }
    for (int i = 1;i <= M;i++) {
    	F[0][i] = 0;
    	int tmp = 0;
    	bool ok = 0;
    	for (int j = 1;j <= N;j++) {
    		if (D[j][i] == 1 && ok == 0) {
    			ok = 1;
    			tmp++;
    		}
    		else if (D[j][i] == 0) ok = 0;
    		F[j][i] = tmp;
    	}
    }
    for (int i = 1;i <= N;i++) {
    	int tmp = 0;
    	for (int j = 1;j <= M;j++) {
    		if (D[i][j] == 1 && D[i + 1][j] == 1) tmp++;
    		G[i][j] = tmp;
    	}
    }
    for (int i = 1;i <= M;i++) {
    	int tmp = 0;
    	for (int j = 1;j <= N;j++) {
    		if (D[j][i] == 1 && D[j][i + 1] == 1) tmp++;
    		H[j][i] = tmp;
    	}
    }
    for (int i = 1;i <= N;i++) {
    	for (int j = 1;j <= M;j++) {
    		DP[i][j] = DP[i - 1][j] + E[i][j] - G[i - 1][j];
    	}
    }
    for (int i = 0;i < Q;i++) {
    	int x, y, a, b;
    	cin >> x >> y >> a >> b;
    	cout << DP[a][b] + DP[x - 1][y - 1] - DP[a][y - 1] - DP[x - 1][b] + G[x - 1][b] - G[x - 1][y - 1] + H[a][y - 1] - H[x - 1][y - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 96384
from bisect import bisect_left

N, M = map(int, input().split())
d = dict()
A = list(map(int, input().split()))
for i in range(N):
	d[A[i]] = d.get(A[i], 0) + 1
for i in range(M):
	B, C = map(int, input().split())
	d[C] = d.get(C, 0) + B

ans = 0
keys = sorted(list(d.keys()), reverse = True)
for k in keys:
	kosuu = min(N, d.get(k))
	ans += k * kosuu
	N -= kosuu
	if N == 0:
		break
print(ans)

Measured memory_bytes: 34452
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const unsigned int M = 1000000007;
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,k,x,y;
    while(cin>>n>>k>>x>>y){
        if(n<=k)cout<<(n*x)<<endl;
        else cout<<(k*x+(n-k)*y)<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define per(i,a,n) for(int i=a;i<=n;i++)
using namespace std;
typedef long long ll;
typedef vector<ll>vec;
typedef vector<vector<ll>> mat;
set<int>s;
int A[5][5],B[5][5];
int main()
{
  int n;
  for(int i=1;i<=3;i++)
    for(int j=1;j<=3;j++)
       cin>>A[i][j];
  cin>>n;
  int x;
for(int i=1;i<=n;i++){
    cin>>x;
    s.insert(x);
}
for(int i=1;i<=3;i++)
  for(int j=1;j<=3;j++){
      if(s.count(A[i][j]))B[i][j]=1;
  }
  for(int i=1;i<=3;i++)
  {
      if(B[1][i]&&B[2][i]&&B[3][i]){cout<<"Yes"<<endl;return 0;}
      if(B[i][1]&&B[i][2]&&B[i][3]){cout<<"Yes"<<endl;return 0;}

      if(B[i][3-i+1]) {}
  }
  if(B[1][1]&&B[2][2]&&B[3][3]){cout<<"Yes"<<endl;return 0;}
  if(B[1][3]&&B[2][2]&&B[3][1]){cout<<"Yes"<<endl;return 0;}
  cout<<"No"<<endl;
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean[][] bool = new boolean[4][13];
        char[] c = new char[]{'S', 'H', 'C', 'D'};
        for(int i = 0; i < n; i++){
            String str = sc.next();
            int index = sc.nextInt();
            if(str.contains("S")){
                bool[0][index - 1] = true;
            }else if(str.contains("H")){
                bool[1][index - 1] = true;
            }else if(str.contains("C")){
                bool[2][index - 1] = true;
            }else if(str.contains("D")){
                bool[3][index - 1] = true;
            }
        }
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 13; j++){
                if(bool[i][j] == false){
                    System.out.println(c[i] + " " + (j + 1));
                }
            }
        }
    }
}


Measured memory_bytes: 26292
// AtCoder template
// 最近sabaがかまってくれないからキレて暴れてる
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m, x; cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m));
    rep(i,n){
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }

    ll ans = INT_MAX;
    bool isOK = false;
    for(ll bit = 0LL; bit < (1<<n); ++bit){
        ll tmp = 0;
        vector<int> skill(m,0);
        rep(i,n){
            if(bit & (1 << i)){
                tmp += c[i];
                rep(j,m) skill[j] += a[i][j];
            }
        }
        bool tmpOK = true;
        rep(i,m){
            if(skill[i] < x){
                tmpOK = false;
                break;
            }
        }
        if(tmpOK){
            ans = min(ans, tmp);
            isOK = true;
        }
    } 
    if(isOK) cout << ans << endl;
    else cout << -1 << endl;
}

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

int main (){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    string t;
    for (ll i=0; i<s.size(); i++){
        if (t.size() == 0 ){
            t.push_back(s[i]);
        }
        else if ( t[t.size()-1] != s[i]){
            t.push_back(s[i]);
        }
    }
    cout << t.size() << endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
main(){
    int a,op,b;
    for(int i=0;;i++){
        scanf("%d %s %d",&a,&op,&b);
        if(op=='?')break;
        if(op=='+'){
            printf("%d\n",a+b);
        }else if(op=='-'){
            printf("%d\n",a-b);
        }else if(op=='*'){
            printf("%d\n",a*b);
        }else if(op=='/'){
            printf("%d\n",a/b);
        }
    }
}


Measured memory_bytes: 2080
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 6223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;

int N, M, S;
const int MAX = 1250000;
struct edge { int to, cost; };
vector<vector<edge> > G;
VI d;

void dikstra(int s) {
	priority_queue<pii, vector<pii>, greater<pii> >que;
	REP(i, MAX)d[i] = LLINF;
	d[s] = 0;
	que.push(pii(0, s));
	while (!que.empty()) {
		pii p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		REP(i, G[v].size()) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(pii(d[e.to], e.to));
			}
		}
	}
}

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


	G.resize(MAX);
	d.resize(MAX);

	cin >> N >> M >> S;
	chmin(S, 2500LL);
	int k = 0;
	map<pii, int>mp;
	REP(i, N) {
		eREP(j, 2500) mp[pii(i, j)] = k++;
	}
	REP(i, M) {
		int u, v, a, b; cin >> u >> v >> a >> b;
		u--; v--;
		eFOR(j,a, 2500) {
			G[mp[pii(u, j)]].push_back((edge) { mp[pii(v, j - a)], b });
			G[mp[pii(v, j)]].push_back((edge) { mp[pii(u, j - a)], b });
		}
	}

	REP(i, N) {
		int c, d; cin >> c >> d;
		eREP(j, 2500 - c) {
			G[mp[pii(i, j)]].push_back((edge) { mp[pii(i, j + c)], d });
		}
	}

	dikstra(mp[pii(0, S)]);

	FOR(i, 1, N) {
		int ans = LLINF;
		eREP(j, 2500) chmin(ans, d[mp[pii(i, j)]]);
		cout << ans << endl;
	}

	return 0;
}



Measured memory_bytes: 66744
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#define ll long long

using namespace std;
ll n,a,b,i,j;
ll mid,r,s,l,t,num;
ll h[1000010],h1[1000010];

bool jud(long long mid)
{
    s=b*mid;
    t=a-b;
    for(j=0;j<n;j++)
    {
        h1[j]=h1[j]-s;
        if(h1[j]<=0)
            continue;
            if(h1[j]%t==0)
                {
                    num=h1[j]/t;
                }
            else
                {
                    num=h1[j]/t+1;
                }
            mid=mid-num;
    }
    if(mid>=0)
        return true;
    else
        return false;
}

int main()
{
    scanf("%d%d%d",&n,&a,&b);
    for(i=0;i<n;i++)
    {
        scanf("%d",&h[i]);
        h1[i]=h[i];
    }
    sort(h,h+n);
    sort(h1,h1+n);
    r=h[n-1];
    //cout<<r<<endl;
    l=0;
    while(r-l>1)
    {
        mid=(r+l)/2;
        if(jud(mid))
            r=mid;
        else
            l=mid;

        for(i=0;i<n;i++)
            h1[i]=h[i];
    }
    printf("%d\n",r);
    return 0;
}


Measured memory_bytes: 5120
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
/**************************************************************************/
signed main()
{
    fast;
    int n,k;
    cin>>n>>k;
    int h[n+1];
    int dp[n+1];
    for(int i=1;i<=n;i++)
        cin>>h[i];
    dp[1] = 0;
    dp[2] = abs(h[2]-h[1]);
    for(int i=3;i<=n;i++)
    {
        dp[i] = dp[i-1]+abs(h[i]-h[i-1]);
        for(int j=i-2;j>=max(i-k,(int)1);j--)
        {
            dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));
        }
    }
    cout<<dp[n];
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
int n,m,i,j,k,l,x,y,z,a,b,c,aa,bb,cc;
x=0;y=0;z=0;
scanf("%d%d%d",&a,&b,&c);
aa=a;bb=b;cc=c;
if((aa%2)+(bb%2)+(cc%2)==1){
if(aa%2==1){b++;c++;}
if(bb%2==1){a++;c++;}
if(cc%2==1){b++;a++;}
x++;}
if((aa%2)+(bb%2)+(cc%2)==2){
if(aa%2==0){b++;c++;}
if(bb%2==0){a++;c++;}
if(cc%2==0){b++;a++;}
x++;}
if(a>=b&&a>=c){x+=(2*a-b-c)/2;}
if(b>a&&b>=c){x+=(2*b-a-c)/2;}
if(c>a&&c>b){x+=(2*c-a-b)/2;}
printf("%d\n",x);
return 0;
}




Measured memory_bytes: 128
s = list(map(int, input()))[::-1]
l = len(s)
b = 1<<(l-1)

sum = 0
for i in range(b):
  conseq = 0
  for j in range(l):
    sum += s[j] * 10**conseq
    if i>>j & 1:
      conseq = 0
    else:
      conseq += 1
      
print(sum)

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

using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int> v(n, 0), dp(n, 0);
    for(int i = 0; i < n; ++i)
        cin >> v[i];

    dp[0] = 0;
    dp[1] = abs(v[1] - v[0]);

    for(int i = 2; i < n; ++i)
        dp[i] = min(abs(v[i] - v[i - 1]) + dp[i - 1], abs(v[i] - v[i - 2]) + dp[i - 2]);

    cout << dp[n - 1] << '\n';
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //srand (time(0));

    solve();
}






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

int main(int argc, const char * argv[]) {
    long long a,b;
    cin>>a>>b;
    if(a*b<=0)cout<<"Zero"<<endl;
    else if(a>0 && b>0)cout<<"Positive"<<endl;
    else if(a<0 && b<0 && (b-a)%2==0)cout<<"Negative"<<endl;
    else if(a<0 && b<0 && (b-a)%2!=0)cout<<"Positive"<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

func getScanner(fp io.Reader) *bufio.Scanner {
	sc := bufio.NewScanner(fp)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 500001), 500000)
	return sc
}

func getHugeScanner(fp io.Reader, size int) *bufio.Scanner {
	sc := bufio.NewScanner(fp)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, size), size)
	return sc
}

func getNextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func getNextInt(sc *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(sc))
	return i
}

func getNextInt64(sc *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(sc), 10, 64)
	return i
}

func getNextFloat64(sc *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(sc), 64)
	return i
}

func Solve(stdin io.Reader, stdout io.Writer) {
	sc := getScanner(stdin)

	n := getNextInt(sc)
	m := getNextInt(sc)

	s := make([][]int, m)
	on := make([]bool, n)

	for i := 0; i < m; i++ {
		k := getNextInt(sc)
		s[i] = make([]int, k)
		for j := 0; j < k; j++ {
			s[i][j] = getNextInt(sc)
			s[i][j]--
		}
	}

	p := make([]int, m)
	for i := 0; i < m; i++ {
		p[i] = getNextInt(sc)
	}

	ans := 0
	for i := 0; i < int(math.Pow(2, float64(n))); i++ {
		mask := 1
		for j := 0; j < n; j++ {
			on[j] = (i & mask) > 0
			mask <<= 1
		}

		x := true
		for j := 0; j < m; j++ {
			num := 0
			for k := 0; k < len(s[j]); k++ {
				if on[s[j][k]] {
					num++
				}
			}
			if num % 2 != p[j] {
				x = false
				break
			}
		}
		if x {
			ans++
		}
	}

	_, _ = fmt.Fprintf(stdout, "%v\n", ans)
}

func main() {
	Solve(os.Stdin, os.Stdout)
	return
}

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

int solve(int i,int j,int k){
	int ans = i*i + j*j + k*k + i*j + i*k + k*j;
	return ans;
}


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

	vector<int>arr(10001);
	f(i,10001){
		arr[i]=0;
	}

	for(int i = 1;i<=100;i++){
		for(int j = 1;j<=100;j++){
			for(int k = 1;k<=100;k++){
				int ans = solve(i,j,k);
				if(ans<=10000)
				arr[ans]++;
			}
		}
	}

	for(int i = 1;i<=n;i++){
		printf("%d\n",arr[i]);
	}
}

Measured memory_bytes: 3692
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main(){
   int N, L;
   std::cin >> N >> L;
   std::vector<std::string> S(N);
   for (int i=0; i<N; i++){
      std::cin >> S.at(i);
   }
   std::sort(S.begin(), S.end());
   std::string Sout;
   for (int i=0; i<N; i++){
      Sout = Sout + S.at(i);
   }
   std::cout << Sout << std::endl;
}



Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn input_char_vec() -> Vec<char> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().chars().collect()
}

fn main() {
    for i in 0..3 {
        let s = input_char_vec();
        print!("{}", s[i]);
    }
    println!();
}


Measured memory_bytes: 2072
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cctype>
#define rg register
#define int long long 
using namespace std;
inline int read(){
	rg int s=0,f=0;
	rg char ch=getchar();
	while(!isdigit(ch)) f|=(ch=='-'),ch=getchar();
	while(isdigit(ch)) s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
	return f?-s:s;
}
signed main(){
	int n=read();
	printf("%lld",n*n*n);
	return 0;
}

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

int main() {
	int n, m, c;
	cin >> n >> m >> c;
	int b[m], a[n][m];
	for (int i = 0; i < m; i++)
		cin >> b[i];

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> a[i][j];

	int count = 0;
	for (int i = 0, sum; i < n; i++) {
		sum = c;
		for (int j = 0; j < m; j++)
			sum += a[i][j] * b[j];
		if (sum > 0)
			count++;
	}
	cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    
        int A, B, C;
        cin >> A >> B >> C;
        int ans = 0;
        int i = 0;
        
        while(true){
            i++;
            if(i%7 != 0){
                C-=A;
                ans++;
                if(C <= 0) break;
            }
            else{
                C-=(A+B);
                ans++;
                    if(C <= 0) break;
            }
            
        }
        
        cout << ans << endl;

}



Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <cmath>
#define EPS (1.0e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

using namespace std;


int S, A, C;
int M;
int N;
int R[256], I[256], O[256];

double m_log[300];

void calcR() {
  for(int i = 0; i < N; ++i) {
    if(i == 0) R[i] = (A*S+C)%M;
    else       R[i] = (A*R[i-1]+C)%M;
  }
}

void calcO() {
  calcR();
  for(int i = 0; i < N; ++i) {
    O[i] = (I[i]+R[i]) % M;
  }
}

double H() {
  double ans = 0;
  int buf[256];
  fill(buf, buf+256, 0);

  calcO();

  for(int i = 0; i < N; ++i) {
    ++buf[O[i]];
  }

  for(int i = 0; i < 256; ++i) {
    if(buf[i] == 0) continue;
    ans += -buf[i] * (m_log[buf[i]] - m_log[N]);
  }
  return ans;
}

void solve() {
  int aS, aA, aC;
  double minH = 99999999;
  for(S = 0; S <= 15; ++S) {
    for(A = 0; A <= 15; ++A) {
      for(C = 0; C <= 15; ++C) {
	double tmp = H();
	if(S == 8 || A == 7 || C == 14) {
	  // for(int i = 0; i < N; ++i) cout << O[i] << " ";
	  //cout << endl;
	}
	//if(tmp == 0) printf("%d %d %d %.20f\n", S, A, C, tmp);
	if(equals(tmp, minH)) {
	  if(aS > S || aS == S && aA > A || aS == S && aA == A && aC > C) {
	    aS = S;
	    aA = A;
	    aC = C;
	  }
	} else if(tmp < minH) {
	  minH = tmp;
	  aS = S;
	  aA = A;
	  aC = C;
	}
      }
    }
  }
  cout << aS << " " << aA << " " << aC << endl;
}

main() {
  M = 256;
  for(int i = 1; i <= 300; ++i) m_log[i] = log(i);
  while((cin >> N) && N) {
    for(int i = 0; i < N; ++i) cin >> I[i];
    solve();
  }
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define min(a, b) (a > b ? b : a)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    int n, query;
    cin >> n >> query;
    
    vector<vector<int> > v(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        v[a].eb(b);
        v[b].eb(a);
    }
    
    int table[200001] = {0}; // 頂点0から数字でかく
    
    
    
    // outa(table, n);
    
    int value[200001] = {0};
    
    rep(i, query) {
        int p, x;
        cin >> p >> x;
        p--;
        value[p] += x;
    }
    
    queue<pair<int, pii> > q;
    table[0] = value[0];
    q.push({0 + value[0], {0, -1}});
    
    // outa(value, n);
    // int sum = 0;
    while (!q.empty()) {
        int sum = q.front().F;
        int now = q.front().S.F;
        int bef = q.front().S.S;
        
        q.pop();
        
        for (auto nxt : v[now]) {
            if (nxt == bef) continue;
            table[nxt] = sum + value[nxt];
            q.push({table[nxt], {nxt, now}});
        }
    }
    outa(table, n);
    /*
    vector<vector<int> > dis(200001);
    rep(i, n) {
        dis[table[i]].eb(i);
    }
    
    
    int ans[200001] = {0};
    
    int sum = 0;
    rep(i, 200001) {
        if (SZ(dis[i]) == 0) break;
        for (auto di : dis[i]) {
            sum += value[di];
        }
        
    }
    */
    
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
    LL N;
    cin >> N;
    VLL memo(5, 0);
    REP(i, 5) cin >> memo[i];

    sort(ALL(memo));

    if (N <= memo[0]) {
        cout << 5 << endl;
    } else {
        cout << (5 + N / memo[0] - (N % memo[0] == 0)) << endl;
    }
}

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

long long N;
long long u[200005];
long long v[200005];

int main(){
	cin >> N;
	for(long long i = 0; i < N - 1; i++) {
		cin >> u[i] >> v[i];
		u[i]--; v[i]--;
		if(u[i] > v[i]) {
			swap(u[i], v[i]);
		}
	}

	long long maxi = 0;

	for(long long i = 0; i < N; i++) {
		long long num = N-i;
		maxi += ((num) * (num+1))/2;
	}


	for(long long i = 0; i < N - 1; i++) {
		long long left = u[i];
		long long right = v[i];

		long long leftcount = left + 1;
		long long rightcount = N - right;
		maxi -= leftcount * rightcount;
	}
	cout << maxi << endl;

}


Measured memory_bytes: 6724
x,y,num = map(int, input().split())
gaiz = [x]*x
kaisu = x
for _ in range(num):
    xg,yg = map(int,input().split())
    if xg >= yg:
        sa = xg-yg
        if yg < gaiz[sa]:
            gaiz[sa]=(yg)
 
if len(gaiz) ==0:
    print(kaisu)
else:
    for num,(maegai,gai) in enumerate(zip(gaiz[:-1],gaiz[1:])):
        if maegai>gai and num+gai < kaisu:
            kaisu = num+gai
    print(kaisu) 

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


int N, M;
vector<pll> job;
bool busy[100000];

signed main(){
    cin >> N >> M;
    int a, b;
    REP(i, N){
        cin >> a >> b;
        job.push_back(pint(a, b));
    }
    sort(ALL(job));
    int head = 0;
    ll ans = 0;
    priority_queue<pint, vector<pint>, less<pint>> que;
    FOR(i, 1, M + 1){
        while(job[head].first == i){
            que.push(pint(job[head].second, job[head].first));
            head++;
        }
        if(que.empty()) continue;
        ans += que.top().first;
        que.pop();
    }
    PRINT(ans);
    return 0;


}

Measured memory_bytes: 3568
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	char[][] chm = new char[8][5];



	void run() {

		for (boolean first = true; sc.hasNextInt(); first = false) {

			if (!first) {

				System.out.println();

			}



			for (int i = 0; i < 8; i++) {

				Arrays.fill(chm[i], '*');

			}

			Arrays.fill(chm[2], '=');



			int d = sc.nextInt();

			for (int i = 0; i < 5; i++) {

				int m = d % 5;

				chm[3 + m][4 - i] = ' ';

				int m2 =1- (d %10)/ 5;

				chm[m2][4 - i] = ' ';

				d /= 10;

			}

			for (int i = 0; i < 8; i++) {

				System.out.println(new String(chm[i]));

			}

		}



	}



	public static void main(String[] args) {

		Main m = new Main();

		m.run();

	}

}

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

struct node
{
	string s;
};
vector<string> sv[100010];
int main()
{
	int n,m;
	cin>>n>>m;
	if(m==0) 
	{
		cout<<0<<" "<<0<<endl;return 0;
	}
	vector<int> v;
	map<int,int> mp;
	for(int i=1;i<=m;i++)
	{
		int num;
		string s;
		cin>>num;
		cin>>s;
		if(mp[num]==0) v.push_back(num),mp[num]++;
		sv[num].push_back(s);
	}
	int Acans=0,Waans=0;
	for(int i=0;i<v.size();i++)
	{
		int flag=0,temp=0;
		for(int j=0;j<sv[v[i]].size();j++)
		{
			if(sv[v[i]][j]=="AC") 
			{
				Acans++,flag=1;break;
			}
			else temp++;
		}
		if(flag==1) Waans+=temp;
	}
	cout<<Acans<<" "<<Waans<<endl;
	return 0;
}

Measured memory_bytes: 15484
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int gcd(int a,int b){
  if (a>b) swap(a,b);
  if (a==0) return b;
  return gcd(b%a,a);
}


int main(void){
  ll a,b;
  
  cin >> a >> b;
  
  cout << a/gcd(a,b)*b << endl;
  
  return 0;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c;
    int ans = 0;
    d = max(a, max(b, c));
    if (d == a) {
        ans = a * 10 + b + c;
    }
    else if (d == b) {
        ans = b * 10 + a + c;
    }
    else {
        ans = c * 10 + a + b;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
from collections import Counter
def main():
    n, *a = map(int, read().split())

    if 1 in a:
        count1 = a.count(1)
        if count1 == 1:
            print(1)
            sys.exit()
        else:
            print(0)
            sys.exit()
    a = np.array(a)
    maxa = a.max()
    seq = np.zeros(maxa + 1, np.int32)
    u, cnt = np.unique(a, return_counts=True)
    for ue, cnte in zip(u, cnt):
        if cnte == 1:
            seq[ue] = 1
    for ae in a:
        t = ae * 2
        while t <= maxa:
            seq[t] = 0
            t += ae
    r = seq.sum()
    print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 50380
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var N = int.Parse(ReadLine());
            var h = ReadLine().Split().Select(int.Parse).ToArray();

            var ans = h[0];
            for (int i = 1; i < N; i++)
            {
                if (h[i] > h[i - 1]) ans += h[i] - h[i - 1];
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
import sys
input = sys.stdin.readline
from math import sqrt
def main():
    N = int(input())
    A = [0]*(N+1)
    n = int(sqrt(N)) + 1
    for x in range(1, n):
        for y in range(1, n):
            for z in range(1, n):
                tmp = x*x + y*y + z*z + x*y + y*z + z*x
                if tmp <= N:
                    A[tmp] += 1
    for i in range(1,N+1):
        print(A[i])

if __name__ == '__main__':
    main()

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

int main() {
  vector<vector<vector<int>>> p(3, vector<vector<int>>(3, vector<int>(2, 0)));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      int a;
      cin>>a;
      p.at(i).at(j).at(0)=a;
    }
  }
  int N;
  cin>>N;
  for(int i=0;i<N;i++){
    int b;
    cin>>b;
    for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      if(b==p.at(i).at(j).at(0)){
        p.at(i).at(j).at(1)=1;
      }
    }
  }
  }
  string Z="No";
    if(p.at(0).at(0).at(1)&&p.at(0).at(1).at(1)&&p.at(0).at(2).at(1)){
      Z="Yes";
    }
    else if(p.at(1).at(0).at(1)&&p.at(1).at(1).at(1)&&p.at(1).at(2).at(1)){
      Z="Yes";
    }
    else if(p.at(2).at(0).at(1)&&p.at(2).at(1).at(1)&&p.at(2).at(2).at(1)){
      Z="Yes";
    }
    else if(p.at(0).at(0).at(1)&&p.at(1).at(0).at(1)&&p.at(2).at(0).at(1)){
      Z="Yes";
    }
    else if(p.at(0).at(1).at(1)&&p.at(1).at(1).at(1)&&p.at(2).at(1).at(1)){
      Z="Yes";
    }
    else if(p.at(0).at(2).at(1)&&p.at(1).at(2).at(1)&&p.at(2).at(2).at(1)){
      Z="Yes";
    }
    else if(p.at(0).at(0).at(1)&&p.at(1).at(1).at(1)&&p.at(2).at(2).at(1)){
      Z="Yes";
    }
    else if(p.at(0).at(2).at(1)&&p.at(1).at(1).at(1)&&p.at(2).at(0).at(1)){
      Z="Yes";
    }
    cout<<Z<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to;
	ld cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	/*if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;*/
	return ((a.x + 1)*(a.y + 1)) < ((b.x + 1)*(b.y + 1));
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll x, ll k, ll p) {//最大値、個数
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
 //#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
ld d, ans;
ld MAX(ld x) {
	ld y = sqrt(d*d - x*x);
	return x + y;
}
signed main() {
	cin >> d;
	ans = d;
	for (int x = 1; x <= 20; x++) {
		ld y = d*d - x*x;
		if (y < 0) break;
		if (y <= 1) ans = max(ans, (ld)x + 1);
		else ans = max(ans, x + sqrt(y));
	}
	ld s = 0, e = d, t1, t2;
	while (e - s > 0.0000000000001) {
		t1 = s + (e - s) / 3, t2 = s + (e - s) / 3 * 2;
		ld r1 = MAX(t1), r2 = MAX(t2);
		if (r1 == r2) s = t1, e = t2;
		else if (r1 > r2) e = t2;
		else s = t1;
	}
	printf("%.15LF\n", max(MAX(s),ans));
	getchar(); getchar();
}


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

using namespace std;


int main() {
  
    
    long int x,ans=0;
    scanf("%ld",&x);
    long int sum=0;
    while(x>=5)
    {
        if(x>=500)
          {
              ans=x/500;
              x=x-(ans*500);
              sum+=1000*ans;
          }
          
        else
          {
                ans=x/5;
              x=x-(ans*5);
              sum+=5*ans;
          }
    }
    
    printf("%ld",sum);
    	return 0;
} 

Measured memory_bytes: 256
import java.util.*;

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

    long n = sc.nextLong();
    long k = sc.nextLong();
    
    long buf = n / k;
    long ans = Math.min(n - k * buf, k * (buf + 1) - n);

    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
loop do
  line = gets
  break if line.nil?
  a,b,c,d,e,f = line.chomp.split(' ').map(&:to_f)
  y = ((c * d) - (f * a)) / ((b * d) - (e * a))
  x = (c - b * y) / a
  printf("%.3f %.3f\n", x.round(4), y.round(4))
end

Measured memory_bytes: 8760
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int n,m,cnt=1,o=0,p,aa[220000],cntl=0,ab[220000];
pair<int,int> pp[220000];
string s,sa,ss[220000];
char c,cc[220000];
queue<int> que;
signed main(){
    ab[0]=1;
    cin>>n>>m;
    rep(i,n){
        cin>>aa[i];
    }
    while(1){
        o=aa[o]-1;
        cnt++;
        m--;
        if(m==0){
            cout<<o+1;
            return 0;
        }
        if(ab[o]==0){
            ab[o]=cnt;
        }else{
            break;
        }
    }
    m=m%(cnt-ab[o]);
    rep(i,m){
        o=aa[o]-1;
    }
    cout<<o+1;
}

Measured memory_bytes: 13604
N, P = map(int, input().split())
S = input()

counter=0
def power_func(a,b,p):
    if b==0:
        return 1
    elif b%2==0:
        d=power_func(a,b//2,p)
        return d*d %p
    elif b%2==1:
        return (a*power_func(a,b-1,p ))%p
if P==2:
    counter = 0
    for i in range(len(S)):
        if S[i] in ['2','4','6','8','0']:
            counter+=i+1
elif P==5:
    counter = 0
    for i in range(len(S)):
        if S[i] in ['5','0']:
            counter+=i+1
else:
    list_a=[0]*P
    list_a[0]+=1
    temp=0
    for i in range(N):
        M = power_func(10,N-i,P)
        temp=(int(S[i])*M+temp)%P
        counter+=list_a[temp]
        list_a[temp]+=1
print(counter)

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n+1);
    rep(i,n) cin >> a[i+1];

    vector<ll> leftCnt(n+1);
    vector<ll> rightCnt(n+1);
    for(int i=1; i<=n; i++){
        if(i+a[i]<=n) rightCnt[i+a[i]]++;
        if(i-a[i]>0)  leftCnt[i-a[i]]++;
    }

    ll ans=0;
    for(int i=2; i<n; i++){
        ans += (leftCnt[i] * rightCnt[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8008