akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll mod =  1000000007;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (int i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

ll inverse(ll x) {
    return power(x, mod - 2, mod);
}

combination table(1e6);


ll b;
ll w;

signed main() {
  ios::sync_with_stdio(false);
  cin >> b >> w;
  vector<ll> p(b+w+1);
  vector<ll> q(b+w+1);
  ll ans = inverse(2);
  p[w] = inverse(power(2, w, mod));
  REP_FROM(i, w, b+w) {
    p[i+1] = p[i] + table.C(i, w-1) * inverse(power(2, i+1, mod) % mod) % mod;
    p[i+1] %= mod;
  }
  q[b] = inverse(power(2, b, mod));
  REP_FROM(i, b, b+w) {
    q[i+1] = q[i] + table.C(i, b-1) * inverse(power(2, i+1, mod) % mod) % mod;
    q[i+1] %= mod;
  }
  REP(i, b+w) {
    ll ans = inverse(2);
    ans += (inverse(2) * p[i]) % mod;
    ans %= mod;
    ans -= (inverse(2) * q[i]) % mod;
    if(ans < 0) ans += mod;
    ans %= mod;
    cout << ans << endl;
  }
}


Measured memory_bytes: 20992
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int[][][] flor = new int[4][3][10];
		for(int i = 0; i < flor.length; i++){
			for(int j = 0; j < flor[i].length; j++){
				for(int k = 0; k < flor[i][j].length; k++){
					flor[i][j][k] = 0;
				}
			}
		}
		int n = sc.nextInt();
		for(int i = 0;i < n; i++){
			int tou = sc.nextInt() - 1;
			int kai = sc.nextInt() - 1;
			int ban = sc.nextInt() - 1;
			int num = sc.nextInt();
			flor[tou][kai][ban] += num;
			if(flor[tou][kai][ban] < 0){
				flor[tou][kai][ban] = 0;
			}
		}
		for(int i = 0; i < flor.length; i++){
			for(int j = 0; j < flor[i].length; j++){
				for(int k = 0; k < flor[i][j].length; k++){
					System.out.printf(" %d",flor[i][j][k]);
				}
				System.out.println();
			}
			if(i == flor.length - 1){
			}else{
				System.out.println("####################");
			}
		}
	}
}




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

int n, a, b, c;
vector<int> len(8);

int dfs(int i, int x, int y, int z) {
    if(i == n){
        if(min(x, min(y, z))>0) return abs(a - x) + abs(b - y) + abs(c - z) - 30;
        else return 1e5;
    }

    int ret0 = dfs(i + 1, x, y, z);
    int ret1 = dfs(i + 1, x + len[i], y, z) + 10;
    int ret2 = dfs(i + 1, x, y + len[i], z) + 10;
    int ret3 = dfs(i + 1, x, y, z + len[i]) + 10;

    return min(min(ret0, ret1), min(ret2, ret3));
}

int main() {
    cin >> n >> a >> b >> c;

    for (int i = 0; i < n; i++) cin >> len[i];
    cout << dfs(0, 0, 0, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
  int a, b;
  cin >> a;
  cin >> b;
  if (a + b == 15) {
    cout << "+" << endl;
  } else if (a * b == 15) {
    cout << "*" << endl;
  } else {
    cout << "x" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
S = input()
op = ["+","-"]
for bit in range(1 << 3) :
    L = []
    for k in range(3) :
        if bit & (1 << k) :
            L.append(op[0])
        else :
            L.append(op[1])
    f = S[0]+L[0]+S[1]+L[1]+S[2]+L[2]+S[3]
    if eval(f) == 7 :
        ans = f + "=7"
        break
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include<vector>
#include<iostream>
#include<string>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<cmath>
#include<algorithm>
#include<numeric>
#define LONG long long int
using namespace std;

int main() {
	string s;
	bool isYYMM = 0;
	bool isMMYY = 0;

	cin >> s;
	if ((s[0] == '0'&&s[1] <= '9'&&s[1] > '0') || (s[0] == '1'&&s[1] < '3'&&s[1] > '0'))
	{
		isMMYY = 1;
	}
	if ((s[2] == '0'&&s[3] <= '9'&&s[3] > '0') || (s[2] == '1'&&s[3] < '3'&&s[3] > '0'))
	{
		isYYMM = 1;
	}

	if (isMMYY&isYYMM)
	{
		cout << "AMBIGUOUS" << endl;
	}
	else if (!isMMYY & !isYYMM)
	{
		cout << "NA" << endl;
	}
	else if (isMMYY && !isYYMM)
	{
		cout << "MMYY" << endl;
	}
	else if (!isMMYY && isYYMM)
	{
		cout << "YYMM" << endl;
	}

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ldouble = long double;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;


int main()
{
	for (ll i = 0; i < 5; i++)
	{
		ll a;
		cin >> a;

		if (a == 0)
		{
			println(i + 1);
		}
	}
}


Measured memory_bytes: 3620
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int n, m;
  ci(n, m);
  co((n - 1) * (m - 1));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define SZ(x) (int)x.size()-1
#define F(i,a,b) for (int i=a;i<=b;++i)
#define DF(i,a,b) for (int i=a;i>=b;--i)
#define pb push_back
#define ms(a,b) memset(a,b,sizeof a)
using namespace std;
int read(){
    char ch=getchar(); int w=1,c=0;
    for (;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
    for (;isdigit(ch);ch=getchar()) c=(c<<3)+(c<<1)+(ch^48);
    return w*c;
}
const int M=666,mod=998244353; 
int f[2][M][M],s[M][M],num,ton[M],to[M],rk[M]; 
int val[M],tim[M],n,k,t[M];
bool pl[M]; 
char ch[M];
int main(){
	scanf("%s",ch+1); n=strlen(ch+1); k=read(); 
	int ct=0; 
	F(i,1,n){
		if (ch[i]=='0') ct++;
		else {
			t[ct]++;
			num++;
			to[num]=ct; 
			ton[num]=t[ct];
		}
	}
	int mi=max(0,num-k); 
//	cout<<num<<" "<<mi<<"   fuck\n";
	int cg=0;
	F(i,0,ct){
		F(j,1,num) if (to[j]==i)  rk[j]=cg+ton[j];
		F(j,1,t[i])  val[++cg]=i,pl[cg]=1,tim[cg]=j;
		val[++cg]=i; tim[cg]=t[i]+1; 
	}
	f[0][0][0]=1;
	int now=1,pre=0;
	F(i,1,num){
		ms(s,0);
		F(j,0,num){
			s[0][j]=f[pre][0][j];
			F(l,1,cg) s[l][j]=f[pre][l][j]+s[l-1][j],s[l][j]%=mod; 
		}
//		cout<<rk[i]<<" "<<"  rand\n"; 
		F(j,1,rk[i]){
			F(l,pl[j],num){
				if (tim[j]>1){
					f[now][j][l]=f[pre][j-1][l-pl[j]]+(pl[j] ? 0 : f[pre][j][l]),f[now][j][l]%=mod; 
				}
				else f[now][j][l]=s[j-pl[j]][l-pl[j]]; 
//				cout<<f[now][j][l]<<"\n"
			}
		}
//		cout<<f[now][rk[i]][i]<<"   sbyy\n"; 
		swap(now,pre); ms(f[now],0); 
	}
	LL ans=0;
	F(i,mi,num) F(j,0,cg) ans=(ans+f[pre][j][i])%mod; 
	cout<<ans<<"\n"; 
    return 0;
}



Measured memory_bytes: 8900
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pdd = pair<double, double>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 998244353;
const ld PI = acosl(-1);

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

    int H, W, M;
    cin >> H >> W >> M;

    vector<int> ycnt(H), xcnt(W);
    map<pii, bool> mp;
    for (int i = 0; i < M; ++i) {
        int h, w;
        cin >> h >> w;
        h--, w--;
        mp[{h, w}] = true;
        ycnt[h]++;
        xcnt[w]++;
    }

    int hma = 0, wma = 0, hidx = 0, widx = 0;
    for (int i = 0; i < H; ++i) {
        if (hma < ycnt[i]) {
            hma = ycnt[i];
            hidx = i;
        }
    }
    for (int i = 0; i < W; ++i) {
        if (wma < xcnt[i]) {
            wma = xcnt[i];
            widx = i;
        }
    }

    int ans = 0;
    ans = hma + wma;
    if (mp.find({hidx, widx}) != mp.end())
        ans--;

    vector<int> hcheck, wcheck;
    for (int i = 0; i < H; ++i) {
        if (hma == ycnt[i])
            hcheck.push_back(i);
    }
    for (int i = 0; i < W; ++i) {
        if (wma == xcnt[i])
            wcheck.push_back(i);
    }

    H = hcheck.size();
    W = wcheck.size();
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (mp.find({hcheck[i], wcheck[j]}) != mp.end())
                continue;
            ans = hma + wma;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, k, x, y;

int main() {
	cin >> n >> k >> x >> y;
	
	int ans;
	if(n <= k) {
		ans = n * x;
	} else {
		ans = k * x + (n - k) * y;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
// URL : https://atcoder.jp/contests/practice2/tasks/practice2_a
#include <atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

signed main() {
    int N, Q;
    cin >> N >> Q;
    dsu d(N);
    while (Q--) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0)
            d.merge(u, v);
        else
            cout << d.same(u, v) << endl;
    }
}


Measured memory_bytes: 4052
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll dp[100010][3];
int main(){
    int n;
    cin >> n;
    ll ary[n][3];
    rep(i,n) rep(j,3) cin >> ary[i][j];

    rep(i, n) {
        dp[i+1][0] = max(dp[i][1], dp[i][2]) + ary[i][0];
        dp[i+1][1] = max(dp[i][0], dp[i][2]) + ary[i][1];
        dp[i+1][2] = max(dp[i][1], dp[i][0]) + ary[i][2];
    }

    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
}


Measured memory_bytes: 4992
N = int(input())
A = list(map(int, input().split()))

cont = []
c = 1
for i in range(N-1):
    if A[i] == A[i+1]:
        c += 1
    else:
        cont.append(c)
        c = 1
else:
    cont.append(c)

# print(cont)
ans = 0
for ci in cont:
    ans += ci // 2
print(ans)

Measured memory_bytes: 3064
def decode():
    n = int(input())
    w = [int(x) for x in input().split()]

    return n, w


def search(w, sw, swi):
    wi = w.index(sw[swi])
    cost = 0
    count = 0
    while wi != swi:
        tw = sw[wi]
        ti = w.index(tw)
        w[ti], w[wi] = w[wi], w[ti]
        cost += w[ti] + w[wi]
        count += 1
        wi = ti
    return cost, count


def search_min_cost(w):
    sorted_w = list(w)
    sorted_w.sort()

    min_w = sorted_w[0]
    cost = 0

    for i, sww in enumerate(sorted_w):
        tmp_cost, count = search(w, sorted_w, i)
        cost += min(tmp_cost, tmp_cost + (min_w + sww) * 2 - (sww - min_w) * count)

    return cost


if __name__ == '__main__':

    n, w = decode()
    print(search_min_cost(w))


Measured memory_bytes: 5632
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 105000;

int n;
int l[MAXN], r[MAXN];
vector< pair<int, pair<int, int>> > v;
int ans = 0;
int mnEnd = 1e9;
set < pair<int, int> > r1, l2, r2;
int mxL, mnR;

int main() { 

  scanf("%d", &n);

  mxL = 0; mnR = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &l[i], &r[i]);
    ans = max(ans, r[i] - l[i] + 1);
    mnEnd = min(mnEnd, r[i]);
    l2.insert({l[i], i});
    r2.insert({r[i], i});
    if (l[i] > l[mxL]) {
      mxL = i;
    }
    if (r[i] < r[mnR]) {
      mnR = i;
    }
  }

  int mxLen = 0;
  for (int i = 0; i < n; i++) {
    if (i != mxL && i != mnR) {
      mxLen = max(mxLen, r[i] - l[i] + 1);
    }
  }
  // cerr << mxLen << " " << mnR << " " << mxL << endl;
  ans = max(ans, mxLen + max(0, r[mnR] - l[mxL] + 1));

  for (int i = 0; i < n; i++) {
    v.push_back({l[i], {-r[i], i}});
  }
  sort(all(v));

  for (int i = 0; i < n; i++) {
    int idx = v[i].second.second;
    int from = v[i].first, to = r[idx];
    if (from > mnEnd) {
      break;
    }

    r1.insert({to, idx});
    l2.erase({from, idx});
    r2.erase({to, idx});

    if (sz(l2) > 0) {
      int cur = r1.begin()->first - from + 1;
      int mxL = l2.rbegin()->first;
      int mnR = r2.begin()->first;  
      cur += max(0, mnR - mxL + 1);
      ans = max(ans, cur);
      //cerr << "upd " << idx << " " << cur << endl;
      //cerr << r1.begin()->first - from + 1 << " " << mnR - mxL + 1 << endl;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12024
S = input()
Q = int(input())

direction = 1
head = []
tail = []
for i in range(Q):
    T = input()
    if T == '1':
        direction = direction * -1
    else:
        T = T.split()
        if T[1] == '1':
            if direction == 1:
                head.append(T[2])
            else:
                tail.append(T[2])
        else:
            if direction == 1:
                tail.append(T[2])
            else:
                head.append(T[2])

head = head[::(-1)]
head.append(S)
head.extend(tail)
S = "".join(head)[::direction]

print(S)

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int a, b, c; cin >> a >> b >> c;
    if(b-a == c-b) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int num[30];

bool check(int a,int t){
	int i,j,k;
	for(i=0,j=0;i<a;i++){
		while(num[j]<t && j<26){j++;}
		if(j>=26)return false;
		num[j]-=t;
	}
	return true;
}

int main(){
	char ca[105];
	int i,j,k;
	int n,m;
	int a,b,c;
	bool s=true;
	
	cin>>n>>m;
	memset(num,0,sizeof(num));
	for(i=0;i<n;i++){
		cin>>ca;
		for(j=0;j<m;j++){
			a=(int)ca[j]-(int)'a';
			num[a]++;
		}
	}
	if(n%2==0 && m%2==0)a=n*m,b=0,c=0;
	if(n%2==0 && m%2==1)a=n*(m-1),b=n,c=0;
	if(n%2==1 && m%2==0)a=(n-1)*m,b=m,c=0;
	if(n%2==1 && m%2==1)a=(n-1)*(m-1),b=n+m-2,c=1;
	
	if(s)s=check(a/4,4);
	if(s)s=check(b/2,2);
	if(s)s=check(c,1);
	
	if(s)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld; 
typedef double db; 
typedef string str; 
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl; 
typedef pair<ld,ld> pd; 
 
typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 
 
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
 
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound 
#define ub upper_bound 
 
const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 1000001;
 
ll N, M, toDiv = -1;
 
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> N >> M;
    vl a(N); 
    bool flag = true;
    F0R(i, N) {
        cin >> a[i];
        if (toDiv == -1) toDiv = 1 << __builtin_ctzll(a[i]);
        else toDiv = min(toDiv, (ll)(1 << __builtin_ctzll(a[i])));
    }
    
    sort(all(a), greater<ll>());
    vl b(N);
    F0R(i, N) {
        b[i] = a[i] / toDiv;
        a[i] /= 2;
        if (i > 0 && b[i] % 2 != b[i - 1] % 2) flag = false;
    }
    
    if (!flag) {
        cout << 0; 
        return 0;
    }
    
    ll LCM = -1;
    F0R(i, N) {
        if (LCM == -1) LCM = a[i];
        else LCM = (a[i] * LCM) / __gcd(a[i], LCM);
        
        if (LCM > M) {
            cout << 0;
            return 0;
        }
    }
    
    ll ans = 1, times = 3;
    while (LCM * times <= M) {
        ans++;
        times += 2;
    }
    
    cout << ans;
    return 0;
    // You should actually read the stuff at the bottom
}
 
/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int N;
    io.read(N);
    int ans;
    for(ans = 1; (ans + 1) * (ans + 1) <= N; ans++);
    cout << ans * ans;
    return 0;
}

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

const int MAX_V = 200;
const int INF = (1<<29);
struct edge {
  int to, cap, rev;
};

vector<edge> G[MAX_V];
vector<edge> tmp[MAX_V];
bool used[MAX_V];

void add_edge(int from,int to, int cap ){
  G[from].push_back( (edge){to,cap,(int)G[to].size()} );
  G[to].push_back( (edge){from,cap,(int)G[from].size()-1} );
}

int dfs(int v,int t,int f){
  if( v == t ) return f;
  used[v] = true;
  for( edge &e : G[v] ){
    if( !used[e.to] && e.cap > 0 ){
      int d = dfs( e.to, t, min( f, e.cap ) );
      // cout << v << " -> " << e.to << " " << d << " : " << e.cap << endl;
      if( d > 0 ){
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset( used,0,sizeof( used ) );
    int f = dfs( s, t, INF );
    if( !f ) return flow;
    flow += f;
  }
}


int N,V,S,T;
/*
int remove_flow( edge &u, edge &v ){
  u.cap = v.cap = 0;
  int fw = max_flow( v.to, u.to );
  if( fw == 0 ){
    max_flow( T, u.to );
    max_flow( v.to, S );
    if( max_flow( S, T ) ) return 0;
    return -1;
  }
  return 0;
}
*/

int add_flow( edge &u, edge &v,int cap,int map ){
  u.cap = cap;
  v.cap = map;
  int ret = max_flow( S, T );
  return ret;
}

int main(){

  int K,N,M;
  cin >> K >> N >> M;
  for(int i=0;i<M;i++){
    int a,b,c;
    cin >> a >> b >> c;
    add_edge( a, b, c );
  }
  T = 0;
  S = K + N + 1;
  for(int i=1;i<=K;i++)
    add_edge( S, i, INF );

  int flow = max_flow( S, T );


  for(int i=0;i<=S;i++)
    tmp[i] = G[i];
  
  int res = flow;
  for(int i=0;i<=K+N;i++){
    for( int j=0;j<(int)G[i].size();j++ ){
      edge &e = G[i][j];
      int map = G[e.to][e.rev].cap;
      int ad = add_flow( e, G[e.to][e.rev], INF, map );
      //      cout << i << " -> " << e.to << " "<< cap << " ad : " << ad << endl;
      res = max( res, flow + ad );
      for(int i=0;i<=S;i++)
        G[i] = tmp[i];
    }
  }
  if( res >= INF )
    cout << "overfuro" << endl;
  else
    cout << res << endl;  
  
}

Measured memory_bytes: 3312
#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(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr <<"at line "<< __LINE__<<": [" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
typedef tree<int, null_type,
		less_equal<int>, 
		rb_tree_tag,tree_order_statistics_node_update> ordered_mset;
		
typedef tree<int, null_type,
		less<int>, 
		rb_tree_tag,tree_order_statistics_node_update> ordered_set;
*/
 
/*
 
PBDS
-------------------------------------------------
			0 based indexing
-------------------------------------------------			 
1) insert(value)
2) erase(value)
3) order_of_key(value) // Number of items strictly smaller than value
4) *find_by_order(k) : K-th element in a set (counting from zero)
 
*/
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());	

const int mod=998244353;
const int mx=2e5+5;

ll fact[mx],inv[mx];

ll power(ll b,ll n)
{
	if(n==0) return 1;
	ll ans=power(b,n/2)%mod;
	ans*=ans;
	ans%=mod;
	if(n%2) ans*=b;
	ans%=mod;
	
	return ans;
}

void make()
{
	fact[0]=1;
	inv[0]=1;
	for(ll i=1;i<(ll)mx;i++)
	{
		fact[i]=fact[i-1]*i;
		fact[i]%=mod;
		inv[i]=power(fact[i],mod-2);
	}
}

ll ncr(int n,int r)
{
	if(n<r) return 0;
	if(n<0 || r<0) return 0;
	
	ll ans=fact[n]*inv[n-r];
	ans%=mod;
	ans*=inv[r];
	ans%=mod;
	
	return ans;
}

void solve()
{
	int n,m,k;
	cin>>n>>m>>k;
	
	make();
	
	ll ans=0;
	
	for(int i=0;i<=k;i++)
	{
		ll temp=ncr(n-1,i)*m;
		temp%=mod;
		temp*=power(m-1,n-i-1);
		temp%=mod;
		
		ans+=temp;
		ans%=mod;
	}
	
	cout<<ans;
	
}
	
		
	
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	
	#ifdef LOCAL
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	
	return 0;
}


Measured memory_bytes: 6768
import java.util.Scanner;
class Main{
    int x, y, z = 0;
    public void aaaa(){
        Scanner sc = new Scanner(System.in);
        x = sc.nextInt();
        y = sc.nextInt();
        while(z == 0){
            if (x < y){
                System.out.println(x + " " + y);
            }else{
                System.out.println(y + " " + x);
            }
            x = sc.nextInt();
            y = sc.nextInt();
            if(x == 0 && y == 0){
                z++;
            }
        }
        
    }
    public static void main(String[] args){
        new Main().aaaa();
    }
        
}

Measured memory_bytes: 27208
n,m=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
x.sort(key=lambda x: x[0])
#print(x)
num=0
money=0
for i in range(n):
    num+=x[i][1]
    money+=x[i][1]*x[i][0]
    if num>m:
        money=money-(num-m)*x[i][0]
        break
print(money)

Measured memory_bytes: 29024
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
}
template<class S, class T> inline void chmin(S &a, T b){
  if(a>b){
    a=b;
  }
}
int main(){
  char S[55];
  int N, hist[26], i, j, len, res[26];
  {
    int Lj4PdHRW;
    for(Lj4PdHRW= 0;Lj4PdHRW< (25) + 1;Lj4PdHRW++){
      res[Lj4PdHRW] = 100;
    }
  }
  rd(N);
  while(N--){
    rd(S);
    len = strlen(S);
    {
      int KL2GvlyY;
      for(KL2GvlyY= 0;KL2GvlyY< (len-1) + 1;KL2GvlyY++){
        S[KL2GvlyY] -= 'a';
      }
    }
    {
      int Q5VJL1cS;
      for(Q5VJL1cS= 0;Q5VJL1cS< (25) + 1;Q5VJL1cS++){
        hist[Q5VJL1cS] = 0;
      }
    }
    {
      int e98WHCEY;
      for(e98WHCEY= 0;e98WHCEY< (len-1) + 1;e98WHCEY++){
        hist[S[e98WHCEY]]++;
      }
    }
    {
      int cTE1_r3A;
      for(cTE1_r3A= 0;cTE1_r3A< (25) + 1;cTE1_r3A++){
        chmin(res[cTE1_r3A], hist[cTE1_r3A]);
      }
    }
  }
  for(i=0;i<26;i++){
    for(j=0;j<res[i];j++){
      putchar_unlocked('a'+i);
    }
  }
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20170408-3

// --- original code ---
// {
//   int N;
//   char S[55];
//   
//   int res[26], hist[26];
//   int i, j, len;
// 
//   res[0..25] = 100;
//   rd(N);
//   while(N--){
//     rd(S);
//     len = strlen(S);
//     S[0..len-1] -= 'a';
//     hist[0..25] = 0;
//     hist[S[0..len-1]]++;
//     res[0..25] <?= hist[0..];
//   }
//   
// 
//   rep(i,26) rep(j,res[i]) putchar_unlocked('a'+i);
//   putchar_unlocked('\n');
// }


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

////////////////////////////////////////
// ポテンシャル付きUnion-Find木(未検証) //
////////////////////////////////////////

// 0-indexed
class UnionFindWithPotential {
private:
	std::vector<int> parent_, size_;
	std::vector<int64_t> potential_delta_;

	// indexの含まれる木の根のノード番号を返す
	int calcRoot(const int index)
	{
		int &parent{parent_[index]};
		if (parent == index) return index;

		const int root{calcRoot(parent)};
		potential_delta_[index] += potential_delta_[parent];
		parent = root;
		return parent;
	}
public:
	UnionFindWithPotential(const int size)
		:parent_(size), size_(size, 1), potential_delta_(size)
	{
		for (int i{}; i < size; i++) parent_[i] = i;
	}

	// index1とindex2の連結判定
	bool areConnected(const int index1, const int index2)
	{
		return calcRoot(index1) == calcRoot(index2);
	}

	// potential(index1) = potential(index2) + weightとなるよう結合
	bool unite(const int index1, const int index2, const int64_t weight)
	{
		const int root1{calcRoot(index1)}, root2{calcRoot(index2)};
		if (root1 == root2)
			return potential_delta_[index1] == potential_delta_[index2] + weight;
		if (size_[root1] <= size_[root2])
		{
			size_[root2] += size_[root1];
			potential_delta_[root1] = (potential_delta_[index2] + weight) - potential_delta_[index1];
			parent_[root1] = root2;
		}
		else
		{
			size_[root1] += size_[root2];
			potential_delta_[root2] = potential_delta_[index1] - (weight + potential_delta_[index2]);
			parent_[root2] = root1;
		}
		return true;
	}

	// indexが含まれる木の要素数を返す
	int calcSize(const int index)
	{
		return size_[calcRoot(index)];
	}

	// potential(index1) - potential(index2)を返す
	// 根が異なる場合はLLONG_MAXを返す
	int64_t calcDiff(const int index1, const int index2)
	{
		if (calcRoot(index1) != calcRoot(index2))
			return LLONG_MAX;
		return potential_delta_[index1] - potential_delta_[index2];
	}
};


int main()
{
	int n, q;
	scanf("%d%d", &n, &q);
	UnionFindWithPotential ufp(n);
	for (int q_i{}; q_i < q; q_i++)
	{
		int query, x, y;
		scanf("%d%d%d", &query, &x, &y);
		if (query == 0)
		{
			int z;
			scanf("%d", &z);
			ufp.unite(y, x, z);
		}
		else if (ufp.areConnected(x, y))
			printf("%lld\n", ufp.calcDiff(y, x));
		else
			puts("?");
	}
	return 0;
}


Measured memory_bytes: 4424
import java.io.*;
 
class Main
{
 public static void main(String[] args) throws IOException
 {
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
  String str = br.readLine();
 
  int x=Integer.parseInt(str),h=x/3600,m,s;
  x%=3600;
   
  m=x/60;
  x%=60;
      
  s=x;
 
  System.out.println(h+":"+m+":"+s);
 }
}

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

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

    ll n;
    cin >> n;
    vector<ll> ai(n);
    rep(i,n) cin >> ai[i];

    ll result = 0;
    ll temp = ai[0];
    rep(i,n-1){
        if(temp>=ai[i+1]){
            result += temp - ai[i+1];
        }
        else{
            temp = ai[i+1];
        }
    }

    cout << result;

    return 0;
}

Measured memory_bytes: 4776
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

   cin>>n;

   vector<pll>v;
     for(i=0; i<n; i++)
     {
         cin>>a>>b;

         v.eb(b,a);
     }

     sort(vll(v));


       for(auto  x  : v)
       {
           ans+=x.S;

           if(ans>x.F)
           {
               cout<<"No"<<endl;

               return 0;
           }
       }

       cout<<"Yes"<<endl;







}



Measured memory_bytes: 7352
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<int, pair<int,int> > data;
int main(){
  int n,m;
  cin >> n >> m ;
  int i,j,k;
  while((n+m)!=0){
    int ns[20010]={};
    vector <data> ds;
    data d;
    for(i=0;i<m;i++){
      cin >> d.first >> d.second.first >> d.second.second;
      ds.push_back(d);
    }
    sort(ds.begin(),ds.end());
    int o=1;
    ns[1]=1;
    for(i=0;i<m;i++){
      if(ns[ds[i].second.first]==1&&ns[ds[i].second.second]==0) {
	ns[ds[i].second.second]=1;
	o++;
      }
    }
    cout << o << endl;
    cin >> n >> m ;
  }
  return 0;
}

Measured memory_bytes: 1764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    int n;
    int temp;
    int a = 0;
    vector<int> v;

    cin >> n;

    for(int i = 0; i < n; i++){
      cin >> temp;
      v.push_back(temp);
    }

    sort(v.begin(), v.end(), greater<int>());

    for (int i = 0; i < n-1; i++){
      if (v[i] != v[i+1]) a++;
    }

    cout << a+1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(x) (((long long)x)%modulo)

int check(vector<int> &V,int ind){
	int maxi = 0;
	if(ind==V.size()-1)return V.size()-1;
	for(int i = ind+1;i<V.size();i++){
		if(V[i]<V[i-1]){
			maxi=i-1;
			break;
		}
		if(i==V.size()-1)return V.size()-1;
	}
	
	for(int i = ind+1;i<V.size();i++){
		if(V[i]>V[i-1]){
			maxi=max(maxi,i-1);
			break;
		}
		if(i==V.size()-1)return V.size()-1;
	}
	return maxi;
}

int main(){
	int N;
	cin>>N;
	vector<int> A(N);
	
	for(int i=0;i<N;i++)cin>>A[i];
	
	int cnt = 0;
	
	int x = 0;
	while(x!=A.size()){
		cnt++;
		x=check(A,x);
		x++;
	}
	
	cout<<cnt<<endl;
	
	
	
	return 0;
}


Measured memory_bytes: 640
//In the name of God
//SMani24
#include<bits/stdc++.h>
using namespace std;

int n, ans;
string s;

int main() {
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		string t = s.substr(i, 3);
		if (t == "ABC")
			ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[100010];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    cout<<a[n-1]<<' ';
    int tmp = a[0];
    for(int i=0;i<n-1;i++){
        if((a[n-1]-2*a[i])>0) tmp = a[i];
        else {
            if(i>0){
                if(abs(2*a[i]-a[n-1])<abs(2*a[i-1]-a[n-1])) tmp = a[i];
            }
            break;
        }
    }
    cout<<tmp;
    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <set>
#include <utility>
#include <climits>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>

#define ll long long
#define ull unsigned long long
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	vector<int> v(n);
	for (int &i : v) {
		cin >> i;
	}
	map<int, vector<int>> mm;
	for (int i = 0, a, b; i < m; ++i) {
		cin >> a >> b;
		--a;
		--b;
		mm[a].push_back(b);
		mm[b].push_back(a);
	}
	int res = 0;
	for (int i = 0; i < n; ++i) {
		int mx = 0;
		for (int j : mm[i]) {
			mx = max(mx, v[j]);
		}
		
		if (v[i] > mx) ++res;
	}
	cout << res;
}

Measured memory_bytes: 14288
n,m=map(int,input().split())
s=[[]for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    s[a-1].append(b-1)
    s[b-1].append(a-1)
t=[-1]*n
q=[0]
while q:
    p=[]
    for j in q:
        for i in s[j]:
            if i!=j and t[i]==-1:
                p.append(i)
                t[i]=j
    q=p[::]
print("Yes")
for i in t[1:]:
    print(i+1)

Measured memory_bytes: 34676
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
using namespace std;
#define EPS 1e-10

struct Point{
    double x,y;
    Point(){}
    Point(double _x,double _y){
        x=_x; y=_y;
    }
    Point operator +(const Point p)const{
        return Point(x+p.x,y+p.y);
    }
    Point operator -(const Point p)const{
        return Point(x-p.x,y-p.y);
    }
	Point operator *(const double d)const{
		return Point(x*d,y*d);
	}
};

struct Line{
    Point a,b;
    Line(){}
    Line(Point _a,Point _b){
        a=_a; b=_b;
    }
};

double dot(Point p,Point q){
    return p.x*q.x+p.y*q.y;
}

double cross(Point p,Point q){
    return p.x*q.y-q.x*p.y;
}

int ccw(Point a,Point b,Point c){
    if(cross(b-a,c-b)>0) return +1;
    if(cross(b-a,c-b)<0) return -1;
    return 0;
}

bool intersectSS(Line s,Line t) {
    return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 &&
           ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}

bool pss(Line l,Line m,Point &p){
    if(intersectSS(l,m)==false) return false;
	Point a1,a2,b1,b2;
	a1 = l.b-l.a; a2 = m.b-m.a;
	b1 = m.a-l.a; b2 = m.b-l.a;
	double s1,s2;
	s1 = abs(cross(a1,b1)/2); s2 = abs(cross(a1,b2)/2);
	if(s1<EPS && s2<EPS) return false;
	p = Point(m.a.x+a2.x*s1/(s1+s2),m.a.y+a2.y*s1/(s1+s2));
	/*if(p.x<min(l.a.x,l.b.x) || max(l.a.x,l.b.x)<p.x || p.x<min(m.a.x,m.b.x) || max(m.a.x,m.b.x)<p.x ||
	   p.y<min(l.a.y,l.b.y) || max(l.a.y,l.b.y)<p.y || p.y<min(m.a.y,m.b.y) || max(m.a.y,m.b.y)<p.y)
		return false;*/
	return true;
}

int main(){
	Line l[3];
	while(true){
		for(int i=0;i<3;i++){
			cin>>l[i].a.x>>l[i].a.y>>l[i].b.x>>l[i].b.y;
			if(l[i].a.x==0 && l[i].a.y==0 && l[i].b.x==0 && l[i].b.y==0) return 0;
		}
		Point p[3];
		bool kyo = false;
		for(int i=0;i<3;i++){
			if(pss(l[i],l[(i+1)%3],p[i])==false) kyo = true;
		}
		if(kyo==true){
			puts("kyo"); continue;
		}
		double s = abs(cross(p[1]-p[0],p[2]-p[0])/2);
		//printf("\t%lf\n",s);
		if(s<EPS) puts("kyo");
		else if(s<100000.0) puts("syo-kichi");
		else if(s<1000000.0) puts("kichi");
		else if(s<1900000.0) puts("chu-kichi");
		else puts("dai-kichi");
	}
    return 0;
}

Measured memory_bytes: 1176
S = input()
 
S = list(S)
 
ls = len(S)
count = 0
ans = 0
 #一番最後がATGCでなくとも対応可にしておく
for i in range(ls):
      if S[i] == 'A' or S[i] == 'T' or S[i] == 'G' or S[i] == 'C':
          count += 1
          if count >= ans:
              ans = count
      else:
          count = 0
 
print(ans)

Measured memory_bytes: 9124
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

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

	a := nextInt()
	b := nextInt()
	_ = nextInt()
	k := nextInt()

	ans := func() int {
		if a >= k {
			return k
		}
		if a+b >= k {
			return a
		}
		d := k - (a + b)
		return a - d
	}()

	fmt.Println(ans)
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, K;
    cin >> N >> K;
    vector<double> P(N);
    rep(i, N) cin >> P[i];
    vector<double> acc(N + 1, 0);
    rep(i, N) {
        acc[i + 1] += acc[i] + (1 + P[i]) / 2.0;
    }
    double ans = 0;
    rep2(i, K, N + 1) {
        ans = max(ans, acc[i] - acc[i - K]);
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3328
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val x = n % 500
    val a = (n-x)/500
    val y = x % 5
    val b = (x-y)/5
    var res = 0
    res += if (a > 0) a*1000 else 0
    res += if (b > 0) b*5 else 0
    println(res)
}

Measured memory_bytes: 31572
#include <iostream>
#include <string>
#define MOD 1000000007
using namespace std;

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

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

int A,B;
string S,T;
string U;

int main(){
    int A,B;
    cin >> S >> T >> A >> B;
    cin >> U;
    if(U==S){
        cout << A-1 <<" " <<  B << endl;
    }else{
        cout << A <<" " <<  B-1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void)
{
  double N;
  double lim;
  while(scanf("%lf", &lim) != EOF ) {
    for(N = 1;;N++){
      if((1.4 * sqrt((5.0*N - 5)*10.0)) >= lim){
	printf("%d\n", (int)N);
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
ll mod = 1e9 + 7;

int A,B;
int x[111];
ll coudp[111][111][5555];
string divide[4] = { "dream","dreamer","erase","eraser" };
int main()
{
	string data;
	int N;
	cin >> N;
	cin >> data;
	bool ans = true;

	if (data.size() % 2 == 1)
	{
		ans = false;
	}
	else if (data.size() % 2 == 0)
	{
		for (int i = 0; i < data.size() / 2; i++)
		{
			if (data.at(i) != data.at(data.size() / 2 +i))
			{
				ans = false;
			}
		}
	}
	if (ans)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}


}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	private static ArrayList<Long> fib = new ArrayList<Long>();

	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
         long N = sc.nextLong();

         long init = 1;

         for(int i = 0; i < N+1; i++){
        	 if(i==0){fib.add(init);continue;}
        	 if(i==1){fib.add(init);continue;}
        	 fib.add(fib.get(i-2) + fib.get(i-1));
         }

         System.out.println(fib.get(fib.size()-1));
	}
}

Measured memory_bytes: 17184
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,K;
  cin>>N>>K;
  vector<ll>A(N);
  REP(i,N)cin>>A[i];
  ll sum=accumulate(ALL(A),0ll);
  vector<ll>factors;
  for(int i=1;i*i<=sum;i++){
    if(sum%i==0){
      factors.push_back(i);
      if(i!=sum/i)factors.push_back(sum/i);
    }
  }
  sort(ALL(factors));
  sort(ALL(A));
  vector<ll>ans;
  for(auto e:factors){
    if(e==1){
      ans.push_back(1);
      continue;
    }
    vector<ll> tmp(N);
    REP(i,N)tmp[i]=A[i]%e;
    sort(ALL(tmp));
    ll tmpsum=accumulate(ALL(tmp),0ll);
    ll ma=N-tmpsum/e;
    ll cnt=0ll;
    REP(i,ma){
      cnt+=tmp[i];
    }
    if(cnt<=K)ans.push_back(e);
  }
  cout<<ans.back()<<endl;
}


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

int main() {
    char num[1001];
    while (1) {
        scanf("%s", num);
        if(num[0] == '0') break;
        int ans = 0;
        for (int i = 0; i < strlen(num); i++) {
            ans += (num[i] - 48);
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 2744
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

int chnum(char c) {
    if (c == 'm')
        return 1000;
    else if (c == 'c')
        return 100;
    else if (c == 'x')
        return 10;
    else if (c == 'i')
        return 1;
    else
        return 0;
}

string intToMcxi(int x) {
    string mcxi;
    char tmp[] = {'i', 'x', 'c', 'm'};
    for (int j = 4; j > 0; j--) {
        int div = 1;
        for (int k = 1; k < j; k++) {
            div *= 10;
        }
        int num = x / div;
        if (num > 0) {
            if (num > 1) mcxi += to_string(num);
            mcxi += tmp[j - 1];
        }
        x -= num * div;
    }
    return mcxi;
}

int mcxiToInt(string mcxi) {
    int ret = 0;
    for (int j = 0; j < mcxi.size(); j++) {
        int a = chnum(mcxi[j]);
        int b = 1;
        if (j > 0 && '0' <= mcxi[j - 1] && '9' >= mcxi[j - 1]) b = (int)(mcxi[j - 1] - '0');
        ret += a * b;
    }
    return ret;
}

string solve(string num1, string num2) {
    int v1     = mcxiToInt(num1);
    int v2     = mcxiToInt(num2);
    string ret = intToMcxi(v1 + v2);
    return ret;
}

int main() {
    int n;
    cin >> n;
    string num1, num2;
    // char c[4] = {m, c, x, i};
    // int v[4] = {1000, 100, 10, 1};

    vector<string> ans;

    for (int i = 0; i < n; i++) {
        cin >> num1 >> num2;
        ans.push_back(solve(num1, num2));
    }

    for (string s : ans) cout << s << endl;
}


Measured memory_bytes: 3396