akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int n;
vector<vector<int>> g;
vector<int> bs, wss;

bool path(int cur, int prev, vector<int>& route)
{
    route.push_back(cur);

    if (cur == n - 1) {
        for (int i = 0; i < route.size(); i++) {
            int j = route.size() - 1 - i;
            if (i <= j) {
                bs.push_back(route[i]);
            }
            if (i < j) {
                wss.push_back(route[j]);
            }
        }
        return true;
    }

    for (auto& n : g[cur]) {
        if (n == prev)
            continue;

        if (path(n, cur, route)) {
            return true;
        }
    }

    route.pop_back();
    return false;
}

int paint(int cur, int prev, vector<bool>& nn)
{
    if (nn[cur])
        return 0;

    nn[cur] = true;
    int ret = 1;
    for (auto& n : g[cur]) {
        if (n == prev)
            continue;
        ret += paint(n, cur, nn);
    }
    return ret;
}

int main()
{
    cin.tie(0);

    cin >> n;
    g.resize(n);

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> route;
    path(0, -1, route);

    int bc = 0, wc = 0;
    {
        vector<bool> bnode(n);
        for (auto& w : wss) {
            bnode[w] = true;
        }
        for (auto& b : bs) {
            bc += paint(b, -1, bnode);
        }
    }
    {
        vector<bool> wnode(n);
        for (auto& b : bs) {
            wnode[b] = true;
        }
        for (auto& w : wss) {
            wc += paint(w, -1, wnode);
        }
    }

    // cerr << bc << ", " << wc << endl;

    if (bc > wc) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }

    return 0;
}


Measured memory_bytes: 13048
import math

a, b, h, m = map(int, input().split())

minute = 60 * h + m
argA = minute / 720 * 2 * math.pi
argB = minute / 60 * 2 * math.pi
a_x = a * math.cos(argA)
a_y = a * math.sin(argA)
b_x = b * math.cos(argB)
b_y = b * math.sin(argB)
d = math.sqrt((a_x - b_x) ** 2 + (a_y - b_y) ** 2)

print(d)

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

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

    long long sum1 = 0, res1 = 0;
    for (int i = 0; i < N; i++) {
        sum1 += A[i];
        if (i % 2 == 0 && sum1 <= 0) {
            res1 += (1 - sum1);
            sum1 = 1;
        }
        if (i % 2 == 1 && sum1 >= 0) {
            res1 += (sum1 + 1);
            sum1 = -1;
        }
    }

    long long sum2 = 0, res2 = 0;
    for (int i = 0; i < N; i++) {
        sum2 += A[i];
        if (i % 2 == 0 && sum2 >= 0) {
            res2 += (1 + sum2);
            sum2 = -1;
        }
        if (i % 2 == 1 && sum2 <= 0) {
            res2 += (1 - sum2);
            sum2 = 1;
        }
    }

    cout << min(res1, res2) << endl;
    return 0;
}

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

typedef long long ll;

int N, A, B, C;
vector<int> l(8);

int magic(int cnt, int a, int b, int c) {
    if (cnt == N) {
        if (min(a, min(b, c)) > 0) {
            return abs(a - A) + abs(b - B) + abs(c - C) - 30;
        } else {
            return 1000000001;
        }
    } 
    int use0 = magic(cnt + 1, a, b, c);
    int useA = magic(cnt + 1, a + l[cnt], b, c) + 10;
    int useB = magic(cnt + 1, a, b + l[cnt], c) + 10;
    int useC = magic(cnt + 1, a, b, c + l[cnt]) + 10;
    return min(use0, min(useA, min(useB, useC)));
}

signed main() {
cin >> N >> A >> B >> C;
for (int i = 0; i < N; i++) {
    cin >> l[i];
}

cout << magic(0, 0, 0, 0) << endl;

}

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

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

using namespace std;

int gcd(int a,int b){ return b?gcd(b,a%b):a; }

int main(){
	int n,a[100000]; cin>>n;
	rep(i,n) cin>>a[i];

	int right[100001];
	right[n]=0;
	rep(i,n) right[n-i-1]=gcd(right[n-i],a[n-i-1]);

	int left=0,ans=0;
	rep(i,n){
		ans=max(ans,gcd(left,right[i+1]));
		left=gcd(left,a[i]);
	}
	cout<<ans<<endl;

	return 0;
}


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


/* macro */
//#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define sec second
#define fir first
#define pb push_back



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
//const int inf = pow(2, 62);
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};



/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


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




/* main */



signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int r, g; cin >> r >> g;

    print(g * 2 - r);
    

    
    




    
    



    
    

    







   




    

    

    




    



    



    

 
    
    


    

    
   
    













}






    










    




    










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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
typedef long long LL;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    //freopen("input.txt", "r", stdin);
  #endif // LOCAL
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) cout << "x";
  cout << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

using namespace std;
using pii=pair<int,int>;
using ll=long long;

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

    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    for(int i=0; i<n; i++) cin>>h[i];
    vector<int> dp(n,INT_MAX);
    dp[0]=0;
    for(int i=1; i<n; i++){
        for(int j=1; j<=k; j++){
            if(i-j<0) continue;
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }        
    }
    cout<<dp[n-1];
    
    return 0;
}


Measured memory_bytes: 3972
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    int n;

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

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        solve();
    }

    void solve() {
        int[] candidates = {1, 6, 36, 216, 6 * 6 * 6 * 6,
            6 * 6* 6 * 6* 6, 6 * 6 * 6 * 6 * 6 * 6, 9, 81, 729,
            9 * 9 * 9 * 9, 9 * 9 * 9* 9* 9};
        int[] dp = new int[100001];
        Arrays.fill(dp, 1 << 30);
        dp[0] = 0;
        for (int i = 0; i < 100001; i++) {
            for (int j = 0; j < candidates.length; j++) {
                if (candidates[j] > i) {
                    continue;
                }
                dp[i] = Math.min(dp[i], dp[i - candidates[j]] + 1);
            }
        }
        System.out.println(dp[n]);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

char check(vector<vector<char>> &mine,int i,int j,int a,int b){
  int count=0;
  if(i>0){
    if(mine.at(i-1).at(j)=='#')
      count++;
    if(j>0&&mine.at(i-1).at(j-1)=='#')
      count++;
    if(j<b&&mine.at(i-1).at(j+1)=='#')
      count++;
  }
  if(i<a){
    if(mine.at(i+1).at(j)=='#')
      count++;
    if(j>0&&mine.at(i+1).at(j-1)=='#')
      count++;
    if(j<b&&mine.at(i+1).at(j+1)=='#')
      count++;
  }
  if(j>0&&mine.at(i).at(j-1)=='#')
    count++;
  if(j<b&&mine.at(i).at(j+1)=='#')
    count++;
  char sum ='0'+count ;
  return sum;
}

int main(){
  int a,b;
  cin>>a>>b;
  vector<vector<char>> mine(a,vector<char>(b));
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      cin>>mine.at(i).at(j);
    }
  }
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      if(mine.at(i).at(j)=='.')
        mine.at(i).at(j)=check(mine,i,j,a-1,b-1);
    }
  }
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      cout<<mine.at(i).at(j);
    }
    cout<<endl;
  }
}


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

int main() {
  int x, y;
  cin >> x >> y;
  for (int i = 0; i <= x; ++i) {
    for (int j = 0; j <= x; ++j) {
      if (i + j == x && 2 * i + 4 * j == y) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3632
#pragma once

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ull mod = 1000000007;

class Primes {
private:
	vector<int> Prime_Number;
	vector<bool> is_prime_;
public:
	Primes(int N) {
		is_prime_.resize(N + 1, true);
		is_prime_[0] = is_prime_[1] = false;
		for (int i = 0; i < N + 1; i++) {
			if (is_prime_[i]) {
				Prime_Number.push_back(i);
				for (int j = 2 * i; j <= N; j += i) is_prime_[j] = false;
			}
		}
	}
	int operator[](int i) { return Prime_Number[i]; }
	int size() { return Prime_Number.size(); }
	int back() { return Prime_Number.back(); }
	bool isPrime(int q) { return is_prime_[q]; }
};

class Divisor {
private:
	vector<ll> F;
	vector<pair<ll, ll>> pfactorize;
public:
	Divisor(ll N) {
		for (ll i = 1; i * i <= N; i++) {
			if (N % i == 0) {
				F.push_back(i);
				if (i * i != N) F.push_back(N / i);
			}
		}
		sort(begin(F), end(F));
		Primes p((ll)sqrt(N) + 1);
		for (int i = 0; i < p.size(); i++) {
			pfactorize.emplace_back(p[i], 0);
			while (N % p[i] == 0) {
				N /= p[i];
				pfactorize.back().second++;
			}
			if (pfactorize.back().second == 0) pfactorize.pop_back();
		}
		if (N > 1) pfactorize.emplace_back(N, 1);
	}
	int size() { return F.size(); }
	const vector<pair<ll, ll>>& pfac() { return pfactorize; } const
	ll operator[](int k) { return F[k]; }
};

int main(void)
{
	ll n, k;
	cin >> n >> k;
	vector<ll> vs(n);
	rep(i, n) cin >> vs[i];
	ll sum = 0;
	rep(i, n) sum += vs[i];
	Divisor d(sum);
	ll minValue = 1;
	vector<ll> buf(n);
	rep(a, d.size()) {
		ll div = d[a];
		rep(i, n) {
			buf[i] = vs[i] % div;
		}
		sort(buf.begin(), buf.end());
		
		vector<long> p(n + 1);
		vector<long> q(n + 1);
		for (int i = 0; i < n; ++i) p[i + 1] = p[i] + buf[i];
		for (int i = n; i > 0; --i) q[i - 1] = q[i] + div - buf[i - 1];
		for (int i = 0; i <= buf.size(); ++i) {
			if (p[i] == q[i]) {
				int ans = p[i];
				if (ans <= k) {
					minValue = max(minValue, div);
					break;
				}
			}
		}		
	}
	cout << minValue << endl;
	return 0;
}


Measured memory_bytes: 764
#include <iostream>

using namespace std;

int searcher(int A[],int n,int key)
{
    int i=0;
    A[n]=key;
    while(A[i]!=key) i++;
    return (i!=n);
}

int main()
{
    int A[10000+10],key,q,n;
    int sum=0;
    cin>>n;
    for(int i=0;i<n;i++) cin>>A[i];
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>key;
        if(searcher(A,n,key)) sum++;
    }
    cout<<sum<<endl;
    return 0;

}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;
    string s;
    cin>>s;
    int flag=1;
    rep(i,0,s.size())
    {
        if(i%2==0 && s[i]=='L')flag=0;
        if(i%2==1 && s[i]=='R')flag=0;

    }
    if(flag)cout<<"Yes";
    else cout<<"No";
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

bool exist[26];
int main()
{
    int N;
    string s;
    cin >> N >> s;

    int mcnt = 0;
    for(int i = 1; i < N; ++i){
        string x = s.substr(0, i);
        string y = s.substr(i); 
        for(int j = 0; j < x.size(); j++){
            for(int k = 0; k < y.size(); k++){
                if(x[j] == y[k])
                    exist[x[j] - 'a'] = true;
            }
        }
        int cnt = 0;
        for(int j = 0; j < 26; ++j)
            if(exist[j] == true){
                cnt++;
                exist[j] = false;
            }
        mcnt = max(mcnt, cnt);
    }

    cout << mcnt << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner (System.in);
        double r = scanner.nextDouble();
        double a = r*r*Math.PI ;
        double b = 2*r*Math.PI ;
        System.out.printf("%f %f",a,b);
    }
}


Measured memory_bytes: 28260
#x = int(input())
#A = list(map(int, input().split()))
#l, r, d = map(int, input().split())
S = input()

if S.count("R") == 0:
  print(0)
elif S.count("R") == 1:
  print(1)
elif S.count("R") == 3:
  print(3)
elif S.count("R") == 2:
  if S[1] == "S":
    print(1)
  else:
    print(2)

Measured memory_bytes: 9104
def max_heapify(nodes, idx):
    left_idx = idx * 2
    right_idx = idx * 2 + 1

    max_idx = idx

    if left_idx <= len(nodes) and nodes[left_idx-1] > nodes[max_idx-1]:
        max_idx = left_idx
    if right_idx <= len(nodes) and nodes[right_idx-1] > nodes[max_idx-1]:
        max_idx = right_idx

    if max_idx != idx:
        tmp = nodes[idx-1]
        nodes[idx-1] = nodes[max_idx-1]
        nodes[max_idx-1] = tmp
        max_heapify(nodes, max_idx)
    return


def build_maxheap(nodes):
    for i in range(1, len(nodes)//2 + 1)[::-1]:
        max_heapify(nodes, i)
    return


def main():
    num_node = int(input())
    nodes = [int(x) for x in input().split()]
    build_maxheap(nodes)
    print(" " + " ".join(map(str, nodes)))
    return


main()


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

int digit(int x) {
 if (x < 10) {
   return 10;}
  else if (x == 100) {
    return 1000;}
  else {return 100;}
}

int main() {
  int a, b;
  cin >> a >> b;
  int c = a * digit(b) + b;
  
  int i = 0;
  while (i * i < c) {
  	i++;
    if (i * i == c) {
    cout << "Yes" << endl;
      break;
    } else if (i * i > c) {
      cout << "No" << endl;
      break;
    }
  }
}


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

using namespace std;

int main(){
  char s[4];
  cin >> s;

  set<char> ans;
  ans.insert(s[0]);
  ans.insert(s[1]);
  ans.insert(s[2]);
  ans.insert(s[3]);

  if( ans.size() == 2 ) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 100001
 
main()
{
  short *A, change, x;
  int i, j, r, n, p=0, kakko;
 
  scanf("%d", &n);
  A = malloc(sizeof(short)*n + 1);
 
  for(i=0; i<n; i++)
    {
      scanf("%hu", &A[i]);
    }
 
  r = i-1;
  x = A[r];
  i = p - 1;
  for(j=p; j<r; j++)
    {
      if(A[j] <= x)
    {
      i = i + 1;
      change = A[j];
      A[j] = A[i];
      A[i] = change;
    }
    }
  change = A[r];
  A[r] = A[i+1];
  A[i+1] = change;
  kakko = i+1;
 
  for(i=0; i<n; i++)
    {
      if(i == kakko)
    {
      printf("[%d] ", A[i]);
      continue;
    }
 
      printf("%d", A[i]);
      if(i != n-1)
    {
      printf(" ");
    }
    }
  printf("\n");
 
  free(A);
  return 0;
}

Measured memory_bytes: 704
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		while(true){
			String s=Console.ReadLine();
			if(s==null)break;
			Sol mySol=new Sol(s);
			Console.WriteLine(mySol.Ans);
		}
	}
}


class Sol{
	String ans;
	public String Ans{
		get{return ans;}
	}
	
	
	public Sol(String expr){
		String A=expr.Substring(0,expr.IndexOf("+"));
		String B=expr.Substring(expr.IndexOf("+")+1,(expr.IndexOf("=")-expr.IndexOf("+")-1));
		String C=expr.Substring(expr.IndexOf("=")+1);
		bool chk=false;
		for(char x='0';x<='9';x++){
			chk=CheckCal(A,B,C,x);
			if(chk){ans=x.ToString();return;}
		}
		ans="NA";
	}
	
	bool CheckCal(String A,String B,String C,char X){
		
		int MaxLength=C.Length;
		if(MaxLength<A.Length || MaxLength<B.Length)return false;
		
		char[] Carr=C.ToCharArray();
		char[] Aarr=new char[MaxLength];
		char[] Barr=new char[MaxLength];
		var t=A.ToCharArray();
		int i=0;
		int j=MaxLength-1;
		for(i=t.Length-1;i>=0;i--){
			Aarr[j]= t[i]=='X'?X:t[i];
			j--;
		}
		for(;j>=0;j--)Aarr[j]='0';

		var tt=B.ToCharArray();
		j=MaxLength-1;				
		for(i=tt.Length-1;i>=0;i--){
			Barr[j]= tt[i]=='X'?X:tt[i];
			j--;
		}
		for(;j>=0;j--)Barr[j]='0';

		for(i=MaxLength-1;i>=0;i--){
			Carr[i]= Carr[i]=='X'?X:Carr[i];
		}
	
		int carry=0;
		for(i=MaxLength-1;i>=0;i--){
			int sum=(int)(Aarr[i]-'0'+Barr[i]-'0')+carry;
			carry=sum/10;
			if(((int)(Carr[i]-'0'))!=sum%10)return false;
		}
		return true;
	}
}



static class dbg{
	public static void w(String s){
		Console.WriteLine(s);
	}
	public static void w(int d){
		Console.WriteLine(d);
	}
	public static void w(long d){
		Console.WriteLine(d);
	}
}

Measured memory_bytes: 6320
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);

    int array_length = scan.nextInt();

    int[] array =new int[array_length];
    for (int i = 0; i < array_length; i++) {
      array[i] = scan.nextInt();
    }

    bubbleSort(array_length, array);
  }

  public static void printArray(int array[], int count) {
  	for (int i = 0; i < array.length-1 ; i++) {
  	    System.out.print(array[i] + " ");
  	}
    System.out.println(array[array.length-1]);
  	System.out.println(count);
  }

  public static void bubbleSort(int n, int array[]){

    int count = 0;
    for(int i = 0; i < n; i++){
      for(int j = n-1; j >= i+1; j--){
        if(array[j] < array[j-1]){
          int swap = array[j];
          array[j] = array[j-1];
          array[j-1] = swap;
          count++;
        }
      }
    }
    printArray(array, count);


  }
}


Measured memory_bytes: 26332
n, k = map(int, input().split())
a = list(map(int, input().split()))

table = [0]
dic = dict()
dic[0] = 1

nxt = a[0] - 1
x = None

while True:
    table.append(nxt)
    if not nxt in dic:
        dic[nxt] = 1
    else:
        x = nxt
        break
    nxt = a[nxt] - 1
    
cnt = 0
while table[cnt] != x:
    cnt += 1

roop = len(table) - 1 - cnt

if k <= cnt:
    print(table[k] + 1)
else:
    k -= cnt
    k %= roop
    print(table[cnt + k] + 1)

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

using namespace std;

const int N = 1e5 + 3;
char a[N];
int n;

int calc(int tp) {
	int res = 0;
	for (int i = 1; i <= n; ++i)
		if (a[i] - '0' != (i + tp) % 2)
			res++;
	return res;
}

int main() {
	scanf("%s", a + 1);
	n = int(strlen(a + 1));
	printf("%d", min(calc(0), calc(1)));
	return 0;
}	


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pld;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;

double dist(pd a, pd b){
    double ans=sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));
    return ans;
}



int main(){
    double N;
    cin>>N;
    vpd xy(N);
    F0R(i,N){
        cin>>xy[i].first>>xy[i].second;
    }
    double ans;
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            ans+=dist(xy[i],xy[j]);
        }
    }
    ans=ans*2/N;
    cout.precision(12);
    out(ans);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    char S[30];
    scanf("%s", S);
    S[5] = ' ';
    S[13] = ' ';
    printf("%s\n", S);
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 6000;
int a[N];
bool L[N][N], R[N][N];
int sum[N][N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  L[0][0] = true;
  for (int i = 0; i < n; ++i) {
    copy(L[i], L[i] + m, L[i + 1]);
    for (int j = m - 1; j >= a[i]; --j) {
      L[i + 1][j] |= L[i][j - a[i]];
    }
  }
  R[n][0] = true;
  for (int i = n - 1; i >= 0; --i) {
    copy(R[i + 1], R[i + 1] + m, R[i]);
    for (int j = m - 1; j >= a[i]; --j) {
      R[i][j] |= R[i + 1][j - a[i]];
    }
  }
  for (int i = 0; i <= n; ++i) {
    sum[i][0] = 0;
    for (int j = 1; j <= m; ++j) {
      sum[i][j] = sum[i][j - 1] + R[i][j - 1];
    }
  }
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    int vl = max(0, m - a[i]), vr = m - 1;
    bool found = false;
    for (int j = 0; j <= vr; ++j) {
      if (!L[i][j]) continue;
      int kr = vr - j, kl = max(0, vl - j);
      if (sum[i + 1][kr + 1] - sum[i + 1][kl] > 0) {
        found = true;
        break;
      }
    }
    if (!found) ++ret;
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 184576
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	T := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	min := a[0]
	cnt := 0
	max_f := 0
	for i := 1; i < N; i++ {
		diff := a[i] - min

		if diff > max_f {
			max_f = diff
			cnt = 1
		} else if diff == max_f {
			cnt++
		}

		if min > a[i] {
			min = a[i]
		}
	}

	ans := cnt
	if T < ans {
		//		ans = T
	}
	out(ans)
}


Measured memory_bytes: 3072
package main

import (
	"fmt"
	"strings"
)

func main() {
	var str string
	fmt.Scan(&str)
	s := strings.Split(str, "")
	cnt := 0
	for i := 0; i < len(s); i++ {
		if s[i] == "1" {
			cnt++
		}
	}
	fmt.Print(cnt)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  long a,b,c=0,d=10000000,e,f,g,h,n,m,mx=0,x,y,ans=0;
  cin>>n>>a>>b;
  rep(i,1,n+1){
    x=i;
    rep(j,0,5){
      c+=x%10;
      x/=10;
    }
    if(a<=c && c<=b) ans+=i;
    c=0;
  }
  co(ans);
    
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}


vector<bool> prime(100000,true);
vector<int> a;

void init(){
	prime[0] = false;
	prime[1] = false;
	rep(i,100000){
		if(prime[i]){
			for(int j = i * 2; j < 100000; j += i){
				prime[j] = false;
			}
		}
	}
	rep(i,55556){
		if(prime[i] && i % 5 == 1) a.pb(i);
	}
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	init();
	int n;cin >> n;
	rep(i,n){
		if(i == n - 1) cout << a.at(i) << endl;
		else cout << a.at(i) << " ";
	}
}


Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : m : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  putStrLn $ if m == n then "Yes" else "No"

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
#![allow(unused_imports)]
use {
    itertools::Itertools,
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::ops::*,
};

#[allow(unused_macros)]
macro_rules !dbg {($($e :expr ) ,*) =>{#[cfg (debug_assertions ) ] $({let (e ,mut err ) =(stringify !($e ) ,std ::io ::stderr () ) ;writeln !(err ,"{} = {:?}" ,e ,$e ) .unwrap () } ) *} ;}

struct UnionFind {
    n: usize,
    par: Vec<usize>,
    rank: Vec<usize>,
}
impl UnionFind {
    fn new(n: usize) -> Self {
        UnionFind {
            n,
            par: (0..n).collect(),
            rank: vec![1; n],
        }
    }
    fn unite(&mut self, x: usize, y: usize) {
        if self.same(x, y) {
            return;
        }
        let rx = self.par[x];
        let ry = self.par[y];
        if self.rank[rx] > self.rank[ry] {
            self.par[ry] = rx;
            self.rank[rx] += self.rank[ry];
        } else {
            self.par[rx] = ry;
            self.rank[ry] += self.rank[rx];
        }
    }
    fn same(&mut self, x: usize, y: usize) -> bool {
        self.root(x) == self.root(y)
    }
    fn root(&mut self, x: usize) -> usize {
        if self.par[x] == x {
            x
        } else {
            self.par[x] = self.root(self.par[x]);
            self.par[x]
        }
    }
    #[allow(dead_code)]
    fn size(&mut self, x: usize) -> usize {
        let r = self.root(x);
        self.rank[r]
    }
    #[allow(dead_code)]
    fn sizes(&mut self) -> Vec<usize> {
        let mut s = vec![];
        for x in 0..self.n {
            if x == self.root(x) {
                s.push(self.rank[x]);
            }
        }
        s
    }
}

#[fastout]
fn main() {
    input! {
       n: usize,
       xy: [(Usize1, Usize1); n]
    }
    let mut xyi = xy
        .iter()
        .enumerate()
        .map(|(i, &(x, y))| (x, y, i))
        .collect::<Vec<_>>();
    xyi.sort();
    let mut uf = UnionFind::new(n);
    let mut s = vec![xyi[0].1];
    for &(_, y, _) in xyi.iter().skip(1) {
        if s[s.len() - 1] < y {
            let yi = s[s.len() - 1];
            while let Some(ym) = s.pop() {
                if ym > y {
                    s.push(ym);
                    break;
                }
                uf.unite(ym, y);
            }
            s.push(yi);
        } else {
            s.push(y);
        }
    }
    let mut ans = vec![0; n];
    for &(_, y, i) in xyi.iter() {
        ans[i] = uf.size(y);
    }
    println!("{}", ans.iter().format("\n"));
}


Measured memory_bytes: 17056
#include<bits/stdc++.h>
using namespace std;
string s,t,ans="";
int i,j,r;
int main(){
    cin>>s>>t;
    if(s.size()<t.size()){
        cout<<"UNRESTORABLE";
        return 0;
    }
    for(i=0;i<=s.size()-t.size();i++){
        int k=i;
        string ss=s;
        j=0;
        while(j<t.size()){
            if(ss[k]=='?')
                ss[k]=t[j];
            else if(s[k]!=t[j])
                break;
            k++;
            j++;
        }
        if(j==t.size()){
            for(r=0;r<ss.size();r++){
                if(ss[r]=='?')
                    ss[r]='a';
            }
            if(ans=="")
                ans=ss;
            else ans=min(ans,ss);
        }
    }
    if(ans=="")
        cout<<"UNRESTORABLE";
    else cout<<ans;
    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: 32840
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n; cin >> n;
    vector<int> a(n); cin >> a;
    map<int, int> m;
    REP(i, n) {
        m[a[i]]++;
    }
    vector<P> v(m.begin(), m.end());
    int vs = v.size();
    int M = v[vs-1].first;
    bool ans = true;
    if (M % 2 == 0) {
        FOR(i, M/2+1, M+1) {
            if (m[i] < 2) ans = false;
        }
        if (m[M/2] != 1) ans = false;
        REP(i, M/2) {
            if (m[i] > 0) ans = false;
        }
    }
    else {
        FOR(i, (M+1)/2+1, M+1) {
            if (m[i] < 2) ans = false;
        }
        if (m[(M+1)/2] != 2) ans = false;
        REP(i, (M+1)/2) {
            if (m[i] > 0) ans = false;
        }
    }

    if (ans) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}


Measured memory_bytes: 384
n, m, c = map(int, input().split())

b = list(map(int, input().split()))

a = []

cnt = 0
for i in range(n):
    s = list(map(int, input().split()))
    a.append(s)

for j in a:
    su = 0
    for k in range(m):
        su += j[k] * b[k]
    su += c
    if su > 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 
#define ALL(a)  (a).begin(),(a).end()



using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int a, int b)
{
  if(a>b){
    return gcd(b,a);
  }
	return a == 0 ? b : gcd(b % a, a);
}
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}

long long kaijo(long long x){
  long long l=10*10*10*10*10*10*10*10*10+7;
  long long sum=1;
  for(int i=x;i>0;i--){
    sum*=i;
    if(sum>l){
      sum%=l;
    }
  }
  return sum;
}






int main(){
  int N;
  cin>>N;
  long long A[N];
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  int x=0;
  if(A[0]>A[1]){
    x=1;
  }else if(A[0]<A[1]){
    x=-1;
  }
  int sum=0;
  for(int i=0;i<N-1;i++){
    if(x==0){
      if(A[i]>A[i+1]){
        x=1;
      }
      if(A[i]<A[i+1]){
        x=-1;
      }
    }else if(x==1){
      
      if(A[i]<A[i+1]){
        x=0;
        sum++;
      }
      

    }else if(x==-1){
      if(A[i]>A[i+1]){
        x=0;
        sum++;
      }
      

    }


  }
  
  cout<<sum+1<<endl;


}





  
  


  


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL M = 1000000007;

bool cmp(LL x,LL y){
	return ((x >= 0 ? x : -x) > (y >= 0 ? y : -y));
}
LL n,k;
LL a[500005],vis[500005];
LL ans = 1,fg = 0;

int main(){
	cin >> n >> k;
	for(LL i = 1;i <= n;i ++){
		cin >> a[i];
		if(a[i] >= 0) fg = 1;
	}
	if(k == n){
		for(LL i = 1;i <= n;i ++){
			ans *= a[i];
			ans %= M;
		}
		ans = (ans + M) % M;
		cout << ans << '\n'; return 0;
	}
	sort(a + 1,a + 1 + n,cmp);
	if((!fg) && (k & 1)){
		for(LL i = n;i >= n - k + 1;i --){
			ans *= a[i];
			ans %= M;
		}
		ans = (ans + M) % M;
		cout << ans << '\n';
	}
	else{
		LL mx = 1,mi = -1,idx[2],idi[2],tot = 0;
		idx[0] = idx[1] = -1; idi[0] = idi[1] = -1;
		for(LL i = 1;i <= k;i ++){
			vis[i] = 1;
			if((a[i] > mx || idx[0] == -1) && a[i] < 0){
				mx = a[i];
				idx[0] = i;
			}
			if((a[i] < mi || idi[0] == -1) && a[i] > 0){
				mi = a[i];
				idi[0] = i;
			}
			if(a[i] < 0) tot ++;
		}
		if(tot & 1){
			for(LL i = k + 1;i <= n + 1;i ++){
				if(a[i] >= 0){
					idx[1] = i;
					break;
				}
			}
			for(LL i = k + 1;i <= n + 1;i ++){
				if(a[i] <= 0){
					idi[1] = i;
					break;
				}
			}
			if(idx[0] == -1){ vis[idi[0]] = 0; vis[idi[1]] = 1; }
			if(idi[0] == -1){ vis[idx[0]] = 0; vis[idx[1]] = 1; }
			if(idx[0] != -1 && idi[0] != -1){
				if(a[idi[1]] * a[idx[0]] > a[idx[1]] * a[idi[0]]){ vis[idi[0]] = 0; vis[idi[1]] = 1; }
				else{ vis[idx[0]] = 0; vis[idx[1]] = 1; }
			}
		}
//		for(LL i = 1;i <= n;i ++) cout << a[i] << ' ' << vis[i] << endl;
		for(LL i = 1;i <= n;i ++) if(vis[i]) ans = (ans * a[i]) % M;
		ans = (ans + M) % M;
		cout << ans << '\n';
	}
	return 0;
}

Measured memory_bytes: 6692
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

//const int mod = 1000000007;
// mint(a).pow(b) -> a^b
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main () {
  int n;
  cin >> n;
  vll a(n);
  rep(i,n) cin >> a[i];

  ll ans = 0;
  rep(b,60) {
    ll bit = ((ll)1<<b); // (ll)をつけないと間違い、 mintはこのままだと使えない
    ll cnt = 0;
    rep(i,n) {
      if (a[i]&bit) cnt++;
    }
    //ans += bit*cnt*(n-cnt);
    ans += (((bit%mod)*cnt)%mod*(n-cnt))%mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>                                                                          
using namespace std;
int main()
{
  int k,x;
  cin >> k >> x;
  int sen=x+(k-1);
  int usi=x-(k-1);
  for(int i=usi; i<=sen; i++){
    cout << i;
    cout << " ";
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    
    int N;
    cin >> N;
    vector<int> P(N);
    rep(i,N) cin >> P[i];
    int count = 0;
    int minimum = INF;
    rep(i,N) {
        if (P[i] < minimum) {
            count++;
            minimum = P[i];
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 1024
require 'prime'

N = gets.strip.to_i

H = Hash.new(0)
(1..N).each do |i|
  i.prime_division.each do |n, f|
    H[n] += f 
  end
end
  
f = (0..74).map{|i| H.values.count{|j| j >= i}}
ans = f[4] * (f[4] - 1) / 2 * (f[2] - 2)
ans += f[14] * (f[4] - 1)
ans += f[24] * (f[2] - 1)
ans += f[74]

puts ans

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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int h = cin.Int();
			int w = cin.Int();
			string[] a = new string[h];
			for (int i = 0; i < h; i++) {
				a[i] = cin.Next();
			}

			bool[] hr = new bool[h];
			bool[] wr = new bool[w];
			for (int i = 0; i < h; i++) {
				bool removes = true;
				for (int j = 0; j < w; j++) {
					if (a[i][j] == '#') {
						removes = false;
						break;
					}
				}

				if (removes) {
					hr[i] = true;
				}
			}

			for (int j = 0; j < w; j++) {
				bool removes = true;
				for (int i = 0; i < h; i++) {
					if (a[i][j] == '#') {
						removes = false;
						break;
					}
				}

				if (removes) {
					wr[j] = true;
				}
			}

			var sb = new StringBuilder();
			for (int i = 0; i < h; i++) {
				if (hr[i]) {
					continue;
				}

				for (int j = 0; j < w; j++) {
					if (wr[j] == false) {
						sb.Append(a[i][j]);
					}
				}

				sb.AppendLine("");
			}

			Console.WriteLine(sb.ToString());
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 13140
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def coprime(a, b):
    return gcd(a, b) == 1

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

A,B=map(int, input().split())
if (A==1)or(B==1)or(coprime(A,B)):
  print(1)
else:
  A=make_divisors(A)
  B=make_divisors(B)
  C=list(set(A)&set(B))
  C.sort(reverse=True)
  count=0
  for i in range(len(C)):
    for j in range(i+1,len(C)):
      if (C[j]!=1)and(C[i]%C[j]==0):
        count=count+1
        break
  print(len(C)-count)

Measured memory_bytes: 5248
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
using namespace std;
int dx[5]={1,0,-1,0,0},dy[5]={0,1,0,-1,0};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
#define INF 2000000000
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int,int>

#define MAX 200005

int dat[MAX];

struct BIT{
	int bit[MAX];
	void init(){
		memset(bit, 0, sizeof(bit));
	}
	void add(int i,int x){
		i++;
		while(i<MAX){
			bit[i]+=x;
			i+=i&-i;
		}
	}
	int get(int i){
		i++;
		int ret=0;
		while(i>0){
			ret+=bit[i];
			i-=i&-i;
		}
		return ret;
	}
};

BIT bit;

signed main(){
	int num; cin>>num;
	for(int i=0; i<num; i++) cin>>dat[i];
	
	int fir=0,last=11000000000;
	for(;;){
		if(fir==last) break;
		int mid=(fir+last)/2;
		int cnt=0,now=0;
		bit.init();
		bit.add(MAX/2, 1);
		for(int i=0; i<num; i++){
			now+=(dat[i]<=mid)?1:-1;
			cnt+=bit.get(MAX/2+now-1);
			bit.add(MAX/2+now, 1);
		}
		if(cnt<num*(num+1)/4+1) fir=mid+1;
		else last=mid;
	}
	cout<<fir<<en;
}



Measured memory_bytes: 2560