akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n;
	while(cin>>n,n){
		map<string,int> ma;
		vector<pair<string,int>> v(n);
		rep(i,n) cin>>v[i].F>>v[i].S;
		rep(i,n){
			ma[v[i].F]=v[i].S;
		}
		int m;
		cin>>m;
		vector<pair<string,vector<string>>> vp(m);
		rep(i,m){
			cin>>vp[i].F;
			int t;
			cin>>t;
			vector<string> tmp(t);
			rep(j,t){
				cin>>tmp[j];
			}
			vp[i].S=tmp;
		}
		string s;
		cin>>s;
		bool update=false;
		rep(i,m){
			update=false;
			rep(j,m){
				int tmp=0;
				rep(k,vp[j].S.size()){
					tmp+=ma[vp[j].S[k]];
				}
				if(tmp<ma[vp[j].F]){
					ma[vp[j].F]=tmp;
					update=true;
				}
			}
			if(!update) break;
		}
		cout<<ma[s]<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

ll pgcd(ll a, ll b){
	return b == 0 ? a : pgcd(b, a%b);
}

int main( int argc, char *argv[] ) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, pos;
	vector<ll> pg;
	ll tmp, bes = 1, act, beg = 0;
	cin >> n;
	vector<ll> pg1(n);
	vector<ll> pg2(n);
	for ( int i = 0 ; i < n ; i++ ){
		cin >> tmp;
		pg.push_back(tmp);
	}
	pg1[0] = pg[0];
	for ( int i = 1 ; i < n ; i++ ){
		pg1[i] = pgcd(pg1[i-1], pg[i]);
	}
	pg2[n-1] = pg[n-1];
	for ( int i = n - 2 ; i >= 0 ; i-- ){
		pg2[i] = pgcd(pg2[i+1], pg[i]);
	}
	ll a, b;
	for ( int i = 0 ; i < n ; i++ ){
		a = i == 0 ? 0 : pg1[i-1];
		b = i == n - 1 ? 0 : pg2[i+1];
		act = pgcd(a, b);
		bes = act > bes ? act : bes;		
	}

	cout << bes << "\n";

	return 0;
}


Measured memory_bytes: 2936
#include <stdio.h>
#include <string.h>

#define LEN 100000

typedef struct pp{
	char name[100];
	int t;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P x);
P dequeue();
int min(int a, int b);

int main(void)
{
	int elaps=0, c,i,q;
	P u;
	scanf("%d %d", &n, &q);
	
	for(i=1; i<=n; i++){
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].t);
	}
	
	head=1;
	tail=n + 1;
	
	while(head != tail){
		u = dequeue();
		c = min(q, u.t);
		u.t = u.t - c;
		elaps = elaps + c;
		if(u.t > 0){
			enqueue(u);
		}
		else{
			printf("%s %d\n",u.name, elaps);
		}
	}
	
	return 0;
}

void enqueue(P x)
{
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}

P dequeue()
{
	P x= Q[head];
	head = (head + 1) % LEN;
	return x;
}

int min(int a, int b)
{
	if(a < b){
		return a;
	}
	else{
		return b;
	}
}


Measured memory_bytes: 11888
/*  ex9_1
    kosaq   */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>//strlenを使用するため
#define SIZE 11

typedef struct{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;//構造体を定義

void initialize_stack(stack *stk);
void push(stack *stk, char elem);
char pop(stack *stk);//プロトタイプ宣言

int main(void){
    char input[SIZE];//入力のために配列を定義
    stack sentence;//構造体を定義
    scanf("%s", input);//0,1,Bからなる配列を入力
    initialize_stack(&sentence);//スタックの初期化

    for(int i = 0; i < strlen(input); i++){
        if(input[i] == '0'){
            push(&sentence, '0');
        }
        else if(input[i] == '1'){
            push(&sentence, '1');
        }
        //0,1のときはスタックにデータを追加
        else if(sentence.count > 0){
            pop(&sentence);//Bのときであり、かつ文字がまだあるとき（count>0）はデータを取り出し
        }
    }
    
    for(int i = 0; i < sentence.count; i++){
        printf("%c", sentence.data[SIZE - i - 1]);//答えの配列を出力
    }
    printf("\n");
    return 0;

}

//スタックの初期化
void initialize_stack(stack *stk){
    stk -> count = 0;
    stk -> size = SIZE;
    stk -> top = &(stk -> data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
    if(stk -> count >= stk -> size){
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else{
        stk -> top--;
        *(stk -> top) = elem;
        stk -> count++;
    }
}

//データの取り出し
char pop(stack *stk){
    char latest;
    if(stk -> count <= 0){
        fprintf(stdout, "Error: stack underflow.\n");
        exit(1);
    }
    else{
        latest = *(stk -> top);
        stk -> top++;
        stk -> count--;
        return latest;
    }
}

Measured memory_bytes: 1620
#include<iostream>
#include<vector>
#include<string>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)

class C{
    public:
        int x, y, r, c;
};

int calDis(C a, C b){
    int c = a.x - b.x, d = a.y - b.y;
    return c * c + d * d;
}

int calSum(int num){
    int ret = 0;
    for(int i = 1; i <= num; i *= 2) if((num & i) != 0) ret++;
    return ret;
}

int main(){
    int n;
    while(cin >>n && n){
        vector<C> discs(n); REP(i, n) cin >>discs[i].x >>discs[i].y >>discs[i].r >>discs[i].c;
        vector<int> overlap(n, 0);
        REP(i, n){
            REP(j, i){
                int tmp = discs[i].r + discs[j].r;
                if(tmp * tmp > calDis(discs[i], discs[j])) overlap[i] = overlap[i] | (1 << j) | overlap[j];
            }
        }
        int ans = 0;
        vector<bool> bitdp(1 << n, false);
        bitdp[0] = true;
        REP(i, bitdp.size()){
            if(!bitdp[i]) continue;
            REP(j, n){
                FOR(k, j + 1, n){
                    if(discs[j].c != discs[k].c || (i & (1 << j)) != 0 || (i & (1 << k)) != 0 || (overlap[j] & i) != overlap[j] || (overlap[k] & i) != overlap[k]) continue;
                    int next = i | (1 << j) | (1 << k);
                    bitdp[next] = true;
                }
            }
            ans = max(ans, calSum(i));
        }
        cout <<ans <<endl;
    }
    return 0;
}

Measured memory_bytes: 3248
#define _USE_MATH_DEFINES


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <numeric>
#include <array>
#include <set>
#include <sstream>
#include <cmath>

using namespace std;

typedef long long LL;


vector<vector<LL>> creat_matrix(LL h, LL w) {
	LL _temp;
	vector<vector<LL>> mat;
	for (LL i = 0; i < h; ++i) {
		vector<LL> vec;
		for (LL j = 0; j < w; ++j) {
			cin >> _temp;
			vec.emplace_back(_temp);
		}
		mat.emplace_back(vec);
	}
	return mat;
}


vector<vector<LL>> inner_product(vector<vector<LL>> X, vector<vector<LL>> Y) {
	size_t n = X.size();
	size_t m = X[0].size();
	size_t l = Y[0].size();

	vector<vector<LL>> mat(n, vector<LL>(l, 0));
	for (LL i = 0; i < n; ++i) {
		for (LL j = 0; j < m; ++j) {
			for (LL k = 0; k < l; ++k) {
				mat[i][k] += X[i][j] * Y[j][k];
			}
		}
	}
	return mat;
}


void show_matrix(vector<vector<LL>> mat) {
	size_t len = mat[0].size();
	for (auto&& t : mat) {
		for (LL i = 0; i < len; ++i) {
			printf("%d", t[i]);
			if (i != (len - 1)) printf(" ");
		}
		printf("\n");
	}
}


vector<string> split(const string& s, char delim) {
	vector<string> elems;
	stringstream ss(s);
	string item;

	while (getline(ss, item, delim)) {
		if (!item.empty()) {
			elems.push_back(item);
		}
	}

	return elems;
}

//
//int main() {
//	int cnt = 0;
//	string w, s; 
//	cin >> w;
//	while (cin >> s, s != "END_OF_TEXT") {
//		string s1, w1;
//		for (int i = 0; i < s.size(); ++i) s1 += tolower(s[i]);
//		for (int i = 0; i < w.size(); ++i) w1 += tolower(w[i]);
//		if (s1 == w1)++cnt;
//	}
//	cout << cnt << endl;
//}


int main() {

	string W;
	cin >> W;
	transform(W.begin(), W.end(), W.begin(), ::toupper);

	string tx;
	int count_num = 0;

	while (cin >> tx, tx != "END_OF_TEXT") {
		transform(tx.begin(), tx.end(), tx.begin(), ::toupper);
		if (tx == W) {
			count_num++;
		}
	}
	printf("%d\n", count_num);

	//while (true)
	//{
	//	getline(cin, tx);

	//	auto sep_tx = split(tx, ' ');

	//	for (auto&& t : sep_tx) {
	//		if (t == "END_OF_TEXT") goto PRINT;

	//		transform(t.begin(), t.end(), t.begin(), toupper);

	//		if (t == W) {
	//			count_num++;
	//		}
	//	}
	//}

	//PRINT:
	//printf("%d\n", count_num);

	return 0;
}



Measured memory_bytes: 3272
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        arr: [isize; n],
    }

    let mut all_amount: isize = arr[0].abs() + arr[n-1].abs();
    for i in 1..n {
        all_amount += (arr[i] - arr[i-1]).abs();
    }

    let ans1 = all_amount - arr[0].abs() - (arr[0] - arr[1]).abs() + arr[1].abs();
    println!("{}", ans1);
    for i in 1..n-1 {
        let ans = all_amount - (arr[i] - arr[i+1]).abs() - (arr[i-1] - arr[i]).abs() + (arr[i-1] - arr[i+1]).abs();
        println!("{}", ans);
    }
    let ansn = all_amount - arr[n-1].abs() - (arr[n-2] - arr[n-1]).abs() + arr[n-2].abs();
    println!("{}", ansn);
}


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

ll x(ll c){
  if(c % 4 == 0) return c;
  if(c % 4 == 1) return 1;
  if(c % 4 == 2) return c + 1;
  return 0;
}

int main() {
  ll a, b;
  cin >> a >> b;
  cout << (x(a - 1) ^ x(b)) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i,n) for (ll i=(ll)n-1;i>=0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}//最大公約数
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}//最小公倍数
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
const int MOD = 1000000007;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back

int main(){
   int n,m;cin>>n>>m;
   vector<VI> AB(MAX);
   rep(i,n){
      ll a,b;cin>>a>>b;
      AB[a].emplace_back(b);
   }
   ll ans=0;
   priority_queue<int>que;
   rep(i,m){
      for(auto v:AB[i+1]){
         que.push(v);
      }
      if(que.size()){
         ans+=que.top();
         que.pop();
      }
   }
   cout<<ans<<endl;
}

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

vector < pair <int, int> > data;

int main(void)
{
	int n, m, a, b;
	while (cin >> n, n){
		data.clear();
		for (int i = 0; i < n; i++){
			scanf("%d %d %d", &m, &a, &b);
			data.push_back(make_pair(a, m));
			data.push_back(make_pair(b, -1 * m));
		}
		sort(data.begin(), data.end());
		
		long long now = 0;
		bool flag = true;
		for (int i = 0; i < data.size(); i++){
			now += data[i].second;
			//cout << now << endl;
			if (150 < now) flag = false;
		}
		if (flag) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int h, w, n;
int sr, sc;
char s[N], t[N];
int ml[N], mr[N], mu[N], md[N];
int x[N], y[N];
int sx, sy;
void upd1(char c) {
	if (c == 'L') --sy;
	if (c == 'R') ++sy;
	if (c == 'U') --sx;
	if (c == 'D') ++sx;
}

void rev(char c) {
	if (c == 'L') ++sy;
	if (c == 'R') --sy;
	if (c == 'U') ++sx;
	if (c == 'D') --sx;
}
//void add(char c) {
//	if (c == 'L') ++l[i]
//}
int adx[N], ady[N];
map<int, int> mp;
int l, r, u, d;
int ll, rr, uu, dd;
void no() {
	puts("NO");
	exit(0);
}
void add1(char c) {
	if (c == 'L') --l;
	if (c == 'R') ++r;
	if (c == 'U') --u;
	if (c == 'D') ++d;
	if (sr + u < 1) no();
	if (sr + d > h) no();
	if (sc + l < 1) no();
	if (sc + r > w) no();
}
void add2(char c) {
	if (c == 'L' && sc + r -1 > 0) --r;
	if (c == 'R' && sc + l + 1 <= w) ++l;
	if (c == 'U' && sr + d - 1 > 0) --d;
	if (c == 'D' && sr + u + 1 <= h) ++u;
}
int main() {
	scanf("%d%d%d%d%d%s%s", &h, &w, &n, &sr, &sc, s + 1, t + 1);
	sx = sr, sy = sc;
	for (int i = 1; i <= n; ++i) {
		add1(s[i]), add2(t[i]);
	}
	puts("YES");
	return 0;
}

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

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

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

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

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

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

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

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

int main(){
    int n;
    cin >> n;
    vpii ba(n);
    rep(i, n) cin >> ba[i].second >> ba[i].first;
    vpii cd(n);
    rep(i, n) cin >> cd[i].first >> cd[i].second;
    RSORT(ba); VSORT(cd);
    int ans = 0;
    rep(i, n) rep(j, n) {
        int a = ba[j].second, b = ba[j].first;
        int c = cd[i].first, d = cd[i].second;
        if (a<c && b<d) {
            ++ans;
            ba[j] = { INF, INF };
            cd[i] = { 0, 0 };
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int H;	//縦
		 int W;	//横
		 while(true){
			 H = Integer.parseInt(scan.next());
			 W = Integer.parseInt(scan.next());
			 if(H == 0 && W == 0){
				 //HとWが0の時、終了。
				 break;
			 }//if
			 //--- 出力 ---
			 for (int i = 0; i < H; i++ ){
				 for (int j = 0; j < W; j++ ){
					 System.out.print("#");
				 }//for
				 System.out.println();
			 }//for
			 System.out.println();
		 }//while 
	}
}

Measured memory_bytes: 26928
#include<stdio.h>
int main()
{
    int A,B,C;
    scanf("%d%d%d",&A,&B,&C);
if(A==B) {
    printf("%d\n",C);
}
else if(C==B){
    printf("%d\n",A);
}
else if(A==C){
    printf("%d\n",B);
}
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1e9+7
#define hell2 1e9+9
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cout << (#x) << " is " << (x) << endl
#define INF 1e9

using namespace std;

ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;
}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 

// max({a, b, c, d})

vector<ll>adj[200005];
ll update[200005];
ll ans[200005];

int binaryToDecimal(string n) 
{ 
    string num = n; 
    int dec_value = 0; 
  
    // Initializing base value to 1, i.e 2^0 
    int base = 1; 
  
    int len = num.length(); 
    for (int i = len - 1; i >= 0; i--) { 
        if (num[i] == '1') 
            dec_value += base; 
        base = base * 2; 
    } 
  
    return dec_value; 
} 

bool isPerfectSquare(long double x) 
{   
  // Find floating point value of  
  // square root of x. 
  long double sr = sqrt(x); 
  
  // If square root is an integer 
  return ((sr - floor(sr)) == 0); 
} 

int main()
{
    int w, h, x, y;
    cin >> w >> h >> x >> y;

    double area = double(w)*double(h)/2;
    // area /= 2;

    cout << prec(10);
    cout << area << " ";
    cout << (x+x == w && y+y == h) << "\n";

}




Measured memory_bytes: 6016
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) printf("Case #%d: ",i);
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;



int main(){
	int n; cin >> n;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];
	int cnt1 = 0, cnt4 = 0;
	bool two = false;
	rep(i, 0, n) {
		if (a[i] % 4 == 0) cnt4++;
		else if (a[i] % 2 == 0) two = true;
		else cnt1++;
	}
	if (two) {
		if (cnt1 <= cnt4) printf("Yes");
		else printf("No");
	}
	else {
		if (cnt1 <= cnt4 + 1) printf("Yes");
		else printf("No");
	}
	return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template



def main():
    N = ii()
    S = li()
    S = list(map(int, S))
    res = [[N for i in range(10)]for j in range(N + 1)]
    for i in range(N - 1, -1, -1):
        for j in range(10):
            res[i][j] = res[i + 1][j]
            res[i][S[i]] = i
    cnt = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                first = res[0][i]
                if(first != N):
                    second = res[first + 1][j]
                    if(second != N):
                        third = res[second + 1][k]
                        if(third != N):
                            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 50652
package main

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

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	i, _ := strconv.Atoi(read())
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func min(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

func abs(x, y int) int {
	if x-y > 0 {
		return x - y
	} else {
		return -(x - y)
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n := readInt()
	aList := make([]int, 0)
	aList = append(aList, 0)
	absSum := 0
	for i := 0; i <= n; i++ {
		aList = append(aList, readInt())
		absSum += abs(aList[i+1], aList[i])
	}
	aList = append(aList, 0)
	for i := 1; i <= n; i++ {
		fmt.Println(absSum - abs(aList[i], aList[i-1]) - abs(aList[i+1], aList[i]) + abs(aList[i-1], aList[i+1]))
	}
}


Measured memory_bytes: 7424
n=int(input())
w=list(map(int,input().split()))

left=0
right=0
tmp=10000000000000

for i in range(n):
    left=0
    right=0
    for j in range(i):
        left+=w[j]
    for k in range(i,n):
        right+=w[k]
    if tmp>abs(left-right):
        tmp=abs(left-right)

print(tmp)

Measured memory_bytes: 3064
def main():
  import sys
  input = sys.stdin.readline
  from collections import deque
  s = list(input())
  s = s[:-1]
  s = deque(s)
  q = int(input())
  c = [[i for i in input().split()] for j in range(q)]
  cnt = 1
  for i in c:
    if i[0] == '1':
      cnt *= -1
    else:
      if (i[1] == '1' and cnt == 1) or (i[1] == '2' and cnt == -1):
        s.appendleft(i[2])
      else:
        s.append(i[2])
  if cnt == 1:
    print(''.join(s))
  else:
    print(''.join(s)[::-1])
if __name__ == '__main__':
    main()

Measured memory_bytes: 32088
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a % 2 == 1 && b % 2 == 1) {
            System.out.println("Odd");
            
        } else {
            System.out.println("Even");
            
        }
    }
}


Measured memory_bytes: 21076
#![allow(dead_code, unused_imports, deprecated)]
use std::cmp::{max, min, Reverse};
use std::collections::*;
use maplit::*;
use num::Integer;
use proconio::input;
use proconio::marker::*;
use proconio::fastout;

const INF : usize = 1000000007;

fn main() {
  input! {
    n : usize, cw : usize,
  };

  let mut w = vec![0];
  let mut v = vec![0];
  for _ in 0..n {
    input! {
      weight : usize, value : usize,
    };
    
    w.push(weight);
    v.push(value);
  }

  let mut dp = vec![vec![0usize; 100000 + 1]; n + 1];

  for j in 0..=100000  {
    if j != 0 {
      dp[0][j] = INF;
    }
  }
  
  for i in 1..=n {
    for j in 0..=100000 {
      if j >= v[i] {
        dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
      } else {
        dp[i][j] = dp[i - 1][j];
      }
    }
  }
  
  let res = (0..100001).filter(|&i| dp[n][i] <= cw )
    .max()
    .unwrap();
  
  println!("{}", res);
}

Measured memory_bytes: 81200
a = int(input())
b = int(input())
if (a,b > 0 and a,b <= 3):
    if (a == 1 and b == 2) or (a == 2 and b == 1):
        print(3)
    elif (a == 1 and b == 3) or (a == 3 and b == 1):
        print(2)
    elif (a == 2 and b == 3) or (a == 3 and b == 2):
        print(1)
else:
    pass

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s[233322];
	cin>>s;
	int a=strlen(s);string a1;
	for(int i=0;i<a;i++)
	{
	if(s[i]!='B')
	a1+=s[i];
	else
	{
		int k=a1.length();
		if(k==0) continue;
		else a1= a1.substr(0, a1.length() - 1);
	}
	}
	
	cout<<a1;
}


Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "set"
#include "vector"
#include "climits"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W;

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

	cin >> N >> K;
	M = LLONG_MAX;
	for (int i = 0; i < N; i++) {
		cin >> H;
		K -= H;
		M = min(M, H);
	}
	cout << N + K / M << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
inline long long lcm(long long a, long long b) { return a * b / __gcd(a,b); }

int main() 
{
    buff();
    long long a, b;
    cin >> a >> b;
    cout << lcm(a,b) << '\n';
    return 0;
}



Measured memory_bytes: 3584
import string

cs = string.ascii_lowercase
def factor(n):
    b = 26
    ds = [n % b]
    n //= b
    while n:
        d = n % b
        ds.append(d)
        n //= b
    return ds

n = int(input())
lst = [
26
,676
,17576
,456976
,11881376
,308915776
,8031810176
,208827064576
,5429503678976
,141167095653376
,3670344486987776
,95428956661682176
]
acc = [sum(lst[:i]) for i in range(len(lst))]
for i, (an1, an) in enumerate(zip(acc, acc[1:]), 1):
    if n < an + 1:
        pos = n - an1 - 1
        fp = factor(pos)
        while len(fp) < i:
            fp.append(0)
        fp.reverse()

        print(''.join(cs[d] for d in fp))
        break


Measured memory_bytes: 9988
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
char s[N][N];
int main() {
	int n, m, d;
	char ch[5] = "RGBY";
	scanf("%d%d%d", &n, &m, &d);
	for (int i = 1; i <= n; ++ i) {
		for (int j = 1; j <= m; ++ j) {
			int x = (i + j) / d % 2 * 2 + (i + m - j) / d % 2;
			putchar(ch[x]);
			s[i][j] = ch[x];
		}
		puts("");
	}
	/*for (int i = 1; i <= n; ++ i) {
		for (int j = 1; j <= m; ++ j) {
			for (int k = 1; k <= n; ++ k) {
				for (int l = 1; l <= m; ++ l) {
					if (abs(i - k) + abs(j - l) == d && s[i][j] == s[k][l]) assert(0);
				}
			}
		}
	}*/
}



Measured memory_bytes: 768
#include<bits/stdc++.h>
 
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(vector<vector<T>> x){cerr<<"\n{"; int f=x.size();for(int i=0;i<f;i++){cerr<<"("; int g=x[i].size(); for(auto j:x[i]){cerr<<j; (--g!=0)?cerr<<",":cerr<<"";}cerr<<")\n";}cerr<<"}";}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void __print(vector<bool> x){cerr<<"{";int f=x.size();for(auto i:x){cerr<<i;(--f !=0)?cerr<<",":cerr<<"";}cerr<<"}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
 
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define trace(x...)
#endif
 
template<typename... T>
void read(T&... args) {
    ((cin >> args), ...);
}
 
template<typename... T>
void writ(T&&... args) {
    ((cout << args << " "), ...);
}
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define INF (ll)1e18
#define IINF (int)1e9
#define EPS 1e-9

bool an(string s){
    int chk=0;
    for(auto i:s){
        chk=(chk+(i-'0'))%9;
    }
    if(chk==0) return true;
    else return false;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s; cin>>s;
    if(an(s)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 3740
#include<iostream>
#include<string>
using namespace std;
int main() {
	int M;
	M = 0;
	string s1s2s3,s,m;
	cin >> s1s2s3;
	s = "1";
	m = "0";
	if (s1s2s3[0] == s[0]) {
		M = M + 1;
	}
	if (s1s2s3[1] == s[0]) {
		M = M + 1;
	}
	if (s1s2s3[2] == s[0]) {
		M = M + 1;
	}
	cout << M << endl;
}

Measured memory_bytes: 256
from operator import itemgetter

n, m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(m)], key=itemgetter(1))

removed = -1
ans = 0
for a, b in ab:
    if a > removed:
        removed = b - 1
        ans += 1

print(ans)


Measured memory_bytes: 29920
#C問題
N, K = map(int, input().split())
D = list(map(str, input().split()))

def check(n, d):
    n = str(n)
    for nstr in n:
        if nstr in d:
            return False
    return True
while True:
    if check(N, D):
        print(N)
        break
    else:
        N += 1


Measured memory_bytes: 2940
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int M = in.nextInt();
    int[][] s = new int[M][];
    for (int k = 0; k < M; k++) {
      s[k] = new int[in.nextInt()];
      for (int i = 0; i < s[k].length; i++) {
        s[k][i] = in.nextInt() - 1;
      }
    }
    int[] p = new int[M];
    for (int i = 0; i < M; i++) {
      p[i] = in.nextInt();
    }
    int ans = 0;
    for (int i = 0; i < Math.pow(2, N); i++) {
      int t = i;
      boolean[] on = new boolean[N];
      for (int j = 0; j < N; j++) {
        on[j] = t % 2 == 1;
        t /= 2;
      }
      boolean all = true;
      for (int k = 0; k < M; k++) {
        int cnt = 0;
        for (int j = 0; j < s[k].length; j++) {
          if (on[s[k][j]]) {
            cnt++;
          }
        }
        if (cnt % 2 != p[k]) {
          all = false;
        }
      }
      if (all) {
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int n,i,j,a,b,c,x,y,z,k;
int main(){
  cin>>n;
  vector<int> br(n);
  for(;i<n;i++)cin>>br[i];
  for(i=0,j=1;i<n;i++){
    if(br[i]==j)j++;
    else c++;
  }
  cout<<(c==n?-1:c);
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
		System.out.println(Math.min(a, b) + " " + Math.max(0, (a + b) - n));
	}
}

Measured memory_bytes: 21844
#include <iostream>

int main() {
  long A, B, C, K;

  std::cin >> A;
  std::cin >> B;
  std::cin >> C;
  std::cin >> K;

  if (K%2==1)
    std::cout << (B-A) << std::endl;
  else
    std::cout << (A-B) << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<int> p;
vector<vector<int> > v(60, vector<int>(4));
int N, M, Q;
int ans = 0;
/* function */
void check_ans() {
    int tmp = 0;
    for (int i = 0 ; i < Q; i++) {
        if (p[v[i][1]] - p[v[i][0]] == v[i][2]) tmp += v[i][3];
    }
    ans = max(tmp, ans);
}
void calc(int pre, int ind) {
    if (ind == N) {
        check_ans();
        return;
    }
    for (int i = pre; i <= M; i++) {
        p[ind] = i;
        calc(i, ind + 1);
        p[ind] = -1;
    }
}
/* main */
int main(){
    cin >> N >> M >> Q;
    for (int i = 0; i < Q; i++) cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3];
    for (int i = 0; i < Q; i++) v[i][0]--, v[i][1]--;
    p.assign(N, -1);

    calc(1, 0);

    cout << ans << '\n';
}

Measured memory_bytes: 3608
[X, Y] = list(map(int, input().split()))
tsuru = 4 * X - Y
kame = Y -2 * X
if (tsuru >= 0) and (tsuru % 2 == 0):
  if (kame >= 0) and (kame % 2 == 0):
    ans = 'Yes'
  else:
    ans = 'No'
else:
  ans = 'No'

print(ans)

Measured memory_bytes: 9172
Q = int(input())
src = [int(input()) for i in range(Q)]
for n in src:
    ans = 0
    _n = n
    st = set()
    while _n >= 10:
        if _n in st:
            print(-1)
            break
        st.add(_n)
        s = str(_n)
        next = 0
        for i in range(1,len(s)):
            next = max(next, int(s[:i]) * int(s[i:]))
        _n = next
        ans += 1
    else:
        print(ans)

Measured memory_bytes: 5620
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int a,b,x;
  cin >> x >> a >> b;
  if (abs(x - a) < abs(x - b)){
    cout << "A\n";
  }
  else{
    cout << "B\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw				"\n"


int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	cin>>n>>x;
	int arr[n];
	for(ll i=0;i<n;i++)
		cin>>arr[i];
	sort(arr,arr+n);
		for(ll i=0;i<n;i++)
	{
		x-=arr[i];
		if(x>=0)cnt++;

	}
	if(x>0)cnt--;
	cout<<cnt<<nw;
	
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define maxn 100005
#define Mod 1000000007
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef set<int> si; 
#define fori(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,b,a) for(int i = (b); i >= (a); --i)
#define all(a) (a).begin(), (a).end()
#define __builtin_popcountll bitCountLL
#define __builtin_popcount bitCount
//__builtin_ctz 末尾0的个数, __builtin_clz 前导0的个数
//__builtin_ffs 最后一个1的位置
const int INF = 2e9;
const ll ML = 4e18;

void solve() {
    int n;
    cin >> n;
    vi x(n-1), y(n-1);
    fori(i,0,n-1) {
        cin >> x[i] >> y[i];
        if(y[i] < x[i]) swap(x[i],y[i]);
    }
    ll ans = 0;
    fori(i,1,n+1) {
        ll len = n + 1 - i;
        ans += (len + 1) * len / 2;
    }
    fori(i,0,n-1) {
        ans -= ll(x[i]) * (n - y[i] + 1);
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	//cout.precision(30); cout << fixed;
	//freopen("D:\\data_in.txt", "r", stdin);
    solve();
    
    /*clock_t start,finish;
    start = clock();
   
    finish = clock();
    cout << "\n" << (double)(finish - start) / (double)(CLOCKS_PER_SEC) * 1000 << "ms" << endl;
    */
    return 0;
}

/***************************************************************
 question:
 idea:
 tag:
 record:
 ***************************************************************/


Measured memory_bytes: 4688
#include<iostream>
#include<cstdio>

int main()
{
	double r;
	std::cin >> r;
	double area, circum;
	double PI = 3.141592653589;
	area = PI * r * r;
	circum = r * 2.0 * PI;
	printf("%.5lf %.5lf\n", area, circum);

	return 0;
}

Measured memory_bytes: 1240
import Data.List

isPrime :: Int -> Bool
isPrime 1 = False
isPrime 2 = True
isPrime n | (length [x | x <- [2 .. n-1], mod n x == 0]) > 0 = False
          | otherwise = True

divisor :: Int -> [Int]
divisor n = foldr f [] $ takeWhile ((<= n) . (^ 2)) [1 .. n]
  where
    f x ds
        | r == 0, q /= x = x : q : ds
        | r == 0         = x : ds
        | otherwise      = ds
      where
        (q, r) = n `divMod` x

solve :: [Int] -> [Int]
solve [] = []
solve (x:xs) = x : solve (filter (\i -> (i `mod` x) /= 0) xs)

main :: IO ()
main = do
    [a,b] <- map read . words <$> getLine :: IO [Int]
    let g = gcd a b
        (_:gs) = sort $ divisor g
    print . (+1) . length $ solve gs


Measured memory_bytes: 2300
// C - 113
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;
int n,m;
int p[100000],y[100000];
vector<int> yd [100001];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	rep(i,m) cin >> p[i] >> y[i] , yd[p[i]].push_back(y[i]);
	rep(i,n) sort(yd[i+1].begin(), yd[i+1].end());
	rep(i,m) printf("%012lld\n",ll(p[i])*1000000+int(lower_bound(yd[p[i]]. begin(),yd[p[i]].end(),y[i])-yd[p[i]].begin())+1);
// 	cout << "Hello, World" << endl;
	return 0;
}

Measured memory_bytes: 7808
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		String tok = sc.next();
		char[] c = tok.toCharArray();
		int t = 0;
		for (int i=c.length-2; i>=1; i--) {
			if ((i&1)==0) continue;
			String a = tok.substring(0, (i+1)/2);
			String b = tok.substring((i+1)/2, i+1);
			if (a.compareTo(b)==0) {
				t+=a.length()+b.length();
				break;
			}
		}
		System.out.println(t);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

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

public class Main {
    //-------------------------------------------------------------//
    public static final void main(String[] args) {
        new Main().solve();
    }
    //-------------------------------------------------------------//
    private final Scanner sc = new Scanner(System.in);
    void solve() {
        String O = sc.next();
        String E = sc.next();
        String ans = "";
        for (int i = 0; i < O.length() + E.length(); i++) {
            if ((i & 1) == 0) {
                ans += O.charAt(i / 2);
            }
            else {
                ans += E.charAt(i / 2);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int N,Y;
    cin>>N>>Y;
    int ans[3]={-1,-1,-1};
    rep(i,N+1){
        rep(j,N-i+1){
            if((Y-1000*i-5000*j)%10000==0&&(Y-1000*i-5000*j)/10000==N-i-j){
                ans[0]=i;
                ans[1]=j;
                ans[2]=N-i-j;
                break;
            }
        }
    }
    cout<<ans[2]<<" "<<ans[1]<<" "<<ans[0]<<endl;
    return 0;
}

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

int main(void){
		int r,c;
		cin >> r >> c;
		int a[r + 1][c + 1];
		//配列初期化
		for(int i = 0;i <= r;i++){
				for(int j = 0;j <= c;j++){
						a[i][j] = 0;
				}
		}
		//配列へ入力
		for(int i = 0;i < r;i++){
				for(int j = 0;j < c;j++){
						cin >> a[i][j];
				}
		}
		//c+1列目の計算
		for(int i = 0;i < r;i++){
				for(int j = 0;j < c;j++){
						a[i][c] += a[i][j];
				}
		}
		//r+1行目の計算
		for(int i = 0;i <= c;i++){
				for(int j = 0;j < r;j++){
						a[r][i] += a[j][i];
				}
		}
		//出力
		for(int i = 0;i <= r;i++){
				for(int j = 0;j <= c;j++){
						cout << a[i][j];
						if(j != c){
								cout << " ";
						}
				}
				cout << endl;
		}
		return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
const int MOD = 1e9+7;
using namespace std;

ll fact[200001];

ll modpow(ll x, ll y){
	ll res = 1;
	while(y > 0){
		if (y & 1) res = res * x % MOD;
		x = x * x % MOD;
		y >>= 1;
	}
	return res;
}

ll factinv(ll n){
	return modpow(fact[n], MOD-2);
}

ll modper(ll n, ll r){
	ll res = 1;
	for (int i = 0; i < r; i++){
		res = res * (n-i) % MOD; 
	}
	return res;
}

ll conb(ll n, ll r){
	return (modper(n, r)*factinv(r))%MOD;
}


int main(){
	ll n, a, b;
	cin >> n >> a >> b;
	fact[0] = 1;
	for (int i = 1; i <= 200000; i++){
		fact[i] = fact[i-1]*(i)%MOD;
	}
	ll ans = modpow(2, n) - conb(n, a) - conb(n, b) - 1;
	if (ans % MOD < 0) cout << ans%MOD+MOD << endl;
	else cout << ans%MOD << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

#define M 998244353

int dp[200001], p[200000], x[200000], d[200000];
int mx[524288];

bool fn(int a, int b) {
    return p[a] < p[b];
}

void st(int i, int l, int r, int k, int v) {
    if (r == l+1) {
        mx[i] = v;
        return;
    }
    int m = (l+r)/2;
    if (k < m)
        st(2*i+1, l, m, k, v);
    else
        st(2*i+2, m, r, k, v);
    mx[i] = MAX(mx[2*i+1], mx[2*i+2]);
}

int gt(int i, int l, int r, int f, int t) {
    if (l >= f && r <= t)
        return mx[i];
    if (l >= t || r <= f)
        return 0;
    int m = (l+r)/2;
    int m1 = gt(2*i+1, l, m, f, t);
    int m2 = gt(2*i+2, m, r, f, t);
    return MAX(m1, m2);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n = gi();
    for (int i = 0; i < n; i++) {
        x[i] = i;
        p[i] = gi();
        d[i] = gi();
    }

    sort(x, x+n, fn);
    memset(mx, 0, sizeof(mx));

    dp[n] = 1;
    for (int i = n-1; i >= 0; i--) {
        int pp = p[x[i]] + d[x[i]];
        int l = i+1, r = n;
        while (l < r) {
            int m = (l+r)/2;
            if (pp > p[x[m]])
                l = m+1;
            else
                r = m;
        }
        if (l > i+1 && l < n) {
            int a = gt(0, 0, n, i+1, l);
            l = MAX(a, l);
        }
        st(0, 0, n, i, l);
        dp[i] = (dp[l] + dp[i+1]) % M;
    }

    printf("%d\n", dp[0]);

    return 0;
}


Measured memory_bytes: 5504
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
using namespace std;

#define rep(i,j,n) for(int (i)=(j);(i)<(n);(i)++)
#define rep2(i,j,n) for(int (i)=(j);(i)<=(n);(i)++)
#define all(i) (i).begin(),(i).end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	vi a(n);
	rep(i, 0, n) cin >> a[i];
	sort(all(a));
	int ans = 0;
	int x = (a[n - 1] % 2 == 0) ? a[n - 1] / 2 : a[n - 1] / 2 + 1;
	rep(i, 0, n - 1) {
		if (abs(ans - x) > abs(a[i] - x)) {
			ans = a[i];
		}
	}
	cout << a[n - 1] << " " << ans << endl;
}

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

public class Main
{
	private static boolean[] prime=new boolean[1000000];

	private static void createPrimes()
	{
		Arrays.fill(prime,true);
		prime[0]=prime[1]=false;
		for(int i=2;i*i<=prime.length-1;){
			for(int j=i+i;j<prime.length;j+=i){
				prime[j]=false;
			}
			for(int j=i+1;j<=prime.length;j++){
				if(prime[j]){
					i=j;
					break;
				}
			}
		}
	}
	private static int countPrimes(int n)
	{
		int cnt=0;
		for(int i=2;i<=n;i++){
			if(prime[i]){
				cnt++;
			}
		}
		return cnt;
	}
	
	public static void main(String[] args)
	{
		createPrimes();
		int n;
		Scanner scan=new Scanner(System.in);
		while(scan.hasNext()){
			n=scan.nextInt();
			System.out.println(countPrimes(n));
		}
		scan.close();
	}
}

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

int main(){
  int i,j,cnt=0;
  int n,h,w;
  cin>>n>>h>>w;
  int a[n],b[n];
  for(i=0;i<n;i++)cin>>a[i]>>b[i];
  for(i=0;i<n;i++){
    if(a[i]>=h && b[i]>=w)cnt++;
  }
  cout<<cnt;
}

Measured memory_bytes: 256
#include<iostream>
 
int main(){
int s_time,hour,minute,second;
std::cin >> s_time;
 
hour=s_time/3600;
minute=(s_time-hour*3600)/60;
second=(s_time-hour*3600-minute*60);
 
std::cout << hour <<":"<< minute <<":"<<second<<std::endl;
return 0;
}

Measured memory_bytes: 1164
def solve(arr,n):
	dp=[0]*n 
	if n==2:
		print(abs(arr[0]-arr[-1]))
		return 
	dp[0]=0 
	dp[1]=abs(arr[0]-arr[1]) 
	for i in range(2,n):
		dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i]),dp[i-2]+abs(arr[i-2]-arr[i])) 
	print(dp[-1]) 
n=int(input())
a=[int(x) for x in input().split()] 
solve(a,n) 

Measured memory_bytes: 84168
n,m=(int(i) for i in input().split())
#print(n,m)

mod=10**9+7
ans=1

if abs(n-m) > 1:
  print(0)
elif n==m:
  for i in range(n,0,-1):
    ans=ans%mod
    ans*=i
  ans=ans*ans*2%mod
  print(ans)
else:
  for i in range(n,0,-1):
    ans=ans%mod
    ans*=i
  for i in range(m,0,-1):
    ans=ans%mod
    ans*=i
  print(ans%mod)
    

Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n+10];
    set<int>x;
    for(int i = 0;i < n;i++)
    {
        cin>>a[i];
        x.insert(a[i]);
    }

    cout<<x.size()<<endl;
}


Measured memory_bytes: 256
n,m=[int(x) for x in input().split()]
k,s=[],[]
for _ in [0]*m:
    val=[int(x) for x in input().split()]
    k.append(val[0])
    s.append(val[1:])
p=[int(x) for x in input().split()]
ans=0
for i in range(1<<n):
    for j in range(m):
        on_switch_num=0
        for l in range(n):
            if l+1 in s[j] and (i>>l & 1) == 1:
                on_switch_num+=1
        if on_switch_num%2==p[j]:
            continue
        else:
            break
    else:
        ans+=1
print(ans)

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

int main(){
  int N,M,j=0;
  cin>>N>>M;
  vector<int> A(N);
  for(int &i:A){
    cin>>i;
    j+=i;
  }
  sort(A.begin(),A.end());
  if(A[N-M]*4*M<j)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3628