akhauriyash/Code-Regression huggingface dataset:
from random import choice
from random import random
from time import time


class Optimizer:
    def __init__(self, C, S):
        self.C = C
        self.S = S
        X = []
        L = [-1] * 26
        for i in range(365):
            max_diff = -10**10
            best_j = 0
            for j in range(26):
                memo = L[j]
                L[j] = i
                diff = self.S[i][j] - \
                    sum([self.C[jj] * (i - L[jj]) for jj in range(26)])
                if diff > max_diff:
                    max_diff = diff
                    best_j = j
                L[j] = memo
            L[best_j] = i
            X.append(best_j)
        self.X = X

    def calc_score(self):
        score = 0
        L = [-1 for j in range(26)]
        A = [0 for j in range(26)]
        for i in range(365):
            score += self.S[i][self.X[i]]
            A[self.X[i]] += (i - L[self.X[i]]) * \
                (i - L[self.X[i]] - 1) // 2
            L[self.X[i]] = i
        for j in range(26):
            A[j] += (365 - L[j]) * (365 - L[j] - 1) // 2
            score -= self.C[j] * A[j]
        return score

    def optimize(self, temp, threp, interval, start_time=time(), lim=1.8):
        max_score = self.calc_score()
        while True:
            t = (time() - start_time) / 2
            if random() < threp:
                i = choice(range(365))
                j = choice(range(26))
                memo = self.X[i]
                self.X[i] = j
                new_score = self.calc_score()
                if new_score > max_score:
                    max_score = new_score
                elif random() < pow(2.7, (new_score - max_score) / pow(2000, 1 - t)):
                    max_score = new_score
                else:
                    self.X[i] = memo
            else:
                a = choice(range(interval))
                i0 = choice(range(365 - a))
                i1 = i0 + a
                self.X[i0], self.X[i1] = self.X[i1], self.X[i0]
                new_score = self.calc_score()
                if new_score > max_score:
                    max_score = new_score
                elif random() < pow(2.7, (new_score - max_score) / pow(2000, 1 - t)):
                    max_score = new_score
                else:
                    self.X[i0], self.X[i1] = self.X[i1], self.X[i0]
            if time() - start_time > lim:
                break
        return max(max_score + 10**6, 0)


if __name__ == "__main__":
    d = int(input())
    *C, = map(int, input().split())
    S = [list(map(int, input().split())) for i in range(d)]
    opt = Optimizer(C, S)
    opt.optimize(500, 0.7, 8)
    for x in opt.X:
        print(x + 1)
    # print(opt.calc_score())


Measured memory_bytes: 91176
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx") 
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i<(b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define dF2(i,a,b) for(int i=(a);i>(b);--i)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define INF 0x3f3f3f3f
#define INFll 0x3f3f3f3f3f3f3f3f
#define y0 _lxybz_
#define y1 _ljmnzyzhhhoscartxdy_
typedef long double ld;
typedef long long ll;
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize
#define lo(x) ((x)&(-(x)))
#define trav(a, x) for (auto &a : x)
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
const ld Pi = 4*atan((ld)1);
template<class T> void chmin(T &a,const T&b) { a = min(a, b); }
template<class T> void chmax(T &a,const T&b) { a = max(a, b); }
namespace IO{
template<class T> inline void read(T&ret)
{
	ret=0; int f=1; char c=getchar();
	while(c<48||c>57){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	ret*=f;
}
template<class T> inline void prin(const T&ret)
{
	if(!ret){putchar(48);return;} static T o; o=ret;
	if(o<0){putchar('-');o=-o;}
	static int op[25],tt; tt=0;
	while(o){
		op[++tt]=o%10;
		o/=10;
	}
	for(int i=tt;i;--i)putchar(op[i]+48);
}
template<class T> inline void pri_(const T&ret)
{
	prin(ret);putchar(' ');
}
template<class T> inline void priE(const T&ret)
{
	prin(ret);putchar('\n');
}
}
using namespace IO;

#define N 
#define MO 
int n,k,s;
inline void _Sol_()
{
	read(n);read(k);read(s);
	if(s!=1000000000){
		F(i,1,k)pri_(s);
		F(i,k+1,n)pri_(s+1);
		return;
	}
	F(i,1,k)pri_(s);
	F(i,k+1,n)pri_(1);
}

int main()
{
	int T=1; //read(T);
	while(T--)_Sol_();
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
    long long  n,sum=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        if((i+1)%3!=0&&(i+1)%5!=0)
            sum+=i+1;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

class Main {
    static final Scanner IN = new Scanner(System.in);
    static final int N = Integer.parseInt(IN.next());
    public static void main(String... args) {
        System.out.println(calc(N));
    }
    static String calc(int x) {
        int d = x / (-2);
        int m = x % (-2);
        if (m == -1) {
            m = 1;
            d++;
        } 
        if (d == 0) {
            return Integer.toString(m);
        } else if (d == 1) {
            return "1" + Integer.toString(m);
        } else {
            return calc(d) + Integer.toString(m);
        }
    }
}

Measured memory_bytes: 23252
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	var n int
	var k int
	n, k = nextInt(), nextInt()

	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	// 2分探索
	var l float64 = 0
	r := math.Pow(10, 9) // 十分に大きい数字
	for r-l > 1 {
		x := int(int(l+r) / 2)

		f := func(x int) bool {
			now := 0
			for i := 0; i < len(a); i++ {
				now = now + (a[i]-1)/x // xの倍数+1の時から切る回数ができる
			}
			return now <= k
		}
		if f(x) {
			r = float64(x)
		} else {
			l = float64(x)
		}
	}
	fmt.Println(int(r))
}


Measured memory_bytes: 5856
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
typedef struct tagListNode {
  int H;     /* 高さ */
  int flag;	//goodなら1、badなら0
} SKY;

int main(void){
	SKY *S;
	int N,M,A,B;
	int i,ans;
	char str[10000000];
 
	fgets(str, sizeof(str), stdin);
	N=atoi(strtok(str," "));
	M=atoi(strtok(NULL," "));

	S=(SKY*)calloc(N,sizeof(SKY));

	fgets(str, sizeof(str), stdin);
	S[0].H=atoi(strtok(str," "));
	S[0].flag=1;
	for(i=1;i<N;i++){
		S[i].H=atoi(strtok(NULL," "));
		S[i].flag=1;
	}

	for(i=0;i<M;i++){
		fgets(str, sizeof(str), stdin);
		A=atoi(strtok(str," "))-1;
		B=atoi(strtok(NULL," "))-1;
		if(S[A].H < S[B].H ){
			S[A].flag=0;
		}else if(S[A].H == S[B].H ){
			S[A].flag=0;
			S[B].flag=0;
		}else{
			S[B].flag=0;
		}
	}

	ans=0;
	for(i=0;i<N;i++){
		if(S[i].flag == 1)ans++;
	}

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

	free(S);

	return 0;
}


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

typedef long long LL;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;

const int INF = 1000000007;
const LL INFLL = 1000000000000000007;

#define st first
#define nd second
#define pb push_back
#define _boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

// ***************************** CODE ***************************** //

const int MAX = 3e3 + 7;
int dp[MAX][MAX];
vector <char> v;

int main() {
    _boost;

    string a, b;
    cin >> a >> b;

    for(int i = 1; i <= a.size(); i++)
    {
        for(int j = 1; j <= b.size(); j++)
        {
            if(a[i-1] == b[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }

    int i = a.size(), j = b.size();
    while(i > 0 && j > 0)
    {
        if(dp[i][j] == dp[i-1][j])
            i--;
        else if(dp[i][j] == dp[i][j-1])
            j--;
        else if(dp[i][j] > dp[i-1][j-1])
        {
            v.pb(a[i-1]);
            i--;
            j--;
        }
    }

    reverse(v.begin(), v.end());
    for(auto i : v) cout << i;

    return 0;
}


Measured memory_bytes: 35584
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main(int argc, char** argv) {
	int a;
	cin>>a;
	if(a%2==1){
		cout<<a*2;
	}
	else
	cout<<a;
	return 0;
}

Measured memory_bytes: 256
/*input
1
*/ 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ll,ll>;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
const ll maxn=1e5+5;
const ll maxlg=__lg(maxn)+5;
int main(){
    ll n;
    cin>>n;
    vector<ll> v;
    REP1(i,100){
        v.pb(i*(i+1)/2);
    }
    ll z=sqrt(n);
    ll ans=0;
    for(int i=2;i<=z;i++){
        int cnt=0;
        while(n%i==0){
            ++cnt;
            n/=i;
        }
        if(cnt){
            ans+=(prev(upper_bound(ALL(v),cnt))-v.begin()+1);
        }
    }
    if(n>1){
        ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 3728
let words str =
  let len = String.length str in
  let rec aux start stop =
    if stop >= len || str.[stop] = ' '
    then String.sub str start (stop-start), stop+1
    else aux start (stop+1)
  in
  let rec iter i l =
    if len-i <= 0 then l
    else
      match str.[i] with
        ' ' -> iter (i+1) l
      | _ ->
        let s,j = aux i (i+1) in
        iter j (s::l)
  in iter 0 []

let () =
  let w = read_line () in
  let rec loop count =
    match read_line () with
      "END_OF_TEXT" -> Printf.printf "%d\n" count
    | s -> loop (words s
                 |> List.fold_left
                   (fun acc x ->
                      acc +
                      (if String.lowercase x = String.lowercase w then 1 else 0))
                   0
                 |> (+) count)
  in loop 0

Measured memory_bytes: 2244
import sys
INF = sys.maxsize
N,M = map(int,input().split(" "))
tmp = []
for _ in range(M):
    a,b = map(int,input().split(" "))
    bit = 0
    nums = map(int,input().split(" "))
    for n in nums:
        bit += 2**(n-1)
    tmp.append((a,bit))

dp = [INF for _ in range(2**N)]
dp[0] = 0

for i in range(M):
    a,bit = tmp[i]
    for j in range(2**N):
        cover = bit | j
        dp[cover] = min(dp[cover], dp[j] + a)

print(dp[-1] if dp[-1] != INF else -1) 

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

const int mn=100;
int n;
long long a[mn],ans=1000;

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i) scanf("%lld",a+i);
    for(int i=1;i<n;++i) {
        if(a[i]<a[i+1]) {
            ans+=(a[i+1]-a[i])*(ans/a[i]);
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)
typedef long long int lli;
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define vc vector<char>
#define vs vector<string>
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define fastio	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
/*-------CONSTANTS------- */
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);
const int INF = 1000000000;
const int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
/*-----------------------------MATH STUFF----------------------------- */
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
int mulmod(int a, int b, int c){lli res=(lli)a*b;return(res>=c?res%c:res);}
template<typename T>T power_mod(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
//Factorials upto 1e5%MOD,nCr%MOD,nPr%MOD
lli fact[100000+5],fact_modinv[100000+5];
void fact_init(){
    fact[0] = 1ll;
    fact_modinv[0] = mod_inverse(fact[0],1ll*MOD);
    for(int i = 1;i<=100000;i++){
        fact[i] = mulmod(fact[i-1],i,1ll*MOD);
        fact_modinv[i] = mod_inverse(fact[i],1ll*MOD);
    }
}
lli choose(int n,int r){
    return mulmod(fact_modinv[n-r],mulmod(fact[n],fact_modinv[r],MOD),MOD);
}
lli P(int n,int r){
    return mulmod(fact[n],fact_modinv[n-r],1ll*MOD);
}
/*-----------------------------START----------------------------- */

int n;

int main(){
    fastio;
    cin>>n;
    priority_queue<double,vector<double>,greater<double>> pq;

    for(int i = 0;i<n;i++){
        double x ;
        cin>>x;
        pq.emplace(x);
    }

    while(pq.size() != 1){
        auto top1 = pq.top();pq.pop();
        auto top2 = pq.top();pq.pop();
        pq.emplace((top1+top2)/2.0);
    }


    cout<<fixed<<setprecision(6)<<pq.top()<<endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	int temp,sum=0;
	int a[1000];
	for (int s = 0; s < n; s++) {
		cin >> a[s];
	}
	for (int i = 0; i <= n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (a[j] < a[i]) {
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}
	for (int i = 0; i < k; i++) {
		sum += a[i];
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL gcd(LL a, LL b)
{
	if (a < b) std::swap(a, b);
	LL r = a % b;
	while (r != 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

LL lcm(LL a, LL b)
{
	return a / gcd(a, b) * b;
}

int main()
{
	LL A, B, C, D;
	in >> A >> B >> C >> D;

	LL ans1 = 0, ans2 = 0;
	--A;
	ans1 = A - (A / C + A / D - A / lcm(C, D));
	ans2 = B - (B / C + B / D - B / lcm(C, D));

	out << ans2 - ans1 << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> istream & operator>>(istream & s, vector<T> & v) { RF(e, v) { s >> e; } return s; }
template<typename T> ostream & operator<<(ostream & s, vector<T> const & v) {
	inc(i, SI(v)) { s << (i == 0 ? "" : " ") << v[i]; }
	return s;
}

template<typename T> using IPQ = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using DPQ = priority_queue<T, vector<T>,    less<T>>;

int main() {
	IN(int, x, y, A, B, C);
	vector<LL> a(A), b(B), c(C);
	cin >> a >> b >> c;
	sort(RALL(a));
	sort(RALL(b));
	sort(RALL(c));
	
	IPQ<LL> aa, bb;
	LL ans = 0;
	inc(i, x) { aa.push(a[i]); ans += a[i]; }
	inc(i, y) { bb.push(b[i]); ans += b[i]; }
	
	RF(e, c) {
		LL va = aa.top();
		LL vb = bb.top();
		LL vm = min(va, vb);
		if(e < vm) { break; }
		ans += e - vm;
		auto & qm = (va < vb ? aa : bb);
		qm.pop();
		qm.push(e);
	}
	OUT(ans);
}


Measured memory_bytes: 4852
# B - Popular Vote
n, m = map((int),(input().split()))

a = list(map(int, input().split()))

a.sort(reverse=True)

flg = True

for i in range(1, m):
    if a[i] < sum(a) / (4 * m):
        flg = False

if flg == True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    md = input[0].split(" ");
	mmdd = input[1].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
    var m1 = parseInt(md[0], 10);
    var d1 = parseInt(md[1], 10);
	var m2 = parseInt(mmdd[0], 10);
	var d2 = parseInt(mmdd[1], 10);
	
	//console.log(m1,d1,m2,d2)
    if (m1 == m2){console.log('0');}
    else{console.log('1');}
	
	
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
string s;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>s;
    if(s[s.size()-1]=='s')
        s.push_back('e');
    s.push_back('s');
    cout<<s;
    return 0;
}


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

int main() {
  int n,k; cin >> n >> k;
  if((n-1)%(k-1)==0)cout << (n-1)/(k-1) << endl;
  else cout << (n-1)/(k-1)+1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
signed main()
{
  int x=0,y=0,z=0,n=0,m=0,w=0;
  std::cin >> x>>y;
  if(y%10==y){
    z=x*10+y;
  }else if(y==100){
    z=x*1000+y;
    if(z==100100){
      std::cout << "No" << '\n';
      return 0;
    }
  }else{
    z=x*100+y;
  }
  if(z==sqrt(z)*sqrt(z))std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr auto INF = INT_MAX / 2;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int n, m;
vi a, b;
vvi c;
int memo[1020][1 << 13];

int dp(int i, int j) {
	if (memo[i][j] != 0)return memo[i][j];
	if (j == 0)return 0;
	if (i == 0)return INF;
	
	int k1 = dp(i - 1, j);

	int jj = 0;
	rep(l, b[i - 1])jj += (1 << (c[i - 1][l] - 1));
	int jjj = 0;
	rep(l, n) if ((j >> l & 1) && !(jj >> l & 1))jjj += 1 << l;
	
	int k2 = dp(i - 1, jjj);
	memo[i][j] = min(k1, k2 + a[i - 1]);
	return memo[i][j];

}

int main() {

	cin >> n >> m;
	a.resize(m);
	b.resize(m);
	c.resize(m);

	rep(i, m + 1)rep(j, 1 << n)memo[i][j] = 0;

	rep(i, m) {
		cin >> a[i] >> b[i];
		c[i].resize(b[i]);
		rep(j, b[i])cin >> c[i][j];
	}

	int ans = dp(m, ((1 << n) - 1));
	if (ans == INF)cout << -1 << endl;
	else cout << ans << endl;

}

Measured memory_bytes: 31104
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using _TYPE = int;
typedef tree< _TYPE, null_type, less< _TYPE >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int n;
const int MAX = 3002;
double inp[MAX];
bool vis[MAX][MAX];
double dp[MAX][MAX];
//dp[i][j]: maximum probability from beginning until index i(inclusive) and having heads more than tails

double solve(int index, int headCount) {
    if(index == n) {
        if(headCount > n - headCount)
            return 1.0;
        return 0.0;
    }
    if(vis[index][headCount])
        return dp[index][headCount];
    vis[index][headCount] = true;
    double &rt = dp[index][headCount];
    rt = solve(index + 1, headCount + 1) * inp[index];
    rt += solve(index + 1, headCount) * (1.0 - inp[index]);
    return rt;
}

int main() {
    IO;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> inp[i];
    cout << fixed << setprecision(10) << solve(0, 0);
    return 0;
}

Measured memory_bytes: 77952
#include <iostream>
#include <cmath>

using namespace std;

int main(){
	int d;
	while(cin >> d){
		int N = 0;
		for(int i = 1; i * d < 600; i++){
			N += (int)pow(i * d, 2) * d;
		}
		cout << N << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
char a[110],b[110];
int main()
{
    scanf("%s",a);
    int len=strlen(a);
    strcpy(b,"keyence");
    int l=0,flag=0,t,p,cnt;
    for(int i=0;i<len;i++)
    {
        l=0,cnt=0;
        if(i>0) cnt+=1;
        while(a[i]==b[l]) i++,l++;
        if(cnt==1&&l<7)
        {
            if(l<7) flag=0;
            else if(l==7) flag=1;
            break;
        }
        else if(cnt==0)
        {
            int fg=1;
            for(int j=len-(7-l);j<len;j++)
            {
                if(a[j]==b[l]) l++;
                else
                {
                    fg=0;
                    break;
                }
            }
            if(fg==1) flag=1;
            break;
        }
    }
    if(flag==1) printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	string s;
	cin >> s;
	rep(i,4)cout << s[i];
	cout << " ";
	for(int i = 4 ; i < 12 ; i ++){
		cout << s[i];
	}
	cout << endl;
}



Measured memory_bytes: 764
#include <stdio.h>
int main(void)
{
  int A,B,C,D,E;
  scanf("%d%d",&A,&B);
  
  C=A+B;
  D=A-B;
  E=A*B;
  
  if(C >= D && C >= E){
    printf("%d",C);
    }else if (D > C && D >= E){
    printf("%d",D);
    }else if(E > C && E > D){
    printf("%d",E);
    }
  return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1


def II(): return int(input())


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


def MI1(): return map(int1, input().split())


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


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def Fibo(n, memo={}):
    if n == 1:
        return 0
    elif n == 2:
        return 1
    elif n in memo:
        return memo[n]
    else:
        memo[n] = Fibo(n - 1, memo) + Fibo(n - 2, memo)
        return memo[n]


def solve():
    n, m = MI()

    s = 0
    mod = 1000000007
    ans = 1
    for _ in range(m):
        t = II() - 1
        d = t - s
        if d < 0:
            keiro = 0
        else:
            keiro = Fibo(d + 2)
        # print(s, t, d, keiro)
        ans = ans * keiro % mod
        s = t + 2
    d = n - s
    if d < 0:
        keiro = 0
    else:
        keiro = Fibo(d + 2)

    ans = ans * keiro % mod
    print(ans % mod)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 568672
require 'matrix'

n, m, l = gets.chomp.split(" ").map(&:to_i)
tmp_a = []
tmp_b = []
n.times do |i|
  tmp_a.push gets.chomp.split(" ").map(&:to_i)
end
m.times do |i|
  tmp_b.push gets.chomp.split(" ").map(&:to_i)
end
a = Matrix.rows(tmp_a)
b = Matrix.rows(tmp_b)
(a * b).to_a.each do |line|
  puts line.join(" ")
end

Measured memory_bytes: 9680
#include <iostream>

using namespace std;

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

    int N;
    cin >> N;
    int a, b;
    int cnt = 0;
    bool flag = false;
    for (int i = 0; i < N; ++i)
    {
        cin >> a >> b;
        if (a == b)
            ++cnt;
        else
            cnt = 0;
        if (cnt >= 3)
            flag = true;
    }
    cout << (flag ? "Yes" : "No");

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9
struct po{int x,d;};
long long dp[155][15][80];

int calc(po a,po b){return (a.d+b.d)*(abs(a.x-b.x));}

int main(){
  while(1){
    int n,m;
    cin>>n>>m;
    if(!n&&!m)break;
  
    vector <po> mp[200];
    for(int i=0;i<200;i++)mp[i].clear();

    for(int i=0,k;i<n;i++){
      cin>>k;
      mp[i].resize(k);
      for(int j=0;j<k;j++) cin>>mp[i][j].x>>mp[i][j].d;
    }
    
    for(int i=0;i<n;i++)
      for(int j=0;j<(int)mp[i].size();j++) 
	for(int k=0;k<=m;k++)dp[i][j][k]=INF;
    
    for(int i=0;i<(int)mp[0].size();i++) dp[0][i][0]=0;
    if(m)for(int i=0;i<(int)mp[1].size();i++) dp[1][i][1]=0;
    
    for(int i=0;i<n;i++){
      for(int j=0;j<(int)mp[i].size();j++)
	for(int k=0;k<=m;k++){
	  for(int l=0;l<(int)mp[i+1].size();l++)
	    dp[i+1][l][k]=min(dp[i+1][l][k],dp[i][j][k]+calc(mp[i][j],mp[i+1][l]));
	  
	  for(int l=0;l<(int)mp[i+2].size()&&k!=m;l++)
	    dp[i+2][l][k+1]=min(dp[i+2][l][k+1],dp[i][j][k]+calc(mp[i][j],mp[i+2][l]));
	}
    }
    
    long long ans=INF;
    for(int i=0;i<(int)mp[n-1].size();i++)
      for(int j=0;j<=m;j++) ans=min(dp[n-1][i][j],ans);
    
    for(int i=0;i<(int)mp[n-2].size();i++)
      for(int j=0;j<m;j++)  ans=min(dp[n-2][i][j],ans);
    cout <<ans<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 2620
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int f(int i, int K) {
    int cnt = 0;
    while (i < K) {
        ++cnt;
        i *= 2;
    }
    return cnt;
}

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

    double ans = (N >= K) ? (double)(N - K + 1) / (double)N : 0.0;
    for (int i = 1; i <= min(K - 1, N); ++i) {
        ans += 1.0 / (double)(N << f(i, K));
    }

    printf("%.10lf", ans);
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

int a[100005];

int main() {
    int n, x;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
	scanf("%d", &x);
	x--;
	a[i] = x;
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
	if(a[a[i]] == i) ans++;
    }
    printf("%d\n", ans / 2);
    return 0;
}


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

int main(void)
{
	int a,b;
	char op;
	
	while(1)
	{
		cin >> a >> op >> b;
		if(op == '+')
		{
			cout << a + b << endl;
		}
		else if(op == '-')
		{
			cout << a - b << endl;
		}
		else if(op == '*')
		{
			cout << a * b << endl;
		}
		else if(op == '/')
		{
			cout << a / b << endl;
		}
		else
		{
			break;
		}
	}
	
	return 0;
}


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

int main()
{
    int a, b;
	string op;

	do{
		cin >> a >> op >> b;
		if(op == "+") cout << a + b << endl;
		if(op == "-") cout << a - b << endl;
		if(op == "*") cout << a * b << endl;
		if(op == "/") cout << a / b << endl;
	}while(op != "?");

	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <string.h>
#include <math.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険

#define rep(i,l,r)for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r)for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k)for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す
/*
   upll : (a<b)なら-1, (a=b)なら0, (a>b)なら1
 downll : (a<b)なら1, (a=b)なら0, (a>b)なら-1

 const void* a : 型を縛らずにconstをつける(=変数aが読み込み専用の変数であることを明示する)
        (ll*)a : 変数aがconst long long *型であると明示する
*/
// int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
// int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
// void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
// void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)



int main(){
    ll n, l; cin >> n >> l;
    ll sum = 0;
    rep(i,0,n) sum += l+i;
    ll ans, m = INF;
    rep(i,0,n) if(m != min(abs(l+i), m)) { m = abs(l+i); ans = sum - (l+i);}
    cout << ans << endl;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map &:to_i
q = gets.to_i

h = Array.new(100001, 0)
sum = 0
a.each do |x|
  h[x] += 1
  sum += x
end

q.times do
  b, c = gets.split.map &:to_i
  sum += h[b] * (c - b)
  h[c] += h[b]
  h[b] = 0
  
  p sum
end


Measured memory_bytes: 23648
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys
import string


if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")



N = int(sys.stdin.readline())
print(int(math.sqrt(N)) ** 2)







Measured memory_bytes: 13576
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;

void solve(long long N, std::vector<long long> x, std::vector<long long> y){
  int ans = INF;
  if(N==1){
    cout << 1 << endl;
    return;
  }
  rep(i,N) REP(j,0,N){
    if(i==j) continue;
    ll p, q;
    p = x[i]-x[j];
    q = y[i]-y[j];
    int temp = 0;
    int cnt = 0;
    rep(k,N)rep(l,N){
      if(x[l]-x[k]==p && y[l]-y[k]==q) cnt++;
    }
    temp += N-cnt;
    chmin(ans,temp);
  }
  cout << ans << endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> x(N);
  std::vector<long long> y(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&x[i]);
    scanf("%lld",&y[i]);
  }
  solve(N, std::move(x), std::move(y));
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    cnt += r - l + 1;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let s = read_as_string();
    println!("{}", &s[0..3]);
}


Measured memory_bytes: 2104
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int count = 0;
		for(int i=1;i<N;i++){
			for(int j=1;i*j<N;j++){
				if( i * j < N ){
					count++;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 27204
/*
 * ITP1_1_D.c
 *
 *  Created on: 2017/05/11
 *      Author: sl2-user
 */
#include<stdio.h>

int main(void){

int a,b,c;
int temp;
scanf("%d %d %d" ,&a,&b,&c);
if(a>b){temp=a;a=b;b=temp;}
if(b>c){temp=b;b=c;c=temp;}
if(a>c){temp=a;a=c;c=temp;}
if(a>b){temp=a;a=b;b=temp;}
printf("%d %d %d\n" , a ,b ,c);
return 0;
}

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

class Room{
    
    public:
        std::vector<int> neighbor;
        int sign;
        int checked;
        
        Room()
        {
            sign = 0;
            checked = 0;
        }
};

void mark(Room *rooms, int no)
{
    for(int i = 0; i < rooms[no-1].neighbor.size(); i++)
    {
        if(rooms[rooms[no-1].neighbor[i]-1].sign == 0)
        {
            rooms[rooms[no-1].neighbor[i]-1].sign = no;
        }
    }
}

int main(void){
    // Your code here!
    Room rooms[100000];
    int N,M;
    int a,b;
    std::vector<int> que;
    scanf("%d %d",&N,&M);
    
    for(int m = 0; m < M; m++)
    {
        scanf("%d %d", &a, &b);
        rooms[a-1].neighbor.push_back(b);
        rooms[b-1].neighbor.push_back(a);
    }
    
    int idx = 0;
    rooms[0].checked = 1;
    rooms[0].sign = -1;
    que.push_back(1);
    while(que.size() < N)
    {
        int targetroom = que[idx++];
        for(int nei : rooms[targetroom-1].neighbor)
        {
            if(rooms[nei-1].checked == 0)
            {
                rooms[nei-1].checked = 1;
                que.push_back(nei);
            }
        }
    }
    
    //printf("queuecheck\n");
    for(int i : que)
    {
        for(int j : rooms[i-1].neighbor)
        {
            if(rooms[j-1].sign == 0)
                rooms[j-1].sign = i;
        }
    }
    
    printf("Yes\n");
    for(int n = 2; n <= N; n++)
    {
        //printf("No. %d is %s: %d\n", n, (rooms[n-1].checked == 0)? "not checked":"checked", rooms[n-1].sign);
        printf("%d\n", rooms[n-1].sign);
    }
    
    /* debug code
    for(int n = 1; n <= N; n++)
    {
        printf("Room %d is connected to...\n", n);
        for(int i = 0; i < rooms[n-1].neighbor.size(); i++)
        {
            printf("%d\n",rooms[n-1].neighbor[i]);
        }
        printf("\n");
    }*/
}


Measured memory_bytes: 10996
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

int gcd(int x, int y)
{
    return (y == 0 ? x : gcd(y, x % y));
}

const int N = 2020;
const int V = 40020;
int n, m;
int a[N];
bool b[N][N];
int ans[N];
bool inAns[N];
int ansSz;
int lastNotCoprime[N];
int minOnSuff[N];
int comp[V];
vector<int> g[V];
int C;
int bestForCol[N];

map<int, int> primeId;
int getId(int p)
{
    if (primeId.count(p) > 0) return primeId[p];
    primeId[p] = m;
    return m++;
}

void dfs(int v)
{
    comp[v] = C;
    for (int u : g[v])
    {
        if (comp[u] != -1) continue;
        if (u < n && inAns[u]) continue;
        dfs(u);
    }
    return;
}

void colors()
{
    for (int i = 0; i < m; i++)
        comp[i] = -1;
    C = 0;
    for (int i = 0; i < n; i++)
    {
        if (inAns[i]) continue;
        if (comp[i] != -1) continue;
        dfs(i);
        C++;
    }
    return;
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    scanf("%d", &n);
    m = n;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
        int x = a[i];
        for (int y = 2; y * y <= x; y++)
        {
            if (x % y != 0) continue;
            int id = getId(y);
            g[i].push_back(id);
            g[id].push_back(i);
            while(x % y == 0)
                x /= y;
        }
        if (x != 1)
        {
            int id = getId(x);
            g[i].push_back(id);
            g[id].push_back(i);
        }
    }
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            if (gcd(a[i], a[j]) > 1)
                b[i][j] = b[j][i] = 1;

    for (int i = 0; i < n; i++)
        lastNotCoprime[i] = -1;
    for (int i = 0; i <= n; i++)
        minOnSuff[i] = (int)1e9 + 2;

    while(ansSz != n)
    {
        colors();
        for (int i = 0; i < C; i++)
            bestForCol[i] = -1;
        for (int i = 0; i < n; i++)
        {
            if (inAns[i]) continue;
            if (minOnSuff[lastNotCoprime[i] + 1] < a[i]) continue;
            if (bestForCol[comp[i]] == -1 || a[bestForCol[comp[i]]] > a[i])
                bestForCol[comp[i]] = i;
        }
        int id = -1;
        for (int i = 0; i < C; i++)
        {
            if (bestForCol[i] == -1) continue;
            if (id == -1 || a[id] < a[bestForCol[i]])
                id = bestForCol[i];
        }
        if (id == -1) throw;
        inAns[id] = 1;
        ans[ansSz++] = a[id];
        for (int i = 0; i < ansSz; i++)
            minOnSuff[i] = min(minOnSuff[i], a[id]);
        for (int i = 0; i < n; i++)
            if (b[id][i])
                lastNotCoprime[i] = ansSz - 1;
    }
    for (int i = 0; i < n; i++)
        printf("%d ", ans[i]);
    printf("\n");

    return 0;
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x,h,w) (y) < 0 || (h) <= (y) || (x) < 0 || (w) <= (x)
#define line cout << "------------------------\n" 
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n, k; cin >> n >> k;
    FOR(i, 0, k) {
        int a, b; cin >> a >> b;
        if (n / 2 < a)a = n - a + 1;
        if (n / 2 < b)b = n - b + 1;
        --a, --b;
        cout << min(a, b) % 3 + 1 << "\n";
    }
}



Measured memory_bytes: 3168
#!/usr/bin/env python3
import sys


def solve(N: int, X: "List[int]"):
    Y = sorted(X)
    me1 = Y[N//2]
    me2 = Y[N//2-1]

    for i in range(N):
        if X[i]<=me2:
            print(me1)
        elif X[i]>=me1:
            print(me2)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 31704
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    ans=10000
    for i in range(1,n):
        w=abs(sum(l[:i])-sum(l[i:]))
        ans=min(w,ans)
    print(ans)
resolve()

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
  int b[3],k,i=-1,j=-1;
  char d[3];
  b[0] = 1;
  b[1] = 0;
  b[2] = 0;
  while(cin>>d[0]>>d[1]>>d[2]){
    if(d[0]=='A'||d[2]=='A'){
      if(i==-1) i = 0;
      else if(i!=-1) j = 0;
    }
     if(d[0]=='B'||d[2]=='B'){
      if(i==-1) i = 1;
      else if(i!=-1) j = 1;
    }
   if(d[0]=='C'||d[2]=='C'){
      if(i==-1) i = 2;
      else if(i!=-1) j = 2;
    }
   k = b[i];
   b[i] = b[j];
   b[j] = k;
   i = -1;
   j = -1;
  }
  for(int o=0;o<3;o++){
    if(b[o]==1){
      if(o==0) cout << 'A' << endl;
      if(o==1) cout << 'B' << endl;
      if(o==2) cout << 'C' << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1132
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	int aa, bb;
	aa = 0; bb = 1010;
	int c;
	for (int i = 0; i < n; i++) {
		cin >> c;
		aa = max(aa, c);
		bb = min(bb, c);
	}
	cout << aa - bb << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> 				void _DO(I&&x){	cerr<<x<<endl;	}
template<typename I,typename...T>	void _DO(I&&x,T&&...tail){	cerr<<x<<" , ";	_DO(tail...);	}
template<typename _a,typename _b> 	ostream& operator << (ostream &_s,const pair<_a,_b> &_p)
{	return _s<<'('<<_p.first<<','<<_p.second<<')';	}
#define IOS
#else
#define debug(...)
#define IOS do{ios_base::sync_with_stdio(0); cin.tie(0);}while(0);
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define stp setprecision(18)<<fixed
const ll INF=0x3f3f3f3f3f3f3f3f;
const int NF=0x3f3f3f3f;
const ll MAX=1e5+5,Mlg=__lg(MAX)+2;
const ll MOD=1e9+7;
// ready~ go!
// let's coding and have fun!
// I can't solve this problem!
bool che(){
	IOS
	char c;	cin>>c;	if(c!='A')	return 0;
	cin>>c;	if(!islower(c))	return 0;
	string s;	cin>>s;
	if( !islower(s.back()) )	return 0;
	s.pop_back();
	bool b=0;
	for(char c:s){
		if(c=='C'&&b==0){
			b=1;
		}
		else{
			if( !islower(c) )	return 0;
		}
	}
	return b;
}
int main(){
	if(che())	cout<<"AC\n";
	else		cout<<"WA\n";
	return 0;
}


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

int main(){
	int x;
  	cin >> x;
  	if(x >= 30){
      cout << "Yes"<< endl;
    }
  	else {
      cout << "No" << endl;
    }
	
	return 0;
}

Measured memory_bytes: 3592