akhauriyash/Code-Regression huggingface dataset:
#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;

class UnionFind {
	vector<int>par, sz, sz2;
public:
	int cnt=0;
	UnionFind() {}
	int add_vertex(){
		int n=par.size();
		par.push_back(n);
		sz.push_back(1);
		sz2.push_back(0);
		return n;
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y){
			cnt-=min(sz2[x],sz[x]);
			sz2[x]++;
			cnt+=min(sz2[x],sz[x]);
			return;
		}
		cnt-=min(sz2[x],sz[x]);
		cnt-=min(sz2[y],sz[y]);
		par[y] = x;
		sz[x] += sz[y];
		sz2[x]+=sz2[y];
		sz2[x]++;
		cnt+=min(sz2[x],sz[x]);
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};

vector<int>E[200000];
int ans[200000];

struct st{
	map<int,int>mp;
	UnionFind uf;
	vector<P>edge;
}dat[200000];

void merge(int u,int v){//u<-v
	if(dat[u].edge.size()<dat[v].edge.size())swap(dat[u],dat[v]);
	for(auto p:dat[v].edge){
		if(!dat[u].mp.count(p.first)){
			dat[u].mp[p.first]=dat[u].uf.add_vertex();
		}
		if(!dat[u].mp.count(p.second)){
			dat[u].mp[p.second]=dat[u].uf.add_vertex();
		}
		dat[u].uf.unite(dat[u].mp[p.first],dat[u].mp[p.second]);
		dat[u].edge.push_back(p);
	}
}

void dfs(int v,int p){
	for(int u:E[v]){
		if(u==p)continue;
		dfs(u,v);
		merge(v,u);
	}
	ans[v]=dat[v].uf.cnt;
}

int main(){
	int n,K;cin>>n>>K;
	rep(i,n-1){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	rep(i,n){
		int c,d;scanf("%d%d",&c,&d);c--;d--;
		dat[i].mp[c]=dat[i].uf.add_vertex();
		if(c!=d)dat[i].mp[d]=dat[i].uf.add_vertex();
		dat[i].uf.unite(dat[i].mp[c],dat[i].mp[d]);
		dat[i].edge.push_back(P(c,d));
	}
	dfs(0,-1);
	rep(i,n){
		printf("%d\n",ans[i]);
	}
}


Measured memory_bytes: 148404
N,A,B = map(int,input().split())
if N == 1:
    if A != B:
        print(0)
    else:
        print(1)
elif A == B:
    print(1)
elif A > B:
    print(0)
else:
    print(B*(N-1)+A - (A*(N-1)+B) + 1)

Measured memory_bytes: 9004
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 100100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,m,ans=0;
    cin >> n >> m;
    ans+=n*(n-1);
    ans+=m*(m-1);
    cout << ans/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#define mp make_pair
#define all(a) a.begin(), a.end()
#define pub push_back
#define ll long long
					  
using namespace std;

int n;
int a[3];

int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//freopen("seating.in", "r", stdin);
	//freopen("seating.out", "w", stdout);
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++){
		int x;
		cin >> x;
		if (x % 4 == 0){
			a[2]++;
		} else if (x % 2 == 0){
			a[1]++;
		} else a[0]++;
	}

	if (a[2] >= a[0] || (a[2] + a[0] == n && a[2] + 1 == a[0])) cout << "Yes"; else cout << "No";

}

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

const int MOD = 1e9+7;
const int MAX_N = 3e5;
ll N, M, K;
ll fact[MAX_N], invf[MAX_N];

ll nChoosek(ll n, ll k)
{
	return fact[n]*invf[n-k]%MOD*invf[k]%MOD;
}

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

void solve()
{
	fact[0] = invf[0] = 1;
	for(int i=1;i<MAX_N;++i) fact[i]=(fact[i-1]*i)%MOD;
	invf[MAX_N-1] = modpow(fact[MAX_N-1],MOD-2);
	for(int i=MAX_N-2;i>=1;--i) invf[i]=(invf[i+1]*(i+1))%MOD;
	ll res = 0;
	for(int dx=0; dx<N; ++dx)for(int dy=0;dy<M;++dy){
		ll d = dx + dy;
		ll ways = (N-dx)*(M-dy);
		if(dx && dy) ways *= 2;
		res = (res + d*ways*nChoosek(N*M-2,K-2))%MOD;
	}
	cout << res << '\n';
}

int main()
{
	cin >> N >> M >> K;
	solve();
	return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p.at(i);
    }

    vector<int> sum(n + 1);
    for (int i = 1; i < n; i++) {
        sum.at(i) = sum.at(i - 1) + (p.at(i - 1) < p.at(i));
    }

    set<int> s;
    for (int i = 0; i < k; i++) {
        s.insert(p.at(i));
    }
    bool is_sorted = false;

    int ans = 0;
    if (sum.at(k - 1) - sum.at(0) == k - 1) is_sorted = true;
    else ans = 1;

    for (int i = k; i < n; i++) {
        s.insert(p.at(i));

        if (sum.at(i) - sum.at(i - k + 1) == k - 1) is_sorted = true;
        else if (!(p.at(i) == *s.rbegin() && p.at(i - k) == *s.begin())) ans++;

        s.erase(p.at(i - k));
    }
    cout << ans + is_sorted << endl;
}

Measured memory_bytes: 11136
#include<iostream>
using namespace std;
int main()
{
int x;
cin>>x;

if(x==999){cout<<"111";}
else if (x==111){cout<<"999";}
else if (x==991){cout<<"119";}
else if (x==119){cout<<"991";}
else if (x==919){cout<<"191";}
else if(x==191){cout<<"919";}
else if (x==199){cout<<"911";}
else if (x==911){cout<<"199";}






return 0;
}


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

using namespace std;

#define int long long

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

vs str;
int len;

vi vals;

#define F first
#define S second

pii dfs(int pos, int offset, int num){
    if(pos == 3){
        if(vals[2] == vals[0] + vals[1] + offset){
            return mp(1, 0);
        }
        else if(vals[2] == (vals[0] + vals[1] + offset) % 10){
            return mp(0, 1);
        }
        else return mp(0, 0);
    }

    pii ret = mp(0, 0);

    if(str[pos][num] != '?'){
        vals[pos] = str[pos][num] - '0';

        pii diff = dfs(pos + 1, offset, num);
        ret.F += diff.F;
        ret.S += diff.S;
    }
    else{
        rep(i, 10){
            if(num == 0 && i == 0) continue;

            vals[pos] = i;

            pii diff = dfs(pos + 1, offset, num);
            ret.F += diff.F;
            ret.S += diff.S;
        }
    }

    return ret;
}

constexpr int MOD = 1000000007;

signed main(void){
    vals = vi(3);
    for(str = vs(3); cin >> str[0], str[0] != "0";){
        len = str[0].size();
        cin >> str[1] >> str[2];

        vvi dp(len + 1, vi(2));
        dp[len][0] = 1;

        for(int i = len - 1; i >= 0; i--){
            rep(j, 2){
                pii diff = dfs(0, j, i);

                (dp[i][0] += dp[i + 1][j] * diff.F) %= MOD;
                (dp[i][1] += dp[i + 1][j] * diff.S) %= MOD;
            }
        }

        cout << dp[0][0] << endl;
    }

	return 0;
}

Measured memory_bytes: 1212
import std.stdio, std.string, std.conv, std.algorithm, std.array;

void main(){
	auto A = readln.chomp.to!(int);
	auto B = readln.chomp.to!(int);
	auto C = readln.chomp.to!(int);
	auto D = readln.chomp.to!(int);
	auto E = readln.chomp.to!(int);
	int ans;
	
	if(A<0){
		ans += -A*C;
		A=0;
	}
	if(A==0){
		ans += D;
		
	}
	if(A>=0){
		ans += (B-A)*E;
	}
	writeln(ans);
}

Measured memory_bytes: 2468
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int const mod = 1e9 + 7;
LL f[105], x, y;
int lim = 91;
LL ans2;

bool Dfs(LL a, LL b, LL res) {
  if (a * f[res - 1] + (res - 1 ? b * f[res - 2] : 0) > x) return 0;
  if (a * f[res] + b * f[res - 1] > y) return 0;
  if (!(res - 1)) {
    ans2 = (ans2 + (x - b) / a) % mod;
    ans2 = (ans2 + (y - b) / a) % mod;
    return 1;
  }
  int i = 1;
  while (Dfs(b + i * a, a, res - 1)) ++i;
  return (i > 1);
}

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  f[0] = f[1] = 1;
  for (RI i = 2; i <= lim; ++i)
    f[i] = f[i - 1] + f[i - 2];
  int Q; read(Q);
  while (Q--) {
    read(x), read(y);
    if (x > y) swap(x, y);
    if (x == 1) { printf("%d %lld\n", 1, y % mod); continue; }
    int ans1 = 0;
    for (RI i = lim; i && !ans1; --i)
      if (f[i - 1] <= x && f[i] <= y)
        ans1 = i - 1;
    ans2 = 0;
    if (ans1 == 1) {
      ans2 = (ans2 + x) % mod;
      ans2 = (ans2 + y) % mod;
    }
    else for (RI i = 2; Dfs(i, 1, ans1 - 1); ++i);
    printf("%d %lld\n", ans1, ans2);
  }

  return 0;
}

// created by Daniel yuan


Measured memory_bytes: 4992
// C - GCD on Blackboard
#include <bits/stdc++.h>
using namespace std;

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

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

	int g = 0; // それまでのAiの 累積gcd
	set<int> s; // それまでの各Aiを除いた gcd の集合

	// s = {前累積gcd, gcd(s, Ai)} を求める
	while(N--){
		int a; cin>>a; // Ai
		set<int> p; swap(p, s); // p<-s, s<-{} : copy & clear
		for(int e:p) s.insert(gcd(e, a)); // s: 再 insert
		s.insert(g); // s: insert 前累積gcd
		g = gcd(a, g); // 今累積gcd
	}

	cout<< *s.rbegin() <<endl; // 末尾に解がくる
}

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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    int ans;
    vector<int> a(3);
    rep(i, 3) cin >> a[i];
    sort(a.rbegin(), a.rend());
    int m = a[0];
    int abc = a[0] + a[1] + a[2];
    if ((3 * m - abc) % 2 == 0)
        ans = (3 * m - abc) / 2;
    else
        ans = (3 * (m + 1) - abc) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
# https://atcoder.jp/contests/abc127/tasks/abc127_c



N, M = gets.split.map(&:to_i)
left_max = 1
right_min = N
M.times do
  left, right = gets.split.map(&:to_i)
  left_max = left if left_max < left
  right_min = right if right_min > right
end

puts (left_max..right_min).size


Measured memory_bytes: 1916
#include <cstdio>

int main()
{
	int x, y, buff;

	while(1){
		scanf("%d %d", &x, &y);
		if(x == 0 && y == 0) break;
		if(x > y){
			buff = y;
			y = x;
			x = buff;
		}
		printf("%d %d\n", x, y);
	}
	return 0;
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)

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

int main(void) {
    int n, d, cnt;
    cnt = 0;
    int num[110] = {0};
    cin >> n;
    REP(i, n){
        cin >> d;
        num[d]++;
    }
    REP(i, 110){
        if(num[i] >= 1) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(),x.end()
auto& errStream=cerr;
#ifdef LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

template<int i,class T>
void print_tuple(ostream&,const T&){
}

template<int i,class T,class H,class ...Args>
void print_tuple(ostream&os,const T&t){
	if(i)os<<",";
	os<<get<i>(t);
	print_tuple<i+1,T,Args...>(os,t);
}

template<class ...Args>
ostream& operator<<(ostream&os,const tuple<Args...>&t){
	os<<"(";
	print_tuple<0,tuple<Args...>,Args...>(os,t);
	return os<<")";
}

ll read(){
	ll i;
	scanf("%"  SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

constexpr ll Ten(int n){
	return n==0?1:Ten(n-1)*10;
}

template<class T>
vector<T> Uniqued(const vector<T>&vv){
	auto v(vv);
	sort(ALL(v));
	v.erase(unique(ALL(v)),v.end());
	return v;
}
template<class T>
void MakeUniqued(vector<T>&v){
	sort(ALL(v));
	v.erase(unique(ALL(v)),v.end());
}

signed main(){
	int n=read(),k=read();
	if(k*2-1<=n)
		Yes();
	else
		No();
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

int main() {
	IOS;
	int n, k;
	cin >> n >> k;
	vector<ll> v(n);
	REP(i, n) {
		cin >> v[i];
	}
	ll min = LMAX;

	REP(i, n - k + 1) {
		ll sum;
		if (v[i] >= 0)sum = abs(v[i + k - 1]);
		else if (v[i + k - 1] <= 0)sum = abs(v[i]);
		else {
			if (abs(v[i]) < abs(v[i + k - 1]))sum = abs(v[i]) * 2 + abs(v[i + k - 1]);
			else sum = abs(v[i]) + abs(v[i + k - 1]) * 2;
		}
		if (sum < min)min = sum;
	}
	cout << min << endl;


}



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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 200111, inf = 1000111222;

int n, k;
ll ans[max_n];

vector<ll> col[max_n];
vector<pair<ll, int>> v;
bool np[max_n];
bool has[max_n];

multiset<ll> r1; // that has pair in the left
multiset<ll> r2; // over all
multiset<ll> r3; // over all
multiset<ll> l1; // over all
multiset<ll> l2; // that has no child in the left

ll set_mx(const multiset<ll>& ms) {
    if (ms.empty()) {
        exit(228);
    }
    auto it = ms.end();
    --it;
    return *it;
}

void add2(int k) {
    vector<ll>& c = col[k];
    r2.erase(r2.find(c[0] + c[1]));
    if (c.size() > 2) {
        r3.erase(r3.find(c[0] + c[1] + c[2]));
    }
    for (int i = 2; i < c.size(); ++i) {
        r1.insert(c[i]);
    }
    l2.insert(c[0] + c[1]);
}

void add1(int k, ll val) {
    vector<ll>& c = col[k];
    r1.erase(r1.find(val));
    l1.insert(val);
}

int main()
{
    //freopen("input.txt", "r", stdin);
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        int val, c;
        scanf("%d %d", &c, &val);
        val *= 2;
        --c;
        col[c].PB(val);
    }
    for (int i = 0; i < k; ++i) {
        sort(col[i].begin(), col[i].end(), greater<ll>());
        col[i][0] = col[i][1] = (col[i][0] + col[i][1]) / 2;
        r2.insert(2 * col[i][0]);
        if (col[i].size() > 2) {
            r3.insert(col[i][0] + col[i][1] + col[i][2]);
        }
        for (int val : col[i]) {
            v.emplace_back(val, i);
        }
    }
    sort(v.begin(), v.end(), greater<pair<ll, int>>());
    for (int i = 0; i < v.size(); ++i) {
        if (has[v[i].S] == 0) {
            has[v[i].S] = 1;
            np[i] = true;
        }
    }
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        ans[i] = -inf;
        if (np[i]) {
            if (!r1.empty()) {
                ans[i] = max(ans[i], sum + set_mx(r1));
            }
            if (!l1.empty() && !r2.empty()) {
                ans[i] = max(ans[i], sum - *l1.begin() + set_mx(r2));
            }
            if (!l2.empty() && !r3.empty()) {
                ans[i] = max(ans[i], sum - *l2.begin() + set_mx(r3));
            }
            sum += v[i].first;
            continue;
        }
        sum += v[i].first;
        ans[i] = sum;
        if (i && np[i - 1]) {
            add2(v[i].S);
        } else {
            add1(v[i].S, v[i].F);
        }
    }
    for (int i = 0; i < n; ++i) {
        if (ans[i] == -inf) {
            ans[i] = -2;
        }
        printf("%lld\n", ans[i] / 2);
    }

    return 0;
}




Measured memory_bytes: 24556
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <queue>
using namespace std;

#define LET(name, value) __typeof(value) name = value
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for (LET(i, (c).begin()); i != (c).end(); ++i)

int time[50], laps[50], limit[2];

struct Entry {
  int id, lane, t;
  Entry(int id, int lane, int t): id(id), lane(lane), t(t) {}
  bool operator<(const Entry& rhs) const {
    return (t == rhs.t) ? (time[id] > time[rhs.id]) : (t > rhs.t);
  }
};

int main() {
  int n;
  while (scanf("%d", &n), n) {
    limit[0] = limit[1] = 0;
    REP(i, n) { scanf("%d%d", time+i, laps+i); laps[i] *= 2; }
    priority_queue<Entry> Q;
    REP(i, n) { Q.push(Entry(i, 0, 0)); }
    while (!Q.empty()) {
      int id = Q.top().id;
      int lane = Q.top().lane;
      int t = Q.top().t;
      Q.pop();
      limit[lane] = max(limit[lane], t + time[id]);
      --laps[id];
      if (laps[id] > 0) { Q.push(Entry(id, !lane, limit[lane])); }
    }
    printf("%d\n", max(limit[0], limit[1]));
  }
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		for (int i=1;i<1000;i++) {
			if ((A*i)%B==C) {
				System.out.println("YES");
				return ;
			}
		}
		System.out.println("NO");
	}
}

Measured memory_bytes: 22996
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#define ll long long
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
ll read()
{
	ll tmp=0; char f=1,c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1; c=getchar();}
	while('0'<=c&&c<='9'){tmp=tmp*10+c-'0'; c=getchar();}
	return tmp*f;
}
using namespace std;
int vis[100010]={0},p[100010],sum[100010];
int n,cnt=0;
int main()
{
	int i,j;
	n=read(); vis[1]=1;
	for(i=2;i<=100005;i++){
		if(!vis[i])p[++cnt]=i;
		for(j=1;j<=cnt&&i*p[j]<=100005;j++){
			vis[i*p[j]]=1;
			if(i%p[j]==0)break;
		}
	}
	sum[0]=0;
	for(i=1;i<=100005;i++){
		sum[i]=sum[i-1];
		if(i&1&&!vis[i]&&!vis[(i+1)>>1])++sum[i];
	}
	for(i=1;i<=n;i++){
		int l=read(),r=read();
		printf("%d\n",sum[r]-sum[l-1]);
	}
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
 using namespace std;
int main()
{
  int n;
  int m;
  cin>>n>>m;
  int s[m];
  int c[m];
  for(int i=0;i<m;i++)
  {
    cin>>s[i];
    cin>>c[i];
  }
  int yy=0;
  map<int,int> mp;
  for(int i=0;i<m;i++)
  {
    if(mp.find(s[i])!=mp.end() && mp[s[i]]!=c[i])
    {yy=1;break;}
    else mp[s[i]]=c[i];
  }  
  if(yy==1)
      cout<<-1<<endl;
  else 
  {int N=n;
     if(N>1 && mp.find(1)!=mp.end() && mp[1]==0)
         cout<<-1<<endl;
     else 
     {
       if(N==1)
       {
        if(mp.find(1)!=mp.end())
            cout<<mp[1]<<endl;
         else cout<<0<<endl; 
       }
       else if(N==2)
       {
         int num=0;
         if(mp.find(1)!=mp.end())
             num=mp[1];
         else 
           num=1;
         if(mp.find(2)!=mp.end())
            num=num*10+mp[2];
          else num=num*10; 
         cout<<num<<endl;
           
       }
       else if(N==3)
       {
            int num=0;
         if(mp.find(1)!=mp.end())
             num=mp[1];
         else 
           num=1;
         if(mp.find(2)!=mp.end())
            num=num*10+mp[2];
          else num=num*10; 
         if(mp.find(3)!=mp.end())
            num=num*10+mp[3];
          else num=num*10; 
         cout<<num<<endl;
       }  
     }  
        
  } 
 return 0;
}


Measured memory_bytes: 256
//
// Created by Huang,Zhiqiang on 2018/8/13.
//

#include <iostream>
#include <algorithm>
using namespace std;

const int INF=int(1e9);
int n,goal;
int con[15][2];
int dp[15][int(1e5)];

int DP(int x,int y)
{
    if(y <= 0) return 0;
    if(x < 1) return INF;
    if(dp[x][y] != -1) return dp[x][y];
    dp[x][y] = INF;
    for(int i = 0; i < con[x][0]; i++)
        dp[x][y] = min(dp[x][y], DP(x-1,y-i*x) + i);
    dp[x][y] = min(dp[x][y], DP(x - 1, y - con[x][0] * x - con[x][1]) + con[x][0]);
    return dp[x][y];
}

int main()
{
    for (int i = 0; i < 15; i++) {
        for (int j = 0; j < 1e5; j++) {
            dp[i][j] = -1;
        }
    }
    cin >> n >> goal;
    goal /= 100;
    for(int i=1;i<=n;i++) {
        cin >> con[i][0] >> con[i][1];
        con[i][1] /= 100;
    }
    cout << DP(n, goal) << endl;
}

Measured memory_bytes: 6272
x1, x2, x3, x4, x5 = map(int, input().split())

if x1 == 0:
    print(1)
elif x2 == 0:
    print(2)
elif x3 == 0:
    print(3)
elif x4 == 0:
    print(4)
else:
    print(5)

Measured memory_bytes: 9116
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int res = 0;
        int cur = 0;
        while (cur < n) {
            if (res == 0) {
                cur += k;
            }  else {
                cur += k -1;
            }
            res++;
        }
        System.out.println(res);

    }

}

Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

vector<int> g[222222];
int used[222222];

void dfs(int n=0){
  if(used[n])return;
  used[n]=1;
  for(int i=0;i<g[n].size();i++)dfs(g[n][i]);
}

int main(){
  int n,m;
  cin>>n>>m;
  
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
	 int l;
	 cin>>l;
	 l--;
	 g[n+l].pb(i);
	 g[i].pb(n+l);
    }
  }

  dfs();
  
  bool ans=true;
  for(int i=0;i<n;i++){
    if(used[i])continue;
    ans=false;
  }
  
  cout<<(ans?"YES":"NO")<<endl;
  
  return 0;
}


Measured memory_bytes: 9472
#include<iostream>
#include <string.h>
using namespace std;

int main()
{
  int n,matomari;
  int count=0;
  string ans = "No";
  char s[10010];
  cin >>n>>s;
  matomari = strlen(s)/2;
  for(int i=0;i<matomari;i++)
  {
    if(s[i]==s[matomari+i])count++;
  }
  if(count==matomari)ans = "Yes";
  if(strlen(s)%2!=0)ans = "No";
  cout<<ans<<endl;
  return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    long long N;
    string S;
    int P;

    cin >> N >> P >> S;
    
    if (P == 2 || P == 5) {
        long long res = 0;
        for (int i = 0; i < N; ++i){
            if ((S[N-i-1]-'0') % P == 0){
                res += N-i;
            }
        }
        cout << res << endl;
        return 0;
    }
    vector<long long> val(P, 0);
    long long tenfactor = 1;
    long long cur = 0;
    val[0]++;
    for (int i = 0; i < N; ++i) {
        cur = (cur + (S[N-i-1]-'0') * tenfactor) % P;
        tenfactor = (tenfactor * 10) % P;
        val[cur]++;
    }
    long long res = 0;
    for (int p = 0; p < P; ++p) res += val[p] * (val[p] - 1) / 2;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
import sys
from operator import itemgetter

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    l = [list(map(int, input().split())) for i in range(n)]
    l.sort(key=itemgetter(1))

    is_possible = True
    sum = 0
    for e in l:
        sum += e[0]
        if sum > e[1]:
            is_possible = False
            break

    print("Yes" if is_possible else "No")


Measured memory_bytes: 53704
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (int) (k); ++i)
#define Rep(i, j, k) for(R int i = (j); i >= (int) (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 111;
const ll INF = 5e16;

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread(buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		R ll x = 0; R int f = 0; R char dd;
		for (; !isdigit(ch); dd) f ^= (ch == '-');
		for (; isdigit(ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) x = -x, putchar('-');
		if (x > 9) write(x / 10); putchar(x % 10 | 48);
	}

	inline void wrn ( ll x ) { write(x), putchar(' '); }

	inline void wln ( ll x ) { write(x), putchar('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x), wln(y); }

}

using IO::wln;
using IO::read;

namespace Cesare {
	
	char s[N], y[N];
	ll k, Ans = 0, oth = 0;
	
	int main() {
		cin >> s + 1 >> k;
		ll len = strlen(s + 1);
		if (len == 1) return wln(k / 2), 0;
		s[len + 1] = s[1];
		For ( i, 1, len + 1 ) y[i] = s[i];
		For ( i, 2, len ) if (s[i] == s[i - 1] && s[i] == s[i + 1]) {
			For ( j, 'a', 'z' ) if (j != s[i - 1] && j != s[i + 1]) 
				{s[i] = j; break;}
			++Ans;
		}
		For ( i, 2, len ) if (s[i] == s[i - 1]) {
			For ( j, 'a', 'z' ) if (j != s[i - 1] && j != s[i + 1]) 
				{s[i] = j; break;}
			++Ans;
		}
		if (s[1] == s[len]) {
			For ( i, 'a', 'z' ) 
				if (i != s[len] && i != y[2]) 
					{y[1] = i; break;}
			++oth;
			For ( i, 2, len ) if (y[i] == y[i - 1] && y[i] == y[i + 1]) {
				For ( j, 'a', 'z' ) if (j != y[i - 1] && j != y[i + 1]) 
					{y[i] = j; break;}
				++oth;
			}
			For ( i, 2, len ) if (y[i] == y[i - 1]) {
				For ( j, 'a', 'z' ) if (j != y[i - 1] && j != y[i + 1]) 
					{y[i] = j; break;}
				++oth;
			}
			if (len & 1) {
//				debug();
				return wln(Ans * (k - k / 2) + oth * (k / 2)), 0;
			} return wln(Ans + oth * (k - 1)), 0;
		} else oth = Ans;
		return wln(Ans + oth * (k - 1)), 0;
	}
	
}

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);

	return Cesare :: main();
}

/*
a

a
7

3

aaaaa
3

7
*/






Measured memory_bytes: 256
# from line_profiler import LineProfiler
from collections import deque
from sys import stdin

def main():
    while(True):
        W, H = map(int, stdin.readline().split())
        if not W: break
        tx,ty = map(int, stdin.readline().split())
        kx,ky = map(int, stdin.readline().split())
        ma = [[False]*(W+2) for _ in range(H+2)]
        for i in range(1,H+1):
            for j,a in enumerate(stdin.readline().split()):
                ma[i][j+1] = bool(1-int(a))
        que = deque([[tx,ty,kx,ky,0]])
        pas = set()
        ans = "NA"
        while(que):
            tx,ty,kx,ky,c = que.popleft()
            if tx == kx and ty == ky:
                ans = c
                break
            for dx,dy in [[-1,0],[0,-1],[1,0],[0,1]]:
                tdx, tdy = ( dx, dy) if ma[ty+dy][tx+dx] else (0,0)
                kdx, kdy = (-dx,-dy) if ma[ky-dy][kx-dx] else (0,0)
                ttx,tty,kkx,kky = tx+tdx,ty+tdy,kx+kdx,ky+kdy
                if (ttx,tty,kkx,kky) in pas: continue
                if c+1 > 100: continue
                que.append([ttx,tty,kkx,kky,c+1])
                pas.add((ttx,tty,kkx,kky))
        print(ans)

if __name__ == "__main__":
    # prf = LineProfiler()
    # prf.add_function(main)
    # prf.runcall(main)
    # prf.print_stats()
    main()


Measured memory_bytes: 35204
import java.util.*;

class Main{

    //メソッドの方で使うからここで宣言しておかなくてはならない
    static Scanner sc = new Scanner(System.in);
    static int a = sc.nextInt();
    static int b = sc.nextInt();
    public static void main(String[] args){
        int re = 0; //結果用
        for(int i = 0; i < 2; i++){
            re = re + Press();
        }
        System.out.println(re);
    }
    
    //比較用メソッド（ボタンが押されたとき）
    public static int Press(){
        if(a > b){
            //メンバ変数は1減らしてもう一回使う（2回比較するから）
            //計算用の戻り値はそのままの値
            a = a - 1;
            return a + 1;
            
           
        //elseなので==の場合もここ
        }else{
            b = b - 1;
            return b + 1;
        }
    }
}

Measured memory_bytes: 24020
n=int(input())
d=[int(input()) for _ in range(n)]
d.sort(reverse=True)
count=0
for i in range(n):
    if d[i-1]==d[i]:
        count+=0
    elif d[i-1]!=d[i]:
        count+=1
if count==0:
    count=1
print(count)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

long long count(long long d) {
    long long c = 0;
    while (d != 1) {
        ++c;
        d /= d;
    }
    return c;
}

int main() {
    long long N;
    cin >> N;
    if (N % 2 != 0) {
        cout << 0 << endl;
        return 0;
    }
    long long sum = 0;
    for(long long i = 10; i <= N; i *= 5) {
        sum += N / i;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
int a[3][111111];
long long ans;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>N;
    for(int i=0;i<3;i++)
        for(int j=0;j<N;j++)
            cin>>a[i][j];
    for(int i=0;i<3;i++)sort(a[i],a[i]+N);
    for(int i=0;i<N;i++){
        int x=a[1][i];
        ans += 1LL
        * ((lower_bound(a[0],a[0]+N,x)-a[0]))
        * (N - (upper_bound(a[2],a[2]+N,x)-a[2]));
    }
    cout<<ans;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    map<ll,ll> m;
    ll a[1000]={0};
    for(long long i=0;i<1000;i++)
    {
        m[i*i*i*i*i]=1;
        a[i]=i*i*i*i*i;
    }
    ll x;
    int temp=0;
    cin>>x;
    long long ans1=0,ans2=0;
    for(int i=0;i<1000;i++)
    {
        if(m[a[i]-x]==1)
        {
            ans1 = i;
            ans2 = a[i] - x;
            break;
        }
        else if(m[x-a[i]]==1)
        {
            ans1=i;
            ans2=x-a[i];
            temp=1;
            break;
        }
    }
    for(ll i=0;i<1000;i++)
    {
        if(i*i*i*i*i==ans2)
        {
            ans2=i;
            break;
        }
    }
    if(temp==1)
        ans2=-ans2;
    cout<<ans1<<" "<<ans2;





}



Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  
  string s;
  cin >> s;
  
  if(s == "SSS") cout << 0;
  if(s == "SSR") cout << 1;
  if(s == "SRS") cout << 1;
  if(s == "SRR") cout << 2;
  if(s == "RSS") cout << 1;
  if(s == "RSR") cout << 1;
  if(s == "RRS") cout << 2;
  if(s == "RRR") cout << 3;
  
  cout << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b; 
    cin>>a>>b;
    if((a%3==0)||(b%3==0)||((a+b)%3==0))cout<<"Possible"<<endl; 
    else cout<<"Impossible"<<endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut enable = vec![true; n];
    for i in 0..m {
        let a = read::<usize>();
        enable[a - 1] = false;
    }
    let big_int = 1000000007u64;
    let mut dp = vec![0u64; n + 1];
    dp[0] = 1;
    for i in 1..n + 1 {
        if enable[i - 1] {
            dp[i] += dp[i - 1];
            dp[i] %= big_int;
            if i > 1 {
                dp[i] += dp[i - 2];
                dp[i] %= big_int;
            }
        }
    }
    // debug!(dp);

    println!("{:?}", dp[n]);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main() {

	int a, b;
	int c;
	cin >> a >> b;
	cin >> c;

	if ((c-(a-b))>0) {

		cout << c - (a - b) << endl;
	}
	else if ((c - (a - b)) <= 0) {

		cout << 0 << endl;
	}
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <bitset>
using namespace std;

int main(void){
  int N;
  cin >> N;
  
  string P;
  string Q;
  for(int i=0;i<N;i++){
    string p;
    cin >> p;
    P += p;
  }
  
  for(int i=0;i<N;i++){
    string q;
    cin >> q;
    Q += q;
  }
  
  vector<char> seq;
  for(int i=0;i<N;i++){
    seq.push_back('0' + (i+1));
  }
  
  vector< string > texts;
  
  do {
    string s(seq.begin(),seq.end());
    texts.push_back(s);
  } while(next_permutation(seq.begin(),seq.end()));
  
  sort(texts.begin(),texts.end());
  
  int a = 0;
  int b = 0;
  
  for(int i=0;i<texts.size();i++){
    if(P==texts[i]){ a = i+1;}
    if(Q==texts[i]){ b = i+1;}
  }
  
  cout << abs(a-b) << endl;
}


Measured memory_bytes: 2424
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    lint x;
    cin >> x;

    vec div;

    for (int i = 1; i * i <= x; i++) {
        if (x % i == 0) {
            div.push_back(i);
            if (i * i != x) div.push_back(x/i);
        }
    }

    for (auto&& i : div) {
        auto j = x/i;
        for (lint ta = 0; ta * ta <= x; ta++) {
            lint tb = ta - i;
            auto p = ta * ta * ta * ta + ta * ta * ta * tb + ta * ta * tb * tb + ta * tb * tb * tb + tb * tb * tb * tb;
            if (p == j) {
                printf("%lld %lld\n", ta, tb);
                exit(0);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3724
#include<stdio.h>
int main(){
 int n,i,x;

 scanf("%d",&n);

 for(i=3;i<=n;i++){
  x=i;
  if(x%3==0){
   printf(" %d",x);
  }else if(x%10==3){
   printf(" %d",x);
   }else{
     while(x>=10){
      x/=10;
      if(x%10==3){
      printf(" %d",i);
      break;
     }
    }
   }
 }
 printf("\n");
return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	string S;
	cin >> S;
	int ans=0;
	for(int i=0; i*2<S.size(); ++i){
		if(S[i]!=S[S.size()-1-i]) ++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]){
        int A[] = {sc.nextInt(), sc.nextInt(), sc.nextInt()};

        Arrays.sort(A);
        int c = A[2] - A[1];
        c += (A[1] - A[0]) / 2;
        if ((A[1] - A[0]) % 2 != 0){
            c += 2;
        }

        System.out.println(c);
    }
}

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

int main() {
    int n;cin>>n;
    int a[n];
    for(int i = 0;i<n;++i){
        cin>>a[i];
        if(i!=0){
            if(a[i]>a[i-1])--a[i];
            if(a[i]<a[i-1]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

int main(){
    string s,t; cin>>s>>t;
    sort(all(s));
    sort(all(t));
    reverse(all(t));
    if(s<t)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, k;
    cin >> n >> k;
    vl a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    bitset<30> kk = k;
    vector<bitset<30>> aa(n);
    for (int i = 0; i < n; ++i) {
        aa[i] = a[i];
    }
    ll ret = 0;
    for (int i = 0; i < n; ++i) {
        if ((aa[i] | kk) == kk)
            ret += b[i];
    }
    for (int i = 0; i <= 30; ++i) {
        if (kk[i] == 0)
            continue;
        ll temp       = 0;
        bitset<30> kt = kk;
        kt[i]         = 0;
        for (int j = i - 1; j >= 0; --j) {
            kt[j] = 1;
        }
        for (int j = 0; j < n; ++j) {
            if ((aa[j] | kt) == kt)
                temp += b[j];
        }
        chmax(ret, temp);
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
long long n, w, val[105], peso[105], dp[105][100005];
int main()
{
    cin >> n >> w;
    for(int i=1; i<=n; i++){
        cin >> peso[i] >> val[i];
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=w; j++){
            if(peso[i]<=j){
                dp[i][j]=max(dp[i-1][j], val[i]+dp[i-1][j-peso[i]]);
            }else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout << dp[n][w] << endl;
    return 0;
}

Measured memory_bytes: 79360
N, M = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

all_votes = a.inject(:+)
all_votes /= (4 * M).to_f
# p all_votes

counter = 0

a.each do |val|
  counter += 1 if val >= all_votes
end

if counter >= M
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
#include <stdio.h>

int main(void)
{
	int i, j, k, l, n, m, ans;
	
	m = 0;
	
	while (m != 50){
		ans = 0;
		scanf("%d", &n);
		
		for (i = 0; i <= 9; i++){
			for (j = 0; j <= 9; j++){
				for (k = 0; k <= 9; k++){
					for (l = 0; l <= 9; l++){
						if (i + j + k + l == n){
							ans++;
						}
					}
				}
			}
		}
		m++;
		printf("%d\n", ans);
	}
	return (0);
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
#include <deque>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int n;
    cin >> n;

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

    int cnt = 0;
    for (int i = 1; i < n-1; i++) {
        if ((p[i] > p[i-1] && p[i] < p[i+1]) || (p[i] < p[i-1] && p[i] > p[i+1])) {
            cnt ++;
        }
    }
    
    cout << cnt << endl;

    return 0;
    

}

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

int area(int d){
    int s = 0;
    for(int i=d; i<=(600-d); i+=d){
        s = s + i*i*d;
    }
    return s;
}

int main(void){
    int d;
    while(cin >> d){
        cout << area(d) <<endl;
    }

 return 0;
}



Measured memory_bytes: 3080
def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    ans = 1

    tmp = num_list[0]

    for i in range(1,n):
        if tmp <= num_list[i]:
            ans += 1
            tmp = num_list[i]

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	if a == 1 {
		a += 13
	}
	if b == 1 {
		b += 13
	}

	if a > b {
		fmt.Println("Alice")
	} else if a < b {
		fmt.Println("Bob")
	} else {
		fmt.Println("Draw")
	}
}


Measured memory_bytes: 512
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int n, h, highest = 0, ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%d", &h);
    if (h >= highest)
      ans++;
    highest = MAX(highest, h);
  }
  printf("%d\n", ans);
  return 0;
}

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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int a, b, c, k;
    cin >> a >> b >> c >> k;
    Int sum = 0;
    Int sub = min(a, k);
    k -= sub;
    sum += sub;
    sub = min(b, k);
    k -= sub;
    sub = min(c, k);
    sum -= sub;
    print(sum);
    return 0;
}

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

using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t, cnt = 0;
    set <string> s;
    cin >> t;
    while(t--)
    {
        string k;
        cin >> k;
        s.insert(k);
        
    }
    cout << s.size() << endl;
    return 0;
}


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

#define mod (1000000007)

int n, m;

int main(){
	scanf("%d%d", &n, &m);
	int ans1 = 0, ans2 = 0;
	for(int i = 1; i <= n; ++ i){
		int xi;
		scanf("%d", &xi);
		ans1 += 1ll * (2ll * i - 1 - n) * xi % mod;
		if(ans1 < 0) ans1 += mod;
		ans1 -= ans1 > mod ? mod : 0;
	}
	for(int i = 1; i <= m; ++ i){
		int yi;
		scanf("%d", &yi);
		ans2 += 1ll * (2ll * i - 1 - m) * yi % mod;
		if(ans2 < 0) ans2 += mod;
		ans2 -= ans2 > mod ? mod : 0;
	}
	printf("%d\n", 1ll * ans1 * ans2 % mod);
	return 0;
}

Measured memory_bytes: 256