akhauriyash/Code-Regression huggingface dataset:
use std::io::Write;
use std::cmp::min;

macro_rules! eprintln {
    ($($args:tt)*) => { let _ = writeln!(&mut std::io::stderr(), $($args)*); }
}

fn read_line() -> Vec<String> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).expect("Failed to read line");
    line.trim().split_whitespace().map(|s| s.to_string()).collect()
}

struct Reader { v: Vec<String>, n: usize }

impl Reader {
    fn new() -> Self { Reader { v: read_line(), n: 0 } }
    fn next<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug {
        if self.n == self.v.len() { self.v = read_line(); self.n = 0; }
        self.n += 1;
        self.v[self.n-1].parse().expect(&self.v[self.n-1])
    }
    #[allow(dead_code)]
    fn nexts<T>(&mut self, n: usize) -> Vec<T>
    where T: std::str::FromStr, T::Err: std::fmt::Debug {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n { v.push(self.next()); }
        v
    }
}

fn main() {
    let mut r = Reader::new();
    let h = r.next();
    let w = r.next();
    let mut a: Vec<Vec<i64>> = Vec::new();
    let mut b: Vec<Vec<i64>> = Vec::new();
    for _ in 0..h {
        let ai = r.nexts(w);
        a.push(ai);
    }
    for _ in 0..h {
        let bi = r.nexts(w);
        b.push(bi);
    }

    let mut dp = Vec::new();
    for i in 0..(h+1) {
        dp.push(vec![]);
        for _ in 0..(w+1) {
            dp[i].push(vec![false; 12800]);
        }
    }
    let x: i64 = a[0][0]-b[0][0];
    dp[1][1][x.abs() as usize] = true;;

    for i in 0..h {
        for j in 0..w {
            for k in 0..12800 {
                let d = (a[i][j]-b[i][j]).abs();
                let k1 = (k as i64 - d).abs() as usize;
                let k2 = k + d as usize;
                if k2 >= 12800 {
                    continue;
                }
                dp[i+1][j+1][k] = dp[i+1][j+1][k] || dp[i][j+1][k1] || dp[i][j+1][k2];
                dp[i+1][j+1][k] = dp[i+1][j+1][k] || dp[i+1][j][k1] || dp[i+1][j][k2];
            }
            //println!("{} {} {:?}", i+1, j+1, dp[i+1][j+1].iter().take(10).enumerate().filter_map(|(i, &x)| if x { Some(i) } else { None }).collect::<Vec<usize>>());
        }
    }
    for k in 0..12800 {
        if dp[h][w][k] {
            println!("{}", k);
            return;
        }
    }
    return;
}


Measured memory_bytes: 98684
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll K,T;cin >> K >> T;
    vector<ll> a(T);
    for(int i=0;i<T;i++) cin >> a[i];
    sort(a.rbegin(),a.rend());
    ll sum=0;
    for(int i=1;i<T;i++) sum+=a[i];
    cout << (a[0]-sum-1>=0 ? a[0]-sum-1:0) << endl;

    return 0;
}

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

int b()
{
    int a, b, m;
    std::cin >> a >> b >> m;
    std::vector<int> priceA(a);
    std::vector<int> priceB(b);
    int minA = 500000;
    int minB = 500000;
    int min = 500000;

    for(int i = 0; i < a; i++)
    {
        int temp;
        std::cin >> temp;
        priceA[i] = temp;
        if(temp < minA)
        {
            minA = temp;
        }
    }
    
    for(int i = 0; i < b; i++)
    {
        int temp;
        std::cin >> temp;
        priceB[i] = temp;
        if(temp < minB)
        {
            minB = temp;
        }
    }
    
    min = minA + minB;
    for(int i = 0; i < m; i++)
    {
        int x, y, c;
        std::cin >> x >> y >> c;
        
        int myPrice = priceA[x-1] + priceB[y-1] - c;
        if(myPrice < min)
        {
            min = myPrice;
        }
    }
    
    std::cout << min;
    return 0;
}


int main(int argc, const char * argv[])
{
    b();
    return 0;
}

Measured memory_bytes: 1024
import collections

N = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

soinsu_list = prime_factorize(N)
sosu_list = collections.Counter(soinsu_list)
count = 0

for k, v in sosu_list.items():
  i = 1
  _v = v
  while _v - i >= 0:
    count+=1
    _v-=i
    i+=1
print(count)

Measured memory_bytes: 9364
# -*- coding: utf-8 -*-

N=int(input())
A=list(map(int,input().split()))

S=[0]*N
S[0]=A[0]

for i in range(1,N):
    S[i]=S[i-1]+A[i]

#S=sum(A)

ans=0
for i in range(N):
    ans+=A[i]*(S[i]-A[i])
    ans%=1000000007

print(ans)

Measured memory_bytes: 31616
using System;

namespace ABC100_C___3_or_2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var ai = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            var count = 0;
            for (int i = 0; i < ai.Length; i++)
            {
                var a = ai[i];
                while (a % 2 == 0)
                {
                    a /= 2;
                    count += 1;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13792
#include <bits/stdc++.h>
using namespace std;
int main(){
	int k,n;
	cin >> n >> k;
	int niz[k];
	cin >> niz[0];
	int maraz=0;
	for(int i=1;i<k;i++){
		cin >> niz[i];
		maraz=max(maraz,niz[i]-niz[i-1]);
	}
	maraz=max(maraz,n-niz[k-1]+niz[0]);
	cout<<n-maraz;
	return 0;
}

Measured memory_bytes: 1024
import Control.Monad
main = replicateM 2 getLine >>= putStrLn . solve
    where
        solve [xs, ys] = build xs ys

build :: String -> String -> String
build (o : os) (y : ys) = o : y : build os ys
build (o : os) _ = o : build os []
build _ _ = []


Measured memory_bytes: 508
#include <iostream>
#define llint long long

using namespace std;

llint N;
llint T[1005], A[1005];

int main(void)
{
	cin >> N;
	for(llint i = 0; i < N; i++) cin >> T[i] >> A[i];
	
	llint t = 1, a = 1, lim;
	for(llint i = 0; i < N; i++){
		lim = max( (t+T[i]-1)/T[i], (a+A[i]-1)/A[i] ) * (T[i]+A[i]);
		t = lim / (T[i] + A[i]) * T[i], a = lim / (T[i] + A[i]) * A[i];
	}
	
	cout << lim << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, Q;
	cin >> Q >> N;
	vector<int> S(Q);
	vector<int> T(Q);
	vector<int> X(Q);
	vector<pair<int, int> > s;
	for (int i = 0; i < Q; i++) {
		cin >> S[i] >> T[i] >> X[i];
		S[i] -= X[i];
		T[i] -= X[i];
		s.emplace_back(S[i], X[i]);
		s.emplace_back(T[i], -X[i]);
	}
	sort(s.begin(), s.end());

	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int cur = 0;
	set<int> st;
	for (int i = 0; i < N; i++) {
		while (cur < s.size() && s[cur].first <= A[i]) {
			if (s[cur].second < 0) {
				st.erase(-s[cur].second);
			}
			else {
				st.insert(s[cur].second);
			}
			cur++;
		}

		if (st.size() == 0) {
			cout << -1 << endl;
		}
		else {
			cout << (*st.begin()) << endl;
		}


	}

}

Measured memory_bytes: 24808
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll N;
    cin>>N;
    v a(N);
    rep(i,0,N)cin>>a[i];
    ll sum = 0;
    rep(i,0,N){
        sum ^= a[i];
    }       
    rep(i,0,N){
        cout<<(sum ^ a[i])<<" ";
    }
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

ll N;
ll A1[200010];
ll A2[200010];

ll dp_pos[200010][16];
ll dp_neg[200010][16];

void solve(ll A[200010], ll dp_pos[200010][16]){
    for(ll pos = N - 1; pos >= 0; pos--){
        for(ll ope_cnt = 0; ope_cnt <= 15; ope_cnt++){ 
            ll res = 1LL << 62;
            if(pos == N - 1) {
                res = 0;
            }
            else{
                // 現在のところの値に対して 4 ^ ope_cnt したものと、次の要素の値を比較し、次の値が何回計算する必要があるか調べる
                ll c_val = A[pos] * (1LL << (ope_cnt * 2));
                if(c_val <= A[pos + 1]){
                    // 操作の必要なし
                    res = dp_pos[pos + 1][0];
                }
                else{
                    // 何回操作したら超えるか調べる
                    // 15を超えた分は、残りの数字をすべて4でかける操作で代用できるので、その分を加算しておくことで代用する
                    // c_val <= A[pos + 1] * (4 ^ n_cnt)となる最小のn_cntを計算する
                    ll n_cnt = 0;
                    ll cmp = (A[pos + 1] + c_val - 1) / A[pos + 1];
                    for(; ; n_cnt++) if(cmp <= 1LL << (n_cnt * 2)) break;
                    ll diff = max(n_cnt - 15, 0LL);
                    res = (N - 1 - pos) * 2 * diff + min(n_cnt, 15LL) * 2 + dp_pos[pos + 1][min(n_cnt, 15LL)];
                }

            }
            dp_pos[pos][ope_cnt] = res;
        }
    }
}

int main(){
    cin >> N;
    for(ll i = 0; i < N; i++){
        cin >> A1[i];
        A2[N - 1 - i] = A1[i];
    }
    
    solve(A1, dp_pos);
    solve(A2, dp_neg);
    
    ll ans = min(dp_pos[0][0], dp_neg[0][0] + N);
    for(ll i = 1; i < N; i++){
        // iから正になる場合
        ans = min(ans, dp_neg[N-i-1][0] + dp_pos[i][0] + i);
    }
    cout<< ans << endl;

    return 0;
}


Measured memory_bytes: 53376
#include <iostream>

int main()
{
    int H, W;
    scanf("%d %d", &H, &W);
    char S[H][W+1];
    for(int i=0; i<H; i++)
        scanf(" %s", S[i]);

    int count_v[H][W];
    for(int i=0; i<H; i++){
        int mode = 0;
        int start = 0;
        for(int j=0; j<W; j++){
            if(S[i][j] == '#') count_v[i][j] = 0;
            if(mode == 0){
                if(S[i][j] == '.'){
                    start = j;
                    mode = 1;
                    if(j == W-1) count_v[i][j] = 1;
                }
            }
            if(mode == 1){
                if(S[i][j] == '#'){
                    int c = j - start;
                    for(int k = start; k < j; k++) count_v[i][k] = c;
                    mode = 0;
                }
                else if(j == W-1){
                    int c = W - start;
                    for(int k = start; k < W; k++) count_v[i][k] = c;
                }
            }
        }
    }

    int count_h[H][W];
    for(int j=0; j<W; j++){
        int mode = 0;
        int start = 0;
        for(int i=0; i<H; i++){
            if(S[i][j] == '#') count_h[i][j] = 0;
            if(mode == 0){
                if(S[i][j] == '.'){
                    start = i;
                    mode = 1;
                    if(i == H-1) count_h[i][j] = 1;
                }
            }
            if(mode == 1){
                if(S[i][j] == '#'){
                    int c = i - start;
                    for(int k = start; k < i; k++) count_h[k][j] = c;
                    mode = 0;
                }
                else if(i == H-1){
                    int c = H - start;
                    for(int k = start; k < H; k++) count_h[k][j] = c;
                }
            }
        }
    }

    int max = 0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            int count = count_v[i][j] + count_h[i][j] - 1;
            if(count > max) max = count;
        }
    }
    printf("%d\n", max);
    /*
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            std::cout << count_v[i][j];
        }
        std::cout << std::endl;
    }
    std::cout << std::endl;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            std::cout << count_h[i][j];
        }
        std::cout << std::endl;
    }
    */
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(s,x) memset(s,x,sizeof(s))
#define pb push_back
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;

const int MAXN = 1e5+5;
const ll MOD = 1e9+7;

int main()
{
    string s;
    cin >> s;
    rep(i, 1, s.size())
        putchar('x');
    cout << endl;

    return 0;
}


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

int main(){
  int n,i,a;
  cin >> n;
  map<int, int> d;
  for(i=0;i<n;i++){
    cin >> a;
    d[a]++;
  }
  bool ans = true;
  cin >> n;
  for(i=0;i<n;i++){
    cin >>a;
    d[a]--;
    if(d[a]<0){
      ans = false;
      break;
    }
  }
  puts(ans?"YES":"NO");
}

Measured memory_bytes: 9600
#include <iostream>
#include <queue>
#define debug 0
using namespace std;
int date[1000][1000]={0};
int cost[1000][1000]={0};
int r,c;
int Px[4]={1,0,-1,0};
int Py[4]={0,-1,0,1};
int XX(int nowx,int P){
	nowx+=Px[P];
	if(nowx>=r)nowx=0;
	if(nowx<0)nowx=r-1;
	return nowx;
}
int YY(int nowy,int P){
	nowy+=Py[P];
	if(nowy>=c)nowy=0;
	if(nowy<0)nowy=c-1;
	return nowy;
}

int main(){
	int ax,ay,bx,by,tx,ty;
	cin>>r>>c>>ax>>ay>>bx>>by;
	queue<int>x;
	queue<int>y;
	x.push(ax);
	y.push(ay);
	date[ax][ay]=1;
	cost[ax][ay]=1;
	
	while(x.empty()==0){
		for(int i=0;i<4;i++){
			tx=XX(x.front(),i);
			ty=YY(y.front(),i);
			if(date[tx][ty]==0){
				date[tx][ty]=date[x.front()][y.front()]+1;
				cost[tx][ty]=cost[x.front()][y.front()];
				x.push(tx);
				y.push(ty);
			}
			else if(date[tx][ty]==date[x.front()][y.front()]+1){
				cost[tx][ty]=(cost[tx][ty]+cost[x.front()][y.front()])%100000007;
			}
		}
		
		
		x.pop();
		y.pop();
	}
	cout<<cost[bx][by]<<endl;
	if(debug){
		for(int i=0;i<c;i++){
			for(int j=0;j<r;j++)cout<<date[j][i]<<" ";
			cout<<endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 9048
import copy

def perm(i, ls):
    if not ls:
        return 1
    else:
        count = 0
        for j in ls:
            if cost[i-1][j-1]:
                ls2 = copy.copy(ls)
                ls2.remove(j)
                count += perm(j, ls2)
        return count

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

cost = [[0 for _ in range(n)] for _ in range(n)]
for i in range(m):
    a, b= map(int, input().split())
    cost[a-1][b-1] = cost[b-1][a-1] = 1


count = perm(1, list(range(2, n+1)))

print(count)

Measured memory_bytes: 47832
k = int(input())

def gcf(a,b):
    if a % b == 0 :
        return b
    return gcf(b, a%b)

def gcf3(a,b,c):
    f_ab = gcf(a,b)
    return gcf(f_ab,c)

ans = 0
for a in range(1,k+1):
    for b in range(a,k+1):
        for c in range(b,k+1):
            if a == b == c:
                ans += gcf3(a,b,c)
            elif a != b and b != c and a != c:
                ans += gcf3(a,b,c)*6
            else:
                ans += gcf3(a,b,c)*3
print(ans)


Measured memory_bytes: 9120
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//グローバル変数


//ライブラリ挿入


int main(){
    int N;
    cin>>N;
    vector<char> s(N+2);
    REP(i,N) cin>>s[i];
    s[N]=s[0];
    s[N+1]=s[1];
    
    //0:ひつじ　1:おおかみ
    const vector<pair<int,int>> a1_a2={{0,0},{0,1},{1,0},{1,1}};
    bool ans=false;
    for(auto p:a1_a2){
        vector<int> a(N+2);
        a[0]=p.first;
        a[1]=p.second;

        REP2(i,1,N+1){
            if(a[i]==0){
                if(s[i]=='o') a[i+1]=a[i-1];
                else a[i+1]=1-a[i-1];
            }else{
                if(s[i]=='x') a[i+1]=a[i-1];
                else a[i+1]=1-a[i-1];
            }
        }

        if(a[0]==a[N]&&a[1]==a[N+1]){
            REP(i,N){
                if(a[i]==0) cout<<"S";
                else cout<<"W";
            }
            cout <<endl;
            return 0;
        }
    }
    cout<<-1<<endl;

    
}

Measured memory_bytes: 888
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
	}
	cf := 0
	cn := 0
	ct := 0
	for _, a := range as {
		if a%4 == 0 {
			cf++
		}
		if a%2 == 0 {
			ct++
		} else {
			cn++
		}
	}
	if ct == cf {
		if cf >= cn-1 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	} else {
		if cf >= cn {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 5504
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>
#include <iomanip>
#include <functional>
#include <array>
#include <climits>
#include <cmath>

using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;

int main()
{
    int a;
    cin >> a;
    int dist = 0;
    for (int i = 0; i < 4; i++)
    {
        int b;
        cin >> b;
        int d = b - a;
        dist = max(dist, d);
    }
    int k;
    cin >> k;
    cout << ((dist <= k) ? "Yay!" : ":(");
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PB push_back
#define MP make_pair
#define FF first
#define SS second




int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k;
    string s;
    cin >> k >> s;
    vector<char> res;
    vector<char> letters(s.begin(), s.end());
    if(s.size() > k){
        for(int i = 0; i < k; ++i){
            res.PB(letters[i]);
        }
        for(int i = 0; i < 3; ++i){
            res.PB('.');
        }

        for(char re : res){
            cout << re;
        }
    }
    if(s.size() <= k){
        cout << s << "\n";
    }

}




Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

constexpr int mod = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    
    long long ans = 1;
    rep(i, N) {
        ans *= i + 1;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
s = int(input()) 

dict={}
num_list = list(map(int, input().split()))

length=len(num_list)
count=[0]*(s+1000)
for i in range(length):
    count[num_list[i]]+=1
    dict[num_list[i]]=count[num_list[i]]
    
sum=0
#print(dict)
for k, v in dict.items():
    sum+=k*v
#print(dict)
#print(sum)

count=0
d=0
n = int(input()) 
for i in range(n):
    a,b = map(int, input().split())  
    if dict.get(a)!=None:
        d=(b-a)*dict[a]
        #print("d:{}".format(d))
        if dict.get(b)!=None:
            count=dict[b]
            dict[b]=dict[a]+dict[b]
        else:
            dict[b]=dict[a]
        dict[a]=0
        sum+=d
        
        #print(dict)
        
    else:
        pass
    d=0
    print(sum)
    #print()

   


Measured memory_bytes: 20328
#include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=10000005;
#define M 1000000007
#define double long double
#define BINF 10000000000000
#define init(arr,val) memset(arr,val,sizeof(arr))
#define MAXN 15000001
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;



#undef int 
int main() {
#define int long long int
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0);
 


    int n, m;
    cin >> n >> m;
    map<int, int>deep;
    int ac = 0, pen = 0;
    set<int>lol;
    for(int i = 0; i < m; i++){
        int x;
        cin >> x;
        string s;
        cin >> s;
        if(s == "WA" and deep[x] != -1){
            deep[x]++;
        }
        if(s == "AC" and deep[x] != -1){
            lol.insert(x);
            pen += deep[x];
            deep[x] = -1;
        }
    }

    cout << lol.size() << ' ' << pen << endl;

    
return 0;
}




Measured memory_bytes: 11264
#include<stdio.h>
int main(void){
  int i,n,sum=0;
  long int d;
  scanf("%d %ld",&n,&d);
  long int x[n],y[n];
  for(i=0;i<n;i++){
    scanf("%ld %ld",&x[i],&y[i]);
    if(d*d>=x[i]*x[i]+y[i]*y[i])sum++;
  }
  printf("%d",sum);
  return 0;
}


Measured memory_bytes: 4856
import heapq
def main():
    X, Y, Z, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    C = [int(c) for c in input().split()]
    A = sorted(A, reverse = True)
    B = sorted(B, reverse = True)
    C = sorted(C, reverse = True)

    ans = []
    h = [[-(A[0]+B[0]+C[0]), 0, 0, 0]]
    added = set([(0, 0, 0)])
    for _ in range(K):
        v, i, j, k = heapq.heappop(h)
        # ans.append(-v)
        print(-v)
        if i+1 < len(A) and (i+1, j, k) not in added:
            heapq.heappush(h, [v+A[i]-A[i+1], i+1, j, k])
            added.add((i+1, j, k))
        if j+1 < len(B) and (i, j+1, k) not in added:
            heapq.heappush(h, [v+B[j]-B[j+1], i, j+1, k])
            added.add((i, j+1, k))
        if k+1 < len(C) and (i, j, k+1) not in added:
            heapq.heappush(h, [v+C[k]-C[k+1], i, j, k+1])
            added.add((i, j, k+1))
    # return ans

if __name__ == '__main__':
    main()

Measured memory_bytes: 4980
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int maxn = 3100;
LL N,A[maxn];

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

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

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    while (cin >> N) {
        FOR(i,0,N)
            cin >> A[i];
        sort(A,A+N);
        LL ans = 0;
        FOR(i,0,N) {
            ans += A[i]-1;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define SIZE          100005
#define REM           1000000007
#define PI            2*acos(0.0)
#define L             long
#define LL            long long
#define UL            unsigned long
#define ULL           unsigned long long
#define TERMINATE     return 0
#define FAST          ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
template <class T> inline T bigmod1(T p,T e,T M){
    LL ret=1;
    for(; e > 0; e >>= 1){
 
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
 
template <class T> inline T gcode(T a,T b){if(b==0)return a;return gcode(b,a%b);}
template <class T> inline T modularinv(T a,T M){return bigmod1(a,M-2,M);}
 
bool SA(const pair<string,string> &a, const pair<string,string> &b){
   return a.second<b.second;
}
bool FA(const pair<string,string> &a, const pair<string,string> &b){
   return a.first<b.first;
}
bool SD(const pair<LL,LL> &a, const pair<LL,LL> &b){
   return a.second>b.second;
}
bool FD(const pair<int,int> &a, const pair<int,int> &b){
   return a.first>b.first;
}
//int dirA[8]={0,0,1,-1,1,-1,1,-1};
//int dirB[8]={1,-1,0,0,1,-1,-1,1};
//int dirA[4]={0,0,1,-1};
//int dirB[4]={1,-1,0,0};
//int kingsA[8]={0,0,1,-1,-1,1,-1,1};  //Kings Move
//int kingsB[8]={-1,1,0,0,1,1,-1,-1};  //Kings Move
//int knightsA[8]={-2,-2,-1,-1,1,1,2,2};  //Knights Move
//int knightsB[8]={-1,1,-2,2,-2,2,-1,1};  //Knights Move

int main(){
	FAST;
	LL a;
	cin>>a;
	LL first=a/500;
	//cout<<first<<endl;
	a-=(first*500);
	LL sec=a/5;
	//cout<<sec<<endl;
	cout<<first*1000+sec*5<<endl;
	cerr<<"time elapsed:"<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<"\n";
	return 0;
}



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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

void dfs(const vector<vector<int64_t>>& adjs, vector<int64_t>& c,
         vector<int64_t>& d, int64_t v, int64_t p) {
    d[v] = c.back();
    c.pop_back();

    for (auto u : adjs[v]) {
        if (u == p) {
            continue;
        }

        dfs(adjs, c, d, u, v);
    }
}

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

    vector<vector<int64_t>> adjs(n);
    for (auto _ : irange(0L, n - 1)) {
        int64_t a, b;
        cin >> a >> b;
        --a;
        --b;
        adjs[a].push_back(b);
        adjs[b].push_back(a);
    }

    int64_t m = 0;
    vector<int64_t> c(n);
    for (auto&& cc : c) {
        cin >> cc;
        m += cc;
    }

    sort(c.begin(), c.end());
    m -= c.back();

    vector<int64_t> d(n);
    dfs(adjs, c, d, 0L, -1L);

    cout << m << endl;

    const auto* delim = "";
    for (auto dd : d) {
        cout << delim << dd;
        delim = " ";
    }
    cout << endl;
}

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

long long GCD(long long a, long long b) 
{ 
    if(b==0) 
        return a; 
    return GCD(b, a % b);  
      
}

long long LCM(long long a, long long b)
{
    long long gcd=GCD(a,b);
     return (a*b)/gcd;
}

int main()
{
    long long i, j, k, n, m, t, x, y, s=0, c=0, l;
    cin >> n >> m;
    if(n<=m)
    {
        for(i=0; i<m; i++)
            cout << n;
    }
    else
    {
        for(i=0; i<n; i++)
            cout << m;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define pri 1000000007
#define all(x) x.begin(),x.end()
#define mx 32
using namespace std;

void masterstroke(){
	ll n;
	cin>>n;
	ll a[n];
	multiset <ll> e;
	for(ll i=0;i<n;i++){
	cin>>a[i];
	if(e.size()==0){e.insert(a[i]);}
	else{
	     auto  f=e.lower_bound(a[i]);
	     if(f==e.begin()){e.insert(a[i]);}
		 else{
		      f--; 
	          e.erase(f);
		      e.insert(a[i]);
		   }
	}
	
	}
	cout<<e.size();
	
	
    

}


int main() {
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++)masterstroke();
	
	// your code goes here
	return 0;
}


Measured memory_bytes: 5760
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;


int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}

int main()
{
  int cnt;
  int A, B;
  int i;
  int result = 0;

  cnt = scanf("%d %d", &A, &B);

  if (A < (2*B)) {
    result = 0;
  } else {
    result = A - 2*B;
  }

  printf("%d", result);

  return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)
#define mod2 998244353

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}
int mod_pow(int x, int y, int m = mod) {
	int res = 1;
	x %= m;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int perm[1000005];
void init_perm(){
	perm[0]=1;
	REP(i,1000005)perm[i]=perm[i-1]*i%mod;
}
int nCk(int x,int y){
	if(x<y)return 0;
	return perm[x]*mod_pow(perm[x-y],mod-2)%mod*mod_pow(perm[y],mod-2)%mod;
}
int N,A,B,C,D;
int dp[1005][1005];
signed main(){
    init_perm();
    cin>>N>>A>>B>>C>>D;
    dp[0][1]=1;
    rep(i,N){
        REP(j,N){
            dp[i][j]%=mod;
            dp[i][j+1]+=dp[i][j];
        }
        for(int j=A;j<=B;j++){
            int ans=1,rem=N-i;
            REP(k,D+1){
                if(i+j*k>N)break;
                ans*=nCk(rem,j);
                ans%=mod;
                rem-=j;
                if(k>=C){
                    dp[i+j*k][j+1]+=dp[i][j]*ans%mod*mod_pow(perm[k],mod-2)%mod;
                    dp[i+j*k][j+1]%=mod;
                }
            }
        }
    }
    int ans=0;
    rep(i,N+2){
        //cout<<dp[N][i]<<endl;
        ans+=dp[N][i]%mod;
    }
    cout<<ans%mod<<endl;
}

Measured memory_bytes: 16000
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
using namespace std;

int main()
{
    int a, b, c;
    
    cin >> a >> b >> c;
    
    if((a+b==c)||(b+c==a)||(c+a==b)) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
W,a,b = map(int,input().split())
count = 0

if a <= b:
    while True:
        if a + W + count >= b:
            print(count)
            break
        else:
            count += 1

if a > b:
    while True:
        if a <= b + W + count:
            print(count)
            break
        else:
            count += 1


Measured memory_bytes: 2940
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_11_A: Graph

#include <cstdio>
#include <cstring>

int main()
{
  unsigned int n;
  std::scanf("%u", &n);

  int g[n][n];
  std::memset(g, 0, sizeof(g));

  unsigned int u, k, v;
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%u %u", &u, &k);
    for (auto j = 0u; j < k; ++j) {
      std::scanf("%u", &v);
      g[u-1][v-1] = 1;
    }
  }

  for (auto i = 0u; i < n; ++i) {
    const char* sep = "";
    for (auto j = 0u; j < n; ++j) {
      std::printf("%s%d", sep, g[i][j]);
      sep = " ";
    }
    std::printf("\n");
  }
}

// eof

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

using i64 = long long int;

i64 acc[200005]={0};

int bsearch(int left, int right){
    int ub = right-1, lb = left+1;
    while(abs(ub-lb) > 1){
        int mid = (ub + lb) / 2;
        if((acc[right]-acc[mid])-(acc[mid]-acc[left]) > 0)lb = mid;
        else ub = mid;
    }
    if(abs((acc[right]-acc[ub])-(acc[ub]-acc[left])) < abs((acc[right]-acc[lb])-(acc[lb]-acc[left])))
        return ub;
    else return lb;
}

int main(){
    i64 n;
    cin >> n;
    vector<i64> v;
    for(int i=0;i<n;++i){
        i64 tmp;
        cin >> tmp;
        v.push_back(tmp);
        acc[i+1] = acc[i] + tmp;
    }

    i64 ans = LLONG_MAX;
    for(int middle=2;middle<n-1;++middle){
        int left = bsearch(0, middle), right = bsearch(middle, n);
        i64 maxi = acc[left], mini = acc[left];
        maxi = max(maxi, acc[middle]-acc[left]); mini = min(mini, acc[middle]-acc[left]);
        maxi = max(maxi, acc[right]-acc[middle]); mini = min(mini, acc[right]-acc[middle]);
        maxi = max(maxi, acc[n]-acc[right]); mini = min(mini, acc[n]-acc[right]);
        ans = min(ans, abs(maxi-mini));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3444
#include <iostream>
#include <cstring>
using namespace std;
char S[305];
int N, K;
int DP[305][305][305];
int Prev[305][305];
int Next[305][305];
void Read()
{
    cin.getline(S + 1, 305);
    N = strlen(S + 1);
    cin >> K;
}

void Solve()
{
    for(int i = 1; i <= N; i++)
    {
        for(int j = 0; j <= N; j++)
            DP[i][i][j] = 1, Next[i][j] = 1, Prev[i][j] = 1;

    }
    for(int i = 1; i < N; i++)
    {
        if(S[i] == S[i + 1])
            DP[i][i + 1][0] = 2;
        else
        {
            DP[i][i + 1][0] = 1;
            DP[i][i + 1][1] = 2;
        }
        for(int j = 1; j <= N; j++)
            DP[i][i + 1][j] = 2, Next[i][j] = 2, Prev[i + 1][j] = 2;
        Next[i][0] = max(Next[i][0], DP[i][i + 1][0]);
        Prev[i + 1][0] = max(Prev[i + 1][0], DP[i][i + 1][0]);
    }
    for(int dist = 3; dist <= N; dist++)
    {
        for(int i = 1; i + dist - 1 <= N; i++)
        {
            int j = i + dist - 1;
            for(int k = 0; k <= N; k++)
            {
                DP[i][j][k] = max(Next[i][k], Prev[j][k]);
                if(S[i] == S[j])
                    DP[i][j][k] = max(DP[i][j][k], DP[i + 1][j - 1][k] + 2);
                else
                    if(k > 0)
                        DP[i][j][k] = max(DP[i][j][k], DP[i + 1][j - 1][k - 1] + 2);
                Prev[j][k] = max(Prev[j][k], DP[i][j][k]);
                Next[i][k] = max(Next[i][k], DP[i][j][k]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i <= K; i++)
        ans = max(ans, DP[1][N][i]);
    cout << ans << "\n";
}
int main()
{
    Read();
    Solve();
    return 0;
}


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

using namespace std;
  
stack<double> s;
  
double calc(string str)
{
    double x = s.top();
    s.pop();
    double y = s.top();
    s.pop();
      
    switch (str[0]) {
        case '+':
            return x + y;
        case '-':
            return y - x;
        case '*':
            return x * y;
    }
    return y / x;
}
  
void solve()
{
    string str, a;
      
    while (getline(cin, str)) {
	stringstream ss(str);
	while (ss >> a) {
	    if (a == "+" || a == "-" || a == "*" || a == "/") {
		s.push(calc(a));
	    }
	    else{
		s.push(atof(a.c_str()));    
	    }
	}
	printf("%.6f\n" ,s.top());
    }
}
 
int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
// #pragma GCC optimization ("O3,unroll-loops")
// #pragma GCC target ("avx,avx2,fma")
using namespace std;

#define _ << ": " <<
#define watch1(var1) (cerr << (#var1) _ var1 << '\n')
#define watch2(var1, var2) cerr << (#var1) _ var1 << ", " << (#var2) _ var2 << '\n'
#define watch3(var1, var2, var3) cerr << (#var1) _ var1 << ", " << (#var2) _ var2 << ", " << (#var3) _ var3 << '\n'
#define wloop(size, arr) cerr << (#arr) << ": "; for (int i = 0; i < size; i++) cerr << arr[i] << " \n"[i+1 == size]

template<typename... Args>
void read(Args&... args) { ((cin >> args), ...); }

template<typename... Args>
void show(Args... args) { ((cout << args << " "), ...); }

#define ints(a...) int a; read(a)
#define longs(a...) int64_t a; read(a)
#define IN(a) for (auto &it : a) cin >> it

void solve() {
    ints(n);
    vector<int> v(n); IN(v);
    int res = 0;
    for (int i = 0; i < n; i++) res ^= v[i];
    for (int i = 0; i < n; i++) cout << (res ^ v[i]) << " \n"[i + 1 == n];
}

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

Measured memory_bytes: 3996
#include<iostream>
#include<queue>

using namespace std;

int main(){
    long long n, t,nn,sum;
    priority_queue<long long, vector<long long>, less<long long>> a;
    while(cin>>n>>t){
        sum = 0;
        for (long long i = 0; i < n;i++){
            cin >> nn;
            a.push(nn);
        }
        while(t!=0){
            nn = a.top();
            nn /= 2;
            a.pop();
            a.push(nn);
            t--;
        }
        while(a.size()){
            sum += a.top();
            a.pop();
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1400
K = int(input())
A = 7 % K
X = 7 % K
n = 1
f = 0
while A != 0:
  X = (X * 10) % K
  A = (A + X) % K
  n += 1
  if n > K:
    print(-1)
    f = 1
    break
if f == 0:
  print(n)

Measured memory_bytes: 9180
N, K = gets.strip.split(' ').map(&:to_i)

result = []
(1..N).each do |dice|
  count = 0
  point = dice
  while point < K do
    point = point * 2
    count += 1
  end
  result << (1 / N.to_f) * 0.5 ** count
end

puts result.inject(&:+)


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

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

    int right = 0;
    long long ans = 0;
    int sum = 0;

    for(int left=0; left<N; left++){
        while(right < N && (sum + A[right] == (sum ^ A[right]))){
            sum += A[right];
            right++;
        }

        ans += right - left;
        if(left == right) right++;
        else sum -= A[left];
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int a[200020];

int main() {
    int n;
    ll k;
    cin>>n>>k;
    rep(i,n) {
        cin>>a[i];
        a[i]--;
    }
    map<int,int> ma;
    vector<int> ord;
    int now = 0,cnt=1;
    ma[0]=1;
    ord.push_back(0);
    int start,end;
    while(1) {
        if(ma[a[now]]) {
            start = ma[a[now]];
            end = cnt+1;
            break;
        } else {
            cnt++;
            ma[a[now]] = cnt;
            ord.push_back(a[now]);
            now = a[now];
        }
    }
    // for(auto n:ord) {
    //     cout<<n<<endl;
    // }
    if(k<start) {
        cout<<ord[k]+1<<endl;
    } else {
        int num = (k-start+1)%(end-start);
        // cout<<num<<" st "<<start<<" end "<<end<<endl;
        cout<<ord[start -1 + num]+1<<endl;
    }
}

Measured memory_bytes: 13748
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  string s;
  cin>>s;
  int ans=0,x=0,i;
  for(i=0;s[i]!='\0';i++)
  {
    if(s[i]=='A' || s[i]=='T' || s[i]=='G' || s[i]=='C')
      x++;
    else
      x=0;
    ans=max(ans,x);
  }
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#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;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<int> p(N),s_p(N);
    REP(i,N){
        cin>>p[i];
        s_p[i] = p[i];
    }
    VSORT(s_p);
    int cnt=0;
    REP(i,N){
        if(p[i]!=s_p[i]) cnt++;
    }
    if(cnt<=2) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int function(int x){
	return x * x;
}

int main(void){
	int d,s,i,w;
	while(scanf("%d", &d) != EOF){
		w = d;
		s = 0;
		for(i = 2; i * d <= 600; i++){
			s += d * function(w);
			w = i * d;
		}
		printf("%d\n", s);
	}
	
	return 0;
}

Measured memory_bytes: 596
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		UINT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

int main()
{
	ll X = 0;
	ll Y = 0;
	ll ret = - 1;

	cin >> X >> Y;

	if ( X > Y ) {
		if ( X % Y == 0 ) {
			ret = -1;
		}
		else {
			ret = X;
		}
	}
	else if ( X < Y ) {
		ret = X;
	}
	else {
		ret = -1;
	}

	cout << ret << endl;

	return 0;
}





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

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

using namespace std;

using int64 = int64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, n;
  cin >> h >> n;
  const int INF = (int)1e9;
  vector<int> dp(h + 1, INF);
  dp[0] = 0;
  while (n--) {
    int a, b;
    cin >> a >> b;
    for (int i = 0; i <= h; i++) {
      int j = min(i + a, h);
      dp[j] = min(dp[j], dp[i] + b);
    }
  }
  cout << dp[h];
  return 0;
}

Measured memory_bytes: 3676
#define DEBUG
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	set<tuple<int,int,int>>mita;
	priority_queue<pair<llint,tuple<int,int,int>>> que;
	
	llint h,i,j,X,Y,Z,K;cin>>X>>Y>>Z>>K;
	vector<llint>A(X);for(i=0;i<X;i++){cin>>A[i];}SO(A);REV(A);A.pub(-big);
	vector<llint>B(Y);for(i=0;i<Y;i++){cin>>B[i];}SO(B);REV(B);B.pub(-big);
	vector<llint>C(Z);for(i=0;i<Z;i++){cin>>C[i];}SO(C);REV(C);C.pub(-big);
	que.push(mp(A[0]+B[0]+C[0],mt(0,0,0)));
	while(K--){
		auto aaa=que.top();que.pop();
		if(mita.count(aaa.sec)){K++;continue;}
		else{mita.ins(aaa.sec);}
		cout<<aaa.fir<<endl;
		int a,b,c;
		tie(a,b,c)=aaa.sec;
		que.push(mp(A[a+1]+B[b]+C[c],mt(a+1,b,c)));
		que.push(mp(A[a]+B[b+1]+C[c],mt(a,b+1,c)));
		que.push(mp(A[a]+B[b]+C[c+1],mt(a,b,c+1)));
	}
	
}

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

int main(void){
   int x,n;
   cin >> x >> n;
   int p[n],num[1000] = {};
   for(int i = 0;i < n;i++){
       cin >> p[i];
       num[p[i]]++;
   }
   int ans = -1;
   
   for(int i = -250;i <= 250;i++){
       if(num[i] == 0){
           if(abs(ans-x) > abs(i-x))ans = i;
           else if(abs(ans-x) == abs(i-x))ans = min(ans,i);
       }
   }
   if(n == 0)ans = x;
   cout << ans << endl;
}

Measured memory_bytes: 3640