akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct Graph {
    struct Vertex { int n, v, b; };
    struct Edge { int i, n, c; };
    Graph(int n, int m) : v(n, { -1, 0, 0 }), e(m), n(n), m(0) {}
    void add_edge(int i, int j, int c) {
        e[m] = { j, v[i].n, c };
        v[i].n = m;
        m++;
    }
    int dfs(int i) {
        if (v[i].v) return 0;
        v[i].v = 1;
        int b = v[i].b;

        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge& o = e[j];
            if (dfs(o.i)) {
                c.push_back(o.c);
                b ^= 1;
            }
        }
        return b;
    }
    void solve() {
        for (int i = 0; i < n; i++) {
            if (dfs(i)) {
                cout << -1 << endl;
                exit(0);
            }
        }

        sort(c.begin(), c.end());

        int k = c.size();
        cout << k << '\n';
        for (int i = 0; i < k; i++) {
            cout << c[i] + 1 << " \n"[i == k - 1];
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    vector<int> c;
    int n, m;
};

struct P {
    bool operator<(const P& p) const {
        return a < p.a;
    }
    int a, b;
};

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

    int n, m;
    cin >> n >> m;

    vector<P> p(n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;

        p[i] = { a, b };
    }
    sort(p.begin(), p.end());

    Graph g(n + 1, m * 2);
    for (int c = 0; c < m; c++) {
        int l, r;
        cin >> l >> r;
        r++;

        l = lower_bound(p.begin(), p.end(), P{ l, 0 }) - p.begin();
        r = lower_bound(p.begin(), p.end(), P{ r, 0 }) - p.begin();
        if (l == r) continue;

        g.add_edge(l, r, c);
        g.add_edge(r, l, c);
    }

    int b = 0;
    for (int i = 0; i < n; i++) {
        g.v[i].b = b ^ p[i].b;
        b = p[i].b;
    }
    g.v[n].b = b ^ 0;

    g.solve();

    return 0;
}

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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	string S;
	
	cin >> S;
	
	int len = S.length();
	ll ans = 0;
	
	for(int i=0; i<(1 << (len - 1)); i++){
		ll res = 0, last = 0;
		for(int j=0; j<len; j++){
			last = 10 * last + (S[j] - '0');
			if(i & (1 << j)){
				res += last;
				last = 0;
			}
		}
		ans += res + last;
	}
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

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

using namespace std;

int f(string s)
{
  string ns = "";
  while(s.length() != ns.length() && s.length() > 1)
  {
    ns = "";
    for(int i = 0; i < s.length(); ++i)
    {
      if(i == s.length()-1)
      {
        ns += s[i];
        break;
      }
      if(s[i] == s[i + 1]) continue;
      ns += s[i];
    }
    s = ns;
  }
  return s.length();
}

int main()
{
  int n;
  string s;
  cin >> n;
  cin >> s;
  cout << f(s) << endl;

  return 0;
}


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

int main(){
    //this ques can be done in a better way but i will do sep just for the sake of ac
    int n;
    cin>>n;
    vector<string>v1,v2;
    for(int i=0;i<n;i++){
        string x;
        cin>>x;
        v1.push_back(x);
    }
    v2=v1;
    int f=0;
    sort(v1.begin(),v1.end());
    for(int i=0;i<n-1;i++){
        if(v1[i]==v1[i+1]){
            f=1;
            break;
        }
    }
    if(f==1)cout<<"No";
    else{
        int f2=0;
        for(int i=1;i<n;i++){
            int y=v2[i-1].size();
            if(v2[i-1][y-1]!=v2[i][0]){
                f2=1;
                break;
            }
        }
        if(f2==1)cout<<"No";
        else cout<<"Yes";
    }
    
}


Measured memory_bytes: 256
N = int(input())
dic = {}
for i in range(N):
    b, a = map(int, input().split())
    if a in dic.keys():
        dic[a] += b
    else:
        dic[a] = b
t = 0
for i, j in sorted(dic.items()):
    t += j
    if i < j or t > i:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 41560
#include <bits/stdc++.h>
#define INF 1e+9
#define debug(x) cerr << #x << ": " << x << "\n";
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<int> G[200001];

int main(void){
    int N, M;
    cin >> N >> M;
    int a, b;
    for(int i = 0; i < M; i++){
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    bool res = false;
    for(int i: G[1]){
        if(i == N){
            res = true;
            break;
        }
        for(int j: G[i]){
            if(j == N){
                res = true;
                break;
            }
        }
    }

    if(res){
        cout << "POSSIBLE\n";
    }else{
        cout << "IMPOSSIBLE\n";
    }
    return 0;
}

Measured memory_bytes: 12016
#include<iostream>
#include<vector>
#include<string>

std::vector<int> split(std::string s, char delim){
  if(s.length() == 0)return std::vector<int>{};
  int prev = 0;
  std::string t;
  std::vector<int> res;
  // std::cout << "len:" << s.length() << std::endl;
  for (int i = 1; i < s.length(); i++) {
    if(s[i] == delim) {
      t = s.substr(prev, i - prev);
      res.push_back(std::stoi(t));
      prev = i;
    }
  }
  if(prev != s.length() - 1){
    t = s.substr(prev, s.length() - prev);
    res.push_back(std::stoi(t));
  }
  return res;
}


int main(){
  int n;
  while(std::cin >> n, n){
    if(n == 0)break;
    std::string s;
    std::getline(std::cin, s);
    std::vector<int> cards = split(s, ' ');
    cards.push_back(n);
    int val = 0, num1 = 0;
    // std::cout << "cards:" << std::endl;
    // for (int i = 0; i < cards.size(); i++) {
    //   std::cout << cards[i] << std::endl;
    // }
    for (int i = 0; i < cards.size(); i++) {
      val += std::min(cards[i], 10);
      if(cards[i] == 1)num1++;
    }
    for (int i = 0; i < num1 and val <= 11; i++) val += 10;
    if(val > 21)val = 0;
    // std::cout << "val:" << val << std::endl;
    std::cout << val << std::endl;
  }
  return 0;
}



Measured memory_bytes: 3172
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cstdio>
using namespace std;
int main(){
    int N;
    int total = 0;
    cin >> N;
    int a[100002];
    for(long i = 1; i <= N; i++)
        cin >> a[i];
    for(int i = 1; i <= N; i++)
        total += abs(a[i] - a[i - 1]);
    total += abs(a[N]);
    for(int i = 1; i <= N; i++)
        cout << total - abs(a[i] - a[i - 1]) -abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]) << endl;
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int snum=0,tnum=0;
  for(int i=0;i<s.size();i++) {
    if(s[i]=='S') {
      snum++;
    }
    else {
      if(snum>0) {
        snum--;
      }
      else {
        tnum++;
      }
    }
  }
  cout << snum+tnum << endl;
}


Measured memory_bytes: 640
N = int(input())
com = [0]
a = 0
v = 0
j = 0
str1 = "abcdefghijklmnopqrstuvwxyz"

if N < 27:
    print(str1[N-1])
else:
    for i in range(1,13):
        a += 26**i
        com.append(a)
    for i in range(13):
        if N < com[i]+1:
            v = com[i-1]
            j = i
            break
    N = N - v - 1
    ans = []
    for i in range(j-1,-1,-1):
        ans.append(str1[N//(26**i)])
        if N >= 26**i:
            N = N - N//(26**i) * (26**i)

    print("".join(ans))

Measured memory_bytes: 9060
/*
Problem : https://atcoder.jp/contests/abc139/tasks/abc139_e
Algorithm : topo sort
Status :
*/
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 1005;
const int MAXM = 1e6 + 5;

int n,m,len;
int dfn[MAXM],head[MAXM],deg[MAXM],a[MAXN];

struct Edge{
	int to,next;
} e[MAXM << 2];

void add(int u,int v){
	e[++len].to = v;
	e[len].next = head[u];
	head[u] = len;
	deg[v]++;
}

int getId(int x,int y){
	if(x > y)
	    swap(x,y);
	return (x - 1) * n + y;
}

int topo(){
	queue<int> q;
	for(int i = 1;i <= n * n;i++){
		if(!deg[i]){
		    q.push(i);
		    dfn[i] = 1;
		}
	}
	int cnt = 0;
	while(!q.empty()){
		int u = q.front();
		q.pop();
		cnt++;
		for(int i = head[u];i != -1;i = e[i].next){
			int v = e[i].to;
			deg[v]--;
			if(!deg[v]){
				if(dfn[v])
					return -1;
				dfn[v] = dfn[u] + 1;
				q.push(v);
			}
		}
	}
	if(cnt != n * n)
	    return -1;
	return *max_element(dfn + 1,dfn + 1 + n * n);
}

int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	memset(head,-1,sizeof(head));
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		for(int j = 1;j < n;j++)
		    scanf("%d",&a[j]);
		for(int j = 1;j < n - 1;j++)
		    add(getId(i,a[j]),getId(i,a[j + 1]));
	}
	printf("%d\n",topo());
	return 0;
}


Measured memory_bytes: 22784
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		boolean[][] ar = new boolean[4][13];
		for ( int i = 1; i <= n; i++ ) {
			String suit = scan.next();
			int rank = scan.nextInt();
			if ( suit.equals("S") ) {ar[0][rank-1] = true;}
			if ( suit.equals("H") ) {ar[1][rank-1] = true;}
			if ( suit.equals("C") ) {ar[2][rank-1] = true;}
			if ( suit.equals("D") ) {ar[3][rank-1] = true;}
		}
		for ( int i = 0; i < 4; i++ ) {
			for ( int j = 0; j < 13; j++ ) {
				if ( ar[i][j] == false ) {
					if ( i == 0 ) { System.out.println("S " + (j+1));}
					if ( i == 1 ) { System.out.println("H " + (j+1));}
					if ( i == 2 ) { System.out.println("C " + (j+1));}
					if ( i == 3 ) { System.out.println("D " + (j+1));}
				}
 			}
		}
	}
}

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

int a,b,h,m;

int main()
{
	cin>>a>>b>>h>>m;
	double x=1.0*360/12/60*(h*60+m);
	double y=1.0*360/60*m;
	double z=abs(x-y);
	if(z>180)
		z=360-z;
	double ans=sqrt(a*a+b*b-2.0*a*b*cos(z*1.0*M_PI/180));
	
	cout<<fixed<<setprecision(20)<<ans<< endl;
	return 0;
}


Measured memory_bytes: 4152
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int n;
    cin>>n;
    int c[n],s[n],f[n];
    c[0]=0;s[0]=0;f[0]=0;
    for(int i=0;i<n-1;i++){
        cin>>c[i]>>s[i]>>f[i];
    }
    vector<int> ans;
    int t=0;
    for(int i=0;i<n;i++){
        //station i からi+1へ c[i]s[i]f[i]
        int t=0;
        for(int j=i;j<n-1;j++){
            if(t<=s[j]){
                t=s[j]+c[j];
            }
            else{
                if(t%f[j]!=0){
                    t+=f[j]-t%f[j];
                }
                t+=c[j];
            }
        }
        ans.push_back(t);
    }
    rep(i,n){
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    cin >> N;
    for(int i = 0; i <= 100; i++) {
        for(int j = 0; j <= 100; j++) {
            if(N == 4 * i + 7 * j) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <random>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int a,b,c,d,e,f; cin >> a >> b >> c >> d >> e >> f;
	int sum=a+b*5+c*10+d*50+e*100+f*500;
	if(sum>=1000){
		cout << 1 << endl;
	}
	else{
		cout << 0 << endl;
	}
}


Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
          
          Scanner s=new Scanner(System.in);
          int N=s.nextInt();
          int Max=0;
          int save=0;
          int all=0;

         for(int i=0;i<N;i++){
            save=s.nextInt();
            if(Max<save)Max=save;
            all+=save;
         }
            Max=Max/2;
            all-=Max;
            System.out.println(all);
        }
}


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

typedef long long ll;

int main() {
    ll N, M;
    ll ans;
    cin >> N >> M;
    if (N == 1 && M == 1) {
        ans = 1;
    } else if (N == 1) {
        ans = M-2;
    } else if (M == 1) {
        ans = N-2;
    } else {
        ans = (N-2)*(M-2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = [0]*(n+1)
b = [0]*(n+1)
c = [0]*(n+1)
for i in range(1,n+1): a[i],b[i],c[i] = map(int,input().split())
dp = [[0,0,0] for i in range(n+1)]
for i in range(1,n+1):
    for j in range(3):
        if j == 0: dp[i][j] = max(dp[i-1][1]+a[i],dp[i-1][2]+a[i])
        elif j == 1: dp[i][j] = max(dp[i-1][0]+b[i],dp[i-1][2]+b[i])
        else: dp[i][j] = max(dp[i-1][0]+c[i],dp[i-1][1]+c[i])
print(max(dp[n]))

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

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

	int ans = 0;
	if (l + 1 - 1 > 0) {
		for (int i = 2; i <= n; i++) ans += l + i - 1;
	}
	else if (l + n - 1 < 0) {
		for (int i = 1; i < n; i++) ans += l + i - 1;
	}
	else {
		for (int i = 1; i <= n; i++) ans += l + i - 1;
	}
	cout << ans << endl;
}

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

#define int long long

signed main() {
#ifdef _DEBUG
  freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  const int N = 10000000;
  vector<int> a(N + 1);
  for (int i = 1; i * i <= N; i++)
  for (int j = i * i; j <= N; j += i) {
    if (i * i == j) a[j] += 1;
    else a[j] += 2;
  }
  int n; cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += i * a[i];
  }
  cout << ans << '\n';
}


Measured memory_bytes: 81248
#include <stdio.h>

void Do(int N){
  int i, c, S;
  char A[N], B[N], C[N];
  scanf("%s", A);
  scanf("%s", B);
  scanf("%s", C);
  S = 0;
  for(i = 0;i < N;i++){
    c = 2;
    if(A[i] == B[i]) c--;
    if(A[i] == C[i]) c--;
    if(B[i] == C[i]) c--;
    if(c == -1) c = 0;
    S += c;
  }
  printf("%d\n", S);
}

int main(void){
  int N;
  scanf("%d", &N);
  Do(N);
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

struct UnionFind {
	std::vector<int> par;

	UnionFind(int n) : par(n, -1)
	{
	}

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) std::swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n, m;
	cin >> n >> m;

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

	UnionFind uf(n);

	rep(i, m) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		uf.merge(x, y);
	}

	int cnt = 0;
	rep(i, n) {
		if (uf.issame(i, p[i])) {
			cnt++;
		}
	}

	out(cnt);

	return 0;
}

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

int main(){
	int a, b;
	string s;
	vector<int> st;
	while(cin >> s) {
		if(s == "+") {
			a = st.back(); st.pop_back();
			b = st.back(); st.pop_back();
			st.push_back(a + b);
		}else if(s == "-") {
			a = st.back(); st.pop_back();
			b = st.back(); st.pop_back();
			st.push_back(b - a);
		}else if(s == "*") {
			a = st.back(); st.pop_back();
			b = st.back(); st.pop_back();
			st.push_back(a * b);
		}else{
			st.push_back(stoi(s));
		}
	}
	printf("%d\n", st.back());
}



Measured memory_bytes: 3280
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptor/reversed.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

void Main()
{
	std::string str;
	std::cin >> str;
	if (str[0] != str[1] && 
		str[1] != str[2] && 
		str[2] != str[3])
	{
		std::cout << "Good" << std::endl;
	}
	else
	{
		std::cout << "Bad" << std::endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define ll long long int
#define forr(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define oo 1000000000000000000LL
using namespace std;
int n,m,k;

int get(vector<string> &v, int x, int y){
    int cnt = 0;
    forr(i,n){
        if((1<<i)&x){
            forr(j,m){
                if( ((1<<j)&y) && v[i][j] == '#' ) cnt++;
            }
        }
    }
    return cnt;
}



void _sol(){
   // int n,m,k; 
    cin >> n >> m >> k;
    vector<string> v(n);
    forr(i,n) cin >> v[i];
    int ans = 0;
    int p = (1<<n), q =(1<<m);

  // cout << p << " " << q << "\n";
    forr(i,p){
        forr(j,q){
            if(get(v,i,j) == k) ans++;
        }
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t = 1; //cin >> t;
    while(t--) _sol();
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};

int main(){
    int N; cin >> N;
    vector<ll> a(N);
    cin >> a[0];
    ll gcd = a[0];
    for (int i = 1; i < N; i++){
        cin >> a[i];
        gcd = GCD(max(gcd,a[i]),min(gcd,a[i]));
    }
    cout << gcd << endl;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import math
N = int(input())

# 0以上整数x「未満」の素数をリストに格納して返す
def primes(x):
    if x < 2:
        return []
    primes = [i for i in range(x)]
    primes[1] = 0  # 1は素数ではない
    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x):
            break
        if prime == 0:
            continue
        for non_prime in range(2 * prime, x, prime):
            primes[non_prime] = 0
    return [prime for prime in primes if prime != 0]

prime_list = primes(55555)  # 5637個
prime_list = [x for x in prime_list if x%5 == 1] #1408

sel_num_list = prime_list[:N]
print(" ".join(map(str, sel_num_list)))


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var antena = new int[5];
            for(int i =0; i < 5; i++)
            {
                antena[i] = int.Parse(Console.ReadLine());
            }

            int K = int.Parse(Console.ReadLine());

            if (K >= antena.Max() - antena.Min())
            {
                Console.WriteLine("Yay!");
            }
            else
            {
                Console.WriteLine(":(");

            }
        }


    }
}


Measured memory_bytes: 13268
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = list(input().strip())

dp = [[0] * N for i in range(N)]
max_leng2 = 0 
for i in range(0, N):
    leng2 = 0

    j = i - 1
    while j > -1:
        if S[i] == S[j]:
            sta_j = j
            if j != 0:
                leng2 = dp[i-1][sta_j-1] + 1
            else: 
                leng2 = 1
            
            if i - sta_j < leng2:
                leng2 = i - sta_j
                
            dp[i][sta_j] = leng2
            max_leng2 = max(max_leng2, leng2)
        j -= 1
print(max_leng2)

Measured memory_bytes: 230152
#include<stdio.h>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
 
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
 
 
int main()
{
    int n;
    int ans=0;
    scanf("%d\n",&n);
    while(n>0){
        int a=n%10;
        if(a==2)ans++;
        n/=10;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int m;
	cin >> m;
	cout << 48 - m << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String[] grade = new String[50];
		int n = 0;
		while(true) {
			int m = scan.nextInt();
			int f = scan.nextInt();
			int r = scan.nextInt();
			if (m == -1 && f == -1 && r == -1) break;
			if ((m == -1 || f == -1) || (m + f < 30)) {
				grade[n] = "F";
			}
			else if (m + f >= 80) {
				grade[n] = "A";
			}
			else if (m + f < 80 && m + f >= 65) {
				grade[n] = "B";
			}
			else if (m + f < 65 && m + f >= 50) {
				grade[n] = "C";
			}
			else if (m + f < 50 && m + f >= 30) {
				if (r >= 50) {
					grade[n] = "C";
				}
				else {
					grade[n] = "D";
				}
			}
			n++;
		}
		for (int i = 0; i < n; i++) {
			System.out.println(grade[i]);
		}
	}

}


Measured memory_bytes: 26392
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;
const int oo = 1e8+7;
const int nax = 1e3 + 5;

struct S {
    int w, s, v;
    void read() {
        scanf("%d%d%d", &w,&s,&v);
    }
    bool operator <(const S& b) const {
        return s - b.w > b.s - w;
    }
};

int n;
vector<S> in;
vector<ll> dp[nax];

ll knap(int ind, int left) {

    if(ind == n) return 0;
    else if(dp[ind][left] != -1) return dp[ind][left];
    
    ll ans = knap(ind+1, left);
    
    if(left - in[ind].w >= 0) {
        int next = min(left - in[ind].w, in[ind].s);
        ans = max(ans, in[ind].v + knap(ind+1, next));
    }
    
    dp[ind][left] = ans;
    return ans;
}

int main() {
    
    scanf("%d", &n);
    
    in.resize(n);
    
    for(int i = 0; i < n; ++i) {
        in[i].read();
        dp[i].assign(2e4+5, -1);
    }
    
    sort(in.begin(), in.end());
    
    ll ans = knap(0, 2e4);
    
    printf("%lld\n", ans);
    
    return 0;
}




Measured memory_bytes: 160384
#include <stdio.h>
int main(void)
{
   int n,i,s=0,z,k, a1,a2,a3;
   int b[100000]={0};

   scanf("%d",&n);

   for(i=1;i<=n;i++)
      scanf("%d",&b[i]);
 
   for(i=1;i<=n+1;i++){
      k=0;
      k=b[i]-b[i-1];

      if(0>k){
         k=k*-1;
      }   

      s=s+k;
   }   

       
   for(i=1;i<=n;i++){
      a1=0;
      a2=0;
      a3=0;

      a1=b[i]-b[i-1];
      a2=b[i+1]-b[i];
      a3=b[i+1]-b[i-1];

      if(0>a1)
        a1=a1*-1;
      if(0>a2)
        a2=a2*-1;
      if(0>a3)
        a3=a3*-1;

      printf("%d\n",s-a1-a2+a3);
   }   
   return 0;
}



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

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  private void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int heapSize = Integer.parseInt(br.readLine());
      String[] keys = br.readLine().split(" ");
      int[] mHeap = new int[heapSize+1];
      mHeap[0] = heapSize;
      for(int i=1; i<=heapSize; i++)
        mHeap[i] = Integer.parseInt( keys[i-1] );

      buildMaxHeap(mHeap);

      StringBuilder buf = new StringBuilder();
      for(int i=1; i<mHeap.length; i++) 
        buf.append(" ").append(mHeap[i]);

      System.out.println(buf);
    } catch(IOException e) {
      System.out.println("IOException!");
    }
  }
  private void buildMaxHeap(int[] heap) {
    for(int i= heap[0]/2; i>0; i--)
      maxHeapify(heap, i);
  }
  private void maxHeapify(int[] heap, int node) {
    int t,left,right,largest;
    left  = nodeLeft(node);
    right = nodeRight(node);

    if( (left <= heap[0]) && (heap[left] > heap[node]) )
      largest = left;
    else
      largest = node;
    if( (right <= heap[0]) && (heap[right] > heap[largest]) )
      largest = right;

    if( largest != node ) {
      t = heap[node]; heap[node] = heap[largest]; heap[largest] = t;

      maxHeapify(heap, largest);
    }
  }
  private int nodeLeft(int node) {
    return node*2;
  }
  private int nodeRight(int node) {
    return node*2+1;
  }
}


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

#define MAX 4000001

signed main()
{
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++)cin >> v[i];
	int s = accumulate(v.begin(), v.end(), 0);
	bitset<MAX> bit;
	bit.reset();
	bit[0] = 1;
	for (int val : v)bit = bit | (bit << val);
	int i;
	for (i = (s + 1) / 2; i <= s; i++)if (bit[i])break;
	cout << i << endl;
}


Measured memory_bytes: 2304
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;
#pragma endregion

#pragma region const
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#pragma endregion

#pragma region util
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}
#pragma endregion

#pragma region init
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

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

int main()
{
	i64 N;
	cin >> N;
	i64 max_l = 0;
	i64 sum_l = 0;
	REP(i, N)
	{
		i64 l;
		cin >> l;
		sum_l += l;
		if (max_l < l)
			max_l = l;
	}

	cout << (max_l < (sum_l - max_l) ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


int main() {
	int dbs[110] = { 0 };
	int ipts;
	int ans = 0;

	for (int i = 0; i < 3; i++) {
		cin >> ipts;
		dbs[ipts] = 1;
	}
	for (int i = 0; i <= 100; i++) {
		if (dbs[i] > 0)ans++;

	}
	cout << ans << endl;









	return 0;
}

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

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF = 1<<29;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0,1,0,-1};
constexpr int dj[] = {1,0,-1,0};

int h, w, ans;

void solve(vector<vector<int> > &a, vector<queue<P> > que, int cnt = -1){
    bool update = false;
    vector<P3> tmp;
    auto q = que;
    for(int k=0;k<3;k++){
        if(que[k].empty()) continue;
        update = true;
        tmp.clear();
        while(!que[k].empty()){
            P p = que[k].front();
            que[k].pop();
            int i = p.first, j = p.second;
            for(int x=0;x<4;x++){
                int ni = i+di[x], nj = j+dj[x];
                if(ni < 0 || ni >= h) continue;
                if(nj < 0 || nj >= w) continue;
                if(a[ni][nj] != 4){
                    tmp.push_back(P3(a[ni][nj],P(ni,nj)));
                    que[a[ni][nj]].push(P(ni,nj));
                    a[ni][nj] = 4;
                }
            }
        }
        if(ans >= cnt) solve(a, que, cnt+1);
        for(auto pp : tmp){
            int i = pp.second.first, j = pp.second.second;
            a[i][j] = pp.first;
        }
        que = q;
    }
    if(!update) ans = min(ans, cnt);
}

int main(){
    vector<vector<int> > a;
    while(cin >> w >> h, w){
        a.clear();
        a.resize(h, vector<int>(w));
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                char c;
                cin >> c;
                if(c == 'R') a[i][j] = 0;
                if(c == 'G') a[i][j] = 1;
                if(c == 'B') a[i][j] = 2;
            }
        }
        ans = INF;
        vector<queue<P> > q(3);
        q[a[0][0]].push(P(0,0));
        a[0][0] = 4;
        solve(a, q);
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3308
use std::io::*;
fn main() {

    let mut ap = String::new();
    stdin().read_line(&mut ap).unwrap();
    let a: usize = ap.trim().split_whitespace().collect::<Vec<&str>>()[0].parse().unwrap();
    let p: usize = ap.trim().split_whitespace().collect::<Vec<&str>>()[1].parse().unwrap();
    let k = a * 3 + p;
    println!("{}",k / 2);


}


Measured memory_bytes: 4352
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
#print(a)
Alice=[]
Bob=[]
for i in range(n):
            if i%2==0:
                        Alice.append(a[i])
            else:
                        Bob.append(a[i])
#print('Alice',Alice)
#print('Bob',Bob)

print((sum(Alice))-(sum(Bob)))
            


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int q;
  cin >> q;
  vector<set<int>> table(26);
  rep(i,s.size()) table[s[i]-'a'].insert(i);
  rep(query,q){
    int com;cin >> com;
    if(com == 1){
      int i;
      char ch;
      cin >> i >> ch;
      --i;
      table[s[i]-'a'].erase(i);
      s[i] = ch;
      table[ch-'a'].insert(i);
    }else{
      int ans = 0;
      int l,r;cin >> l >> r;
      --r;--l;
      rep(j,26){
        set<int>::iterator it = table[j].lower_bound(l);
        if(it != table[j].end() && *it <= r) ans++;
      }
      printf("%d\n",ans);
    }
  }
}

Measured memory_bytes: 27240
N=int(input())
A=list(map(int,input().split()))

A.sort(reverse=True)

ans=A[0]

if N%2==0:
    mat=N//2
    for i in range(mat-1):
        ans+=2*A[1+i]
else:
    mat=(N-1)//2
    for j in range(mat-1):
        ans+=2*A[1+j]
    ans+=A[mat]
print(ans)

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

#define pb push_back
#define mp make_pair
#define size(n) ( int( n.size() ) )
#define sqr(n) ( (n) * (n) )
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 5;
int a[N];
ll ans = 0;

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    scanf("%d",&n);
    for ( int i = 1; i <= n; i++ ){
        scanf("%d",&a[i]);
    }
    sort( a + 1, a + n + 1 );
    int l = 1, r, mx = 0;
    while( l <= n ){
        r = l;
        while( ( r <= n ) && ( a[l] == a[r] ) ){
            r++;
        }
        if ( r - l >= 4 ){
            ans = max( ans, a[l] * 1ll * a[l] );
        }
        if ( r - l >= 2 ){
            ans = max( ans, mx * 1ll * a[l] );
            mx = max( mx, a[l] );
        }
        l = r;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 640
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    data = sc.strarr()
    stack = []
    for d in data:
        if d == '+':
            stack.append(stack.pop() + stack.pop())
        elif d == '-':
            stack.append(((-1) * stack.pop()) + stack.pop())
        elif d == '*':
            stack.append(stack.pop() * stack.pop())
        else:
            stack.append(int(d))
    print(stack[0])


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


main()



Measured memory_bytes: 5676
# Reference: https://note.nkmk.me/python-union-find/
class UnionFind:
    # if x is root: self.parents[x] = -(the number of the group nodes)
    # else: self.parents[x] = the parent of x
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # return the parent of x
    def find(self, x):
        history = []
        while self.parents[x] >= 0:
            history.append(x)
            x = self.parents[x]
        for node in history:
            self.parents[node] = x
        return x

    # merge the group of x and the group of y
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 0
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        return 1

from sys import stdin
input = stdin.buffer.readline

def main():
    n, m = map(int, input().split())

    uf = UnionFind(n)

    ans = n - 1
    for _ in range(m):
        a, b = map(int, input().split())
        ans -= uf.union(a-1, b-1)

    print(ans)

main()


Measured memory_bytes: 69780
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
#include<iomanip>
#include<bits/stdc++.h>
#define swap(type ,a ,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(i=0;i<n;i++)
#define forR(i,s,n) for(i=s;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}
#define DOUBLE fixed << setprecision(15)

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

int main(){
    int r;
    cin >> r;
    cout << r*r << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>

#define MOD 1000000007

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;

int main(void)
{
	vector<bool> judge(8, false);
	int N; cin >> N;
	int other = 0;
	rep(i, 0, N) {
		int a; cin >> a;
		if (a < 400)judge[0] = true;
		else if (a < 800)judge[1] = true;
		else if (a < 1200)judge[2] = true;
		else if (a < 1600)judge[3] = true;
		else if (a < 2000)judge[4] = true;
		else if (a < 2400)judge[5] = true;
		else if (a < 2800)judge[6] = true;
		else if (a < 3200)judge[7] = true;
		else other++;
	}

	int ans = 0;
	rep(i, 0, 8) {
		if (judge[i] == true)ans++;
	}

	cout << max(ans, 1) << " " << ans + other << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
n = int(input())
d = {}
lines = sys.stdin.readlines()
ans = [None] * n
for i in range(n):
    q, *arg = lines[i].split()
    if q == '0':
        d[arg[0]] = arg[1]
    elif q == '1':
        ans[i] = d[arg[0]]

[print(x) for x in ans if x is not None]


Measured memory_bytes: 59580
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {
  int n; cin >> n;
  vector<int> h(n);
  for(int i=0; i<n; i++) cin >> h[i];
  vector<int> c(n+1, 1e9);
  c[0] = 0; c[1] = abs(h[1]-h[0]);
  for(int i=2; i<n; i++){
    c[i] = min(c[i-1]+abs(h[i]-h[i-1]), c[i-2]+abs(h[i]-h[i-2]));
  }
  cout << c[n-1] << "\n";

  return 0;
}



///


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{
  int h,w;
  while(1)
  {
    cin>>h>>w;
    if((h==0)&&(w==0)) break;
    for(int i=0;i<h;i++)
    {
      for(int j=0;j<w;j++)
        cout<<(((i+j)%2==0)?'#':'.');
      cout<<endl;
    }
    cout<<endl;
  }
}

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

int main ()
{
	char o[55], e[55];
  	int i = 0;
	cin >> o;
	cin >> e;
	for (i = 0; o[i] != '\0' && e[i] != '\0'; i++) {
	    cout << o[i] << e[i];
	}
  	if (o[i] != '\0') cout << o[i];
	return 0;
}

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

int main(void){
  int n, m, x;
  int a;
  int i;
  int c1=0;
  int c2=0;
  
  scanf("%d %d %d", &n, &m, &x);
  for(i=0;i<m;i++){
    scanf("%d", &a);
    if(a<x){
      c1++;
    }else if(a>x){
      c2++;
    }
  }
  printf("%d", (c1 > c2) ? c2 : c1);
  return 0;
}

Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var n, change, count int
	var a [100]int
	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	k := 1
	flag := true
	for flag == true {
		flag = false
		for j := n - 1; j >= k; j-- {
			if a[j] < a[j-1] {
				change = a[j]
				a[j] = a[j-1]
				a[j-1] = change
				count++
				flag = true
			}
		}
		k++
	}
	for i := 0; i < n-1; i++ {
		fmt.Printf("%d ", a[i])
	}
	fmt.Println(a[n-1])
	fmt.Println(count)
}



Measured memory_bytes: 1184
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math;
import core.stdc.stdio;
import std.container.rbtree;
// foreach, foreach_reverse, writeln

class UnionFind {
	int[] data;
	this(int n) {
		data = new int[n];
		data[] = -1;
	}
	int find(int v) {
		if (data[v] < 0) return v;
		return data[v] = find(data[v]);
	}
	bool join(int u, int v) {
		u = find(u);
		v = find(v);
		if (u == v) return false;
		if (data[u] > data[v]) swap(u,v);
		data[u] += data[v];
		data[v] = u;
		return true;
	}
}

alias set = RedBlackTree!int;

void main() {
	int n, m;
	scanf("%d%d", &n, &m);
	int[] p = new int[n];
	foreach (i; 0..n) scanf("%d", &p[i]);
	auto uf = new UnionFind(n);
	foreach (i; 0..m) {
		int x, y;
		scanf("%d%d", &x, &y);
		uf.join(x-1, y-1);
	}
	set[] s = new set[n];
	foreach (i; 0..n) s[i] = new set();
	foreach (i; 0..n) {
		int g = uf.find(i);
		s[g].insert(i);
	}
	int ans = 0;
	foreach (i; 0..n) {
		int g = uf.find(i);
		ans += s[g].equalRange(p[i]-1).empty?0:1;
	}
	writeln(ans);
}

Measured memory_bytes: 18556
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def is_kaibun(kaibun):
    for i in range(len(kaibun)//2):
        if kaibun[i] != kaibun[-i-1]:
            return False
    return True    

def solve(S: str):
    all = is_kaibun(S)
    zenhan = is_kaibun(S[:len(S)//2])
    kouhan = is_kaibun(S[len(S)//2+1:])
    if all and zenhan and kouhan:
        print(YES)
    else:
        print(NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

int main()
{
	ll n;cin >> n;
	ll ans = 1;
	for(ll i = 2;i*i<=n;i++)
	{
		if(n%i==0)ans = i;
	}
	cout<<n/ans+ans-2<<endl;
	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
x=list(map(int,input().split()))
ans=10**9
for i in range(n-k+1):
    if x[i+k-1]<=0:
        ans=min(ans,-x[i])
    elif x[i]>=0:
        ans=min(ans,x[i+k-1])
    else:
        ans=min(ans,x[i+k-1]-x[i]+min(x[i+k-1],-x[i]))
print(ans)

Measured memory_bytes: 14224
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

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

    int ans = 0;
    int l = 0;
    while(l < n-1){
        int tmp = 0;
        int a = l;
        while(a+1 < n && h[a] >= h[a+1]){
            tmp++;
            a++;
        }
        ans = max(ans, tmp);
        l = a+1;
    }
    cout << ans << endl;
    return 0;
}


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

int insertionSort(int* A,int n,int g,int cnt){
  for(int i=g;i<n;i++){
    int v = A[i], j = i - g;
    while(j >= 0 && A[j] > v){
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
  }
  return cnt;
}

int main(){
  int n,m=0,g=0,cnt=0;
  cin >> n;
  int* A = new int[n];
  for(int i=0;i<n;i++){
    cin >> A[i];
  }

  while(true){
    if(3*g+1 > n)break;
    g = 3*g+1;
    m++;
  }
  int g_max = g;
  for(int i=0;i<m;i++){
    cnt = insertionSort(A, n, g, cnt);
    g = (g-1)/3;
  }

  cout << m << endl;
  for(int i=0;i<m;i++){
    cout << (i !=0 ? " ": "") << g_max;
    g_max = (g_max-1)/3;
  }
  cout << endl;
  cout << cnt << endl;
  for(int i=0;i<n;i++){
    cout << A[i] << endl;
  }

  delete[] A;
}


Measured memory_bytes: 6736
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	int n, m;
	cin >> n >> m;
	int mask[10], parity[10];
	rep(i, m){
		int k;
		cin >> k;
		mask[i] = 0;
		rep(j, k){
			int d;
			cin >> d;
			mask[i] |= (1 << (d - 1));
		}
	}

	rep(i, m) cin >> parity[i];

	int ans = 0;
	rep(amask, 1 << n){
		bool ok = true;
		rep(i, m){
			const int tmp = amask & mask[i];
			if(__builtin_popcount(tmp) % 2 != parity[i]) ok = false;
		}
		if(ok) ans++;
	}

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

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

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

    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];

    map<int, int> mp;
    rep(i, 0, n) {
        mp[a[i]]++;
    }

    long long ans = 0;
    for (auto e: mp) {
        ans += (long)e.second * (e.second - 1) / 2;
    }

    rep(i, 0, n) {
        cout << ans - (long)(mp[a[i]] - 1) << endl;
    }

    return 0;
}

Measured memory_bytes: 8320
def meu_map(l):
    for i in range(len(l)):
        l[i] = int(l[i])


n = int(raw_input())
array = raw_input().split()

meu_map(array)

fatores = 0
for e in array:
    while e != 1:
        if e % 2 == 0:
            e /= 2
            fatores += 1
        else:
            break

print(fatores)

Measured memory_bytes: 33132