akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cerr << (*begin) << " ";
    *begin++;
  }
  cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cerr << " " << Array[i][j];
    }
    cerr << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

signed main() {
  int n, m, c;
  cin >> n >> m >> c;
  vec<int> B(m);
  rep (i, m) {
    cin >> B[i];
  }

  int ans = 0;
  rep (i, n) {
    int sum = c;
    rep (j, m) {
      int b;
      cin >> b;
      sum += b * B[j];
    }
    dbg(sum)
    if (sum > 0) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
p = {str(i):[] for i in range(1,n+1)}
l = []
for i in range(m):
    t = input().split()
    l.append((t[0],int(t[1])))
    p[t[0]].append(int(t[1]))
for i in range(1,n+1):
    i = str(i)
    p[i].sort()
    d = {}
    for j in range(len(p[i])):
        d[p[i][j]] = str(i).zfill(6)+str(j+1).zfill(6)
    p[i]=d
for t in l:
    print(p[t[0]][t[1]])

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

int main() {
    int N;
    cin >> N;
    int x[N];
    int y[N];
    rep(i, N) cin >> x[i] >> y[i];

    vector<int> v(N);
    iota(v.begin(), v.end(), 0);

    double ans = 0;
    int cnt = 0;

    do {
        cnt++;
        rep(k, N - 1) {
            int i = v[k];
            int j = v[k + 1];
            ans += sqrt(pow(x[i] - x[j], 2.0) + pow(y[i] - y[j], 2.0));
        }
    } while (next_permutation(v.begin(), v.end()));

    cout << fixed;
    cout << setprecision(10) << ans / cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    rep(i, M) cin >> A.at(i);

    ll workDays = 0;
    rep(i, M) {
        workDays += A.at(i);
    }

    ll ans = -1;
    if (N >= workDays) {
        ans = N - workDays;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612
fn main() {
    let n = read::<i32>();
    println!("{}", (n / 500) * 1000 + (n % 500 / 5) * 5);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
bool f[100001];
int c[100001],r,l;
int main(){
  for(int i=2;i<=100000;i++){
    if(!f[i]){
      for(int j=i*2;j<=100000;j+=i){
        f[j]=true;
      }
    }
  }
  for(int i=3;i<=100000;i++){if(!f[i]&&!f[(i+1)/2]){c[i]++;}}
  for(int i=3;i<=100000;i++){c[i]+=c[i-1];}
  int q;
  cin>>q;
  while(q--){
    cin>>l>>r;
    cout<<c[r]-c[l-1]<<endl;
  }
}

Measured memory_bytes: 1152
let inputStr = '';

process.stdin.on('data', (input) => { inputStr += input; });

process.stdin.on('end', () => {
  const arr = inputStr.split('\n');
  search(arr[1].split(' ').map((s) => Number(s)), arr[3].split(' ').map((s) => Number(s)));
});

const search = (S, T) => {
  let match = 0;

  T.forEach((num) => {
    if (binarySearch(S, num) > -1) {
      match++;
    }
  });

  console.log(match);
};

const binarySearch = (base, num) => {
  let left = 0;
  let right = base.length;
  while (left < right) {
    const sum = left + right;
    let i = (sum % 2 === 1) ? (sum-1)/2 : sum/2;
    const center = base[i];
    if (center === num) {
      return i;
    }

    if (center > num) {
      right = i;
    } else {
      left = i + 1;
    }
  }

  return -1;
};;



Measured memory_bytes: 32396
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

int main(){
    int N; cin>>N;
    ll ans=1;

    vector<int> d(3,-1);

    for(int i=0;i<N;i++){
        int x; cin>>x;
        int k;
        ll count=0;
        for(int j=0;j<3;j++){
            if(d.at(j)==x-1) {k=j; count++;}
        }
        ans=(ans*count)%mod;
        if(count>0) d.at(k)++;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

int main(void){
    int n;
    register int i,j;
    scanf("%d",&n);
    char ins[n+1];
    scanf("%s",ins);
    int dp[n+1][n+1];
    for(i = 0;i <= n;i++)for(j = 0;j <= n;j++)dp[i][j] = 0;
    for(i = n-1;i >= 0;i--)for(j = n-1;j >~ 0;j--)dp[i][j] = ins[i] == ins[j]?dp[i+1][j+1]+1:0;
    int asax = 0;
    for(i = 0;i < n;i++)for(j = 0;j < n;j++)asax = max(asax,min(j-i,dp[i][j]));
    printf("%d",asax);
    return 0;
}

Measured memory_bytes: 97920
#include <stdio.h>

int main() {
    int s;
    scanf("%d", &s);
    int h = s / (60 * 60);
    s = s % (60 * 60);
    int m = s / 60;
    s = s % 60;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}

Measured memory_bytes: 2708
#include <cstdio>

const int nmax = 100009;
int a[nmax], B[2 * nmax];
long long c[2 * nmax], e[nmax];

inline void calc(int a, int b, long long &ans, int m) {
    if (a == b) return ;
    if (a > b)
        b += m;
    ans += b - a;
    if (a + 1 == b)
        return ;

    B[a + 1]++;
    c[b + 1] -= b - a - 1;
    B[b]--;
}

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

    long long ans = 0;
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);

    for (int i = 0; i < n - 1; i++)
        calc(a[i], a[i + 1], ans, m);

    long long add = 0;
    for (int i = 1; i <= 2 * m; i++) {
        c[i] += c[i - 1] + add;
        add += B[i];

        if (i <= m)
            e[i] += c[i];
        else e[i - m] += c[i];
    }

    long long best = 0;
    for (int i = 1; i <= m; i++)
        if (e[i] > best)
            best = e[i];

    printf("%lld\n", ans - best);

    return 0;
}


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

int main () {
  int x;
  int i;
  for (i=1; i>0; i++) {
    cin >> x;
    if (x != 0) {
      cout << "Case " << i << ": " << x << endl;
    } else {
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3044
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N = 110;

int n, a[N];

int main(){
	while(~scanf("%d", &n)){
		int m = n * 2;
		for(int i=0; i<m; i++){
			scanf("%d", a+i);
		}
		sort(a, a+m);
		int ans = 0;
		for(int i=0; i<m; i+=2){
			ans += a[i];
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int N, M, a, b, c, d, e, f;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	char x, y;
	cin >> x >> y;
	if (y == 'B')
	{
		cout << "ARC";
	}
	else
		cout << "ABC";
}

Measured memory_bytes: 3652
import sys

a,b,c = 0,0,0
for i in range(int(input())):
    t,x,y = map(int,input().split())
    dif = abs(x - a) + abs(y - b)
    t_dif = t - c
    if dif > t_dif:
        print("No")
        sys.exit()
    if (t_dif % dif) % 2 == 0:
        a,b,c = x,y,t
    else:    
        print("No")
        sys.exit()
    
print("Yes")    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    vector<ll> a(n+2),b(n+2),c(n+2);
    rep(i,n)cin >> a[i];
    ll ans = 0;
    ll sum = 0;
    rep(i,n){
        b[i+1] = b[i] + a[i];
    }
    c = b;
    // + - + - の順にする
    ll tot = 0;
    for(int i=1;i<=n;i++){
        b[i] += tot;
        if(i%2==1){
            // b[i]>0
            if(b[i]>0)continue;
            else {
                tot += 1 - b[i];
                ans += abs(1 - b[i]);
            }
        }else{
            if(b[i]<0)continue;
            else {
                tot += -1 - b[i];
                ans += abs(-1 - b[i]);
            }
        }
    }
    ll t = ans;
    // - + - の順にする
    tot = 0;
    ans = 0;
    b = c;
    for(int i=1;i<=n;i++){
        b[i] += tot;
        if(i%2==1){
            if(b[i]<0)continue;
            else {
                tot += -1 - b[i];
                ans += abs(-1 - b[i]);
            }
        }else{
            if(b[i]>0)continue;
            else {
                tot += 1 - b[i];
                ans += abs(1 - b[i]);
            }
        }
    }
    cout << min(ans,t) << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
template<class Type> void line(const Type &a){int cnt=0;for(auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n;
	cin>>n;
	
	vi a(n);
	REP(i,n) cin>>a[i];
	//line(a);

	if(a[0]!=0){
		cout<<0<<endl;
		return 0;
	}

	vi num(3,0);
	llong ans=3;
	num[0]++;
	for(int i=1;i<n;++i){
		int cnt=0;
		int flag;
		REP(j,3){
			if(a[i]==num[j]){
				cnt++;
				flag=j;
			}
		} 
		ans*=cnt;
		ans%=MOD;
		num[flag]++;
		//line(num);
		//debug(flag);
	}
	
	cout<<ans<<endl;
}


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

using namespace std;
using Long = long long;

int main(void)
{
	int n;

	cin >> n;

	Long a[n];
	multiset<int> vals;

	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		vals.insert(a[i]);
	}

	for (int i = 0; i < n; ++i)
	{
		auto it = vals.find(a[i]);
		vals.erase(it);

		cout << *(--end(vals)) << "\n";

		vals.insert(a[i]);
	}

	return 0;
}

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

int main() {
  int N, Ans=0;
  cin >> N;
  for(int i=N; i<=200000; i++){
    if(N==2) Ans=2;
    for(int j=2; j<N; j++){
      if(i%j==0) break;
      else if(j==N-1) Ans=i;
    }
    if(Ans!=0) break;
  }
  cout << Ans << endl;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int a[100001];
int main() {
  int n,k;
  cin >> n >> k;
  cout << (int)ceil((n-1)*1.0/(k-1)) << endl;
}


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

using namespace std;

int main() {
  string S;
  cin >> S;
  int N = S.length();
  for (int i = 0; i < N; i++) {
    if (S[i] != S[N - i - 1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = 0; i < (N - 1) / 2; i++) {
    if (S[i] != S[(N - 1) / 2 - i - 1]) {
      cout << "No" << endl;
      return 0;
    }
    if (S[i + (N + 1) / 2] != S[(N - 1) / 2 - i - 1 + (N + 1) / 2]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
    n, m, k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))

    t = 0
    for i in range(m):
        t += b[i]

    j = m
    ans = 0
    for i in range(n+1):
        while j > 0 and t > k:
            j -= 1
            t -= b[j]
        if t > k:
            break
        ans = max(ans,i+j)
        if i == n:
            break
        t += a[i]
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 110904
n = int(input())
nums=list(input().split())
    


def selectionSort(nums):
    count=0
    for i in range(len(nums)):
        minj=i
        for j in range(i,len(nums)):
            if int(nums[j])<int(nums[minj]):
                minj=j
        if i!=minj:          
            tmp=nums[minj]
            nums[minj]=nums[i]
            nums[i]=tmp
            count+=1
    print(' '.join(nums))
    print(count)


selectionSort(nums)



Measured memory_bytes: 5596
from collections import Counter
import sys
#input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(input())
D = list(map(int, input().split()))

if D[0]!=0:
    print(0)
    exit()

div = 998244353

c = Counter(D)
if c[0]!=1:
    print(0)
    exit()

maxD = max(D)
res = 1
for i in range(1, maxD):
    res *= (c[i]**c[i+1])
    res %= div

print(res)


Measured memory_bytes: 19936
// header {{{
using namespace std;

// C++
#include <algorithm>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>

#pragma GCC optimization_level 3

// util {{{
#define print(x)	        cout << (x)
#define printvec(x)       for(int i = 0;i < (x).size();i++)cout << (x).at(i) << " ";cout << endl
#define println(x)	        cout << (x) << endl
#define printn		        cout << endl
#define read(x)	            cin >> (x)
#define readvec(x)        for(int i = 0; i < (x).size();i++)cin >> (x).at(i)

#define rep(i, n)	        for(int i = 0; i < (int)(n); i++)
#define rep_1(i, n) 	    for(int i = 1; i <=(int)(n); i++)

#define all(x) 		        (x).begin(),(x).end()
#define vint                vector<int>
#define outif(x,y,z)        if(x) cout<<(y)<<endl; else cout<<(z)<<endl
#define loop 		        while(true)

// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

void solve() {
    vint cases;
    loop{
        int tmp;
        read(tmp);
        if(tmp == 0){
         break;
        } else {
            cases.push_back(tmp);
        }
    };
    rep(i,cases.size()){
        if(cases.at(i) == 0){continue;}
        cout << "Case" << " " << i + 1 << ":" << " " << cases.at(i) << endl;
    }
}

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


Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  long ans;
  long div[1000000];
  div[0] = 1;
  for(long i = 1;i<1000000;i++){
    div[i] = (div[i-1]*3)%1000000007;
  }
  bool t = 0;
  cin>>s;
  long p = 0;
  for(long i = s.size()-1;i>=0;i--){
    p = s.size()-i;
    if(s.at(i) == '1' && t == 0){
      ans = div[p-1]+2;
      t = 1;
    }
    else if(s.at(i) == '1' && t == 1){
      ans = (2*ans + div[p-1])%1000000007;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
	int W,H,x,y;
	cin >> W >> H >> x >> y;
	cout << fixed << setprecision(6);
	cout << double(W)*double(H) / 2.0;
	cout << ' ' << ((x + x == W)&&(y + y == H)) << endl;
}

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

int main(){
  int n;
  string word;
  cin >> n >> word;
  int last = word.size()-1;
  map<string,bool> check;
  check[word]=1;
  
  for(int i=1; i<n; ++i){
    string next;
    cin>>next;
      if(word[last]==next[0] && !check.count(next)){
        word = next;
        last = word.size()-1;
        check[word]=1;
      }
    else{
        cout << "No" << endl;
        return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int main(void)
{
	int A, B, C;
	cin >> A >> B >> C;
	if (A == B)cout << C <<endl;
	else if (A == C)cout << B << endl;
	else cout << A << endl;
	return 0;
}


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;
#define MAXN 202020
using namespace std;



int n;
vector<vi> t(2 , vi(2 * MAXN , INF));


void build(int par){
    for(int i = n - 1 ; i > 0 ; --i){
        t[par][i] = min(t[par][2 * i] , t[par][2 * i + 1]);
    }
}
 
void modify(int par , int p , int val){
    for(t[par][p += n] = val ; p > 1 ; p /= 2){
        t[par][p / 2] = min(t[par][p] , t[par][p ^ 1]);
    }
}
 
int query(int par , int l , int r){//[l , r)
    int res = INF;
    for(l += n , r += n ; l < r ; l /= 2 , r /= 2){
        if(l % 2){
            res = min(res, t[par][l]);
            ++l;
        }
        if(r % 2){
            --r;
            res = min(res , t[par][r]);
        }
    }
    return res;
}

int last = 0;
map<int , pii> code;
map<pii , int> rcode;
vi pos;

vi g[MAXN / 2];

void solve(vi & p , int l , int r , int prev = -1){
	if(r - l < 1)return;
	if(r >= sz(p) || l < 0)return;
	if(r - l == 1){
		code[last] = {p[l] , p[r]};
		rcode[{p[l] , p[r]}] = last;
		
		if(prev != -1){
			g[prev].pb(last);
		}
		prev = last;
		++last;
	}else{
		pii o = {0 , 0};
		
		int par = l % 2;
		o.fi = query(par , l , r + 1);
		
		int pos1 = pos[o.fi];
		o.se = query((pos1 + 1) % 2 , pos1 + 1 , r + 1);
		
		code[last] = o;
		rcode[o] = last;
		
		if(prev != -1){
			g[prev].pb(last);
		}
		prev = last;
		++last;
		

		int pos2 = pos[o.se];
		
		modify(pos1 % 2 , pos1 , INF);
		modify(pos2 % 2 , pos2 , INF);

		solve(p , pos1 + 1 , pos2 - 1 , prev);
		solve(p , l , pos1 - 1 , prev);
		solve(p , pos2 + 1 , r  , prev);
		
	}
}

vi restore(){
	vi res;
	priority_queue<pii , vector<pii> , greater<pii>> q; 
	q.push(code[0]);
	
	while(!q.empty()){
		pii u = q.top();
		q.pop();
		
		res.pb(u.fi);
		res.pb(u.se);
		
		for(int c : g[rcode[u]]){
			q.push(code[c]);
		}
	}
	return res;
}

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


	cin >> n;
	
	pos.resize(n + 1);
	
	vi p(n);
	rep(i , n){
		cin >> p[i];
		pos[p[i]] = i;
		
		int par = i % 2;
		
		t[par][n + i] = p[i];
		t[par ^ 1][n + i] = INF;
	}

	
	build(0);
	build(1);
	
	solve(p , 0 , n - 1);
	
	for(int e : restore()){
		cout << e << " ";
	}
	
	return 0;
}

Measured memory_bytes: 38612
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
    int X;

    cin >> X;

    double max_val = 1;
    double pow_val = 0;

    for(int i = 2; i <= sqrt(X); i++) {
        for(int j = 1;;j++) {
            if(pow(i, j) > X) {
                pow_val = pow(i, j - 1);
                break;
            }
        }
        max_val = max(max_val, pow_val);
    }
    cout << int(max_val) << endl;

    return 0;

}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

void print_vec(vector<string> &A){
    for(int i=0;i<A.size();i++){
        cout << A.at(i);
        if(i == A.size()-1){
            cout << endl;
        }else{
            cout << ' ';
        }
    }
}

void bubbleSort(vector<string> &A){
    bool flag = 1;
    for(int i=0; flag; i++){
        flag = 0;
        for(int j = A.size()-1; j>= i+1; j--){
            if(A.at(j).at(1) < A.at(j-1).at(1)){
                swap(A.at(j),A.at(j-1));
                flag = 1;
            }
        }
    }
}

void selectionSort(vector<string> &A){
    for(int i=0; i<A.size();i++){
        int minj = i;
        for(int j=i;j<A.size();j++){
            if(A.at(j).at(1) < A.at(minj).at(1)){
                minj = j;
            }
        }
        if(i != minj){
            swap(A.at(i),A.at(minj));
        }
    }
}

int main(){
    int N;
    cin >> N;
    vector<string> A(N),B(N);
    rep(i,N){
        cin >> A.at(i);
        B.at(i) = A.at(i);
    }
    bubbleSort(A);
    print_vec(A);
    cout << "Stable" << endl;
    selectionSort(B);
    print_vec(B);
    cout << ((A == B) ? "Stable" : "Not stable") << endl;
}   


Measured memory_bytes: 3236
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    private static final BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) {
        exec(args);
    }

    public static void exec(String[] args) {
        String str = readLineStandardInput();
        int N = Integer.parseInt(str);
        str = readLineStandardInput();
        String[] Astr = str.split(" ");
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        for(int i = 0; i < Astr.length; i++) {
            int tmp = Integer.parseInt(Astr[i]);
            min = min > tmp ? tmp : min;
            max = max < tmp ? tmp : max;
        }
        int res = max - min;
        System.out.println(res);
    }

    private static String readLineStandardInput() {
        String str;
        try {
            str = input.readLine();
        } catch(IOException e){
            str = null;
            System.out.println(e);
        }
        return str;
    }
}


Measured memory_bytes: 21076
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const ll MOD = 1e9+7;
//}}}

int main(){
  int a[3];
  rep(i, 3) cin >> a[i];
  sort(a, a + 3);
  cout << (a[2] - a[0]) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cstdio>
#include<math.h>
#include<string>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define inf 0X3f3f3f3f
#define N 100
int a[N];
int b[N];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            b[i]=a[i];
        }
        sort(a,a+n);
        int flag=0;
        for(int i=0;i<=n;i++)
        {
            if(a[i]!=b[i])
                flag++;
        }
        if(flag>2)
            printf("NO\n");
        else
            printf("YES\n");
    }
}

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

#define f(i, q) for(int i = 0; i < q; i++)  

typedef long long ll;

int main() {
    int r, g, b, n;

    cin >> r >> g >> b >> n;

    int count = 0;
    for (int i = 0; i * r <= n; i++) {
        for (int j = 0; i * r + j * g <= n; j++) {
            // for(int k = 0; i * r + j * g  + k * b <= n; k++) {
            //     if(i*r + j*g + k*b == n)
            //         count++;
            // }

            if( (n - (i * r + j * g)) % b == 0 ) {
                count++;
            }
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }





int main() {
    ll n;
    cin >> n;
    queue<ll> que;
    REP(i, 1 << n){
        ll a;
        cin >> a;
        que.push(a);
    }
    while(que.size() > 1){
        ll a = que.front(); que.pop();
        ll b = que.front(); que.pop();
        if(a > b) que.push(a - b);
        else if(a < b) que.push(b - a);
        else que.push(a);
    }
    cout << que.front() << endl;
}


Measured memory_bytes: 2432
#include <iostream>
using namespace std; using P=pair<int,int>; using ll=long long;

int main() {
  int n; cin>>n;
  ll x[n],y[n],h[n];
  for(int i=0;i<n;i++) cin>>x[i]>>y[i]>>h[i];
  for(ll cx=0;cx<=100;cx++) {
    for(ll cy=0;cy<=100;cy++) {
      ll he;
      // h[i]==0のとき、値が一意に求まらない
      for(int i=0;i<n;i++) if (h[i]!=0) {he=h[i]+abs(x[i]-cx)+abs(y[i]-cy); break;}
      if (he<=0) continue; // これはありえない
      bool ok=true;
      //cout<<cx<<" "<<cy<<" "<<he<<endl;
      for(int i=0;i<n;i++) {
        if (max(he-abs(x[i]-cx)-abs(y[i]-cy),0LL) != h[i]) {ok=false; break;}
      }
      if (ok) {
        cout<<cx<<" "<<cy<<" "<<he<<endl;
        return 0;
      }
    }
  }
  //cerr<<"OMG"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Set(a,b) memset(a,b,sizeof(a))
using namespace std;
const int N=1e6+10;
const int mod=1e9+7;
template <typename T> inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}
typedef long long ll;
template<typename T>inline void Inc(T&x,int y){x+=y;if(x>=mod) x-=mod;return;}
template<typename T>inline void Dec(T&x,int y){x-=y;if(x <  0) x+=mod;return;}
template<typename T>inline int fpow(int x,T k){int ret=1;for(;k;k>>=1,x=(ll)x*x%mod) if(k&1) ret=(ll)ret*x%mod;return ret;}
inline int Sum(int x,int y){x+=y;if(x>=mod) return x-mod;return x;}
inline int Dif(int x,int y){x-=y;if(x < 0 ) return x+mod;return x;}
int n,H,D;
int fac[N],ifac[N],f[N];

int main()
{
	init(n),init(H),init(D);fac[0]=ifac[0]=1;
	int sum=0;
	for(int i=1;i<=n;++i) fac[i]=(ll)fac[i-1]*i%mod,Inc(sum,fac[i]);
	ifac[n]=fpow(fac[n],mod-2);
	for(int i=n-1;i;--i) ifac[i]=(ll)ifac[i+1]*(i+1)%mod;
	f[0]=fac[n];int S=fac[n];
	int L=0;
	for(int i=1;i<=H;++i) {
		if(i-L>D) Dec(S,f[L++]);
		if(i==H) cout<<S<<endl;
		f[i]=(ll)S*sum%mod;
		Inc(S,f[i]);
	}
	return 0;
}


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

using namespace std;

int main(){
    string s, fr="", bc="";
    bool rev=false;
    long long int q;
    cin >> s >> q;
    for (int i=0; i<q; i++){
        int query;
        cin >> query;
        if (query == 1){
            rev = !rev;
        }
        else {
            int f;
            char c;
            cin >> f >> c;
            if ((f == 1 && !rev) || (f == 2 && rev)){
                fr.push_back(c);
            }
            else {
                bc.push_back(c);
            }
        }
    }
    reverse(fr.begin(), fr.end());
    s = fr + s + bc;
    if (rev)  reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 1348
x, k, d=map(int, input().split())
if round(abs(x)/d) >= k :
    print(abs(abs(x)-k*d))
else:
    if (k-round(abs(x)/d))%2:
        print(d-abs(abs(x)-d*round(abs(x)/d)))
    else:
        print(abs(abs(x)-d*round(abs(x)/d)))

Measured memory_bytes: 9212
import math
def A():
    temp = [int(i) for i in input().split()]
    print(int(math.ceil(temp[0]/temp[1])))

def B():
    temp = [int(i) for i in input().split()]
    H = temp[0]
    N = temp[1]
    A = [int(i) for i in input().split()]
    if H <= sum(A):
        print('Yes')
    else:
        print('No')

B()

Measured memory_bytes: 14012
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

 int main(){

 long long n,m;
 cin>>n;
 int a[n];
 map<int,int>mp;


 for(int i=0;i<n;i++){
    cin>>a[i];
    mp[a[i]]++; }

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

 for(int i=0;i<m;i++)
 {
    if(mp[b[i]] > 0){
        mp[b[i]]--;
    }
    else {
        cout<<"NO"<<endl;
        return 0;
    }
 }

 cout<<"YES"<<endl;

return 0;
 }

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

int f(int n, int k){
	int ans = 0;
	while(0 < n){
		n /= k;
		ans++;
	}
	
	return ans;
}

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

	int ans = f(n, k);

	cout << ans << endl;

	return 0;
}


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

using namespace std;

using ll = long long;

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

    int n, d; cin >> n >> d;
    cout << n / (2 * d + 1) + (n % (2 * d + 1) > 0) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

  int main(){
   int a, b, c;

   scanf("%d" , &a);
   scanf("%d" , &b);
   scanf("%d" , &c);

   if(a<b&&b<c){
    printf("Yes\n");
   }

   else{
    printf("No\n");
   }

   return 0;
}


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

int main() {
  int  H, W;
  cin >> H >> W;
  string box;
  for (int j = 0; j < W + 2; j++) {
    box += '#';
  }
  vector<string> total(H + 2);
  total.at(0) = box;
  for (int i = 0; i < H; i++) {
    string a;
    cin >> a;
    string newa = '#' + a + '#';
    total.at(i + 1) = newa;
  }
  total.at(H + 1) = box;
  for (int k = 0; k < total.size(); k++) {
    cout << total.at(k) << endl;
  }
}



Measured memory_bytes: 3644
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
//dp[i]:前i个位置染完的最小花费
//dp[0] = 0, dp[others] = INF
//if(a[i] == b[i]) dp[i] = dp[i-1]
//else dp[i] = min{dp[j] + cost(j+1, i)|max(0, i-k) <= j < i}
//cost(x, y):ceil((sum[i]-sum[j+1])/2)+1=(sum[i]-sum[j+1]+1)/2+1
//dp[i]=min{(2*dp[j]-sum[j+1]+sum[i]+3)/2|max(0, i-k) <= j < i}
//f[j] = 2*dp[j] - sum[j+1]//用长度为k的单调队列维护
//dp[i]=min{(f[j]+sum[i]+3)/2}
//f[i] = 2*dp[i]-sum[i+1]入队
const int maxn =  5e5 + 10;
const int INF = 0x3f3f3f3f;
int n, k;
char s[maxn], t[maxn];
int sum[maxn];
int dp[maxn];
struct Queue {
    struct Node {
        int pos, val;
    }node[maxn];
    int l, r;
    void init() { l = 1, r = 0; }
    void update(int pos, int val) {
        while (l <= r && val < node[r].val) r--;
        node[++r] = Node{pos, val};
        while (l <= r && node[r].pos - node[l].pos >= k) l++;
    }
    int query() {
        if (l > r) return INF;
        return node[l].val;
    }
}que;
int main() {
    scanf("%d%d", &n, &k);
    scanf("%s%s", s+1, t+1);
    sum[0] = 0, t[0] = '#';
    for (int i = 1; i <= n; i++) sum[i] = sum[i-1] + (t[i] != t[i-1]);
    dp[0] = 0;
    que.init();
    que.update(0, 2*dp[0]-sum[1]);
    for (int i = 1; i <= n; i++) {
        dp[i] = INF;
        if (s[i] == t[i]) dp[i] = dp[i-1];
        else {
            //cout << i << ":" << que.query() << endl;
            dp[i] = min(dp[i], (que.query()+sum[i]+3)/2);
        }
        que.update(i, 2*dp[i]-sum[i+1]);
        //cout << dp[i] << "test" << endl;
    }
    printf("%d\n", dp[n]);
    return 0;
}



Measured memory_bytes: 12004
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>

#define ll long long
#define endl \'n'
using namespace std;

const int INF = 0x3f3f3f3f;


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    ll x, ans=0;
    for(int i=0; i<n; i++)
    {
        cin >> x;
        while(x%2==0)
        {
            x/=2;
            ans++;
        }
    }
    cout << ans;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    while(true){
      boolean hantei = true;
      for(int i = 2; i <X; i++){
        if(X % i == 0){hantei = false; break;}
      }
      if(hantei == true)break;
      else X++;
    }
    System.out.println(X);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, m;
vector<vector<int>> g;
int main() {
  cin >> n >> m;
  g.resize(n + 1);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
  }
  for (int s = 1; s <= n; ++s) {
    queue<int> que;
    que.push(s);
    vector<int> par(n + 1), dist(n + 1);
    i64 dist_min = 1ll << 30;
    par[s] = -1;
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      for (int v : g[u]) {
        if (par[v] == 0) {
          par[v] = u;
          dist[v] = dist[u] + 1;
          que.push(v);
        }
        if (v == s) {
          dist_min = dist[u];
          vector<int> route;
          for (int a = u; a != -1; a = par[a]) {
            route.push_back(a);
          }
          set<int> st;
          for (int u : route) st.insert(u);
          bool ok = true;
          for (int u : route) {
            int cnt = 0;
            for (int v : g[u]) {
              cnt += st.count(v);
            }
            if (cnt != 1) ok = false;
          }
          if (ok) {
            cout << route.size() << '\n';
            for (int u : route) cout << u << '\n';
            return 0;
          }
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include<stdlib.h>
 
int main()
{
	int x,a,b;
	scanf("%d %d %d",&x,&a,&b);
	if(x<=1000&&a<=1000&&b<=1000){
		if (abs(x-a)<abs(x-b)){
			printf("A\n");}
		else{
			printf("B\n");}}
	else{printf("Enter Valid Numbers");}
	return 0;
}
 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int n,tot;
LL a[100010];
LL gcd(LL x,LL y)
{
    if (x%y == 0) return y;
    else return gcd(y,x%y);
}
int init()
{
    for (int i = 0;i < n;i++) if (a[i]&1)
    {
        if (a[i] == 1) return 0;
        else a[i]--;
    }
    LL g = a[0];
    for (int i = 1;i < n;i++) g = gcd(g,a[i]);
    for (int i = 0;i < n;i++) a[i] /= g;
    tot = 0;
    for (int i = 0;i < n;i++) if (!(a[i]&1)) tot++;
    return 1;
}
int dfs()
{
    if (tot&1) return 1;
    else {
        if (n-tot >= 2) return 0;
        else {
            if (!init()) return 0;
            return dfs()^1;
        }
    }
}
int main()
{
    cin >> n;
    for (int i = 0;i < n;i++)
    {
        scanf("%lld",&a[i]);
        if (!(a[i]&1)) tot++;
    }
    if (dfs()) printf("First\n");
    else printf("Second\n");
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define FOR(i, a, b) for(int i = a; i < b; i++)
#define RFOR(i, n) for(int i = n - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back
 
ll dp[100005];

int main() {
    int N, W; cin >> N >> W;
    vector<ll> v(N), w(N);
    for(int i = 0; i < N; i++) cin >> w[i] >> v[i];
    for(int i = 0; i < N; i++) {
        for(int j = W; j >= 0; j--) {
            if(j - w[i] < 0) continue;
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }
        
    cout << dp[W] << endl;
}

Measured memory_bytes: 4412
using System;
using System.Linq;

namespace arc078_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long ret = long.MaxValue;
            long flont = 0;
            long back = x.Sum();
            for (int i = 0; i < n - 1; i++)
            {
                flont += x[i];
                back -= x[i];
                ret = Math.Min(ret, Math.Abs(flont - back));
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 32988
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>

using namespace std;

int main()
{
    string str;
    cin >> str;

    int hemi = 0;
    for (int i = 0; i < str.size(); i++) {
        if (hemi == 0) {
            if (str[i] == 'C') {
                hemi = 1;
            }
        } else if (hemi == 1 && str[i] == 'F') {
           hemi = 2; break;
        }
    }
    if (hemi == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

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

  vector<int> dp(100000);
  dp[1] = 0;
  dp[2] = abs(h[2]-h[1]);
  int i = 3;
  while (i <= n) {
    dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    i++;
  }

  cout << dp[n] << endl;

  return 0;
}

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

int main()
{
int n,ans=0;
cin >> n;

    for(int i=0;i<n;i++)
    {   
    int inp;
    cin>> inp;

    if(inp <2)continue;
    if(inp ==2)ans++;
    if(inp % 2 ==0)continue;
        else
        {
        int flag = 1;
            for(int i=3;i*i <= inp;i+=2)
            {
                if(inp % i == 0)
                {
                flag =0;
                break;
                }
            }
         if(flag == 1)ans++;
        }
    
    }

cout << ans << endl;

return 0;
}


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

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int cou = 0;
    for (int i = a; i <= b; i++) {
        if (c%i == 0)cou++;
    }
    cout << cou << endl;
}


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

int maxHappiness(vector<vector<int>> &happiness){
    int days= happiness.size();
    int activities = happiness[0].size();
vector<vector<int>> dp(days, vector<int>(activities, -1));
for(int j=0;j<activities;j++){
        dp[0][j] = happiness[0][j];
    }
        for(int i=1; i<days; i++){
        for(int j=0;j<activities;j++){
int maxAns = INT_MIN;
    for(int k=0;k<activities;k++){
        if(k!=j) maxAns = max(dp[i-1][k], maxAns);
}
dp[i][j] = happiness[i][j] + maxAns;
}
    }
    int ans = INT_MIN;
    for(int i=0;i<activities;i++){
        ans = max(ans, dp[days-1][i]);
    }
    return ans;
}

int main(){
 int n;
        cin>>n;
        vector<vector<int>> happiness(n, vector<int>(3));
        
        for(int i=0; i<n; i++){
                for(int j=0; j<3; j++){
                cin>>happiness[i][j];
}
        }
    cout<<maxHappiness(happiness)<<endl;

}







Measured memory_bytes: 14060
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		for (int x = 0; x < n; x++) {
			String query = scanner.next();
			ArrayList<String> list = new ArrayList<String>();
			for (int i = 0; i < query.length() - 1; i++) {
				StringBuffer top = new StringBuffer(query.substring(0, i + 1));
				StringBuffer bottom = new StringBuffer(query.substring(i + 1,
						query.length()));

				String[] tops = new String[2];
				tops[0] = top.toString();
				tops[1] = top.reverse().toString();
				String[] bottoms = new String[2];
				bottoms[0] = bottom.toString();
				bottoms[1] = bottom.reverse().toString();
				for (int j = 0; j < tops.length; j++) {
					for (int j2 = 0; j2 < bottoms.length; j2++) {
						String sequence0 = tops[j] + bottoms[j2];
						String sequence1 = bottoms[j2] + tops[j];
						if (!list.contains(sequence0)) {
							list.add(sequence0);
						}
						if (!list.contains(sequence1)) {
							list.add(sequence1);
						}
					}
				}
			}
			System.out.println(list.size());
		}

	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

}

Measured memory_bytes: 59008
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>

using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(LL i = (a); i < (LL)(n); ++i)
#define REM(i,a,n) for(LL i = ((n) - 1); i >= (a); --i)
#define FLOAT fixed << setprecision(16)
#define SPEEDUP {cin.tie(0); ios::sync_with_stdio(false);}
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const string INFSTR = "\x7f";
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template<class T>
T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }
// all_of
// partial_sum, adjacent_difference

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#include "Flow_Solver.h"
#include "Tree.h"
#include "Suffix_Array.h"
#include "Geometry.h"
#include "Matrix.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

#if 1234567891
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

int GCD(int a, int b) {
	if (b == 0) return a;
	return GCD(b, a % b);
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a % 2 || b % 2 || c % 2) {
		cout << 0 << endl;
	} else {
		int gcd = GCD(b - a, c - b);
		int ans = 0;
		if (gcd == 0) {
			ans = -1;
		} else {
			while (gcd % 2 == 0) {
				++ans;
				gcd /= 2;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

int main(){
 int n, m;
  cin >> n >> m;
  int arr[105], sum = 0;
  for (int i = 0; i < n; ++i){
    cin>> arr[i];
    sum += arr[i];
  }
  sort(arr, arr + n);
  int ct = 0;
  for (int i = n - 1; i >= 0; --i){
    if (arr[i] * 4 * m >= sum) ++ct;
    if (ct == m){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

typedef long long ll;
using vi = vector<int>;
using vll = vector<ll>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];

    vector<int> a(n);
    rep(i, n) a[i] = i + 1;

    map<vector<int>, int> mp;
    do {
        mp[a] = mp.size();
    } while(next_permutation(all(a)));

    int ans = abs(mp[p] - mp[q]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rt", stdin);
#endif
	int a, b,c, k;
	cin >> a >> b >> c >> k;
	int total = 0;
	int mn = min(a, k);
	total += mn;
	k -= mn;
	mn = min(b, k);
	k -= mn;
	mn = min(k, c);
	total -= mn;
	cout << total;
	return 0;
}


Measured memory_bytes: 3652