akhauriyash/Code-Regression huggingface dataset:
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
ASSA
---+/
/+---test
ASSS
---+/

void main(string[] args) {
  const S = readln.chomp.to!string;

  size_t[char] x;
  foreach (c; S) {
    if (c !in x) x[c] = 0;
    ++x[c];
  }
  if (x.length == 2 && x.values[0] == x.values[1]) {
    "Yes".writeln;
  } else {
    "No".writeln;
  }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
long n,a[1<<17],b[1<<17],sum;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
		if(i)
		{
			b[i-1]=a[i]-a[i-1];
		}
	}
	b[n-1]=a[0]-a[n-1];
	long all=-~n*n/2;
	if(sum%all)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	long k=sum/all;
	for(int i=0;i<n;i++)
	{
		b[i]-=k;
		if(b[i]>0||b[i]%n)
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
}

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

using ll= long long;
#define double long double
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _set(x) __builtin_popcount(x)
#define _setl(x) __builtin_popcountll(x)
#define PI  3.14159265358979323846264338327950L
#define mod 1000000007LL

void debug(){
	cerr<<"]\n";
}
template<class H,class ... T> void debug(H h,T... t){
	cerr<<h;
	if(sizeof... (t)){
		cerr<<", ";
	}
	debug(t...);
}
#ifdef DEBUG
	#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", debug(__VA_ARGS__)
	#define dpv(...) cerr<< "["#__VA_ARGS__ " : ";for(int i: (__VA_ARGS__)){cerr<<i<<" ";}cerr<<"]\n"
#else
	#define dbg(...) 0
	#define dpv(...) 0
#endif

ll bpow(ll a,ll b){
	ll res= 1;
	while(b){
		if(b&1){
			res = res*a%mod;
		}
		a = a*a %mod;
		b >>=1;
	}
	return res;
}

ll mul(ll a,ll b){
	return (a*b)%mod;
}
void solve(){
	ll n;
	cin>>n;
	cout<<(bpow(10,n)-2*bpow(9,n)%mod+mod+bpow(8,n)) %mod <<"\n";
}


int32_t main(){
	IOS
	// freopen("input.txt","r",stdin);
	int _;
	// cin>>_;
	_=1;
	for(int i=1;i<=_;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

/*
   check for overflows int long long
   correct mize of array
*/


Measured memory_bytes: 3664
#include<iostream>
#include<vector>

using namespace std;

struct MEL{int s,l,p;};
const int MAX = 400;
int dp[MAX];
vector<MEL> V;

void solve(){

  fill(dp,dp+MAX,-1);

  dp[0] = 0;
  for(int i = 0; i < V.size(); i++)
    for(int j = V[i].s; j <= V[i].l; j++)
      for(int k = 0; k < MAX && k+j < MAX; k++)
	if(dp[k] >= 0) dp[k+j] = max(dp[k+j],dp[k]+V[i].p); 
      

  vector<int> ans;
  int m;
  cin >> m;
  while(m--){
    int in;
    cin >> in;
    if(dp[in] == -1){
      cout << "-1" << endl;
      return;
    }
    ans.push_back(dp[in]);
  }
  for(int i = 0; i < ans.size(); i++)
    cout << ans[i] << endl;
}

int main(){

  int n;
  cin >> n;
  while(n--){
    MEL mel;
    cin >> mel.s >> mel.l >> mel.p;
    V.push_back(mel);
  }
  solve();
  return 0;
}

Measured memory_bytes: 1236
import math
n = int(input())
lis = list(map(int,input().split()))
lisa = lis[0::2]
lisb = lis[1::2]
  # print(lisa,lisb)
cou = [0 for i in range(10 ** 5+1)]
co = [0 for i in range(10 ** 5+1)]
for i in range(len(lisa)):
  cou[lisa[i]] += 1
for i in range(len(lisb)):
  co[lisb[i]] += 1
if cou.index(max(cou)) != co.index(max(co)):
  print(n -(max(cou) + max(co)))
else:
  num = max(cou)
  cou[cou.index(max(cou))] = 0
  co[co.index(max(co))] = 0
  ans = cou + co
  print(n -(num + max(ans)))

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  
 vector<int> d(N);
  for(int i=0;i<N;i++) cin >> d.at(i);
  
  for(int i=0;i<N;i++){
    sort(d.begin(),d.end());
    if(d[i] != d[i+1]){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3600
#include<iostream>
using namespace std;
#define lli long long int
#include<vector>
#include<algorithm>
int main(){
  lli r,d,x,i;
  cin>>r>>d>>x;
  //vector<int>v(10);
  //cout<<x<<"\n";
  for(i=1;i<=10;i++){
    x=(r*x)-d;
    cout<<x<<"\n";
  }
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
using namespace std;
const int num = 500005, INF = 2000000000;
int A[num], l[num / 2 + 1], r[num / 2 + 1], cnt = 0;
void merge(int a[], int left, int mid, int right) {
	int num1 = mid - left;
	int num2 = right - mid;
	for (int i = 0; i < num1; i++) {
		l[i] = a[left + i];
	}
	for (int i = 0; i < num2; i++) {
		r[i] = a[mid + i];
	}
	int t = 0, u = 0;
	l[num1] = INF;
	r[num2] = INF;
	for (int s = left; s < right; s++) {
		cnt++;
		if (l[t] <= r[u]) {
			a[s] = l[t];
			t++;
		}
		else {
			a[s] = r[u];
			u++;
		}
	}
}
void mergeSort(int a[], int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(a, left, mid);
		mergeSort(a, mid, right);
		merge(a, left, mid, right);
	}
}
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &A[i]);
	mergeSort(A, 0, n);
	for (int i = 0; i < n; i++) {
		printf("%d", A[i]);
		if (i != n -1)cout << " ";
	}
	printf("\n");
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 7020
#include<bits/stdc++.h>
    using namespace std;
    using Int = long long;
    template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
    template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
     
    //INSERT ABOVE HERE
    signed main(){
      Int l,r;
      cin>>l>>r;
      if(r-l>1e4){
        cout<<0<<endl;
        return 0;
      }
      Int ans=2019;
      for(Int i=l;i<r;i++)
        for(Int j=i+1;j<=r;j++)
          chmin(ans,i*j%2019);
      cout<<ans<<endl;
      return 0;
    }

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


int main() {
    long long int n;
    
    cin >> n;
    vector<vector<long long int>> v(n);
    vector<long long int> at(n);
    vector<long long int> bt(n);
    vector<long long int> ct(n);
    for (long long int i = 0 ; i < n ; i++){
        int a, b , c ; 
        cin >> a >> b >> c;
        v[i].push_back(a);
        v[i].push_back(b);
        v[i].push_back(c);
        
    }

    at[0] = v[0][0];
    bt[0] = v[0][1];
    ct[0] = v[0][2];
    for (long long int i = 1 ; i < n ; i++){

        at[i] = max(bt[i-1] + v[i][0], ct[i-1] + v[i][0]);
        bt[i] = max(at[i-1] + v[i][1], ct[i-1] + v[i][1]);
        ct[i] = max(at[i-1] + v[i][2], bt[i-1] + v[i][2]);
    }
    long long ans = max(at[n-1], bt[n-1]);
    cout << max(ans, ct[n-1]);
    return 0;
}


Measured memory_bytes: 12748
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  int d[K];
  int A[K][N];
  map<int,int> M;
  for(int i=0;i<K;i++){
    cin >> d[i];
    for(int j=0;j<d[i];j++){
      cin >> A[i][j];
      M[A[i][j]]=1;
    }
  }
  int count=0;
  for(int i=1;i<=N;i++){
    if(M[i]==0)count++;
  }
  cout << count;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	string s, t;
	cin >> s >> t;
	s += s;
	if (s.find(t) != string::npos) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;

int main() {
   map<int,int> m;
  m[1]=0;
  m[2]=0;
  m[3]=0;
  m[4]=0;
  int a,b;
  cin >> a >> b;
  m[a]++;
  m[b]++;
  int c,d;
  cin >> c >> d;
  m[c]++;
  m[d]++;
  int e,f;
  cin >> e >> f;
  m[e]++;
  m[f]++;
  if(m[1]==3 || m[2]==3 || m[3]==3 || m[4]==3)
  cout << "NO" << endl;
  else
  cout << "YES" << endl;
}



Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

const pair<int, int> ds[4] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};

int main(void)
{
    int W, H;
    string S;
    cin >> H >> W;
    auto map = vcd(vector<bool>, H+2, vcd(bool, W+2, false));
    queue<pair<pair<int, int>, int>> q;
    for (int i = 1; i <= H; i++)
    {
        cin >> S;
        for (int j = 1; j <= W; j++)
        {
            map[i][j] = S[j-1] == '.';
            if (!map[i][j]) q.push({{i, j}, 0});
        }
    }
    int ans;
    int x, y;
    while (!q.empty())
    {
        y = q.front().first.first;
        x = q.front().first.second;
        ans = q.front().second;
        q.pop();
        fa(di, ds) if (map[y+di.first][x+di.second]) { map[y+di.first][x+di.second] = false; q.push({{y+di.first, x+di.second}, ans+1}); }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12560
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long int MOD = 1000000007;


int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}


void output_yn(bool b) {
	if (b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


int main()
{
	long long int n;

	cin >> n;


	cout << n * n * n << endl;

	return 0;

}

Measured memory_bytes: 256
from itertools import combinations_with_replacement
N,M,Q=map(int,input().split())
abcd = [[int(j) for j in input().split()] for i in range(Q)]


ans =list(combinations_with_replacement(range(1,M+1),N))
x=[]
for i in range(len(ans)):
  kz=0
  a = list(ans[i])
  for j in range(Q):
    if a[(abcd[j][1])-1] - a[(abcd[j][0])-1] == abcd[j][2]:
      kz += abcd[j][3]
    else:
      continue
  x.append(kz)
  
x.sort()

print(x[-1])

Measured memory_bytes: 25580
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }
int main() {
  int N, K; cin>>N>>K;
  double ans = 0;
  for(int n = 1; n <= N; n++) {
    double work	= 1.0 /	N;
    int	score =	n;
    while(score	< K) {
      work /= 2.0;
      score *= 2;
    }
    ans	+= work;
  }
  //  cout << ans << endl;                                                                   
  printf("%0.11f", ans);
  puts("");
  return 0;
}


Measured memory_bytes: 256
N = int(input())
pt, px, py = 0, 0, 0

for i in range (N):
    t, x, y = map(int, input().split())
    dt = abs(t - pt)
    dxy = abs(x-px+y-py)
    if dxy > dt or (dxy - dt)%2:
        print("No")
        exit()
    pt, px, py = t, x, y
print("Yes")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{

	
   long long int n;
  cin>>n;
  char c;
   string neww="";
  while(n>0)
   {
    int r=n%26;
    
    if(r==0)
    c='z';
    else
   	c=r+96;
   	
   	
   	neww=neww+c;
   	n=(n-1)/26;
   }
   long long int ne=neww.size();
   for(int i=ne-1;i>=0;i--)
   cout<<neww[i];
   
   
}

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

int main(){
  string a;
  cin >> a;
  int b=0;
  if(a.size()==1 || a.at(a.size()-1)=='h'){
    cout <<"No"<<endl;
    return 0;
  }
  for(int i=0;i<a.size();i++){
    if(i%2==0 && a.at(i)!='h'){
      b++;
      break;
    }
    else if(i%2==1 &&a.at(i)!='i'){
      b++;
      break;
    }
  }
  if(b==0)cout <<"Yes"<<endl;
  else{
    cout <<"No"<<endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int A,B;cin>>A>>B;
    if(A<=8&&B<9)cout<<"Yay!"<<endl;
    else cout<<":("<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
int main(){
    cin>>N;
    cout<<(N-1)/2<<endl;
    return 0;
}

Measured memory_bytes: 764
import math
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
a10=(a%10)
if a%10==0:
    a10=a10+10
b10=(b%10)
if b%10==0:
    b10=b10+10
c10=(c%10)
if c%10==0:
    c10=c10+10
d10=(d%10)
if d%10==0:
    d10=d10+10
e10=(e%10)
if e%10==0:
    e10=e10+10
sum=min(a10,b10,c10,d10,e10)
print((math.ceil(a/10)+math.ceil(b/10)+math.ceil(c/10)+math.ceil(d/10)+math.ceil(e/10))*10-(10-sum))

Measured memory_bytes: 3064
import java.util.*;
import java.awt.*;

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

        int N = sc.nextInt();
        int T = sc.nextInt();
        int ans = 1001;

        for (int i = 0; i < N; i++) {
            int c = sc.nextInt();
            int t = sc.nextInt();

            if (t <= T) {
                ans = Math.min(ans, c);
            }
        }

        if (ans == 1001) {
            System.out.println("TLE");
        } else {
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
int n;
int a[15];
signed main(){
    cin>>n;
    int i=0;
    while(n){
        n--;
        a[i]=n%26;
        n/=26;
        i++;
    }
    rep(j,i){
        char c='a'+a[i-1-j];
        cout<<c;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3616
a,b = input().split()
a = int(a)
b = int(b)
A = a-1
B = b-1

S = a*A/2
F = b*B/2
if a<1.9 and b<1.9:
  print(0)
elif a<1.9 and b>1.9:
  print(int(F))
elif a>1.9 and b<1.9:
  print(int(S))
elif a>1.9 and b>1.9:
  print(int(S+F))
        


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    int W, H, x, y, r;
    cin  >> W >> H >> x >> y >> r;
    
    if(x - r >= 0 && y - r >= 0 && W >= x + r && H >= y + r)
        cout << "Yes" << endl;
        
    else
        cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 3132
# coding: utf-8

n = int(input())
s = list(input())
count = 0
hantei = True

for i in range(n):
    if s[i] == "A":
        try:
            if s[i+1]=="B" and s[i+2]=="C":
                count += 1
            else:
                continue
        except IndexError:
            break
    
print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i, x, n) for(int i = x; i < n; i++)
#define repr(i, x, n) for(int i = x; i > n; i--)
#define pii pair<int,int>
#define ll long long
const long long iinf = 1e18;
const int inf = 1e9;
const int MOD = (1e6+3);
int dir4[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int knight[8][2] = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{-1,2},{1,-2},{-1,-2}};

using namespace std;

void solve()
{
    long long n; cin >> n;
    string s = "zabcdefghijklmnopqrstuvwxy";
    string ans = "";
    while(n){
        int rem = n%26;
        ans += s[rem];
        if(rem == 0) n--;
        n /= 26LL;
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
}
//new line is printed in the main

int main()
{
    int t = 1;
        // cin >> t; // comment out if no test case is required
    // int i = 1;
    while(t--){
        //cout << "Case " << i++ << ": ";
        solve();
        // printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3632
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int m, n;
	int[][] a;
	boolean[][] visited;

	void run(){
		for(;;){
			m=sc.nextInt();
			n=sc.nextInt();
			if((m|n)==0){
				break;
			}
			a=new int[n][m];
			for(int j=0; j<n; j++){
				for(int i=0; i<m; i++){
					a[j][i]=sc.nextInt();
				}
			}
			solve();
		}
	}

	void solve(){
		visited=new boolean[n][m];
		int ans=0;
		for(int j=0; j<n; j++){
			for(int i=0; i<m; i++){
				if(!visited[j][i]&&a[j][i]==1){
					ans++;
					dfs(i, j);
				}
			}
		}
		println(ans+"");
	}

	void dfs(int x, int y){
		if(x<0||x>=m||y<0||y>=n){
			return;
		}
		if(visited[y][x]){
			return;
		}
		if(a[y][x]!=1){
			return;
		}
		visited[y][x]=true;
		for(int j=-1; j<=1; j++){
			for(int i=-1; i<=1; i++){
				if((i|j)!=0){
					dfs(x+i, y+j);
				}
			}
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
package main

import (
	"bufio"
	"errors"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

// NextLine reads a line text from stdin, and then returns its string.
func NextLine() string {
	sc.Scan()
	return sc.Text()
}

// NextIntsLine reads a line text, that consists of **ONLY INTEGERS DELIMITED BY SPACES**, from stdin.
// And then returns intergers slice.
func NextIntsLine() []int {
	ints := []int{}
	intsStr := NextLine()
	tmp := strings.Split(intsStr, " ")
	for _, s := range tmp {
		integer, _ := strconv.Atoi(s)
		ints = append(ints, integer)
	}
	return ints
}

// NextRunesLine reads a line text, that consists of **ONLY CHARACTERS ARRANGED CONTINUOUSLY**, from stdin.
// Ant then returns runes slice.
func NextRunesLine() []rune {
	return []rune(NextLine())
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// PowInt is integer version of math.Pow
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}
	fa := float64(a)
	fe := float64(e)
	fanswer := math.Pow(fa, fe)
	return int(fanswer)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	fa := float64(a)
	fanswer := math.Abs(fa)
	return int(fanswer)
}

// DeleteElement returns a *NEW* slice, that have the same and minimum length and capacity.
// DeleteElement makes a new slice by using easy slice literal.
func DeleteElement(s []int, i int) []int {
	if i < 0 || len(s) <= i {
		panic(errors.New("[index error]"))
	}
	// appendのみの実装
	n := make([]int, 0, len(s)-1)
	n = append(n, s[:i]...)
	n = append(n, s[i+1:]...)
	return n
}

// Concat returns a *NEW* slice, that have the same and minimum length and capacity.
func Concat(s, t []rune) []rune {
	n := make([]rune, 0, len(s)+len(t))
	n = append(n, s...)
	n = append(n, t...)
	return n
}

// sort package (snippets)
//sort.Sort(sort.IntSlice(s))
//sort.Sort(sort.Reverse(sort.IntSlice(s)))
//sort.Sort(sort.Float64Slice(s))
//sort.Sort(sort.StringSlice(s))

// copy function
//a = []int{0, 1, 2}
//b = make([]int, len(a))
//copy(b, a)

/*******************************************************************/

var n, m int

func main() {
	tmp := NextIntsLine()
	n, m = tmp[0], tmp[1]

	q := m / 2
	r := m % 2
	if n >= q {
		fmt.Println(q)
		return
	}
	delta := q - n
	qq := (2 * delta) / 4
	rr := (2 * delta) % 4
	if r+rr == 4 {
		fmt.Println(n + qq + 1)
	} else {
		fmt.Println(n + qq)
	}
}


Measured memory_bytes: 640
import sys
import collections

n = int(sys.stdin.readline().strip())
l = sys.stdin.readlines()
l = [x.strip() for x in l]

sum = 0

for i in range(n):
  l2 = [l[j][i] for j in range(3)]
  c = collections.Counter(l2)
  most = c.most_common()[0][1]
  if most == 1:
    # 2つ変える
    sum += 2
  elif most == 2:
    sum += 1

print(sum)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

bool isPrime(int x) {
  int i;
  if(x < 2)return 0;
  else if(x == 2) return 1;
  if(x%2 == 0) return 0;
  for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
  return 1;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n;
  cin >> n;
  ll cnt = 0;
  for (ll i = 3; cnt < n; i += 10) {
    if (isPrime(i)) {
      cout << i << ' ';
      ++cnt;
    }
  }

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<=b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
typedef long long ll;
using namespace std;

int main(){
    IOS

    int n;
    cin >> n;
    ll V = 0, E = 0;
    FOR(i,1,n){
        V += i * (n - i + 1);
    }
    FOR(i,1,n-1){
        ll u, v;
        cin >> u >> v;
        if(u > v)
            swap(u, v);
        E += u * (n - v + 1);
    }
    cout << V - E;

    return 0;
}

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

#define endl '\n'
#define ll long long
#define ull unsigned long long
#pragma GCC optimize("-O3")
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

const int inf=0x3f3f3f3f;
const int MAXN=101010;
const ull mod=1e9+7;

ll a[MAXN];

int main() {
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    ll n;
    cin>>n;
    ll ans=(n*n-n)/2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}

//3項以上の場合
int gcd(vector<int>a) {
  int ans = a[0];
  for (int i=1; i<sz(a); i++) {
    ans = gcd(ans, a[i]);
  }
  return ans;
}

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> left(n), right(n);
    left[0] = a[0];
    right[0] = a[n-1];
    rep(i, n-1) {
        left[i+1] = gcd(left[i], a[i+1]);
        right[i+1] = gcd(right[i], a[n-2-i]);
    }
    int ans = gcd(a);
    ans = max(ans, max(left[n-2], right[n-2]));
    if (n >= 3) {
        rep(i, n-2) {
            ans = max(ans, gcd(left[i], right[n-i-3]));
        }
    }
    
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;


const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

ll n,d;
mt x;
ll ans;

ll dist(ll a,ll b){
  ll ret = 0;
  for(ll i = 0;i < d;i++){
    ret += (x[a][i]-x[b][i])*(x[a][i]-x[b][i]);
  }
  return ret;
}

int main(){
  cin >> n >> d;
  x = mt(n,vl(d));
  for(ll i = 0;i < n;i++){
    for(ll j = 0;j < d;j++){
      cin >> x[i][j];
    }
  }
  for(ll i = 0;i < n;i++){
    for(ll j = i+1;j < n;j++){
      ll y = dist(i,j);
      for(ll k = 1;k*k <= y;k++){
        if(k*k == y) ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import numpy as np

def test_switch(e_balls, sw, p):
    for i, e_ball in enumerate(e_balls):
        eb = np.asarray(e_ball)
        si = sw[eb - 1]
        
        if p[i] != (np.sum(si == 1) % 2):
            return False
    
    return True

def transform_sw(sw):
    if sw[0] == 0:
        sw[0] = 1
        return sw
    else:
        sw[0] = 0

    for i, s in enumerate(sw[1:]):
        if s == 0:
            sw[i + 1] = 1
            return sw
        elif s == 1:
            sw[i + 1] = 0
    
    return sw


N, M = map(int, input().split())

e_balls = []

for m in range(M):
    i = input().split()
    s = [int(si) for si in i[1:]]
    e_balls.append(s[:])

p = [int(pi) for pi in input().split()]

sw = np.array([0 for _ in range(N)])
cnt = 0

while np.sum(sw == 1) != N:
    if test_switch(e_balls, sw, p):
        cnt += 1
    transform_sw(sw)

if test_switch(e_balls, sw, p):
        cnt += 1

print(cnt)

Measured memory_bytes: 18448
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

int main(){
	IO_STREAM;
	int N;	cin>>N;
	string S;	cin>>S;
	int ans=1;
	rep(i,0,N-1){
		if(S[i]!=S[i+1])	ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3728
k=int(input())

array = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(array[k-1])

Measured memory_bytes: 9068
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

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;
}
constexpr int mod = 998244353;
constexpr int inf = 3e18;

string S;
int K;
int dp[305][305][305];
int sum[305];
int N;
int memo[305][305],memo2[305][305];
signed main(){
	cin>>S>>K;
	chmin(K,300ll);
	int cnt=0;
	vector<int>v;
	int all=0;
	rep(i,len(S)){
		if(S[i]=='0'){
			v.pb(cnt);
			cnt=0;
		}else {
			cnt++;all++;
		}
	}
	if(S.back()!='0')v.pb(cnt);
	N=len(v);
	rep(i,N){
		sum[i]+=v[i];
		sum[i+1]=sum[i];
	}
	dp[0][0][0]=1;
	rep(i,N){
		memset(memo,0,sizeof(memo));
		memset(memo2,0,sizeof(memo2));
		rep(j,all+1){
			rep(k,K+1){
				if(dp[i][j][k]==0)continue;
				(memo[j][k]+=dp[i][j][k])%=mod;
				if(j+v[i]+1<=all){
					(memo[j+v[i]+1][k]-=dp[i][j][k]-mod)%=mod;
				}
				if(j+v[i]+1<=all){
					(memo2[j+v[i]+1][k+1]+=dp[i][j][k])%=mod;
				}
			}
		}
		rep(j,all+1){
			rep(k,K+1){
				(memo[j+1][k]+=memo[j][k])%=mod;
				(memo2[j+1][k+1]+=memo2[j][k])%=mod;
			}
		}
		rep(j,all+1){
			if(j<sum[i])continue;
			rep(k,K+1){
				dp[i+1][j][k]=(memo[j][k]+memo2[j][k])%mod;
			}
		}
	}
	int ans=0;
	rep(i,K+1)(ans+=dp[N][all][i])%=mod;
	cout<<ans<<endl;
}


Measured memory_bytes: 58296
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000;
#define all(v) v.begin(), v.end()

ll M;
ll modPow(ll a, ll n) {
  if (n == 0) return 1; // 0乗にも対応する場合
  if (n == 1) return a % M;
  if (n % 2 == 1) return (a * modPow(a, n - 1)) % M;
  ll t = modPow(a, n / 2);
  return (t * t) % M;
}

int main(){
  ll N,ans=0;
  string S;
  cin >> N >> M >> S;
  vector<ll> T(N+1),U(M,0);
  if(M==2){
    rep(i,N){
      if(S.at(i)=='0'||S.at(i)=='2'||S.at(i)=='4'||S.at(i)=='6'||S.at(i)=='8'){
        ans+=i+1;
      }
    }
    cout << ans << endl;
  }else if(M==5){
    rep(i,N){
      if(S.at(i)=='0'||S.at(i)=='5'){
        ans+=i+1;
      }
    }
    cout << ans << endl;
  }else{
    T.at(0)=0;
    U.at(0)++;
    rep(i,N){
      T.at(i+1)=T.at(i)+(S.at(N-i-1)-'0')*modPow(10,i);
      T.at(i+1)%=M;
      U.at(T.at(i+1))++;
    }
    rep(i,M){
      ans+=(U.at(i)*(U.at(i)-1))/2;
    }
    cout << ans << endl;
  }
}

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

int main() {
  int n, q;
  cin >> n;
  vector<int> s(n);
  for (auto& e : s) cin >> e;
  cin >> q;
  vector<int> t(q);
  for (auto& e : t) cin >> e;
  int cnt = 0;
  for (auto& i : t) {
    for (auto& j : s) {
      if (i == j) {
        cnt++;
        break;
      }
    }
  }
  cout << cnt << "\n";
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>                                           
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;  
typedef unsigned long long ull;         
typedef vector < pii > vpii;                                   	
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;
 
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
 
const int inf = 1e9, maxn = 2e5 + 48, mod = 998244353, N = 5012;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 300;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = acos(-1);
const ll INF = 1e18;
 

int n, k, p[N], c[N], sum;
bool was[N];
vi pr;

void dfs (int v) {
	was[v] = 1;
	sum += c[v];
	pr.pb(sum);
	
	if (!was[p[v]])
		dfs(p[v]);
}

main () {
	cin >> n >> k;
	for (int i = 1; i <= n; ++i)
		cin >> p[i];
	for (int i = 1; i <= n; ++i)
		cin >> c[i];

	int ans = -INF;

	for (int i = 1; i <= n; ++i) {
		memset(was, 0, sizeof(was));
		sum = 0;
		pr.clear();
		dfs(i);
		for (int i = 0; i < sz(pr); ++i) {
			int rest = k - i - 1;
			if (rest < 0)
				break;
			ans = max(ans, pr[i] + (rest / sz(pr)) * max(0ll, sum));
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3816
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll binpowmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return binpowmod(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,m,n,i,f=0,j,ans=0,k,x;
    cin >> x ;
    ll temp;
    vector<ll> v;
    v.pb(0);
    for(i=1;i<=1e5;++i) 
    {
        temp = pow(i,5);
        v.pb(temp);
        v.pb(-1*temp);
    }
    sort(v.begin(),v.end());
    double h;
    for(i=0;i<=1e5;++i)
    {
        temp = x - pow(i,5);
        //cout << temp << endl ;
        if(binary_search(v.begin(),v.end(),temp))
        {
            if(temp>0)
            {
                h = pow(temp,0.2);
                //cout << h << endl ;
                ans=h;
                ans*=-1;
                cout << i << " " << ans ;
            }
            else 
            {
                temp*=-1;
                h = pow(temp,0.2);
                //cout << h << endl ;
                ans=h;
                //ans*=-1;
                cout << i << " " << ans ;
            }
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 5928
N = int(input())
a = list(map(int, input().split()))
if abs(max(a)) >= abs(min(a)):
    for i in range(N):
        if a[i] == max(a):
            num = i
            break
    print(2*N-1)
    for i in range(N):
        if num != i:
            print(num+1, i+1)
    print(num+1, num+1)
    for i in range(1,N):
        print(i, i+1)
else:
    for i in range(N):
        if a[i] == min(a):
            num = i
            break
    print(2*N-1)
    for i in range(N):
        if num != i:
            print(num+1, i+1)
    print(num+1, num+1)
    for i in range(N-1):
        print(N-i, N-i-1)

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

int main() {
	int n,x;
	cin>>n>>x;
	int a[n];
	int s=0;
	int i;
	for( i=0;i<n;i++){
	   cin>>a[i];
	   s+=a[i];
	}
	 sort(a,a+n);
	 int p=a[0];
	 int d,ans;
	if(s==x)cout<<n;
	else{
	   d=x-s;
	   ans=d/p;
	    cout<<(ans+n)<<endl; 
	}
	
	  
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;

int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	int a, p;
	cin >> a >> p;
	int x = 3*a + p;
	cout << x/2; 
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n;
  scanf("%d",&n);

  int a[2][n];
  for(int i = 0;i < 2;i ++){
    for(int j = 0;j < n;j ++){
      scanf("%d",&a[i][j]);
    }
  }

  int ans = 0 , max = 0;
  for(int i = 0;i < n;i ++){
    int t = 0;
    for(int j = 0;j < n;j ++){
      ans += a[t][j];
      if(i == j){
        t ++;
       ans +=  a[t][j];
      }
    }
    if(max < ans){
      max = ans;
    }
    ans = 0;
  }


  printf("%d\n",max);

  return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  ll n,k; cin >> n >> k;
  vll a(n);
  rep(i,n) cin >> a[i];
  for (int i=k; i<n; i++) {
    if (a[i-(k)] < a[i]) {
      cout << "Yes" <<endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4784
// B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <numeric>


using lolo=long long;
using namespace std;
using vec=vector<lolo>;
using pari=pair<lolo, lolo>;
using vvec=vector<vec>;
using vecb=vector<bool>;
#define FOR(i,n) for (lolo i=0; i<n; ++i)
#define FORIT(it,v) for (auto it=v.begin(); it!=v.end(); ++it)
#define FORANGE(it, v) for (auto it : v)
#define FORN(i,a,b) for (lolo i=a; i<b; ++i)
#define REV(i,a,b) for (lolo i=a; i>b; --i)
#define ALL(x) x.begin(), x.end()

int main()
{
	lolo N;
	cin >> N;
	//v/*ec S(N);
	//vec P(N);*/
	//map<lolo, lolo> rest;
	vector<pair<string, lolo> > A;
	map<pair<string, lolo>, lolo> D;

	FOR(i, N) {
		string s;
		lolo  p;
		cin >> s >> p;
		A.emplace_back(s, p);
		D[A[i]] = i+1;
		//rest[]
		//rest
		//S[i] = s;
		//P[i] = p;
	}
	sort(ALL(A), [](auto a, auto b) {
		if (a.first != b.first) {
			return a.first < b.first;
		}
		else {
			return a.second > b.second;
		}
		
		});

	FOR(i, N)
	{
		cout << D[ A[i] ]  << endl;
	}
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)


signed main(){
    
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    
    int t=0;
    int K = k;
    while(K>0){
        t++;
        K/=2;
    }
    
    vector<pii> data(t);
    
    int count = 0;
    rep(i,t){
        int count = 0;
        rep(j,n){
            if(v[j]&(1LL<<(i))){
                count++;
            }
        }
        if(count<=n/2){
            int p = n-count;
            data[i] = pii((p-count)*(1LL<<(i)), 1LL<<(i));
        }
    }
    sort(all(data), greater<pii>());
    int ans = 0;
    rep(i,data.size()){
        if(data[i].second<=k){
            k -= data[i].second;
            ans += data[i].first;
        }
    }
    int sum = 0;
    rep(i,n)sum += v[i];
    cout<<ans+sum<<endl;
}


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

int selectionsort(int a[], int n){
    int count=0;

    for(int i=0;i<n;i++){
        int minj=i;
        for(int j=i;j<n;j++){
            if(a[j]<a[minj])minj=j;
        }
        swap(a[i], a[minj]);
        if(i!=minj)count += 1;
    }

    return count;
}

int main(){
    int n, count; cin >> n;
    int a[n];

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

    count = selectionsort(a, n);

    for(int i=0;i<n;i++){
        if(i)cout << " ";
        cout << a[i];
    }

    cout << endl << count << endl;;
}



Measured memory_bytes: 3120
#include<iostream>
#include<vector>

using namespace std;

typedef vector<int>::iterator ITE;
int n,m;


int find(vector<int> &V, int t){

  for(int i = 0; i < V.size(); i++)
    if(V[i] == t) return i;
  return -1;
}

int main(){
  cin >> n >> m;
  vector<int> V;
  while(n--){
    int in,pos;
    cin >> in;
    pos = find(V,in);
    if(pos != -1){
      V.erase((ITE)&V[pos]);
      V.push_back(in);
    }else if(V.size() < m) V.push_back(in);
    else{
      V.erase((ITE)&V[0]);
      V.push_back(in);
    }
  }

  for(int i = V.size()-1; i >= 0; i--)
    cout << V[i] << endl;
  return 0;
}

Measured memory_bytes: 1532
def main():
  while True:
    n = int(input())
    if not n:
      break
    ps = [list(map(int,input().split())) for i in range(n)]
    dic = set()
    for t in ps:
      dic.add((t[0],t[1]))
    ans = 0
  
    for i in range(n):
      for j in range(n):
        p1 = ps[i]
        p2 = ps[j]
        p1x = p1[0]
        p1y = p1[1]
        p2x = p2[0]
        p2y = p2[1]
        vx = p2x - p1x
        vy = p2y - p1y
        if (p1x + vy, p1y - vx) in dic and (p2x + vy, p2y - vx) in dic:
          ans = max(ans, vx ** 2 + vy ** 2)
    

    print(ans)
main()  





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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

int main(){
#define int ll
  int n; cin >> n;
  vi a(n);
  vi pos(n);
  rep(i,n){
    cin >> a[i]; a[i]--;
    pos[a[i]] = i;
  }

  set<int> st1,st2;
  // insert sentinels
  st1.insert(-1); st1.insert(n);
  st2.insert(1); st2.insert(-n);

  int res = 0;
  rep(ai,n){
    int r = *st1.lower_bound(pos[ai]);
    int l = -*st2.lower_bound(-pos[ai]);
    //cout << l << " " << r << endl;
    //cout << (pos[ai] - l) * (r - pos[ai]) << endl;
    res += (ai+1) * (pos[ai] - l) * (r - pos[ai]);
    st1.insert(pos[ai]);
    st2.insert(-pos[ai]);
  }
  cout << res << endl;
}

Measured memory_bytes: 22144
#include<bits/stdc++.h>
using namespace std;
const long long maxn=1e5+5;
const long long inf=9223372036854775807;
//long long
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    long long ans=-inf;
    ans=max(a*c,ans);
    ans=max(a*d,ans);
    ans=max(b*c,ans);
    ans=max(b*d,ans);
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  vector<double> v(n); REP(i,n) cin >> v[i];
  sort(v.begin(), v.end());
  double ans = v[0];
  for (int i = 1; i < n; i++) {
    ans = (ans+v[i])/2;
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

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

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int[] score = new int[10];
		int ave,sum = 0;

		for(int i = 0; i < 5; i++){
			score[i] = sc.nextInt();
			if(score[i] < 40){
				score[i] = 40;
			}
			sum = sum+score[i];
		}

		ave = sum/5;
		sc.close();

		System.out.println(ave);

	}

}

Measured memory_bytes: 26012
#include <stdio.h>

int main(void)
{
  int n;
  double a;
  int i;
  double sum = 0;
  
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%lf", &a);
    sum += 1 / a;
  }
  
  printf("%.10f", 1 / sum);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
// Binary Indexed Tree (Fenwick Tree)
template <typename T>
struct BIT {
    ll n;
    vector<T> d;
    BIT(ll n = 0) : n(n), d(n + 1, INF) {}
    void add(ll i, T x = 1) {
        for (i++; i <= n; i += i & -i) {
            d[i] = min(d[i], x);
        }
    }
    T sum(ll i) {
        T x = INF;
        for (i++; i; i -= i & -i) {
            x = min(x, d[i]);
        }
        return x;
    }
};

int main() {
    ll N, Q;
    cin >> N >> Q;

    BIT<ll> H(N), W(N);
    ll ans = (N - 2) * (N - 2);

    rep(i, Q){
        ll m, v;
        cin >> m >> v, v--;
        if(m == 1){
            ll u = H.sum(N - v - 1);
            if (u == INF) u = N - 1;
            ans -= u - 1;
            W.add(N - u - 1, v);
        // err(m, v, u, ans);

        }else{
            ll u = W.sum(N - v - 1);
            if (u == INF) u = N - 1;
            ans -= u - 1;
            H.add(N - u - 1, v);
        // err(m, v, u, ans);
        }

    }

    cout << ans << endl;
}

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

int main(){
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;

    if (s == u) a--;
    if (t == u) b--;

    cout << a << " " << b << endl;


    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes"<<"\n";
  else cout<<"No"<<"\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int i,j,k,ans=1;
    int w,h,x,y,judge;
    double s=0.0;


    scanf("%d %d %d %d",&w,&h,&x,&y);

    s = (double)w*(double)h/2.0;

    judge=0;
  	if( !(w==0||h==0) ){
        if((w%2==0)&&(h%2==0)){
            if((w/2==x)&&(h/2==y)){
                judge=1;
            }   
        }
	}	
  
    printf("%lf %d\n",s,judge);

    return 0;
}


Measured memory_bytes: 128