akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) (((a%MOD+MOD)%MOD+(b%MOD+MOD)%MOD)%MOD)
#define MUL(a, b) ((((a%MOD+MOD)%MOD)*((b%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }
template<typename I> int ACC(I f, I l, int i){ return accumulate(f, l, i); }


string S;
int dp[100010][20];


signed main(){
	cin >> S;

	dp[0][0] = 1;
	rep(i, 0, SZ(S)){
		int x = (S[i] == '?' ? -1 : S[i]-'0');
		rep(j, 0, 13)
			if(x != -1) CHADD(dp[i+1][(j*10+x)%13], dp[i][j]);
			else
				repe(k, 0, 9) CHADD(dp[i+1][(j*10+k)%13], dp[i][j]);
	}

	cout << dp[SZ(S)][5] << endl;

	return 0;
}

Measured memory_bytes: 16128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
using namespace std;

int main() {
	string s;
	int count = 0;
	cin >> s;
	REP(i, s.size()) {
		if (i == 0) {
			continue;
		}
		else {
			if (s[i] == '0') {
				if (s[i-1] == '0') {
					count++;
					s[i] = '1';
				}
			}
			else {
				if (s[i - 1] == '1') {
					count++;
					s[i] = '0';
				}
			}
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 512
N, M = map(int, input().split())
H = list(map(int, input().split()))
Hnew=H
Hdel=list()
Hdel2=list()
AB=list()
for i in range(M):
    AB.append(list(map(int, input().split())))
    

for i in range(M):
    if H[AB[i][0]-1]==H[AB[i][1]-1]:
        Hdel.append(H[AB[i][0]-1])
        Hdel.append(H[AB[i][1]-1])
        Hdel2.append(AB[i][0])
        Hdel2.append(AB[i][1])
        
    elif H[AB[i][0]-1]>H[AB[i][1]-1]:
        Hdel.append(H[AB[i][1]-1])
        Hdel2.append(AB[i][1])
    else:
        Hdel.append(H[AB[i][0]-1])
        Hdel2.append(AB[i][0])

        
Hdel2=list(set(Hdel2))        
Hdel=list(set(Hdel))
print(len(H)-len(Hdel2))

Measured memory_bytes: 35848
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	string S;
	cin>>S;
	int N =S.size();
	int cnts = 0,cntt =0;
	rep(i,N){
		if(S[i]=='T'){
			if(cnts)cnts--;
			cntt++;
		}
		else {
			cnts++;
		}
	}
	cout<<cnts*2<<endl;
}

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


int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  priority_queue<double, vector<double>, greater<>> pq;
  int n; cin >> n;
  while (n--) {
    int a; cin >> a;
    pq.push(a);
  }
  while (pq.size() >= 2) {
    double a = pq.top(); pq.pop();
    double b = pq.top(); pq.pop();
    pq.push((a + b) / 2);
  }
  cout << fixed << setprecision(10) << pq.top() << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int H,W,N,a,b;
  string S,T;
  cin>>H>>W>>N>>a>>b>>S>>T;
  a--,b--;
  int mnx=0,mxx=H-1,mny=0,mxy=W-1;
  while(N--){
    if(T[N]=='L')mxy=min(mxy+1,W-1);
    else if(T[N]=='R')mny=max(mny-1,0LL);
    else if(T[N]=='U')mxx=min(mxx+1,H-1);
    else mnx=max(mnx-1,0LL);
    if(S[N]=='L')mny++;
    else if(S[N]=='R')mxy--;
    else if(S[N]=='U')mnx++;
    else mxx--;
    if(mny>mxy || mnx>mxx){
      puts("NO");
      return 0;
    }
  }
  puts(mnx<=a && a<=mxx && mny<=b && b<=mxy?"YES":"NO");
}

Measured memory_bytes: 3912
#include <bits/stdc++.h>
#define ri register int
using namespace std;
const int rlen = 1 << 20 | 5;
char buf[rlen], *ib = buf, *ob = buf;
#define gc() (((ib == ob) && (ob = (ib = buf) + fread(buf, 1, rlen, stdin))), ib == ob ? -1 : *ib++)
#define pb push_back
#define rez resize
#define ppp pop_back
inline int read() {
  static int ans;
  static char ch;
  for (ans = 0, ch = gc(); !isdigit(ch); ch = gc());
  while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc();
  return ans;
}
inline int Read(char *s) {
  static int top;
  static char ch;
  for (ch = gc(), top = 0; !isalpha(ch); ch = gc());
  while (isalpha(ch)) s[++top] = ch, ch = gc();
  return top;
}
typedef long long ll;
typedef pair <int, int> pii;
#define fi first
#define se second
inline ll readl() {
  static ll ans;
  static char ch;
  for (ans = 0, ch = gc(); !isdigit(ch); ch = gc());
  while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc();
  return ans;
}
const int N = 1e6 + 5;
int n, a[N], ps[N], nxt[N], cnt[N], rd[N];
ll K;
bool vs[N];
int main() {
  #ifdef ldxcaicai
  freopen("lx.in", "r", stdin);
  #endif
  n = read(), K = readl();
  for (ri i = 1; i <= n; ++i) {
    a[i] = read();
    if (ps[a[i]]) nxt[ps[a[i]]] = i;
    ps[a[i]] = i;
  }
  for (ri i = 1; i <= n; ++i) if (!nxt[ps[a[i]]]) nxt[ps[a[i]]] = i;
  int R = 1, p = 1;
  for (ri tt = 1; ; ++tt) {
    if (tt > 1 && p == 1) {
      K = K % R ? K % R : R;
      break;
    }
    rd[p] = R;
    if (nxt[p] <= p) ++R;
    p = nxt[p] < n ? nxt[p] + 1 : 1;
  }
  vector <int> res;
  for (ri i = n; i; --i) if (rd[i] == K) {
    int p = i;
    for (; p <= n; ++p) {
      if (!cnt[a[p]]) ++cnt[a[p]], res.pb(a[p]);
      else while (cnt[a[p]]) --cnt[res.back()], res.ppp();
    }
    for (ri i = 0; i < res.size(); ++i) cout << res[i] << ' ';
    return 0;
  }
  return 0;
}

Measured memory_bytes: 8976
#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;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

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

ll ans[10005];
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    for(int x=1;x<=100;x++){
        for(int y=1;y<=100;y++){
            for(int z=1;z<=100;z++){
                ll t = x*x + y*y + z*z + x*y + y*z + z*x;
                if(t <=10000)ans[t]++;
            }
        }
    }
    for(int i=1;i<=n;i++)cout << ans[i] << endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
int N;
vector<vector <int> > p;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
bool isFind = false;

void f(int i, int j, int cnt, int index) {

    if (isFind == true)
        return;
    if (i < 0 || j < 0)
        return;
    if (cnt == p[index][0]) {
        if (i == p[index][1] && j == p[index][2]) {
            isFind = true;
        }
        return;
    }

    int dist = (abs(i-p[index][1]) + abs(j-p[index][2]));
    int t = p[index][0] - cnt;
    if (dist > t)
        return;

    if (t % 2 != dist % 2)
        return;


    f(i+1, j, cnt+1, index);
    f(i, j+1, cnt+1, index);
    f(i-1, j, cnt+1, index);
    f(i, j-1, cnt+1, index);

}

int main() {
    ios::sync_with_stdio(false);
    cin >> N;

    for (int i = 0; i < N; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        p.push_back({a,b,c});
    }

    int x, y, time;
    x = y = time = 0;
    for (int i = 0; i < p.size(); i++) {
        isFind = false;
        int dist = (abs(x-p[i][1]) + abs(y-p[i][2]));
        int t = p[i][0] - time;
        if (dist <= t) {
            if (t % 2 == dist % 2)
                f(x, y, time, i);

            x = p[i][1];
            y = p[i][2];
            time = p[i][0];
        }
        else {
            cout << "No\n";
            return 0;
        }
        if (isFind == false) {
            cout << "No\n";
            return 0;
        }

    }
    cout <<"Yes\n";
    return 0;
}




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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(i, c) for (auto&& t : c)
#define ALL(c) begin(c), end(c)
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define fk first
#define sv second

const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

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

  int x, a, b;
  cin >> x >> a >> b;

  if (abs(x - a) < abs(x - b)) {
    cout << "A\n";
  } else {
    cout << "B\n";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define inf (int)(1e9)

int main(){
	int H, W, i, j, ans = 0;
	scanf("%d%d", &H, &W);
	vector<string> S(H);
	for(i = 0; i < H; i++){
		cin >> S[i];
	}
	int dx[4] = {0, 1, 0, -1};
	int dy[4] = {1, 0, -1, 0};
	for(i = 0; i < H; i++){
		for(j = 0; j < W; j++){
			if(S[i][j] == '#'){
				continue;
			}
			vector<vector<int>> dis(H, vector<int>(W, inf));
			queue<pair<pair<int, int>, int>> q;
			q.push(make_pair(make_pair(i, j), 0));
			while(q.size() > 0){
				int x = q.front().first.first;
				int y = q.front().first.second;
				int v = q.front().second;
				q.pop();
				if(x < 0 || H <= x || y < 0 || W <= y || S[x][y] == '#' || dis[x][y] <= v){
					continue;
				}
				dis[x][y] = v;
				ans = max(ans, v);
				for(int d = 0; d < 4; d++){
					q.push(make_pair(make_pair(x + dx[d], y + dy[d]), v + 1));
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


int main(){
    int n, x, t;
    cin >> n >> x >> t;
    int rem = n%x;
    int q = n/x;
    
    int total = q*t;
    if(rem != 0){
        total += t;
    }
    
    cout << total << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	--n;
	int a[n];
	for(int i=0;i<n;++i)
		cin>>a[i];
	int sum=a[0]+a[n-1];
	for(int i=1;i<n;++i)
		sum+=min(a[i-1],a[i]);
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using ld = long double;

int N;
vector<vector<int>> edges;
vector<map<int, ld>> vmp;

ld dfs(int from, int now) {
	if (from != -1 && vmp[from].find(now) != vmp[from].end()) {
		return vmp[from][now];
	}
	if (edges[now].size() == 1 && edges[now].front() == from) {
		return vmp[from][now] = 1;
	}
	ld res = 0;
	for (int next : edges[now])if (next != from) {
		res += dfs(now, next);
	}
	res /= (edges[now].size() - 1);
	if (from == -1)return res;
	else return vmp[from][now] = res + 1;
}
void dfs2(int from, int now) {
	if (from != -1) {
		vmp[now][from] = 1 + (
			edges[from].size() == 1
			? 0
			: ((vmp[from][from] - vmp[from][now]) / (edges[from].size() - 1))
			);
	}
	ld res = 0;
	for (auto itr : vmp[now])res += itr.second;
	vmp[now][now] = res;
	for (int next : edges[now])if (next != from)dfs2(now, next);
}

int main()
{
	cin >> N;
	edges.resize(N);
	vmp.resize(N);
	rep(i, N - 1) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}
	dfs(-1, 0);
	dfs2(-1, 0);
	rep(i, N) {
		cout << fixed << setprecision(15) << vmp[i][i] / edges[i].size() << endl;
	}

	return 0;
}


Measured memory_bytes: 62592
n,k=map(int,input().split())
a=list(map(int,input().split()))
data=[0]*(n+1)
data[1]=1
ans=[1]
res=0
for i in range(n):
  p=a[res]
  if data[p]==0:
    data[p]=1
    ans.append(p)
    res=p-1
  else:
    res=ans.index(p)
    break
if len(ans)>k:
  print(ans[k])
else:
  m=len(ans)-res
  k-=res
  d=k%m
  print(ans[res+d])

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

int main() {
 int a, b,c,d,e;
 cin >> a >> b;
  int sum,minus,multi;

  sum = a+b;
  minus = a-b;
  multi = a*b;
  
  c = max(sum,minus);
  d = max(c,multi);
 cout << d << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> as;
    int a;
    long long int sum, ans, sunuke, arai;
    for (int i = 0; i < N; i++) {
        cin >> a;
        as.push_back(a);
    }
    sum = accumulate(as.begin(), as.end(), 0l);

    sunuke = as[0];
    arai = sum - as[0];

    ans = abs(sunuke - arai);
    for (int i = 1; i < N - 1; i++) {
        sunuke += as[i];
        arai -= as[i];
        ans = min(ans, abs(sunuke - arai));
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<queue>
using namespace std;

const int INF=0x3f3f3f3f;
int h,w,n;//
typedef pair<int,int> P;
queue <P> q;
char g[1002][1002];
int x,y;//起点的横纵坐标
int nx,ny;//下一个点
int d[1002][1002];
int _x[4]={-1,0,0,1},_y[4]={0,-1,1,0};
bool is_legal(int x,int y)//格子是否越界
{
	if(x>=1&&x<=h&&y>=1&&y<=w) return true;
	else return false;
		
}
//队列初始要有起点
//从起点出发，目的地：power的奶酪
//power奶酪的最小步数
int bfs(int power)
{
	while(!q.empty()) q.pop();
	q.push(P(x,y));
	for(int i=1;i<=h;i++)
			for(int j=1;j<=w;j++)
			{
				d[i][j]=INF;
			}
	d[x][y]=0;
	while(!q.empty())
	{
		P p=q.front();
		q.pop();
		int row=p.first;
		int column=p.second;
		
		for(int i=0;i<4;i++)
		{
			nx=row+_x[i];
			ny=column+_y[i];
			if(!is_legal(nx,ny)) continue;
			
			//d[nx][ny]=d[row][column]+1;障碍物或越界，d数组不变
			if(g[nx][ny]=='0'+power) 
			{
				d[nx][ny]=d[row][column]+1;
				//下一次bfs的起点
				x=nx;
				y=ny;
				return d[nx][ny];
			}
			if(g[nx][ny]!='X') 
			{
				
				if(d[row][column]+1<d[nx][ny])
				{
					d[nx][ny]=d[row][column]+1;
				q.push(P(nx,ny));
				}
				
			}
		}
	}
	return INF;
}

int main()
{
	while(scanf("%d %d %d",&h,&w,&n)!=EOF)
	{
		for(int i=1;i<=h;i++)
			for(int j=1;j<=w;j++)
			{
				cin>>g[i][j];
				if(g[i][j]=='S') {x=i;y=j;}
			}
		
		int ans=0;
		
		
		//1～n奶酪的最小步数之和
		
		for(int k=1;k<=n;k++) {
			ans+=bfs(k);
		}
		
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 8028
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

int main()
{
	int N;
	std::vector<std::string> S;

	std::cin >> N;
	S.resize(N);
	for (auto& s : S) {
		std::cin >> s;
		std::sort(s.begin(), s.end());
	}

	std::unordered_map<std::string, long> M;
	for (const auto& s : S) {
		++M[s];
	}

	long result = 0;
	for (const auto& m : M) {
		result += m.second * (m.second-1) / 2;
	}
	std::cout << result << "\n";
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	string s,t;cin>>s>>t;
	string S=s+s;
	map<char,vector<int>>mp;
	rep(i,S.size()){
		mp[S[i]].push_back(i);
	}
	int cur=0;
	ll ans=0;
	rep(i,t.size()){
		char c=t[i];
		vector<int>&v=mp[c];
		auto it=lower_bound(v.begin(),v.end(),cur);
		if(it==v.end()){
			puts("-1");return 0;
		}
		else{
			ans+=*it-cur+1;
			cur=*it+1;
			cur%=s.size();
		}
	}
	cout<<ans<<endl;
}

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

int main(){
    int n;
    cin >> n;
    int l[n];
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    sort(l,l+n);
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k < n; k++){
                if(l[i] >= l[j] + l[k]) continue;
                if(l[j] >= l[i] + l[k]) continue;
                if(l[k] >= l[i] + l[j]) continue;
                ans++;
            }   
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll a,b,c; cin >> a >> b >> c;
    if(a==b && b==c) {
        if(a % 2 == 0) cout << -1 << endl;
        else cout << 0 << endl;
    }
    else{
        ll cnt = 0;
        while(a%2==0 && b%2==0 && c%2==0){
            ll tmp = a/2 + c/2;
            ll tmp2 = a/2 + b/2;
            a = b/2 + c/2;
            b = tmp;
            c = tmp2;
            cnt++;
            //cout << a << " " << b << " " << c << endl;
        }
        cout << cnt << endl;
    }
}

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

long long int gcd(long long int a, long long int b) {
  long long int v0 = a, v1 = b, v2 = a % b;
  while (v2 != 0) {
    v0 = v1;
    v1 = v2;
    v2 = v0 % v1;
  };
  return v1;
}

long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
}

int main(){
  long long int n,m,i,ima,a,ichi=1,zero=0;
  cin>>n>>m;
  long long int b[n];
  cin>>ima;
  ima/=2;
  b[0]=ima;
  for(i=1;i<n;i++){
    cin>>a;
    a/=2;
    b[i]=a;
    ima=lcm(ima,a);
    if(ima>1000000000){
      cout<<0;
      return 0;
    }
  }
  for(i=0;i<n;i++){
    if((ima/b[i])%2==0){
      cout<<0;
      return 0;
    }
  }
  if(m<ima){
    cout<<0;
  }else{
    cout<<max(zero,(m-ima)/(2*ima)+ichi);
  }
}


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

#define LL long long

const LL INF = 1e18;

int T;
LL N, A, B, C, D;

map<LL, LL> f;

inline LL dfs(LL x)
{
	if(f.count(x)) return f[x];
	LL res;
	if(1.0 * x * D < (double)INF) res = x * D;
	else res = INF;
	res = min(res, dfs(x / 2) + A + (x % 2) * D);
	if(x % 2) res = min(res, dfs(x / 2 + 1) + A + (2 - x % 2) * D);
	res = min(res, dfs(x / 3) + B + (x % 3) * D);
	if(x % 3) res = min(res, dfs(x / 3 + 1) + B + (3 - x % 3) * D);
	res = min(res, dfs(x / 5) + C + (x % 5) * D);
	if(x % 5) res = min(res, dfs(x / 5 + 1) + C + (5 - x % 5) * D);
	return f[x] = res;
}

int main()
{
	scanf("%d", &T);
	while(T --)
	{
		scanf("%lld %lld %lld %lld %lld", &N, &A, &B, &C, &D);
		f.clear();
		f[0] = 0; f[1] = D;
		printf("%lld\n", dfs(N));
	}
	return 0;
}


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

signed main(void)
{
	long long l, r;
	long long ans;
	cin >> l >> r;

	ans = (long long)1e9;
	r = min(r, l + 4038);
	for(long long i = l; i < r; i++)
		for(long long j = i + 1; j <= r; j++)
		{
			ans = min(ans, i * j % 2019);
		}
	cout << ans  << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    string s;
    while(cin >> s, s != "#"){
        int y, m, d;
        cin >> y >> m >> d;
        if(y > 31 || (y == 31 && m >= 5)){
            printf("? %d %d %d\n", y-30, m, d);
        }else {
            printf("HEISEI %d %d %d\n", y, m, d);
        }
    }
    return 0;
}



Measured memory_bytes: 3180
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

ll mod = 1000000007;

int main(int argc, char const *argv[])
{

    ll n;
    cin >> n;

    if (n == 1)
    {
        cout << 0 << endl;
        exit(0);
    }

    if (n == 2)
    {
        cout << 2 << endl;
        exit(0);
    }

    ll zentai = 1;
    for (ll i = 0; i < n; i++)
    {
        zentai *= 10;
        zentai %= mod;
    }

    ll both = 1;

    for (ll i = 0; i < n; i++)
    {
        both *= 8;
        both %= mod;
    }

    ll no_zero = 1;

    for (ll i = 0; i < n; i++)
    {
        no_zero *= 9;
        no_zero %= mod;
    }

    zentai -= no_zero;
    zentai %= mod;
    if (zentai < 0)
    {
        zentai += mod;
    }
    zentai -= no_zero;
    zentai %= mod;

    if (zentai < 0)
    {
        zentai += mod;
    }
    zentai += both;
    zentai %= mod;
    cout << zentai << endl;
}


Measured memory_bytes: 3628
fh = int(input())
oh = int(input())
ft = int(input())
om = int(input())
count = 0

for i in range(fh + 1):
    for j in range(oh + 1):
        for k in range(ft + 1):
            nm = 0
            nm = i * 500 + j * 100 + k * 50
            if om == nm:
                count +=1

print(count)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
	for(int n;cin>>n && n;){
		int a[100];
		for(int i=0;i<n;i++)
			cin>>a[i];
		long long dp[100][21]={};
		dp[0][a[0]]=1;
		for(int i=1;i<n-1;i++)
			for(int j=0;j<=20;j++){
				if(j+a[i]<=20)
					dp[i][j+a[i]]+=dp[i-1][j];
				if(j-a[i]>=0)
					dp[i][j-a[i]]+=dp[i-1][j];
			}
		cout<<dp[n-2][a[n-1]]<<endl;
	}
	
	return 0;
}

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

int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    if(a[0]%2 == a[1]%2 && a[1]%2 == a[2]%2){
        cout << (2*a[2] - a[0] - a[1])/2;
    }else if(a[0]%2 != a[2]%2 && a[1]%2 != a[2]%2){
        cout << (a[2]-a[1])/2 + (a[2]-a[0])/2 + 1;
    }else{
        cout << (a[2]-a[1])/2 + (a[2]-a[0])/2 + 2;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int a[maxn],b[maxn];

int main()
{
	int n=read(),m=read(),k=read(),m1=inf,m2=inf;
	for(int i=1;i<=n;i++) a[i]=read(),m2=min(a[i],m2);
	for(int i=1;i<=m;i++) b[i]=read(),m1=min(b[i],m1);
	int ans=m1+m2;
	while(k--)
	{
		int x=read(),y=read(),z=read();
		ans=min(ans,a[x]+b[y]-z);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4736
def put_era(day):
  if day < [1868, 9, 8]:
    print("pre-meiji")
  
  elif day <= [1912, 7, 29]:
    print(*["meiji",day[0] - 1868 + 1, day[1], day[2]])
  
  elif day <= [1926, 12, 24]:
    print(*["taisho",day[0] - 1912 + 1, day[1], day[2]])
  
  elif day <= [1989, 1, 7]:
    print(*["showa",day[0] - 1926 + 1, day[1], day[2]])
  
  else:
    print(*["heisei",day[0] - 1989 + 1, day[1], day[2]])

while True:
  try:
    day = list(map(int, input().split()))
    put_era(day)

  except EOFError:
    break


Measured memory_bytes: 5600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_3_B_Queue
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var N = int.Parse(input[0]);
            var q = int.Parse(input[1]);

            var name = new List<List<string>>();
            for (int i = 0; i < N; i++)
            {
                name.Add(new List<string>());
                for (int j = 0; j < 2; j++)
                {
                    name[i].Add("0");
                }
                var input2 = Console.ReadLine().Split(' ');
                for (int j = 0; j < 2; j++)
                {
                    name[i][j] = input2[j];
                }
            }

            var judge = true;
            var outCount = 0;
            var totalTime = 0;
            while (judge)
            {
                for (int i = 0; i < name.Count; i++)
                {
                    //if (name[i][1] == "0")
                    //{
                    //    continue;
                    //}
                    var needQueue = int.Parse(name[i][1]);
                    int useTime = needQueue <= q ? needQueue : q;
                    totalTime += useTime;
                    needQueue -= useTime;
                    name[i][1] = needQueue.ToString();
                    if (int.Parse(name[i][1]) <= 0)
                    {
                        Console.WriteLine(name[i][0] + " " + totalTime);
                        outCount++;
                        name.RemoveAt(i);
                        i--;
                    }
                }
                if (outCount >= N)
                {
                    judge = false;
                }
            }
        }
    }
}



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

Measured memory_bytes: 636
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <string>
#include <sstream>

using namespace std;

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

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

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

  int A, B;
  cin >> A >> B;

  if (A >= 13) {
    cout << B << endl;
  } else if (A >= 6) {
    cout << B / 2 << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static Scanner sc;
	
	public static void main(String[] args) {
		//System.out.println("Please input H and W below");
		//宣言
		sc = new Scanner(System.in);
		int H[]= new int[300];
		int W[]= new int[300];
		int i=1;
		int j=1,k=1;
		//入力
		for(;;) {
			H[i]=sc.nextInt();
			W[i]=sc.nextInt();
			if(H[i]==0 && W[i]==0) {
				break;
			}
			i++;
		}
		i=1;
		//出力
		for(;;){
			if(H[i]==0 && W[i]==0) {
				break;
			}
			for(j=1;j<=H[i];j++) {
				if(j==1 ||j==H[i]) {//上辺と下辺
					for(k=1;k<=W[i];k++) {
						System.out.print("#");
					}
					System.out.print("\n");
				}else{//それ以外
					for(k=1;k<=W[i];k++) {
						if(k==1 ||k==W[i]) {
							System.out.print("#");
						}else {
							System.out.print(".");
						}
					}
					System.out.print("\n");
				}
			}
			System.out.print("\n");
			i++;
		}
	}
}



Measured memory_bytes: 37448
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################

ans = 0
s = input()
t = input()
for i in range(len(s)):
	if s[i] != t[i]:
		ans+=1
print(ans)









Measured memory_bytes: 9672
#include <iostream>
#include <cstring>
#include <cmath> 
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;   
int main()  
{ 
    string s;
    cin>>s;
    string t;
    for(int i=0;i<s.size();i+=2)t+=s[i];
    cout<<t<<endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 760
#include<stdio.h>
  #define NUMBER 10000
  int main(void){
      int i,temp,c=0,x[NUMBER],y[NUMBER];
      for(i=0;1;i++){
         scanf("%d %d",&x[i],&y[i]);
         if(x[i]==0&&y[i]==0)
           break;
         c++;
      }
      for(i=0;i<c;i++){
         if(x[i]>y[i]){
           temp=x[i];
           x[i]=y[i];
           y[i]=temp;
         }
         printf("%d %d\n",x[i],y[i]);
      }
      return 0;
  }


Measured memory_bytes: 1928
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <cmath>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    ll n; cin >> n;
    vector<ll> c;
    for (int i = 0; i < n; i++) {
        ll _c; cin >> _c;
        c.push_back(_c);
    }
    sort(c.begin(), c.end());
    ll a = c[n - 1];
    ll sum = 0;
    for (int i = 0; i < n - 1; i++) {
        sum += c[i];
    }
    if (sum > a) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

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

int main(){
  int A,B,C;
  cin >> A >> B >> C;

  int ans= (A>=B && A>=C) ? 10*A +B +C
          :(B>=A && B>=C) ? 10*B +C +A
                          : 10*C +A +B;

  cout << ans << endl;
}

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

int main()
{
	string str;
	int count=0;
	cin >> str;
	int j = str.length() - 1;
	for(int i=0; i<str.length(); i++)
	{
		
		if(i > j ) break;
		if(str[i] != str[j])
			{
				//cout << "i and j are: " << i << " " << j << "\n";
				//cout << str[i] << " " << str[j] << "\n";
				count++;
			}
		j--;
	}
	cout << count;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]

from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

m = 1
for a in A:
    m = lcm(m, a)

m -= 1

ans = 0
for a in A:
    ans += m % a

print(ans)

Measured memory_bytes: 5172
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

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

    ll ans = (n - 1) * n / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<ll> a(N+1, 0), ans(N+1, 0), ninc;
	vector<int> inc{0};
	ll now=0;
	for(int i=1; i<=N; ++i){
	    cin >> a[i];
	    if(now<a[i]){
	        inc.push_back(i);
	        now=a[i];
	    }
	    else{
	        ninc.push_back(a[i]);
	    }
	}
	for(int i=1; i<inc.size(); ++i){
	    ans[inc[i]]=(a[inc[i]]-a[inc[i-1]])*(inc.size()-i);
	}
	sort(ninc.begin(), ninc.end());
	int ninc_now=0, inc_now=1;
	while(ninc_now<ninc.size()){
	    if(a[inc[inc_now]]<ninc[ninc_now]){
	        ans[inc[inc_now]] += (a[inc[inc_now]]-a[inc[inc_now-1]])*(ninc.size()-ninc_now);
	        ++inc_now;
	    }
	    else{
	        ans[inc[inc_now]] += ninc[ninc_now]-a[inc[inc_now-1]];
	        ++ninc_now;
	    }
	}
	for(int i=1; i<=N; ++i) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 3320
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
geta = lambda fn: map(fn, readline().split())
gete = lambda fn: fn(readline())

# sys.setrecursionlimit(10**5)

def main():
    a, b = geta(int)
    s = a + b
    if s & 1 == 0:
        print(s//2)
    else:
        print("IMPOSSIBLE")
    
	
if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>      
using namespace std;
const int N = 2e5 + 100;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ull unsigned long long
#define ll long long
#define pii pair <int,int>
#define forn(l,i,n) for(int i = l;i <= n;++i)   
#define FOR(l,i,n) for(int i = l;i < n;++i)
#define all(v) v.begin(), v.end()
#define pll pair <ll,ll>
const ll inf = 1e9 + 7;
const ll ll_inf = 1e17 + 100;   
const double pi = 3.14159265358979323;
inline void fr(){
    freopen("gcd.in", "r", stdin);
    freopen("gcd.out", "w", stdout);
}
void boost()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
 
ll binpow (ll a, ll n)
{
    ll res = 1;
    while (n) {
        if (n & 1)
        {
            res *= a;
            res %= inf;
        }
        a *= a;
        n >>= 1;
        a %= inf;
    }
    return res;
}
        
int n;
int h[N];
int dp[N];
 
main()	
{                                                                        
	cin >> n;
	dp[0] = inf;
	for (int i = 1;i <= n;++i)
	{
	  	cin >> h[i];
	}
	for (int i = 2;i <= n;++i)
	{
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]),dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n];
}	 


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

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

  if(s.at(5)=='0' && s.at(6)<'5')
  {
    cout<<"Heisei"<<endl;
  }
  else
  {
     cout<<"TBD"<<endl;
  }
}


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

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

int main(){
  int n, k;
  cin >> n >> k;
  int ans = (n-1)/(k-1);
  if((n-1)%(k-1) != 0) ans++;
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
//YESNO

using namespace std;



signed main()
{
	int X;
	cin >> X;
	
	int a = X / 500;
	int b = (X % 500) / 5;

	cout << a * 1000 + b * 5 << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define MX 3000
#define PB push_back
ll MOD = 1e9 + 7;
using namespace std;
ll dp[MX + 5][MX + 5];
ll cum[MX + 3];
int arr[MX + 1];
int main() {
	int n, k;
	cin >> n;
	for(int i = 1; i <= n; ++i)
		cin >> arr[i], cum[i] = arr[i] + cum[i - 1];
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n - i + 1; ++j) {
			dp[i][j] = max(arr[j] + cum[i + j - 1] - cum[j] - dp[i - 1][j + 1], arr[i + j - 1] + cum[i + j - 2] - cum[j - 1] - dp[i - 1][j]);
			//cout << dp[i][j] << " ";
		}
		//cout << endl;
	}
	cout << 2 * dp[n][1] - cum[n] << endl;
}

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

#define int long long

int A[301][301];

signed main() {
    int n;
    cin >> n;
    for(int i=1; i<=n; ++i) {
        for(int j=1; j<=n; ++j) {
            cin >> A[i][j];
        }
    }
    for(int i=1; i<=n; ++i) {
        for(int j=1; j<=n; ++j) {
            for(int k=1; k<=n; ++k) {
                if(k!=i&&k!=j) {
                    if(A[i][k]+A[k][j]<A[i][j]) {
                        cout << -1 << endl;
                        return 0;
                    }
                }
            }
        }
    }
    int ans = 0;
    for(int i=1; i<=n; ++i) {
        for(int j=1; j<=n; ++j) {
            bool p = true;
            for(int k=1; k<=n; ++k) {
                if(k!=i && k!=j) {
                    if(A[i][k]+A[k][j]==A[i][j]) p = false;
                }
            }
            if(p) ans += A[i][j];
        }
    }
    cout << ans/2 << endl;
    return 0;
}



Measured memory_bytes: 896
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
inline int read()
{
	register int c=getchar(),f=1,k=0;
	while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
	return k*f;
}
const int maxn=2*(1e5)+100;
char s[maxn];
unsigned int sum[maxn],f[maxn],g[1<<26];
int n;
inline int min(int a,int b)
{
	return a<b?a:b;
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	memset(f,32,sizeof(f));
	memset(g,32,sizeof(g));
	g[0]=0;
	for (register int i=1;i<=n;i++)sum[i]=sum[i-1]^(1<<(s[i]-'a'));
	for (register int i=1;i<=n;i++)
	{
		f[i]=min(f[i],g[sum[i]]+1);
		for (register int j=0;j<26;j++)f[i]=min(f[i],g[sum[i]^(1<<j)]+1);
		g[sum[i]]=min(g[sum[i]],f[i]);
	}
	printf("%d\n",f[n]);
} 


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

int main() {
    int n, j, cnt=0;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    vector<bool> dp(1000007, true);
    vector<bool> np(1000007, false);
    rep(i,n){
        j=2;
        if(dp[a[i]]){
            while(1){
                if(a[i]*j>1000007) break;
                dp[a[i]*j]=false;
                ++j;
            }
            if(np[a[i]]) dp[a[i]]=false;
            np[a[i]]=true;
        }
    }
    rep(i,n){
        if(dp[a[i]]) ++cnt;
    }
    cout << cnt << "\n";
    return 0;
}

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

using namespace std;

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

  int aux;
  int maior = 0;
  int cont = 0;

  while(n--) {
    cin >> aux;
    if(aux >= maior) cont++;
    maior = max(maior, aux);
  }

  cout << cont << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

char c[55][55];
int H, W, cnt;

int main() {
  cin >> H >> W;
  for (int i=1; i <= H; i++) {
    for (int j=1; j <= W; j++) cin >> c[i][j];
  }
  for (int i=1; i <= H; i++) {
    for (int j=1; j <= W; j++) {
      if(c[i][j] == '#' && c[i][j-1] != '#' && c[i-1][j] != '#' && c[i][j+1] != '#' && c[i+1][j] != '#') cnt++;
    }
  }
  if(cnt == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
first = input()
record = list()
record.append(first)

for i in range(n-1):
    next_word = input()
    if first[-1] != next_word[0] or next_word  in record:
        print("No")
        break
    record.append(next_word)
    first = next_word
else:
    print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;


int main() {
    ios_base::sync_with_stdio(false);

    while (1) {
        int n;
        cin >> n;
        if (n==0) break;
        vector<int> a(n);
        rep(i,n) cin >> a[i];
        vector<vector<int>> dp(n,vector<int>(n));
        repr(i,1,n) {
            invrep(j,i) {
                if (dp[j+1][i-1]==(i-1)-(j+1)+1 && abs(a[j]-a[i])<=1) dp[j][i]=i-j+1;
                repr(k,j,i) {
                    dp[j][i]=max(dp[j][i],dp[j][k]+dp[k+1][i]);
                }
            }
        }
        cout << dp[0][n-1] << endl;
    }
    

    return 0;   
}



Measured memory_bytes: 3252
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    if (N % digitSum(N) == 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }

  public static int digitSum(int number) {
    int sum = 0;
    while (number > 0) {
      sum += (number % 10);
      number /= 10;
    }
    return sum;
  }
}

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

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

using namespace std;

int main() {
  while(1) {
    int w,h;
    cin>>w>>h;
    if(!w)break;
    vector<string> t(h);
    REP(i,h)cin>>t[i];
    vector<vector<string>> dp(h,vector<string>(w));
    string mx = "0";
    REP(i,h)REP(j,w) {
      if (t[i][j] > '9') continue;
      if (i>0 && j>0) {
        if (dp[i-1][j].size() > dp[i][j-1].size() || (dp[i-1][j].size() == dp[i][j-1].size() && dp[i-1][j] > dp[i][j-1])) {
          dp[i][j] = dp[i-1][j] + t[i][j];
        } else {
          dp[i][j] = dp[i][j-1] + t[i][j];
        }
      } else if (i>0) {
        dp[i][j] = dp[i-1][j] + t[i][j];
      } else if (j>0) {
        dp[i][j] = dp[i][j-1] + t[i][j];
      } else {
        dp[i][j] = t[i][j];
      }
      if (dp[i][j].size() > 1 && dp[i][j][0] == '0') dp[i][j] = dp[i][j].substr(1);
      if (dp[i][j].size() > mx.size() || (dp[i][j].size() == mx.size() && dp[i][j] > mx)) {
        mx = dp[i][j];
      }
    }
    cout<<mx<<endl;
  }
  return 0;
}

Measured memory_bytes: 1376
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
    char a[10000],i,l,t;
    scanf("%s",&a);
    l=strlen(a);
    t=1;
    for(i=0;i<=l-1;i++)
    {
    	if(t==1)
    	{
    		if(a[i]=='C')
    		{
    			t++;
			}
		}
		if(t==2)
		{
			if(a[i]=='F')
			{
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
	return 0;
} 

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 200010
const int MOD = 998244353;

int pw(int a, int b, int m = MOD) {
    if (b == 0)return 1;
    if (b & 1)return a * pw(a, b - 1) % m;
    return pw(a * a % m, b / 2);
}

int inverse(int a) {
    return pw(a, MOD - 2);
}

int fact[maxn], inv[maxn];

void preprocess(int lmt) {
    fact[0] = 1;
    for (int i = 1; i <= lmt; i++)fact[i] = (fact[i - 1] * i) % MOD;
    inv[lmt] = inverse(fact[lmt]);
    for (int i = lmt - 1; i >= 0; i--)inv[i] = (i + 1) * inv[i + 1] % MOD;
}


int C(int n, int r) {
    if (r > n)return 0;
    return fact[n] * inverse(fact[r] * fact[n - r] % MOD) % MOD;
}

void solve() {
    preprocess(maxn - 1);
    int n, m, k;
    cin >> n >> m >> k;

    int ans = 0;
    for (int i = 0; i <= k; i++) {
        int cur = m * pw(m - 1, n - 1 - i);
        cur %= MOD;
        cur *= C(n - 1, i);
        cur %= MOD;
        ans += cur;
        ans %= MOD;
    }
    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 6792
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
int main()
{
    Hello
    int n, m, ans = 0;
    cin >> n >> m;
    int arr[n + 5];
    vector<set<int>>v;
    set<int> :: iterator it;
    v.resize(n + 5);
    for(int i = 1; i <= n; i++)
        cin >> arr[i];
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        v[a].insert(arr[b]);
        v[b].insert(arr[a]);
    }
    /*for(int i = 1; i <= n; i++){
        cout << "new " << i << endl;
        for(auto j : v[i])
            cout << j << " ";
        cout << endl;
    }*/
    for(int i = 1; i <= n; i++){
        if(v[i].size() == 0)
            ans++;
        else{
            it = v[i].end();
            it--;
            if(arr[i] > *it)
                ans ++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 17684
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define N 1000000
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
pii a[N]; int b[N],s[N];
const double QAQ=4.292036732051033807686783083602,gg=11.415926535897932384626433832795;
int main()
{	int x1,y1,x2,y2,x,y,n,g=1,ans=0,tot=0; cin>>x1>>y1>>x2>>y2>>n;
	if(x1>x2) swap(x1,x2),swap(y1,y2);
	if(y1>y2) y1=-y1,y2=-y2,g=-1;
	for(rint i=1;i<=n;i++)
	{	scanf("%d%d",&x,&y); y*=g;
		if(x1<=x&&x<=x2&&y1<=y&&y<=y2) a[++tot]=mp(x,y),b[tot]=y;
	}
	sort(a+1,a+tot+1); sort(b+1,b+tot+1); int len=unique(b+1,b+tot+1)-b-1;
	for(rint i=1;i<=tot;i++)
	a[i].second=lower_bound(b+1,b+len+1,a[i].second)-b-1,s[i]=1e9;
	for(rint i=1,cur;i<=tot;i++)
	{	ans=max(ans,cur=upper_bound(s+1,s+tot+1,a[i].second)-s);
		s[cur]=min(s[cur],a[i].second);
	}
	printf("%.12lf",100.0*(x2-x1+y2-y1)-ans*QAQ+((y2-y1+1==ans||x2-x1+1==ans)?QAQ+gg:0));
	return 0;
}


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

 
int main()
{
   int n;
   scanf("%d",&n);
   int x[n],y[n];
   
   double ans=0;
   int i,j;
   for(i=0;i<n;++i)
       scanf("%d%d",&x[i],&y[i]);
       
       
   for(i=0;i<n;++i)
     {
         for(j=0;j<n;++j)
           {
               if(i!=j)
                 {
                     ans+=sqrt(pow((x[i]-x[j]),2)+pow((y[i]-y[j]),2));
                 }
           }
           
           
     }
     

     int fact=1,fact1=1;
     for(i=1;i<=n;++i)
         fact*=i;
         
        fact1=fact/n; 
        
     printf("%0.10lf",fact1*ans/fact);    
  
}

Measured memory_bytes: 384
def get_gcd(a, b):
    if a < b:
        a, b = b, a
    r = -1
    while r:
        r = a % b
        a = b
        b = r
    return a

a, b = map(int, input().split())
g = get_gcd(a, b)
ans = int(a * b / g)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
 
ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
ld id(){ ld x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

ll mod=1000000007;
string t[6];
ll cx[6];
ll cy[6];
ll H, W, K;

ll fn(ll p){
    ll r=0;
    if(p<W){
        cx[p]=true;
        r+=fn(p+1);
        cx[p]=false;
        r+=fn(p+1);
        return r;
    }
    if(p<W+H){
        cy[p-W]=true;
        r+=fn(p+1);
        cy[p-W]=false;
        r+=fn(p+1);
        return r;
    }
   REP(h,0,H){
        REP(w,0,W){
            if(t[h][w]=='#' && !cx[w] && !cy[h]){
                r++;
            }
        }
    }
    return (r==K);
}

int main(){
    H=ii();
    W=ii();
    K=ii();
    REP(h,0,H){
        t[h]=is();
    }
    oie(fn(0));
    return 0;
}

Measured memory_bytes: 3612