akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 30, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  ;
  cin >> N >> M;
  va.resize(N);
  rep(i, 0, N - 1) { cin >> va[i]; }
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }

int div2count(int n) {
  int ret = 0;
  if (!n) return 0;
  for (;;) {
    if (n & 1) {
      return ret;
    }
    ret++;
    n >>= 1;
  }
}
void solve() {
  ;
  ;
  // auto gcd = [](int a, int b) { return b ? gcd(a % b, a) : a; };
  // auto lcm = [](int a, int b) { return a * b / gcd(a, b); };
  each(x, va) {
    x >>= 1;  // ぐうすうなので
  }
  //

  int cnt2 = div2count(va[0]);
  for (auto x : va) {
    if (cnt2 != div2count(x)) {
      cout << 0 << endl;
      return;
    }
  }

  int al = 1;
  rep(i, 0, N - 1) {
    al = lcm(al, va[i]);
    // debug2(i, al);
  }
  if (al > M) {
    cout << 0;
    return;
  }
  // if (M / al % 2 == 1) {
  //   cout << M / al / 2 + 1 << endl;
  //   return;
  // } else {
  //   cout << M / al / 2 << endl;
  // }

  // //  al = accumulate(all(va), 1, lcm);
  // auto isOK = [&](int mid, int key) {
  //   return al * mid + al / 2 <= M;  // for now
  // };
  // auto binary_search = [&](int key) {
  //   int ng = INF;
  //   int ok = -1;
  //   while (abs(ok - ng) > 1) {
  //     int mid = (ok + ng) >> 1;
  //     (isOK(mid, key) ? ok : ng) = mid;
  //   }
  //   return ok;
  // };
  // int kk = binary_search(0);
  // cout << kk + 1 << endl;
  M += al;
  cout << M / 2 / al << endl;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 1024
/*
 * 2544.cc: Older Research Bldg. No.7
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  string name("kogakubu10gokan");

  for (int i = 0; i < n; i++) {
    int yi;
    string namei;
    cin >> yi >> namei;

    if (yi > q) break;
    name = namei;
  }

  cout << name << endl;
  return 0;
}

Measured memory_bytes: 1204
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]

# Warshall-Floyd法
dist = [list(A[i]) for i in range(N)]
via = [[None for i in range(N)] for j in range(N)]
for k in range(N):
    for i in range(N):
        for j in range(N):
            d = dist[i][k] + dist[k][j]
            if dist[i][j] >= d:
                dist[i][j] = d
                if i != k and j != k:
                    via[i][j] = k

ans = 0
for i in range(N):
    for j in range(i):
        if dist[i][j] < A[i][j]:
            ans = -1
            break

        if via[i][j] == None:
            ans += dist[i][j]

    if ans == -1:
        break

print(ans)


Measured memory_bytes: 46588
#include <stdio.h>
#include <iostream>
int main() {
    int n;
    int a;
    int flag = 1;

    scanf("%d" , &n);
    int i,j;

    for(i = 0; i < n; i++) {
        scanf("%d", &a);

        if(a % 2 == 0 && a % 3 != 0 && a % 5 != 0) {
            flag = 0;
            break;
        }
    }

    if (flag == 1)
        printf("APPROVED");
    else printf("DENIED");

    return 0;
}



Measured memory_bytes: 256
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N,M = (int(_) for _ in input().split())
    ans = 0
    if(abs(N-M)>1):
        print(0)
        exit(0)
    if(abs(N-M)==1):
        ans = math.factorial(N) * math.factorial(M) % (10**9+7)
    else:
        ans = (math.factorial(N) * math.factorial(M))*2 % (10**9+7)
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 5768
def main():
    # = int(input())
    # = map(int, input().split())
    # 
    # for i in range():
    #     .append(list(map(int, input().split())))
    s = input()
    all_max = 0
    max = 0
    for i in range(len(s)):
        if s[i] == 'R':
            max += 1
        else:
            if max > all_max:
                all_max = max
            max = 0
    if max > all_max:
        all_max = max
    print(all_max)
            
if __name__ == '__main__':
    main()


Measured memory_bytes: 9104
n = int(input())
a = list(map(int, input().split()))
a.sort()
color = set()
free = 0
for i in range(n):
    if a[i] < 3200:
        color.add(a[i]//400)
    else:
        free += 1
print("{} {}".format(max(1, len(color)), free + len(color)))

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
int main(){
	int x,y,z,n;
	while(scanf("%d%d%d",&x,&y,&z)!=EOF){
		n = (x-z)/(y+z);
		printf("%d\n",n);
	}
	return 0;	
}

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

int hantei(long x);

int main(){
  long X,n;  
  scanf("%ld",&X);
  n=X;
  while(hantei(n) == 0){
    n++;
  }
  printf("%ld",n); 
  return 0;
}

int hantei(long x){
  long i,y;
  y=sqrt(x);

  if(x==2||x==3)
    return 1;
  
  if(x%2==0)
    return 0;
  
  for(i=3;i<y;i+=2){
    if(x%i==0)
      return 0;
  }
  
  return 1;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, k;
    cin >> n >> k;
    char c; string s;
    while(k--) {
        cin >> c;
        s += c;
    }
    for(int i = n;;i++) {
        bool pass = true;
        for(char c: to_string(i)) {
            if (s.find(c) != string::npos)
                pass = false;
        }
        if (pass) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}



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

void printInt(int a) {
    std::cout << a << std::endl;
}

int calcTotalForPos(int* X, int N, int P) {
    int total = 0;
    for(int i=1; i<=N; i++){
        total += std::pow(X[i] - P, 2);
    }
    return total;
}

int main(){
    int N;
    std::cin >> N;
    int X[N+1];
    for(int i=1; i<=N; i++){
        std::cin >> X[i];
    }
    
    int totals[101];
    
    for(int i=1; i<=101; i++){
        totals[i-1] = calcTotalForPos(X, N, i);
    }

    int min = 1316134911;
    for(int i=0; i<101; i++){
        if(totals[i] < min){
           min = totals[i]; 
        }
    }
    
    printInt(min);
}



Measured memory_bytes: 256
N, K = map(int, input().split())
RSP = list(map(int, input().split()))
T = list(input())
rsp = ['r', 's', 'p']
for i in range(N-K):
    if T[i] == T[i+K]:
        T[i+K] = 0
print(sum(RSP[i]*T.count(rsp[(i+1)%3]) for i in range(3)))


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

int Bubble(vector<int>& A) {
    const int N=A.size();
    int cnt=0;
    bool flag = 1; // ????????£??\????´?????????¨??????
    while(flag) {
	flag = 0;
	for(int j=N-1; j>=1; j--){
	    if(A[j] < A[j-1]) {
		swap(A[j],A[j-1]);
		flag = 1;
		cnt++;
	    }
	}
    }
    return cnt;
}

int main() {
    int n; cin >> n;
    vector<int> A(n);
    for(int i=0; i<n; i++) cin >> A[i];
    int ans = Bubble(A);
    for(int i=0; i<n; i++)
	if(i != n-1) 
	    cout << A[i] << " ";
	else
	    cout << A[i] << endl;

    cout << ans << endl;
}

Measured memory_bytes: 3076
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    int c = Integer.parseInt(sc.next());
    int d = Integer.parseInt(sc.next());
    int e = Integer.parseInt(sc.next());
    int f = Integer.parseInt(sc.next());

    double maxConc = 0;
    int ansAll = a*100;
    int ansSugar = 0;
    int ansa = 0;
    int ansb = 0;
    int ansc = 0;
    int ansd = 0;

    for (int ai = 0; (ai * 100) <= f; ai += a) {
      double conc = 0;
      for (int bi = 0; (bi * 100) <= f - (ai * 100); bi += b) {
        loop: for (int ci = 0; ci <= f - (ai * 100) - (bi * 100); ci += c) {
          for (int di = 0; di <= f - (ai * 100) - (bi * 100) - ci; di += d) {
            if ((ai + bi) * 100 + ci + di > f) {
              break;
            } else if ((ai + bi) * e < ci + di) {
              break;
            } else if (ai + bi == 0) {
              break loop;
            } else {
              conc = (double) (100 * (ci + di)) / ((ai + bi) * 100 + ci + di);
              if (conc > maxConc) {
                maxConc = conc;
                ansAll = (ai + bi) * 100 + ci + di;
                ansSugar = ci + di;
                // ansa = ai;
                // ansb = bi;
                // ansc = ci;
                // ansd = di;
              }
            }
          }
        }
      }
    }

    System.out.println(ansAll + " " + ansSugar);
//    System.out.println(ansa + " " + ansb + " " + ansc + " " + ansd);
    sc.close();
  }

}


Measured memory_bytes: 20948
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;

int main() {
    long double a, b, h, m;
    cin >> a >> b >> h >> m;

    const long double angle = 2.0 * 3.14159265359 * (
        (h + m / 60.0) / 12.0 - m / 60.0
    );
    const long double dist = sqrt(
        (a * a + b * b) - (2.0 * a * b) * cos(angle)
    );
    cout << fixed << setprecision(20) << dist;
    return 0;
}

Measured memory_bytes: 4160
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

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

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a) * b);
}

xy_t projection(const line &l, const xy_t &p){
	double t = dot(p - l.first, l.first - l.second) / norm(l.first - l.second);
	return l.first + t * (l.first - l.second);
}

bool intersectSP(const line &l, const xy_t &p){
	return abs(l.first- p) + abs(l.second - p) - abs(l.first - l.second) < EPS;
}

double distanceSP(line s, xy_t p){
	const xy_t r = projection(s, p);
	if(intersectSP(s, r)) return abs(r - p);
	return min(abs(s.first - p), abs(s.second - p));
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
char field[200][200];

int main(){
	int n, d;
	cin >> d;
	rep(t, d){
		if(t != 0) cout << endl;
		cin >> n;
		if(n == 2){
			cout << "##\n# \n";
			continue;
		}
		fill(&field[0][0], &field[199][199] + 1, '#');
		rep(i, n + 2){
			rep(j, n + 2) field[i+1][j+1] = ' ';
		}
		int x = 2;
		int y = 2 + n - 1;
		int cnt = 0;
		int dire = 0;
		while(true){
			cnt = 0;
			while(field[y + 2 * dy[dire]][x + 2 * dx[dire]] != '#'){
				cnt++;
				field[y][x] = '#';
				y += dy[dire];
				x += dx[dire];
			}
			field[y][x] = '#';
			if(cnt < 2) break;
			dire = (dire + 1) % 4;
		}
		rep(i, n){
			rep(j, n) cout << field[i+2][j+2];
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  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;
  }
 
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {
	ll n;
	cin >> n;
	mint ans = 10, a = 9, b = 8;
	ans = ans.pow(n);
	a = a.pow(n);
	b = b.pow(n);
	ans -=a*2;
	ans+=b;
	cout<<ans.x<<endl;
	return 0;
}


Measured memory_bytes: 3616
/*
********************
Author : Sahil Kundu
********************
*/
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb(i) push_back(i)
#define pp() pop_back()
#define f first
#define s second
#define mk(l,r) make_pair(l,r)
#define all(vc) vc.begin(),vc.end()
#define bg(vc) vc.begin()
#define ed(vc) vc.end()
#define ms(i,j) memset(i,j,sizeof i)
#define w(t) while(t--)
const ll MAX=1e5+5;
const ll INF=2e18;
/*bool isprime[MAX];
vector<ll> vc;
void init()
{
    ms(isprime,true);
    isprime[1]=false;
    for(ll i=2;i*i<=MAX;i++)
    {
        if(isprime[i])
        {
            for(ll j=i*i;j<=MAX;j+=i)
                isprime[j]=false;
        }
    }
    for(ll i=2;i<=MAX;i++)
        if(isprime[i])
        vc.pb(i);
}*/
int ans[MAX]={0};
list<int>*vc;
void dfs(int u,bool vis[],int n)
{
    vis[u]=true;
    list <int> que;
    que.pb(u);
   	//for(auto a:que)
      //  cout<<a<<" ";
    while(!que.empty())
    {
        int s= que.front();
        que.pop_front();
        for(auto i=vc[s].begin();i!=vc[s].end();i++)
        {
            //cout<<*i<<endl;
            if(!ans[*i])
                    ans[*i]=s;
            if(!vis[*i])
            {
                que.pb(*i);
                vis[*i]=true;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    //cin>>t;
    //init();
    w(t)
    {
        int n,m;
        cin>>n>>m;
        vc=new list<int>[n+1];
        for(int i=0;i<m;i++)
        {
            int u,v;
            cin>>u>>v;
            vc[u].pb(v);
            vc[v].pb(u);
        }
        
        int count=0;
        bool vis[MAX]={false};
        dfs(1,vis,n);
        int flag=0;
        for(int i=2;i<=n;i++)
        {
            //cout<<"i "<<i<<" "<<ans[i]<<endl;
            if(!ans[i])
            {
                cout<<"No"<<endl;
                flag=1;
            }
            if(flag)
                break;
        }
        if(flag)
            continue;
        cout<<"Yes\n";
        for(int i=2;i<=n;i++)
            cout<<ans[i]<<endl;
    }
}
/*
ll msb(ll x)
{
	ll k=(ll)log2(x);
	return (ll)(pow(2,k));
}
#define gc getchar_unlocked
void scanint(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}*/

Measured memory_bytes: 22028
#include<iostream>
#include<algorithm>
#include<vector>
#include <iomanip>
#include <math.h>
 
using namespace std;
 
int main(){
	int n;
  	cin >> n;
  
  	int b,f,r,v;
  	vector<vector<vector<int> > > residence(4, vector<vector<int> >(3, vector<int>(10, 0)));
  	for(int i=0; i<n; i++){
    	cin >> b >> f >> r >> v;
      	residence.at(b-1).at(f-1).at(r-1) += v;
    }
  
  	for(int k=0; k< 4; k++){
    	for(int j=0; j< 3; j++){
	    	for(int i=0; i< 10; i++){
				cout << " " << residence.at(k).at(j).at(i);
            }
          cout << endl;
        }
        if(k==3){
        	break;
        }  
      	cout << "####################";
      	cout << endl;
    }
  
  	
  return 0;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
#define F(n) for(int i=0;i<n;++i)

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c>21) cout << "bust" << endl;
    else cout << "win" << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define __STDC_FORMAT_MACROS
#include <array>
#include <cinttypes>
#include <cstdio>
#include <functional>
#include <queue>
#include <vector>

using namespace std;

template<class T> void gc(T &x)
{
    char c;
    int s = 0;
    x = 0;

    c = getchar_unlocked();

    if (c == '-') s = 1;
    else if ('0' <= c && c <= '9')  x = c - '0';

    while (true)
    {
        c = getchar_unlocked();

        if (c < '0' || c > '9') break;
        x = x * 10 + (c - '0');
    }

    if (s) x = -x;
}

int main()
{
    int N;
    if (scanf("%d", &N) < 1) return 0;

    array<int, 300000> ary;

    int64_t sum = 0;

    for (int i = 0; i < 3 * N; i++)
    {
        int tmp = 0;
        gc(tmp);
        ary[i] = tmp;
    }

    // for push
    int now;

    // for top
    int cur;

    priority_queue<int, vector<int>, greater<int> > qg;
    for (int i = 0; i < N; i++)
    {
        now = ary[i];
        qg.push(now);
        sum += now;
    }

    array<int64_t, 100001> aryMax;

    aryMax[0] = sum;

    for (int i = N; i < 2 * N; i++)
    {
        now = ary[i];

        qg.push(now);

        sum += now;

        cur = qg.top();

        sum -= cur;
        qg.pop();

        aryMax[i - N + 1] = sum;
    }

    sum = 0;

    // クリア
    qg = priority_queue<int, vector<int>, greater<int> >();

    priority_queue<int, vector<int>, less<int> > ql;
    for (int i = 3 * N - 1; 2 * N <= i; i--)
    {
        now = ary[i];
        ql.push(now);
        sum += now;
    }

    array<int64_t, 100001> aryMin;

    aryMin.fill(0);

    aryMin[N] = sum;

    for (int i = 2 * N - 1; N <= i; i--)
    {
        now = ary[i];

        ql.push(now);

        sum += now;

        cur = ql.top();

        sum -= cur;
        ql.pop();

        aryMin[i - N] = sum;
    }

    int64_t ans = aryMax[0] - aryMin[N];
    for (int i = 0; i <= N; i++)
    {
        ans = max(ans, aryMax[i] - aryMin[i]);
    }

    // クリア
    ql = priority_queue<int, vector<int>, less<int> >();

    printf("%" PRId64 "\n", ans);
    return 0;
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
typedef long long ll;
using namespace std;
 

int main(){
   int a,b,m; cin >> a >> b >> m;
   vector<int> aa(a); vector<int> bb(b);
   int ma=100100100; int mb=100100100;
   rep(i,a){
        cin >> aa[i];
        ma=min(ma,aa[i]);
   }
   rep(i,b){
        cin >> bb[i];
        mb=min(mb,bb[i]);
   }
   int ans=ma+mb;
   rep(i,m){
       int x,y,z; cin >> x >> y >> z;
       ans=min(ans,aa[x-1]+bb[y-1]-z);
   }
   cout << ans << endl;
return 0;
}


Measured memory_bytes: 1024
#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
ll mod = 1000000007LL;




int main() {
	int n, k;
	cin >> n >> k;
	
	vector<int> vs(n);
	rep(i, n) {
		cin >> vs[i]; 
	}

	int ans = 0;
	int max_l = min(k, n + 1);


	rep(l, max_l + 1) {
		vector<int> vrs;
	
		int cur_k_l = k - l;
		rep(i,l) {
			vrs.push_back(vs[i]); 			
		}

		int max_r = min(cur_k_l, n - l);
		rep(r, max_r + 1) {
			int cur_k_r = cur_k_l - r;


			vector<int> vrls = vrs;

			rep(i, r) {
				vrls.push_back(vs[vs.size() - i - 1]);
			}

			sort(vrls.begin(), vrls.end());
			
			int total = 0;
			rep(i, vrls.size()) {
				if (cur_k_r > 0 && vrls[i] < 0) {
					cur_k_r--;
					continue;
				}
				total += vrls[i];
			}
			//cout << "l:" << l << " r:" << r << " vrls.size():" << vrls.size();
			//cout << " total:" << total << endl; 

			ans = max(total, ans);
		}
	}
	cout << ans << endl;

	return 0;
}


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

int main() {
    int N,K;
    cin >> N >> K;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        int height;
        cin >> height;
        if(height >= K) ans++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int H, W;
  cin >> H >> W;
  cout << string(W + 2, '#') << endl;
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    cout << "#" << s << "#" << endl;
  }
  cout << string(W + 2, '#') << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
            for (int i = 0; i < count; i++)
            {
                var d = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).OrderByDescending(n => n).Select(n => n * n).ToArray();
                Console.WriteLine(d[0] == d[1] + d[2] ? "YES" : "NO");
            }
        }
    }
}

Measured memory_bytes: 6312
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <numeric>
using namespace std;

int main(){
    int N;
    cin >> N;
    int storeN = N;

    int S = 0;

    while(N > 0){
        S = S + N % 10;
        N = (N - N % 10) / 10;
    }

    if(storeN % S == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	k := sc.ReadInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = sc.ReadInt()
	}

	for i := k; i < n; i++ {
		if a[i] > a[i-k] {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}

}

// from [my library](https://github.com/ikngtty/go-contestlib)
// -   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base, exponent int) int {
	if exponent < 0 {
		panic(fmt.Sprintf("exponent (%d) should not be a minus", exponent))
	}

	answer := 1
	for i := 0; i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Ceil(divident, dividor int) int {
	if dividor == 0 {
		panic("dividor should not be 0")
	}

	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// -   sortutil

func ReverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// -   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 5920
import java.util.*;

public class Main {

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

    }

}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007ll
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define sorrev(v) sort(v.begin(),v.end(),greater<ll>())
#define uni(v) unique(v.begin(),v.end())
#define bs binary_search
#define lb(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define ub(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

int main() 
{
    FAST;
    ll n;
    cin>>n;
    ll maxplus=LLONG_MIN,minplus=LLONG_MAX,maxminus=LLONG_MIN,minminus=LLONG_MAX;
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        maxplus=max(maxplus,x+y);
        minplus=min(minplus,x+y);
        maxminus=max(maxminus,x-y);
        minminus=min(minminus,x-y);
    }
    cout<<max(maxplus-minplus,maxminus-minminus);
    subt;
    return 0;
}

Measured memory_bytes: 3788
w,h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
maxw=0
minw=w
maxh=0
minh=h
for i in range(n):
  if a[i][-1]==1:    
    maxw=max(a[i][0],maxw)
  elif a[i][-1]==2:
    minw=min(a[i][0],minw)
  elif a[i][-1]==3:    
    maxh=max(a[i][1],maxh)
  else:
    minh=min(a[i][1],minh)
    
haba=max(0,minw-maxw)
takasa=max(0,minh-maxh)

print(haba*takasa)

Measured memory_bytes: 3064
n,k = map(int,input().split())
a = list(range(n+1))
b = a[::-1]
ans = 0

min = sum(a[:k-1])
max = sum(b[:k-1])


for i in range(k,n+2):
    min += a[i-1]
    max += b[i-1]
    ele = max - min +1
    ans += ele

M =10**9 + 7
print(ans % M)

Measured memory_bytes: 69476
//
//  main.c
//  AtCoder
//
//  Created by kasahara shoji on 2018/05/11.
//  Copyright © 2018年 kasahara shoji. All rights reserved.
//

#include <stdio.h>

int check(int a,int b,int c){
    int data;
    if(a>=b)data=a;
    else data=b;
    if(data>=c){}
    else data=c;
    
    return data;
}

int main(){
    
    int A,B,C,K;
    int d;
    int all;
    
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    scanf("%d",&K);
    
    d=check(A,B,C);
    if(d==A)all=B+C;
    if(d==B)all=A+C;
    if(d==C)all=B+A;
    
    for(int i=0;i<K;i++){
        d*=2;
    }
    printf("%d",d+all);
    return 0;
}


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

import numpy as np

N = int(input())
A = [int(_) for _ in input().split()]

# A_n = [a + b + 1 for a, b in enumerate(A)]

# ret = 0
# for n in range(len(A)):
#     #print(A_n[:n], n + 1 - A[n])
#     ret += A_n[:n].count(n + 1 - A[n])
# print(ret)

nmax = int(2e5 + 1)
X = [0] * nmax
Y = [0] * nmax
for n, a in enumerate(A):
    x = n - a
    y = n + a
    if x >= 0 and x < nmax:
        X[x] += 1
    if y >= 0 and y < nmax:
        Y[y] += 1
ret = 0
for x, y in zip(X, Y):
    ret += x * y
print(ret)


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

#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define ld long double
#define pb push_back
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000000
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >


ll mulmod(ll, ll);
ll fastpower(ll, ll);
void getprime(vector<bool>&);
void getfact(vector<ll>&, vector<ll>&);
ll ncr(ll, ll, vector<ll>&, vector<ll>&);

void solve()
{
    ll n, x;
    cin>>n;
    x = n % 1000;
    if(x == 0)
        x = 1000;
    ll res = 1000 - x;
    cout<<res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t = 1;
    //cin>>t;
    while(t--)
    {
        solve();        
    }
    return 0;
}

ll mulmod(ll a, ll b)
{
    ll res = 0; 
    a = a % MOD;
    while(b > 0)
    {
        if (b % 2 == 1)
            res = (res + a) % MOD;
 
        a = (a * 2) % MOD; 
        b /= 2;
    } 
    return res % MOD; 
}

ll  fastpower(ll a, ll n)
{
    ll res = 1;
    while(n > 0)
    {
        if(n % 2 != 0)
        {
            res = (res * a) % MOD;
        }
        n /= 2;
        a = (a * a) % MOD;
    }
    return res;
}

void getprime(vector<bool>&prime)
{
    prime[0] = false;
    prime[1] = false;
    
    for(ll i = 2;i <= MAX; i++)
    {
        if(prime[i])
        {
            for(ll j = i*i; j <= MAX; j += i)
                prime[j] = false;
        }
    }
}

void getfact(vector<ll> &fact, vector<ll> &ifact)
{
    fact[0] = 1;
    ifact[0] = 1;
    
    for(ll i = 1; i <= MAX; i++)
    {
        fact[i] = (fact[i-1] * i)%MOD;
        ifact[i] = (ifact[i-1] * fastpower(i, MOD -2) )%MOD;
    }
}

ll ncr(ll n, ll r, vector<ll>&fact, vector<ll>&ifact)
{
    ll res;
    res = (((fact[n] * ifact[r]) % MOD) * ifact[n-r]) % MOD;
    return res;
}


Measured memory_bytes: 3612
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    n = int(input())
    li = [0] * n
    ri = [0] * n
    for i in range(n):
        li[i], ri[i] = map(int, input().split())
    li.sort()
    ri.sort()
    ans = 0
    if n % 2 == 1:
        l = li[n//2]
        r = ri[n//2]
        ans = r-l+1
    else:
        l = li[n//2-1]+li[n//2]
        r = ri[n//2-1]+ri[n//2]
        ans = r-l+1
    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 74476
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

k = I()
s = S()

if len(s)<=k:
    print(s)
else:
    ans = s[:k] + "..."
    print(ans)

Measured memory_bytes: 68280
#include <cstdio>
#include <iostream>
#include <queue>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <map>

#ifdef __BORLANDC__
	typedef __int64 Long;
#else 
	typedef long long Long;
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) b = min(a, b)
#define pb push_back
#define mp make_pair

using namespace std;

int main(){
	rep(i, 9) rep(j, 9){
		Long a = i + 1;
		Long b = j + 1;
		cout << a << "x" << b << "=" << a * b << endl;
	}
	
	return (0);
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<int> h(n);
  re(i, n) cin >> h[i];

  int c = 1;
  int max = h[0];
  fo(i, 1, n) {
    if (max <= h[i]) {
      c++;
      max = h[i];
    }
  }

  cout << c << endl;

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef int64_t Int;
typedef uint64_t uInt;
const double pi = M_PI;

int main() {
    string s;
    cin >> s;

    Int ans = 0, temp = 0;
    bool flag = false;
    for (Int i = 0; i < s.size(); i++) {
        for (Int j = i; j < s.size(); j++) {
            switch (s[j]) {
            case 'A':
            case 'C':
            case 'G':
            case 'T':
                temp++;
                break;

            default:
                flag = true;
                break;
            }

            if (flag) {
                flag = false;
                break;
            }
        }

        ans = max(ans, temp);
        temp = 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

const int md = 998244353;

void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

const int N = 307;

int dp[N][N][N];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  string s; int k;
  cin >> s >> k;
  int n = s.size();
  vector <int> have;
  int cur = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '0') {
      have.push_back(cur);
      cur = 0;
    } else {
      ++cur;
    }
  }
  have.push_back(cur);
  int m = have.size();
  dp[m][0][0] = 1;
  for (int i = m - 1; i >= 0; --i) {
    for (int go = 0; go <= n; ++go) {
      for (int cost = 0; cost <= n; ++cost) {
        if (dp[i + 1][go][cost] == 0) continue;
        for (int d = 0; d <= go; ++d) {
          add(dp[i][go - d][cost], dp[i + 1][go][cost]);
        }
        for (int d = 1; d <= have[i]; ++d) {
          add(dp[i][go + d][cost + d], dp[i + 1][go][cost]);
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= min(k, N - 1); ++i) {
    add(ans, dp[0][0][i]);
  }
  cout << ans << '\n';
}



Measured memory_bytes: 30936
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    cin >> n;
    vector<vector<int>> num(10, vector<int>(10, 0));
    for ( int i = 1; i <= n; ++i ) {
        string tmp_s = to_string(i);
        ++num[tmp_s.front()-'0'][tmp_s.back()-'0'];
    }
    int ans = 0;
    for ( int i = 1; i <= n; ++i ) {
        string tmp_s = to_string(i);
        ans += num[tmp_s.back()-'0'][tmp_s.front()-'0'];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n = intin()
    wlist = [input() for _ in range(n)]

    history = []
    prev = None
    for w in wlist:

        if w in history:
            print('No')
            return
        history.append(w)

        if prev is None:
            prev = w
            continue
        if w[0] != prev[-1]:
            print('No')
            return
        prev = w

    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include<stdio.h>
#include<stdlib.h>
#define MAX 10000
struct node{
  int key;
  int cost;
  struct node *next;
};

typedef struct node *adj;
adj G[MAX];
adj SuperNode(int key,int cost,adj Node){
  adj n;
  n=(adj)malloc(sizeof(struct node));
  n->key=key;
  n->cost=cost;
  n->next=Node;
  return n;
}

adj Insert(int a,int b,int c){
  adj H;
  H=SuperNode(b,c,G[a]->next);
  G[a]->next=H;
}

int main(){
  int i,j,n,count=0,v,c,c1,v1;
  int color[MAX],D[MAX],pi[MAX],nx,min;
  adj H;

  scanf("%d",&n);
  for(i = 0;i < n;i++)G[i]=SuperNode(0,0,NULL);
  for(i = 0;i < n;i++){
    scanf("%d%d",&v,&c);

    for(j = 0;j <c;j++){
      scanf("%d %d",&v1,&c1);
    Insert(i,v1,c1);
  }
}

for(i=0;i<n;i++){
  color[i]=0;
  pi[i]=-1;
  D[i]=10000000;
 }
 D[0]=0;

while(1){
  min=10000000;
  for(i=0;i<n;i++){
    if(color[i] != 2 && D[i] < min){
      min=D[i];
      nx=i;
    }
  }

  if(min==10000000)break;
  color[nx]=2;

  for(H=G[nx];H!=NULL;H=H->next){
    if(color[H->key] !=2 && (H->cost+D[nx]) < D[H->key]){
        pi[H->key]=nx;
        D[H->key]=H->cost+D[nx];
        color[H->key]=1;
    }

  }
 }
 for(i=0;i<n;i++)printf("%d %d\n",i,D[i]);
return 0;
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
 
const int N=200005;

int n,k,c;
int a[N],b[N];
char s[N];

void init()
{scanf("%d %d %d",&n,&k,&c);
 scanf("%s",s+1);
}

void work()
{int pos=0;
 for (int i=1;i<=n;i++)
   if (s[i]=='o')
     {a[++pos]=i;
      if (pos>=k) break;
      i+=c;
     }
 pos=k;
 for (int i=n;i>=1;i--)
   if (s[i]=='o')
     {b[pos--]=i;
      if (pos<=0) break;
      i-=c;
	 }
 for (int i=1;i<=k;i++)
   if (a[i]==b[i])
     printf("%d\n",a[i]);  
}

int main()
{
 init();
 work();
 return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll A, B; cin >> A >> B;
  ll result = A * B;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3644
import numpy as np
from numba import njit, i8


@njit(i8(i8, i8, i8[:, :]), cache=True)
def solve(R, C, items):
    dp = np.zeros((R + 1, C + 1, 4), dtype=np.int64)
    for i in range(R):
        for j in range(C):
            for k in range(2, -1, -1):
                dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k] + items[i][j])
            for k in range(4):
                dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k])
                dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k])
    return dp[R][C - 1][0]


R, C, K, *rcv = map(int, open(0).read().split())
items = np.zeros((R + 1, C + 1), dtype=np.int64)
for r, c, v in zip(*[iter(rcv)] * 3):
    items[r - 1][c - 1] = v
print(solve(R, C, items))


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

double distance(double x1,double y1,double x2,double y2){
  return sqrt(pow((x2-x1),2)+pow((y2-y1),2));
}

double heron(double a,double b,double c){
  double z=(a+b+c)/2;
  return sqrt(z*(z-a)*(z-b)*(z-c));
}

int main(void){
  int n=0,i;
  double x[20],y[20],ans=0,a,b,c;
  while(scanf("%lf,%lf",&x[n],&y[n])!=EOF)
    n++;
  for(i=0;i<n-2;i++){
    a=distance(x[0],y[0],x[i+1],y[i+1]);
    b=distance(x[i+1],y[i+1],x[i+2],y[i+2]);
    c=distance(x[0],y[0],x[i+2],y[i+2]);
    ans+=heron(a,b,c);
  }
  printf("%.6f\n",ans);
  return 0;
}

Measured memory_bytes: 656
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use itertools::Itertools;

#[fastout]
fn main() {
    input! {
    n: usize,
    m: usize,
    mut x: [i64; m]
    }
    x.sort();
    let d = (1..m).map( |i| x[i] - x[i - 1]).sorted().collect::<Vec<i64>>();
    let ans = d[..m.checked_sub(n).unwrap_or(0)].iter().sum::<i64>();
    println!("{}", ans);
}

Measured memory_bytes: 4432