akhauriyash/Code-Regression huggingface dataset:
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)size(x))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)-1)/(x)+1)
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    int n;
    cin>>n;

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

    sort(all(a));
    sort(all(b));

    if(n%2)
    {
        cout<<b[n/2]-a[n/2]+1;
    }
    else
    {
        int x=(a[n/2]+a[n/2-1]);
        int y=(b[n/2]+b[n/2-1]);
        int ans=(y-x)+1;
        cout<<ans;
    }
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 6348
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    string s; cin>>s;
    int cnt=0,n=s.size();
    rep(i,n){
        if(s[i]-'0'==i%2) cnt++;
    }
    cout<<min(cnt,n-cnt)<<endl;
}


Measured memory_bytes: 3736
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		long ans = 0;
		for(int i = 1; i < n + 1; i++) {
			ans += (long)i*((long)n/(long)i)*(((long)n/(long)i)+1)/2;
		}
		System.out.println(ans);
	}
}


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

int n;
vector<lint> a;

bool isValid(lint m) {
    lint count = 0;
    for (int i = 0; i < n; i++) {
        lint b = max(0LL, a[i] + m - (n - 1));
        count += (b + n) / (n + 1);
    }
    return count <= m;
}
bool isValid2(lint m) {
    lint count = 0;
    for (int i = 0; i < n; i++) {
        lint b = max(0LL, a[i] + m - (n - 1));
        count += (b + n) / (n + 1);
    }
    return count == m;
}

int main() {
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    lint ok = LLONG_MAX / 2, no = -1;
    while (abs(ok - no) > 1) {
        lint mid = (ok + no) / 2;
        if (isValid(mid)) {
            ok = mid;
        } else {
            no = mid;
        }
    }
    for (lint i = max(0LL, ok - 1000000); i < ok + 1000000; i++) {
        if (isValid2(i)) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <unordered_map>
using namespace std;

typedef unsigned long ul;
typedef array<ul, 6> dice;

bool f(int n)
{
	static const array<dice, 6> tbl = {
			0,1,2,3,4,5, 1,5,2,3,0,4, 2,1,5,0,4,3,
			3,1,0,5,4,2, 4,0,2,3,5,1, 5,1,3,2,4,0};
	dice d;
	unordered_map<ul, bool> db;
	array<ul, 24> r;

	while (n--) {
		for (ul &x: d)
			cin >> x;
		int i = 0;
		for (dice t: tbl) {
			for (int j = 0; j < 4; j++) {
				ul l = 0;
				for (int k = 0; k < 6; k++)
					l += (d[t[k]] + 1) << k * 10;
				if (db.count(l))
					return true;
				r[i * 4 + j] = l;
				ul x = t[1]; t[1] = t[2]; t[2] = t[4]; t[4] = t[3]; t[3] = x;
			}
			i++;
		}
		for (ul l : r)
			db[l] = true;
	}
	return false;
}

int main()
{
	int n;
	cin >> n;
	cout << (f(n) ? "No" : "Yes") << endl;
}


Measured memory_bytes: 3176
# https://atcoder.jp/contests/abc137/tasks/abc137_c

import math

import sys
import collections

n=int(input())
a=[''.join(sorted(input())) for _ in range(n)]

ans = 0
for v in collections.Counter(a).values():
    for i in range(1, v):
        ans += i
print(ans)

Measured memory_bytes: 19740
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> cost(N);
    for(int i = 0 ; i < N ; i++)
       cin >> cost[i];
    
    vector<int> dp(N+1, 1e9 + 5);
    dp[0] = 0;
    for(int i = 0 ; i < N ; i++)
    {
        for(int j = i+1 ; j <= i + K ; j++)
        {
            if(j < N)
            dp[j] = min(dp[j], dp[i] + abs(cost[j] - cost[i]) );
        }
    }

    cout << dp[N-1];

}





Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
#define me(a,b) memset(a,b,sizeof(a))
const int Max = 1e7;
long double a[Max];
int main(){
	int n,k;
	cin>>n>>k;
	long double x;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		a[i]=(1+x)/2.0;
//		cout<<a[i]<<endl;
	}
	long double ans=0,sum=0;
	int num=0;
	for(int i=0;i<n;i++){
		if(num<k){
			ans+=a[i];
			sum+=a[i];
			num++;
		}
		else{
			sum=sum-a[i-k]+a[i];
			ans=max(ans,sum);
		}
	}
	printf("%.6Lf\n",ans);
return 0;
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MOD = 1e9+7;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//C++17以上
template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main() {
    int l,r;cin >> l >> r;
    if(r-l >= 3000){
        cout << 0 << endl;
    }else{
        ll ans = INF;
        for(ll i=l;i<r;i++){
            for(ll j=i+1;j<=r;j++){
                chmin<ll>(ans,(i*j)%2019);
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#  --*-coding:utf-8-*--


def f(s):
    x = [0]*26
    base = ord('a')
    
    for c in s:
        x[ord(c) - base] += 1

    return x


def main():
    N = int(input())
    Q = {}

    for i in range(N):
        S = input()
        k = tuple(f(S))

        if k in Q:
            Q[k] += 1
        else:
            Q[k] = 1

    print(sum(map(lambda n: n*(n-1)//2, Q.values())))




if __name__ == '__main__':
    main()


Measured memory_bytes: 35928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define fi first
#define se second
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
vector<pair<int,int>> g[maxn];
int col[maxn];
void dfs(int now,int fa,int c)
{
    col[now]=c;
    for(auto x:g[now])
    {
        if(x.fi==fa) continue;
        if(x.se&1) dfs(x.fi,now,c^1);
        else dfs(x.fi,now,c);
    }
}
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int u,v,d;
        cin>>u>>v>>d;
        g[u].pb(make_pair(v,d));
        g[v].pb(make_pair(u,d));
    }
    dfs(1,1,0);
    for(int i=1;i<=n;i++) cout<<col[i]<<'\n';
    return 0;
}



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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

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

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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; }


int main(void){
  ios::sync_with_stdio(false);
  

  ll n;
  cin >> n;

  ll ans = 0;
  REP(i, n+1){
    if (i % 3 != 0  and i % 5 !=0){ans += i;}
  }

  cout << ans << endl;



  return 0;
}



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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> d(2 * n);
    for (int i = 0; i < 2 * n; i++) {
        cin >> d[i];
    }
    for (int i = 0; i + 6 <= 2 * n; i++) {
        if (d[i] == d[i + 1] && d[i + 2] == d[i + 3] && d[i + 4] == d[i + 5]) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>

int main() {
	
	int N, check = 0;
	scanf("%d", &N);
	
	if(N % 2 == 1){
		printf("No\n");
		return 0;
	}
	
	char S[N];
	scanf("%s", S);
	
	for(int i = 0; S[i] != '\0'; i++){
		if(S[i] == S[(N / 2) + i]){
			check++;		
		}
	}
	
	if(check == N / 2){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 1628
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <bitset>
#include <fstream>
#include <unordered_set>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
  
          
using namespace std;
using namespace __gnu_pbds;
 
  
 
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")*/
      
#define int long long
#define eb emplace_back
#define pb push_back
#define ld long double
#define mp make_pair
#define f first
#define s second
#define deb(a) cerr << #a << " = " << a << '\n';
#define fast() { \
    ios_base::sync_with_stdio(0); \
    cin.tie(0); \
    cout << fixed << setprecision(5); \
    cerr << fixed << setprecision(11); \
}
 
template < typename firstType, typename secondType = null_type, class compare = less < firstType > >
struct sett {
    typedef tree <
        firstType,
        secondType,
        compare,
        rb_tree_tag,
        tree_order_statistics_node_update
    > _ ;
};
 
  
const int INF = 1e9 + 7;
const ld EPS = 1e-10;
const int MAXI = 200000;
const int P = 223; 
const int MOD = 998244353; 
const int MAXST = 2000000;
const ld PI = 3.14159265358979323;
        
ostream &operator<<(ostream &stream, const pair <int, int> &p) {
    stream << p.first << ' ' << p.second << ' ';
    return stream;
}



signed main(){  
    fast();
    srand(time(0));
    #ifdef _LOCAL               
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int a, b, n;
    cin >> a >> b >> n;
    int ans = min(b - 1, n);
    cout << a * ans / b - a * (ans / b);
    return 0;                   
   	
}

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)


template <typename T>
void printV(vector<T> A) {
    if (A.empty()) cerr << "EMTPY\n";
    else { 
        cerr << "[";
        for (int i = 0; i < A.size() -1 ; ++i) {
            cerr << A[i] << ", ";
        }
        if (A.size()) cerr << A.back() << "]\n";
    }
}


template <typename T>
void printVV(vector<vector<T>> A) {
    cerr << "[";
    for (auto v : A) {
        printV<T>(v);
    }
    cerr << "]";
}

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...);
}

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    double l = n*1.0/3;
    cout << fixed << setprecision(7);
    cout << pow(l, 3);
    return 0;
}



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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

struct node
{
  node* nxt;
  node* prv;
  int val;
};

int idx=0;
node resorce[2000000];

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

  node* start=&resorce[idx++];
  node* end=&resorce[idx++];
  start->nxt=end; start->prv=NULL;
  start->val=-1;
  end->prv=start; end->nxt=NULL;
  end->val=-1;

  int q;
  cin>>q;
  while(q--){
    string com;
    int x;
    cin>>com;
    if(com=="insert"){
      cin>>x;
      node* crt=&resorce[idx++];
      crt->val=x;
      crt->nxt=start->nxt;
      crt->prv=start;
      start->nxt=crt;
      crt->nxt->prv=crt;
    }else if(com=="delete"){
      cin>>x;
      node* crt=start;
      while(crt!=end&&crt->val!=x)crt=crt->nxt;
      if(crt==end)continue;
      node* prev=crt->prv;
      node* next=crt->nxt;
      prev->nxt=next;
      next->prv=prev;
    }else if(com=="deleteFirst"){
      node* crt=start->nxt;
      start->nxt=crt->nxt;
      crt->nxt->prv=start;
    }else if(com=="deleteLast"){
      node* crt=end->prv;
      end->prv=crt->prv;
      crt->prv->nxt=end;
    }
  }
  vector<ll> res;
  node* crt=start->nxt;
  while(crt!=end){
    res.push_back(crt->val);
    crt=crt->nxt;
  }
  cout<<res[0];
  repl(i,1,res.size()){
    cout<<" "<<res[i];
  }
  cout<<endl;
	return 0;
}

Measured memory_bytes: 30616
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  vector<int> v;
  cin >> n;
  if(n==0){
    cout << 0 << endl;
    return 0;
  }
  while(n != 0){
    int md, dv;
    dv = n/(-2);
    md = n-dv*(-2);
    if(md == -1){
      dv++;
      md=1;
    }
    if(md == 1){
      v.push_back(1);
    }else{
      v.push_back(0);
    }
    n = dv;
  }
  for(int i=v.size()-1; i>=0;i--){
    cout << v[i];
  }
  cout << endl;
}



Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    static class Writer {
        PrintWriter cout;

        Writer() throws IOException {
            cout = new PrintWriter(System.out);
        }

        Writer(String name) throws IOException {
            cout = new PrintWriter(new FileWriter(name));
        }

        StringBuilder out = new StringBuilder();

        void print(Object a) {
            out.append(a);
        }

        void close() {
            cout.print(out.toString());
            cout.close();
        }
    }

    static class Reader {
        BufferedReader in;

        Reader() throws IOException {
            in = new BufferedReader(new InputStreamReader(System.in));
        }

        Reader(String name) throws IOException {
            in = new BufferedReader(new FileReader(name));
        }

        StringTokenizer tokin = new StringTokenizer("");

        String next() throws IOException {
            if (!tokin.hasMoreTokens()) {
                tokin = new StringTokenizer(in.readLine());
            }
            return tokin.nextToken();
        }

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

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


    public static void main(String args[]) throws IOException {
        Reader in = new Reader();
        Writer out = new Writer();
        if (in.nextInt() == 1) {
            out.print("Hello World");
        } else {
            long a = in.nextLong();
            long b = in.nextLong();
            out.print(a + b);
        }
        out.close();
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n, m;
  int x[100000];
  int y[100000];
  cin >> n >> m;
  for(int i = 0;i < m;i++){
    cin >> x[i];
  }
  if(n > m){
    cout << 0 << endl;
    return 0;
  }
  if(m == 1){
    cout << 0 << endl;
    return 0;
  }
  sort(x, x + m);
  for(int i = 1;i < m;i++){
    y[i - 1] = x[i] - x[i - 1];
  }
  sort(y, y + m - 1);
  long int sum = 0;
  for(int i = 0;i < (m - n);i++){
    sum += y[i];
  }
  cout << sum << endl;
}

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

int main(){
  long long w,h,x,y; cin>>w>>h>>x>>y;
  cout<<w*h/2.0<<" ";
  if (x==w/2.0 && y==h/2.0) cout<<1<<endl;
  else cout<<0<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    
    using namespace std;
    int const MOD=1e9+7;
    int r,c;
    bool valid(int i, int j){
      if(i<0 || i>=r || j<0 || j>=c)
        return 0;
      return 1;
    }
   int dfs(int i, int j, vector<vector<char>>&g, vector<vector<int>>&dp){
      if(!valid(i, j) || g[i][j]=='#')
        return 0;
      
      if(dp[i][j]!=-1)
        return dp[i][j];
      
      if(i==(r-1) && j==(c-1))
        return dp[i][j]=1;

      dp[i][j]=(dfs(i, j+1, g, dp)%(MOD) + dfs(i+1, j, g, dp)%(MOD))%(MOD);
      return dp[i][j];
    }
    int main(){
      cin>>r>>c;
      vector<vector<char>>g(r, vector<char>(c,'.'));
      vector<vector<int>>dp(r, vector<int>(c, -1));
      for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
          cin>>g[i][j];
          //cout<<g[i][j]<<" ";
        }
        //cout<<"\n";
      }
 
      dfs(0,0, g, dp);
      cout<<dp[0][0]<<"\n";
    }

Measured memory_bytes: 5376
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
 
int main() {
	//入力
	string S;
	cin >> S;
 
	//処理
	string T = "ATCG";
 
	int ans = 0; //ATCG文字列の最大長
	int now = 0; //今見ている文字を末尾とするATCG文字列の最大長
	for (int i = 0; i < S.size(); i++)
	{
		bool isATCG = false;
		for (int j = 0; j < T.size(); j++)
		{
			if (S[i] == T[j]) isATCG = true;
		}
 
		if (!isATCG) {
			//違う場合は0にする
			now = 0;
		}
		else {
			//ATCG文字の場合は、前の文字列に1つ文字を足せる
			now++;
			//最大値を更新する
			ans = max(now, ans);
			// if(now > ans) ans = now; も同じ
		}
	}
 
	cout << ans << endl;
}
 

Measured memory_bytes: 256
def main():
    n=int(input())
    a = list(map(int,input().split()))
    if a==[0 for _ in range(n)]:
        print(0)
        return
    box=[0 for _ in range(n)]
    for i in range(n,0,-1):
        if n//i==1:
            box[i-1]=a[i-1]
        else:
            c=0
            for j in range((n//i)-1):
                c+=box[(j+2)*i-1]
            box[i-1]=(a[i-1]+c)%2
    print(sum(box))
    ans=[]
    for i in range(n):
        if box[i]==1:
            ans.append(str(i+1))
    print(' '.join(ans))

if __name__ == "__main__":
    main()

Measured memory_bytes: 76520
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

ll f(int x,int y,int z){
	return x * x + y * y + z * z + x * y + y * z + z * x;
}

int main(){
	int n;
	cin >> n;
	vector<int> ans(n);
	rep2(x,1,101){
		rep2(y,1,101){
			rep2(z,1,101){
				if(f(x,y,z) <= n)
					ans[f(x, y, z) - 1]++;
			}
		}
	}
	
	rep(i, n) cout  <<ans[i] << endl;

	return 0;
}

Measured memory_bytes: 3568
/*
 
 * This code is written by Sanskar Agarwal
 
*/
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define VPLL vector<PLL>
#define VPII vector<PII>
#define PQ priority_queue<PLL,VPLL, greater<PLL> > 
#define PQI priority_queue<PII,VPII,greater<PII> >
#define UMLL unordered_map<ll,ll>
#define UMII unordered_map<int,int>
#define VI vector<int>
#define VL vector<ll>
#define S second
#define F first
#define PB push_back


int main()
{

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

        
    int a,b,c;
    int k;
    int cnt=0;
    cin>>a>>b>>c>>k;
    while(b<=a) {
        cnt++;
        b*=2;
    }

    // cout << cnt <<  " ";
    while(c<=b)
    {
        cnt++;
        c*=2;
    }
    // cout << cnt <<  ' ';

    if(cnt<=k)
        cout << "Yes";
    else
        cout << "No";

    return 0;
}

Measured memory_bytes: 3652
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,ans=0,sum=0; cin>>n;
    rep(i,n){
        ll a; cin>>a;
        ans=(ans+a)%MOD;
        sum=(sum+a*a)%MOD;
    }
    ans=ans*ans%MOD;
    ans=(ans-sum+MOD)%MOD*(MOD+1)/2%MOD;
    cout<<(ans+MOD)%MOD<<endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int long long

// AND OR XORは各bitでみよ
//kが決まればO(n)
//最大、最小の探索において無駄な探索は不要

void solve() {
	int n, k; cin >> n >> k;
    vector<int> a(n), b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }
    int ans = 0;
    rep(j, n) {
        if((k | a[j]) == k) ans += b[j];
        //ビット演算の計算順序は低い
    }
    for(int i = 32; i >= 0; i--) {
        if(k & (1<<i)) {
            int mask = k - (1<<i);
            rep(j, i) mask |= (1<<j);

            int res = 0;
            rep(j, n) {
                if((mask | a[j]) == mask) res += b[j];
            }
            ans = max(ans, res);
        }
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 1792
import math

N, D = map(int, input().split())
X = [[int(i) for i in input().split()] for i in range(N)] 

cnt = 0
for i in range(N):
    for j in range(N):
        if i == j:
            break
        tmp_sum = 0
        for d in range(D):
            tmp_sum += (X[i][d] - X[j][d]) ** 2
        if math.sqrt(tmp_sum).is_integer():
            cnt += 1

print(cnt) 

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

int main() {
  int N,K,Q;
  cin >> N >> K >> Q;
  vector <int> vec(Q);
  for( int i = 0; i < Q; i++){
    cin >> vec.at(i);
  }
  vector <int> score(N,K-Q);
  int a;
  for( int i = 0; i < Q; i++){
    a = vec.at(i);
    score.at(a-1)++;
  }
  for( int i = 0; i < N; i++){
    if( score.at(i) > 0){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 1408
while True:
    H,W = map(int,input().split())

    if H == 0 and W == 0:
        break

    else:
        c = 1
        h = H
        while h > 0:
            if c == 1 or c == H:
                print("#"*W)
            else:
                s = "."*(W-2)
                print("#"+s+"#")
            h -= 1
            c += 1
                
    print("")


Measured memory_bytes: 5612
import java.util.*;
 
class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int max = 0;
		int min = 0;
		int ans = Integer.MAX_VALUE;
		ArrayList<Integer> ary = new ArrayList<Integer>();
		
		for(int i = 0; i < N; i ++) {
			ary.add(Integer.parseInt(sc.next()));
		}
		max = Collections.max(ary);
		min = Collections.min(ary);
		
		for(int i = min; i <= max; i++) {
			int x = 0;
			for(int y = 0;y < ary.size(); y++) {
				x += (ary.get(y) - i) * (ary.get(y) - i);
			}
			if(x <= ans) {
				ans = x;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
n,k=map(int,input().split())
A=list(map(int,input().split()))
C=[0]+[-1]*(n-1)
p=1
c=0
s=-1
e=-1
for i in range(n):
    p=A[p-1]
    c+=1
    if C[p-1]==-1:
        C[p-1]=c
    else:
        s=C[p-1]
        e=c
        break
P=1
if s!=-1 and e!=-1:
    if k<=s:
        while k>0:
            P=A[P-1]
            k-=1
        print(P)
    else:
        l=(k-s)%(e-s)
        k=s+l+1
        while k>1:
            P=A[P-1]
            k-=1
        print(P)
else:
    if k<=n:
        while k>0:
            P=A[P-1]
            k-=1
        print(P)
    else:
        while n>0:
            P=A[P-1]

Measured memory_bytes: 32280
N = 8
board = [['.'] * N for i in range(N)]
k = int(input())
for i in range(k):
    pos = list(map(int, input().split()))
    board[pos[0]][pos[1]] = 'Q'


def is_safe(board, row, col):
    for i in range(N):
        if board[row][i] == 'Q':
            return False

    for i, j in zip(range(row, -1, -1), range(col, -1, -1)):
        if board[i][j] == 'Q':
            return False

    for i, j in zip(range(row, -1, -1), range(col, N, 1)):
        if board[i][j] == 'Q':
            return False

    for i, j in zip(range(row, N, 1), range(col, -1, -1)):
        if board[i][j] == 'Q':
            return False
    
    for i, j in zip(range(row, N, 1), range(col, N, 1)):
        if board[i][j] == 'Q':
            return False

    return True

def solve(board, col):
    if col >= N:
        return True

    for i in range(N):
        if board[i][col] == 'Q':
            return solve(board, col + 1)
        
    for i in range(N):
        if is_safe(board, i, col):
            board[i][col] = 'Q'
            if solve(board, col + 1):
                return True
            board[i][col] = '.'

    return False


solve(board, 0)
for i in range(N):
    print(''.join(board[i]))



Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

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

    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    int ans = 1 << 30;
    rep(i, n)
    {
        int tmp = 0;
        while (v[i] % 2 == 0)
        {
            tmp++;
            v[i] /= 2;
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


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

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VP;


//REPEAT
//------------------------------------------
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i > n;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,m)  RFOR(i,m,0)

//container util
//------------------------------------------
#define pb(a) push_back(a)
#define fst first
#define snd second
#define SORT(V) sort((V).begin(),(V).end())
#define REV(V) reverse((V).begin(),(V).end())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//grobal variable
//------------------------------------------

//def function
//------------------------------------------

//main
//------------------------------------------

signed main(){
  int N;
  VI h(100010);
  cin >> N;
  REP(i, N){
    cin >> h.at(i);
  }

  VI dp(100010);

  dp.at(1)=abs(h.at(0)-h.at(1));

  FOR(i, 1, N){
    dp.at(i+1) = min(dp.at(i)+abs(h.at(i)-h.at(i+1)),
    dp.at(i-1)+abs(h.at(i-1)-h.at(i+1)));
  }

  cout << dp.at(N-1) << endl;


  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int n, k, ans;
    int a[55];
    while(~scanf("%d%d", &n, &k)) {
        for(int i = 0;i < n;i++) {
            scanf("%d", &a[i]);
        }
        sort(a, a+n);
        ans = 0;
        for(int i = n-1;i >= n-k;i--) {
            ans += a[i];
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>



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

using namespace std;

int main() {
	
	string S;
	cin >> S;
	if (S == "ABC") {
		cout << "ARC";
	}
	else {
		cout << "ABC";
	}

	return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
  int n, q; cin >> n >> q;
  string s; cin >> s;
  vector<char> t(q), d(q);
  REP(i, q) cin >> t[i] >> d[i];

  function<int()> calc_r = [&](){
    function<bool(int)> check_r = [&](int i){
      for(int j = 0; j < q; j++){
        if(s[i] == t[j]){
          if(d[j] == 'L') i--;
          else i++;
        }

        if(i < 0) return false;
        if(i >= n) return true;
      }
      
      return false;
    };

    int l = -1, r = n;
    while(l + 1 < r){
      int m = (l + r) / 2;
      if(check_r(m))
        r = m;
      else
        l = m;
    }

    return n - r;
  };


  function<int()> calc_l = [&](){
    function<bool(int)> check_l = [&](int i){
      for(int j = 0; j < q; j++){
        if(s[i] == t[j]){
          if(d[j] == 'L') i--;
          else i++;
        }

        if(i < 0) return true;
        if(i >= n) return false;
      }
      
      return false;
    };

    int l = -1, r = n;
    while(l + 1 < r){
      int m = (l + r) / 2;
      if(check_l(m))
        l = m;
      else
        r = m;
    }

    return l + 1;
  };

  int l = calc_l(), r = calc_r();

    cout << max(n - r - l, 0) << endl;

  return 0;
}


Measured memory_bytes: 900
#include<iostream>
#include<algorithm>

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


int main(){
    
    int n;
    cin >> n;
    int d[100];
    rep(i,n) cin >> d[i];

    int num[110] = {0};
    rep(i,n){
        num[d[i]]++;
    }

    int res =0;
    for(int i = 1; i<= 100; ++i){
        if(num[i]){
            ++res;
        }
    }

    cout << res << endl;

    return 0;
};



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

int main()
{
	int W, a, b;
	cin >> W >> a >> b;
	int w1 = max(a, b) - (min(a, b) + W);
	cout << (w1 < 0 ?0:w1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline void LB(vector<T>& v, T& a) { return *lower_bound(ALL(v),a); }
template <typename T> inline void LBP(vector<T>& v, T& a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline void UB(vector<T>& v, T& a) { return *upper_bound(ALL(v),a); }
template <typename T> inline void UBP(vector<T>& v, T& a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template< typename T, typename V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; }
template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int N,D;
  cin >> N >> D;
  int ans = N;
  REP(ms,POW(N)) {
    vector<int> cnt(N,0);
    REP(i,N) if (ms >> i & 1) {
      for (int j = -D; j <= D; j++) {
        int n = i+j;
        if (0 <= n && n < N) cnt[i+j]++;
      }
    }
    bool ok = true;
    REP(i,N) ok &= (cnt[i] > 0);
    if (ok) CHMIN(ans,(int)__builtin_popcount(ms));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
def main():
    x = int(input())
    ans = 0
    d = 0
    if x == 1:
        return 1
    for i in range(2, x):
        d = i
        p = 2
        while d ** p <= x:
            ans = max(ans, d ** p)
            p += 1
    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3060
n=int(input())
a=[]

for i in range(n):
    a.append(int(input()))

zisyo={}
for i in range(n):
    if a[i] in zisyo:
        zisyo.pop(a[i])
    else:
        zisyo[a[i]]=1
print(len(zisyo))

Measured memory_bytes: 16276
S = input()
n = len(S)
d = [str(chr(i+97)) for i in range(26)]
ans = float('inf')
for dd in d:
    s = S
    t = ''
    m = 0
    while True:
        if s.count(dd) == len(s):
            break
        for i in range(len(s)-1):
            if s[i] == dd or s[i+1] == dd:
                t = t + dd
            else:
                t = t + s[i]
        s = t
        t = ''
        m += 1
    ans = min(ans,m)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
vector<vector<bool>> graph(8,vector<bool>(8)) ;
vector<bool> visit(8);

int dfs(int v, int N){
    
    
    bool all_Visit = true;  // 変数：全て訪問済
    
    // 全て訪問済か確認
    for(int i = 0; i < N; i++){
        if(visit[i] == false) all_Visit = false;
    }
    
    // 全て訪問のとき1を返して加える
    if(all_Visit) return 1;
    
    
    int ret = 0;  // 変数：今回の答えの値リピート
    
    for(int i = 0; i < N; i++){
        if(graph[v][i] == false) continue;  // 判定：入力時に値が入ってない
        if(visit[i]) continue; // ルート自身が存在しない時
        
        visit[i] = true;
        ret += dfs(i, N);
        visit[i] = false;  // 再設定のためリセットしている
    }
    
    return ret;
}





int main(void){
    
    int N, M;
    
    cin >> N >> M;
    
    for(int i = 0; i < M; i++){
        int A, B;
        cin >> A >> B;
        A--, B--;
        graph[A][B] = graph[B][A] = true;
    }
    
    //vector<bool> visit(8);
    for(int i = 0; i < N; i++){
        visit[i] = false;
    }
    
    visit[0] = true;
    cout << dfs(0, N) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<vector>
#include<array>
#include<algorithm>

uint64_t xor64(void) {
  static uint64_t x = 88172645463325252ULL;
  x = x ^ (x << 7);
  return x = x ^ (x >> 9);
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int D; std::cin >> D;
  int c[26];
  for(auto& ci: c) std::cin >> ci;
  std::vector<std::array<int,26>> s(D);
  for(int d = 0; d < D; ++d) {
    for(auto& si: s[d]) std::cin >> si;
  }
  std::vector<int> t(D);
  for(int i = 0; i < D; ++i) t[i] = i%26;
  std::set<int> last[26];
  for(auto& li: last) li.insert(-1); // sentinel
  int ans = 0;
  for(int d = 0; d < D; ++d) {
    int t1 = t[d];
    ans += s[d][t1];
    last[t1].insert(d);
    for(int i = 0; i < 26; ++i) {
      ans -= c[i]*(d - *last[i].rbegin());
    }
  }
  for(auto& li: last) li.insert(D); // sentinel
  
  // additional score when t[d] = i compare to t[d] = -1
  auto sum_up = [](int d) { return d*(d-1)/2; };
  auto score = [&](int d, int i)->int {
    int res = s[d][i];
    auto it = last[i].lower_bound(d);
    int nd = *it;
    int pd = *--it;
    int diff = sum_up(d-pd) + sum_up(nd-d) - sum_up(nd-pd);
    res -= c[i]*diff;
    return res;
  };
  
  // hill climbing
  int lm = 0;
  int sc[26];
  for(;;) {
    if((xor64()>>25)&1) {
      int dd = -1, ma = 0;
      for(int d = 0; d < D; ++d) {
        int pi = t[d];
        last[pi].erase(d);
        for(int i = 0; i < 26; ++i) sc[i] = score(d, i);
        int mi = std::max_element(sc, sc+26) - sc;
        int cur = sc[mi] - sc[pi];
        if(ma < cur) { ma = cur; dd = d; } 
        last[pi].insert(d);
      }
      if(ma == 0) ++lm;
      else {
        int pi = t[dd];
        last[pi].erase(dd);
        for(int i = 0; i < 26; ++i) sc[i] = score(dd, i);
        int mi = std::max_element(sc, sc+26) - sc;
        last[mi].insert(dd);
        lm = 0;
      }
    } else {
      // swap
      int d1 = xor64()%D, d2 = xor64()%D;
      while(d1 < d2-16 || d2 < d1-16 || t[d1] == t[d2]) {
        d1 = xor64()%D; d2 = xor64()%D;
      }
      int pi1 = t[d1], pi2 = t[d2];
      last[pi1].erase(d1);
      int diff = score(d1, pi2) - score(d1, pi1);
      last[pi2].insert(d1);
      last[pi2].erase(d2);
      diff += score(d2, pi1) - score(d2, pi2);
      if(diff > 0) {
        last[pi1].insert(d2);
        t[d1] = pi2;
        t[d2] = pi1;
        lm = 0;
      } else {
        last[pi2].insert(d2);
        last[pi2].erase(d1);
        last[pi1].insert(d1);
        ++lm;
      }
    }
    if(lm >= 10) break;
  }
  for(auto ti: t) std::cout << ti+1 << "\n";
  return 0;
}


Measured memory_bytes: 3708
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; ++i) {
    cin >> H[i];
  }
  int ans = 1;
  for (int i = 1; i < N; ++i) {
    bool happy = true;
    for (int j = 0; j < i; ++j) {
      if (H[j] > H[i]) happy = false;
    }
    if (happy) ++ans;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	long long a[n+1], l[n+1], r[n+1];
	a[0] = 1;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	if(a[n] != 2){
		cout << -1 << endl;
		return 0;
	}
	l[n] = 2; r[n] = 2;
	for(int i = n; i > 0; i--){
		if(((l[i]+a[i]-1)/a[i]) * a[i] > r[i] || (r[i]/a[i]) * a[i] + a[i] - 1 < l[i]){
			cout << -1 << endl;
			return 0;
		}
		l[i-1] = ((l[i]+a[i]-1)/a[i]) * a[i];
		r[i-1] = (r[i]/a[i]) * a[i] + a[i] - 1;
	}
	cout << l[0] << " " << r[0] << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;


int main(){
    int N;
    cin >> N;
    vector<int> A;
    LL sum=0;
    A.push_back(0);
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        A.push_back(a);
    }
    A.push_back(0);
    for(int i=0;i<A.size();i++){
        sum+=abs(A[i+1]-A[i]);
    }
    for(int i=1;i<A.size()-1;i++){
        if(A[i]<A[i-1]&&A[i]<A[i+1]) cout << sum-2*min(abs(A[i+1]-A[i]),abs(A[i-1]-A[i])) << endl;
        else if(A[i]>A[i-1]&&A[i]>A[i+1]) cout << sum-2*min(abs(A[i+1]-A[i]),abs(A[i-1]-A[i])) << endl;
        else cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1784
#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 int mod = 998244353;
struct mint {
 ll x;
 mint(ll x=0):x((x%mod+mod)%mod){}
 mint operator-() const { return mint(-x);}
 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;
 }

 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;
 }
};

struct combination {
 vector<mint> fact, ifact;
 combination(int n):fact(n+1),ifact(n+1) {
 assert(n < mod);
 fact[0] = 1;
 for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
 ifact[n] = fact[n].inv();
 for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
 }
 mint operator()(int n, int k) {
 if (k < 0 || k > n) return 0;
 return fact[n]*ifact[k]*ifact[n-k];
 }
} comb(1000010);

mint f(ll n) {
 mint t = 1;
 for (ll i = 0; i < n; i++)
 t *= (i+1);
 return t;
}

mint comb2(ll n, ll k) {
 mint t;
 for (ll i = 0; i < n; i++)
 t *= (n - i) / (i + 1);
 return t;
}

int main() {
  int n, m, k; cin >> n >> m >> k;
  mint ans = 0;
  for (int i = 0; i <= k; i++)
    ans += comb(n-1, i) * m * mint(m-1).pow(n-i-1);
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 18632
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func atoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	var n int
	fmt.Scan(&n)
	var a []int

	b := strings.Split(gets(), " ")

	// fmt.Println(A)
	// fmt.Println(B)

	a = append(a, atoi(b[0]))

	for i := 1; i < len(b); i++ {
		work := atoi(b[i])
		work2 := atoi(b[i-1])
		if work > work2 {
			a = append(a, work2)
		} else {
			a = append(a, work)
		}
	}
	a = append(a, atoi(b[len(b)-1]))

	sum := 0

	for _, value := range a {
		sum += value
	}

	// fmt.Println(a)
	fmt.Println(sum)
}


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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  ll n, m, x;
  cin >> n >> m >> x;
  vector<ll> c(n);
  vector<vector<long>> a(n, vector<long>(m));

  for (long i = 0; i < n; i++) {
    cin >> c.at(i);
    for (long j = 0; j < m; j++) {
      cin >> a.at(i).at(j);
    }
  }

  ll ans = 0;
  for (long i = 0; i < n; i++) {
    ans += c.at(i);
  }
  ans++;
  ll init = ans;

  for (long bit = 0; bit < (1 << n); bit++) {
    vector<long> u(m, 0);
    ll sum = 0;
    for (long i = 0; i < n; i++) {
      if (bit & (1 << i)) {
        sum += c.at(i);
        for (long j = 0; j < m; j++) {
          u.at(j) += a.at(i).at(j);
        }
      }
    }
    bool ok = true;
    for (long i = 0; i < m; i++) {
      if (u.at(i) < x) {
        ok = false;
      }
    }
    if (ok) {
      ans = min(ans, sum);
    }
  }

  if (ans == init) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 3620