akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void)
{
	int x, y, z;
	int a;

	scanf("%d%d%d", &x, &y, &z);

	if (x > y)
	{
		a = x;
		x = y;
		y = a;
	}

	if (x > z)
	{
		a = x;
		x = z;
		z = a;
	}

	if (y > z)
	{
		a = y;
		y = z;
		z = a;
	}

	printf("%d %d %d\n", x, y, z);

	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Graph vector<vector<ll>>
#define INF (1ll<<60)
#define mod 1000000007
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; }

int main(){
    ll n;cin>>n;
    vector<vector<ll>> a(n,vector<ll>(n));
    rep(i,n)rep(j,n) cin>>a[i][j];

    vector<vector<ll>> dp(25,vector<ll>(1<<n,0));
    dp[0][0]=1;

    rep(i,n){//i番目の男性まで組を作っている
        rep(j,(1<<n)){//すでに組んでいる女性をbitで表現
            if(dp[i][j]==0) continue;
            rep(k,n){
                if(!((j>>k)&1) && a[i][k]){
                    dp[i+1][j|(1<<k)]+=dp[i][j];
                    dp[i+1][j|(1<<k)]%=mod;
                }
            }
        }
    }

    cout<<dp[n][(1<<n)-1]<<endl;
    return 0;
}

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

int main(){
    ll N,count=0;
    cin >> N;
    vector<ll> now(N+1);
    repr(i,1,N+1){
        cin >> now[i];
        if(now[i]!=i){
            count++;
        }
    }
    if(count==0||count==2){
        puts("YES");
    }else{
        puts("NO");
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

#ifndef GCD
#define GCD
// solve ax+by=gcd(a, b)
// return gcd(a, b)
template<typename T>
T gcd(const T a, const T b, T* const px = nullptr, T* const py = nullptr){
	if(py == nullptr){
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	T d = a;
	if(b != 0){
		d = gcd(b, a % b, py, px);
		*py -= (a / b) * *px;
	}else{
		*px = 1; *py = 0;
	}
	return d;
}
#endif

#ifndef LCM
#define LCM
// return lcm(a, b)
template<typename T>
T lcm(const T a, const T b){
	T ret = a / gcd(a, b);
	ret *= b;
	return ret;
}
#endif


int main(void){
	ll A, B, C, D;
	cin >> A >> B >> C >> D;

	ll res = B - A + 1;
	res -= B / C - (A - 1) / C;
	res -= B / D - (A - 1) / D;
	ll E = lcm(C, D);
	res += B / E - (A - 1) / E;

	cout << res << '\n';

	return 0;
}


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

class Main {
  public static void main(String[] args) throws Exception{
    try (Scanner sc = new Scanner(System.in)){
      String S = sc.next();
      String T = sc.next();
      HashMap<Character, Integer> hm = new HashMap<Character, Integer>();
      for (int i = 0; i < S.length(); i++) {
        if (hm.containsKey(S.charAt(i))) {
          hm.put(S.charAt(i), hm.get(S.charAt(i)) + 1);
        } else {
          hm.put(S.charAt(i), 1);
        }
      }
      HashMap<Character, Integer> hm2 = new HashMap<Character, Integer>();
      for (int i = 0; i < T.length(); i++) {
        if (hm2.containsKey(T.charAt(i))) {
          hm2.put(T.charAt(i), hm2.get(T.charAt(i)) + 1);
        } else {
          hm2.put(T.charAt(i), 1);
        }
      }
      int[] arr1 = new int[hm.size()];
      int[] arr2 = new int[hm2.size()];
      int i = 0;
      for (Integer var : hm.values()) {
        arr1[i] = (int)var;
        i++;
      }
      i = 0;
      for (Integer var : hm2.values()) {
        arr2[i] = (int)var;
        i++;
      }
      Arrays.sort(arr1);
      Arrays.sort(arr2);
      //System.out.println(Arrays.toString(arr2));
      if (arr1.length != arr2.length) {
        System.out.println("No");
        return;
      } else {
        for (int j = 0; j < arr1.length; j++) {
          if (arr1[j] != arr2[j]) {
            System.out.println("No");
            return;
          }
        }
        System.out.println("Yes");
      }
    }
  }
}


Measured memory_bytes: 34872
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {

  double a, b, c, d;

  cin >> a >> b >> c >> d;

  double height = c - a;
  double width = d - b;
  double distance = sqrt(pow(height,2) + pow(width, 2));

  cout << fixed << setprecision(6) << distance << endl;
  return 0;

}

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

int main() {
	string S;
	int ans = 0, a;
	cin >> a;
	cin >> S;
	for (int i = 0; i < S.size()-2; i++) {
		if (S[i] == 'A') {
			if (S[i + 1] == 'B' && S[i + 2] == 'C') {
				ans++;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#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;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define ceil(a,b) (a+b-1)/b
#define endl "\n"
 const int N=100005;
 const int inf=1e17;
 const double eps=1e-9;
int pow1(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=res*a;
		}
        a=a*a;
        b>>=1;
    }
    return res;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int h,n;
    cin>>h>>n;
    int a[n],b[n];
    for(int x=0;x<n;x++){
        cin>>a[x]>>b[x];
    }
    int dp[h+1];
    for(int x=0;x<=h;x++){
        dp[x]=inf;
    }
    dp[h]=0;
    for(int x=h;x>=1;x--){
        for(int i=0;i<n;i++){
            if(x-a[i]>=0){
                if(dp[x-a[i]]>dp[x]+b[i]){
                    dp[x-a[i]]=dp[x]+b[i];
                }
            }else{
                if(dp[0]>dp[x]+b[i]){
                    dp[0]=dp[x]+b[i];
                }
            }
        }
    }
    cout<<dp[0];








	
return 0;
}


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

int main(){
  char a;
  cin >> a;
  string big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  string sml = "abcdefghijklmnopqrstuvwxyz";
  for(int i = 0; i < 26; i++){
    if(big[i] == a){
      cout << "A" << endl;
      break;
    }else if(sml[i] == a){
      cout << "a" << endl;
      break;
    }
  }
}

Measured memory_bytes: 3596
#include <functional>
#include <algorithm>
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <cctype>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <queue>
#include <stdio.h>
#include <stack>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define TR(i,x) for(__typeof(x.begin()) i=x.begin();i!=x.end();i++)
#define ALL(x) x.begin(),x.end()
#define SORT(x) sort(ALL(x))
#define CLEAR(x) memset(x,0,sizeof(x))
#define FILL(x,c) memset(x,c,sizeof(x))
#define PB push_back
#define MP make_pair

using namespace std;

const double eps = 1e-8;

typedef map<int,int> MII;
typedef map<string,int> MSI;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<long double> VD;
typedef pair<int,int> PII;
typedef long long int64;
typedef long long LL;
typedef unsigned int UI;
typedef long double LD;

int main() {
    long long n, k;
    cin >> n >> k;
    int h[200005];

    REP(i, n) {
        cin >> h[i];
    }
    if (k >= n) {
        cout << 0 << endl;
        return 0;
    }
    sort(h, h + n);
    long long a = 0;
    REP(i, n - k) {
        a += h[i];
    }
    cout << a << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
    int N, A, B, C, D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;
    
    S = "#" + S + "#";

    auto can_reach = [&](int start, int end) {
        for (int i = start; i + 1 <= end; i++) {
            if (S[i] == '#' && S[i + 1] == '#') return false;
        }
        return true;
    };

    if (!can_reach(A, C) || !can_reach(B, D)) {
        cout << "No" << endl;
        return 0;
    }

    if (C > D) {
        bool snuke_can_over = false;
        for (int i = B; i <= D; i++) {
            if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') {
                snuke_can_over = true;
            }
        }
        if (!snuke_can_over) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 772
let to_array s = Str.split (Str.regexp_string " ") s
                 |> List.map float_of_string
                 |> Array.of_list;;
let is_parallel x1 y1 x2 y2 x3 y3 x4 y4 =
  let prod =(x2 -. x1) *. (y4 -. y3) -. (x4 -. x3) *. (y2 -. y1) in
  if prod < (1e-10) && prod > -.(1e-10) then true else false;;

let is_orthogonal x1 y1 x2 y2 x3 y3 x4 y4 =
  let inner_prod = (x2 -. x1) *. (x4 -. x3) +. (y2 -. y1) *. (y4 -. y3) in
  if inner_prod < (1e-10) && inner_prod > -.(1e-10) then true else false

let rec read = function
    0 -> ()
  | i -> let l = read_line () |> to_array in
         let (x1,y1,x2,y2,x3,y3,x4,y4) = (l.(0),l.(1),l.(2),l.(3),l.(4),l.(5),l.(6),l.(7))
         in
         let () = if is_parallel x1 y1 x2 y2 x3 y3 x4 y4 then print_endline "2"
                  else if is_orthogonal x1 y1 x2 y2 x3 y3 x4 y4 then print_endline "1"
                  else print_endline "0"
         in read (i-1);;
let () = read_int () |> read;;

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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

int n; long m;
long A[100003], pref[100003];

long sum;
long hit(long num)
{
	sum = 0;
	int idx = n;
	long res = 0;
	for(int i = 1; i <= n; i++)
	{
		while(A[i]+A[idx] < num && idx) idx--;
		res += idx;
		sum += pref[idx] + 1LL*idx*A[i];
	}
	return res;
}

int main()
{
	// freopen("input.in", "r", stdin);

	scanf("%d %lld", &n, &m);
	for(int i = 1; i <= n; i++)
		scanf("%lld", &A[i]);

	sort(A+1, A+1+n);
	reverse(A+1, A+1+n);
	for(int i = 1; i <= n; i++)
		pref[i] = pref[i-1]+A[i];

	long kir = 0, kan = A[1]+A[1];
	while(kir < kan)
	{
		long mid = (1+kir+kan)/2;
		if(hit(mid) < m) kan = mid-1;
		else kir = mid;
	}
	long x = hit(kir);
	printf("%lld\n", sum - (x-m)*kir);
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
 
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	long long int n,t,a;
	vector <long long int> v;
 
	cin >> n >> t;
 
	for(int i=0;i<n;i++)
	{
		cin >> a;
		v.push_back(a);
	}

	long long int res = 0; 
	for(int i=1;i<n;i++)
	{
		res += min(t,v[i]-v[i-1]);	
	}
	res+=t;
	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>

using namespace std;
typedef long long ll;

int main() {
  vector<ll> n(3);
  int k;
  for (int i = 0; i < 3; i++) {
    cin >> n[i];
  }
  cin >> k;
  
  vector<vector<ll>> v(3);
  for (int i = 0; i < 3; i++) {
    v[i].resize(n[i]);
    for (int j = 0; j < n[i]; j++) {
      cin >> v[i][j];
    }
    sort(v[i].begin(), v[i].end(), greater<ll>());
  }
  
  priority_queue<pair<ll, vector<int>>> pq;
  set<pair<ll, vector<int>>> s;
  pq.push({v[0][0] + v[1][0] + v[2][0], vector<int>({0, 0, 0})});
  
  for (int i = 0; i < k; i++) {
    auto c = pq.top(); pq.pop();
    cout << c.first << endl;
    
    for (int j = 0; j < 3; j++) {
      if (c.second[j] + 1 < n[j]) {
        ll sum = c.first - v[j][c.second[j]] + v[j][c.second[j] + 1];
        auto num = c.second;
        num[j]++;
        pair<ll, vector<int>> d = {sum, num};
        if (s.count(d) == 0) {
          s.insert(d);
          pq.push(d);
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
long long n,s,cnt,i;
int main() {
	cin>>n;
	while(i<n) {
		++i;
		if(i%3==0) continue;
		if(i%5==0) continue;
		s+=i;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG



int main() {
  ll X, Y, a, b;
  cin >> X >> Y;
  
  if((4*X-Y) % 2 == 0){
    a = (4*X-Y)/2;
    if(0 <= a && a <= X){
      cout << "Yes" << endl;
      return 0;
    }
  }




  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void solve(long long N, long long K) {
  double ans = 0.0;
  for (ll n = 1; n <= N; n++) {
    ll p = 0;
    if (n < K) {
      p = ceil((double)log2((double)K / n));
    }
    ans += 1.0 / N * pow((1.0 / 2), p);
  }
  printf("%.12f\n", ans);
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  solve(N, K);
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  string s,t;
  cin>>s>>t;
  ll sn=sz(s);
  ll tn=sz(t);
  vvll dp(sn+1,vll(tn+1));
  for(int i=0;i<sn;i++){
    for(int j=0;j<tn;j++){
      if(s[i]==t[j]){
        dp[i+1][j+1]=dp[i][j]+1;
      }
      else{
        dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
      }
    }
  }
  ll i=sz(s);
  ll j=sz(t);
  string ans="";
  while(i>0&&j>0){
    if(dp[i][j]==dp[i-1][j]){
      i--;
    }
    else if(dp[i][j]==dp[i][j-1]){
      j--;
    }
    else{
      ans=s[i-1]+ans;
      i--;
      j--;
    }
  }
  COUT(ans);
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define MAX_SIZE 1000000

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

vector<int> primes;

void sieve() {
    bool ar[MAX_SIZE];
    memset(ar, -1, sizeof(ar));
    for (int ctr1 = 2; ctr1 < MAX_SIZE; ++ctr1)
        if (ar[ctr1]) {
            primes.push_back(ctr1);
            for (int ctr2 = 2 * ctr1; ctr2 < MAX_SIZE; ctr2 += ctr1)
                ar[ctr2] = 0;
        }
}

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    sieve();
    ll a, b;
    cin >> a >> b;
    ll cd = gcd(a, b);
    int rez = 1;
    for (int ctr1 = 0; ctr1 < primes.size() && primes[ctr1] * primes[ctr1] <= cd; ++ctr1) {
        if (cd % primes[ctr1] == 0) {
            while (cd % primes[ctr1] == 0)
                cd /= primes[ctr1];
            ++rez;
        }
    }

    cout << rez + (cd != 1) << "\n";
    return 0;
}

Measured memory_bytes: 1916
X, K, D = map(int, input().split())

now = abs(X)
move_count = K
move_size = D

moved_count, surplus = divmod(now, D)

if move_count - moved_count < 0:
    now -= move_count * move_size
    move_count = 0
else:
    move_count -= moved_count
    now = surplus

move_count %= 2
if move_count == 0:
    print(abs(now))
    exit()

if now <= 0:
    now += move_size
elif now > 0:
    now -= move_size
print(abs(now))


Measured memory_bytes: 61668
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
    ll N;
    cin >> N;
    vl H(N);

    for(ll i=0; i<N; i++){
        cin >> H.at(i);
    }
    ll ma = 0;
    ll sum = 0;
    for(ll i=N-1; i>0; i--){
        if(H.at(i) <= H.at(i-1)){
            sum++;
        }
        else{
            ma = max(sum, ma);
            sum = 0;
        }
    }
    cout << max(ma, sum) << endl;
}


Measured memory_bytes: 1024
if __name__ == '__main__':
    s = input().rstrip().split(' ')
    N,M = int(s[0]), int(s[1])
    s = input().rstrip().split(' ')
    A = [int(elem) for elem in s]
    A.sort(reverse=True)
    p = 'Yes'
    for elem in A[:M]:
        if(elem < sum(A)*(1.0/(4*M))):
            p = 'No'
            break

    print(p)


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

// macros
#define overload_rep(va_0, va_1, va_2, va_3, name, ...) name
#define rep_0_(i, n) for(int i = 0; i < (n); ++i)
#define rep_1_(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep_2_(i, x, y, z) for(int i = (x); i >= (y); --i)
#define rep(...) overload_rep(__VA_ARGS__, rep_2_, rep_1_, rep_0_)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
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; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// libraries

// declarations
int N, M;
int white, black;
int idx;
int color[700];
bool dp[2][701];
bool connected[700][700];
vector<int> graph[700];

bool bipartite(int v, int c){
    (c == 1 ? white : black)++;
    color[v] = c;
    for(int u : graph[v]){
        if(color[u] == c)return false;
        if(color[u] == 0 && !bipartite(u, -c))return false;
    }
    return true;
}

// solve
int main(){

    cin >> N >> M;
    rep(i, M){
        int a, b;
        cin >> a >> b;
        a--; b--;
        connected[a][b] = connected[b][a] = true;
    }

    rep(i, N)rep(j, N)if(i != j){
        if(!connected[i][j]){
            graph[i].push_back(j);
        }
    }

    dp[0][0] = true;
    rep(i, N)if(color[i] == 0){
        white = black = 0;
        if(!bipartite(i, 1)){
            cout << "-1\n";
            return 0;
        }
        rep(j, 0, N)if(dp[idx][j]){
            dp[1 - idx][j + white] = dp[1 - idx][j + black] = true;
            dp[idx][j] = false;
        }
        idx = 1 - idx;
    }

    int ans = 1ll << 30;
    rep(i, 0, N)if(dp[idx][i]){
        chmin(ans, i * (i - 1) / 2 + (N - i) * (N - i - 1) / 2);
    }

    cout << ans << '\n';
    return 0;

}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<tuple<string,int,int>>t;
    rep(i,n){
        string s; int p;
        cin>>s>>p;
        t.push_back(make_tuple(s,-p,i+1));
    }
    sort(t.begin(),t.end());
    rep(i,n){
        cout<<get<2>(t[i])<<endl;
    }
}


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

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    
    if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
def f_c():
    s = input()
    co, ce = 0, 0
    for i in range(len(s)):
        if i%2!=0:
            co = co+1 if s[i]!="1" else co
            ce = ce+1 if s[i]!="0" else ce
        else:
            co = co+1 if s[i]!="0" else co
            ce = ce+1 if s[i]!="1" else ce
    print(min(co, ce))

if __name__ == "__main__":
    f_c()


Measured memory_bytes: 40304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n, k;
    cin >> n >> k;
    ll a[n];
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n - k) {
        cout << (a[i] < a[i + k] ? "Yes" : "No") << endl;
    }
    return 0;
}

Measured memory_bytes: 5164
n,k=map(int,input().split())
l=[int(x) for x in input().split()]
dp=[0 for i in range(k+1)]
dp[0]=1
M=10**9+7
for i in range(len(l)):
	p=[0]*(k+1)
	for j in range(k-1,-1,-1):
		li= j+1
		ri=j+min(l[i],k-j)+1
		if li<=ri:
			p[j+1]+=dp[j]
		if ri<=k:
			p[j+min(l[i],k-j)+1]-=dp[j]
		'''for o in range(j+1,j+min(l[i],k-j)+1):
			dp[o]+=dp[j]'''
	su=0
	for i in range(k+1):
		su=(su+p[i])%M
		dp[i]=(dp[i]+su)%M
print(dp[k]%(10**9+7))
#print(dp[0][n-1])

Measured memory_bytes: 96656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a,b;
  cin >> n >> a>>b;
  if (n*a > b) {
    cout << b << endl;
  }
  else if (n*a<b) {
      cout << n*a << endl;
    }
  else {
     cout << b <<endl;
   }
}


Measured memory_bytes: 256
#include <iostream>

constexpr int MAX=302,MOD=(int)1e9+7;

int n,m;

//1-indexed
int dp[MAX][MAX][MAX];//i>j>k

void func1(int l,int r){
    for(int i=0;i<l;++i){
        for(int j=0;j<i||(i==0&&j==0);++j)
        dp[r][i][j]=-1;
    }
}

void func2(int l,int r){
    for(int i=l;i<r;++i){
        for(int j=0;j<l;++j)
            dp[r][i][j]=-1;
    }
}

void func3(int l,int r){
    for(int i=l;i<r-1;++i){
        for(int j=i+1;j<r;++j)
        dp[r][j][i]=-1;
    }
}

int main() {

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

    std::cin>>n>>m;

    int l,r,x;

    for(int i=0;i<m;++i){

        std::cin>>l>>r>>x;

        if(x==1){
            func2(l,r);
            func3(l,r);
        }
        else if(x==2){
            func1(l,r);
            func3(l,r);
        }
        else{
            func1(l,r);
            func2(l,r);
        }
    }

    if(dp[1][0][0]!=-1)
        dp[1][0][0]=3;
    else{
        std::cout<<0<<std::endl;
        return 0;
    }

    for(int i=1;i<=n;++i){
        for(int j=0;j<i||j==0;++j){
            for(int k=0;k<j||k==0;++k){
                if(dp[i][j][k]!=-1){
                    if(dp[i+1][j][k]!=-1){
                        dp[i+1][j][k]+=dp[i][j][k];
                        dp[i+1][j][k]%=MOD;
                    }
                    if(dp[i+1][i][j]!=-1){
                        dp[i+1][i][j]+=dp[i][j][k];
                        dp[i+1][i][j]%=MOD;
                    }
                    if(dp[i+1][i][k]!=-1){
                        dp[i+1][i][k]+=dp[i][j][k];
                        dp[i+1][i][k]%=MOD;
                    }
                }
            }
        }
    }

    int ans=0;

    for(int i=0;i<n;++i){
        for(int j=0;j<i||(i==0&&j==0);++j){
            if(dp[n][i][j]!=-1){
                ans+=dp[n][i][j];
                ans%=MOD;
            }
        }
    }

    std::cout<<ans<<std::endl;

    return 0;
}

Measured memory_bytes: 105856
#include <iostream>

using namespace std;

int main(){
    int n, number;
    int S[14] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
    int H[14] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
    int C[14] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
    int D[14] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
    char Pattern;

    cin >> n;

    for (int i = 0; i < n; i++){
        cin >> Pattern;
        cin >> number;

        if ( Pattern == 'S' ) {
            S[number] = 100;
        } else if ( Pattern == 'H' ) {
            H[number] = 100;
        } else if ( Pattern == 'C' ) {
            C[number] = 100;
        } else {
            D[number] = 100;
        }
    }

    for ( int i = 1; i <= 13; i++) {
        if ( S[i] < 100 ) {
            cout << "S " << i << endl;
        }
    }
    for ( int i = 1; i <= 13; i++) {
        if ( H[i] < 100 ) {
            cout << "H " << i << endl;
        }
    }
    for ( int i = 1; i <= 13; i++) {
        if ( C[i] < 100 ) {
            cout << "C " << i << endl;
        }
    }
    for ( int i = 1; i <= 13; i++) {
        if ( D[i] < 100 ) {
            cout << "D " << i << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3088
import sys
inputs = sys.stdin.readlines()

N = int(inputs[0])
A = list(map(int, inputs[1].split()))
B = list(map(int, inputs[2].split()))
C = list(map(int, inputs[3].split()))

x = 0
pre = -1
for a in A:
  x += B[a-1]
  if pre+1 == a:
  	x += C[pre-1]
  pre = a

print(x)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int ans,n;
int main()
{
  cin>>n;
  for (int i=0;i<n;i++)
  {
      int x;cin>>x;
    ans=__gcd(ans,x);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
const int M=100000+10;
int a[M],b[M];
int max(int a,int b)
{
    if(a>b) return 1;
    return 0;
}
int main()
{
    int  n,x;
    while(scanf("%d %d",&n,&x)!=EOF)
    {
        long long  sum=0;
        int mi=1000000001,y=0,i,f=0,ans=0;
        for(i=0;i<n;i++)
            scanf("%d",&a[i]),b[i]=a[i];
        if(a[0]+a[1]>x)
        {
            sum+=a[0]+a[1]-x;
            if(x>a[0])
                a[1]=x-a[0];
            else a[1]=0;
        }
        for(i=2;i<n;i++)
        {
           // printf("b[%lld]=%lld\n",i,b[i]);
            if(a[i]>(x-a[i-1])) a[i]=x-a[i-1];
            if(b[i]>a[i])     sum+=b[i]-a[i];
        }
        printf("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 1024
a,b,c,d=map(int,input().split())

def gcd(x,y): #最大公約数を求める
    if y == 0:
        return x
    else:
        return gcd(y,x%y)

def fai(n,x,y): #n以下の整数のうち、xでもyでも割り切れる整数の個数
    g=gcd(x,y) #xとyの最大公約数
    l=x//g*y #xとyの最小公倍数。切り捨てでなくても大丈夫
    return n-(n//x)-(n//y)+(n//l)
    #全体-xの倍数の個数-yの倍数の個数+xとyの倍数の個数

print(fai(b,c,d)-fai(a-1,c,d))

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
  NodePointer x;
  x = nil->next;
  while(x!=nil&&x->key != key) x = x->next;
  return x;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
 
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  /* your code */
  NodePointer t = nil->prev;
  if( t == nil)return;
  deleteNode(t);
}

void delete(int key){
  /* your code */
  NodePointer x = listSearch(key);
  if(x==nil)return;
  deleteNode(x);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
  x->prev = nil;

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key);
	nd++; 
      }
      size--;
    }

  }

  printList();
  return 0;
}



Measured memory_bytes: 33036
a,b,c,d = map(int, open(0).read().split())
if b <= 0:
    if c <= 0:
        print(a*c)
    else:
        print(b*c)
elif a > 0:
    if d > 0:
        print(b*d)
    else:
        print(a*d)
else:
    if c > 0:
        print(b*d)
    elif d <= 0:
        print(a*c)
    else:
        print(max(a*c,b*d))

Measured memory_bytes: 9180
def det(p1, p2, org=(0, 0)):
    """cross product"""
    return (p1[0]-org[0])*(p2[1]-org[1]) - (p2[0]-org[0])*(p1[1]-org[1])

def convex_hull(points):
    s = sorted(set(points), key=lambda x: (x[1], x[0]))
    hull = []
    for i in range(len(s)):
        while len(hull) > 1 and det(hull[-2], s[i], hull[-1]) > 0:
            hull.pop()
        hull.append(s[i])
    t = len(hull)
    for i in range(len(s) - 2, -1, -1):
        while len(hull) > t and det(hull[-2], s[i], hull[-1]) > 0:
            hull.pop()
        hull.append(s[i])

    return hull[:-1]


n = int(raw_input())
points = [tuple(map(int, raw_input().split())) for _ in xrange(n)]
cf = convex_hull(points)
print len(cf)
for p in cf:
  print "%d %d"%p



Measured memory_bytes: 32736
#include<iostream>
#include<string>
using namespace std;
long long a[5000];
bool check[5000];
int main(){
	int n;
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<5000;i++){
		a[i]=0;
		check[i]=true;
	}
	bool na=true;
	long long b,c,d;
	for(int i=0;i<n;i++){
		cin>>b>>c>>d;
		a[b]+=c*d;
		if(a[b]>=1000000&&check[b]==true){
			check[b]=false;
			na=false;
			cout<<b<<endl;
		}
	}
	if(na==true)
		cout<<"NA"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define ll long long int
#define REP(i,n) for(ll i=0;i<n;i++)
#define SZ(v) (ll)v.size()
#define endl "\n"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define pbds tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const ll INF=1e29;
const ll MOD=1000000007;
const ll nxm=2e7+5;
void solve()
{
ll h1,h2,m1,m2,k;
cin>>h1>>m1>>h2>>m2>>k;
ll res;
if(h1==h2)
{
    res=m2-m1;
}
else
{
res=60-m1;
res+=m2;
h1++;
if(h1<h2)
{
    res+=60*(h2-h1);
}
}

cout<<res-k;
}
int main(){
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
//	cin>>t;
	while(t--){
		solve();
	}


	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define int long long
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=1e6+5;
int cnt[MAX];
bool dobry[MAX];
int ans=0;
int32_t main()
{
  BOOST;
  int n;
  cin>>n;
	for (int i=1;i<=n;i++)
	{
		int a;
		cin>>a;
		cnt[a]++;
	}
	
	for (int i=1;i<=1e6;i++)dobry[i]=true;
	
	for (int i=1;i<=1e6;i++)
	{
		if (cnt[i]>0)
		{
			for (int j=i*2;j<=1e6;j+=i)dobry[j]=false;
		}
		if (!cnt[i])dobry[i]=false;
		if (cnt[i]>1)dobry[i]=false;
		if (dobry[i])ans++;
	}
	cout<<ans;
  return 0;
}

Measured memory_bytes: 12440
#include<cstdio>
inline long long max(long long x,long long y){return x>y?x:y;}
int n,k,a[100001],b[100001];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d%d",a+i,b+i);
	long long ans=0;
	for(int i=0;i<n;i++)
		if((a[i]&k)==a[i])ans+=b[i];
	if(!k){printf("%lld\n",ans);return 0;}
	int bit=0;
	while((1<<(bit+1))<=k)bit++;
	for(int i=bit;i>=0;i--)
		if(k&(1<<i))
		{
			long long x=0,mask=0;
			for(int j=bit;j>=i;j--)mask|=(1<<j)&k;
			mask--;
			for(int j=0;j<n;j++)
				if((a[j]&mask)==a[j])x+=b[j];
			ans=max(ans,x);
		}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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 ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N;
  cin >> N;

  int ans = 0;
  REP(i, N){
    ans += (i+1)*(N-i);
  }
  REP(i, N-1){
    int u, v;
    cin >> u >> v;
    if(u > v) swap(u, v);
    ans -= u*(N-v+1);
  }

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 3640
//#define FILE_INPUT
#define _CRT_SECURE_NO_WARNINGS
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef string str;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vbl;
 
#define majorro cout.precision(20); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define forn(i, n) for(ll (i) = 0; (i) < (n); ++(i))
#define fornm(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define rfornm(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define fin() for(ll i = 0; i < n; ++i)
#define readvec(vector, n) {ll temp_vec_val;forn(i, n){cin >> temp_vec_val;vector.push_back(temp_vec_val);}}
#define printvec(vector, delimeter) {ll length_of_vector=vector.size();\
                                    forn(elementvec, length_of_vector){cout << vector[elementvec] << delimeter;}}
#define printarr(arr, length, delimeter) {forn(elementarr, length){cout << arr[elementarr] << delimeter;}}
#define sortvec(vector) sort(vector.begin(), vector.end())
 
 
struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
 
unsigned long long bpow(unsigned long long a, ll n, ll mod)
{
    return n ? n & 1 ? (bpow(a, n - 1, mod) * a) % mod : (bpow((a * a) % mod, n >> 1ll, mod)) % mod : 1ll;
}

int get_digit(ll num, int len, int index)
{
    return num / bpow(10, len - index - 1, 1) % 10;
}
 
ll digit_sum(ll num)
{
    ll dig_sum = 0;
    while(num > 0)
    {
        dig_sum += num % 10;
        num /= 10;
    }
    return dig_sum;
}

const ldbl EPS = 0.000001;
const ll MOD = 1000000007;
// const ll MOD = 3037000499;
// const ull MOD = 1000000000000000003;
const ll INF = 1e18;
const double pi = 2 * acos(0.0);
ll n, m, k, p, q, t, sum = 0, cnt = 0;
ll mx = INT64_MIN;
ll mn = INT64_MAX;
bool flag = 0;
vll v;
str s = "", s1, s2;

void bad_solve(){}

bool possible[(ll)1e6+1] = {0};
ll costs[6] = {100, 101, 102, 103, 104, 105};

void solve() //set.merge() -> c++17
//DELET DEBUG OUTPUT!11!1
//DONT FORGET MODULO SUBSTRACTION
{
    possible[0] = 1;
    cin >> n;
    forn(i, n)
    {
        forn(j, 6)
        {
            possible[i+costs[j]] |= possible[i];
        }
    }
    cout << possible[n];
}
 
int main()
{
#ifdef FILE_INPUT
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    majorro
 
    solve();
 
    // freopen("test.txt", "w", stdout);
    // bad_solve();
 
//  memset(v, INT_MAX, 1000*2000*sizeof(int));
 
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,ans=0,x;
	cin >> n >> x;
	vector<ll> a(n);
	FOR(i,0,n)cin >> a[i];
	FOR(i,1,n){
		ll wa = a[i]+a[i-1];
		if(wa>x){
			ll k = wa-x;
			ans += k;
			a[i]-=k;
			if(a[i]<0)a[i]=0;
		}
	}
	cout << ans <<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <map>
#include <cstring>
using namespace std;
#define MAXH 101
#define MAXW 101
#define INF 1000

int H, W;
char S[MAXH][MAXW];
int dp[MAXH][MAXW];

int solve(){
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    int up, left;
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            if(i == 0 && j == 0) continue;
            
            if(j == 0){
                left = INF;
            }else{
                if(S[i][j - 1] == '.' && S[i][j] == '#'){
                    left = dp[i][j - 1] + 1;
                }else{
                    left = dp[i][j - 1];
                }
            }

            if(i == 0){
                up = INF;
            }else{
                if(S[i - 1][j] == '.' && S[i][j] == '#'){
                    up = dp[i - 1][j] + 1;
                }else{
                    up = dp[i - 1][j];
                }
            }

            dp[i][j] = min(left, up);
        }
    }

    int res;
    res = dp[H - 1][W - 1];
    if(S[0][0] == '#') res++;
    return res;
}

int main(){
    cin >> H >> W;
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            cin >> S[i][j];
        }
    }

    int res = solve();

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

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

int main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	//insert code
	int n,k;
	cin>>n>>k;
	vi arr(n);
	rep(i,0,n)cin>>arr[i];
	sort(all(arr));
	ll val = 0;
	rep(i,0,k)val+=arr[i];
	cout<<val<<endl;
	return 0;
}

Measured memory_bytes: 3624
# 159   ########## dbt

n, m = map(int, input().split())

def factorial(a):
    p = 1
    for i in range(a, 0 , -1):
        p *= i
    return p

def combo(b, num):
    ans = factorial(b) // (factorial(num) * factorial(b - num))
    return ans

print(combo(n, 2) + combo(m, 2))

Measured memory_bytes: 9164
//
//AtCoder Beginner Contest 173
//B
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<string> s(n);
    REP(i, n) cin >> s[i];

    int ac=0;
    int wa=0;
    int tle=0;
    int re=0;
    REP(i, n){
        if (s[i]=="AC") ac++;
        else if (s[i]=="WA") wa++;
        else if (s[i]=="TLE") tle++;
        else if (s[i]=="RE") re++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;


    return 0;
}


Measured memory_bytes: 6412
#include <stdio.h>
#include <inttypes.h>

#define MOD_BY UINT32_C(1000000007)

uint32_t add(uint32_t a, uint32_t b) {
	uint32_t r = a + b;
	if (r >= MOD_BY) r -= MOD_BY;
	return r;
}

uint32_t mul(uint32_t a, uint32_t b) {
	return (uint32_t)(((uint64_t)a * b) % MOD_BY);
}

int N;
char node[1000][4];
int child_num[1000];
int children[1000][10];

uint32_t keisan(int idx) {
	uint32_t ret = 0;
	int i;
	switch (node[idx][0]) {
	case 'E':
		ret = 1;
		for (i = 0; i < child_num[idx]; i++) {
			ret = mul(ret, keisan(children[idx][i]));
		}
		if (node[idx][1] == '?') ret = add(ret, 1);
		break;
	case 'A':
		for (i = 0; i < child_num[idx]; i++) {
			ret = add(ret, keisan(children[idx][i]));
		}
		if (node[idx][1] == '?') ret = add(ret, 1);
		break;
	case 'R':
		ret = 1;
		for (i = 0; i < child_num[idx]; i++) {
			ret = mul(ret, add(keisan(children[idx][i]), 1));
		}
		if (node[idx][1] != '?') ret = add(ret, MOD_BY - 1);
		break;
	}
	return ret;
}

int main(void) {
	int i;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%s", node[i]) != 1) return 1;
	}
	for (i = 1; i < N; i++) {
		int s, t;
		if (scanf("%d%d", &s, &t) != 2) return 1;
		s--;
		t--;
		children[s][child_num[s]++] = t;
	}
	printf("%"PRIu32"\n", keisan(0));
	return 0;
}

Measured memory_bytes: 704
N = int(input())

lLst = [0] * (N + 1)

if N == 0:
    print(2)
elif N == 1:
    print(1)
else:
    lLst[0] = 2
    lLst[1] = 1
    for i in range(2, N + 1):
        lLst[i] = lLst[i - 1] + lLst[i - 2]

    print(lLst[N])

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
using namespace std;

long long int a, b, k;
long long int res = 0;

int main()
{

    cin >> k >> a >> b;

    if (k < a + 1 || b <= a || a + 1 == b)
    {
        cout << k + 1;
        return 0;
    }
    else
    {
        //a-1回叩く
        k = k - (a - 1);

        //現在A枚
        res = a;

        res += (b - a) * (k / 2);

        if (k % 2 != 0)
        {
            res++;
        }

        cout << res;
    }

    return 0;
}

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

/*long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}*/

int main() {
    int H, W;
    cin >> H >> W;
    char S[H][W];

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++) {
            cin >> S[i][j];
        }
    }
    int S_count_1[H][W] = {0};
    int sum = 0;
    for(int i = 0; i < H; i++) {
        sum = 0;
        for(int j = 0; j < W; j++) {
            if(S[i][j] == '#') { S_count_1[i][j] = 0; sum = 0; }
            else if(S[i][j] == '.') { S_count_1[i][j] = sum; sum++; }
        }
    }
    sum = 0;
    int S_count_2[H][W] = {0};

    for(int i = 0; i < H; i++) {
        sum = 0;
        for(int j = W - 1; j >= 0; j--) {
            if(S[i][j] == '#') { S_count_2[i][j] = 0; sum = 0; }
            else if(S[i][j] == '.') { S_count_2[i][j] = sum; sum++; }
        }
    }

    int S_count_3[H][W] = {0};
    sum = 0;

    for(int j = 0; j < W; j++) {
        sum = 0;
        for(int i = 0; i < H; i++) {
            if(S[i][j] == '#') { S_count_3[i][j] = 0; sum = 0; }
            else if(S[i][j] == '.') { S_count_3[i][j] = sum; sum++; } 
        }
    }
    int S_count_4[H][W] = {0};
    sum = 0;
    for(int j = 0; j < W; j++) {
        sum = 0;
        for(int i = H - 1; i >= 0; i--) {
            if(S[i][j] == '#') { S_count_4[i][j] = 0; sum = 0; }
            else if(S[i][j] == '.') { S_count_4[i][j] = sum; sum++; }        
        }
    }
    int max = -100;
    for(int i = 0; i < W; i++) {
        for(int j = 0; j < H; j++) {
            if(S[j][i] == '.') {
                if(max < 1 + S_count_1[j][i] + S_count_2[j][i] + S_count_3[j][i] + S_count_4[j][i]) max = S_count_1[j][i] + S_count_2[j][i] + S_count_3[j][i] + S_count_4[j][i] + 1;
            }
        }
    }

    cout << max << endl;
    return 0;
}

Measured memory_bytes: 70008
from collections import deque
n, k = map(int, input().split())
p = list(map(int,input().split()))

kitai = [0]*1000
tmp = 0
for i in range(1000):
  tmp += i+1
  kitai[i] = tmp/(i+1)
#print(kitai)

total_kitai = [0]*(n+1)
tmp = 0
for i in range(n):
  tmp += kitai[p[i]-1]
  total_kitai[i+1] = tmp
#print(total_kitai)

ans = 0
for i in range(n-k+1):
  ans = max(total_kitai[i+k]-total_kitai[i],  ans)
print(ans)
         

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

#define ll long long;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int NMax = 1e4;
vector<int> f(NMax + 1);

int main() {
  int n;
  cin >> n;
  for (int x = 1; x * x < n; ++x) {
    for (int y = 1; y * y < n; ++y) {
      for (int z = 1; z * z < n; ++z) {
        int v = x*x + y*y + z*z + x*y + y*z + x*z;
        if (v <= n)
          f[v] += 1;
      }
    }
  }
  for (int i = 1; i <= n; ++i)
    cout << f[i] << "\n";

  return 0;
}

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


using namespace std;


const int MAXN = 500 + 23;











int h, w, a, b, z[MAXN][MAXN];


int main() {
    cin >> h >> w >> a >> b;
    if (h % a) {
        cout << "Yes\n";
        for (int i = 1; i <= h; i++)
            for (int j = 0; j < w; j++)
                z[i - 1][j] = ((i % a)? h / a + 1: -a * (h / a + 1) + h / a);
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++)
                cout << z[i][j] << ' ';
            cout << endl;
        }
        return 0;
    }
    if (w % b) {
        cout << "Yes\n";
        for (int i = 0; i < h; i++)
            for (int j = 1; j <= w; j++)
                z[i][j - 1] = ((j % b)? w / b + 1: -b * (w / b + 1) + w / b);
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++)
                cout << z[i][j] << ' ';
            cout << endl;
        }
        return 0;
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 2304