akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
 
/*------------------------------------------------------------------*/
 
int main(){
    ll n, k; cin >> n >> k;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    sort(h.begin(), h.end());
    ll ans = 0;
    ll ans_min = INFINITY;
    rep(i, n - k + 1){
        ans_min = min(h[i + k - 1] - h[i], ans_min);
    }
    cout << ans_min << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define M 1000000007
using namespace std;
int dp[3001][3001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   int n,m;
   cin>>n>>m;
   char s[n][m];
   int i,j,k,l;
   for(i=0;i<n;i++)
   {
       for(j=0;j<m;j++)
       cin>>s[i][j];
   }
   for(i=1;i<=n;i++)
   {
       for(j=1;j<=m;j++)
       {
           if(i==1)
           {
               if(s[i-1][j-1]=='.')
               dp[i][j]=1;
              else
              break;
               
           }
           
           else
           {
               
               if(s[i-1][j-1]=='#')
               dp[i][j]=0;
               else
               dp[i][j]=(dp[i-1][j]+dp[i][j-1])%M;
           }
       }
   }
   
   cout<<dp[n][m];
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
  int h,a;
  cin >> h >> a;
  int ans = 0;
  ans += h/a;
  if(h%a != 0) ans++;
  cout << ans << endl;
return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DEC(i, a, b) for (int i = (a); i > (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const ll LINF = (int)1e18;
const double EPS = 1e-9;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n,k;
  cin>>n>>k;
  cout<<  (n%k?1:0) <<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <stdio.h>
#include <time.h>
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;

const int MAX = 510000;
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 comb(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(){
    string s;
    map<string,int>mp;
    int n ; cin >> n;
    COMinit();
    ll ans=0;

    rep(i,n){
        cin >> s;
        sort(s.begin(),s.end());
        ans += mp[s];
        ++mp[s];   
    }
    cout << ans  << endl;

   }

Measured memory_bytes: 23168
def check(i,j,number_list):
    number=[]
    for k in number_list:
        number.append(k)
    k=number[i]
    number[i]=number[j]
    number[j]=k
    flag=1
    for l in range(len(number_list)):
        if (int(number[l])==(l+1)):
            continue
        else:
            flag=0
            break
    return flag
N=int(input())
in_number_list=input().split(" ")
number_list=[]

for i in in_number_list:
    number_list.append(int(i))

flag=0

for i in range(N):
    for j in range(i,N):
        a=check(i,j,number_list)
        if(a==1):
            print("YES")
            flag=1
            break
    if(flag==1):
        break
if(flag==0):
    print("NO")

Measured memory_bytes: 40048
# coding: utf-8
# Your code here!

# import math
# from decimal import Decimal
# from collections import deque, Counter
# from itertools import product


def LI():
    return list(map(int,input().split()))
    
def OPEN():
    return map(int,open(0).read().split())
    

n,*a=OPEN()

now=a[0]
ans=[]
for i in range(n):
    if a[i]<now:
        ans+=(now-a[i]),
        a[i]=now
    now=a[i]
    
print(sum(ans))
        

Measured memory_bytes: 33340
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanRunes() []rune { return []rune(scanString()) }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	m := scanInt()

	a := []int{1,m}
	for i := 2; i*i <= m; i++ {
		if m%i == 0 {
			a = append(a, i, m/i)
		}
	}

	sort.Ints(a)

	ans := sort.Search(len(a), func(idx int) bool {
		return m/a[idx] < n
	})

	fmt.Fprintln(wr, a[ans-1])
	
}


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

int main()
{
    int a, b;
    cin >> a >> b;

    int ans;
    for (ans = 0; ans * (a - 1) + 1 < b; ans++);

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, Counter


N, M = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
c = Counter(x)
a = defaultdict(int)
E = defaultdict(int)
for i,j in c.items():
    a[i%M] += j
    E[i%M] += j//2
ans = a[0]//2
for i in range(1, M):
    j = M - i
    if i < j:
        m = min(a[i], a[j])
        t = min((a[i] - m)//2, E[i]) + min((a[j] - m)//2, E[j])
        ans += m+t
    elif i == j: #i==0は最初のifにかかってしまうため注意
        ans += a[i] //2

print(ans)


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

int main()
{
    long long n, k, i;
    k = 0;
    cin >> n;
    for (i = 1; i < n + 1; i++)
    {
        if (i % 3 == 0 || i % 5 == 0)
        {
        }
        else
        {
            k = k + i;
        }
    }

    cout << k << endl;
    return 0;
}

Measured memory_bytes: 3644
n,k=map(int,input().split())
arr=list(map(int,input().split()))
ans=0
for i in range(1,n):
  if arr[i]+arr[i-1]<=k:
    continue
  elif arr[i-1]<=k<arr[i]+arr[i-1]:
    ans+=arr[i]+arr[i-1]-k
    arr[i]=k-arr[i-1]
  else:
    ans+=arr[i]
    arr[i]=0
    ans+=arr[i-1]-k
    arr[i-1]=k
print(ans)

Measured memory_bytes: 14252
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
x = sum(b)
for i in range(0,n-1):
    if a[i+1]-a[i]==1:
        x+=c[a[i]-1]
print(x)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int n; double x[100] = {}, y[100] = {};
    cin >> n;
    for (int i = 0; i < n;i++) {
        cin >> x[i];
    }
    for (int i = 0; i < n;i++) {
        cin >> y[i];
    }
    double m1 = 0, m2 = 0, m3 = 0,m4=0;
    for (int i = 0; i < n;i++) {
        m1 += fabs(x[i] - y[i]);
        m2 += pow(x[i] - y[i], 2);
        m3 += pow(fabs(x[i] - y[i]), 3);
        m4 = (m4 > fabs(x[i] - y[i])) ? m4 : fabs(x[i] - y[i]);
    }
    double d1 = m1, d2 = pow(m2, 1. / 2), d3 = pow(m3, 1. / 3),d4=m4;
    printf("%.6f\n", d1);
    printf("%.6f\n", d2);
    printf("%.6f\n", d3);
    printf("%.6f\n", d4);

}


    
     




Measured memory_bytes: 3356
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
using namespace std;
int  n,a[120];
long long sum,ans;
long long Min=1e7;

int main(){
	scanf("%d",&n);
	ans=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]==a[1]) ans++;
	}
	sort(a+1,a+n+1);
	if(ans==n) printf("0\n");
	else{
		if(n==1) printf("0\n");
		else{
			for(int i=a[1];i<=a[n];i++){
				sum=0;
				for(int j=1;j<=n;j++){
					sum=sum+(a[j]-i)*(a[j]-i);
				}
				if(sum<Min) Min=sum;
			}
			printf("%lld\n",Min);
		}
	}
}

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

int main() {
	int N;
	cin >> N;
	vector<vector<int> > V(N);
	for (int i = 0; i < N - 1; i++) {
		int A, B;
		cin >> A >> B;
		A--, B--;
		V[A].push_back(B);
		V[B].push_back(A);
	}
	vector<int> MAX(N, 0);
	vector<vector<int> > Dist(N, vector<int>(N, -1));
	for (int i = 0; i < N; i++) {
		queue<int> Q;
		Dist[i][i] = 0;
		Q.push(i);
		while (!Q.empty()) {
			int P = Q.front();
			Q.pop();
			for (int NP : V[P]) {
				if (Dist[i][NP] == -1) {
					Dist[i][NP] = Dist[i][P] + 1;
					Q.push(NP);
				}
			}
		}
		for (int j = 0; j < N; j++) {
			MAX[i] = max(MAX[i], Dist[i][j]);
		}
	}
	int MIN = 1000000000;
	for (int i = 0; i < N; i++) MIN = min(MIN, MAX[i]);
	vector<int> M;
	for (int i = 0; i < N; i++) {
		if (MIN == MAX[i]) M.push_back(i);
	}
	if (M.size() == 1) {
		int X = M[0];
		cout << MAX[X] + 1 << " ";
		long long ANS = 1000000000000000000;
		long long MUL = 1;
		vector<vector<int> > G(MAX[X] + 1);
		for (int i = 0; i < N; i++) {
			G[Dist[X][i]].push_back(i);
		}
		MUL = V[X].size();
		for (int i = 1; i < MAX[X]; i++) {
			int Z = 1;
			for (int j : G[i]) {
				Z = max(Z, (int)V[j].size() - 1);
			}
			MUL *= Z;
		}
		ANS = min(ANS, MUL);
		for (int Y : V[X]) {
			G.assign(MAX[X] + 1, {});
			for (int i = 0; i < N; i++) {
				G[min(Dist[X][i], Dist[Y][i])].push_back(i);
			}
			MUL = 2;
			for (int i = 0; i < MAX[X]; i++) {
				int Z = 1;
				for (int j : G[i]) {
					Z = max(Z, (int)V[j].size() - 1);
				}
				MUL *= Z;
			}
			ANS = min(ANS, MUL);
		}
		cout << ANS << endl;
	}
	else {
		int X = M[0], Y = M[1];
		cout << MAX[X] << " ";
		vector<vector<int> > G(MAX[X]);
		for (int i = 0; i < N; i++) {
			G[min(Dist[X][i], Dist[Y][i])].push_back(i);
		}
		long long MUL = 2;
		for (int i = 0; i < MAX[X] - 1; i++) {
			int Z = 1;
			for (int j : G[i]) {
				Z = max(Z, (int)V[j].size() - 1);
			}
			MUL *= Z;
		}
		cout << MUL << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]|| s[3]==s[4]){
      cout<<"Bad"<<endl;
    }else{
      cout<<"Good"<<endl;
    }
}

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

using namespace std;
using ll = long long;

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))


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

  vector<ll> negative, positive;
  rep(i, N) {
    int A; cin >> A;
    if (A > 0)
      positive.push_back(A);
    else if (A < 0)
      negative.push_back(A);
  }
  all(sort, positive);
  all(sort, negative);

  ll minus_size = positive.size() * negative.size();
  ll _zeros = (N - (positive.size() + negative.size()));
  ll zeros = _zeros * (N - _zeros) + _zeros * (_zeros-1) / 2;

  rep(i, negative.size()) negative[i] *= -1;
  all(reverse, negative);

  if (minus_size >= K) {
    K = minus_size - K + 1;
    ll ok = 2e18, ng = 0; // okより下はK個以上ある
    while (abs(ok - ng) > 1) {
      ll mid = (ok + ng) / 2;
      ll count = 0;
      for (const auto& e : positive)
        count += all(upper_bound, negative, mid / e) - negative.begin();

      if (count >= K)
        ok = mid;
      else
        ng = mid;
    }
    cout << -ok << endl;
  } else if (zeros + minus_size >= K) {
    cout << 0 << endl;
  } else {
    ll ok = 2e18, ng = 0; // ok以下はK個以上ある
    while (abs(ok - ng) > 1) {
      ll mid = (ok + ng) / 2;
      ll count = minus_size + zeros;
      for (auto it = positive.begin(); it != positive.end(); ++it)
        count += upper_bound(it + 1, positive.end(), mid / (*it)) - (it + 1);
      for (auto it = negative.begin(); it != negative.end(); ++it)
        count += upper_bound(it + 1, negative.end(), mid / (*it)) - (it + 1);

      if (count >= K)
        ok = mid;
      else
        ng = mid;
    }
    cout << ok << endl;
  }

  return 0;
}


Measured memory_bytes: 2420
import bisect


def read_input():
    N = int(input())
    A = [int(x) for x in input().split(" ")]
    B = [int(x) for x in input().split(" ")]
    C = [int(x) for x in input().split(" ")]
    return N, A, B, C


def main():

    N, A, B, C = read_input()
    count = 0
    A.sort()

    C.sort()
    len_c = len(C)
    for b in B:
        l = bisect.bisect_left(A, b)
        r = len_c - bisect.bisect_right(C, b)
        count += l * r

    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 22592
def main():
    N , M , A , B = list(map(int,input().split()))
    X = list(map(int,input().split()))
    Y = list(map(int,input().split()))

    flag = False
    

    for Z in range(A,B):
        if A < Z:
            if Z <= B:
                if max(X) < Z:
                    if min(Y) >= Z:
                        flag = True
                        ans = Z
    
    if flag:
        print("No War")

    else:
        print("War")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.util.Scanner;


public class Main {



	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k=sc.nextInt();
		int s=sc.nextInt();
		for (int i=0;i<n;i++) {
			System.out.print(i<k ? s : (s+1)%1_000_000_000);
			if (i<n-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	}

}

Measured memory_bytes: 42044
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

ll a,b,c,d;

void solve(){
 cin >> a >> b >> c >> d;
 
  if((c+b-1)/b<=(a+d-1)/d) cout << "Yes" << endl;
  else cout << "No" << endl;
 
}

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  

Measured memory_bytes: 3636
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<ll> v(n+1);
  v[0]=2, v[1]=1;
  if(n>=2) {
    for(int i=2; i<n+1; i++) {
      v[i]=v[i-1]+v[i-2];
    }
  }
  cout << v[n] << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <stdio.h>
#include <list>
using namespace std;

int main(){
    list<int> A;
    int q;
    scanf("%d", &q);
    int query,x,d;
    list<int>::iterator itr=A.end();
    for (int i = 0; i < q; i++)
    {
        scanf("%d",&query);
        switch (query)
        {
        case 0:
            scanf("%d",&x);
            itr=A.insert(itr,x);
            break;

        case 1:
            scanf("%d",&d);
            if(d<0){
                for (int i = 0; i < -d; i++) itr--;          
            }else
            {
                for (int i = 0; i < d; i++) itr++;              
            }
            
            
            break;
        
        case 2:
            itr=A.erase(itr);
            break;

        default:
            break;
        }
    }
    for ( itr = A.begin(); itr != A.end(); itr++)
    {
        printf("%d\n", *itr);
    }
    
    return 0;
}


Measured memory_bytes: 18760
//author:luckYrat(twitter:@luckYrat_)
//<ここに一言>

//せんげん！
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


//なまえくーかん！
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

//てーすう！
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);

//でふぁいん！
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)

//みじかく！
#define pb push_back
#define fir first
#define scn second
#define ednl endl

//いぇすのー！
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

//きんぼーnほーこー！！
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
	int k,n;cin>>k>>n;
	vector<int> A(n);
	for(int i = 0; n > i; i++){
		cin>>A[i];
	}
	int ans = A[n-1]-A[0];
	for(int i = 1; n > i; i++){
		ans = min(ans,A[i-1]-A[i]+k);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using li = int64_t;
using P = pair<int, int>;
#define F first()
#define S second()

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << "  " << y << endl;
    return 0;
}

Measured memory_bytes: 256
//author:luckYrat(twitter:@luckYrat_)
//<ここに一言>

//せんげん！
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


//なまえくーかん！
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

//てーすう！
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);

//でふぁいん！
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)

//みじかく！
#define pb push_back
#define fir first
#define scn second
#define ednl endl

//いぇすのー！
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

//きんぼーnほーこー！！
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
struct dta{
	long long k,y;
};
bool operator< (const dta &a,const dta &b){
	if(a.y==b.y){
		return a.k < b.k;
	}else{
		return a.y < b.y;
	}
}
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
	long long x,y,a,b,c;cin>>x>>y>>a>>b>>c;
	priority_queue<dta> A;
	for(int i = 0; a > i; i++){
		long long p;cin>>p;//赤色
		A.push({1,p});
	}
	for(int i = 0; b > i; i++){
		int p;cin>>p;
		A.push({2,p});
	}
	for(int i = 0; c > i; i++){
		int p;cin>>p;
		A.push({3,p});
	}
	long long ko = 0;
	long long ans = 0;
	long long nwx = 0;//赤色
	long long nwy = 0;
	while(nwx+nwy+ko != x+y){
		dta Z = A.top();A.pop();
		if(Z.k==3){
			ko++;
			ans += Z.y;
		}else if(Z.k==2 && nwy!=y){
			ans += Z.y;
			nwy++;
		}else if(Z.k==1 && nwx != x){
			ans += Z.y;
			nwx++;
		}
	}
	cout << ans << endl;
}

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

using namespace std;

int N, W, w[100], v[100];
long long dp[109][100009];

int main(){
	cin >> N >> W;
	for(int i = 0; i < N; ++i) cin >> w[i] >> v[i];
	
	for(int j = 0; j <= W; ++j) dp[0][j] = 0;
	
	for(int i = 0; i < N; ++i){
		for(int j = 0; j <= W; ++j){
			if(j + w[i] <= W){
				dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j]+v[i]);
			}
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
		}
	}
	
	cout << dp[N][W] << endl;
}

Measured memory_bytes: 80128
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();
        long[] Az = new long[N];
        long maxA = 0;
        for (int i = 0; i < N; i++){
            Az[i] = sc.nextLong();
            if (maxA < Az[i]){
                maxA = Az[i];
            }
        }
        long left = 0;
        long right = maxA;
        long mid = 0;
        int cutCnt = 0;
        long minNo = maxA+1;
        long ans = maxA;
        long nextToAns = maxA;
        int cnt = 0;
        int cannotFindFlg = 0;
        while (left < right){
            mid = (left + right)/2;
            if (mid == 0) break;
            cutCnt = 0;
//            System.out.println(left +" "+right+" mid "+mid+" "+cnt+" ans "+ans+" "+(cutCnt > K)+" "+cutCnt);
            for (int i = 0; i < N; i++){
//                System.out.println(mid +" Az[i] "+Az[i]+" "+(Math.ceil((double) Az[i] / mid)));
                cutCnt += Math.ceil((double) Az[i] / mid) - 1;
            }
//            System.out.println("cutCnt "+cutCnt);
            if (cutCnt > K){
                minNo = mid;
//                right = mid;
                left = mid + 1;
            } else {
                ans = mid;
                if (minNo == ans + 1){
                    System.out.println("aa");
                    cannotFindFlg = 1;
                    nextToAns = mid;
                    break;
                }
//                left = mid + 1;
                right = mid;
            }
//            System.out.println(left +" "+right+" mid "+mid+" "+cnt+" ans "+ans+" "+(cutCnt > K)+" "+cutCnt);
            cnt++;
//            if (cnt == 10) break;
        }
        if (cannotFindFlg == 0){
            System.out.println(ans);
        } else {
            System.out.println(nextToAns);
        }

    }
}


Measured memory_bytes: 61252
import java.util.Scanner;

public class Main{
    public static void main(String[] args){

        try(Scanner scanner = new Scanner(System.in);){
            String line = scanner.nextLine();
            String answer = "";
            int length =line.length();

            for(int i=0; i<length; i++){
                char ch = line.charAt(i);
                if(Character.isLowerCase(ch)){
                    ch = Character.toUpperCase(ch);
                }else{
                    ch = Character.toLowerCase(ch);
                }
                answer = String.valueOf(ch);
                System.out.print(answer);
                
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 26860
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        int K = ni();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = ni();
        }

        for (int i = K; i <N; i++) {
            if(A[i-K] < A[i]) out.println("Yes");
            else out.println("No");
        }
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);
    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

int main() {
    double N,T,A;
    cin >> N >> T >> A;
    vector<double>H(N);
    for(int i = 0; i < N; i++) {
        cin >> H[i];
        H[i] = T-H[i]*0.006;
    }
    double cnt = 1000000;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        if(abs(A-H[i]) < cnt) {
            ans = i+1;
            cnt = abs(A-H[i]);
        }
    }
    cout << ans << endl;
}

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

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}


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

    vector<int>x(n);
    rep(i,n)cin>>x[i];
    x.push_back(X);

    sort(x.begin(),x.end());

    vector<int>sub(n);
    rep(i,n)sub[i]=x[i+1]-x[i];

    int ans=sub[0];

    rep2(i,1,n-1)ans=__gcd(ans,sub[i]);

    cout<<ans<<endl;
}






Measured memory_bytes: 1024
n= int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
for i in range(n):
  ans += B[i]
  if i != n-1 and A[i] + 1 == A[i+1]:
    ans += C[A[i]-1]
print(ans)
  

Measured memory_bytes: 3060
#include <cstdio>
const int Maxn=1000000;
char s[Maxn+5];
int n;
int f[Maxn+5][2];
int mn(int a,int b){
	return a<b?a:b;
}
int main(){
	scanf("%s",s+1);
	while(s[++n]!='\0');
	n--;
	f[0][1]=1;
	for(int i=1;i<=n;i++){
		f[i][0]=mn(f[i-1][0]+(s[i]-'0'),f[i-1][1]+(10-(s[i]-'0')));
		f[i][1]=mn(f[i-1][0]+(s[i]-'0')+1,f[i-1][1]+(10-(s[i]-'0')-1));
	}
	printf("%d\n",f[n][0]);
	return 0;
}


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

using namespace std;

using ll = long long;

int main(){
    ll N;
    ll a[5];
    cin >> N >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    sort(a, a + 5);
    ll k = (N+a[0]-1)/a[0];

    cout << k + 4LL << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 0, 1 },{ -1 ,1 },{ -1, 0 },
	{ -1 ,-1 },{ 0,-1 },{ 1 ,-1 },
	{ 1,0 },{ 1 ,1 }
};
double getRadian(double x, double y, double x2, double y2) {
	double radian = atan2(y2 - y, x2 - x);
	return radian;
}
#define INF 10000000
signed main() {
	int E, V;

	scanf("%d %d", &V, &E);
	vector<pair<int,pii>> edge(E);
	vector<vector<int>> nd(V, vector<int>(V, INF));
	REP(i, V) {
		nd[i][i] = 0;
	}
	REP(i, E) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		a--; b--;
		edge[i] = { c,{a,b} };
		nd[a][b] = c;
		nd[b][a] = c;
	}
	REP(k, V) {
		REP(i, V) {
			REP(j, V) {
				nd[i][j] = min(nd[i][j], nd[i][k] + nd[k][j]);
			}
		}
	}
	int ans = 0;
	REP(i, E) {
		if (nd[edge[i].second.first][edge[i].second.second] < edge[i].first) {
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#define MN 100000
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int x[MN+5],T,n,q[MN+5],top,tail;
long long f[MN+5];
int main()
{
	n=read();x[n+1]=read();T=read();
	for(int i=1;i<=n;++i) x[i]=read();
	f[0]=x[1];q[top=tail=1]=0;long long mn=1e18;
	for(int i=1,j=0;i<=n;++i)
	{
		while(j<i&&(x[i]-x[j+1])*2>=T) mn=min(mn,f[j]-3LL*x[j+1]),++j; 
		while(top>=tail&&(x[i]-x[q[tail]+1])*2>=T) ++tail;
		f[i]=min(mn+3LL*x[i],top>=tail?f[q[tail]]-x[q[tail]+1]+x[i]+T:(long long)1e18);
		f[i]=min(f[i],f[i-1]+T);f[i]+=x[i+1]-x[i];
	//	cout<<i<<" "<<mn<<" "<<(top>=tail?q[tail]:-1)<<" "<<f[i]<<endl;
		while(top>=tail&&f[i]-x[i+1]<=f[q[top]]-x[q[top]+1]) --top;q[++top]=i;
	}
	printf("%lld\n",f[n]);
	return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7,inv2=(mod+1)/2;
int n,q,a[4001],dp[4001][4001];
int main()
{
	cin>>n>>q;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)dp[i][j]=(a[i]>a[j]);
	for(int k=1,x,y;k<=q;k++)
	{
		cin>>x>>y;
		dp[x][y]=dp[y][x]=1ll*inv2*(dp[x][y]+dp[y][x])%mod;
		for(int i=1;i<=n;i++)
			if(i!=x&&i!=y)dp[i][x]=dp[i][y]=1ll*inv2*(dp[i][x]+dp[i][y])%mod,dp[x][i]=dp[y][i]=1ll*inv2*(dp[x][i]+dp[y][i])%mod;
	}
	long long ans=0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)ans+=dp[i][j];
	while(q--)ans=ans*2%mod;
	cout<<ans<<'\n';
}


Measured memory_bytes: 47360
#include<iostream>
#include<cmath>
using namespace std;
#define N 500000

int sosu[N];

void ans(){
	fill(sosu,sosu+N,1);
	sosu[1]=0;
	sosu[2]=1;
	for(int i=2 ; i<sqrt(N) ; i++){
		if(sosu[i]==1){
			for(int j=2*i ; j<N ; j+=i){
				sosu[j] = 0;
			}
		}
	}
}

int main(){
	ans();
	int x;
	int count;
	while(1){
		cin >> x;
		if(x==0)break;
		count =0;
		for(int j=x+1 ; j<=2*x ; j++){
			count+=sosu[j];
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 3112
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;                                      
	

int main(){       
	int n;
	scanf("%d",&n);
	cout << "ABC"<< n << endl;
	
	return 0;
}







Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int BUF = 200005;
const int MOD = 1000000007;


int pow(int p, int n) {
    if (n == 0) return 1;
    int t = pow(p, n / 2);
    return n & 1 ? 1LL * t * t % MOD * p % MOD: 1LL * t * t % MOD;
}


int inv(int v) {
    return pow(v, MOD - 2);
}


int nVal, nPick;
int val[BUF];

void read() {
    cin >> nVal >> nPick;
    for (int i = 0; i < nVal; ++i) {
        cin >> val[i];
    }
}


bool cmp(int a, int b) {
    return abs(a) < abs(b);
}


void work() {
    sort(val, val + nVal, cmp);
    reverse(val, val + nVal);

    if (nPick == nVal) {
        int ans = 1;
        for (int i = 0; i < nVal; ++i) {
            ans = 1LL * ans * (MOD + val[i]) % MOD;
        }
        cout << ans << endl;
        return;
    }

    if (nPick % 2 == 1 && *max_element(val, val + nVal) <= 0) {
        int ans = 1;
        for (int i = nVal - 1; i >= nVal - nPick; --i) {
            ans = 1LL * ans * (MOD + val[i]) % MOD;
        }
        cout << ans << endl;
        return;
    }

    bool isNeg = false;
    int ans = 1;
    for (int i = 0; i < nPick; ++i) {
        ans = 1LL * ans * (MOD + val[i]) % MOD;
        if (val[i] < 0) isNeg = !isNeg;
    }

    if (!isNeg) {
        cout << ans << endl;
        return;
    }

    int posMinIdx = -1;
    int negMinIdx = -1;
    for (int i = nPick - 1; i >= 0; --i) {
        if (val[i] > 0 && posMinIdx == -1) {
            posMinIdx = i;
        }
        if (val[i] < 0 && negMinIdx == -1) {
            negMinIdx = i;
        }
    }

    int posMaxIdx = -1;
    int negMaxIdx = -1;
    for (int i = nPick; i < nVal; ++i) {
        if (val[i] > 0 && posMaxIdx == -1) {
            posMaxIdx = i;
        }
        if (val[i] < 0 && negMaxIdx == -1) {
            negMaxIdx = i;
        }
    }
    
    if (negMinIdx == -1 || posMaxIdx == -1 ||
        (posMinIdx != -1 && negMaxIdx != -1 && 1LL * abs(val[negMaxIdx]) * abs(val[negMinIdx]) > 1LL * val[posMinIdx] * val[posMaxIdx])) {
        // ans / posMin * negMax > ans / negMin * posMax
        ans = 1LL * ans * inv(val[posMinIdx]) % MOD;
        ans = 1LL * ans * (MOD + val[negMaxIdx]) % MOD;
    } else {
        ans = 1LL * ans * inv(MOD + val[negMinIdx]) % MOD;
        ans = 1LL * ans * val[posMaxIdx] % MOD;
    }

    cout << ans << endl;
}


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


Measured memory_bytes: 4256
N = int(input())
G = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
    u,k,*varray = map(int,input().split())
    for v in varray:
        G[u-1][v-1] = 1
    # for j in range(N):
    #     print(G[i][j])
for row in G:
    print(*row)


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

int main(void)
{
    int a;
    cin >> a;

    string s="hon";
    if(a%10==3){
        s="bon";
    }
    else if (a % 10 == 0 || a % 10 == 1 || a % 10 == 6 || a % 10 ==8)
    {
        s="pon";
    }

    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;



int main(){FIN

    ll d,n;
    cin>>d>>n;
    cout<<(int)pow(100,d) * ((n==100)? n+1:n)<<endl;
    return 0;
}

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

int main() {

    string str;
    int k;
    cin>>k;
    cin>>str;
    if(k>=str.length()) 
        cout<<str;
    else {
        for(int i=0;i<k;i++)
            cout<<str[i];
        cout<<"...";
    }
        return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define hashset unordered_set
#define hashmap unordered_map
#define getbit(x, i) (((x) >> (i)) & 1)
using namespace std;
typedef pair<int, int> pii;
template <typename T>
inline vector<T> readvector(size_t size) {
    vector<T> res(size);
    for (size_t i = 0; i < size; ++i) {
        cin >> res[i];
    }
    return res;
}
template <typename T>
inline void printvector(vector<T> &arr, string sep = " ", string ends = "\n") {
    for (size_t i = 0; i < arr.size(); ++i) {
    }
}
inline int binPow(int x, int deg, int mod) {
    int ans = 1;
    for (int i = sizeof(x) * CHAR_BIT - 1; i >= 0; i--) {
        ans *= ans;
        ans %= mod;
        if (getbit(deg, i)) ans *= x;
        ans %= mod;
    }
    return ans;
}
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, k;
    cin >> n >> k;
    auto arr = readvector<int>(n);
    sort(arr.begin(), arr.end());
    n = accumulate(arr.begin(), arr.begin() + max(0ll, n - k), 0ll);
    cout << n << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
ll N, M;
vector<int> G[100005];
// 二部グラフ判定
int wh[100005];
bool check(int v, int gr) {
  bool ret = true;
  if(wh[v]==0) {
    wh[v] = gr;
    for(int to : G[v]) {
      ret &= check(to, gr%2+1);
    }
  } else {
    ret = wh[v] == gr;
  }
  return ret;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  FOR(i,0,M) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  if(check(1, 1)) {
    int white = 0;
    FOR(i,1,N+1) {
      white += wh[i] == 1;
    }
    cout << white * (N - white) - M << endl;
  } else {
    cout << N * (N - 1) / 2 - M << endl;
  }
  return 0;
}

Measured memory_bytes: 6912
import heapq

n=int(input())
a=[-int(x) for x in input().split()]

heapq.heapify(a)
ans=heapq.heappop(a)
n-=1

while True:
    n-=1
    if n==0:
        break
    temp=heapq.heappop(a)
    ans+=temp
    n-=1
    if n==0:
        break
    ans+=temp



print(-ans)

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll A, B, M;
  cin >> A >> B >> M;

  vector<ll> a(A);
  for (ll i = 0; i < A; ++i) {
    cin >> a[i];
  }
  vector<ll> b(B);
  for (ll i = 0; i < B; ++i) {
    cin >> b[i];
  }

  vector<ll> x(M);
  vector<ll> y(M);
  vector<ll> c(M);
  for (ll i = 0; i < M; ++i) {
    cin >> x[i];
    cin >> y[i];
    cin >> c[i];
    x[i]--;
    y[i]--;
  }

  ll ans = 1e18;
  for (ll i = 0; i < M; ++i) {
    ans = min(ans, (a[x[i]] + b[y[i]]) - c[i]);
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  ans = min(ans, a[0]+b[0]);

  cout << ans << endl;
  
  return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    string s;
    cin >> s;
    cout << s.substr(0, 3) << endl;
    return 0;
}


Measured memory_bytes: 3628
// Let's bring the sky down :)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 5;
const int K = 1e2 + 5;
int n;
ll we[K], v[K];
ll dp[K][N];
ll solve(int idx, int left){
    if(idx == n)
        return 0;
    if(dp[idx][left] != -1) return dp[idx][left];
    ll ans = max((we[idx] > left ? 0 : v[idx] + solve(idx + 1, left - we[idx])), solve(idx + 1, left));
    return dp[idx][left] = ans;
}
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int w;
    cin >> n >> w;
    for(int i = 0; i < n; i++){
        cin >> we[i] >> v[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << solve(0, w);
return 0;
}


Measured memory_bytes: 82304
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;
int main(void){
    int j=0;
    char out[13];
    string str;

    cin >> str;

    for(int i=0;i<str.size();i++){
        out[j]=str[i];
        if(i==3){
            j++;
            out[j]=' ';
        }
        j++;
    }
    cout << out << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        if(n%2 == 0) {
            System.out.println(n/2);
        } else {
            System.out.println((n+1)/2);
        }
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
    #define FOR(i, a, b) for(int i = a; i < b; i++)
    #define REP(i, n) FOR(i, 0, n)
    using namespace std;
    int main(){
        int N;
        cin >> N;
        int s[N];
        int sum = 0;
        REP(i, N) {
            cin >> s[i];
            sum += s[i];
        }
        if(sum % 10) {
                cout << sum << "\n";
                return 0;
        }
        sort(s, s+N);
        REP(i, N) {
            if(s[i] % 10) {
                cout << sum-s[i] << "\n";
                return 0;
            }
        }
        cout << 0 << "\n";
    }

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

int main() {
  int n, a, b, sum = 0;
  cin >> n >> a >> b;
  vector<int> k(5, 0);
  for(int i = 1; i < n+1; i++) {
    k[0]++;
    for(int j = 0; j < 5; j++) {
      if(k[j] > 9) {
        k[j] = 0;
        k[j+1]++;
      } else {
        break;
      }
    }
    int ks = k[0]+k[1]+k[2]+k[3]+k[4];
    if(ks >= a && b >= ks) {
      sum += i;
    }
  }
  cout << sum << "\n";
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#define _CRT_SECURE_NO_WARNINGS
#endif
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x) {x = 0;register bool _=0;register T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void print(T n) {register bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);pc(10);}
template<typename First, typename ... Ints>
void scan(First &arg, Ints&... rest) { scan(arg);scan(rest...); }

using namespace std;
const int MM = 302;

int n;
double dp[MM][MM][MM];

double go(int i, int j, int k){
    if(dp[i][j][k] != -1)
        return dp[i][j][k];
    
    double ret = 1;
    int sum = i+j+k;
    
    if(i)
        ret += (1.0*i/n)*go(i-1, j, k);
    if(j)
        ret += (1.0*j/n)*go(i+1, j-1, k);
    if(k)
        ret += (1.0*k/n)*go(i, j+1, k-1);
    
    return dp[i][j][k] = ret/(1-(1.0*n-sum)/n);
}

int main(){
    for(int i = 0; i < MM; i++)
        for(int j = 0; j < MM; j++)
            for(int k = 0; k < MM; k++)
                dp[i][j][k] = -1;
    
    dp[0][0][0] = 0;
    scan(n);
    int a[4] = {0,0,0,0};
    for(int i = 0,s; i < n; i++){
        scan(s);
        a[s]++;
    }
    printf("%.10lf\n", go(a[1], a[2], a[3]));
    return 0;
}


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

#define ll long long 
#define int ll
#define endl "\n"

const int mx = 9;
vector <vector <char> >grid(mx, vector <char> (mx));
vector <vector <char> >temp(mx, vector <char> (mx));
set <int> rows;
set <int> cols;
int h, w, k;

int result(){
	temp.clear();
	temp = grid;
	for (int i=0; i<h; i++){
		for (int j=0; j<w; j++){
			if (rows.count(i) or cols.count(j)){
				temp[i][j] = '.';
			}
		}
	}
	
	int cont = 0;
	for (int i=0; i<h; i++){
		for (int j=0; j<w; j++){
			if (temp[i][j] == '#') cont++;
		}
	}
	
	return cont;
}

signed main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	//freopen("input.txt", "r", stdin); 
	//freopen("output.txt", "w", stdout);
		
	
	cin >> h >> w >> k;
	for (int i=0; i<h; i++){
		for (int j=0; j<w; j++){
			cin >> grid[i][j];
		}
	}	
	
	int ans = 0;
	
	for (int row_mask = 0; row_mask < (1<<h); row_mask++){
		rows.clear();
		for (int row_bit = 0; row_bit < h; row_bit++){
			if (row_mask&(1<<row_bit)){
				rows.insert(row_bit);
			}
		}
		
		for (int col_mask = 0; col_mask < (1<<w); col_mask++){
			cols.clear();
			for (int col_bit = 0; col_bit < w; col_bit++){
				if (col_mask&(1<<col_bit)){
					cols.insert(col_bit);
				}
			}
//				cerr << "Rows ";
//				for (int i:rows) cerr << i << " ";
//				cerr << endl << "Columns ";
//				for (int i:cols) cerr << i << " ";
//				cerr << endl;
				int this_ = result();
//				cerr << "Number of black cells: " << this_ << endl;
				if (this_ == k) ans++;
		}
	}
	
	cout << ans << endl;
	
}

Measured memory_bytes: 3660