akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(void)
{
  int a, b;
  int d, r;
  double f;

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

  d = a / b;
  r = a % b;
  f = (double)a / b;

  printf("%d %d %f\n", d, r, f);

  return 0;
}

Measured memory_bytes: 636
#include <stdio.h>
char tbl[2000][2000];
short row[2000][2000];
short col[2000][2000];
int max(int x,int y)
{
  return x > y ? x : y;
}
int
main()
{
  int i,j;
  int h,w;
  scanf("%d %d", &h, &w);
  for (i=0; i<h; i++) {
    scanf("%s", tbl[i]);
  }

  for (i=0; i<h; i++) {
    j = 0;
    int start = 0;
    int j2;
    while (1) {
      if (j == w) {
        for (j2=start; j2<w; j2++)
          row[i][j2] = j-start;
        break;
      }
      if (tbl[i][j] == '#') {
        for (j2=start; j2<j; j2++)
          row[i][j2] = j-start;
        row[i][j] = 0;
        start = j+1;
      }
      j ++;
    }
  }


  for (j=0; j<w; j++) {
    i = 0;
    int start = 0;
    int i2;
    while (1) {
      if (i == h) {
        for (i2=start; i2<h; i2++)
          col[i2][j] = i-start;
        break;
      }
      if (tbl[i][j] == '#') {
        for (i2=start; i2<i; i2++)
          col[i2][j] = i-start;
        col[i][j] = 0;
        start = i+1;
      }
      i ++;
    }
  }

  int m = 0;
  for (i=0;i<h;i++) {
    for (j=0;j<w;j++) {
      m = max(m,col[i][j] + row[i][j]);
    }
  }
  printf("%d\n",m-1);
  /*
  for (i=0;i<h;i++) {
    for (j=0;j<w;j++) {
      printf("%d", col[i][j]);
    }
    printf("\n");
  }
  */
}



Measured memory_bytes: 19712
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    set<int> a, b;
    for(int i = 0; i < n; i++)
    {
        int x; cin >> x;
        a.insert(x);
    }
    for(int i = 0; i < m; i++)
    {
        int x; cin >> x;
        b.insert(x);
    }
    set<int> s, t;
    for(auto x : a)
    {
        if(b.count(x)) s.insert(x);
        t.insert(x);
    }
    for(auto x : b) t.insert(x);
    cout << s.size() << " " << t.size() << endl;
    for(auto x : s) cout << x << endl;
    for(auto x : t) cout << x << endl;
    return 0;
}




Measured memory_bytes: 25968
#include<cstdio>
#include<vector>
using namespace std;
#define N 4001
int he[N],ne[(N<<1)-1],e[(N<<1)-1],cnt=1;
int St[N],Ed[N],d[N],w[(N<<1)-1],vis[N],n,m;
vector<int>b[(N<<1)-1],c[(N<<1)-1];

void add(int u,int v){
	ne[++cnt]=he[u];
	he[u]=cnt;
	e[cnt]=v;
}

bool dfs(int x,int fa,int Ed,vector<int>&b){
	if(x==Ed)return 1;
	for(int i=he[x];i;i=ne[i]){
		if(e[i]!=fa){
			b.push_back(i);
			if(dfs(e[i],x,Ed,b)) return 1;
			b.pop_back();
		}
	}
	return 0;
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;++i){
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	for(int i=0;i<m;++i){
		scanf("%d%d",&St[i],&Ed[i]);
		dfs(St[i],0,Ed[i],b[i]);
		for (int j=0;j<b[i].size();j++){
			c[b[i][j]/2].push_back(i);
			++d[b[i][j]/2];
		}
	}
	int ans=0;
	for(int i=1;i<n;++i)ans+=min(2,d[i]);
	printf("%d\n",ans);
	for(;;){
		int p=0,q=-1;
		for(int i=1;i<n;++i){
			if(d[i]==1&&w[i*2]!=w[i*2+1]){
				p=i;
				break;
			}
		}
		if(p==0){
			for(int i=1;i<n;++i){
				if(d[i]>=2){
					p=i;
					break;
				}
			}
		}
		if(p==0)break;
		for(int i=0;i<c[p].size();++i){
			if(!vis[c[p][i]]){
				q=c[p][i];
				break;
			}
		}
		vis[q]=1;
		for (int i=0;i<b[q].size();++i){
			if (b[q][i]/2==p){
				if (w[b[q][i]]){
					swap(St[q],Ed[q]);
					for(int j=0;j<b[q].size();++j)
					b[q][j]^=1;
				}
				for (int j=0;j<b[q].size();j++){
					--d[b[q][j]/2];
					w[b[q][j]]=1;
				}
				break;
			}
		}
	}
	for(int i=0;i<m;++i)
	printf("%d %d\n",St[i],Ed[i]);
	return 0;
}

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

int ax[]={1, 0, 1};
int ay[]={0, 1, 1};

int bx[]={0, 0, 0};
int by[]={1, 2, 3};

int cx[]={1, 2, 3};
int cy[]={0, 0, 0};

int dx[]={-1, 0, -1};
int dy[]={1, 1, 2};

int ex[]={1, 1, 2};
int ey[]={0, 1, 1};

int fx[]={0, 1, 1};
int fy[]={1, 1, 2};

int gx[]={1, -1, 0};
int gy[]={0, 1, 1};


int main(){
	char map[12][12];
	int x, y;

	for(int i=0;i<12;i++){
		for(int j=0;j<12;j++){
			map[i][j]=0;
		}
	}

	while(1){
		for(int i=0; i<8; i++)
			cin>>map[i];

		if(cin.eof())break;

		x=y=0;
		for(int i=0; i<64; i++){
			if(map[i/8][i%8]=='1'){
				x=i%8;
				y=i/8;
				break;
			}
		}

		if(map[y+ay[0]][x+ax[0]]=='1'&&map[y+ay[1]][x+ax[1]]=='1'&&map[y+ay[2]][x+ax[2]]=='1')
			cout<<"A\n";
		else if(map[y+by[0]][x+bx[0]]=='1'&&map[y+by[1]][x+bx[1]]=='1'&&map[y+by[2]][x+bx[2]]=='1')
			cout<<"B\n";
		else if(map[y+cy[0]][x+cx[0]]=='1'&&map[y+cy[1]][x+cx[1]]=='1'&&map[y+cy[2]][x+cx[2]]=='1')
			cout<<"C\n";
		else if(map[y+dy[0]][x+dx[0]]=='1'&&map[y+dy[1]][x+dx[1]]=='1'&&map[y+dy[2]][x+dx[2]]=='1')
			cout<<"D\n";
		else if(map[y+ey[0]][x+ex[0]]=='1'&&map[y+ey[1]][x+ex[1]]=='1'&&map[y+ey[2]][x+ex[2]]=='1')
			cout<<"E\n";
		else if(map[y+fy[0]][x+fx[0]]=='1'&&map[y+fy[1]][x+fx[1]]=='1'&&map[y+fy[2]][x+fx[2]]=='1')
			cout<<"F\n";
		else if(map[y+gy[0]][x+gx[0]]=='1'&&map[y+gy[1]][x+gx[1]]=='1'&&map[y+gy[2]][x+gx[2]]=='1')
			cout<<"G\n";

	}
	return 0;
}

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

ll A, B, C;

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

    ll V = A*B*C;
    ll ans = 1.0e18;
    ans = min(ans, abs(A/2*B*C - V + A/2*B*C));
    ans = min(ans, abs(B/2*A*C - V + B/2*A*C));
    ans = min(ans, abs(C/2*B*A - V + C/2*B*A));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//2017-11-30
//miaomiao
//
#include <bits/stdc++.h>
using namespace std;

#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define Forr(i, a, b) for(int i = (a); i >= (int)(b); --i)

#define N (200000+5)
const int oo = 0x3f3f3f3f;

char chr;
inline void Read(int &x){
	chr = getchar();
	while(chr < '0' || chr > '9') chr = getchar();
	x = 0;
	while(chr >= '0' && chr <= '9'){
		x = (x<<1) + (x<<3) + (chr^'0');
		chr = getchar();
	}
}

int ql, qr;

#define lc (o<<1)
#define rc (o<<1|1)
#define mid ((L+R)>>1)

struct Seg_tree{
	int h[N<<2];

	void Build(int o, int L, int R){
		h[o] = -oo;
		if(L == R) return;
		Build(lc, L, mid); Build(rc, mid+1, R);
	}

	void Modify(int o, int L, int R, int p, int pv){
		if(L == R){h[o] = pv; return;}

		if(p <= mid) Modify(lc, L, mid, p, pv);
		else Modify(rc, mid+1, R, p, pv);
		h[o] = max(h[lc], h[rc]);
	}

	int Query(int o, int L, int R){
		if(ql <= L && qr >= R) return h[o];

		int ret = -oo;
		if(ql <= mid) ret = max(ret, Query(lc, L, mid));
		if(qr > mid) ret = max(ret, Query(rc, mid+1, R));
		return ret;
	}
}st1, st2;

#undef lc
#undef rc
#undef mid

struct node{
	int l, r;
	bool operator <(const node &rhs)const{return l < rhs.l;}
}seg[N];

int n, m, ans, b[N], sum[N], f[N], pre[N], suf[N];

void Solve(){
	int p = 0, l, r;
	
	st1.Build(1, 1, n); st2.Build(1, 1, n);
	For(si, 1, m){
		l = seg[si].l; r = seg[si].r;
//		printf("(%d %d)\n", l, r);

		while(p+1<si && seg[p+1].l < l){
			++p;
			st1.Modify(1, 1, n, seg[p].r, f[p]-pre[seg[p].r]);
			st2.Modify(1, 1, n, seg[p].r, f[p]-sum[seg[p].r]);
		}
		f[si] = pre[l-1] + (sum[r] - sum[l-1]);

		ql = l; qr = r;
		f[si] = max(f[si], sum[r]+st2.Query(1, 1, n));

		ql = 1; qr = l-1;
		if(ql <= qr) f[si] = max(f[si], st1.Query(1, 1, n)+pre[l-1]+(sum[r]-sum[l-1]));
		
		ans = max(ans, f[si] + suf[r+1]);
		
//		printf("f[%d] = %d (+%d)\n", si, f[si], suf[r+1]);
//		puts("-----------------");
	}

	printf("%d\n", n-ans);
}

int main(){
	Read(n);
	For(i, 1, n){
		Read(b[i]);
		sum[i] = sum[i-1] + b[i]; pre[i] = (ans += !b[i]);
	}
	Forr(i, n, 1) suf[i] = suf[i+1] + (!b[i]);

	Read(m);
	For(i, 1, m) Read(seg[i].l), Read(seg[i].r);
	sort(seg+1, seg+m+1);
	
	Solve();

	return 0;
}

Measured memory_bytes: 10880
#include<stdio.h>
int main() {
	int i, j, n, b, cards[5][16] = {0};
	scanf("%d", &n);
	 for (i = 1;i <= n;i++) {
		char c;
		scanf(" %c %d", &c, &b);
		if (c == 'S') {
			cards[0][b-1] = 1;
		}
		else if (c == 'H') {
			cards[1][b-1] = 1;
		}
		else if (c == 'C') {
			cards[2][b-1] = 1;
		}
		else {
			cards[3][b-1] = 1;
		}
	}
	for (i = 0;i < 4;i++) {
		for (j = 0;j < 13;j++) {
			char m;
			if (cards[i][j] == 0) {
				if (i == 0) {
					m = 'S';
				}
				else if (i == 1) {
					m = 'H';
				}
				else if (i == 2) {
					m = 'C';
				}
				else {
					m = 'D';
				}
				printf("%c %d\n", m, j + 1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 596
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int N;
int A[MAX], B[MAX], C[MAX];

int main() {

    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }    
    REP(i, N) {
        cin >> B[i];
    }    
    REP(i, (N-1)) {
        cin >> C[i];
    }    

    ll ans = 0;
    int temp = -1;
    REP(i, N) {
        int dish = A[i]-1;
        ans += B[dish];
        if(dish==temp) {
            ans += C[dish-1];
        }
        temp = dish+1;
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main(){
	int N;
	cin>>N;
	if(N%10==9){
		cout<<"Yes"<<endl;
		return 0;
	}
	N/=10;
	if(N%10==9){
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)

using Weight = int;
struct Edge {
	int src, dst, id; Weight weight;
	Edge() {}
	Edge(int s, int d, int id, Weight w) : src(s), dst(d), id(id), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

struct UnionFind {
	vector<int> par;
	int cnt;
	UnionFind(int size_) : par(size_, -1), cnt(size_) {}
	void unite(int x, int y) {
		if((x = find(x)) != (y = find(y))) {
			if(par[y] < par[x]) swap(x, y);
			par[x] += par[y]; par[y] = x; cnt--;
		}
	}
	bool same(int x, int y) { return find(x) == find(y); }
	int find(int x) { return par[x] < 0 ? x : par[x] = find(par[x]); }
	int size(int x) { return -par[find(x)]; }
	int size() { return cnt; }
};

int N, M;
bool operator < (const Edge &e, const Edge &f) { return e.weight < f.weight; }
pair<Weight, Edges> kruskal(Edges es) {
	UnionFind uf(N);
	Weight total = 0; Edges T;
	for(auto &e : es)if(!uf.same(e.src, e.dst)) {
		T.push_back(e); total += e.weight; uf.unite(e.src, e.dst);
	}
	return make_pair(total, T);
}

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

	while(cin >> N >> M) {
		vector<Edge> es(M);
		for(int i = 0; i < M; i++) {
			int a, b, w;
			cin >> a >> b >> w;
			a--, b--;
			es[i] = Edge(a, b, i, w);
		}
		sort(es.begin(), es.end());

		int req = 0, total = 0;
		auto res = kruskal(es);
		for(Edge& e : res.second) {
			Edges es2;
			for(int i = 0; i < M; i++) {
				if(es[i].id == e.id) continue;
				es2.push_back(es[i]);
			}
			auto res2 = kruskal(es2);
			if(res2.second.size() != N - 1 || res.first < res2.first) {
				req++;
				total += e.weight;
			}
		}

		cout << req << " " << total << endl;
	}
}

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

typedef long long ll;
using namespace std;

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

  rep(i,0,n){
    if((ans * 2) < (ans + k)) ans *= 2;
    else ans += k;
  }
  pout(ans);
	return 0;
}

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++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define MOD 1000000007

int main(void) {
  string s;
  cin >> s;
  int cnt=0;
  if(s == "RRR") cout << 3 << endl;
  else if(s == "SSS") cout << 0 << endl;
  else if(s == "RRS" || s == "SRR") cout << 2 << endl;
  else cout << 1 << endl;
}

Measured memory_bytes: 3620
#!/usr/bin/env python3

N = int(input().split()[0])
total = 0
for i in range(1, N + 1):  # max = 200
    a = i
    if a % 2 == 0:
        continue
    c = 0
    for j in range(1, N + 1):  # max = 200
        if a % j == 0:
            c += 1
    if c == 8:
        total += 1
ans = total
print(ans)


Measured memory_bytes: 2940
n = int(input())
arr = list(map(int, input().split()))
if n == 2:
    print(abs(arr[0] - arr[1]))
    exit()
dp = [10 ** 9 for _ in range(n)]
dp[0] = abs(arr[0] - arr[1])
dp[1] = min(abs(arr[2] - arr[0]), abs(arr[2] - arr[1]) + dp[0])

for i in range(3, n):
    dp[i - 1] = min(
        abs(arr[i] - arr[i - 1]) + dp[i - 2], abs(arr[i] - arr[i - 2]) + dp[i - 3]
    )

# dp[2] = min(abs(arr[3] - arr[2]) + dp[1], abs(arr[3] - arr[1]) + dp[0])
# dp[3] = min(abs(arr[4] - arr[3]) + dp[2], abs(arr[4] - arr[2]) + dp[1])
# dp[4] = min(abs(arr[5] - arr[4]) + dp[3], abs(arr[5] - arr[3]) + dp[2])

print(dp[-2])


Measured memory_bytes: 14356
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int t=0;
  for(int i=0;i<2;i++){
    if(a>b){
      t+=a;
      a--;
    }else{
      t+=b;
      b--;
    }
  }
  cout<<t<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 101

int main(){

  int n,u,k,i,j,l,Adj[MAX],v[MAX],graph[MAX][MAX];

  scanf("%d",&n);

  for(i = 1; i <= n; i++){
    for(j = 1; j <= n; j++){
      graph[i][j] = 0;
    }
  }

  for(i = 1; i <= n; i++){
    scanf("%d%d",&u,&k);
    for(j = 1; j <= k; j++){
      scanf("%d",&v[j]);
      graph[i][v[j]] = 1;
    }

  }
  
  for(i = 1; i <= n; i++){
    for(j = 1; j <= n; j++){
      printf("%d",graph[i][j]);
      if(j < n) printf(" ");
    }
    printf("\n");
  }
  return 0;
}

  
  
  

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

int main(){
	string s;
	cin >> s;
	if((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2]== s[3])) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	return 0;
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
const int P = 998244353;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int tot, prime[MAXN], f[MAXN];
int miu[MAXN], inv[MAXN], func[MAXN];
void update(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}
int power(int x, int y) {
	if (y == 0) return 1;
	int tmp = power(x, y / 2);
	if (y % 2 == 0) return 1ll * tmp * tmp % P;
	else return 1ll * tmp * tmp % P * x % P;
}
void sieve(int n) {
	miu[1] = 1;
	for (int i = 2; i <= n; i++) {
		if (f[i] == 0) {
			prime[++tot] = f[i] = i;
			miu[i] = P - 1;
		}
		for (int j = 1; j <= tot && prime[j] <= f[i]; j++) {
			int tmp = prime[j] * i;
			if (tmp > n) break;
			f[tmp] = prime[j];
			if (prime[j] == f[i]) miu[tmp] = 0;
			else miu[tmp] = (P - miu[i]) % P;
		}
	}
	for (int i = 1; i <= n; i++) {
		inv[i] = power(i, P - 2);
		for (int j = 1; i * j <= n; j++)
			update(func[i * j], 1ll * inv[i] * miu[j] % P);
	}
}
int a[MAXN], cnt[MAXN], value[MAXN];
int main() {
	int n; read(n);
	int m = 1e6; sieve(m);
	for (int i = 1; i <= n; i++)
		read(a[i]), cnt[a[i]]++;
	for (int i = 1; i <= m; i++) {
		for (int j = i; j <= m; j += i)
			update(value[i], 1ll * j * cnt[j] % P);
	}
	int ans = 0;
	for (int i = 1; i <= m; i++)
		update(ans, 1ll * value[i] * value[i] % P * func[i] % P);
	for (int i = 1; i <= n; i++)
		update(ans, P - a[i]);
	writeln(1ll * ans * inv[2] % P);
	return 0;
}

Measured memory_bytes: 28928
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

ll N,X,p[55],bp[55];
ll dfs(ll n,ll x){
    if(n==0) {if(x<=0) return 0; else return 1;}
    if(x<=bp[n-1]+1) return dfs(n-1,x-1);
    else return p[n-1]+1+dfs(n-1,x-2-bp[n-1]);
}
main() {
    cin >> N >> X;
    p[0]=1; bp[0]=1;
    for(int i=1;i<=N;i++){
        p[i]=p[i-1]*2+1;
    }
    for(int i=1;i<=N;i++){
        bp[i]=bp[i-1]*2+3;
    }
    cout << dfs(N,X) << endl;
}


Measured memory_bytes: 256
import           Control.Applicative
import           Control.Monad

print' :: Show a => [a] -> IO ()
print' = putStrLn . unwords . fmap show

(<:>) :: Int -> ([Int], Int) -> ([Int], Int)
x <:> (xs, n) = (x : xs, n)

bubble' :: ([Int], Int) -> ([Int], Int)
bubble' (xs, n) = f n xs
  where
    f k []  = ([],  k)
    f k [a] = ([a], k)
    f k (a:b:cs)
        | a < b     = b <:> f (k + 1) (a : cs)
        | otherwise = a <:> f k       (b : cs)

bubble :: [Int] -> ([Int], Int)
bubble xs =
    let (xs', m) = foldr (.) id (replicate n bubble') (reverse xs, 0)
     in (reverse xs', m)
  where
    n = length xs

main :: IO ()
main = do
    getLine
    xs <- fmap read . words <$> getLine :: IO [Int]
    let (ys, n) = bubble xs
    print' ys
    print  n



Measured memory_bytes: 4224
def resolve():
    n = int(input())
    p = [int(i) for i in input().split()]

    min = 2 * 10 ** 6
    ans = 0
    for i in range(n):
        if p[i] <= min:
            min = p[i]
            ans += 1
    print(ans)
    
if __name__ == "__main__":
    resolve()

Measured memory_bytes: 24744
N = int(input())
a = list(map(int, input().split()))

pow = 1
pow_at = pow
div_flg = True

while div_flg == True :
    for i in a :
        if i % 2**pow != 0 :
            div_flg = False
            pow_at = pow - 1
    pow += 1
            
print(pow_at)

Measured memory_bytes: 3060
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-05-12 16:16:14

---------------------------------*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;

ll a[1007], b[1007], c[1007];
int main(int argc, char const *argv[])
{
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	for(int i = 1; i <= x; ++i)	cin >> a[i];
	for(int i = 1; i <= y; ++i)	cin >> b[i];
	for(int i = 1; i <= z; ++i)	cin >> c[i];
	sort(c+1, c+1+z);
	reverse(c+1, c+1+z);
	priority_queue<pair<ll, int> > v;
	for(int i = 1; i <= x; ++i){
		for(int j = 1; j <= y; ++j){
			v.push({a[i]+b[j]+c[1], 1});
		}
	}
	for(int i = 1; i <= k; ++i){
		auto p = v.top(); v.pop();
		cout << p.first << endl;
		if(p.second == z)	continue;
		v.push({p.first-c[p.second]+c[p.second + 1], p.second + 1});
	}
	return 0;
}

Measured memory_bytes: 18792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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 main(){
    int a, b, c; cin >> a >> b >> c;

    bool fg = false;
    for(int i=1; i<=b; i++){
        if(a*i%b==c)fg = true;
    }
    if(fg) cout << "YES" << ln;
    else cout << "NO" << ln;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define F first
#define S second
using namespace std;
int n;
int a[100010];
int res=1;
void dfs(int x,int y,int z)
{
	if (y<=res) return;
	//cout <<x<<" "<<y<<" "<<z<<" ##\n";
	if (x==n)
	{
		res=max(res,y);
		return;
	}
	dfs(x+1,__gcd(y,a[x]),z);
	if (!z) dfs(x+1,y,1);
}
int main()
{
	cin >>n;
	for (int i=0;i<n;i++)
	{
		cin >>a[i];
		//a[i]=i+1;
	}
	dfs(1,a[0],0);
	dfs(1,a[1],1);
	cout <<res;
	return 0;
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    
    sort(a.begin(),a.end(),greater<int>());
    int sum_alice=0;
    int sum_bob=0;
    for(int i=0;i<n;i+=2){
        sum_alice+=a[i];
    }
    for(int i=1;i<n;i+=2){
        sum_bob+=a[i];
    }
    cout<<sum_alice-sum_bob<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2 ],R[MAX / 2 + 2 ];

void merge(struct Card A[], int n, int left, int mid, int right) {
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for ( i = 0; i < n1; i++ ) L[i] = A[left+i];
    for ( i = 0; i < n2; i++ ) R[i] = A[mid+i];
    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for ( k = left; k < right; k++ ) {
        if ( L[i].value <= R[j].value ) {
            A[k] = L[i++];
        } else {
            A[k]= R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right) {
    int mid;
    if ( left + 1 < right ){
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[],int n,int p,int r){
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p - 1;
    for ( j = p; j < r;j++) {
        if ( A[j].value <= x.value ) {
            i++;
            t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    t = A[ i + 1 ]; A[ i + 1 ] = A[r]; A[r]= t;
    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r) {
    int q;
    if( p < r ){
        q = partition(A,n,p,r);
        quickSort(A, n, p, q - 1);
        quickSort(A, n, q + 1, r);
    }
}

int main() {
    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;

    scanf("%d",&n);

    for ( i = 0; i < n; i++) {
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A,n,0,n);
    quickSort(B,n,0,n-1);

    for ( i = 0 ; i < n ; i++ ) {
        if( A[i].suit != B[i].suit) stable = 0; 
    }

    if (stable == 1) printf("Stable\n");
    else printf("Not stable\n");
    for( i = 0; i < n; i++ ) {
        printf("%c %d\n",B[i].suit,B[i].value);
    }
    return 0;
}


Measured memory_bytes: 4116
import collections
import itertools
ans = 0

N = int(input())
s_list = []
for i in range(N):
    s_list.append(input())

d = {}
for s in s_list:
    l2 = []
    for i in range(len(s)):
        l2.append(s[i])
    l2.sort()
    a = ""
    for i in l2:
        a += i
    if a in d:
        ans+=d[a]
        d[a]+=1
    else:
        d[a] = 1

print(ans)

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

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;
const double PI=3.1415926535897932;

ll N, D, T, ans=0, tmp=0;
vector<ll> A;
string S;

signed main(){
    cin >> D >> T >> N;
    if(D<=T*N) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"

using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
int n;
map <int,int> p[2];
int maxim[2];
int v[100001];
priority_queue <pii> pp,ii;
int main()
{
    cin >> n;
    for(int i  =1;i <= n;i++){
        int x;
        cin >> x;
        p[i % 2][x]++;
        v[i] = x;
    }
    for(auto x : p[0])
    {
        pp.push({x.second, x.first});
    }
    for(auto x : p[1]){
        ii.push({x.second, x.first});
    }
    pii firstp = pp.top(),secondp = {0,0};
    pp.pop();
    if(pp.size())
        secondp = pp.top();
     pii firsti = ii.top(),secondi = {0,0};
    ii.pop();
    if(ii.size())
        secondi = ii.top();
    int minim = 2e9;
    if(firsti.second != firstp.second)
    minim = min(minim,n - firsti.first - firstp.first);
     minim = min(minim,n - secondi.first - firstp.first);
      minim = min(minim,n - firsti.first - secondp.first);
      cout << minim;
    return 0;
}


Measured memory_bytes: 6520
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;
typedef long long ll;
int main() {
	int h, w, d;
	scanf("%d%d%d", &h, &w, &d);
	pair<int, int> pa[90009];
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++){
			int a;
			cin >> a;
			pa[a] = make_pair(i, j);
		}
	}
	int q;
	cin >> q;
	int ch[90009];
	for(int j=1; j<=d; j++){
		ch[j] = 0;
		int lx = pa[j].first, ly = pa[j].second;
		for(int i=j+d; i<=h*w; i+=d){
			ch[i] = ch[i-d] + abs(pa[i].first - lx)+ abs(pa[i].second - ly);
			lx = pa[i].first;
			ly = pa[i].second;
		}
	}
	for(int i=0; i<q; i++){
		int l, r;
		scanf("%d%d", &l, &r);
		
		printf("%d\n", ch[r]-ch[l]);
	}
	return 0;
}

Measured memory_bytes: 2176
def solve():
    A,B = input().split()
    A = int(A)

    decimal_digit = len(B) - 2
    B_int = int("".join(B.split('.')))

    tmp = A * B_int
    tmp = str(tmp)
    
    if int(tmp) <= decimal_digit:
        print("0")
    else:
        print(tmp[:len(tmp)-decimal_digit])

if __name__ == '__main__':
    solve()

Measured memory_bytes: 61908
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc116_a.cpp
 * time   : Fri May  1 14:31:27 2020
 * quest  : A - Right Triangle
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int ab, bc, ca;
  cin >> ab >> bc >> ca;
  cout << (ab * bc * ca) / (max(ab, max(bc, ca)) * 2) << "\n";
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort()

s = [0] * (N+1)

for i in range(N):
    s[i+1] = s[i] + ab[i][1]
    if s[i] < K <= s[i+1]:
        print(ab[i][0])
        break


Measured memory_bytes: 32112
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));

  int cost = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> C.at(i);
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }
  int ans = INF;
  
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    int cost = 0;
    vector<int> sum(M);
    bitset<12> s(tmp);
    for (int i = 0; i < N; i++) {
      if(s.test(i)) {
        cost += C.at(i);
        for (int j = 0; j < M; j++) {        
          sum.at(j) += A.at(i).at(j);
        }
      }
    }
    bool ok = true;
    for (int j = 0; j < M; j++) {
      if (sum.at(j) < X) {
        ok = false;
      }
    }
    if (ok) {
      ans = min(ans, cost);
    }
  }
  if (ans == INF) {
  cout << -1 << endl;
  }
  else {
    cout << ans << endl;
  }           
  return 0;
}

Measured memory_bytes: 3632
import sys
def input(): return sys.stdin.readline().rstrip()
class mod_comb3:
  def __init__(self,mod=10**9+7,n_max=1):
    self.mod,self.n_max=mod,n_max
    self.fact,self.inv,self.factinv=[1,1],[0,1],[1,1]
    if 1<n_max:setup_table(n_max) 
  def comb(self,n,r):
    if r<0 or n<r:return 0
    if self.n_max<n:self.setup_table(n)
    return self.fact[n]*(self.factinv[r]*self.factinv[n-r]%self.mod)%self.mod
  def setup_table(self,t):
    for i in range(self.n_max+1,t+1):
      self.fact.append(self.fact[-1]*i%self.mod)
      self.inv.append(-self.inv[self.mod%i]*(self.mod//i)%self.mod)
      self.factinv.append(self.factinv[-1]*self.inv[-1]%self.mod)
    self.n_max=t

def main():
    n,m,k=map(int,input().split())
    mod=998244353
    f=mod_comb3(mod)
    ans=0
    t=m*pow(m-1,n-1-k,mod)
    for kx in range(k,-1,-1):
        ans+=f.comb(n-1,kx)*t%mod
        t=t*(m-1)%mod
    print(ans%mod)

if __name__=='__main__':
    main()

Measured memory_bytes: 32832
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main(){
  int N;
  cin >> N;
  int W[N];
  int sum[N];
  REP(i, 0, N){
    cin >> W[i];
    if (i==0)
      sum[0] = W[0];
    else
      sum[i] = sum[i-1] + W[i];
  }

  // cout << sum[N-1] << endl;

  int diff;
  int ans = inf;
  REP(i, 0, N){
    diff = abs(sum[N-1] - (sum[i] * 2));
    ans = min(ans, diff);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#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>;
ll StoN(string s, int i, int j) {
    ll res = 0;
    for(int x=i;x<j;x++) {
        res *= 10;
        res += s[x] - '0';
    }
    return res;
}
int main() {
    string s; cin >> s;
    int n = s.size();
    ll ans = 0;
    rep(i, (1<<(n-1))) {
        vector<int> st;
        st.push_back(0);
        rep(j, n-1) {
            if((i>>j)&1) st.push_back(j+1);
        }
        st.push_back(n);
        ll res = 0;
        rep(j, st.size()-1) {
            res += StoN(s, st[j], st[j+1]);
        }
        ans += res;
    }
    cout << ans;
}


Measured memory_bytes: 256
list_HW = list()
while True:
    base = input("")
    term = base.split(' ')
    if(int(term[0]) == 0 and int(term[0]) == 0):
        break
    else:
        map_HW = {'H': int(term[0]), 'W': int(term[1])}
        list_HW.append(map_HW)

for HW in list_HW:
    h = HW['H']
    w = HW['W']

    for r in range(h):
        if r == 0 or r == (h-1):
            for s in range(w):
                print('#',end='')
        else:
            for s in range(w):
                if s == 0 or s == (w-1):
                    print('#',end='')
                else:
                    print('.',end='')
        print('',end='\n')

    print('',end='\n')



Measured memory_bytes: 7016
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>

using namespace std;

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

    bool res = (a == 5 && b == 5 && c == 7) || (a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5);
    string str = res ? "YES" : "NO";

    cout << str << endl;

    return 0;
} 


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 100005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   vi a;
   rep(i,0,n)
   {
       int x;
       cin>>x;
       a.pb(x);
   }
   int l=0,r=0;
   int sum=0;
   int ans=0;
   while(l<n)
   {
       while(r<n && (sum^a[r])== sum + a[r])
       {
           sum^=a[r++];ans++;
       }
       sum^=a[l++];
       ans+=(r-l);
   }
   cout<<ans<<endl;
}



Measured memory_bytes: 2420
#include <iostream>

using namespace std;

int main(){
	int n;
	cin >> n;
	
	char pre_char;
	int count = 1;
	cin >> pre_char;
	for(int i = 1; i < n; i++){
		char c;
		cin >> c;
		if(pre_char != c) count++;
		pre_char = c;
	}
	
	cout << count << endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
#include <queue>
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 100005;
struct obj {
	int a, b;
};
obj ob[maxn];
ll lget[maxn], rget[maxn];

int main() {
	int x = read, y = read, z = read;

	int n = x + y + z;
	ll ans = 0;
	for(int i = 1; i <= n; i ++) {
		int v = read;
		ans += v;
		ob[i].a = read - v;
		ob[i].b = read - v;
	}

	std::sort(ob + 1, ob + n + 1, [](obj x, obj y) {
				return x.a - x.b > y.a - y.b;
			});

	std::priority_queue<int, std::vector<int>, std::greater<int> > biggest;

	for(int i = 1; i <= n; i ++) {
		lget[i] = lget[i - 1] + ob[i].a;
		biggest.push(ob[i].a);
		if(int(biggest.size()) > y) {
			lget[i] -= biggest.top();
			biggest.pop();
		}
	}

	while(!biggest.empty()) biggest.pop();
	for(int i = n; i; i --) {
		rget[i] = rget[i + 1] + ob[i].b;
		biggest.push(ob[i].b);
		if(int(biggest.size()) > z) {
			rget[i] -= biggest.top();
			biggest.pop();
		}
	}

	ll max = - 1000000000000000000;
	for(int k = y; k <= n - z; k ++)
		max = std::max(max, lget[k] + rget[k + 1]);

	printf("%lld\n", ans + max);
}

Measured memory_bytes: 6164
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  string s;
  cin >> s;
  int l=s.size();
  ll ans=0;
  for (int i=0;i<(1<<l-1);i++){
    ll sum=s.at(0)-'0';
    for (int j=0;j<l-1;j++){
      if (i&(1<<j)){
        ans+=sum;
        sum=s.at(j+1)-'0';
        if (j==l-2)
          ans+=sum;
      }
      else{
        sum=sum*10+(s.at(j+1)-'0');
        if (j==l-2)
          ans+=sum;
      }
    }
  }
  if(l==1)
    cout << s.at(0)-'0' << endl;
  else
    cout << ans << endl;
}

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

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

  return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
 
#define NL '\n'
#define xx first
#define yy second
#define ll long long
#define mp make_pair
#define pb push_back
#define sz(x) x.size()
#define all(x) (x).begin(), (x).end()
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;++i)
#define async() ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 
#define FayeValentine 
void dz(){cerr<<NL;}template<typename H,typename... T> void dz(H h,T... t){cerr<<' '<<h;dz(t... );}
#ifdef  FayeValentine
#define debug(...) cerr<<"("<<#__VA_ARGS__<<"):",dz(__VA_ARGS__)
#else
#define debug(...) 
#endif
 

void absinthe() {
	int m, k; cin >> m >> k;
	if(m == 1) {
		if(k == 0) cout << "0 0 1 1" << NL;
		else cout << -1 << NL;
		return;
	}
	if((1<<(m)) <= k) {
		cout << -1 << NL;
		return;
	}
	for(int i = 0; i < (1<<m); i++) {
		if(i == k) continue;
		cout << i << " ";
	}
	cout << k << " ";
	for(int i = (1<<m)-1; i >= 0; i--) {
		if(i == k) continue;
		cout << i << " ";
	}
	cout << k;
}
 
 
int main(){
  async();
  int __t = 1, __c; //cin >> __t;
  for(__c = 1; __c <=__t; __c++) {
    //cout << "Case " << __c << ": "; 
    absinthe();
  }
}  

Measured memory_bytes: 1792
from itertools import product

if __name__ == '__main__':
    N = int(input())
    count = 0
    digits = len(str(N))
    
    for n in range(1, digits+1):

        for t in product('357', repeat=n):
            num = ''.join(t)
            if int(num) <= N:
                if '3' in num and '5' in num and '7' in num:
                    count += 1
    print(count)
            

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main() {
	log.SetFlags(log.Lshortfile)
	nextReader = NewScanner()
	var inputs []int
	n := nextInt()

	for i := 0; i < n; i++ {
		inputs = append(inputs, nextInt())
	}

	var count int
	for {
		endFlag := false
		for i, v := range inputs {
			if v%2 != 0 {
				endFlag = true
				break
			}
			inputs[i] = v / 2
		}
		if endFlag {
			break
		}
		count++
	}

	fmt.Println(count)

}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

var nextReader func() string

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


Measured memory_bytes: 640
import sys, math
from functools import lru_cache
from collections import defaultdict
from decimal import Decimal
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    a = list(mi())

    for i in range(N-1):
        if a[i] == a[i+1]:
            a[i+1] = -1
    print(a.count(-1))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9992
#include <stdio.h>
#include <stdlib.h>
int c(const void *v1,const void *v2){
    return *(int *)v2-*(int *)v1;
}
int main(void){
    int n,m,line[1000][2],i,sum=0,t,f,o=0,res=0;
    scanf("%d %d",&n,&m);
    for(i=0;i<m;i++){
        scanf("%d %d",&t,&f);
        t>=n?sum++:(line[o][0]=t,line[o++][1]=f);
    }
    if(sum >= m-1)
        puts("0");
    else{
        qsort(line,o,sizeof(int)*2,c);
        for(i=0;i<m-1-sum;i++)
            res+=n-line[i][0];
        printf("%d\n",res);
    }
    return 0;
}

Measured memory_bytes: 656
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int n, t,min=0,max=0,iro[8]={};
cin>>n;
for(int i=0;i<n;i++){
cin>>t;
if(399>=t&&iro[0]==0){
min++;
max++;
iro[0]++;
}
if(399<t&&799>=t&&iro[1]==0){
min++;
max++;
iro[1]++;
}
if(799<t&&1199>=t&&iro[2]==0){
min++;
max++;
iro[2]++;
}
if(1199<t&&1599>=t&&iro[3]==0){
min++;
max++;
iro[3]++;
}
if(1599<t&&1999>=t&&iro[4]==0){
min++;
max++;
iro[4]++;
}
if(1999<t&&2399>=t&&iro[5]==0){
min++;
max++;
iro[5]++;
}
if(2399<t&&2799>=t&&iro[6]==0){
min++;
max++;
iro[6]++;
}
if(2799<t&&3199>=t&&iro[7]==0){
min++;
max++;
iro[7]++;
}
if(3200<=t){
max++;
}
}
if(min==0)min++;
printf("%d %d",min, max);
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rep2(i,s,t) for(int i = s; i <= t; ++i)
#define rev(i,n) for(int i = n-1; i >= 0; --i)
#define rev1(i,n) for(int i = n; i > 0; --i)
#define rev2(i,s,t) for(int i = s; i >= t; --i)
#define F first
#define S second
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
int main()
{
  int n,k; cin >> n >> k;
  int r,s,p; cin >> r >> s >> p;
  string t; cin >> t;
  int res = 0;
  rep(i,k) {
    vi dp(3, 0);
    int x = i;
    while(x < n) {
      vi ndp(3, 0);
      if(t[x] == 'r') {
	ndp[0] = max(dp[1], dp[2]);
	ndp[1] = max(dp[0], dp[2]);	
	ndp[2] = max(dp[0], dp[1]) + p;
      }
      if(t[x] == 's') {
	ndp[0] = max(dp[1], dp[2]) + r;
	ndp[1] = max(dp[0], dp[2]);	
	ndp[2] = max(dp[0], dp[1]);
      }
      if(t[x] == 'p') {
	ndp[0] = max(dp[1], dp[2]);
	ndp[1] = max(dp[0], dp[2]) + s;	
	ndp[2] = max(dp[0], dp[1]);
      }
      dp = ndp;
      x += k;
    }
    res += max({dp[0], dp[1], dp[2]});
  }
  cout << res << "\n";
    
  return 0;
}


Measured memory_bytes: 3744
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
using namespace std;
typedef long long ll;

ll ds(ll digit) {
	ll res = 0;
	while (digit!=0) {
		res += digit % 10;
		digit /= 10;
	}
	return res;
}
ll MOD = 1000000007;
int main() {
	ll N;
	cin >> N;
	ll a[N];
	for (ll i = 0; i < N; ++i) {
		cin >> a[i];
	}
	ll sum = 0;
	for (ll i = 0; i < N; ++i) {
		sum += a[i];
	}
	ll x = sum / N;
	ll y = (sum + N - 1) / N;
  	ll ans1=0;
  	ll ans2=0;
	for (ll i = 0; i < N; ++i) {
		 ans1 += (a[i] - x)*(a[i] - x);
		 ans2 += (a[i] - y)*(a[i] - y);
	}
	cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define INFI 100000

struct point{
	int h,w;
};

class sales{
private:
	int n;
	int **dist;
	int **dp;
	int ans;
public:
	sales(int n){
		this->n=n;
		dist=new int*[n];
		for(int i=0;i<n;i++) dist[i]=new int[n];
		dp=new int*[1<<n];
		for(int i=0;i<(1<<n);i++){
			dp[i]=new int[n];
			for(int j=0;j<n;j++) dp[i][j]=-1;
		}
	}
	void set(int n,int m,int c){
		dist[n][m]=c;
		dist[m][n]=c;
	}
	void set(){
		for(int i=0;i<n;i++) dist[i][0]=0;
		ans=rec(0,0);
	}
	int rec(int s,int v){
		if(dp[s][v]>=0) return dp[s][v];

		if(s==(1<<n)-1 && v==0) return dp[s][v]=0;
		int res=INFI;
		for(int i=0;i<n;i++){
			if(!(s>>i & 1)){
				res=i_min(res,rec(s|(1<<i),i)+dist[v][i]);
			}
		}
		return dp[s][v]=res;
	}
	void show(){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++) cout<<dist[i][j]<<" ";
			cout<<endl;
		}
	}
	int i_min(int p,int q){
		if(p<q) return p;
		return q;
	}
	int ret(){
		return ans;
	}
};


int w,h;
char p[20][21];
int dist[20][20];
int dust;
point d[10];
sales *s;

void dec(int ph,int pw,int c){
	if(p[ph][pw]=='x') return;
	if(ph<0 || ph>=h ||pw<0 || pw>=w) return;
	if(dist[ph][pw]<=c) return;
	dist[ph][pw]=c;
	
	dec(ph-1,pw,c+1);
	dec(ph+1,pw,c+1);
	dec(ph,pw-1,c+1);
	dec(ph,pw+1,c+1);
	return;
}

int main(){
	int i,j,k;
	while(cin>>w>>h){
		if(w==0 && h==0) break;
		dust=1;
		for(i=0;i<h;i++){
			cin>>p[i];
			for(j=0;j<w;j++){
				if(p[i][j]=='*'){
					d[dust].h=i;
					d[dust++].w=j;
				}
				else if(p[i][j]=='o'){
					d[0].h=i;
					d[0].w=j;
				}
			}
		}
		s=new sales(dust);
		int error=0;
		for(i=0;i<dust-1;i++){
			s->set(i,i,0);
			for(j=0;j<h;j++) for(k=0;k<w;k++) dist[j][k]=INFI;
			dec(d[i].h,d[i].w,0);
			for(j=i+1;j<dust;j++){
				if(dist[d[j].h][d[j].w]==INFI){
					error=1;
					break;
				}
				s->set(i,j,dist[d[j].h][d[j].w]);
			}
			if(error==1) break;
		}
		if(error==1){
			cout<<"-1"<<endl;
		}
		else{
			s->set(dust-1,dust-1,0);
			s->set();
			cout<<s->ret()<<endl;
		}
		delete s;
	}
	return 0;
}

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

int main(){
  int l; cin >> l;
  int copy=l;
  int i=0,s=0;
  vector<int> v;
  while(l){
    v.push_back(l%2);
    if(l%2)s++;
    l/=2;
  }
  s--;
  int len=v.size();
  printf("%d %d\n",len,s+2*(len-1));
  s=1;
  for(int i=0;i<len-1;i++){
    printf("%d %d %d\n%d %d %d\n",i+1,i+2,0,i+1,i+2,s);
    if(v.at(i)){
      copy-=s;
      printf("%d %d %d\n",i+1,len,copy);
    }
    s*=2;
  }
}


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

int n,k=-1,d[N];
vector<int>g[N];
char s[N][N];

int bfs(int x){
	queue<int>q;
	q.push(x);d[x]=1;
	while(!q.empty()){
		int x=q.front();q.pop();
		for(int i=0;i<g[x].size();++i){
			int y=g[x][i];
			if(d[y]&&abs(d[y]-d[x])!=1)return -1;
			if(!d[y]){
				d[y]=d[x]+1;
				q.push(y);
			}
		}
	}
	return *max_element(d+1,d+n+1);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%s",s[i]+1);
	for(int i=1;i<=n;++i)
	for(int j=1;j<=n;++j)
	if(s[i][j]=='1'){
		g[i].push_back(j);
	}
	for(int i=1;i<=n;++i){
		memset(d,0,sizeof(d));
		k=max(k,bfs(i));
	}
	printf("%d\n",k);
}

Measured memory_bytes: 512