akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
vector<ll> A, B;
ll n;

ll cnt(vector<ll> P, ll x) {
    vector<pair<ll, ll>> odd, even, U(n);
    ll ret = 0;
    for(ll i = 0; i < n; i++) {
        // iが偶数番目でそのカードが表で終わると決めた or
        // iが奇数番目でそのカードが裏で終わると決めた
        // => ソートされると偶数番目で終わる
        // (奇数回動くと裏で終わるため)
        // 奇数番目で終わるときはその逆
        if(i % 2 == (x >> i) % 2)
            even.emplace_back(P[i], i);
        else
            odd.emplace_back(P[i], i);
    }
    // 偶数番目で終わるカードと奇数番目で終わるカードの枚数差が2枚以上はありえない．
    if((int)even.size() - (int)odd.size() > 1 || (int)even.size() - (int)odd.size() < 0) return INF;
    // それぞれカードの値でソート
    sort(odd.begin(), odd.end(), [](const pair<ll, ll> &a, const pair<ll, ll> &b) {
        if(a.first == b.first) return a.second < b.second;
        return a.first < b.first;
    });
    sort(even.begin(), even.end(), [](const pair<ll, ll> &a, const pair<ll, ll> &b) {
        if(a.first == b.first) return a.second < b.second;
        return a.first < b.first;
    });
    // ソート後の数列を復元
    for(ll i = 0; i < n; i++) {
        if(i % 2 == 0)
            U[i] = even[i / 2];
        else
            U[i] = odd[i / 2];
    }
    // ここで昇順になっていない場合はアウト
    for(ll i = 0; i < n - 1; i++) {
        if(U[i].first > U[i + 1].first) return INF;
    }
    // もとの数列PからUになるためにどのくらい移動したか(転倒数)
    for(ll i = 0; i < n - 1; i++) {
        for(ll j = n - 1; j >= i + 1; j--) {
            if(U[j].second < U[j - 1].second) {
                swap(U[j], U[j - 1]);
                ret++;
            }
        }
    }
    return ret;
}

ll solve(ll x) {
    vector<ll> P(n);
    for(ll i = 0; i < n; i++) {
        if((x >> i) % 2 == 0)
            P[i] = A[i];
        else
            P[i] = B[i];
    }
    return cnt(P, x);
}

int main() {
    ll m, i, j, k;
    cin >> n;
    A = vector<ll>(n);
    B = vector<ll>(n);
    for(i = 0; i < n; i++)
        cin >> A[i];
    for(i = 0; i < n; i++)
        cin >> B[i];
    ll ret = INF;
    for(i = 0; i < (1ll << n); i++) {
        ret = min(ret, solve(i));
    }
    if(ret == INF) ret = -1;
    cout << ret << endl;
    return 0;
}

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

int main() {
	long int l,r; cin >> l >> r;

	long int ans=2019;

	for(long int i=l;i<r && i<l+2019;i++){
		for(long int j=i+1; j<=r && j<l+2019; j++){
			if(ans > (i*j)%2019){
				ans = (i*j)%2019;
			}
		}
	}
cout << ans << endl;
}

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

int main(){
    int N;
    cin>>N;
    vector<int> A(N+1);
    for(int i=1;i<=N;i++) cin>>A[i];
    vector<vector<int>> D(N+1);
    for(int i=1;i<N;i++){
        for(int k=2;i*k<=N;k++){
            D[i*k].push_back(i);
        }
    }
    vector<int> M;
    for(int i=N;i>=1;i--){
        if(A[i]) M.push_back(i);
        for(auto d:D[i])A[d]^=A[i];
    }
    cout<<M.size()<<endl;
    for(auto m:M)cout<<m<<' ';
    cout<<endl;
    return 0;
}

Measured memory_bytes: 23548
class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n

    def root(self, a):
        if self.parent[a] < 0:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]

    def size(self, a):
        return -self.parent[self.root(a)]

    def connect(self, a, b) -> bool:
        a = self.root(a)
        b = self.root(b)

        if a == b:
            return False

        if self.size(a) < self.size(b):
            a, b = b, a

        self.parent[a] += self.parent[b]

        self.parent[b] = a

        return True


N, M, K = map(int, input().split())
fri_g = dict([str(i), []] for i in range(N))
blk_g = dict([str(i), []] for i in range(N))
unif = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    unif.connect(a-1, b-1)
    fri_g[str(a-1)].append(b-1)
    fri_g[str(b-1)].append(a-1)

for _ in range(K):
    c, d = map(int, input().split())
    blk_g[str(c-1)].append(d-1)
    blk_g[str(d-1)].append(c-1)

for i in range(N):
    i_str = str(i)
    n_link = unif.size(i) - 1  # remove theirselves
    n_friends = len(fri_g[i_str])
    n_blk_and_link = sum([unif.root(d) == unif.root(i) for d in blk_g[i_str]])
    # n_blk_and_link = 0
    # for d in blk_g[i_str]:
    #     n_blk_and_link += unif.root(d) == unif.root(i)

    print(n_link - n_friends - n_blk_and_link)


Measured memory_bytes: 66260
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,X;
    cin>>N>>X;
    vector<int>m(N+1);
    for(int i=0;i<N;++i){
        cin>>m[i];
    }
    sort(m.begin(),m.end());
    reverse(m.begin(),m.end());
    m.pop_back();
    sort(m.begin(),m.end());
    int sum=N;
    for(int i=0;i<N;++i){
       X-=m[i];
    }

        while (X-m[0]>=0)
        {
            X-=m[0];
            sum++;
        }
        
        cout<<sum<<endl;
    }
    



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

using namespace std;

void showIntArray(int a[], int n) {
  for (int i=0; i<n; i++) {
    cout << a[i] << ' ';
  } cout << endl;
}

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B && B == C) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];

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

    int p = n;
    p-=2;
    long long ans = v[n-1];
    int idx = n-2;
    while(p>0){
        ans += v[idx];
        p--;
        if(p==0)
            break;
        ans += v[idx];
        p--;
        idx--;
    }
    cout <<ans;
}


Measured memory_bytes: 4068
// 解き直し.
// https://img.atcoder.jp/nikkei2019-qual/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    priority_queue<LL> pq;
    LL ans = 0, a, b;
    rep(i, N){
        scanf("%lld %lld", &a, &b);
        pq.push(a + b);
        ans -= b;
    }
    
    // 2. 幸福度の差は？
    bool f = (1 & N);
    while(!pq.empty() && N > 0){
        // 要素を一つ取り出す.
        LL p = pq.top();
        pq.pop();
        
        // 加算.
        if(f){
            if(N & 1)    ans += p;
        }else{
            if(!(N & 1)) ans += p;
        }
        
        // デクリメント.
        N--;
    }
    
    // 3. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 4332
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip> 

using namespace std;

#define mp make_pair
#define pb push_back
#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 nfor(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define correct(x, y, n, m) (0 <= x && x < n && 0 <= y && y < m)
#define all(x) (x).begin(), (x).end()
#define fst first
#define snd second
#define endl "\n"

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int,int,int> iii;

template<typename T> inline T abs(T a){ return ((a < 0) ? -a : a); }
template<typename T> inline T sqr(T a){ return a * a; }
template<class T> T gcd(T a, T b) { return a ? gcd (b % a, a) : b; }
template<class T> T lcm(T a, T b) { return a / gcd (a, b) * b; }
template<class T> T sign(T a) { return a > 0 ? 1 : (a < 0 ? -1 : 0); }

string to_string(string s) {
    return '"' + s + '"';
}
    
string to_string(const char* s) {
    return to_string((string) s);
}
    
string to_string(bool b) {
    return (b ? "true" : "false");
}
    
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
    
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void fastIO() {
    cin.sync_with_stdio(false);
    cin.tie(0);
}

template<typename T>
vector<T> make_unique(vector<T> v) {
    sort(all(v));
    return v.resize(unique(all(v)) - v.begin());
}

int nxt() {
    int x;
    cin >> x;
    return x;
}

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int dxKn[8] = {-2, -1, 1, 2,  2,  1, -1, -2};
const int dyKn[8] = { 1,  2, 2, 1, -1, -2, -2, -1};
const int dxK[8] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dyK[8] = {1, -1, 0, 0, 1, -1, 1, -1};

const int MOD = int(1e9) + 7;
const int INF = int(1e9) + 100;
const ll INF64 = 2e18;
const ld PI = ld(3.1415926535897932384626433832795);
const ld e = ld(2.7182818284590452353602874713527);
const ld EPS = 1e-9;

//#############################
const int MAXN = 1000005;

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

    cout << a * b << endl;
    return 0;
}

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

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
ll dx[4] = {1,0,-1,0};
ll dy[4] = {0,1,0,-1};

int main(){
    int n,diff=0;cin>>n;
    vll a(n);
    rep(i,n) cin >> a[i];
    vll ans(n, 0);
    rep(i,n-1) ans[i+1] += a[i] - ans[i];
    diff = (a[n-1] - ans[0] - ans[n-1])/2;
    rep(i,n) {
        if(i%2) ans[i] -= diff;
        else ans[i] += diff;
    }
    for(auto p:ans) cout<<p*2<<" ";
    cout<<endl;
    return 0;
}  


Measured memory_bytes: 2944
S=input()
count = 0
for i in reversed(range(len(S))):
    for j in range(0, len(S)-i):
        S_part = S[j:i+j+1]
        l = list(set(S_part))
        l.sort()
        if set(l)&set(['A','C','G','T'])==set(l):
            count = max(count, len(S_part))
print(count)

Measured memory_bytes: 3060
n,m,k = map(int, input().split())

# 行と列の組み合わせを全探索で試し、1回でも成立する場合は終了する
for i in range(n+1):
  for j in range(m+1):
    if i*(m-j) + j*(n-i) == k:
      print("Yes")
      exit()
print("No")

Measured memory_bytes: 9180
<?php
$array = explode(' ', trim(fgets(STDIN)));

$five_count = 0;
$seven_count = 0;
for ($i = 0; $i < count($array); $i++) {
    if ((int)$array[$i] === 5) {
        $five_count++ ;
    } elseif ((int)$array[$i] === 7) {
        $seven_count++;
    }
}

if ($five_count === 2 && $seven_count === 1) {
    echo 'YES';
} else {
    echo 'NO';
}

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  ll n;cin>>n;
  ll a[n];
  ll b[n];
  ll yama[n];
  REP(i,n){
    cin>>a[i];
    b[i] = a[i];
  }

  //まずは0で
  yama[0] = 0;
  for(int i=1;i<n;i++){
    yama[i] = a[i-1]*2;
    a[i] -= yama[i]/2;
  }

  yama[0] = a[n-1];
  b[0] -= yama[0]/2;


  for(int i=1;i<n;i++){
    yama[i] = b[i-1]*2;
    b[i] -= yama[i]/2;
  }

  REP(i,n){
    cout<<yama[i]<<" ";
  }

 

  return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;
int main()
{
	SPEED
	ll n;
	cin >> n;

	vector<ll> arr(n);
	ll sum = 0;
	map<ll, ll> mp;

	for (ll i = 0; i < n; ++i)
	{
		cin >> arr[i];
		sum += arr[i];

		if (mp.count(arr[i]))
		{
			mp[arr[i]]++;
		}
		else
		{
			mp[arr[i]] = 1;
		}
	}

	ll q, b, c;
	cin >> q;

	while(q--)
	{
		cin >> b >> c;
		if (mp.count(b))
		{
			if (mp[b]>0)
			{
				ll cnt = mp[b];
				mp[b] = 0;

				if (mp.count(c))
				{
					mp[c] += cnt;
				}
				else
				{
					mp[c] = cnt;
				}
				

				//update sum
				ll sub = cnt*b;
				ll add = cnt*c;

				sum -= sub;
				sum += add;

				//prll it out
				cout << sum << '\n';
			}
			else
			{
				cout << sum << '\n';
			}
		}
		else
		{
			cout << sum << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 8672
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}


int main(){
  ll i,j,N,M,K,cnt=0,ans=0;
  cin>>N;
  string ss;
  vec a(10);
  mat v;
  set<vec> se;
  map<vec,ll> mapp;
  rep(i,N){
    cin>>ss;
    rep(j,10){
      a[j]=ss[j];
    }
    vsort(a);
    auto p=se.insert(a);
    if(p.second){
      v.push_back(a);
      mapp[a]=1;
    }else{
      mapp[a]++;
    }
  }
  rep(i,v.size()){
    cnt=mapp[v[i]];
    ans+=cnt*(cnt-1)/2;
  }
  cout<<ans<<endl;
  return 0;
}

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

    
int main(){
    
    int a,b,t;
    cin >> a >> b ;
    if(a==b){cout << 2*a << endl;}
    if(a>b){cout << a+(a-1) << endl;}
    if(a<b){cout << b+(b-1) << endl;}
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
int a,b;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol c=1,d=1,e=0,f=0,g=0,h=0;
  cin >>a>>b;
  cout <<max(0,a-(b*2))<<'\n';
  return (0);
}


Measured memory_bytes: 256
h1, m1, h2,m2,k = map(int, input().split())
if h1 > h2:
    h2 +=24
h = h2 - h1
m = m2 - m1
if m < 0:
    m = m + 60
    h = h - 1
time = h*60 + m 
print(time - k)


Measured memory_bytes: 9172
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=200010;

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

    string s;
    cin>>s;
    ll ans=0;
    for(ll i=0;i<s.size();++i){
        ans+=(s[i]-'0');
        ans%=9;
    }
    if(ans==0){cout<<"Yes";}
    else{cout<<"No";}

    return (0);
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  if (A - 2 * B < 0) {
    cout << 0 << endl;
  } else {
    cout << A - 2 * B << endl;
  }
  return 0;
}


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

class Main {
    static Scanner scanner = new Scanner();
    static long mod = 1000000007;

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[] a = new int[n];
        Integer[] b = new Integer[n];
        boolean posi = false, nega = false, zero = false;
        long sum = 0;
        for (int i = 0; i < n; i++) {
            sum += a[i] = Math.abs(b[i] = scanner.nextInt());
            posi |= b[i] > 0;
            nega |= b[i] < 0;
            zero |= b[i] == 0;
        }
        Arrays.sort(a);
        if (posi && nega) {
            System.out.println(sum);
            Deque<Integer> posiDeque = new ArrayDeque<>();
            Deque<Integer> negaDeque = new ArrayDeque<>();
            Arrays.sort(b, Comparator.comparingInt(Math::abs));
            for (int i = 0; i < n; i++) {
                if (b[i] > 0) {
                    posiDeque.add(b[i]);
                } else {
                    negaDeque.add(b[i]);
                }
            }
            while (posiDeque.size() >= 2) {
                int i = posiDeque.poll();
                int j = negaDeque.poll();
                System.out.println(j + " " + i);
                negaDeque.add(j - i);
            }
            while (!negaDeque.isEmpty()) {
                int i = posiDeque.poll();
                int j = negaDeque.poll();
                System.out.println(i + " " + j);
                posiDeque.add(i - j);
            }
        } else {
            Arrays.sort(b, Comparator.comparingInt(Math::abs));
            System.out.println(zero ? sum : sum - a[0] * 2);
            for (int i = 1; i < n - 1; i++) {
                System.out.println(b[i - 1] + " " + b[i]);
                b[i] = b[i - 1] - b[i];
            }
            if (posi) {
                System.out.println(b[n - 1] + " " + b[n - 2]);
            } else {
                System.out.println(b[n - 2] + " " + b[n - 1]);
            }
        }
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

Measured memory_bytes: 58384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N;
  cin >> N;
  int a = 0;
  int b = 0;
  int c = 0;
  for(int i=1; i<=3500; i++){
    for(int j=1; j<=3500; j++){
      if((4*i*j - N*i - N*j) > 0){
       if((N*i*j) % (4*i*j - N*i - N*j) == 0 &&  (N*i*j) / (4*i*j - N*i - N*j) > 0){
        a = i;
        b = j;
        c = (N*i*j) / (4*i*j - N*i - N*j);
        break;
       }
      }
    }
  }
  cout << a << " " << b << " " << c << endl;
}

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

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<vector<int>> cnt(k, vector<int>(k));
  for (int i = 0; i < n; ++i) {
    int x, y;
    char c;
    scanf("%d %d %c", &x, &y, &c);
    x %= k << 1, y %= k << 1;
    if (x / k + y / k == 1) {
      if (c == 'W')
        cnt[x % k][y % k] += 1;
      else
        cnt[x % k][y % k] -= 1;
    } else {
      if (c == 'B')
        cnt[x % k][y % k] += 1;
      else
        cnt[x % k][y % k] -= 1;
    }
  }

  vector<vector<int>> s1(k, vector<int>(k)), s2(k, vector<int>(k));
  for (int i = 0; i < k; ++i)
    for (int j = 0; j < k; ++j) {
      s1[i][j] = cnt[i][j];
      if (i)
        s1[i][j] += s1[i - 1][j];
      if (j)
        s1[i][j] += s1[i][j - 1];
      if (i && j)
        s1[i][j] -= s1[i - 1][j - 1];

      s2[k - i - 1][k - j - 1] = cnt[k - i - 1][k - j - 1];
      if (k - i - 1 < k - 1)
        s2[k - i - 1][k - j - 1] += s2[k - i][k - j - 1];
      if (k - j - 1 < k - 1)
        s2[k - i - 1][k - j - 1] += s2[k - i - 1][k - j];
      if (k - i - 1 < k - 1 && k - j - 1 < k - 1)
        s2[k - i - 1][k - j - 1] -= s2[k - i][k - j];
    }

  int d = 0;
  for (int i = 0; i < k; ++i)
    for (int j = 0; j < k; ++j) {
      int u;
      if (i && j)
        u = s1[i - 1][j - 1] + s2[i][j];
      else
        u = s2[i][j];
      d = max(d, abs(u * 2 - s2[0][0]));
    }
  printf("%d\n", (n + d) >> 1);

  return 0;
}

Measured memory_bytes: 12032
local w, h = io.read("*n", "*n")
local lim = (w + 1) * (h + 1) - 1
local cost = {}
local idxs = {}
for i = 1, w + h do
  cost[i] = io.read("*n")
  idxs[i] = i
end
table.sort(idxs, function(a, b) return cost[a] > cost[b] end)

local wuse, huse = 0, 0
local cnt = 0
local ret = 0LL
while cnt < lim do
  local idx = idxs[#idxs]
  table.remove(idxs)
  local u = 0
  if idx <= w then
    wuse = wuse + 1
    u = h + 1 - huse
  else
    huse = huse + 1
    u = w + 1 - wuse
  end
  cnt = cnt + u
  ret = ret + cost[idx] * u
end
local str = tostring(ret):gsub("LL", "")
print(str)


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<long double>v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    vector<vector<long double> >dp(n+1,vector<long double>(n+1));
    dp[1][1]=v[0];
    dp[1][0]=(long double)1-v[0];
    for(int i=2;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(j==0)
            dp[i][j]=dp[i-1][j]*((long double)1-v[i-1]);
            else
            dp[i][j]=dp[i-1][j]*((long double)1-v[i-1])+dp[i-1][j-1]*(v[i-1]);
        }
    }

    long double ans=0.00;
    for(int i=n;i>=n/2+1;i--)
        ans+=dp[n][i];
    cout <<setprecision(10)<<fixed<< ans << endl;
/**
5
0.42 0.01 0.42 0.99 0.42
*/
    return 0;
}


Measured memory_bytes: 144288
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll r() {
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	if(c=='-')f=-1,c=getchar();
	while(isdigit(c))x=x*10+c-'0',c=getchar();
	return x*f;
}
#define d r()
char a,b,c;
int main(){
	cin>>a>>b>>c;
	cout<<a<<b<<c;
	return 0;
}


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

int main() {
    long long n;
    cin >> n;
    vector<long long> a(n,0);
    for (long long i = 0; i < (n); ++i) {
        cin >> a.at(i);
    }
    long long min = *min_element(a.begin(), a.end());
    long long max = *max_element(a.begin(), a.end());
    long long sum = accumulate(a.begin(), a.end(), 0LL);
    cout  << min << " " << max << " " << sum << endl;

    return 0;
}


Measured memory_bytes: 3136
#include <stdio.h>

int main(){
    int x,y;
    for(int i = 1;;i++){
        scanf("%d %d",&x,&y);
        if(x == 0 && y == 0) break;
        if (x < y){
            printf("%d %d\n",x,y);
        }
        else printf("%d %d\n",y,x);
    }
    return 0;
}


Measured memory_bytes: 2708
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

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

    int n,k; cin >> n >> k;
    vector<int> a(n);
    for(int i = 0;i < n;i ++) cin >> a.at(i);

    vector<int> cnta(n),cntb(2001),cntc(n);

    for(int i = 0;i < n;i ++){
        for(int j = i;j < n;j ++){
            if(a.at(i) > a.at(j)) cnta.at(i) ++;
        }
    }

    for(int i = 0;i < n;i ++){
        cntb.at(a.at(i)) ++;
    }

    for(int i = 0;i < n;i ++){
        for(int j = 0;j < a.at(i);j ++){
            cntc.at(i) += cntb.at(j);
        }
    }

    int ans = 0;

    for(int i = 0;i < n;i ++){
        ans += cnta.at(i) * k;
        ans %= 1000000007;
        int x = k * (k-1) / 2;
        x %= 1000000007;
        ans += cntc.at(i) * x;
        ans %= 1000000007; 
    }

    cout << ans << endl;

}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
	int n, d;
	cin >> n >> d;
	int ans = 0;
	int tmp = d+1;
	while(tmp+d <= n){
		ans++;
		tmp += 2*d+1; 
	}
	if(n % (2*d+1) != 0){
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
using ll = long long;
 
const ll INF = 1LL << 60;
ll dist[205][205];
 
int main(){
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> vr;
    rep(i,R){
        int r;
        cin >> r;
        r--;
        vr.push_back(r);
    }
    rep(i,205)rep(j,205){
        dist[i][j] = INF;
        dist[i][i] = 0;
    }
    rep(i,M){
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    rep(k, N) rep(i, N) rep(j, N) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
 
    sort(vr.begin(), vr.end());
    ll ans = INF;
    do{
        ll tmp = 0;
        for (int i = 1; i < vr.size(); i++){
            tmp += dist[vr[i]][vr[i - 1]];
        }
        ans = min(ans, tmp);
    } while (next_permutation(vr.begin(), vr.end()));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include <functional>
#include <queue>
#include <regex>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;


/*vectorの要素を全部確認するやつだよ。


for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}


*/


/*for文でx,yを上下左右確認するやつだよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}
*/

/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}


*/

/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; i++) {
	for (int j = 0; j < w; j++) {

	}
}

*/

class UnionFind {
private:
	std::vector<int> parent;
	std::vector<int> height;
	std::vector<int> m_size;

public:
	UnionFind(int size_) : parent(size_), height(size_, 0), m_size(size_, 1) {
		for (int i = 0; i < size_; ++i) parent[i] = i;
	}
	void init(int size_) {
		parent.resize(size_);
		height.resize(size_, 0);
		m_size.resize(size_, 1);
		for (int i = 0; i < size_; ++i) parent[i] = i;
	}
	int find(int x) {
		if (parent[x] == x) return x;
		return parent[x] = find(parent[x]);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		int t = size(x) + size(y);
		m_size[x] = m_size[y] = t;
		if (height[x] < height[y]) parent[x] = y;
		else parent[y] = x;
		if (height[x] == height[y]) ++height[x];
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		if (parent[x] == x) return m_size[x];
		return size(parent[x] = find(parent[x]));
	}
};


int main(void) {
	int n, m; cin >> n >> m;
	int x, y, z;

	UnionFind uf(n+1);
	uf.init(n+1);
	int ans = n;

	for (int i = 0; i < m; i++) {
		cin >> x >> y >> z;

		if (uf.same(x, y)) { }
		else {
			uf.unite(x, y);
			ans--;
		}
	}

	cout << ans << endl;



}


Measured memory_bytes: 1408
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 3e18+7
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<pair<int,ll>,ll> p;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};

int C[10],need[10]={0,2,5,5,4,5,6,3,7,6};
int dp[11000];

int main(){
  int N,M;
  cin>>N>>M;
  for(int i=0;i<M;i++){
    int a;
    cin>>a;
    C[a]++;
  }
  for(int i=1;i<=9;i++){
    if(C[i]==0){
      C[i]=-1;
    }else{
      C[i]=need[i];
    }
  }
  for(int i=0;i<11000;i++){
    dp[i]=-10000;
  }
  dp[0]=0;
  for(int i=1;i<=N;i++){
    for(int j=1;j<=9;j++){
      if(C[j]==-1) continue;
      if(i-C[j]<0) continue;
      dp[i]=max(dp[i],dp[i-C[j]]+1);
    }
  }
  //cout<<dp[N]<<endl;
  int num=dp[N];
  while(num!=0){
    //cout<<N<<endl;
    for(int i=9;i>=0;i--){
      if(C[i]>=0 && N-C[i]>=0 && dp[N]==dp[N-C[i]]+1){
        cout<<i;
        N-=C[i];
        num--;
        break;
      }
    }
  }
  cout<<endl;

}


Measured memory_bytes: 256
open Scanf
open Printf

let () = scanf "%d %d" (fun a b ->
  if a = 1 && b = 1 then "Draw"
  else if a = 1 && b <> 1 then "Alice"
  else if a = b && b <> 1 then "Draw"
  else if a > b && b <> 1 then "Alice"
  else "Bob"
  ) |> printf "%s\n"

Measured memory_bytes: 3732
n,m = map(int,input().split())

ab = [0]*m

for i in range(0,m):
  ab[i] = input().split()

to = [0]*n
d = [0]*2
for i in range(0,m):
  d[0] = int(ab[i][0])
  d[1] = int(ab[i][1])
  to[d[0]-1] += 1
  to[d[1]-1] += 1

for i in range(len(to)):
  print(to[i])

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
// #define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define repr(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define reprs(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;

ll N,K;

int main(){
	FAST;
	cin >> N >> K;
	double ans=0;
	reps(i,N){
		double r=1.0/N;
		int now=i;
		while(now<K) {
			now*=2;
			r/=2;
		}
		ans+=r;
	}

	cout << std::setprecision(10) << ans << LF;

	return 0;
}

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

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"
#define all(x) x.begin(),x.end()
#define sz(x) x.size()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

void solve()
{
	int n;
	cin>>n;
	vector<int> v(n);
    vector<bool> vis(n);
	for(auto &x:v)cin>>x;
    for(int i=1;i<n;i++){
        if((i==n-1 && v[i]>v[i-1]) || (v[i]>=v[i-1] && v[i]>v[i+1]) || (v[i]>v[i-1] && v[i]>=v[i+1]))vis[i]=1;
    }
	vector<int> d;
	int mn=500;
    for(int i=0;i<n;i++){
        if(vis[i]){
            d.emplace_back(mn);
            d.emplace_back(v[i]);
            mn=v[i];
        }else{
            mn=min(mn,v[i]);
        }
    }
	ll yen=1000,cur=0;
	ll ans=1000;
	// for(auto x:d)cerr<<x<<" ";
	for(int i=0;i<sz(d);i++){
		if(i%2==0){
			cur=yen/d[i];
			yen-=cur*d[i];
		}else{
			yen+=d[i]*cur;
			ans=max(ans,yen);
			cur=0;
		}
	}
	cout<<ans<<"\n";
}

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


Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define MAX_SIZE 1010
int n, m;
LL r, a;
LL x[MAX_SIZE], y[MAX_SIZE], z[MAX_SIZE], t[MAX_SIZE];

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
		cin >> x[i] >> y[i] >> z[i];

	int P[8][3] = { { 1,1,1 },{ 1,1,-1 },{ 1,-1,1 },{ 1,-1,-1 },{ -1,1,1 },{ -1,1,-1 },{ -1,-1,1 },{ -1,-1,-1 } };
	for (int i = 0; i < 8; ++i) {
		for (int j = 0; j < n; ++j)
			t[j] = x[j] * P[i][0] + y[j] * P[i][1] + z[j] * P[i][2];
		sort(t, t + n);
		a = 0;
		for (int k = n - m; k < n; ++k)
			a += t[k];
		if (r < a)
			r = a;
	}
	cout << r << endl;
	return 0;
}

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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    double n, k;
    cin>>n>>k;

    double ans = 0;
    for (int i=1;i<=(int)n;i++){
        if (i<=k-1){

            double nn = log2(k/i);
            double nfloor = floor(nn);

            if (nn-nfloor > 0) nfloor++;

            double res = pow(0.5, nfloor);
            res *= (1/n);

            ans += res;
        }
        else ans += (1/n);
    }
    printf ("%.12lf\n", ans);

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {
  int n, h;
  cin >> n >> h;
  vector< pair<int, int> > p;
  for(int i=0; i<n; i++){
    int a, b;
    cin >> a >> b;
    p.push_back({-a, 0});
    p.push_back({-b, 1});
  }
  sort(p.begin(), p.end());
  int cnt = 0;
  for(int i=0; i<p.size(); i++){
    if( h <= 0 ) break;
    if( p[i].second == 1 ){
      h += p[i].first;
      cnt++;
    }else if( p[i].second == 0 ){
      cnt += (h + (-p[i].first) - 1) / (-p[i].first);
      break;
    }
  }
  cout << cnt << endl;

  return 0;
}




//


Measured memory_bytes: 2420
#include <iostream>
#include <set>
#include <string>

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

    int ret = 0;
    int t = 0;

    for (int i = 0; i < s.length(); ++i)
    {
        std::string ss = s.substr(i, 1);
        if (ss == "A" || ss == "T" || ss == "G" || ss == "C")
        {
            t++;
            if (ret < t)
            {
                ret = t;
            }
        }
        else
        {
            t = 0;
        }
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
list=[]

for i in range(n):
  s, p = input().split()
  list.append((s,int(p),i+1))

list.sort(key=lambda x:x[1],reverse=True)
list.sort(key=lambda x:x[0])

for i in range(n):
  print(list[i][2])

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )



int N, C;
int D[30][30];
int G[3][250000];
int counter[3];
int minv[3][30];
int minc[3][30];


int main() {
    cin >> N >> C;
    rep(i, 0, 3) {
        counter[i] = 0;
    }
    rep(i, 0, 3) {
        rep(j, 0, C) {
            minv[i][j] = numeric_limits<int>::max();
        }
    }
    rep(i, 0, C) {
        rep(j, 0, C) {
            cin >> D[i][j];
        }
    }

    rep(i, 0, N) {
        rep(j, 0, N) {
            int tmp;
            cin >> tmp;
            tmp--;
            G[(i + j+2) % 3][counter[(i + j+2) % 3]++] = tmp;
        }
    }

    rep(i, 0, 3) {
        rep(c, 0, C) {
            int tmp = 0;
            rep(j, 0, counter[i]) {
                tmp += D[G[i][j]][c];
            }
            minv[i][c] = tmp;
            minc[i][c] = c;
        }
    }

    int res = numeric_limits<int>::max();
    rep(i, 0, C) {
        rep(j, 0, C) {
            rep(k, 0, C) {
                if ((minc[0][i] != minc[1][j]) && (minc[0][i] != minc[2][k]) && (minc[1][j] != minc[2][k])) {
                    int tmp = minv[0][i] + minv[1][j] + minv[2][k];
                    if (tmp < 0) continue;
                    res = min(res, tmp);
                }
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 1280
#include<stdio.h>
#include<stdlib.h>

int cmp(int*,int*);

int main(){
  long long n,k; scanf("%lld%lld",&n,&k);
  long long arr[n],sum=0;
  for(long long i=0; i<n; i++){
    scanf("%lld",&arr[i]);
  }
  qsort(arr,n,sizeof(long long),cmp);
  for(long long i=0; i<n; i++){
    if(i<k) continue;
    else sum+=arr[i];
  }
  printf("%lld\n",sum);
  return 0;
}

int cmp(int* a,int* b){
  if(*a>*b) return -1;
  else if(*a<*b) return 1;
  else return 0;
}

Measured memory_bytes: 3324
let n = stdin.ReadLine() |> int
let rsint () = stdin.ReadLine().Split() |> Array.map int
let a = rsint()
let b = rsint()
let c = rsint()
(a |> Array.sumBy (fun x -> b.[x - 1])) + 
(a |> Array.take (n - 1) |> Array.zip (a |> Array.skip 1)
    |> Array.sumBy (fun (x, y) -> if (x - 1) = y then c.[y - 1] else 0))
|> stdout.WriteLine

Measured memory_bytes: 13268
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    int house[4][3][10]={{}};
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                house[i][j][k]=0;
            }
        }
    }
    //printf("%d",house[0][1][2]);
    int n,a,b,c,d;
    scanf("%d",&n);
    //printf("%d",n);
    for(int l=1;l<=n;l++){
        scanf("%d %d %d %d",&a,&b,&c,&d);
        house[a-1][b-1][c-1]+=d;
    }
    //printf("%d",house[0][0][2]);
    for (int e=0;e<4;e++){
        for(int f=0;f<3;f++){
            for(int g=0;g<10;g++){
                printf(" %d",house[e][f][g]);
            }
            printf("\n");
        }
        if(e<3){
        printf("####################\n");
        }
    }
    return 0;
}



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

int main() {
    int n; cin >> n;
    bool isY = false;
    for(int i = 0; i < n; i++) {
        char s; cin >> s;
        if(s == 'Y') isY = true;
    }
    if(isY) cout << "Four" << endl;
    else cout << "Three" << endl;
    return 0;
}


Measured memory_bytes: 256
n, m = map(int,input().split())
li = [[] for i in range(n)]
for i in range(m):
    a, b = map(int,input().split())
    li[a-1].append(b-1)
    li[b-1].append(a-1)
sign = {0: 0}
step = {0: 1}
now = {0}
flg = False
while len(now) > 0:
    if flg:
        print('No')
        exit()
    flg = True
    next = set()
    for i in now:
        for j in li[i]:
            if not j in sign:
                sign[j] = i
                step[j] = step[i] + 1
                next.add(j)
                flg = False
    now.clear()
    now = next

print('Yes')
for i in range(n - 1):
    print(sign[i + 1] + 1)

Measured memory_bytes: 48928
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Solve();
            WriteLine(Result);
        }

        public static string Result { get; set; }

        private static void Solve()
        {
            var hw = Utils.ReadInts().ToArray();
            var a = new string[hw[0]];
            for (var i = 0; i < hw[0]; ++i)
            {
                a[i] = ReadLine();
            }
            Result = a.Select(s => s.Count(c => c == '#')).Sum() == hw.Sum() - 1 ? "Possible" : "Impossible";
        }
    }

    public static class Utils
    {
        #region Extensions for IO

        public static int ReadInt()
            => ReadInts().First();

        public static IEnumerable<int> ReadInts()
            => ReadStrings().Select(int.Parse);

        public static IEnumerable<String> ReadStrings()
            => ReadLine().Split(' ');

        #endregion

        #region Extensions of int

        public static bool IsOdd(this int n)
            => !n.IsEven();

        public static bool IsEven(this int n)
            => n % 2 == 0;
        
        public static bool CanDivideWith(this int n, int divisor)
            => n % divisor == 0;

        #endregion

        #region Extensions of string

        public static int ToInt(this string str)
            => int.Parse(str);

        public static long ToLong(this string str)
            => long.Parse(str);

        public static bool IsNullOrEmpty(this string str)
            => string.IsNullOrEmpty(str);

        #endregion

        public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (var item in source)
            {
                action(item);
            }
        }
    }
}


Measured memory_bytes: 2904
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<numeric>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

using P = pair<ll, ll>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    sort(all(A));
    vector<P> CB;
    ll b, c;
    rep(_, 0, M) {
        cin >> b >> c;
        CB.emplace_back(c, b);
    }
    sort(all(CB));
    reverse(all(CB));
    int idx = 0;
    for (auto& cb : CB) {
        for (int cnt = 0; idx < N && cnt < cb.second && A[idx] <= cb.first; ++cnt) {
            A[idx++] = cb.first;
        }
    }
    cout << accumulate(all(A), 0LL) << endl;
    return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <list>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 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() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll a, b, q;
	cin >> a >> b >> q;
	vector<ll> s(a);
	rep(i, a) cin >> s[i];
	vector<ll> t(b);
	rep(i, b) cin >> t[i];
	vector<ll> x(q);
	rep(i, q) cin >> x[i];

	// 2分探索？

	// ありえるパターン
	// →→、←←、→←、←→
	// 神社と寺の順番は任意

	// 二分探索でxの前後の点を神社と寺で探す
	// 距離を上の4パターン調べて最小値を出力

	rep(i, q) {
		ll ans = infll;

		int sback, sfront;
		int tback, tfront;

		sfront = lower_bound(allof(s), x[i]) - s.begin();
		sback = sfront - 1;
		tfront = lower_bound(allof(t), x[i]) - t.begin();
		tback = tfront - 1;

		//cout << i << "番目" <<  endl;
		// →→
		if (sfront < a && tfront < b){
			//cout << "→→" << max(s[sfront], t[tfront]) - x[i] << endl;
			ans = min(ans, max(s[sfront], t[tfront]) - x[i]);
		}
		// ←←
		if (sback >= 0 && tback >= 0) {
			//cout << "←←" << x[i] - min(s[sback], t[tback]) << endl;
			ans = min(ans, x[i] - min(s[sback], t[tback]));
		}
		// →←
		if (sfront < a && tback >= 0) {
			//cout << "→←" << s[sfront] - t[tback] << endl;
			ans = min(ans, s[sfront] - t[tback] + min(s[sfront] -x[i], x[i] - t[tback]));
		}
		// ←→
		if (sback >= 0 && tfront < b) {
			//cout << "←→" <<  t[tfront] - s[sback] << endl;
			ans = min(ans, t[tfront] - s[sback] + min(x[i] - s[sback], t[tfront] - x[i]));
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3712