akhauriyash/Code-Regression huggingface dataset:
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

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

        int N = sc.nextInt();
        BigInteger M = new BigInteger(new Integer(sc.nextInt()).toString());

        int[] A = new int[N];
        int[] B = new int[N];

        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
        }

        sc.close();

        sort(A, B);

        BigInteger count = new BigInteger("0");
        BigInteger value = new BigInteger("0");

        for(int i=0; i<N; i++){
            if(count.add(new BigInteger(new Integer(B[i]).toString())).compareTo(M) <= 0){
                count = count.add(new BigInteger(new Integer(B[i]).toString()));
                value = value.add(new BigInteger(new Integer(A[i]).toString()).multiply(new BigInteger(new Integer(B[i]).toString())));
                if(count.compareTo(M) >= 0){
                    break;
                }
            }else{
                value = value.add(new BigInteger(new Integer(A[i]).toString()).multiply(M.subtract(count)));
                break;
            }
        }

        System.out.println(value);

    }

    /*
     * 軸要素の選択
     * 順に見て、最初に見つかった異なる2つの要素のうち、
     * 大きいほうの番号を返します。
     * 全部同じ要素の場合は -1 を返します。
     */
    static int pivot(int[] a,int i,int j, int[] b){
        int k=i+1;
        while(k<=j && a[i]==a[k]) k++;
        if(k>j) return -1;
        if(a[i]>=a[k]) return i;
        return k;
    }

    /*
     * パーティション分割
     * a[i]～a[j]の間で、x を軸として分割します。
     * x より小さい要素は前に、大きい要素はうしろに来ます。
     * 大きい要素の開始番号を返します。
     */
    static int partition(int[] a,int i,int j,int x, int[] b){
        int l=i,r=j;

        // 検索が交差するまで繰り返します
        while(l<=r){

            // 軸要素以上のデータを探します
            while(l<=j && a[l]<x)  l++;

            // 軸要素未満のデータを探します
            while(r>=i && a[r]>=x) r--;

            if(l>r) break;
            int t=a[l];
            a[l]=a[r];
            a[r]=t;

            int tb=b[l];
            b[l]=b[r];
            b[r]=tb;

            l++; r--;
        }
        return l;
    }

    /*
     * クイックソート（再帰用）
     * 配列aの、a[i]からa[j]を並べ替えます。
     */
    public static void quickSort(int[] a,int i,int j, int[] b){
        if(i==j) return;
        int p=pivot(a,i,j, b);
        if(p!=-1){
            int k=partition(a,i,j,a[p], b);
            quickSort(a,i,k-1, b);
            quickSort(a,k,j, b);
        }
    }

    /*
     * ソート
     */
    public static void sort(int[] a, int[] b){
        quickSort(a,0,a.length-1, b);
    }

}


Measured memory_bytes: 91028
fun main(args: Array<String>) {
    val (n,m,c) = readLine()!!.split(" ").map { it.toInt() }
    val b = readLine()!!.split(" ").map { it.toInt() }
    val a = (1..n).map{ readLine()!!.split(" ").map { it.toInt() }}

    a.map { list->
        list.mapIndexed { i,it->it*b[i] }.sum()+c
    }.count{ it>0 }.let { println(it) }
}

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

#if debug
#include "printer.hpp"
#define dump(a) cerr << #a << "(" << __LINE__ << ") = " << a << endl;
#else
#define dump(...)
#endif

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a, b) for (int i = (b) - 1; i >= a; i--)
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
const ll mod = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(8);

  ll N;
  string S;
  cin >> N >> S;
  
  ll ans = 1;
  rep(i, 0, N - 1) {
    if (S[i] != S[i + 1]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int main(){

  char a[101];
  scanf("%s",a);

  char s[101];
  scanf("%s",s);

  char c[101];
  scanf("%s",c);

  printf("A%cC",s[0]);

  return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;
    vector<int> L(n, -1), R(n, -1), pos;
    for(int i = 0; i < n; ++i){
        if(s[i] == 'o') pos.emplace_back(i);
    }
    L[pos[0]] = 1, R[pos.back()] = k;
    for(int i = 0; i < n; ++i){
        if(s[i] == 'x') continue;
        if(L[i] == -1)  continue;
        auto it = upper_bound(pos.begin(), pos.end(), i + c);
        if(it != pos.end()) L[*it] = min(L[i] + 1, k);
    }
    for(int i = n - 1; i >= 0; --i){
        if(s[i] == 'x') continue;
        if(R[i] == -1)  continue;
        auto it = lower_bound(pos.begin(), pos.end(), i - c);
        if(it != pos.begin())   R[*(--it)] = max(R[i] - 1, 1);
    }
    vector<int> cntL(k + 1, 0), cntR(k + 1, 0);
    for(int i = 0; i < n; ++i){
        if(s[i] == 'x') continue;
        if(L[i] != -1)  ++cntL[L[i]];
        if(R[i] != -1)  ++cntR[R[i]];
    }
    for(int i = 0; i < n; ++i){
        if(s[i] == 'x') continue;
        if(L[i] == -1 || R[i] == -1)    continue;
        if(cntL[L[i]] > 1 || cntR[R[i]] > 1)    continue;
        if(L[i] == R[i])    cout << i + 1 << endl;
    }
}

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

int main(){
    long long number,blueball,redball,answer;
    cin >> number >> blueball >> redball;
    if (redball ==0 && blueball == 0){
        answer =0;
    }
    else if(number % (blueball + redball) <= blueball){
    	answer = (number / (blueball + redball)) * blueball;
        answer += number % (blueball + redball);
    }
    else{
        answer = (number / (blueball + redball)) * blueball;
        answer += blueball;
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
program Y042C
    implicit none
    integer(8)::N,ans,Ac(100000),i
    integer(8),allocatable,dimension(:)::A
    read*,N
    allocate(A(N))
    read*,A
    Ac=0
    call heapsort(N,A)
    ans=0

    do i=1,N
        if(A(i)>100000)then
            ans=ans+1
        else
            Ac(A(i))=Ac(A(i))+1
        end if
    end do
    
    do i=1,100000
        if(Ac(i)<i)then
            ans=ans+Ac(i)
        else
            ans=ans+Ac(i)-i
        end if
    end do

    print'(i0)',ans
end program Y042C

subroutine heapsort(n,array)
    implicit none
    integer(8),intent(in) :: n
    integer(8),intent(inout) :: array(1:n)
   
    integer(8) ::i,k,j,l
    integer(8) :: t
   
    if(n.eq.1)return
  
    l=n/2+1
    k=n
    do while(k.ne.1)
       if(l.gt.1)then
          l=l-1
          t=array(L)
       else
          t=array(k)
          array(k)=array(1)
          k=k-1
          if(k.eq.1) then
             array(1)=t
             exit
          endif
       endif
       i=l
       j=l+l
       do while(j.le.k)
          if(j.lt.k)then
             if(array(j).lt.array(j+1))j=j+1
          endif
          if (t.lt.array(j))then
             array(i)=array(j)
             i=j
             j=j+j
          else
             j=k+1
          endif
       enddo
       array(i)=t
    enddo
  
    return
  end subroutine heapsort

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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  for (int i = 0; i < m; i++)
  {
    cin >> a[i];
    n -= a[i];
  }
  if (n < 0)
  	cout << -1 << endl;
  else
    cout << n << endl;
}
  

Measured memory_bytes: 3632
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;

using namespace std;

int main() 
{   
    int n;
    cin >> n;
    map<char, int> s;
    irep(i,n) {
        char tmp;
        cin >> tmp;
        s[tmp] = 1;
    }
    
    if(s.size() == 3) {
        cout << "Three" << endl;
    } else {
        cout << "Four" << endl;
    }
    return 0;
}
    



Measured memory_bytes: 256
swithCount, lightCount = map(int, input().split())
swithList = [0] * swithCount

for lightIndex in range(lightCount):
    connectedSwitchList = list(map(int, input().split()))
    for si in connectedSwitchList[1:]:
        switchIndex =  si - 1
        swithList[switchIndex] = swithList[switchIndex] | 1 << lightIndex

expectedLightStatusList = list(map(int, input().split()))
expectedLightStatus = 0

for i, eachStatus in enumerate(expectedLightStatusList):
    expectedLightStatus = expectedLightStatus | eachStatus << i

resultCount = 0
for eachSwitchSet in range(1 << swithCount):
    actuallyLightStatus = 0
    for switchIndex in range(swithCount):
        if eachSwitchSet >> switchIndex & 1:
            actuallyLightStatus = actuallyLightStatus ^ swithList[switchIndex]

    if expectedLightStatus == actuallyLightStatus:
        resultCount += 1

print(resultCount)



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;

using namespace std;



int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    sort(l.begin(), l.end());
    int ans = 0;
    rep(i,n-2) {
        int pos = i+2;
        for(int j = i+1; j < n-1; j++) {
            if(pos == j) pos++;
            while(l[pos] < l[i]+l[j] && pos < n) {
                pos++;
            }
            pos--;
            if(pos == j) {
                pos++;
                continue;
            }
            ans += pos - j;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>

int main() {
	char S[4];
	int ifBad=0;

	gets(S, 4);
	for (int i = 0;i < 4;i++) {
		if (i != 3 && S[i] == S[i + 1])
			ifBad = 1;
	}
	if (ifBad)
		printf("Bad");
	else
		printf("Good");
	return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	LL c = 1e9;
	LL S;
	cin >> S;

	cerr << S / c << endl;
	if(S < c){
		cout << "0 0 " << S << " 1 0 1" << endl;	
	}
	else{
		LL x1 = (S + c - 1) / c;
		LL y2 = c;
		LL y1 = 1;
		LL x2 = (__int128_t)x1 * y2 - S;
		cout << "0 0 " << x1 << " " << y1 << " " <<  x2 << " " << y2 << endl;
		cerr << abs((LL)((__int128_t)x1 * y2 - (__int128_t)x2 * y1)) << endl;
	}


	return 0;
}


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

int main(){
  int n;
  cin >> n;
  char s;
  string ans="Three";
  for(int i=0;i<n;i++){
    cin >> s;
    if(s=='Y'){
      ans="Four";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3576
import bisect

a,b,q = map(int,input().split())

s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]
x = [int(input()) for i in range(q)]

ans = 10**100

for i in range(q):
    ans = 10**100
    s_idx = bisect.bisect_left(s,x[i])
    t_idx = bisect.bisect_left(t,x[i])
    s_idx -= 1
    t_idx -= 1
    #print(x[i],s_idx,t_idx)
    for j in range(2):
        for k in range(2):
            ans = min(ans,abs(x[i] - s[min(s_idx+j,a-1)]) + abs(s[min(s_idx+j,a-1)] - t[min(t_idx+k,b-1)]))
            ans = min(ans,abs(x[i] - t[min(t_idx+k,b-1)]) + abs(s[min(s_idx+j,a-1)] - t[min(t_idx+k,b-1)]))
            
    print(ans)

Measured memory_bytes: 16144
#include<iostream>
#include<cstdio>
using namespace std;
#define P 1000000007
typedef long long ll;
int x,y,i,j,m,n;
ll f[1010][1010],fac[1000010];
bool flag;
inline void facborn()
{
  fac[0]=fac[1]=1;
  for(int i=2;i<=1000000;i++)
    fac[i]=fac[i-1]*i%P;
}
inline ll fastpow(ll a,ll n,ll p)
{
  ll ans=1;
  while(n)
  {
    if(n&1)ans=ans*a%P;
	a=a*a%P;
	n>>=1;
  }
  return ans;
}
//inline ll fac(int x){ll res=1;for(int i=2;i<=x;i++)res=res*i%P;return res%P;}
inline ll ny(int b,int p)
{
  return fastpow(b,p-2,p);
}
inline ll C(int n,int m)
{
  if(n==m)return 1;
  else return fac[n]*ny(fac[m],P)%P*ny(fac[n-m],P)%P;
}
int main()
{
  //freopen("t4.in","r",stdin);
  //freopen("t4.out","w",stdout);
  cin>>x>>y;facborn();
  if((x+y)%3!=0){cout<<0<<endl;return 0;}
  n=(x+y)/3;
  if(n<=x&&x<=2*n&&n<=y&&y<=2*n)flag=1;
  if(!flag){cout<<0<<endl;return 0;}
  m=2*n-x+1;
  n++;
  //cout<<n<<" "<<m<<endl;
  //cout<<C(6,3)<<endl;
  //cout<<fac(666666)<<endl;
  //cout<<fac(333333)<<endl;
  cout<<C(n-1,m-1)%P<<endl;
  //cout<<C(6,3)<<endl;
  /*f[0][0]=f[1][2]=f[2][1]=1;
  for(i=1;i<=15;i++)
    for(j=1;j<=15;j++)
	  if(i!=1&&j!=1)
        f[i][j]=f[i-1][j-2]+f[i-2][j-1];
  for(i=1;i<=15;i++){
    for(j=1;j<=15;j++)
	  cout<<f[i][j]<<" ";
	cout<<endl;}*/
  //cout<<f[x][y]<<endl;
  return 0;
}

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

#define ll long long

using namespace std;

const int MAXN = 1010;
const int MAXM = 100010;
const int MAXINT = 2147483647;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n, m, k;
int ans, tot, cnt;

int a[MAXN][MAXN], b[MAXN][MAXN];

string s;

inline int read() {
	int s = 0, f = 1;
	char ch = getchar();
	while ('0' > ch || ch > '9') {if (ch == '-') f = -1; ch = getchar();}
	while ('0' <= ch && ch <= '9') {s = (s << 3) + (s << 1) + ch - 48; ch = getchar();}
	return s * f;
}

void re() {
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			a[i][j] = b[i][j];
		}
	}
}

int count() {
	int res = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i][j] == 1) {
				res++;
			}
		}
	}
	return res;
}

int main(){
	int T;
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; i++) {
		cin >> s;
		for (int j = 0; j < s.size(); j++) {
			if (s[j] == '#') a[i][j + 1] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			b[i][j] = a[i][j];
		}
	}
	for (int i = 0; i < (1 << n); i++) {
		for (int j = 0; j < (1 << m); j++) {
			int x = i, y = j, num = 1;
			while (num <= n) {
				if (x & 1) for (int k = 1; k <= m; k++) a[num][k] = 2;
				x >>= 1;
				++num;
			}
			num = 1;
			while (num <= m) {
				if (y & 1) for (int k = 1; k <= n; k++) a[k][num] = 2;
				y >>= 1;
				++num;
			}
			num = count();
			if (num == k) ans++;
			re();
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3796
#include<stdio.h>

void main()
{
	int scanCheck = 0;
	int x, y;
	int turu, kame;


	scanCheck = scanf("%d", &x);
	scanCheck = scanf("%d", &y);

	turu = 2 * x - 0.5 * y;
	kame = 0.5 * y - x;
	if ((turu < 0) || (kame < 0)) {
		printf("No");
	}
	else if ((turu + kame == x) && (2 * turu + 4 * kame == y)) {
		printf("Yes");
	}
	else {
		printf("No");
	}
}

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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    if(k == 1) cout << 0 << ln;
    else cout << n - k << ln;
    return 0;
}


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

struct UnionFind{
    vector<int> par;
    UnionFind(int n) : par(n){
       REP(i, n) par[i] = i;
    }
    int root(int x){
        if(x == par[x]) return x;
        else return par[x] = root(par[x]);
    }
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(x < y) swap(x, y);
        par[x] = y;
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
};

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

    int n, m;
    cin >> n >> m;

    vector<int> P(n);
    REP(i, n){
        int p;
        cin >> p;
        p--;
        P[i] = p;
    }

    UnionFind uf(n);
    REP(i, m){
        int x, y;
        cin >> x >> y;
        x--; y--;
        uf.unite(x, y);
    }

    int ans = 0;
    REP(i, n){
        ans+=uf.same(i,P[i]);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1024
import java.util.*;

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

	class AOJ0227{
		public AOJ0227() {
			while(true){
				int n = in.nextInt();//購入する野菜
				int m = in.nextInt();//袋に入る野菜
				if(n==0&&m==0)break;
				int[] p = new int[n];
				for(int i=0;i<n;i++)p[i] = in.nextInt();
				Arrays.sort(p);
				int result = 0;
				int sum = 0;
				for(int i=0;i<n;i++)sum+=p[i];
				int cnt = 0;
				for(int i=n-1;i>=0;i--){
					cnt++;
					if(cnt==m){
						cnt=0;
						result+=p[i];
					}
				}
				System.out.println(sum-result);
			}
		}
	}


}

Measured memory_bytes: 55652
fun main(args: Array<String>){
    val n = readLine()!!.split(" ").map { it.toInt() }[0]
    val a = readLine()!!.split(" ").map { it.toInt() }
    var min = 99999999
    var count = 0
    var i = 0
    for (i in 0..n-1) {
        if (min > a[i]) {
            min = a[i]
        }
        if (a[i] <= min){
            count++
        }
    }
    println(count)
}




Measured memory_bytes: 82892
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

#define REP(i,n) for(int i=0;i<n;i++)
#define EPS (1e-9)
#define INF (1e9 + 1)
#define PI (acos(-1))

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

ll lcm(ll a, ll b) {
	ll c = (b / gcd(a, b));
	return c * a;
}

ll A, B, N, sum = 0;

string S;
int ans = INF;

int main() {
	cin >> S;
	REP(i, S.length() - 2) {
		int Slng = (S[i] - '0') * 100 + (S[i + 1] - '0') * 10 + S[i + 2] - '0';
		if (abs(Slng - 753) < abs(ans - 753)) ans = Slng;
	}
	cout << abs(ans - 753) << endl;
}

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

using namespace std;

typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n, W; cin >> n >> W;
    vector <ll> dp(W + 1);
    // dp[i] - the maximum total value of items with weight exactly i
    for (ll item = 0; item < n; ++item){
        ll weight, value; cin >> weight >> value;
        for (ll weight_used = W - weight; weight_used >= 0; --weight_used){
            dp[weight + weight_used] = max(dp[weight + weight_used], dp[weight_used] + value);
        }
    }
    ll ans = 0;
    for (ll i = 0; i <= W; ++i){
        ans = max(ans, dp[i]);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  /* code */
  int n ;
  int m ;
  long long ans = 0 ;
  cin >> n >> m;
  vector<int> a(n);

  for (int i = 0; i < n; i++) {
    /* code */
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  for (int i = 0; i < m; i++) {
    int y;
    y = a[n-1]/2;
    a.insert(lower_bound(a.begin(),a.end(),y),y);
    a.pop_back();
  }

  for (int i = 0; i < n; i++) {
    /* code */
    ans += a[i];
  }
  cout << ans << "\n";
  
  return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<int>res(4,0);
	for (int i = 0; i < n; i++) {
		string x;
		cin >> x;
		if (x == "AC")res.at(0)++;
		else if (x == "WA")res.at(1)++;
		else if (x == "TLE")res.at(2)++;
		else res.at(3)++;
	}
	cout << "AC x " << res.at(0) << endl;
	cout << "WA x " << res.at(1) << endl;
	cout << "TLE x " << res.at(2) << endl;
	cout << "RE x " << res.at(3) << endl;
}

Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;

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

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

        for(int i=0;i<Math.min(K,42);i++) {

            Arrays.fill(B,0);

            for (int i2 = 0; i2 < N; i2++) {
                int t = A[i2];
                int d1 = i2 - t;
                int d2 = i2 + t;
                if (d1 < 0) {
                    d1 = 0;
                }
                B[d1]+=1;
                if (d2 < N-1) {
                    B[d2+1]-=1;
                }
            }
            for(int i3=1;i3<N;i3++){
                B[i3]+=B[i3-1];
            }
            A=B.clone();


        }



        System.out.printf("%d",A[0]);
        for(int i=1;i<N;i++){
            System.out.printf(" %d",A[i]);
        }
        System.out.printf("%n");

        scn.close();

    }

}

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

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007
#define rvs(i) reverse( i.begin(), i.end() )

using namespace std;

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

	int m = 0; cin >> m;
	rep(i, m)
	{
		string tmp; cin >> tmp;
		vector<string> str;
		for(int j = 1; j < (int)tmp.size(); j++)
		{
			string tmp1, tmp2, tmp3, tmp4;
			tmp1 = tmp.substr(0, j);
			tmp2 = tmp.substr(j);
			tmp3 = tmp1; rvs(tmp3);
			tmp4 = tmp2; rvs(tmp4);

			str.push_back(tmp1 + tmp2);
			str.push_back(tmp1 + tmp4);
			str.push_back(tmp3 + tmp2);
			str.push_back(tmp3 + tmp4);
			str.push_back(tmp2 + tmp1);
			str.push_back(tmp2 + tmp3);
			str.push_back(tmp4 + tmp1);
			str.push_back(tmp4 + tmp3);
		}
		sort(all(str));
		str.erase(unique(all(str)), str.end());
		printf("%d\n", (int)str.size());
	}
	return 0;
}

Measured memory_bytes: 1340
/**
 *    author:  tourist
 *    created: 22.01.2020 00:30:57       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    b[i] = (s[i] == 'A');
  }
  int ptr = 0;
  int flip = 0;
  for (int i = 0; i < k; i++) {
    if (b[ptr] ^ flip) {
      b[ptr] ^= 1;
    } else {
      flip ^= 1;
      ptr += 1;
      if (ptr == n) ptr = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ((b[(ptr + i) % n] ^ flip) ? 'A' : 'B');
  }
  cout << '\n';
  return 0;
}


Measured memory_bytes: 1684
#include <bits/stdc++.h>
using namespace std;
int main() {
  int _; cin >> _;
  string s; cin >> s;
  int x = 0, mx = 0;
  for (char c : s) {
    if (c == 'I') x++; else x--;
    mx = max(mx, x);
  }
  cout << mx << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int d;cin>>d;
    vin c(26);rep(i,26)cin>>c[i];
    vvin s(d,vin(26));
    rep(i,d)rep(j,26)cin>>s[i][j];
    vin last(26,0);int sum,tmp;ll m;
    vin ans(d);
    rep(i,d){
        m=-INF;
        rep(j,26){
            sum=0;
            sum+=s[i][j];
            rep(k,26){
                if(k==j)continue;
                sum-=c[k]*(i+1-last[k]);
            }
            if((ll)sum>m)tmp=j;
        }
        ans[i]=tmp;
        last[tmp]=i+1;
    }
    rep(i,d)cout<<ans[i]+1<<endl;
}

Measured memory_bytes: 3676
#include<stdio.h>
#include<stdlib.h>

#define NIL NULL

struct node{
  struct node *l;
  struct node *r;
  struct node *p;
  int key;
};

typedef struct node * Node;

Node root;

void Preorder(Node t){
  printf(" %d",t->key);
  if(t!=NIL){
    if(t->l!=NIL)Preorder(t->l);
    if(t->r!=NIL)Preorder(t->r);
  }
}

void Inorder(Node t){
  
  if(t!=NIL){
    if(t->l!=NIL){
      Inorder(t->l);
      }
    printf(" %d",t->key);
    
    if(t->r!=NIL){
      Inorder(t->r);
      }
  }
}

void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key=k;
  z->l=NIL;
  z->r=NIL;
  
  while(x!=NIL){
    y=x;

    if(z->key<x->key) x=x->l;
    else x=x->r;
  }
  z->p=y;
  
  if(y==NIL) root=z;
  else if(z->key<y->key) y->l=z;
  else y->r=z;
}

main(){
  int n, i, x;
  char str[20];
  
  scanf("%d",&n);

  for ( i = 0; i < n; i++ ){
    scanf("%s",str);

    if (str[0]=='i'){
      scanf("%d",&x);
      insert(x);
    } 
    else if (str[0]=='p'){
      Inorder(root);
      printf("\n");
      
      Preorder(root);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 24040
using System;
using System.Linq;
using System.Text;
using static ConsoleReader;

class Program
{
    static void Main(string[] args)
    {
        var a = ReadArray<int>(5);
        var res = a
            .Select((el, index) => (el, index))
            .First(pair => pair.el == 0)
            .index + 1;
        Console.WriteLine(res);
    }
}

public static class IntExtentions
{
    public static void Times(this int n, Action<int> action)
    {
        for (var i = 0; i < n; i++)
        {
            action(i);
        }
    }

    public static void Times(this (int n, int m) dimensions, Action<int, int> action)
    {
        var (n, m) = dimensions;
        n.Times(i => m.Times(j => action(i, j)));
    }
}

public static class ConsoleReader
{
    public static T Read<T>()
        where T : IConvertible
    {
        var inputBuffer = new StringBuilder();
        int currChar;

        while ((currChar = Console.Read()) != -1)
        {
            if (!char.IsWhiteSpace((char)currChar))
            {
                inputBuffer.Append((char)currChar);
            }
            else if (inputBuffer.Length != 0)
            {
                break;
            }
        }

        return (T)Convert.ChangeType(inputBuffer.ToString(), typeof(T));
    }

    public static T[] ReadArray<T>(int count)
        where T : IConvertible
    {
        if (count < 0)
        {
            throw new ArgumentOutOfRangeException(nameof(count), $"'{nameof(count)}' must be >= 0");
        }

        var result = new T[count];

        for (var i = 0; i < count; i++)
        {
            result[i] = Read<T>();
        }

        return result;
    }
}

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

int main(){
  int r, D;
  vector<int> x(11);
  cin >> r >> D >> x.at(0);
  for (int i = 0;i<10;i++){
    x.at(i+1) = (r*x.at(i)) - D;
    cout << x.at(i+1) << endl;
  }
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
	int N;
	int input;
	int Max=0,Min=10000;
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> input;
		Max=max(Max,input);
		Min=min(Min,input);
	}
	cout << Max-Min << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const char A = 'A';
const char T = 'T';
const char C = 'C';
const char G = 'G';
int main(){
    string s;
    while(cin>>s){
        int ans = 0;
        int last = -1;
        for(int i =0 ;i<(int)s.size(); i++){
            char c = s[i];
            if(c == A || c == T ||  c == C || c == G){
                if(last < 0){
                    ans = max(ans, 1);
                    last = i;
                }
                else {
                    int tmp = i - last + 1;
                    ans = max(ans, tmp);
                }
            }
            else last = -1;
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

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

using ll = std::int64_t;

int N, M, P[100100], Y[100100];
std::vector<int> v[100100];

std::string f(std::string s){
    while(s.size() < 6){
        s = "0" + s;
    }
    return s;
}

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

    std::cin >> N >> M;

    for(int i=0;i<M;++i){
        std::cin >> P[i] >> Y[i];

        v[P[i]].emplace_back(Y[i]);
    }

    for(int i=1;i<=N;++i){
        std::sort(v[i].begin(), v[i].end());
    }

    for(int i=0;i<M;++i){
        int x = std::lower_bound(v[P[i]].begin(), v[P[i]].end(), Y[i]) - v[P[i]].begin() + 1;
        
        std::string s1 = f(std::to_string(P[i])),
            s2 = f(std::to_string(x));

        std::cout << s1 << s2 << std::endl;
    }
}


Measured memory_bytes: 7808
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

const int inf = 1e9;

int r(int a, int b) {
    if ((a+b) >= 255) return 255;
    else if ((a+b) <= 0) return 0;
    else return a+b;
}

int main(void){
    int n,m;
    while (cin>>n>>m && n) {
        vector<int> a(n);
        vector<int> code(m);
        for (int i = 0; i < m; i++) cin >> code[i];
        for (int i = 0; i < n; i++) cin >> a[i];
        
        vector<vector<int> > dp(256, vector<int>(n+1, inf) );
        dp[128][0] = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 256; j++) {
                if (dp[j][i] == inf) continue;
                
                int x, p;
                for (int k = 0; k < m; k++) {
                    x = r(j, code[k]);
                    p = (a[i]-x) * (a[i]-x);
                    dp[x][i+1] = min(dp[x][i+1], dp[j][i]+p);
                }
            }
        }
        int ans = inf;
        for (int i = 0; i < 256; i++) ans = min(ans, dp[i][n]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 22820
def main():
    n = int(input())
    x = input()
    
    val = 0
    rui = 1
    mod = 0
    
    nagasa = 2*10**5+1
    #nagasa = 5
    d_li = [0]*(nagasa)
    
    for i in range(1,nagasa):
        t_v = i
        t_m = bin(t_v).count("1")
        ans = 0
        while t_v != 0:
            if d_li[t_v] != 0:
                ans += d_li[t_v]
                break
            ans += 1
            t_v %= t_m
            #t_m = bin(t_v).count("1")
        d_li[i] = ans
    
    #print(d_li)
    #exit()
    """
    for i in range(n):
        val += int(x[n-1-i])*rui
        rui *= 2
    """
    val = int(x, 2)
    #print(val)
    #exit()
    
    mod = bin(val).count("1")
    
    rui = pow(2,(n-1))
    
    t_v_p = val % (mod+1)
    if mod == 1:
        t_v_m = 0
    else:
        t_v_m = val % (mod-1)
        
    for i in range(n):
        ans = 0
        #t_v = val
        #t_m = mod
        if int(x[i]) == 1:
            if mod == 1:
                t_v = 0
            else:
                t_v = t_v_m
                t_v -= pow(2,(n-1-i),mod-1)
                #t_v -= rui % (mod-1)
                t_v %= (mod-1)
                ans += 1
                #t_m -= 1
        else:
            t_v = t_v_p
            t_v += pow(2,(n-1-i),mod+1)
            #print(t_v,rui)
            #t_v += rui % (mod+1)
            t_v %= (mod+1)
            ans += 1
            #t_m += 1
        rui //= 2
        #print(t_v,mod)
        #while t_v != 0:
        """
        if t_v != 0:
            if int(x[i]) == 1:
                if mod == 1:
                    t_v = 0
                else:
                    t_v %= mod-1
            else:
                t_v %= mod + 1
            #t_v %= t_m
            ans += 1
        """
        ans += d_li[t_v]
        #t_m = bin(t_v).count("1")
        #ans_li.append(ans)
        print(ans)
        #print(ans_li)
        
if __name__ == '__main__':
    main()
"""
#print(ans_li)
for i in range(n):
    print(ans_li[n-1-i])
"""

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

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

    int x = 0;

    for(int i=1; i<=N; i++)
    {
        int y;
        cin >> y;

        x += (y != i);
    }

    if(x <= 2)
        cout << "YES\n";
    else
        cout << "NO\n";
        
    return 0;
}


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

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  ret.push_back(1);
  for(int64_t i = 2; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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



  int n;
  cin >> n;
  map<int,int> s;
  const int n_max = 1e6+10;
  vector<int> aru(n_max,0);
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
    aru[a[i]]++;
  }
  sort(a.begin(),a.end());
  int ans = 0;
  if(a[0]==1) {
    if(aru[a[0]]>1)cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
  }
  rep(i,n){
    if(aru[a[i]]>=10000000 || aru[a[i]]<1) continue;
    else{
      if(aru[a[i]]==1) ans++;
      for(int j=a[i]*2;j<n_max;j+=a[i]){
        aru[j] = 1e7;
      }
    }
  }
  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 7952
import sys
import numpy as np
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())

    map_ = np.array([list(input().strip()) for i in range(H)]) == "."

    up = np.zeros((H, W), dtype=int)
    down = np.zeros((H, W), dtype=int)
    left = np.zeros((H, W), dtype=int)
    right = np.zeros((H, W), dtype=int)

    for i in range(1, H):
        up[i] = (up[i-1] + 1) * map_[i-1]
    for i in range(H-2, -1, -1):
        down[i] = (down[i+1] + 1) * map_[i+1]
    for j in range(1, W):
        left[:,j] = (left[:,j-1] + 1) * map_[:,j-1]
    for j in range(W-2, -1, -1):
        right[:,j] = (right[:,j+1] + 1) * map_[:,j+1]
    
    print(((up + down + left + right + 1) * map_).max())


if __name__ == "__main__":
    main()

Measured memory_bytes: 219820
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MAX_S 8000

using namespace std;
typedef pair<llong, llong> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

string s;
int x, y;
vector<int> xF_sections;
vector<int> yF_sections;

/*
    sections = {x_1, x_2, ..., x_n} のとき
    x_1 ・ x_2 ・ ... ・ x_n = x    (各・は+または-)
    とできるかをDPで判定

    sの先頭が'F' ⇒ はじめのx方向への移動は+方向のみなので，
    この情報をsolve関数に与える(first_x)

    dp[i][j] : section[0] ~ section[i - 1]まで見たとき，j - 8000を作れるか
*/
bool dp[MAX_S / 2 + 1][2 * MAX_S + 1];

bool solve(vector<int> sections, int x, bool first_x) {
    for(int i = 0; i <= MAX_S / 2; ++i)
        for(int j = 0; j <= 2 * MAX_S; ++j)
            dp[i][j] = false;
    dp[0][0 + MAX_S] = true;
    
    for(int i = 0; i < sections.size(); ++i)
        for(int j = -MAX_S; j <= MAX_S; ++j)
            if(dp[i][j + MAX_S]) {
                dp[i + 1][j + sections[i] + MAX_S] = true;
                if(i > 0 || !first_x)
                    dp[i + 1][j - sections[i] + MAX_S] = true;
            }

    return dp[sections.size()][x + MAX_S];
}

int main(int argc, char **argv) {
    cin >> s >> x >> y;
    s.push_back('T');   //sentinel

    int T_cnt = 0, xF_cnt = 0, yF_cnt = 0;
    for(int i = 0; i < s.size(); ++i)
        if(s[i] == 'T')  {
            T_cnt++;
            if(xF_cnt > 0) xF_sections.push_back(xF_cnt);
            if(yF_cnt > 0) yF_sections.push_back(yF_cnt);
            xF_cnt = yF_cnt = 0;
        } else {
            if(T_cnt % 2 == 0) xF_cnt++;
            else yF_cnt++;
        }
    
    bool res = solve(xF_sections, x, s[0] == 'F') && solve(yF_sections, y, false);
    
    cout << (res ? "Yes" : "No") << endl;
}

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

bool check(int n)
{
	if(n>=1 && n<=12)
		return true;
	return false;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
  	string S;
	cin>>S;

	string S1,S2;

	for(int i = 0;i<4;i++)
	{
		if(i == 0 || i == 1)
			S1 = S1 + S[i];
		else
			S2 = S2 + S[i];
	}

	//cout<<S1<<" "<<S2<<endl;

	int a = stoi(S1);
	int b = stoi(S2);

	if(check(a) && check(b))
		cout<<"AMBIGUOUS"<<endl;
	else if(check(a))
		cout<<"MMYY"<<endl;
	else if(check(b))
		cout<<"YYMM"<<endl;
	else
		cout<<"NA"<<endl;

	return 0;
} 

Measured memory_bytes: 256
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <functional> 
// using namespace __gnu_pbds;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MaX 300005
using namespace std;

 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
   	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
// typedef tree<int, null_type, less<int>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//     new_data_set; 
bool isprime(ll n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}

const int M=1e6+5,N=2e5+5;
ll n,ans=0;
ll vis[M];
ll a[N];
int main()
{
	fast();
	cin>>n;
	ll i,j;
	rep(i,n)
		cin>>a[i];
	for(i=0;i<n;i++)
	{
		ll x=a[i];
		if(vis[x])
		{
			vis[x]=2;
			continue;
		}
		for(j=x;j<M;j+=x)
			vis[j]++;
	}
	for(i=0;i<n;i++)
		if(vis[a[i]]==1)
			ans++;
	cout<<ans;
	exit(0);
}

Measured memory_bytes: 12980
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int solve(int N) {
    int test = N, order = 0, ans = 0;

    for(int i = 0; test > 0; i++) {
        test /= 10;
        if(test > 0) order++;
    }

    if(order % 2) {
        for(int i = 0; i < order; i += 2) {
            ans += 9 * pow(10, i);
        }
    } else {
        for(int i = 0; i < order; i += 2) {
            ans += 9 * pow(10, i);
        }
        ans += N - pow(10, order) + 1;
    }

    return ans;
}

int main() {
    int N;
    cin >> N;
    cout << solve(N) << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
N,M=map(int,input().split())
edges={tuple(sorted(map(int,input().split()))) for i in range(M)}

ans = 0
for i in itertools.permutations(range(2,N+1),N-1):
    l=[1]+list(i)
    ans+=sum(1 for edge in zip(l,l[1:]) if tuple(sorted(edge)) in edges)==N-1
print(ans)

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

typedef long long ll;

using namespace std;

ll MAX = 1e9+1;

void solve() {
    int n;
    cin >> n;
    int k = (n+1)/2;  // need k, k+1, ..., n heads

    vector<double> dp(n+1); // dp[i] ~ p(i heads) so far
    dp[0] = 1; // initially, we are certain there are 0 heads

    // if we are processing coin j
    // dp[i] = p(i heads after j-1 coins & coin j is tails) 
    //         + p(i-1 heads after j-1 coins & coin j is heads
    double p;
    for (int i = 0; i < n; i++) {
        cin >> p;
        // we need to iterate from n down to 0 because we need to preserve the last state i-1
        for (int j = n; j >= 0; j--) {
            dp[j] = dp[j]*(1-p) + dp[j-1]*p;
        }
    }
    double ans = 0;
    for (int i = k; i <= n; i++) 
        ans += dp[i];
    cout.precision(20);
    cout << ans << endl;
}


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






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,t,a[505050],tr[505050],ans[505050],lt[505050];
vector<int>q[505050],qq[505050];
void gx(int x,int vl)
{
	while(x<=n)
	{
		tr[x]+=vl;
		x+=x&(-x);
	}
}
int sm(int x)
{
	int rt=0;
	while(x>0)
	{
		rt+=tr[x];
		x-=x&(-x);
	}
	return rt;
}
int main()
{
	cin>>n>>t;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=t;i++)
	{
		int l,r;
		cin>>l>>r;
		q[r].push_back(l);
		qq[r].push_back(i);
	}
	for(int i=1;i<=n;i++)
	{
		if(lt[a[i]]!=0)
		{
			gx(lt[a[i]],-1);
		}
		lt[a[i]]=i;
		gx(i,1);
		for(int j=0;j<q[i].size();j++)
		{
			ans[qq[i][j]]=sm(i)-sm(q[i][j]-1);
		}
	}
	for(int i=1;i<=t;i++)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}

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

using namespace std;
#define int long long
#define MOD 1000000007
#define pb push_back
int N,K;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>N>>K;
    vector<vector<int> >dp(N+10,vector<int>(K+10,0));
    dp[0][K]=1;
    
    vector<int>A(N+1);
    for(int i=1;i<=N;i++)
    {
        cin>>A[i];
    }
    
    for(int i=1;i<=N;i++)
    {
        for(int j=0;j<=K;j++)
        {
            dp[i][max(j-A[i],(long long)(0))]+=dp[i-1][j];
            dp[i][max(j-A[i],(long long)(0))]%=MOD;
            dp[i][j+1]=(dp[i][j+1]+MOD-dp[i-1][j])%MOD;
        }
        for(int j=1;j<=K;j++)
        {
            dp[i][j]+=dp[i][j-1];
            dp[i][j]%=MOD;
        }
    }
    
   /* for(int i=0;i<=N;i++)
    {
        for(int j=0;j<=K;j++)
        {
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
    */
    cout<<dp[N][0];
    
    
    return 0;
}

Measured memory_bytes: 87296
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int max = 0;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int tmp = sc.nextInt();
            if (max < tmp) {
                max = tmp;
            }
            sum += tmp;

        }
        if (max < sum-max) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 21716
#include <iostream>
#include<string>
#include<set>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    if (n > m) cout << "safe" << endl;
    else cout << "unsafe" << endl;
    return 0;
}

Measured memory_bytes: 3636
N=int(input())
S=input()

ans=0
for i in range(10):
  i=str(i)
  ind=S.find(i)
  if ind<0:
    continue
  S2=S[ind+1:]
  for j in range(10):
    j=str(j)
    j_ind=S2.find(j)
    if j_ind<0:
      continue
    S3=S2[j_ind+1:]
    ans+=len(set(S3))
    
print(ans)

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

ll extended_gcd(ll a, ll b, ll &x, ll &y)
{
    if(a==0)
    {
        x = 0;
        y = 1;
        return b;
    }
    
    ll x1,y1;
    ll g = extended_gcd(b%a, a, x1, y1);
    
    x = y1-(b/a)*x1;
    y = x1;
    return g;
}

ll powe(ll x,ll n) {
  if(x==0) return 0;
  if(n==0) return 1;
  ll val = powe(x,n/2);
  if(n%2) return (((val*val)%N)*x)%N;
  return (val*val)%N;
}

// ll comb(ll n, ll k) { 
//     if(k==0) return 1;
//     if(k==n) return 1;
//     return (((mods[n]*invmods[n-k])%N)*invmods[k])%N;
// }

ll cofac(vector<vector<ll> > &adj) {
  ll tot = 1, idx;
  ll res = 1;

  for(ll i=1;i<adj.size();i++) {
    idx = i;

    while(idx<adj.size() && !adj[idx][i])
      idx++;

    if(idx==adj.size())
      return 0;

    if(idx!=i) {
      swap(adj[i],adj[idx]);
      if((idx-i)%2)
        res = -res;
    }

    vector<ll> temp(adj[i].begin(),adj[i].end());

    ll val = temp[i];
    for(ll j=i+1;j<adj.size();j++) {
      ll curr = adj[j][i];

      for(ll k=i+1;k<adj.size();k++) {
        adj[j][k] = ((val*adj[j][k])%N - (curr*temp[k])%N + 2*N)%N;
      }

      tot = (tot*val)%N;
    } 
  }

  for(ll i=1;i<adj.size();i++)
    res = (res * adj[i][i])%N;
  
  ll x,y;
  extended_gcd(tot,N,x,y);
  // cout<<(res*x)%N<<endl;
  return (2*N+(res*x)%N)%N;
}


void solve(vector<ll> &counts, vector<vector<ll> > &adj, ll idx, ll sum) {
  counts[idx] += sum;
  for(ll i=0;i<adj[idx].size();i++)
    solve(counts,adj,adj[idx][i],counts[idx]);
}
int main() {

  ll n,q;
  cin>>n>>q;

  // std::cout << std::fixed;
  // std::cout << std::setprecision(6);

  vector<vector<ll> > adj(n,vector<ll>());
  vector<ll> counts(n,0);
  // vector<ll> par(n,-1);

  for(ll i=0;i<n-1;i++) {
    ll a,b;
    cin>>a>>b;
    adj[a-1].push_back(b-1);
    // par[b-1]=a-1;
  }

  for(ll i=0;i<q;i++) {
    ll a,b;
    cin>>a>>b;
    counts[a-1] += b;
  }

  solve(counts,adj,0,0);

  for(ll i=0;i<n;i++) {
    cout<<counts[i]<<" ";
  }
  cout<<endl;


  return 0;
} 


Measured memory_bytes: 24320