akhauriyash/Code-Regression huggingface dataset:
function get_darken_blacks(A, blacks){
  var darken_blacks=[]
  for(var i=0;i<blacks.length;i++){
    var c_black = blacks[i];
    x = c_black[1];
    y = c_black[0];

    if((y>0 && A[y-1][x]=='#')&&(x>0 && A[y][x-1]=='#')&&(x<A[0].length-1 && A[y][x+1]=='#')&&(y<A.length-1 && A[y+1][x]=='#')){continue;}


    if(y>0                            && A[y-1][x]=='.'){
      darken_blacks.push([y-1, x]);
      A[y-1][x]='#';
    }
    if(x>0                            && A[y][x-1]=='.'){
      darken_blacks.push([y, x-1]);
      A[y][x-1]='#';
    }
    if(x<A[0].length-1 && A[y][x+1]=='.'){
      darken_blacks.push([y, x+1]);
      A[y][x+1]='#';
    }
    if(y<A.length-1       && A[y+1][x]=='.'){
      darken_blacks.push([y+1, x]);
      A[y+1][x]='#';
    }
  }
  return darken_blacks;
}

function get_blacks(A){
  blacks = [];
  for(var i=0;i<A.length;i++){
    for(var j=0;j<A[0].length;j++){
      if(A[i][j]=='#'){blacks.push([i,j])}
    }
  }
  return blacks;
}

function main(input){
  const lines = input.split('\n');
  const H = lines[0].split(' ').map(x => parseInt(x))[0];
  const W = lines[0].split(' ').map(x => parseInt(x))[1];
  var A=[];
  for(var i=0;i<H;i++){
    var line = lines[1+i].split('');
    A.push(line);
  }

//  console.log([H,W,A]);

  var result = 0;

  var blacks = get_blacks(A);

  if(blacks.length==1){
    var black = blacks[0];
    long_x = 0;
    long_y = 0;
    if(black[0] > H-1-black[0]){long_y = black[0]}else{long_y=H-1-black[0]}
    if(black[1] > W-1-black[1]){long_x = black[1]}else{long_x=W-1-black[1]}
  console.log(long_x+long_y);

    return;
  }

  while(true){
    blacks = get_darken_blacks(A, blacks)
    //A=darken(A, blacks);
    //console.log('==');
    //console.log(blacks);
    //console.log(A);
    if(blacks.length==0){break;}
    result++;
  }

  console.log(result);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

using namespace std;

const int N = 1 << 18, L = 1e5 + 5, S = 1 << 9;

int n, q, v[N], w[N];

int dp[S][L];
pair<int, int> val[22];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", v+i, w+i);
  }
  for (int i = 1; i < S; ++i) {
    int vv = v[i], ww = w[i];
    int par = i / 2;
    for (int j = 0; j < L; ++j)
      dp[i][j] = dp[par][j];
    for (int j = 0; j + ww < L; ++j)
      dp[i][j+ww] = max(dp[i][j+ww], dp[par][j] + vv);
  }
  scanf("%d", &q);
  while (q--) {
    int u, l;
    scanf("%d %d", &u, &l);
    int ans = 0;
    if (u < S) {
      ans = dp[u][l];
    } else {
      int len = 0;
      while (u >= S) {
        val[len++] = {v[u], w[u]};
        u /= 2;
      }
      int nmask = 1 << len;
      ans = 0;
      for (int mask = 0; mask < nmask; ++mask) {
        int ww = 0;
        int vv = 0;
        for (int i = 0; i < len; ++i)
          if ((mask >> i) & 1)
            vv += val[i].first, ww += val[i].second;
        if (ww <= l)
          ans = max(ans, vv + dp[u][l - ww]);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int a, b, c;cin >> a >> b >> c;
    string ans = "NO";
    if(b-a == c-b) ans = "YES";
    cout << ans << endl;
    return 0;
}


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

int max2(int a, int b){
  if(a>b) return a;
  else return b;
}

int main() {
  int N;
  cin >> N;
  int K;
  cin >> K;
  char S[1000000];

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

  int change = 0;

  for(int i=0; i<N-1; i++){
    if(S[i] != S[i+1]) change++;
  }

  int change_after = max2(change - 2*K,0);
  int ans = max2(N-1-change_after,0);



  cout << ans  << endl;

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int MOD = 1000000007;

int main() {
    int n,m;
    cin>>n>>m;
    cout<<(n-1)*(m-1)<<endl;
}


Measured memory_bytes: 256
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long
using namespace std;
#define ss second
#define ff first
int32_t main()
{
    fastio;
    int T,n,m,i,j,k,a,b,c,x,y;
    T=1;
    while(T --> 0)
    {
        cin>>x>>y>>a>>b>>c;
        int A[a],B[b];
        vector<int> C(c+x+y);
        for(i=0;i<a;i++)    cin>>A[i];
        for(i=0;i<b;i++)    cin>>B[i];
        for(i=0;i<c;i++)    cin>>C[i];

        partial_sort(A,A+x,A+a,greater<int>());
        partial_sort(B,B+y,B+b,greater<int>());
        
        for(i=0;i<x;i++)    C[c++]=(A[i]);
        for(i=0;i<y;i++)    C[c++]=(B[i]);

        partial_sort(C.begin(),C.begin()+x+y,C.end(),greater<int>());
        int ans=0;
        for(i=0;i<x+y;i++)  
            ans+=C[i];
        
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 3968
N,K = map(int,input().split())
A = list(map(int,input().split()))
rd = [-1 for _ in range(N)]
rd[0] = 1

def nomal_loop():
    now_town = 1
    for _ in range(K):
        now_town = A[now_town-1]
    print(now_town)

    return 0

def else_loop():
    next_town = A[0]
    count = 1
    K_count = K
    while(1):
        count +=1
        K_count -= 1
        if rd[next_town-1] == -1:
            rd[next_town-1] = count
            next_town = A[next_town-1]
        else:
            warukazu = count - rd[next_town-1]
            result = (K_count+warukazu) % warukazu
            for _ in range(result):
                next_town = A[next_town-1]
            print(next_town)
            break
    return 0

if N > K:
    nomal_loop()
else:
    else_loop()



    


Measured memory_bytes: 99616
#include<bits/stdc++.h>
using namespace std;
int n , t;
int f[3005][3005],g[3005][3005];
int a[3005],b[3005];
int main()
{
	scanf("%d%d",&n,&t);
	--t;
	for(int i=1;i<=n;++i)
	    scanf("%d%d",&a[i],&b[i]);
	int INF=-1e9;
	for(int i=1;i<=n;++i)
		for(int j=0;j<=t;++j)
		   f[i][j]=max(j>=a[i]?f[i-1][j-a[i]]+b[i]:INF,f[i-1][j]);
	for(int i=n;i>=1;--i)
		for(int j=0;j<=t;++j)
		   g[i][j]=max(j>=a[i]?g[i+1][j-a[i]]+b[i]:INF,g[i+1][j]);
	int ans=0;
    for(int i=1;i<=n;++i)
    	for(int j=0;j<=t;++j)
    		ans=max(ans,f[i-1][j]+g[i+1][t-j]+b[i]);
    cout<<ans<<endl;
	return 0;
}

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

int main() {
	int a;
	cin >> a;
	int h,m,s;
	s = a%60;
	m = (a / 60)%60;
	h = a/ 3600;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}


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

using namespace std;

int main(){

	int value;
	int quan;

	int sumValue=0;
	int idx=0;
	double avg=0;

	char cm;
	while(cin>>value>>cm>>quan){
		sumValue+=value*quan;
		avg+=quan;
		idx++;
	}
	avg/=idx;
	cout<<sumValue<<endl;
	cout<<(int)(avg+0.5)<<endl;

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

template< int mod >
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(long long n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ModInt &a) {
    long long t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
  static int get_mod() { return mod; }
};
const int MOD = 1000000007;
using mint = ModInt< MOD >;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  map<ll, int> lcm;
  rep(i, n) {
    auto tmp = prime_factor(a[i]);
    for (auto e : tmp)
      chmax(lcm[e.first], e.second);
  }
  mint l = 1;
  for (auto e : lcm) {
    mint p = e.first;
    l = l*p.pow(e.second);
  }
  mint ans = 0;
  rep(i, n) ans += l/a[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 896
import java.util.*;

public class Main {

    static <T extends Comparable<? super T>> boolean nextPermutation(T[] sequence) {
        int first = getFirst(sequence);
        if (first == -1) return false;
        int toSwap = sequence.length - 1;
        while (sequence[first].compareTo(sequence[toSwap]) >= 0) --toSwap;
        swap(sequence, first++, toSwap);
        toSwap = sequence.length - 1;
        while (first < toSwap) swap(sequence, first++, toSwap--);
        return true;
    }

    static <T extends Comparable<? super T>> int getFirst(T[] sequence) {
        for (int i = sequence.length - 2; i >= 0; --i)
            if (sequence[i].compareTo(sequence[i + 1]) < 0) return i;
        return -1;
    }

    static <T extends Comparable<? super T>> void swap(T[] sequence, int i, int j) {
        T tmp = sequence[i];
        sequence[i] = sequence[j];
        sequence[j] = tmp;
    }

    static class Pair {
        int x, y;

        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Pair> li = new ArrayList<>();
        for (int i = 0; i < n; ++i) li.add(new Pair(sc.nextInt(), sc.nextInt()));

        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; ++i) arr[i] = i;
        double sum = 0;
        int cnt = 0;
        do {
            for (int i = 0; i < n - 1; ++i) {
                sum += Math.sqrt(Math.pow(li.get(arr[i]).x - li.get(arr[i+1]).x, 2) +
                        Math.pow(li.get(arr[i]).y - li.get(arr[i+1]).y, 2));
            }
            ++cnt;
        } while(nextPermutation(arr));

        System.out.println(sum / cnt);
    }
}

Measured memory_bytes: 23976
#include <stdio.h>

#define N_MAX 200000

int n, m, a, b, i, is;
int is_from_one[N_MAX + 1];
int is_to_n[N_MAX + 1];

int main(void) {
    scanf("%d%d", &n, &m);
    
    for (i = 1; i <= m; ++i) {
        scanf("%d%d", &a, &b);
        if (a == 1) {
            is_from_one[b] = 1;
        } else if (b == n) {
            is_to_n[a] = 1;
        }
    }
    
    for (i = 1; i <= n; ++i) {
        //printf("%d from1, to n = %d, %d\n", i, is_from_one[i], is_to_n[i]);
        
        if (is_from_one[i] && is_to_n[i]) {
            is = 1;
        }
    }
    
    if (is) {
        puts("POSSIBLE");
    } else {
        puts("IMPOSSIBLE");
    }
    
    return 0;
}

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

using namespace std;
const int inf=0x7f7f7f7f;
const int maxn=200050;
const int maxm=5000050;

set<int> s;

long long n;
long long a[maxn];
long long pos[maxn];
long long ans;

int main()
{
    //ios::sync_with_stdio(true);
    //ios::sync_with_stdio(false);
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	scanf("%lld",&n);
	for(long long i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        pos[a[i]]=i;
    }

    s.insert(0);
    s.insert(n+1);

    for(long long i=1;i<=n;i++)
    {
        auto it=s.lower_bound(pos[i]);
        long long r=*(it);
        it--;
        long long l=*it;
        //cout<<l<<' '<<r<<endl;

        ans+=i*(pos[i]-l)*(r-pos[i]);
        s.insert(pos[i]);
    }

    printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 12800
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
using ll = long long;

int main(){
  ll N;
  cin >> N;
  
  ll root_N = sqrt(N);
  for( ll i=root_N; i>0; i-- ){
    if( N % i == 0 ){
      cout << ( (i-1)+(N/i-1) );
      return 0;
    }
  }
  return 0;
}


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

int i,j,k,xa,ya,xb,yb;
double sp[3][2],vec[3][2],pot[3][2],area;

int crosspoint(int i,int j){
	
	double px=sp[i][0],py=sp[i][1];
	double ax=vec[i][0],ay=vec[i][1];
	double qx=sp[j][0],qy=sp[j][1];
	double bx=vec[j][0],by=vec[j][1];

	if( ( ax*bx+ay*by!=0 ) && ( ax*by==ay*bx ))return 0;

	double a=ax,b=-bx,c=qx-px;
	double d=ay,e=-by,f=qy-py;
	double t,x,y;

	if(a!=0){
		t=d/a;
		e-=b*t;
		f-=c*t;
		y=f/e;
		x=(c-b*y)/a;
	}
	else{
		y=c/b;
		x=(f-e*y)/d;
	}

	if(x<0 || x>1 || y<0 || y>1)return 0;

	pot[i][0]=px+ax*x;
	pot[i][1]=py+ay*x;

	return 1;

}

int main(){
	while(1){
		for(i=0;i<3;i++){
			if(scanf("%d %d %d %d",&xa,&ya,&xb,&yb)==EOF)goto exit;
			vec[i][0]=xb-xa;vec[i][1]=yb-ya;
			sp[i][0]=xa;sp[i][1]=ya;
		}
		for(i=0;i<3;i++){
			if(crosspoint(i,(i+1)%3)==0)goto bad;
		}

		double vx=pot[1][0]-pot[0][0];
		double vy=pot[1][1]-pot[0][1];
		double wx=pot[2][0]-pot[0][0];
		double wy=pot[2][1]-pot[0][1];

		area=fabs((vx*wy-vy*wx)/2);

		if(area>=1900000){printf("dai-kichi\n");continue;}
		if(area>=1000000){printf("chu-kichi\n");continue;}
		if(area>=100000){printf("kichi\n");continue;}
		if(area>0){printf("syo-kichi\n");continue;}
		bad: printf("kyo\n");
	}
	exit: return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

    ll N, A, B;
    cin >> N >> A >> B;

    ll ab_diff = abs(A - B);
    ll ans = LLINF;
    if(ab_diff % 2 == 0) {
        ans = ab_diff / 2;
    }
    else {
        // 左端に移動する場合
        ll cand1 = A - 1;   // 左に行き着くのにかかるターン数
        ll tmp_b = B - cand1;
        if(tmp_b % 2 != 0) {
             tmp_b--;
             cand1++;
        }
        cand1 += tmp_b / 2;

        // 右端に移動する場合
        ll cand2 = N - B;
        tmp_b = (N - A) - cand2;
        if(tmp_b % 2 != 0) {
            tmp_b--;
            cand2++;
        }
        cand2 += tmp_b / 2;
        ans = min(cand1, cand2);
    }
    printf("%lld\n", ans);

    return 0;
}



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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int A, B;
	
	cin >> A >> B;
	
	int ans;
	
	ans = max(A+B, A-B);
	ans = max(ans, A*B);
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
# C - Green Bin
def main():
    count = 0
    dictCount = {}
    for i in [input() for i in range(int(input()))]:
        strInput = ''.join(sorted([c for c in i]))
        if strInput in dictCount:
            count += dictCount[strInput]
            dictCount[strInput] += 1
        else:
            dictCount[strInput] = 1
    print(count)

if __name__ == "__main__":
    main()
    

Measured memory_bytes: 24976
#include <iostream>

using namespace std;

int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if(x > W or y > H){
        cout << "No" << endl;
    }
    else if(x == W or y == H){
        cout << "No" << endl;
    }
    else if(W > (x - r) and (x - r) >= 0 and H > (y - r) and (y - r) >= 0){
        cout << "Yes" << endl;
    }
    else if(W > (x + r) and (x + r) >= 0 and H > (y + r) and (y + r) >= 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = 0
mae = -1
for i in range(len(A)):
    ans += B[A[i]-1]
    if mae + 1 == A[i]:
        ans += C[mae-1]
    mae = A[i]
print(ans)

Measured memory_bytes: 38384
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
        int gap = b - a;
        int sum = 0;
        for(int i = 1; i <= gap; i++) {
          sum += i;
        }
    
		// 出力
		System.out.println(sum - b);
	}
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> ppiii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> query;
typedef pair<ll, pii> key;

ll facs[100005];
const int MOD = 1000000007;

ll modpow(ll b, ll e, ll m) {
  ll r = 1;
  while(e) {
    if(e%2) {
      r*=b;
      r%=m;
    }
    b*=b;
    b%=m;
    e/=2;
  }
  return r;
}

ll l[100005];
ll ifacsprefix[100005];
void solve() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> l[i];
  facs[0] = 1;
  for(int i = 1; i <= n; i++) {
    facs[i] = i * facs[i-1];
    facs[i] %= MOD;
  }
  for(int i = 1; i <= n; i++) {
    ifacsprefix[i] = ifacsprefix[i-1] + modpow(i, MOD-2, MOD);
    ifacsprefix[i] %= MOD;
  }
  ll ret = 0;
  for(int i = 0; i < n; i++) {
    ret -= l[i];
    ret += ifacsprefix[n-i] * l[i];
    ret += ifacsprefix[i+1] * l[i];
    ret %= MOD;
  }
  ret += MOD;
  ret *= facs[n];
  cout << ret % MOD << "\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << " ";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


Measured memory_bytes: 2560
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<int, int>
const ll  MOD = 1000000007;

int main() {
	ll n, x, y;
	cin >> n >> x >> y;
	vector<ll> ans(n + 3, 0);
	reps(i, 1, n) {
		reps(j, i + 1, n + 1) {
			if (i <= x && y <= j) ans.at(j - i - (y - x - 1))++;
			else if(j <= x || y <= i) ans.at(j - i)++;
			else if (i <= x && x < j) ans.at(min(j - i, x - i + 1 + y - j))++;
			else if (x < i && j < y) ans.at(min(j - i, i - x + 1 + y - j))++;
			else ans.at(min(j - i, i - x + 1 + j - y))++;
			
		}
	}
	reps(i, 1, n) cout << ans.at(i) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    char x;
    cin >> x;
    if(x == 'a'||x == 'i'||x == 'u'||x == 'e'||x == 'o'){
        cout << "vowel" << endl;
    }

    else{
        cout << "consonant" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#H, W = map(int,input().split())
#N = int(input())
#al = list(map(int,input().split()))
X, N = map(int,input().split())
pl = list(map(int,input().split()))

lst = [i for i in range(-101,200)]

anslst = []
for n in lst:
    if not n in pl:
        anslst.append(n)



an = 1000
idx = 0
for i in range(len(anslst)):
    tmp = abs(X - anslst[i])
    if tmp < an:
        an = tmp
        idx = i


ans = anslst[idx]
print(ans)

Measured memory_bytes: 9204
using System;
using System.Collections.Generic;

class AOJ {
  static void Main(string[] args)
  {
    int[] balls;
    string s;
    bool flag;

    Stack<int> B = new Stack<int>();
    Stack<int> C = new Stack<int>();

    s = Console.ReadLine();

    for (int i = 0; i < int.Parse(s); i++) {

      balls = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
      flag = true;

      B.Push(0);
      C.Push(0);

      foreach (int j in balls) {

        if (B.Peek() < j)
          B.Push(j);

        else if (C.Peek() < j)
          C.Push(j);

        else {
          flag = false;
          break;
        }
      }

      Console.WriteLine(flag ? "YES" : "NO");
    }
  }
}

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

int N;
vector<int> G[100000];
vector<int> sf;
bool get_path(int w, int v, vector<int> &path){
  if( v == N-1 ){
    path.push_back(N-1);
    return true;
  }
  for(int i = 0; i < G[v].size(); i++){
    int u = G[v][i];
    if(w != u && get_path(v, u, path)){
      path.push_back(v);
      return true;
    }
  }
  return false;
}
int count(int v){
  //cout << v << " -- " << sf[v] << endl;;
  int ret = 1;
  for(int i = 0; i < G[v].size(); i++){
    int u = G[v][i];
    if( sf[u] == 0 ){
      sf[u] = sf[v];
      ret += count(u);
    }
  }
  return ret;
}
int main(){
  cin >> N;
  sf.resize(N, 0);
  for(int i = 0; i < N - 1; i++){
    int a, b;
    cin >> a >> b; a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> path;
  get_path(-1, 0, path);
  reverse( path.begin(), path.end() );
  for(int i = 0; i < path.size(); i++){
    if( (i % 2) == 0 ){
      sf[ path[i / 2] ] = 1;
    }else{
      sf[ path[path.size() - (i / 2) -1] ] = -1;
    }
  }
  int f = 0, s = 0;
  for(int i = 0; i < path.size(); i++){
      if( sf[path[i]] == 1 ){
      f += count( path[i] );
    }else{
      s += count( path[i] );
    }
  }
  if( f > s ){
    cout << "Fennec" << endl;
  }else{
    cout << "Snuke" << endl;
  }
}


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

int main() {
  int T;
  cin >> T;
  for(int t=0; t<T; t++) {
    if(t) cout << endl;
    int a[9][9];
    for(int i=0;i<9;i++)for(int j=0;j<9;j++) cin >> a[i][j];
    bool u[9][9];
    memset(u,false,sizeof(u));
    for(int i=0;i<9;i++) {
      for(int j=0;j<9;j++) {
        for(int k=0;k<9;k++) {
          if(i!=k&&a[i][j]==a[k][j]) u[i][j]=u[k][j]=1;
          if(j!=k&&a[i][j]==a[i][k]) u[i][j]=u[i][k]=1;
        }
        for(int k=0;k<3;k++) {
          for(int l=0;l<3;l++) {
            int x=i/3*3+k,y=j/3*3+l;
            if((i!=x||j!=y)&&a[i][j]==a[x][y]) u[i][j]=u[x][y]=1;
          }
        }
      }
    }
    for(int i=0;i<9;i++) {
      for(int j=0;j<9;j++) {
        if(u[i][j]) cout << '*';
        else cout << ' ';
        cout << a[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define spn setprecision
using namespace std;
int arr[101];
int main() {
	int n,x,m=1000000,ans=0,inp;
	sd(n);
	sd(x);
	for(int i = 1; i <= n; i++){
		sd(inp);
		x-=inp;
		ans++;
		m=min(m,inp);
	}
	ans+=x/m;
	pd(ans);
	return 0;
}

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

int N;
vector<int> vec;

/*与えられた値が素数かつ5で割って1余る数ならtrueを返す*/
bool pandm51(int n){
  if(n % 5 != 1) return false;
  
  for(int i = 2; i *i <= n; i++){
    if(n % i == 0) return false;
  }

  return true;
}

/*五つの数の和が素数でない、つまり五つの値がすべて5で割って1余る数であればよい
よって一の位が1の数を探していき、N個の素数が見つかった時点で終了。N個あるかは保証されていないが今回は通った*/
int main(){
  cin >> N;

  int i = 11;
  while(i <= 55555){
    if(pandm51(i)) vec.push_back(i);
    if(vec.size() == N) break;
    i += 10;
  }

  for(int i = 0; i < N-1; i++) cout << vec[i] << " ";
  cout << vec[N-1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;

const int INF = 1e9 + 7;
const long long LLINF = 1e18;

int main() {
    int W, H, N;
    int x[101], y[101], a[101];
    cin>>W>>H>>N;
    REP(i, 0, N) cin>>x[i]>>y[i]>>a[i];

    int mny=0, mnx=0, mxy=H, mxx=W;
    REP(i, 0, N){
        if(a[i]==1) mnx=max(mnx, x[i]);
        else if(a[i]==2) mxx=min(mxx, x[i]);
        else if(a[i]==3) mny=max(mny, y[i]);
        else mxy=min(mxy, y[i]);
    }

    if(mxx-mnx<=0 || mxy-mny<=0) cout<<0<<endl;
    else cout<<(mxx-mnx)*(mxy-mny)<<endl;
    return 0;
}

Measured memory_bytes: 256
# D - Score Attack
import sys
sys.setrecursionlimit(10 ** 9)

import numpy as np
from heapq import heappush, heappop

N, M, = map(int, input().split())
graph = [[] for _ in range(N+1)] # graph[0]は使わない

for _ in range(M):
    a, b, c = map(int, input().split())
    graph[a].append((b, -c)) # ヒープ構造を使うためスコアと重みはマイナスの値

def dijkstra(start, co):
    INF = 10 ** 15
    dist = [INF] * (N+1) # dist[0]は使わない
    dist[start] = 0
    que = [(0, start, co)] # queではscoreを先頭に
    while que:
        score, place, count = heappop(que) # placeは現在地
        if score > dist[place] or count > 2000: # 前来た時より点数が悪いか、無限ループしている場合continue
            continue
        for next_node, weight in graph[place]:
            score2 = score + weight
            if next_node == N and count > 1000: # いくらでも大きくなる場合
                print('inf')
                exit()
            if dist[next_node] > score2 and count < 2000: # 点数が良くなるなら、データを更新
                dist[next_node] = score2
                heappush(que, (score2, next_node, count+1))
    return dist

d1 = np.array(dijkstra(1, 0))
print(-d1[N])

Measured memory_bytes: 12796
#include<bits/stdc++.h> 
//compiling code: g++ test.cpp(file) -o script(output) -std=c++11(version) -O2(make it 2x faster)
using namespace std;

int N, x[105], sums[101];

int main(){
    cin >> N;
    for (int i=1; i<=N; i++){
        cin >> x[i];
    }

    int sum = 0;

    int position = 1;
    while(position<=100){  
        for (int i=1; i<=N; i++){
            sums[position] += (x[i] - position)*(x[i] - position);     
        }
        position ++;
    }
    
    int first = 1000000000;
    for (int i=1; i<=100; i++){
        if (first > sums[i]){
            first = sums[i];
        }
    }

    cout << first <<"\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long
const int N = 2e5 + 5;
using namespace std;

int n, k, p[N], bit[N];
long long a[N], ans;

void update(int i){
    while (i < N){
        bit[i]++;
        i += i&(-i);
    }
}

int get(int i){
    int ans = 0;
    while (i > 0){
        ans += bit[i];
        i -= i&(-i);
    }
    return ans;
}

signed main(){
    srand(time(NULL));
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) a[i] += a[i-1] - k;
    for (int i = 0; i <= n; i++) p[i] = i;
    sort(p, p+1+n, [](int x, int y){return (a[x] < a[y] || (a[x] == a[y] && x < y));});
    for (int i = 0; i <= n; i++) a[p[i]] = i+1;
    update(a[0]);
    for (int i = 1; i <= n; i++){
        ans += get(a[i]);
        update(a[i]);
    }
    cout << ans;
}


Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<map>
#include<numeric>
//#include <bits/stdc++.h>
#include<cstring>
#include<iostream>
#include<functional>
using namespace std;
int main() {

	int A, B;

	cin >> A >> B;

	if (A + B >= 10)
		cout << "error\n";
	else
		cout << (A + B) << endl;


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mem(x,v) memset(x,v,sizeof(x))
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define gc getchar
#define pc putchar
#define fi first
#define se second
inline ll read(){
    ll x=0,f=1;char c=gc();
    for(;!isdigit(c);c=gc())if(c=='-')f=-1;
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return x*f;
}
inline void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
inline void writeln(ll x){write(x);pc('\n');}
inline void wri(ll x){write(x);pc(' ');}
const int maxn = 5500;
ll c[maxn],f[maxn],ans;
int n,a[maxn];
ll A,B,C;
#define lson (o<<1)
#define rson (o<<1|1)
#define mid ((l+r)>>1)
ll tag[maxn<<2],T[maxn<<2];
ll query(int o,int l,int r,int x,int y){
	if(l==x && r==y) return T[o];
	if(y<=mid) return query(lson,l,mid,x,y) + tag[o]; else
	if(mid+1<=x) return query(rson,mid+1,r,x,y) + tag[o]; else
	return min(query(lson,l,mid,x,mid),query(rson,mid+1,r,mid+1,y)) + tag[o];
}
void modify(int o,int l,int r,int x,int y,ll v){
	if(l==x && r==y){
		T[o] += v;
		tag[o] += v;
		return ;
	}
	if(y<=mid) modify(lson,l,mid,x,y,v); else
	if(mid+1<=x) modify(rson,mid+1,r,x,y,v); else
	modify(lson,l,mid,x,mid,v),modify(rson,mid+1,r,mid+1,y,v);
	T[o] = min(T[lson],T[rson]) + tag[o];
}
void M(int o,int l,int r,int x,ll v){
	if(l==r){
		T[o] = v;
		return ;
	}
	if(x<=mid) M(lson,l,mid,x,v - tag[o]); else
			   M(rson,mid+1,r,x,v - tag[o]);
	T[o] = min(T[lson],T[rson]) + tag[o];
}
int main(){
    n = read(),A = read(),B = read();
    Rep(i,1,n) a[i] = read();
    if(A>B){
        swap(A,B);
        reverse(a+1,a+1+n);
        Rep(i,1,n) a[i] = n-a[i]+1;
    }
    C = min(A,B);
    ans = 1ll << 60;
    memset(T,0x3f,sizeof(T));
    memset(tag,0,sizeof(tag));
    Rep(i,1,n){//A是右移，B是左移 
    	f[i] = min((i - 1) * A,query(1,1,n,1,a[i]) + i * C - C);
        if(a[i]+1<=n) modify(1,1,n,a[i]+1,n,B-C);
        M(1,1,n,a[i],f[i]-i*C);
        ans = min(ans,f[i] + B * (n - i));
    }writeln(ans);
    return 0;
}

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

main()
{
    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int w,h,x,y;
	cin>>w>>h>>x>>y;

	int q=0;
	long double p=w*h*1.0/2;

	if(w%2==0 and h%2==0)
	{
		if(w/2==x and h/2==y)
			q=1;
	}

	cout<<fixed<<setprecision(6)<<p;
	cout<<" "<<q;
}

Measured memory_bytes: 256
//Link : https://atcoder.jp/contests/arc073/tasks/arc073_d

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200005
#define inf 1000000000000000LL
#define OUT (ll)4e18
int x[N];

int dist(int x,int y) {
  return abs(x-y);
}

ll segMinus[N*4],segPlus[N*4];
ll lazyMinus[N*4],lazyPlus[N*4];

void init(int pos,int l,int r) {
  segMinus[pos] = segPlus[pos] = inf;
  lazyPlus[pos] = lazyMinus[pos] = 0;
  if(l==r) {
    return;
  }
  int mid = (l+r)/2;
  init(pos*2,l,mid);
  init(pos*2+1,mid+1,r);
}

void push(ll *seg,ll *lazy,int pos,int l,int r) {
  if(lazy[pos]!=0) {
    seg[pos] += lazy[pos];
    if(l!=r) {
      lazy[pos*2] += lazy[pos];
      lazy[pos*2+1] += lazy[pos];
    }
    lazy[pos] = 0;
  }
}

void update(ll *seg,ll *lazy,int pos,int l,int r,int ql,int qr,ll value) {
  push(seg,lazy,pos,l,r);
  if(qr<l || r<ql) {
    return;
  }
  if(ql<=l && r<=qr) {
    lazy[pos] = value;
    push(seg,lazy,pos,l,r);
    return;
  }
  int mid = (l+r)/2;
  update(seg,lazy,pos*2,l,mid,ql,qr,value);
  update(seg,lazy,pos*2+1,mid+1,r,ql,qr,value);
  seg[pos] = min(seg[pos*2],seg[pos*2+1]);
}

ll query(ll *seg,ll *lazy,int pos,int l,int r,int ql,int qr) {
  push(seg,lazy,pos,l,r);
  if(qr<l || r<ql) {
    return OUT;
  }
  if(ql<=l && r<=qr) {
    return seg[pos];
  }
  int mid = (l+r)/2;
  return min(query(seg,lazy,pos*2,l,mid,ql,qr),
  query(seg,lazy,pos*2+1,mid+1,r,ql,qr));
}

ll solveMin(int q,int n) {
  ll ret = 0;
  swap(x[0],x[1]);
  init(1,1,n);
  update(segPlus,lazyPlus,1,1,n,x[0],x[0],x[0]-inf);
  update(segMinus,lazyMinus,1,1,n,x[0],x[0],-x[0]-inf);
  for(int i=2;i<q;++i) {
    ll d = dist(x[i-1],x[i]);
    ret += d;
    ll a = query(segPlus,lazyPlus,1,1,n,x[i],n)-x[i];
    ll b = query(segMinus,lazyMinus,1,1,n,1,x[i])+x[i];
    ll mini = min(a,b);
    ret = min(ret,mini);
    ll minPlus = mini + x[i-1];
    ll minMinus = mini - x[i-1];
    update(segPlus,lazyPlus,1,1,n,1,n,d);
    update(segMinus,lazyMinus,1,1,n,1,n,d);
    ll p = query(segPlus,lazyPlus,1,1,n,x[i-1],x[i-1]);
    ll m = query(segMinus,lazyMinus,1,1,n,x[i-1],x[i-1]);
    minPlus = min(p, minPlus);
    minMinus = min(m, minMinus);
    update(segPlus,lazyPlus,1,1,n,x[i-1],x[i-1], minPlus-p);
    update(segMinus,lazyMinus,1,1,n,x[i-1],x[i-1], minMinus-m);
  }
  return ret;
}

void solve() {
  int n,q;scanf("%d %d %d %d ", &n,&q,&x[1],&x[0]);
  for(int i=2;i<q+2;++i) {
    scanf("%d  ", &x[i]);
  }
  q += 2;
  printf("%lld\n", min(solveMin(q,n),solveMin(q,n)));
}

int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 25600
def main():
    x, k, d = map(int, input().split())

    if k >= abs(x) // d:
        a = abs(x) - d * (abs(x) // d)
        b = abs(a - d)
        left_number = k - (abs(x) // d)
        if left_number % 2 == 0:
            minimum = a
        else:
            minimum = b

    else:
        minimum = abs(x) - k * d

    print(minimum)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9152
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def X(): return list(input())
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
moti = []
for j in range(N):
    a = i()
    moti.append(a)

moti = set(moti)
print(len(moti))


Measured memory_bytes: 10024
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
	
ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
int digits(int n)
{
	int count = 0;
	while (n > 0)
	{
		n /= 10;
		count++;
	}
	return count;
}
ll combination(ll n, ll r)
{
	if (r * 2 > n)
		r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i)
	{
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int GCD(int x, int y)
{
	return x ? GCD(y % x, x) : y;
}
vector<int> divisor(int n)
{
	vector<int> value;
	FOR(i, 1, pow(n, 0.5) + 1)
	{
		if (i <= sqrt(n))
		{
			if (n % i == 0)
			{
				value.push_back(i);
				if (i * i != n)
				{
					value.push_back(n / i);
				}
			}
		}
	}
	return value;
}
int main()
{
	string s;
	cin>>s;
	bool ans=false;
	rep(i,s.size()-1){
		if(s.substr(i,2)=="AC"){
			ans=true;
		}
	}
	if(ans){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

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

        int a[n][m];
        int b[m];
        int result[n];

        for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                        scanf("%d", &a[i][j]);
                }
        }

        for (int i = 0; i < m; i++) {
                scanf("%d", &b[i]);
        }

        for (int i = 0; i < n; i++) {
                result[i] = 0;
        }

        for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                        result[i] += a[i][j] * b[j];
                }
        }

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



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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int a,b,c; cin>>a>>b>>c;
	cout<<max({a,b,c})*10+a+b+c-max({a,b,c})<<"\n"s;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
bool isPrime(int x)
{
	if(x<2)
		return false;
    if(x==2)
		return true;
	if(x%2==0)
	    return false;
	for(int i=3;i<=sqrt(x);i+=2)
		if(x%i==0)
			return false;
	return true;
}
int main()
{
	int n;
	cin>>n;
	int sum=0;
	for(int i=0;i<n;i++)
	{
		int t;
		cin>>t;
		if(isPrime(t))
			sum++;
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 3056
n = int(input())
ans = 10**6
for i in range(1,n):

  tmp = 0
  a = str(i)
  b = str(n-i)
  for j in a:
   tmp+= int(j)
  for k in b:
   tmp+= int(k)
  ans = min(ans,tmp)
print(ans)
  
  

Measured memory_bytes: 2940
t=int(input())

#mapH[j][i]=(i,j)

for repeet in range(t):
        actinidia_tate=[]
        actinidia_yoko=[]
        gx,gy=[int(i) for i in input().split(" ")]

        mapH=[[0 for i in range(gx+1)] for j in range(gy+1)]
        mapH[0][0]=1
        p=int(input())
        for i in range(p):
                x1,y1,x2,y2=[int(j) for j in input().split(" ")]
                if x1==x2:
                        actinidia_tate.append([x1,max(y1,y2)])
                else:
                        actinidia_yoko.append([max(x1,x2),y1])
	
        for i in range(1,gx+1):
                try:
                        actinidia_yoko.remove([i,0])
                except:
                        mapH[0][i]+=mapH[0][i-1]
        for j in range(1,gy+1):
                try:
                        actinidia_tate.remove([0,j])
                except:
                        mapH[j][0]+=mapH[j-1][0]
	
        for i in range(1,gx+1):
                for j in range(1,gy+1):
                        try:
                                actinidia_yoko.remove([i,j])
                        except:
                                mapH[j][i]+=mapH[j][i-1]
                        try:
                                actinidia_tate.remove([i,j])
                        except:
                                mapH[j][i]+=mapH[j-1][i]


        if mapH[-1][-1]==0:
                print("Miserable Hokusai!")

        else:
                print(mapH[-1][-1])

Measured memory_bytes: 7640
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

bool same(string t,int s,int g){
	char c = t.at(s) ;
	for(int i=s;i<=g;i++){
		if(t.at(i)!=c) return false ;
	}
	return true ;
}

int main(){
	string s ; cin >> s ;
	int n = s.size() ;
	int ans = 1000000 ;
	for(char c='a';c<='z';c++){
		bool ok = false ;
		for(int i=0;i<n;i++){
			if(s.at(i)==c) ok = true ;
		}
		if(!ok) continue ;
		string t = s ;
		int sub = 0 ;
		for(int i=0;i<n;i++){
			if(same(t,0,n-1-sub)) break ;
			sub++ ;
			for(int j=0;j<n-sub;j++){
				if(t.at(j+1)==c) t.at(j) = c ;
			}
		}
		if(ans>sub) ans = sub ;
	}
	cout << ans << endl ;
}


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

#define ll long long int
#define ld long double
#define sll(x) scanf("%lli", &x)
#define sll2(x,y) scanf("%lli %lli", &x,&y)
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define loop(i,a,b) for(ll i=a; i<b; i++)
#define eloop(i,a,b) for(ll i=a; i<=b; i++)
#define svll(v,a,b) eloop(i,a,b){ll t; sll(t); v[i]=t;}
#define all(x) x.begin(), x.end()
#define nan LLONG_MAX
#define nin LLONG_MIN
#define dan DBL_MAX
#define din DBL_MIN
#define nl printf("\n");
#define vll vector<ll> 
#define pii pair<int, int> 
#define vpii vector<pii >
#define ff first
#define ss second
#define prvp(v,a,b) eloop(i,a,b) cout << "(" << v[i].ff << ", " << v[i].ss << ")" ;
#define prvi(v,a,b) eloop(i,a,b) cout << v[i] << " ";
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

int main(){
	//freopen("3.txt", "r", stdin);
	ll T=1; //sll(T);
	while(T--){
		ll a;
		ld b;
		cin >> a >> b;

		ll ans = (ll)(a*b);
		cout << ans << endl;
	}

	return 0;
}

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

int main(int argc, char const *argv[]) {
    string s, t, u;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    cin >> u;

    if (s == u) --a;
    else if (t == u) --b;

    cout << a << ' ' << b << endl;
    return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int dp[1002][1002];
int main()
{
	vector<string> A;
	string xx;
	// memset(dp,-1,sizeof(dp[0][0]*102*102));
	int i,j,m,n;
	cin>>m>>n;
	// if(m==0)
	//    return 0;
	for(i=0;i<m;i++)
	{
		cin>>xx;
		A.push_back(xx);
	}
	dp[1][1]=1;
	if(m==1 && n==1)
		return 1;

	for(i=1;i<=m;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(A[i-1][j-1]=='#')
			{
				dp[i][j]=0;
				continue;
			}
			if(i==1 && j==1)
				continue;
			else if(i==1)
				dp[i][j]=dp[i][j-1];
			else if(j==1)
				dp[i][j]=dp[i-1][j];
			else
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
		}
	}
	cout<<dp[m][n];
}

Measured memory_bytes: 5248
#include <stdio.h>
#include <string.h>

char a[21][21];

int main()
{
  int n,x,y,m,s;
  int i;
  char d[3];

  while(1){
    scanf("%d", &n);
    if(n==0)
      break;

    memset(a,0,sizeof(a));

    for(i=0;i<n;i++){
      scanf("%d%d", &x, &y);
      a[x][y]=1;
    }

    scanf("%d", &m);
    x=10,y=10;
    while(m-- > 0){
      scanf("%s%d", d, &s);
      while(s-- > 0){
	if(d[0] == 'E')x++;
	else if(d[0] == 'S')y--;
	else if(d[0] == 'W')x--;
	else if(d[0] == 'N')y++;
	
	if(a[x][y]){
          n--;
          a[x][y]=0;
        }
      }
    }

    if(n==0)
      printf("Yes\n");
    else printf("No\n");
  }
  return 0;
}



Measured memory_bytes: 2596
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

    set<string> s;
    for (auto i = 0; i < n; i++) {
        string in;
        cin >> in;
        s.insert(in);
    }

    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 19152
# coding: utf-8
import sys
import itertools


def sr(): return sys.stdin.readline().rstrip()


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


S = sr()
ans = 0


def dfs(depth, p_list):
    global ans

    if depth == 4:
        sum_list = []
        T = S
        text = ''
        for j, p in enumerate(p_list):
            if p == 1:
                sum_list.append(int(T[:1]))
            elif p == -1:
                sum_list.append(int(T[:1]) * -1)

            if len(text) == 0:
                text += T[:1]
            else:
                if p == 1:
                    text += '+' + T[:1]
                elif p == -1:
                    text += '-' + T[:1]
            T = T[1:]
        # print(p_list, sum_list)
        ans = sum(sum_list)
        if ans == 7:
            text += '=7'
            print(text)
            exit()

        return

    for i in [1, -1]:
        p_list[depth] = i
        dfs(depth + 1, p_list)


def main():

    p_list = [0] * (4)
    dfs(0, p_list)


main()


Measured memory_bytes: 3064
// #includes {{{
#include <bits/stdc++.h>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

int N;
int A[100010];

int main(){
	cin>>N;
	REP(i,N)cin>>A[i];
	int o=0,e=0;
	REP(i,N){
		if(A[i]%2==1)o++;
		else e++;
	}
	if(o%2==1){
		cout<<"NO"<<endl;
	}else{
		e+=o/2;
		cout<<"YES"<<endl;
	}

}


Measured memory_bytes: 640