akhauriyash/Code-Regression huggingface dataset:
/*AOJ 0012*/

#include<iostream>
using namespace std;

class Line_obj{
public:
	double x1,x2,y1,y2;

	void set(double sx1,double sx2,double sy1,double sy2){
		x1 = sx1;
		x2 = sx2;
		y1 = sy1;
		y2 = sy2;
	}

	int isUpDown(double x3,double y3){

		if( (x1-x2)*(y3-y1)+(y1-y2)*(x1-x3)>0){
			return 1;
		}
		else if( (x1-x2)*(y3-y1)+(y1-y2)*(x1-x3)<0){
			return -1;
		}
		else{
			return 0;
		}
	}

};

int main(){

	Line_obj line1,line2,line3;

	double x1,y1,x2,y2,x3,y3,xp,yp,xh,yh;

	while(cin>>x1){
		cin>>y1;
		cin>>x2;
		cin>>y2;
		cin>>x3;
		cin>>y3;
		cin>>xp;
		cin>>yp;

		line1.set(x1,x2,y1,y2);
		line2.set(x1,x3,y1,y3);
		line3.set(x2,x3,y2,y3);

		xh = (x1+x2+x3)/3.0;
		yh = (y1+y2+y3)/3.0;

		if( line1.isUpDown(xp,yp)*line1.isUpDown(xh,yh)<0 ||
			line2.isUpDown(xp,yp)*line2.isUpDown(xh,yh)<0 ||
			line3.isUpDown(xp,yp)*line3.isUpDown(xh,yh)<0){
				cout<<"NO"<<endl;
		}

		else{
			cout<<"YES"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
use std::collections::*;
use std::io::*;
use std::*;
macro_rules! get {
    ($($t:tt),*; $n:expr) => {
        {
            let stdin = std::io::stdin();
            let ret = std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
                let line = line.unwrap();
                let mut it = line.split_whitespace();
                _get!(it; $($t),*)
            }).collect::<Vec<_>>();
            ret
        }
    };
    ($($t:tt),*) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut it = line.split_whitespace();
            _get!(it; $($t),*)
        }
    };
}
macro_rules! _get {
    // iterator(splitted input-string) => iterator(output-type)
    ($it:ident; [char]) => {
        _get!($it; String).chars().collect::<Vec<_>>()
    };
    ($it:ident; usize1) => {
        $it.next().unwrap().parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
    };
    ($it:ident; [usize1]) => {
        $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
    };
    ($it:ident; [$t:ty]) => {
        $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
    };
    ($it:ident; $t:ty) => {
        $it.next().unwrap().parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
    };
    ($it:ident; $($t:ty),+) => {
        ($(_get!($it; $t)),*)
    };
}
fn run_length_encoding(s: &str) -> Vec<(char, i32)> {
    let mut res: Vec<(char, i32)> = Vec::new();
    s.chars().for_each(|c| match &mut res.last_mut() {
        Some(t) => {
            if c == t.0 {
                t.1 += 1;
            } else {
                res.push((c, 1));
            }
        }
        None => res.push((c, 1)),
    });
    res
}

fn main() {
    let n = get!(i32);
    let s = get!(String);
    let rle = run_length_encoding(&s);
    println!("{}", rle.len());
}


Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9 + 7, INF = 1e18;
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;}



signed main(){
	int N;
	cin >> N;
	cout<<N*N*N<<endl;
}

Measured memory_bytes: 764
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
	int x,s;
	cin>>x>>s;
	int cnt=0;
	for(int i=0; i<=x; i++)
	{
		for(int j=0; j<=x; j++)
		{
			int k=s-i-j;
			if(k>=0 && k<=x) cnt++;
//			cout<<i<<' '<<j<<' '<<k<< endl;
		}
	}
	
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 3460
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[][] s = new int[N][2];
        for(int i = 0; i < N; i++){
            s[i][0] = sc.nextInt();
            s[i][1] = sc.nextInt();
        }
        Arrays.sort(s ,(x, y) -> y[1] - x[1]);
        int[] count = new int[N+1];
        long ans = 0;
        long sum = 0;
        long kind = 0;
        // 美味しさが大きいほうからK個選択したときの得点を計算
        for(int i = 0; i < K; i++){
            sum += s[i][1];
            count[s[i][0]]++;
            if(count[s[i][0]] ==1){
                kind++;
            }
        }
        ans = sum + kind * kind;
        // 既に選択済みのスシの中から次に入れ替える候補の添え字
        int idx = K-1;
        // まだ選ばれていないスシのうち、種類数が減らないように未選択の種類のスシを入れ替えていく
        for(int i = K; i < N; i++){
            // 既に選択済みのスシは入れ替えてもマイナスなので入れ替えない
            if(count[s[i][0]] >0) continue;
            while (idx >= 0) {
                // 選択済みのうち交換すると種類が減ってしまうスシの場合は交換しない
                if (count[s[idx][0]] == 1) {
                    idx--;
                    continue;
                }
                count[s[i][0]] = 1;
                count[s[idx][0]]--;
                kind++;
                sum = sum + s[i][1] - s[idx][1];
                ans = Math.max(ans, sum + kind * kind);
                idx--;
                break;
            }
        }

        System.out.println(ans);
        sc.close();
    }

}


Measured memory_bytes: 95008
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
typedef long long ll;
const int N=2e5+10;
vector<int>G[N];
int n,col[N],cnt[N],all;
ll ans[N],sz[N];
ll dfs(int u,int fa)
{
    ll tmp=cnt[col[u]];//保存其他树的cnt
    sz[u]=1;
    for(int v:G[u]){
        if(v==fa) continue;
        ll l=all-cnt[col[u]];//子树前
        sz[u]+=dfs(v,u);
        ll r=all-cnt[col[u]];//遍历子树后
        ll len=r-l;
        ans[col[u]]-=(len*(len-1)/2);
    }
    cnt[col[u]]=tmp+sz[u];//每次col[u]的颜色  重新被当前u全部覆盖
    all++;
    return sz[u];
}
int main()
{
    scanf("%d",&n);
    rep(i,1,n) scanf("%d",&col[i]);
    rep(i,2,n)
    {
        int u,v;scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
 
 
 
    rep(i,1,n) ans[i]=1ll*n*(n-1)/2;//所有路径
    dfs(1,-1);
    for(int i=1;i<=n;++i){//除了子树，从根节点到最近的颜色 联通块也要去掉
        //printf("i:%d cnt:%d ans:%lld\n",i,cnt[i],ans[i]);
        ll len=n-cnt[i];
        ans[i]-=(len*(len-1)/2);
    }
    for(int i=1;i<=n;++i) ans[col[i]]++;//每个单独的点是一条路径
    for(int i=1;i<=n;++i) printf("%lld\n",ans[i]);
}

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

ll solve() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) cin >> A[i];
    for ( int i = K; i < N; i++ ) {
        if ( A[i-K] < A[i] ) cout << "Yes";
        else cout << "No";
        cout << "\n";
    }
    return 0;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 4832
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int l, r, d;
	cin >> l >> r >> d;
	
	cout << r / d - (l - 1) / d << endl;
	
	return 0;
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);

		int[] A = new int[7];
		int n, a, b;
		
		for(int i = 0; i < 6; i++)
			A[i] = input.nextInt();

		n = input.nextInt();

		for( int i = 0; i < n; i++)
		{
			a = input.nextInt();
			b = input.nextInt();
			System.out.println(dice(a, b, A));
		}
	}

	private static int dice(int a, int b, int A[])
	{
		int ret = 0;
		if( a == A[0])
		{
			if( b == A[1])
				ret = A[2];
			else if( b == A[2])
				ret = A[4];
			else if( b == A[4])
				ret = A[3];
			else if( b == A[3])
				ret = A[1];
		}

		else if( a == A[1])
		{
			if( b == A[0])
				ret = A[3];
			else if( b == A[3])
				ret = A[5];
			else if( b == A[5])
				ret = A[2];
			else if( b == A[2])
				ret = A[0];
		}		

		else if( a == A[2])
		{
			if( b == A[0])
				ret = A[1];
			else if( b == A[1])
				ret = A[5];
			else if( b == A[5])
				ret = A[4];
			else if( b == A[4])
				ret = A[0];
		}		

		else if( a == A[3])
		{
			if( b == A[0])
				ret = A[4];
			else if( b == A[4])
				ret = A[5];
			else if( b == A[5])
				ret = A[1];
			else if( b == A[1])
				ret = A[0];
		}		

		else if( a == A[4])
		{
			if( b == A[0])
				ret = A[2];
			else if( b == A[2])
				ret = A[5];
			else if( b == A[5])
				ret = A[3];
			else if( b == A[3])
				ret = A[0];
		}		

		else if( a == A[5])
		{
			if( b == A[1])
				ret = A[3];
			else if( b == A[3])
				ret = A[4];
			else if( b == A[4])
				ret = A[2];
			else if( b == A[2])
				ret = A[1];
		}
		return ret;
	}		
}

Measured memory_bytes: 26212
#include<iostream>
using namespace std;
int main(){
  int c,n;
  for(;;){
    cin>>n;
    if(n==0)
      break;
    c=0;
    while(n){
      n/=5;
      c+=n;
    }
    cout<<c<<endl;
  }
  return 0;
}

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

int main() {
    int N; cin >> N;
    vector<long long> S(N + 1, 0);
    for(int i=0; i<N; ++i) cin >> S[i + 1], S[i + 1] += S[i];

    long long res = 1LL << 60;
    for(int m=2; m<=N-2; ++m) {
        long long p,q,r,s;
        long long X = S[m], Y = S[N] - S[m];
        auto it = upper_bound(begin(S) + 1, begin(S) + 1 + m, X / 2);
        long long l1 = *(it - 1), l2 = *it;
        if(abs(X - 2 * l1) < abs(X - 2 * l2)) {
            p = l1, q = X - l1;
        } else {
            p = l2, q = X - l2;
        }

        it = upper_bound(begin(S) + 1 + m, end(S), X + (Y / 2));
        l1 = *(it - 1) - X, l2 = *it - X;
        if(abs(Y - 2 * l1) < abs(Y - 2 * l2)) {
            r = l1, s = Y - l1;
        } else {
            r = l2, s = Y - l2;
        }

        res = min(res, max({p,q,r,s}) - min({p,q,r,s}));
    }
    cout << res << endl;
}

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

int main (){
  int N,d=1000;
  cin >> N;
  for (int i=0;i<N;i++){
    int a,b,c=0;
    cin >> a;
    b=a%2;
    while (b==0){
      c++;
      a /=2;
      b=a%2;
    }
    if (d>c){
      d=c;
    }
  }
  cout << d<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

// {x, y, h}
vector<tuple<int, int, int>> points;

bool check(const int cand_x, const int cand_y, const int cand_h, const int N) {
    for (int i = 0; i < N; i++) {
        int x, y, h;
        tie(x, y, h) = points[i];
        if (max(cand_h - abs(x - cand_x) - abs(y - cand_y), 0) != h) {
            return false;
        }
    }
    return true;
}


// {x, y, h}
tuple<int, int, int> solve(const int N) {
    for (int cand_y = 0; cand_y <= 100; cand_y++) {
        for (int cand_x = 0; cand_x <= 100; cand_x++) {
            vector<int> hs;
            for (int i = 0; i < N; i++) {
                int x, y, h;
                tie(x, y, h) = points[i];
                if (h == 0) continue;
                hs.push_back(h + abs(x - cand_x) + abs(y - cand_y));
            }

            bool ok = true;
            for (int i = 1; i < (int) hs.size(); i++) {
                if (hs[i] != hs[i - 1]) {
                    ok = false;
                    break;
                }
            }

            if (ok) {
                int cand_h = hs[0];
                if (check(cand_x, cand_y, cand_h, N)) {
                    return tie(cand_x, cand_y, hs[0]);
                }
            }
        }
    }

    int _x = -1, _y = -1, _z = -1;
    return tie(_x, _y, _z);
}

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

    points.resize(N);
    for (int i = 0; i < N; i++) {
        int x, y, h;
        cin >> x >> y >> h;
        points[i] = tie(x, y, h);
    }

    tuple<int, int, int> center = solve(N);
    {
        int x, y, h;
        tie(x, y, h) = center;
        cout << x << " " << y << " " << h << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    int A[100000];
    for(int i=0;i<N;i++)
        cin >> A[i];
    
    // 昇順ソート
    sort(A, A + N);
    int min = A[0], index = 0;
    while(A[N-2] != 0){
        for(int i=0;i<N;i++){
            if(i != index)
                A[i] = A[i] % min;
        }
        // 昇順ソート
        sort(A, A + N);
        for(int i=0;i<N;i++){
            if(A[i] > 0){
                min = A[i];
                index = i;
                break;
            }
        }
    }
    
    for(int i=0;i<N;i++){
        if(A[i] > 0){
            cout << A[i] << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <functional>


#ifdef _DEBUG
#define typeof(X) std::identity<decltype(X)>::type //C++0x (for vs2010)
#else
#define typeof(X) __typeof__(X) // for gcc
#endif

using namespace std;
static const double EPS = 1e-6;
typedef long long ll;
const int MODULO = 1000000007;
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

int main(){
	int a = 0,b = 0;
	string s;
	map<int,int> m1,m2;
	while(getline(cin,s)){
		if(!~sscanf(s.c_str(),"%d,%d",&a,&b)) break;
		m1[a]++;
	}
	while(getline(cin,s)){
		if(!~sscanf(s.c_str(),"%d,%d",&a,&b)) break;
		m2[a]++;
	}
	for(map<int,int>::iterator it = m1.begin(); it != m1.end(); ++it){
		if(m2[(*it).first] == 0) continue;
		printf("%d %d\n",(*it).first,(*it).second + m2[(*it).first]);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

struct mypair{
    string forward;
    string back;
    mypair(){

    }
    mypair(string f,string b):forward(f),back(b){

    }

    bool operator < (const mypair &right)const{
        if(forward == right.forward){
            return back < right.back;
        }

        return forward < right.forward;
    }
        
    bool operator > (const mypair &right)const{
        if(forward == right.forward){
            return back > right.back;
        }

        return forward > right.forward;
    }
};


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

    LL N;
	cin >> N;

	string str;
	cin >> str;

    string prestr = str.substr(0,N);
    string sufstr = "";
    for(int i = 0; i < N; i++){
        sufstr += str[2*N-i-1];
    }

    vector<mypair> sufvec(1 << 18);
    vector<mypair> prevec(1 << 18);

    for(int i = 0; i < (1 << N); i++){
        LL ibit = 1;
        string pref = "";
        string preb = "";
        string suff = "";
        string sufb = "";
        int j = 0;
        while(ibit < (1 << N)){
            if(ibit == (ibit & i)){
                pref += prestr[j];
                suff += sufstr[j];
            }
            j++;
            ibit <<= 1;
        }
        ibit = (1 << (N-1));
        j = N-1;
        while(ibit > 0){
            if(ibit != (ibit & i)){
                preb += prestr[j];
                sufb += sufstr[j];
            }
            j--;
            ibit >>= 1;
        }
        prevec[i] = mypair(pref,preb);
        sufvec[i] = mypair(suff,sufb);
    }

    LL ans = 0;
    sort(sufvec.begin(),sufvec.end());

    for(int i = 0; i < (1 << N); i++){
        auto itrbegin = lower_bound(sufvec.begin(),sufvec.end(),prevec[i]);
        auto itrend = upper_bound(sufvec.begin(),sufvec.end(),prevec[i]);
        LL count = (LL)(itrend - itrbegin);
        ans += count;
    }

    cout << ans << endl;


    
    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

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

class Union_find{
private:
	vector<int32> par;
	int32 n;

public:
	Union_find(int32 n):n(n){
		par.resize(n, -1);
	}

	int32 find(int32 x){
		return par[x] < 0 ? x : par[x] = find(par[x]);
	}

	int32 size(int32 x){
		return -par[find(x)];
	}

	void unite(int32 x, int32 y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(size(x) < size(y)) swap(x, y);
		par[x] += par[y];
		par[y] = x;
	}

	bool same(int32 x, int32 y){
		return find(x) == find(y);
	}
};

const int64 mod = 1e9+7;

using Edge = tuple<int64, int64, int64>;
int64 N, M, Q;
int64 sum = 0;
vector<Edge> e;
vector<PLL> G[4040];
vector<int64> d;
int64 table[13][4040], maxi[13][4040];

void init(){
	d.resize(N);
	memset(table, -1, sizeof table);
	memset(maxi, -1, sizeof maxi);
	function<void(int32, int32, int32)> idfs = [&](int32 v, int32 p, int32 dep){
		d[v] = dep;
		table[0][v] = p;
		REP(i, G[v].size()){
			if(G[v][i].sc == p) continue;
			maxi[0][G[v][i].sc] = G[v][i].fs;
			idfs(G[v][i].sc, v, dep+1);
		}
	};
	idfs(0, -1, 0);
	REP(i, 12){
		REP(j, N){
			if(table[i][j] != -1){
				table[i+1][j] = table[i][table[i][j]];
				maxi[i+1][j] = max(maxi[i][j], maxi[i][table[i][j]]);
			}
		}
	}
}

int64 lca(int32 u, int32 v){
	if(d[u] < d[v]) swap(u, v);
	int64 res = 0;
	for(int32 i = 12;i >= 0;i--){
		if((d[u]-d[v]) >> i & 1){
			res = max(res, maxi[i][u]);
			u = table[i][u];
		}
	}
	if(u == v) return res;
	for(int32 i = 12;i >= 0;i--){
		if(table[i][u] != table[i][v]){
			res = max({res, maxi[i][u], maxi[i][v]});
			u = table[i][u];
			v = table[i][v];
		}
	}
	res = max({res, maxi[0][u], maxi[0][v]});
	return res;
}

int main(void){
	cin >> N >> M;
	REP(i, M){
		int64 a, b, c;
		cin >> a >> b >> c; a--; b--;
		e.push_back(Edge(c, a, b));
	}
	Union_find uf(N);
	sort(all(e));
	REP(i, e.size()){
		int64 u, v, c;
		tie(c, u, v) = e[i];
		if(uf.same(u, v)) continue;
		uf.unite(u, v);
		sum += c;
		G[u].push_back({c, v});
		G[v].push_back({c, u});
	}
	init();
	cin >> Q;
	REP(i, Q){
		int32 u, v;
		cin >> u >> v; u--; v--;
		int64 res = lca(u, v);
		cout << sum-res << endl;
	}
}

Measured memory_bytes: 14828
<?php

    // AtCoder Beginner Contest 163
    // B - Homework

    list($num_day, $m) = in_ints();
    $works = in_ints();

    $sum_work_day = array_sum($works);
    if ($num_day >= $sum_work_day) {
        out($num_day - $sum_work_day);
    } else {
        out('-1');
    }

    // -----------------------------------------------------
    function in() { return trim(fgets(STDIN)); }
    function in_int() { return (int)in(); }
    function in_vals() { return explode(' ', in()); }
    function in_ints() { return array_map('intval', in_vals()); }
    function out($s) { echo $s . PHP_EOL; }
    function yes() { out('Yes'); }
    function no() { out('No'); }


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

int main() {
  int n, W;
  cin >> n >> W;
  vector<int> w(n + 1), v(n + 1);
  for (int i = 1; i <= n; i++) cin >> w[i] >> v[i];
  vector<vector<long>> dp(n + 1, vector<long>(W + 1, 0));
  for (int i = 0; i < n; i++) {
    dp[i + 1] = dp[i];
    for (int j = 0; j + w[i + 1] <= W; j++)
      dp[i + 1][j + w[i + 1]] = max(dp[i][j + w[i + 1]], dp[i][j] + v[i + 1]);
  }
  cout << dp[n][W];
  return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>


const int MOD = 1000000007;
int main(){

   string s;
   cin >> s;
    bool f = false;
    char a = s[0];
   for(int i=0;i < 3;i++){
       if(s[0] != s[i]){
           f = true;
       }
       
   }
   if(f){
       cout << "Yes" << endl;

   }else{
       cout << "No" << endl;
   }
   
    
    
    
    return 0;
}

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

int main(void){

    int N, Pbuf;
    int res = 0;
    priority_queue<int, vector<int>, greater<int>> P;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> Pbuf;
        P.push(Pbuf);
        if(Pbuf == P.top())res++;
    }
    
    cout << res << endl;

    return 0;

}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
//In wrong answers we believe//
#define db 				double
#define ll 				long long int
#define ld				long long double
//#define int 			long long int
#define ull 			unsigned long long
#define vii 			vector <int>
#define vll 			vector < ll >
#define pii 			pair <int, int>
#define fi 				first
#define se 				second
#define rep(i,a,n)      for(int i=a;i<n;i++)
#define endl 			'\n'
#define mem(a,b) 		memset(a, b, sizeof a)
#define mkp 			make_pair
#define pb 				push_back
#define max3(a,b,c) 	max(a,max(b,c))
#define min3(a,b,c) 	min(a,min(b,c))
#define w(t)            int t; cin>>t; while(t--)
#define all(a)			a.begin(), a.end()
using namespace std;
db pi		 =			2*acos(0.0);
db eps       =			0.000001;
ll mod       =			(1e9+7);   //998244353
const ll INF =			1000000000000000LL;
void print(vector <int> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}
void printll(vector <ll> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}

ll ncr(ll n, ll r)
{
    r=min(r,n-r);
    ll A[r],i,j,B[r];
    iota(A,A+r,n-r+1);  
    iota(B,B+r,1);     

    ll g;
    for(i=0;i<r;i++)
    for(j=0;j<r;j++)
    {
        if(B[i]==1)
            break;
        g=__gcd(B[i], A[j] );
        A[j]/=g;
        B[i]/=g;
    }
    ll ans=1;
    for(i=0;i<r;i++)
        ans=(ans*A[i]%mod);
    return ans;
}
const int SIZE=100001;
bool judgePermutation(int a[], int n){
    static int used[SIZE+1];
    for(int i = 1; i <= n; i++) used[i] = 0;
    for(int i = 0; i < n; i++) used[a[i]] = 1;
    for(int i = 1; i <= n; i++) {
        if(!used[i]) return 0;
    }
    return 1;
}


int main(){	
//CONDITION && cout << "YES" || cout << "NO"; cout << '\n';
//////////////////////////////////////////////////////////////////////
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cerr.tie(NULL);
//For fast IO
///////////////////////////////////////////////////////////////////// 
//  std::cout.unsetf ( std::ios::floatfield );  // floatfield not set
//  std::cout.precision(10);
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	ll x;
	cin>>x;
	ll a=100,day=0;
	while(a<x){
		a*=1.01;
		day++;
	}
	cout<<day<<endl;
	return 0;
    
    }

Measured memory_bytes: 3656
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
import itertools
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    x, n = map(int, input().split())
    p = {int(pi) for pi in input().split()}

    for i in itertools.count():
        if (x - i) not in p:
            print(x - i)
            break
        if (x + i) not in p:
            print(x + i)
            break


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


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

typedef long long ll;
typedef pair<int,int> pii;
#define p_queue priority_queue
#define INF 2147483647

int read() {
	int xx=0,ww=1;
	char ch=getchar();
	while(ch>'9'||ch<'0') {
		if(ch=='-') ww=-ww;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		xx=10*xx+ch-48;
		ch=getchar();
	}
	return xx*ww;
}

int a,b,k;

int main() {
	a=read(),b=read(),k=read();
	for(int i=1; i<=k; ++i) {
		if(i%2==1) {
			if(a%2==1) --a;
			b+=a/2;
			a/=2;
		} else {
			if(b%2==1) --b;
			a+=b/2;
			b/=2;
		}
	}
	printf("%d %d\n",a,b);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<ll,ll>mp;
ll a[2000005];
int main()
{
    // Ai+Aj = j-i equivalent to Ai+i= j-Aj
    ll n;
    cin >> n;
    for(ll i=1;i<=n;i++)
    {
        cin >> a[i];
        mp[a[i]+i]++;
    }
    ll ans=0;
    for(ll j=1;j<=n;j++)
    {
        ans+=mp[j-a[j]];
    }
    cout << ans << endl;
}


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

int main(void) {
  int N;
  cin >> N;
  int mode = 0;  // 0: not determin, 1: ascending, 2: descending
  int answer = 1;
  int P;
  cin >> P;
  for (int i = 1; i < N; ++i) {
    int C;
    cin >> C;
    if (mode == 0) {
      if (P < C)
        mode = 1;
      else if (P > C)
        mode = 2;
    } else if (mode == 1) {
      if (P > C) {
        answer++;
        mode = 0;
      }
    } else {
      if (P < C) {
        answer++;
        mode = 0;
      }
    }
    P = C;
  }
  cout << answer << endl;
  return 0;
}

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

#define ran 22

int n;
vector<pair<int, int> > v[ran];

bool chk(int mask) {
	bool honest[22];
	for(int i=1;i<=n;i++)
		honest[i] = ((mask & (1<<(i-1))) > 0);
	for(int i=1;i<=n;i++) {
		if (!honest[i]) continue;
		for(int j=0;j<v[i].size();j++)
			if(honest[v[i][j].first] != v[i][j].second) return false;
	}
	return true;
}

int main() {
	scanf("%d", &n);
	for(int i=1;i<=n;i++) {
		int x;
		scanf("%d", &x);
		for(int j=0;j<x;j++) {
			int id, val;
			scanf("%d%d", &id, &val);
			v[i].push_back(make_pair(id, val));
		}
	}
	
	int ans = 0;
	for(int mask=0;mask<(1<<n);mask++)
		if(chk(mask)) ans = max(ans, __builtin_popcount(mask));
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main(){
	int x, y, a, b, c, c1;
	vector<int> a1, b1;
	vector<int> ans;
	long long ans1 = 0;
	cin >> x >> y >> a >> b >> c;
	for (int i = 0; i < a; i++) {
		int a2;
		cin >> a2;
		a1.emplace_back(a2);
	}
	for (int j = 0; j < b; j++) {
		int b2;
		cin >> b2;
		b1.emplace_back(b2);
	}
	for (int k = 0; k < c; k++) {
		cin >> c1;
		ans.emplace_back(c1);
	}
	sort(a1.begin(), a1.end());
	sort(b1.begin(), b1.end());
	for (int i = a - 1; i >= max(0,a - x); i--) {
		ans.emplace_back(a1[i]);
	}
	for (int j = b - 1; j >= max(0,b - y); j--) {
		ans.emplace_back(b1[j]);
	}
	sort(ans.begin(), ans.end());
	for (int k = ans.size() - 1; k >= ans.size() - x - y; k--) {
		ans1 += ans[k];
	}
	cout << ans1 << endl;
	return 0;
}

Measured memory_bytes: 3188
import sys, collections
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = I()

    def sieve(n):
        is_prime = [True for _ in range(n+1)]
        is_prime[0] = False
        is_prime[1] = False
        for i in range(2, int(n**0.5)+1):
            if is_prime[i]:
                for j in range(i*2, n+1, i):
                    is_prime[j] = False
        return [i for i in range(n+1) if is_prime[i]]

    primes = sieve(int(N**0.5))

    ans = []
    temp = N
    for i in primes:
        j = i
        while j<int(N**0.5)+1:
            if temp%j == 0:
                ans.append(j)
                temp //= j
            j *= i
    if temp > int(N**0.5):
        ans.append(temp)

    # print(ans)
    print(len(ans))

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 20592
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int main(){

    int N,K,A,ans=0;
    cin>>N>>K;

    for(int i=1;i<=N;i++){
        cin>>A;
        if(A>=K)ans++;
    }

    cout<<ans<<endl;

    return 0;
}

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

int main(){
  int n;
  string s1, s2;
  int a = 0, b = 0;
  cin >> n;
    
    for ( int i = 0; i < n; i++ ){
      cin >> s1 >> s2;
      if ( s1 > s2 ) a+=3;
      else if ( s1 < s2 ) b+=3;
          else {
        a++; b++;
      }
    }
   cout << a << " " << b << endl; 
        
    

 return 0;
}    

Measured memory_bytes: 1208
/*
  #問題：
  


  #分析：
  #オブジェクト：
  
  #条件：
  

  #要求：
  

  #解法：
  
*/

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

using namespace std;

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

  if(b>=a){
    cout<<a<<endl;
  }else{
    cout<<a-1<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100 
#define WHITE 0
#define GRAY  1
#define BLACK 2
#define NIL -1
int n;
int M[MAX][MAX];


void dik()
{
  int i;
  int v;
  int min;
  int d[MAX];
  int color[MAX];
  int u;

  for( i = 0 ; i < n ; i ++ ){
    d[i] = 10000000;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;

  while(1){
    min = 10000000;
    u = NIL;
    for( i = 0 ; i < n ; i++ ){
      if( min > d[i] && color[i] != BLACK ){
	u = i;
	min = d[i];
      }
    }
    if( u == NIL )break;
    color[u] = BLACK;
    for( v = 0 ; v < n ; v++ ){
      if( color[v] != BLACK && M[u][v] != 10000000){
	if( d[v] > d[u] + M[u][v] ){
	  d[v] = d[u] + M[u][v];
	  color[v] = GRAY;
	}
      }
    }
  }
  for( i = 0 ; i < n ; i++ ){
    printf("%d ",i);
    if( d[i] == 10000000 )printf("-1\n");
    else printf("%d\n",d[i]);
  }
}

int main()
{
  int i;
  int j;
  int m;
  int u,v;
  int c;
  
  
  scanf("%d",&n);
  for( i = 0 ; i < n ; i++ ){
    for( j = 0 ; j < n ; j++ ){
      M[i][j] = 1000000;
    }
  }

  for( i = 0 ; i < n ; i++ ){
    scanf("%d%d",&u,&m);
    for( j = 0 ; j < m ; j++ ){
      scanf("%d%d",&v,&c);
      M[u][v] = c;
    }
  }

  dik();

  return 0 ;
}
  



Measured memory_bytes: 2052
#include<bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;
const int N=1e6;
const int P=1e9+7;
int f[N];
int inv[N];
int qpow(int a,int b){
	int res=1;
	for(;b;b>>=1){
		if(b&1){
			res=1ll*res*a%P;
		}
		a=1ll*a*a%P;
	}
	return res;
}
signed main()
{
	int n,a,b;
	cin>>n>>a>>b;
	int ans=qpow(2,n)-1;
	int C=1;
	for(int i=0;i<a;i++){
		C=1ll*C*(n-i)%P*qpow(i+1,P-2)%P;
	}
	ans-=C;
	C=1;
	for(int i=0;i<b;i++){
		C=1ll*C*(n-i)%P*qpow(i+1,P-2)%P;
	}
	ans-=C;
	ans%=P;
	ans=(ans+P)%P;
	cout<<ans;
}

Measured memory_bytes: 256
n = gets.to_i
arr = gets.chomp.split.map(&:to_i)
m = gets.to_i
arr2 = gets.chomp.split.map(&:to_i)
arr3 = gets.chomp.split.map(&:to_i)
h = Hash.new(0)
arr.each{|x| h[x] += 1}
m_max = arr2.max
arr4 = Array.new(m_max + 1, 0)
h.each{|k, v| arr4[k] = k * v if k <= m_max}
1.upto(arr4.length - 1){|i| arr4[i] += arr4[i - 1]}
0.upto(m - 1){|i| puts (arr4[arr2[i]] >= arr3[i] ? "Yes" : "No")}


Measured memory_bytes: 74192
package main

import (
    "bufio"
    "fmt"
    "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)
    w := nextInt()
    h := nextInt()
    x := nextInt()
    y := nextInt()
    r := nextInt()
    if x - r < 0 || x + r > w {
      fmt.Println("No")
    } else if y - r < 0 || y + r > h {
      fmt.Println("No")
    } else {
      fmt.Println("Yes")
    }
}


Measured memory_bytes: 1112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
vector<pair<string,ll>> v[50];
void step(ll x){
    if(x==1){
        v[x].push_back({"a",1});
        return;
    } else {
        for(ll i=0;i<v[x-1].size();i++){
            for(ll j=0;j<=v[x-1][i].second;j++){
                string a; char b;
                a=v[x-1][i].first;
                b='a'+j;
                a=a+b;
                if(j==v[x-1][i].second) v[x].push_back({a,j+1});
                else v[x].push_back({a,v[x-1][i].second});
            }
        }
    }
}

int main() {
    // your code goes here
    ll n;
    cin >> n;
    rep(is,1,n) step(is);
    for(ll i=0;i<v[n].size();i++) cout << v[n][i].first << endl;
    return 0;
}

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

int gcd(ll a,ll b){
  if (a%b == 0)return(b);
  else return(gcd(b,a%b));
}

int main(){
  int k;
  int flag;
  ll total=0;
  cin>>k;

  if(k==1){
    cout<<1<<endl;
    return 0;
  }
  if(k==2){
    cout<<9<<endl;
    return 0;
  }
  //全部同じ数字
  for(int i=1;i<=k;i++){
    total+=i;
  }


  //2つ同じ数字の時
  for(int i=1;i<=k;i++){
    for(int j=i+1;j<=k;j++){
      int s =gcd(i,j);
      total += (s*6);

    }
  }

  //全部数字が違うとき
  for(int i=1;i<=k;i++){
    for(int j=i+1;j<=k;j++){
      for(int l=j+1;l<=k;l++){
        int  x = gcd(i,j);
        int  y = gcd(x,l);
        total+=(6*y);
      }
    }
  }
  cout<<total<<endl;
}


Measured memory_bytes: 3644
#include<iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;

struct node
{
    int num,next;
};

node e[400011];
int edge[100011];
int taile;

void add(int xx,int yy)
{
    e[taile].num=yy;
    e[taile].next=edge[xx];
    edge[xx]=taile++;
}

int cover[100011];



int n,m;
long long ans0[3];
long long ans1[3];
long long ans;
int st;
int num;
void dfs(int now,int fa,int col)
{
    cover[now]=col;
    num++;
    int i;
    
    for(i=edge[now];i!=-1;i=e[i].next)
    {
        if(e[i].num!=fa)
        {
            if(st==0)st=1;
            
            if(cover[e[i].num]==0)
            {
                dfs(e[i].num,now,3-col);
            }
            else
            {
                if(cover[e[i].num]==col)
                {
                    st=2;
                }
            }
        }
    }
    return ;
}

int main()
{
    int i,j,k;
    int xx,yy;
    memset(edge,-1,sizeof(edge));
    taile=1;
    
    scanf("%d %d",&n,&m);
    
    for(i=1;i<=m;i++)
    {
        scanf("%d %d",&xx,&yy);
        add(xx,yy);
        add(yy,xx);
    }
    
    memset(cover,0,sizeof(cover));
    ans=0;
    memset(ans0,0,sizeof(ans0));
    memset(ans1,0,sizeof(ans1));
    
    for(i=1;i<=n;i++)
    {
        if(cover[i]==0)
        {
            st=0;num=0;
            dfs(i,-1,1);
            
            ans0[st]++;
            ans1[st]+=num;
            
        }
    }
    
    //cout<<ans0[0]<<' '<<ans0[1]<<' '<<ans0[2]<<endl;
    //cout<<ans1[0]<<' '<<ans1[1]<<' '<<ans1[2]<<endl;
    
    
    
    ans+=ans0[0]*ans0[0];
    
    ans+=ans0[0]*(ans1[1]+ans1[2])*2ll;
    ans+=ans0[1]*2ll;
    ans+=ans0[1]*(ans0[1]-1)*2ll;
    ans+=ans0[2];
    ans+=ans0[2]*(ans0[2]-1);
    ans+=ans0[1]*ans0[2]*2ll;
    
    
    cout<<ans<<endl;
    
    return 0;
} 


Measured memory_bytes: 6912
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace ABC175
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(" ");
            long X = long.Parse(input[0]);
            if (X < 0) { X *= -1; }
            long K = long.Parse(input[1]);
            long D = long.Parse(input[2]);

            if(X/D >= K)
            {
                Console.WriteLine(X - K * D);
            }
            else
            {
                long abs = 0;
                long cnt = 0;

                while(abs < X)
                {
                    abs += D;
                    cnt++;
                }
                if((K-cnt)%2 == 0)
                {
                    Console.WriteLine(abs - X);
                }
                else
                {
                    Console.WriteLine(D- (abs - X));
                }
            }

        }
    }
}


Measured memory_bytes: 27544
#include <iostream>
#include <queue>
#include <utility>
using namespace std;

int main()
{
	int x,y;
	
	while(cin>>x>>y&&x)
	{
		string m;
		for(int i=0;i<y;i++)
		{
			for(int l=0;l<x;l++)
			{
				string k;cin>>k;
				m+=k;
			}
		}
		typedef pair<string,int> psi;
		queue<psi> que;que.push(psi(m,0));
		while(!que.empty())
		{
			psi now=que.front();que.pop();
			
			{
				bool ok=true;
				for(int i=0;i<now.first.size();i++)if(now.first[i]!=now.first[0])ok=false;
				if(ok)
				{
					cout<<now.second<<endl;
					break;
				}
			}

			
			
			{
				char s[4]="RGB";
				for(int c=0;c<3;c++)
				{
					if(now.first[0]==s[c])continue;
					char b[20][20]={};
					for(int i=1;i<=y;i++)
					{
						for(int j=1;j<=x;j++)
						{
							b[i][j]=now.first[(i-1)*x+(j-1)];
						}
					}
					typedef pair<int,int> pii;
					queue<pii> Q;Q.push(pii(1,1));
					int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
					char ori=b[1][1];
					b[1][1]=s[c];
					while(!Q.empty())
					{
						pii g = Q.front();Q.pop();
						
						for(int i=0;i<4;i++)
						{
							if(b[g.first+dy[i]][g.second+dx[i]]==ori)
							{
								b[g.first+dy[i]][g.second+dx[i]]=s[c];
								pii next;
								next.first=g.first+dy[i];
								next.second=g.second+dx[i];
								Q.push(next);
							}
						}
					}
					
					psi next;
					next.second=now.second+1;
					for(int i=1;i<=y;i++)
					{
						for(int j=1;j<=x;j++)
						{
							next.first+=b[i][j];
						}
					}
					
					que.push(next);
				}
			}
			
			
		}
	}
	
}

Measured memory_bytes: 46640
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
  if(a%b == 0){
    return b;
  }else{
    return gcd(b, a%b);
  }
}
int gcd_arr(vector<int> &a){
  int n = a.size();
  for(int i=n-2; i>=0; i--){
    a[i] = gcd(a[i], a[i+1]);
  }
  return a.front();
}

int main(void){
    long long int i=0,j,c=0,n,m=0,ans=0,z=0;
    string s;
    cin >> n >> m;
    vector<int> x(n);
    for(i=0;i<n;i++)
    {
        cin >> x[i];
        x[i]=abs(m-x[i]);
    }
    c=gcd_arr(x);
    cout << c << endl;
    return 0;
}


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

int main() {
    string S;
    int rem;
    cin >> S;

    if(S == "SUN"){
        rem =7;
    }
    if(S == "MON"){
        rem =6;
    }
    if(S == "TUE"){
        rem =5;
    }
    if(S == "WED"){
        rem =4;
    }
    if(S == "THU"){
        rem =3;
    }
    if(S == "FRI"){
        rem =2;
    }
    if(S == "SAT"){
        rem =1;
    }

    cout << rem << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	ll N, x;
	cin >> N >> x;
	vector<ll> a(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> a[i];
	}

	vector<vector<ll>> m(N, vector<ll>(N));
	for (auto i = 0; i < N; ++i)
	{
		auto temp = LLONG_MAX;
		for (auto j = 0; j < N; ++j)
		{
			auto k = (i - j + N) % N;
			temp = min(temp, a[k]);
			m[i][j] = temp;
		}
	}

	auto result = LLONG_MAX;
	for (auto i = 0; i < N; ++i)
	{
		auto sum = 0ll;
		for (auto j = 0; j < N; ++j)
		{
			sum += m[j][i];
		}
		sum += x * i;
		result = min(result, sum);
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 31616
N = int(input())
A = map(int,input().split())
A_even = [i for i in A if i % 2 == 0]
baisuu = [i for i in A_even if i % 3 == 0 or i % 5 == 0]
if A_even == baisuu:
    print("APPROVED")
else:
    print("DENIED")


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

using namespace std;

// n を受け取って、0~n の総和を計算して返す関数
int sum(int n) {
  // 処理内容 : 0 ~ n の総和を計算する

  // ベースケース
  if (n == 0) {
    return 0;  // 再帰呼び出しをせずとも 0 という結果が確定している
  }

  // 再帰ステップ
  int s = sum(n - 1);  // 0 ~ (n-1) の総和
  return s + n;  // 0 ~ n の総和
}

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

    int n = b - a - 1;

    int ans = sum(n) - a;
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

N = INT()
A = LIST()
A = Counter(A)
#print(A)

a = []
for x in A:
	if 4 <= A[x]:
		a.extend([x, x])
	elif 2 <= A[x]:
		a.append(x)

#print(a)
a.sort(reverse = True)

if len(a) < 2:
	print(0)
else:
	print(a[0]*a[1])


Measured memory_bytes: 28120
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n,m;
    cin >> n >> m;
    vector<P> key;
    int a,b;
    REP(i,m){
        cin >> a >> b;
        int c,s = 0;
        REP(j,b){
            cin >> c;
            c--;
            s |= 1 << c;
        }
        key.push_back(P(s, a));
    }
    vector<int> dp(1 << n, INF);
    dp[0] = 0;
    REP(s,1 << n){
        REP(i,m){
            int t = s | key[i].first;
            int cost = dp[s] + key[i].second;
            dp[t] = min(dp[t], cost);
        }
    }
    int ans = dp.back();
    if(ans == INF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i

def has_8divs?(i)
  cnt = 0
  (1..i).each do |j|
    if i%j == 0
      cnt+=1
    end
   end
  return cnt == 8 ? true : false
end

ary = []
(0..n).each do |i|
  if i.odd?
  	ary << i if has_8divs?(i)
  end
end

p ary.size

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    ll a,b;
    cin >> a >> b;
    ll ans ;
    if(a*b<=0){
        cout << "Zero" << endl;
    }
    //  ( a > 0 && b > 0 ) || ( a < 0 && b < 0)
    else if(a > 0 && b > 0){
        cout << "Positive" << endl;
    }
    else if(a < 0 && b < 0){
        int num = b -a + 1;
        if(num%2==0){
            cout << "Positive" << endl;
        }
        else{
            cout << "Negative" << endl;
        }
    }
}

Measured memory_bytes: 3632