akhauriyash/Code-Regression huggingface dataset:
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 


int main(){

	int n;
	long long x;
	cin>>n>>x;

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

	//k=0;
	vector<long long> b=a;
	long long res=0;
	for(int i=0;i<n;i++) res+=b[i];

	for(int k=1;k<n;k++){
		long long cost=k*x;
		for(int i=0;i<n;i++){
			b[i]=min(b[i],a[(i-k+n)%n]);
			cost+=b[i];
		}
		res=min(res,cost);

	}

	cout<<res<<endl;

}

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

int n, m, s, d[105][105], t1[1005], t2[1005], t3[1005], v[105][105], a[105][105];
int main()
{
	int i, j, k;
	cin >> n >> m;
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			d[i][j] = 1e9;
		}
		d[i][i] = 0;
	}
	for (i = 0; i < m; i++) {
		scanf ("%d %d %d", &t1[i], &t2[i], &t3[i]);
		a[t1[i]][t2[i]] = t3[i];
		d[t1[i]][t2[i]] = d[t2[i]][t1[i]] = t3[i];
//		v[t1[i]][t2[i]] = v[t2[i]][t1[i]] = 1;
	}
	for (k = 1; k <= n; k++) {
		for (i = 1; i <= n; i++) {
			for (j = 1; j <= n; j++) {
				if (i == j) continue;
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
//	//			for (k = 1; k <= n; k++) {
//					if (d[i][k] + d[k][j] < d[i][j] && i != k && k != j) {
//						d[i][j] = d[i][k] + d[k][j];
//							v[i][j] = v[j][i] = 1;
//					}
//	//			}
			}
		}
	}
	for (i = 0; i < m; i++) s += (a[t1[i]][t2[i]] != d[t1[i]][t2[i]]);
	cout << s;
    return 0;
}


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

int main() {
    int n,m,a,b,c,sum=0,flag=0;
	string s;
    cin>>a;
    for(int i=0;i<6;i++){
        if(a%2==1){
            sum++;
        }
        a/=10;
    }
    cout<<sum<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll n,m;
	scanf("%lld%lld",&n,&m);
	if(n==1&&m==1) printf("1\n"),0;
	else if(n==1||m==1) printf("%lld\n",n*m-2),0;
	else {
		printf("%lld\n",n*m-(2*n+2*m-4));
	}
	return 0;
}


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

#define SIZE 10000

struct WORD {
	char value[13];
	struct WORD *next;
};

struct WORD* HashTable[SIZE];	//default: all NULL

int HashFunc(char s[]) {
	long long hash = 0;
	for (int i = 0; s[i] != '\0'; i++) {
		hash += s[i] * (i + 1);
	}
	return (int)(hash * 13 % SIZE);
}

void AddWord(char s[], int hashNum) {
	struct WORD* newWord = (struct WORD*)malloc(sizeof(struct WORD));
	strcpy(newWord->value, s);
	newWord->next = NULL;
	if (HashTable[hashNum] == NULL) HashTable[hashNum] = newWord;
	else {
		newWord->next = HashTable[hashNum];
		HashTable[hashNum] = newWord;
	}
}

void Insert(char s[]) {
	int hash = HashFunc(s);
	AddWord(s, hash);
}

void Find(char s[]) {
	int hash = HashFunc(s);
	struct WORD* pos;
	for (pos = HashTable[hash]; pos != NULL; pos = pos->next) {
		if (!strcmp(s, pos->value)) {
			printf("yes\n");
			return;
		}
	}
	printf("no\n");
	return;
}

int main() {
	int n;
	char command[7], value[13];
	for (int i = 0; i < SIZE; i++) {
		HashTable[i] = NULL;
	}
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s %s", command, value);
		if (command[0]=='i') Insert(value);
		else if (command[0]=='f') Find(value);
	}

	return 0;
}


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

int main(){

  string S;
  int N;
  int j=0;
  
  cin >> S;
  N = S.size();
  for(int i=0;i<N/2;++i){
    if(S.at(i) != S.at(N-1-i)){
      cout << "No" << endl;
      return 0;
    }
  }

  for(int i=0;i<(N-1)/4;++i){
    if(S.at(i) != S.at((N-1)/2-i-1)){
      cout << "No" << endl;
      return 0;
    }
  }

  for(int i=(N+3)/2-1;i<N;++i){
    if(S.at(i) != S.at(N-1-j)){
      cout << "No" << endl;
      return 0;
    }
    ++j;
  }
  cout << "Yes" <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long int N,A,B,C,D,E;
  cin >> N >> A >> B >> C >> D >> E;
  
  long long int t=4;
  
  long long int m=min(min(min(min(A,B),C),D),E);
  
  if(N%m==0){
    t +=N/m;
  }else{
    t +=(N-N%m)/m+1;
  }
  
  cout << t << endl;

}

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

priority_queue<int> S;
int main()
{
	int k;
	string str;

	while (true)
	{
		cin >> str;
		if (str == "insert")
		{
			cin >> k;
			S.push(k);
		}
		else if (str == "extract")
		{
			cout << S.top() << endl;
			S.pop();
		}
		else if (str == "end") break;
	}

	return 0;
}

Measured memory_bytes: 6908
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
struct node{
	int a, b, c;
}a[1000100];

int n, ma, mb;
ll m[60][510][510];

bool check(int cura, int curb){
	if(cura == 0 && cura == curb){
		return false;
	}
	return ma*curb == mb*cura;
}

ll memo(int curr, int wa, int wb){
	if(curr == n){
		if(check(wa, wb)){
			return 0;
		} else {
			return (ll)1e18;	
		}
	}
	if(m[curr][wa][wb] != -1){
		return m[curr][wa][wb];	
	}
	ll ans = (ll)1e18;
	ans = min(ans, a[curr].c + memo(curr+1, wa+a[curr].a, wb+a[curr].b));
	ans = min(ans, memo(curr+1, wa, wb));
	m[curr][wa][wb] = ans;
	return ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> ma >> mb;
	for(int i=0 ; i<n ; i++){
		cin >> a[i].a >> a[i].b >> a[i].c;
	}
	memset(m, -1, sizeof(m));	
	ll r = memo(0, 0, 0);
	if(r > (ll)1e12){
		cout << "-1\n";
	} else {
		cout << r;
	}	
	return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  auto r = count(begin(s), end(s), 'R');
  auto g = count(begin(s), end(s), 'G');
  auto b = count(begin(s), end(s), 'B');
  auto ans = r * g * b;
  for (int j = 1; j < n; j++) {
    for (int i = 0; i < j; i++) {
      int k = 2 * j - i;
      if (k < n) {
        if (s[i] != s[j] and s[j] != s[k] and s[k] != s[i])
          ans --;
      }
    }
  }
  cout << ans << endl;
}


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

int main(){
  int n ;
  cin >> n ;
  
  if ( n % 1111 == 0 )
    cout << "Yes" << endl;
  else if ( (n - n % 10) % 111 == 0 )
    cout << "Yes" << endl;
  else if ( n % 1000 % 111 == 0 )
    cout << "Yes" << endl;
  else 
    cout << "No" << endl;
}

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

int main() {
    string n;
    
 
   cin >> n;
  
   int engineerPos = n.find("9");
  
   if(engineerPos!=-1){
     cout << "Yes" << endl;
   }else{
     cout << "No" << endl;
   }
   
 
  
  return 0;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
m = [0] * n
for i in range(n):
    m[i] = int(input())
sm = sum(m)

if sm < x:
    print(n + ((x - sm) // min(m)))
elif sm == x:
    print(n)
# else:
#     s = 0
#     m.sort()
#     for i in range(n):
#         s += m[i]
#         if s >= x:
#             print(s)
#             exit()
        

Measured memory_bytes: 38256
#include <iostream>
#include <cmath>
 
using namespace std;
int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int less_or_eq_A = 0;
	int more_A_less_eq_B = 0;
	int more_B = 0;
 
 
	for (int i = 0; i < N; i++) {
		int p;
		cin >> p;
		if (p <= A) {
			less_or_eq_A++;
		} else if (p <= B) {
			more_A_less_eq_B++;
		} else {
			more_B ++;
		}
	}
	cout << min(min(less_or_eq_A,more_A_less_eq_B), more_B) << endl;
 
 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define INF 1000000000
int main(){

  while(true){
    int n,k;
    cin >> n >> k;
    if(n==0)break;
    int cost[100][100];
    for(int i =0;i<n;i++){
      for(int j =0;j<n;j++){
        if(i!=j)cost[i][j]=INF;
        else cost[i][j] = 0;
      }
    }
    int flg = false;
    for(int i =0;i<k;i++){
      int a,b,c,d,e,f;
      cin >>f;
      if(!f){
        if(flg){
          for(int i1 =0;i1<n;i1++){
            for(int j =0;j<n;j++){
              for(int k = 0;k<n;k++){
                cost[j][k]=min(cost[j][k],cost[j][i1]+cost[i1][k]);
              }
            }
          }
        }
        flg = false;
        cin >>a>>b;
        if(cost[a-1][b-1]==INF){
          cout <<-1<<endl;
        }
        else{
          cout << cost[a-1][b-1]<<endl;
        }
      }
      else{
        cin >>c>>d>>e;
        if(cost[d-1][c-1]>e){
          flg = true;
          cost[d-1][c-1]=cost[c-1][d-1]=e;
        }
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3116
#include<stdio.h>
#include<math.h>
#define MOD 998244353
#define MAX 3001
#define MAX_DISTANCE 501
#define PRECISION 0.00000000001
#define INF 4000000000000000000
int main()
{
    double cir;
    scanf("%lf",&cir);
    cir=cir*2*acos(-1);
    printf("%.8f",cir);
    return 0;
}


Measured memory_bytes: 1748
from collections import defaultdict


n, m = map(int, input().split())
light_list = list(map(int, input().split()))
ret = 0

diff_dict = defaultdict(int)
cnt=0
for i in range(n-1):
    if light_list[i+1] > light_list[i]:
        diff_dict[light_list[i+1]+1] += light_list[i+1] - light_list[i]
        ret += light_list[i+1] - light_list[i]
    else:
        diff_dict[light_list[i+1]+1] += m - (light_list[i] - light_list[i+1])
        ret += light_list[i+1]
        cnt += 1


ret_min = float('inf')
for i in range(1, m+1):
    if i-1 == light_list[0]:
        cnt += 1
    if i-1 == light_list[-1]:
        cnt -= 1
    if diff_dict[i]:
        ret += diff_dict[i]
    ret -= cnt
    ret_min = min(ret+cnt, ret_min)




print(ret_min)

Measured memory_bytes: 62060
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cap,rev;};//ikisaki youryou gyakuhen
class MF{//max flow
	public:
	int n;
	vector<vector<edge> >G;//[MAX];
	vector<bool>used;//[MAX];
	MF(int size){
		n=size;
		G=vector<vector<edge> >(n);
	}
	void add_edge(int from, int to, int cap){
		edge q={to,cap,int(G[to].size())};
		G[from].push_back(q);
		q={from,0,int(G[from].size()-1)};
		G[to].push_back(q);
	}
	int dfs(int v,int t, int f) {
		if(v==t)return f;
		used[v]=1;
		for(int i=0;i<G[v].size();i++){
			edge &e=G[v][i];
			if(used[e.to]||e.cap<=0) continue;
			int d =dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
		return 0;
	}
	int mf(int s,int t) {//from s to t,ford_fulkerson
		int flow=0,f;
		while(1){
			used=vector<bool>(n,false);
			f=dfs(s,t,inf);
			if(f==0)return flow;
			flow+=f;
		}
	}
};
int main(){
	int n,m,a,b;
	cin>>n>>a>>b;
	vi A,B,in(n);
	rep(i,n){
		int q,w;
		cin>>q>>w;
		in[i]=q-w;
	}
	int out=0;
	rep(i,n)if(abs(in[i])<=a||b<=abs(in[i])&&abs(in[i])<=2*a)out++;
	else if(in[i]>0)A.pb(in[i]);
	else B.pb(in[i]);
	
	n=A.size(),m=B.size();
	MF mf(2+n+m);
	int s=n+m,t=s+1;
	rep(i,n)mf.add_edge(s,i,1);
	rep(i,m)mf.add_edge(n+i,t,1);
	rep(i,n)rep(j,m){
		int w=abs(A[i]+B[j]);
		if(w<=a||b<=w&&w<=2*a)mf.add_edge(i,n+j,1);
	}
	out+=mf.mf(s,t);
	cout<<out<<endl;
}







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

int main(){
    int n,m,tmp,sum=0;
    cin >> n >> m;

    for(int i=0;i<m;i++){
        cin >> tmp;
        sum += tmp;
    }
    if(sum > n) cout << -1 << endl;
    else cout << n-sum << endl;
}

Measured memory_bytes: 3632
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let _n: usize = s.next().unwrap().parse().unwrap();

	let mut cnt = vec![vec![0i64; 128]; 128];

	for s in s {
		let neg = if let Some(i) = s.find(".") {
			(s.len() - 1) - i
		} else {
			0
		};

		let s = s.replace(".", "");
		let n: i64 = s.parse().unwrap();
		let e2 = {
			let mut m = n;
			let mut r = 0;
			while m % 2 == 0 {
				r += 1;
				m /= 2;
			}
			r
		};
		let e5 = {
			let mut m = n;
			let mut r = 0;
			while m % 5 == 0 {
				r += 1;
				m /= 5;
			}
			r
		};
		cnt[64 + e2 - neg][64 + e5 - neg] += 1;
	}

	let mut ansid = 0;
	let mut ansdis = 0;
	for e2 in -63..64 {
		for e5 in -63..64 {
			for f2 in -63..64 {
				for f5 in -63..64 {
					if e2 + f2 >= 0 && e5 + f5 >= 0 && (e2, e5) != (f2, f5) {
						ansdis += cnt[(64 + e2) as usize][(64 + e5) as usize] * cnt[(64 + f2) as usize][(64 + f5) as usize];
					}
				}
			}
			if e2 >= 0 && e5 >= 0 {
				ansid += cnt[(64 + e2) as usize][(64 + e5) as usize] * (cnt[(64 + e2) as usize][(64 + e5) as usize] - 1) / 2;
			}
		}
	}
	println!("{}", ansdis / 2 + ansid);
}


Measured memory_bytes: 4652
#include<bits/stdc++.h> 
using namespace std;
 
int main() {
    long long ans = 0;  
	int n;
	cin >> n;
	vector<int> s(n);
	vector<int> a(n);
	vector<int> b(n);
    for (int i = 0; i < n; i++) {
	    cin >> a[i] >> b[i];
	    s[i] = a[i] + b[i];
        ans -= b[i];
    }
    sort(s.begin(), s.end());
    reverse(s.begin(), s.end());
    for (int i = 0; i < n; i+=2) {
        ans += s[i];
    }
    cout << ans;
    return 0;
 }

Measured memory_bytes: 1408
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

class Tree {
    public:
    struct Node {
        std::vector<int> edge;
        int rank;
        int direction;
    };
    std::vector<Node> node;
    Tree() {}
    Tree(const int node_num_max) {
        node.resize(node_num_max);
    }
    void add_directed_edge(const int from, const int to) {
        node[from].edge.push_back(to);
    }
    void add_undirected_edge(const int node1, const int node2) {
        add_directed_edge(node1, node2);
        add_directed_edge(node2, node1);
    }
    void set_rank(int n, int rank, int parent) { // 辺が有向でも無向でも使える。呼び出すとき、parentは-1にしておくとよい。
        node[n].rank = rank;
        for (int c : node[n].edge) {
            if (c != parent) {
                set_rank(c, rank + 1, n);
            }
        }
    }
    int calc_diameter(int max_idx) {
        // 点は1～max_idxという想定。
        set_rank(1, 0, -1);
        int tmp_idx = 1;
        int tmp_diameter = 0;
        for (int i = 1; i <= max_idx; i++) {
            if (tmp_diameter < node[i].rank) {
                tmp_idx = i;
                tmp_diameter = node[i].rank;
            }
        }
        set_rank(tmp_idx, 0, -1);
        for (int i = 1; i <= max_idx; i++) {
            tmp_diameter = std::max(tmp_diameter, node[i].rank);
        }
        return tmp_diameter;
    }
};

const int MAX_N = 200050;
Tree tree = Tree(MAX_N);

int N, a[MAX_N], b[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;

    for (int i = 1; i < N; i++) {
        std::cin >> a[i] >> b[i];
    }

    if (N == 1) {
        std::cout << "First" << std::endl;
        return 0;
    }

    for (int i = 1; i < N; i++) {
        tree.add_undirected_edge(a[i], b[i]);
    }

    int diameter = tree.calc_diameter(N);

    if (diameter % 3 == 1) {
        std::cout << "Second" << std::endl;
    } else {
        std::cout << "First" << std::endl;
    }

    return 0;
}

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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef map<int,int> mii;

const int MOD = 1e9+7;

void solve () {
	int r,c,k;
	cin >> r >> c >> k;
	string grid[r];
	for (int i = 0;i < r;++i) {
		cin >> grid[i];
	}
	int ans = 0;
	for (int i = 0;i < pow(2,r)-1;++i) {
		for (int j = 0;j < pow(2,c)-1;++j) {
			int cnt = 0;
			for (int u = 0;u < r;++u) {
				for (int v = 0;v < c;++v) {
					if (((1<<u)&i) > 0 || ((1<<v)&j) > 0) continue;
					else {
						if (grid[u][v] == '#') ++cnt;
					} 
				}
			}
			if (cnt == k) {
				++ans;
			}
		}
	}
	cout << ans << '\n';
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}



Measured memory_bytes: 4036
#include <stdio.h>

int main(void)
{
	int N,K,i;
	long long total=0;
	scanf("%d",&N);
	scanf("%d",&K);
	for(i=K;i<=N+1;i++){
		total+=(long long)i*(2*N-(i-1))/2-(long long)i*(i-1)/2+1;
		total=(long long)total%1000000007;
	}
	printf("%lld",total);
	return 0;
}

Measured memory_bytes: 1736
//50
#include<iostream>
#include<algorithm>

using namespace std;

struct S{
  int d,t,n;
  bool operator<(S a)const{
    if(t!=a.t){
      return t<a.t;
    }else{
      return d<a.d;
    }
  }
};

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    S p[1000];
    for(int i=0;i<n;i++){
      cin>>p[i].d;
      p[i].n=i+1;
      p[i].t=m/p[i].d*p[i].d;
    }
    sort(p,p+n);
    if(!(p[0]<p[1])&&!(p[1]<p[0])){
      cout<<n<<endl;
    }else{
      cout<<p[0].n<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A.at(i);
    ll sum = accumulate(A.begin(), A.end(), N * -1);
    cout << sum << endl;
}


Measured memory_bytes: 256
<?php
// $time_s = microtime(true);

fscanf(STDIN, "%d %d", $A, $B);

$ans = 0;
for ($i = $A; $i <= $B; $i++) {
    if (isPand($i)) {
        $ans++;
    }
}
echo $ans . "\n";

// $time_g = microtime(true);

// echo $time_g - $time_s . "\n";

function isPand($num) {
    $arr = str_split(strval($num));
    return (($arr[0] == $arr[4]) && ($arr[1] === $arr[3]));
}



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

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

    int a[n],b[n],c[n];

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

    int dp[n][3];

    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];

    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<"\n";
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


set<int>s;
bool mm[200005];
int ini[400005];
int pre[400005];


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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,k;
    cin>>n>>k;
    int a[n+1]={0};
    for(int i=1;i<=n;i++)
    {
            cin>>a[i];
            a[i]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]>a[i-1])
            ini[i]=1;
        pre[i]=pre[i-1]+ini[i];
    }
    for(int i=k;i<=n;i++)
    {
        if(pre[i]-pre[i-k+1]==k-1)
        {
            ini[i]=1;
        }
        else
        {
            ini[i]=0;
        }
    }
    int ans=0;
    s.insert(a[1]);
    set<int>cur;
    cur.insert(a[1]);
    bool ok=false;
    for(int i=2;i<=k;i++)
    {
        auto j=cur.lower_bound(a[i]);
        while(j!=cur.end())
        {
            ok=true;
            mm[*j]=1;
            cur.erase(j);
            j=cur.lower_bound(a[i]);   
        }
        cur.insert(a[i]);
        s.insert(a[i]);
    }
    bool flag=false;
    if(ini[k])
        flag=true;
    else
    {
        ans+=ok;
    }
    
    for(int i=k+1;i<=n;i++)
    {
        cur.erase(a[i-k]);
        s.erase(a[i-k]);
        auto j=cur.lower_bound(a[i]);
        while(j!=cur.end())
        {
            mm[*j]=1;
            cur.erase(j);
            j=cur.lower_bound(a[i]);   
        }
        if(ini[i])
        {
            flag=true;
        }
        else
        {
            auto t=s.lower_bound(a[i]);
            if(t!=s.end())
                    ans++;
            else if(mm[a[i-k]])
                    ans++;
        }
        cur.insert(a[i]);
        s.insert(a[i]);
    }

    ans+=flag;
    cout<<ans;

} 


Measured memory_bytes: 26240
N,M = map(int, input().split())

sets = []
for i in range(M):
  s,c = input().split()
  sets.append((s,c))

start = 0
if N != 1:
  start = 10**(N-1)

for n in range(start,10**N):
  for s,c in sets:
    if str(n)[int(s)-1] == c:
      continue
    else:
      break
  else:
    print(n)
    break
else:
  print(-1)

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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    int ans = n;
    REP(i, n - 1) {
        if(s[i] != s[i + 1]) {
            int dist = max(i + 1, n - i - 1);
            ans = min(ans, dist);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
b = [0]
ans = 0
for i in range(1, n+1):
    b.append(a[i-1] + b[i-1])
d = Counter(b)
d_v = d.values()
for i in d_v:
    ans += i*(i-1)//2
print(ans)

Measured memory_bytes: 41692
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define vll vector<ll> 
#define vvl vector<vll>
#define pii pair<ll,ll>
#define F first
#define S second
#define endl "\n"
#define M 1000000007
ll max(ll a,ll b){if (a>b) return a; else return b;}
 
/*ll po(ll x, ll y){
    if(y==0)
    return 1;
    if(y%2){
        return ((x)(po(x,y/2)%M)(po(x,y/2)%M) + M)%M;
    }
   return ((po(x,y/2)%M)*(po(x,y/2)%M) + M)%M;
}*/
 
void seive(bool prime[]){
    //bool prime[100002]; 
     
  
    for (ll p=2; p*p<=1000001; p++) 
    { 
        if (prime[p]) 
        { 
            for (ll i=p*p; i<=1000001; i+=p) 
                prime[i] = false; 
        } 
    }
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
    //cin>>t;
	while(t--){
	  string s;cin>>s;
	  ll sum=0;
	  fo(i,s.size())
	  sum+=(s[i]-'0');
	  if(sum%9==0)
	  cout<<"Yes"<<endl;
	  else
	  cout<<"No"<<endl;
	}
return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 55;
const int M = N * N;
const int Mod = 1e9 + 7;

int Dp[N][N][2 * M];

void add_self(int& x, int y)
{
    if((x += y) >= Mod) x -= Mod;
}

int add(int x, int y)
{
    return add_self(x, y), x;
}

int mul(int x, int y)
{
    return (ll) x * y % Mod;
}

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

    int nn = n * n;

    Dp[0][0][m + M] = 1;

    for(int i = 1; i <= n; i++)
    {
        for(int j1 = 0; i + j1 <= n; j1++)  /// empty cells after 'i'
        {
            for(int k = -nn; k <= nn; k++)    /// current oddness
            {
                int j2 = j1;

                Dp[i][j1][k + M] = 0;

                add_self(Dp[i][j1][k + M], mul(j1 + j2 + 1, Dp[i - 1][j1][k + i - i + M]));
                if(j1 > 0 && j2 > 0 && k - i - i >= -nn)
                    add_self(Dp[i][j1][k + M], mul(j1 * j2, Dp[i - 1][j1 - 1][k - i - i + M]));
                if(k + i + i <= nn)
                    add_self(Dp[i][j1][k + M], Dp[i - 1][j1 + 1][k + i + i + M]);
            }
        }
    }

    cout << Dp[n][0][0 + M] << endl;
}


Measured memory_bytes: 64512
m = []
f = []
r = []

while True:
    item = list(map(int, input().split()))
    if item == [-1, -1, -1]:
        break
    m.append(item[0])
    f.append(item[1])
    r.append(item[2])

def grade(m, f, r):
    if m == -1 or f == -1:
        return("F")
    elif m+f >= 80:
        return("A")
    elif m+f >=65 and m+f <80:
        return("B")
    elif m+f >= 50 and m+f <65:
        return("C")
    elif m+f >= 30 and m+f <50:
        if r >= 50:
            return("C")
        else:
            return("D")
    else:
        return("F")

for i in range(len(m)):
    print(grade(m[i], f[i], r[i])) 


Measured memory_bytes: 5600
#include <iostream>
#include <algorithm>
using namespace std;
string a,b;
struct dd{
    short int x=0,y=0;
};
int f[3001][3001];
dd t[3001][3001],s[3001][3001];
void trace(short int x1,short int y1){
    short int xx=x1,yy=y1,r,c;
    string q="";
    while (xx!=0&&yy!=0){
        q=a[xx-1]+q; r=xx; c=yy;
        xx=t[r][c].x;
        yy=t[r][c].y;
    }
    cout<<q;
}
int main()
{
    cin>>a>>b;
    int w=0,px,py;
    for (unsigned int i=1;i<=a.size();++i){
        for (unsigned int j=1;j<=b.size();++j){
            if (a[i-1]==b[j-1]) {
                f[i][j]=f[i-1][j-1]+1;
                    t[i][j].x=s[i-1][j-1].x; t[i][j].y=s[i-1][j-1].y;
                    s[i][j].x=i; s[i][j].y=j;}
            else {
                if (f[i-1][j]>f[i][j-1]) {
                    f[i][j]=f[i-1][j];
                    t[i][j]=s[i-1][j];
                    s[i][j]=s[i-1][j];
                } else {
                    f[i][j]=f[i][j-1];
                    t[i][j]=s[i][j-1];
                    s[i][j]=s[i][j-1];
                }
            }
            if (w<f[i][j]) {
                w=f[i][j];
                px=i;
                py=j;
            }
        }
    }
    trace(px,py);
}


Measured memory_bytes: 105856
Scanf.(Array.(
  let n,x=scanf" %d %d"@@fun u v->u,v in
  let s,p=make 50 1,make 50 1 in
  init 49 (fun i->
    s.(i+1)<-2*s.(i)+3;
    p.(i+1)<-2*p.(i)+1) |> ignore;
  let rec f lv ofs =
    if lv=0 then (
      (* if ofs=1 then 1 else 0 *)
      assert (ofs=1); 1
    ) else let r=s.(lv-1) in
    if ofs=0 || ofs=1 then 0
    else if ofs<=1+r   then f (lv-1) (ofs-1)
    else if ofs =2+r   then 1 + p.(lv-1)
    else if ofs<=2+r+r then 1 + p.(lv-1) + f (lv-1) (ofs-2-r)
    else if ofs =3+r+r then 1 + 2 * p.(lv-1)
    else failwith ""
  in print_int @@ f n x
));;

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, a, n) for (int i = (n); i < (a); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int a,b;cin>>a>>b;
  cout<<max(max(a+b,a-b),a*b)<<endl;
}


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

using namespace std;
typedef long long ll;


int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k-1]=s[k-1]+32;
    cout << s << endl;
}


Measured memory_bytes: 256
# Studying https://atcoder.jp/contests/arc097/submissions/13758236

N,M,K = gets.split.map(&:to_i)

友達の輪と大きさ = [-1]*(N+1)
輪 = lambda{|a|
	next 友達の輪と大きさ[a]<0 ? a : 友達の輪と大きさ[a]=輪[友達の輪と大きさ[a]]
}
輪の大きさ = lambda{|a|
	next -友達の輪と大きさ[輪[a]]
}
友達です = lambda{|*ab|
	a,b = ab.map(&輪)
	next if a==b
	a,b = b,a if 友達の輪と大きさ[b]<友達の輪と大きさ[a]
	友達の輪と大きさ[a] += 友達の輪と大きさ[b]
	友達の輪と大きさ[b] = a
}

友達の数 = [0]*(N+1)

M.times{
	a,b = gets.split.map(&:to_i)
	友達です[a,b]
	友達の数[a] += 1
	友達の数[b] += 1
}

友達の輪の中の目障りなあいつ = [0]*(N+1)

K.times{
	a,b = gets.split.map(&:to_i)
	next if 輪[a]!=輪[b]
	友達の輪の中の目障りなあいつ[a] += 1
	友達の輪の中の目障りなあいつ[b] += 1
}

puts 1.upto(N).map{|n|
	輪の大きさ[n] - 1 - 友達の数[n] - 友達の輪の中の目障りなあいつ[n]
}


Measured memory_bytes: 17688
#include <stdio.h>
int main( void )
{
	int i=0,j,k,m,h[300],w[300];
	
	while(1){
		scanf("%d %d",&h[i],&w[i]);
		if(h[i]==0 && w[i]==0)
			break;
		i++;
	}
	
	for(k=0;k<i;k++){
		for(m=0;m<h[k];m++){
			for(j=0;j<w[k];j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2048
#include <iostream>
#include <map>
#include <cmath>

std::map<size_t, size_t>
get_prime_factors(size_t const N) {
  std::map<size_t, size_t> prime_factors;

  if (N<2) {
    prime_factors.insert(std::make_pair(N, 1));
    return prime_factors;
  }

  auto n = N;
  for (size_t p=2; p*p<=N; p++) {
    while (n % p == 0) {
      prime_factors[p]++;
      n /= p;
    }
  }

  if (n > 1) prime_factors[n]++;

  return prime_factors;
}
int main() {
  size_t N, P;
  std::cin >> N >> P;

  size_t ans = 1;

  for (auto const & p : get_prime_factors(P)) {
    auto n = std::get<1>(p);
    while (n >= N) {
      ans *= std::get<0>(p);
      n -= N;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


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

long n,a,b,c,q,k,x,y;
vector<vector<long>> aaa(100010);
vector<long> bbb(100010,-1);
vector<long> ans(100010);

void tansaku(long x,long y) {
  bbb[x-1]=y;
  for(long i=0;i<aaa[x-1].size();i++) {
    if(bbb[aaa[x-1][i]/10000000000-1]==-1) tansaku(aaa[x-1][i]/10000000000,y+aaa[x-1][i]%10000000000);
  }
}

int main() {
  cin >> n;
  for(long i=0;i<n-1;i++) {
    cin >> a >> b >> c;
    aaa[a-1].push_back(b*10000000000+c);
    aaa[b-1].push_back(a*10000000000+c);
  }
  cin >> q >> k;

  tansaku(k,0);
  for(long i=0;i<q;i++) {
    cin >> x >> y;
    ans[i]=bbb[x-1]+bbb[y-1];
  }

  for(long i=0;i<q;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh

int main(){
	dhoom;
	int n;
	cin >> n;
	int b[n + 1];
	int a[n + 1];
	
	for(int i = 1 ; i <= n ;i++)
	{	cin >> a[i];
		b[i] = a[i];
    }
    sort(b + 1 , b + n + 1);
   // int x = a[(n + 1)/2];
	map< int ,int > mp;
    for(int i = 1 ; i <= n ; i++){
		if(i <= (n/2)){
			mp[b[i]] = b[n/2 + 1];
		}
		else 
			mp[b[i]] = b[n/2];
	}
	for(int i = 1 ; i <= n ; i++)
		cout << mp[a[i]] << endl;
    return 0;
}


Measured memory_bytes: 14784
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define INF (1<<24)
int H,W,size,sy,sx,gy,gx,ans,ans2;
int t[10000],ty[10000],tx[10000];
int dp[(1<<5)][10000];
int calc(int y,int x,int y2,int x2){return abs(y-y2)+abs(x-x2);}
int rec(int S,int pos);
void init();
int main(){
  while(cin>>W>>H&&W&&H){
    init();
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	char ch;cin>>ch;
	if(ch=='S')sy=i,sx=j;
	else if(ch=='G')gy=i,gx=j;
	else if(ch!='.'){
	  t[size]=ch-'1';
	  ty[size]=i;
	  tx[size]=j;
	  size++;
	}
      }
    }
    for(int i=0;i<5;i++){
      for(int j=0;j<size;j++){
	if(t[j]!=(i+1)%5)continue;
	int S = (1<<i);
	S |= (1<<t[j]);
	int a=rec(S,j)+calc(sy,sx,ty[j],tx[j]);
	if(a<ans2)ans2=a,ans=i+1;
      }
    }
    if(ans2==INF)cout<<"NA"<<endl;
    else cout<<ans<<' '<<ans2<<endl;
  }
  return 0;
}

void init(){
  size=0;
  ans2=INF;
  for(int i=0;i<(1<<5);i++){
    for(int j=0;j<10000;j++){
      dp[i][j]=-1;
    }
  }
}

int rec(int S,int pos){

  //cout<<S<< ' ' <<pos<<endl;
  if(S==(1<<5)-1)return calc(gy,gx,ty[pos],tx[pos]);
  if(dp[S][pos]!=-1)return dp[S][pos];

  int res=INF;
  for(int i=0;i<size;i++){
    if((S>>t[i])&1)continue;
    int a=(t[i]+4)%5;
    if((S>>a)&1)res=min(res, rec(S|(1<<t[i]),i)+calc(ty[pos],tx[pos],ty[i],tx[i]));
  }
  return dp[S][pos]=res;
}

Measured memory_bytes: 2484
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int pre[100005];
int main()
{
   	int n , k;
  	cin >> n >> k;
  	string s;
  	cin >> s;
  	int cnt = 0;
  	for(int i = 0 ; i < s.size() - 1 ; i++){
      	pre[i] = cnt;
		if(s[i] == 'A' && s[i + 1] == 'C')
        {
			cnt++;
        }
      	pre[i + 1] = cnt;
    }
   /* for(int i = 0; i < s.size() ; i++)
    	cout << pre[i] << " ";*/
  	while(k--){
		int l , r;
      	cin >> l >> r;
      	cout << pre[r - 1] - pre[l - 1] << endl;
    }
	return 0;
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main() {

    int n, m;
    cin>>n>>m;
    int cnt[51]={0};
    rep(i,m){
        int a, b;
        cin>>a>>b;
        cnt[a]++;
        cnt[b]++;
    }
    for(int i=1; i<=n; i++)
        cout << cnt[i]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    long A, B;
    long ans = 0;
    cin >> A >> B;
    for(int i = 1; i <= 40; i++){
        long n = (long)1 << i;
        long a = A/n;
        long b = B/n;
        long k = A%n;
        long l = B%n;
        long m = (b-a-1)*(n/2) + (n-max(k, n/2)) + max((long)0, l-n/2+1);
        if(m%2 == 1) ans += n/2;
        //cout << (n-max(k, n/2)) << ' ' << (min(n/2-1, l)+1) << endl;
        //cout << n << ' ' << a << ' ' << b << ' ' << k << ' ' << l << endl;
        //cout << ans << endl;
    }
    cout << ans << endl;
}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int N;
	
	cin >> N;
	
	vector<int> a(N + 1);
	
	rep(i, N)
		cin >> a[i + 1];
	
	int ans = 0;
	vector<int> b(N + 1, 0);
	
	for(int i=N; i>0; i--){
		int count = 0;
		for(int j=i; j<=N; j+=i)
			count += b[j];
		if(count % 2 == a[i])
			b[i] = 0;
		else
			b[i] = 1;
		ans += b[i];
	}
	
	cout << ans << endl;
	
	rep(i, N)
		if(b[i + 1] == 1)
			cout << i + 1 << " ";
	
	return 0;
}

Measured memory_bytes: 2432
H1,M1,H2,M2,S = map(int,input().split())
if M2 >= M1:
    h = H2 - H1
    m = M2 - M1
else:
    m = M2 + 60 -M1
    h = H2 -1 - H1
print(max(h*60+m-S,0))

Measured memory_bytes: 9180
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i
num = 0
total = 0

for i in 0..a do
  for j in 0..b do
    for k in 0..c do
      total = 500*i + 100*j + 50*k
      num+=1 if total == x
    end
  end
end
print num

Measured memory_bytes: 1788
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        cans: [u64; 3],
    }
    let mut cans = cans;
    cans.sort();
    cans.dedup();
    println!("{}", cans.len());
}


Measured memory_bytes: 4352
import java.util.*;
class Main{
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		int a=s.nextInt();
		for(int i=0;i<a;i++){
			char[] b=new char[51];
			String str=s.next();
			int right=25;
			int left=25;
			int now=25;
			b[25]=str.charAt(0);
			for(int j=0;j<str.length()/3;j++){
				if(str.charAt(j*3+1)=='-'){
					now++;
					if(now>right){
						b[now]=str.charAt(j*3+3);
						right++;
					}
				}else{
					now--;
					if(now<left){
						b[now]=str.charAt(j*3+3);
						left--;
					}
				}
			}
			for(int j=left;j<=right;j++)System.out.print(b[j]);
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
object Main {
  def main(args: Array[String]): Unit = {
    solve2
  }

  def solve2(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val a = new Array[Int](n + 2) // 両端は0にする
    for (i <- 1 until n + 1) {
      a(i) = sc.nextInt()
    }

    var cost = 0
    for (i <- 1 until n + 2) {
      cost += math.abs(a(i) - a(i - 1))
    }
    val pw = new java.io.PrintWriter(System.out)
    for (i <- 1 until n + 1) {
      val tmp = cost - math.abs(a(i - 1) - a(i)) - math.abs(a(i) - a(i + 1)) + math.abs(a(i - 1) - a(i + 1))
      pw.println(tmp)
    }
    pw.flush()
  }


  // 以下は最初に出したややこしすぎるやり方。。
  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    var a = new Array[Int](n + 2)
    a(0) = 0
    a(n + 1) = 0
    for (i <- 1 until n + 1) {
      a(i) = sc.nextInt()
    }
    val accL = new Array[Int](n + 2)
    for (i <- 1 until n + 2) {
      accL(i) = accL(i - 1) + math.abs(a(i) - a(i - 1))
    }
    var accR = new Array[Int](n + 2)
    val reverseA = a.reverse
    for (i <- 1 until n + 2) {
      accR(i) = accR(i - 1) + math.abs(reverseA(i) - reverseA(i - 1))
    }
    accR = accR.reverse

    //indexやら、reverseやら全然整理がつかん。。
    val pw = new java.io.PrintWriter(System.out)
    for (i <- 1 until n + 1) {
      val cost = accL(i - 1) + math.abs(a(i - 1) - a(i + 1)) + accR(i + 1)
      pw.println(cost)

    }
    pw.flush()
  }


}


Measured memory_bytes: 55864
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1e6 + 7;
int n, q;
int len[N];
int mn[N << 2];
void build(int v, int tl, int tr) {
    if (tl == tr) {
        mn[v] = len[tl];
        return;                        
    }   
    int tm = (tl + tr) >> 1;
    build(v * 2 + 1, tl, tm);
    build(v * 2 + 2, tm + 1, tr);
    mn[v] = min(mn[v * 2 + 1], mn[v * 2 + 2]);
}   
int getr(int v, int tl, int tr, int i, int x) {
    if (tl > i || mn[v] > x)
        return -1;
    if (tl == tr)
        return tl;
    int tm = (tl + tr) >> 1;
    int t = getr(v * 2 + 2, tm + 1, tr, i, x);
    if (t != -1)
        return t;
    else
        return getr(v * 2 + 1, tl, tm, i, x);        
}   

struct Edge {
    int v, x, y, f;
};  

vector <Edge> g[N];
vector <ii> rg[N];
map <ii, int> num;
int ptr = 0;
ii state[N];

void add_edge(int u, int v, int x, int y, int f) {
    g[u].app({v, x, y, f});
    rg[v].app(mp(u, f));
}
void gen(int i, int pref) {
    if (pref == 0)
        return;
    if (num.find(mp(i, pref)) != num.end())
        return;

    state[ptr] = mp(i, pref);
    int u = num[mp(i, pref)] = ptr++;

    if (i == 0)
        return;

    int j = getr(0, 0, q, i - 1, pref);
    j = max(j, 0ll);
    gen(j, len[j]);
    gen(j, pref % len[j]);

    int v1 = num[mp(j, len[j])];
    add_edge(u, v1, pref, len[j], pref/len[j]);
    int v2 = num[mp(j, pref%len[j])];
    add_edge(u, v2, pref, pref%len[j], 1);
}   
int root;
int dp[N];
bool used[N];
void dfs(int u) {
    used[u] = 1;

    if (u == root) {
        dp[u] = 1;
        return;
    }   

    dp[u] = 0;
    for (auto e : rg[u]) {
        int v = e.f, k = e.s;
        if (!used[v]) {
            dfs(v);
        }   
        dp[u] += dp[v] * k;
    }   
}   
int ans[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n >> q;
    len[0] = n;
    for (int i = 1; i <= q; ++i)
        cin >> len[i];
    build(0, 0, q);
    gen(q, len[q]);
    root = num[mp(q, len[q])];
    for (int i = 0; i < ptr; ++i) {
        if (!used[i]) {
            dfs(i);
        }   
    }   
    for (int i = 0; i < ptr; ++i) {
        if (state[i].f == 0) {
            ans[state[i].s] += dp[i];
        }   
    }   
    for (int i = n; i; --i) {
        ans[i] += ans[i + 1];
    }   
    for (int i = 1; i <= n; ++i)
        cout << ans[i] << ' ';
    cout << endl;
    #ifdef HOME
    cerr << Time << endl;
    #endif
}

Measured memory_bytes: 165760
#include <stdio.h>

int main(void)
{
  int a[3] = {0};
  int i, j;
  int t;
  
  scanf("%d %d %d", &a[0], &a[1], &a[2]);

  for(i = 0; i < 3; i++)
    for(j = 2; j > 0; j--)
      if(a[j] < a[j - 1]){
	t = a[j];
	a[j] = a[j - 1];
	a[j - 1] = t;
      }

  printf("%d %d %d\n", a[0], a[1], a[2]);
	
  return 0;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

const ll INF = 1LL << 60;

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

int div_ct(int n) {
  int c = 0;
  int k;
  for ( k = 1; k <= n; k++ ) { 
    if ( n % k == 0 ) { c++; } 
  }
  return c;
}

int main() {
  string s;cin>>s;
  int n=s.size();
  if(s=="keyence"){cout<<"YES";return 0;}
  reps(i,n)rep(j,n){
    if(i>j)continue;

    string t=s.substr(0,i);
    string u=s.substr(j,n-j+1);
    if(t+u=="keyence"){cout<<"YES";return 0;}
  }
  cout<<"NO";
}


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

int main() {
  int N, Alice=0, Bob=0;
  cin >> N;
  
  vector<int> vec(N);
  
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  for(int i=0; i<N; i++){
    Alice += vec.at(i);
    
    if((i+1)<N){
      Bob += vec.at(i+1);
    }
    i++;
  }
  cout << Alice - Bob << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;

int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int a,b;
	cin>>a>>b;
	int ans=a*3+b;
	ans/=2;
	cout<<ans<<endl;




	return 0;
}


Measured memory_bytes: 256