akhauriyash/Code-Regression huggingface dataset:
// abc067_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    vector<ll> cumsum(N+1);
    REP(i, N) cumsum[i+1] = cumsum[i] + A[i];

    ll sm = cumsum[N];
    ll ans = 1e18;
    REP(i, N-1) {
        ll x = cumsum[i+1];
        ll y = sm - x;

        ans = min(ans, abs(x - y));
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 3456
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define mst(a,b) memset((a),(b),sizeof(a))
#define PII pair<int,int>
#define rep(i,x,y) for(auto i=(x);i<=(y);++i)
#define dep(i,x,y) for(auto i=(x);i>=(y);--i)
using namespace std;
template<class T>inline void rd(T &x) {
  x=0; int ch=getchar(),f=0;
  while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
  while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
  if(f)x=-x;
}
const int inf=0x3f3f3f3f;
string s,t,tt;
int n;
int main()
{
  cin>>s;
  n=s.size();
  t=s;tt=s;
  s=" "+s;
  string t1=s.substr(1,(n-1)/2);
  string t2=s.substr((n+3)/2);
  string t3=t1;reverse(t3.begin(),t3.end());
  string t4=t2;reverse(t4.begin(),t4.end());
  int f1,f2,f3;f1=f2=f3=0;
  if(t3==t1) f1=1;
  if(t2==t4) f2=1;
  reverse(tt.begin(),tt.end());
  if(tt==t) f3=1;
  if(f1&&f2&&f3) puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 256
n=int(input())
*l,=map(int,input().split())

#dの中に、ある整数に対し何個のボールがあるかの情報を格納。
d={}
for i in l:
  if i in d:
    d[i]+=1
  else:
    d[i]=1

#全部のボールを使えるときの数を計算。同時に、整数iが一つ減った時の値を計算。
all = 0
decrease = {}
for k, v in d.items():
  all+=v*(v-1)//2
  decrease[k] = v-1

#ループして出力
for i in l:
  print(all-decrease[i])

Measured memory_bytes: 32508
def prime_factorize(n):
    ans = []
    for i in range(2, int(n ** (1 / 2)) + 1):
        c = 0
        while True:
            if not n % i == 0:
                ans.append([i, c])
                break
            n //= i
            c += 1
        if n == 1:
            break
    if n != 1:
        ans.append([int(n), 1])
    return ans

n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
s = [0] * (5 * (10 ** 5))
for i in a:
    p = prime_factorize(i)
    for q in p:
        r = (q[0] - 1) // 2
        s[r] = max(s[r], q[1])
l = 1
for i in range(len(s)):
    l *= pow(max(2 * i + 1, 2), s[i], mod)
    l %= mod
ans = 0
for i in a:
    ans += pow(i, mod - 2, mod) * l % mod
    ans %= mod
print(ans)

Measured memory_bytes: 66396
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;
 
int main() {
    string s;
    cin >> s;

    bool f;
    if(s[0] == s[1] && s[0] != s[2] && s[2] == s[3]){ cout << "Yes" << endl; return 0;}
    if(s[0] != s[1] && s[0] == s[2] && s[1] == s[3]){ cout << "Yes" << endl; return 0;}
    if(s[0] != s[1] && s[1] == s[2] && s[0] == s[3]){ cout << "Yes" << endl; return 0;}

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1e9+7;
const ll  longinf = 1LL<<60;
const int mod=1e9+7;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  int a,b;
  cin>>b>>a;
  string s="",t="";
  rep(i,100){
    s+='.';
    t+='#';
    }
  cout<<"40 100"<<endl;
  rep(i,10){
    rep(j,50){
      if(a>1){
        cout<<"#.";
        a--;
        }
      else cout<<"..";
      }
    cout<<endl;
    cout<<s<<endl;
    }
   rep(i,10){
     cout<<t<<endl;
    rep(j,50){
      if(b>1){
        cout<<"#.";
        b--;
        }
      else cout<<"##";
      }
    cout<<endl;
    }
  
  return 0;
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;

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

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

ll invmod(ll a, ll m)
{
    return power(a,m-2,m);
}

int main()
{
    int n,k,i;
    cin>>n;
    int dp1[n+1]={},dp2[n+1]={},dp3[n+1]={};
    for(i=1;i<=n;i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        dp1[i]=a+max(dp2[i-1],dp3[i-1]);
        dp2[i]=b+max(dp1[i-1],dp3[i-1]);
        dp3[i]=c+max(dp1[i-1],dp2[i-1]);
    }
    cout<<max(dp1[n],max(dp2[n],dp3[n]));
    
}

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

int main(){
    int s[3];
    int tmp;
    cin >> s[0] >>s[1]>>s[2];
    for(int i=0;i<2; i++){
        if(s[i]>s[i+1]){
            tmp=s[i];
            s[i]=s[i+1];
            s[i+1]=tmp;
        }
        }
        cout << s[2]*10+s[1]+s[0] << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<math.h>
#include <algorithm>
using namespace std;

int main(){
  
  int N;
  cin>>N;
  
  int X[N];
  int sum=0;
  
  for(int i=0;i<N;i++){
    cin>>X[i];
    sum+=X[i];
  }
  
  int ave=sum/N;
  int ans=0;
  int ans1=0;
  int ans2=0;
  
  for(int i=0;i<N;i++){
    ans+=(X[i]-ave)*(X[i]-ave);
    ans1+=(X[i]-ave+1)*(X[i]-ave+1);
    ans2+=(X[i]-ave-1)*(X[i]-ave-1);
  }
  
  cout<<min({ans,ans1,ans2})<<endl;
  
  return 0;
}

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

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

int main()
{
	long long int n; cin>>n;
	long long int a[1000001];
	for(long long int i=0;i<n;i++) cin>>a[i];
	
	long long int l[1000001],r[1000001];
	
	l[0]=a[0],r[n-1]=a[n-1];
	
	for(long long int i=1,j=n-2;i<n;i++,j--)
	{
	   l[i]=gcd(l[i-1],a[i]);
	   r[j]=gcd(r[j+1],a[j]);
	}
	long long int m=0;
	for(long long int i=1;i<=n-2;i++) m=max(m,gcd(l[i-1],r[i+1]));
	
	m=max(m,l[n-2]);
	m=max(m,r[1]);
	cout<<m<<endl;
}

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

int main(){
    int N;
    string ans = "No";

    std::cin >> N;

    for(int i = 1; i <=9; i++){
        if(N%i == 0){
            if(N/i < 10){
                ans = "Yes";
            }
        }
    }
    std::cout << ans;


}

Measured memory_bytes: 3628
#include<stdio.h>
#include<math.h>
int main()
{
	int n;
	scanf("%d",&n);
	int res = n%10;
	if(res == 2 || res == 4 || res == 5 || res == 7 || res == 9)
	{
		printf("hon");
	}
	else if(res == 0 || res == 1 || res == 6 || res == 8)
	{
		printf("pon");
	}
	else
	{
		printf("bon");
	}
	return 0;
}

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

using namespace std;

double mx = -1;

int main() {
    ios_base::sync_with_stdio(false);
    
    int A, sol1 = 0, B, C, D, E, F, sol2 = 0;
    cin >> A >> B >> C >> D >> E >> F;
    
    for (int i = 0; i * 100 * A <= F; ++i) {
        for (int j = 0; j * 100 * B <= F; ++j) {
            for (int k = 0; k * C + 100 * A * i + 100 * B * j <= F; ++k) {
                for (int l = 0; l * D + k * C + 100 * A * i + 100 * B * j <= F; ++l) {
                    double wt = (i * 100 * A + j * 100 * B);
                    double sg = k * C + l * D;
                    if (wt + sg <= F && mx * (wt + sg) < 100.0 * sg && wt * E >= 100 * sg) {
                        mx = 100.0 * sg / (wt + sg);
                        sol1 = wt + sg;
                        sol2 = sg;
                    }
                }
            }
        }
    }
    
    cout << sol1 << ' ' << sol2 << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n;
    cin>>n;
    ll s=0;
    ll tmp=n;
    while(tmp/10!=0){
        s+=tmp%10;
        tmp/=10;
    }
    s+=tmp%10;
    if(n%s==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll m, n;
	cin >> m >> n;

	vl cost(m+1,oo);
	cost[0] = 0;
	while (n--) {
		ll a, b;
		cin >> a >> b;
		FOR(i,0,m+1) {
			cost[i] = min(cost[i], cost[max(0LL,i-a)] + b);
		}
	}
	cout << cost[m] << endl;
}



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

	else
	{
		printf("Right\n");
	}
	return 0;
}

Measured memory_bytes: 1648
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto x = readln.chomp.to!int;
  auto c = ('C' + (x / 1000)).to!char;
  writeln("AB" ~ c);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

//union-find
#define LIMIT 100
int uniroot[LIMIT+10],unicnt[LIMIT+10];
void ufinit(int n){for(int i=0;i<n;i++){uniroot[i]=i;unicnt[i]=1;}}
int root(int x){return uniroot[x]!=x?uniroot[x]=root(uniroot[x]):x;}
int same(int x,int y){return root(x)==root(y);}
void uni(int x,int y){if((x=root(x))==(y=root(y)))return;uniroot[x]=y;unicnt[y]+=unicnt[x];}

ll n,m;
ll a[60],b[60];
ll ans;
int main(){
	scanf("%lld%lld",&n,&m);
	rep(i,0,m)scanf("%lld%lld",a+i,b+i);
	rep(i,0,m){
		ufinit(n);
		rep(j,0,m)if(i!=j)uni(a[j]-1,b[j]-1);
		if(unicnt[root(1)]!=n)ans++;
	}
	printf("%lld\n",ans);
}

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

int main() {
    li n;
    cin>>n;
string s;
cin>>s;
string ans=s;
li cnt=0;
sort(s.begin(),s.end());
for(li i=0;i<n;i++){
    if(s[i]!=ans[i])
    cnt++;
}
cout<<cnt/2<<endl;
 return 0;
}


Measured memory_bytes: 3920
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ld pi = 3.14159265358;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,M;
    cin >> N >> M;
    vector<ll> coin(M);
    rep(i,M)cin >> coin[i];
    vector<ll> memo(N + 1,INF);
    memo[0] = 0;
    for(ll i = 1;i <= N;i++){
        rep(j,M){
            if(coin[j] <= i){
                memo[i] = min(memo[i],memo[i - coin[j]] + 1);
            }
        }
    }
    cout << memo[N] << endl;
}


Measured memory_bytes: 3332
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

var INF = 1e15;

function segTree(n){
  var l = n.length, u = l-1, x = 2, i, v;
  while(u)u >>= 1, x <<= 1;
  v = this.seg = Array(x-1).fill(INF);
  this.l = x = (x >> 1) - 1;
  for(i = 0; i < l; i++)v[i+x] = n[i];
  for(i = x-1; i >= 0; i--)v[i] = segSolve(v[i+i+1],v[i+1<<1]);
}
function segSolve(a,b){
  return Math.min(a,b);
}
segTree.prototype={
  get:function(l,r){//[l,r)
    if(l >= r)return 0;
    var v = this.seg;
    return q(l,r,0,this.l+1,0);
    function q(l,r,x,y,i){
      if(l === x && r === y)return v[i];
      var m = x+y >> 1;
      if(m < r)if(l < m)return segSolve(q(l,m,x,m,i+i+1),q(m,r,m,y,i+1<<1));
      else return q(l,r,m,y,i+1<<1);
      return q(l,r,x,m,i+i+1);
    }
  },
  update:function(x,i){
    var v = this.seg;
    i += this.l;
    v[i] = x;
    for(i = i-1>>1; i >= 0; i = i-1>>1){
      v[i] = segSolve(v[i+i+1],v[i+1<<1]);
    }
  },
}

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var e = o.m(m);
  e.sort((a,b)=>a[0]<b[0]?-1:a[0]>b[0]?1:a[1]-b[1]);
  var seg = new segTree(xArray(INF,n));
  seg.update(0,0);
  for(var i = 0; i < m; i++){
    var l = e[i][0], r = e[i][1], c = e[i][2];
    l--, r--;
    var cost = seg.get(l,r+1)+c;
    if(seg.get(r,r+1) > cost)seg.update(cost,r);
  }
  var ans = seg.get(n-1,n);
  if(ans >= 1e15)return -1;
  return ans;
}

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

int main() {
  int a;
  cin >> a;
  int b;
  cin >> b;
  int max = a + b;
  if (max < a - b) {
    max = a - b;
  }
  if (max < a*b) {
    max = a*b;
  }
  cout << max << endl;
}

Measured memory_bytes: 256
/*
 
dunjen_master
 
*/
 

#include<bits/stdc++.h>

 
using namespace std;
 
const int MAX_N = int(1e6) + 10;
const long long int MOD=1e9+7;
const long long int INF=1e18;

typedef long long int ll;

ll mul(ll a,ll b){

    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll c=a*b;
    c=(c+MOD)%MOD;
    return c;
}
ll add(ll a,ll b){
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll ans=(a+b);
    ans=(ans+MOD)%MOD;
    return ans;
}
ll power(ll a,ll b,ll c=0){
    ll ans=1;
    while(b){
        if(b&1){
            ans=mul(ans,a);
        }
        a=mul(a,a);
        b=b/2;
    }
    return ans;
}




int main(){
 
    
     int n;
    cin>>n;
 
    ll sum=0;
 
    for(int i=1;i<=n;i++){
        if(i%15==0 || i%3==0 || i%5==0){
             ;
        }else{
            sum+=i;
        }
    }
    cout<<sum<<endl;
 
 
    
    
 
    
}

    

    
 
    



Measured memory_bytes: 3636
#import collections
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
#import copy
#import numpy as np

#import bisect
k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()

s=0
for i in range(n-1):
    if a[i+1]-a[i]>s:
        s = a[i+1]-a[i]
if k-a[-1]+a[0]>s:
    s = k-a[-1]+a[0]
print(k-s)


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

typedef long long ll;
typedef long double ld;

ll pw(int x) {
	ll res = 1;
	for (int i = 1; i <= x; i++) {
		res *= 10;
	}
	return res;
}

int N = 100000;

char ask(ll x) {
	cout << "? " << x << endl;
	char c;
	cin >> c;
	return c;
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	int len = -1;
	for (int i = 0; i <= 10; i++) {
		if (ask(pw(i)) == 'N') {
			len = i;
			break;
		}
	}
	if (len == -1) {
		for (int i = 1; i <= 10; i++) {
			if (ask(pw(i) + 1) == 'Y') {
				len = i + 1;
				break;
			}
		}
		if (len == 2) {
			if (ask(2) == 'Y') {
				len = 1;
			}
		}
	}
	ll l = pw(len - 1) - 1, r = pw(len) - 1;
	while (r - l > 1) {
		ll m = (l + r) / 2;
		if (ask(m * 10) == 'N') {
			l = m;
		} else {
			r = m;
		}
	}
	cout << "! " << r << endl;
}



Measured memory_bytes: 684
import java.util.*
fun main(args:Array<String>) {
   val (N, K)  = readLine()!!.split(" ").map(String::toInt)
  var prob = if(N>=K) {(N-(K-1)).toDouble()} else {0.0}
  for(n in 1..arrayOf(N,K-1).min()!!) {
      val num = Math.ceil(Math.log(K.toDouble()/ n.toDouble()) / Math.log(2.0)) 
      prob+= Math.pow(0.5,num)
  }
  prob /= N.toDouble()
  println(prob)
}

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


/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)


#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;


    ll n;


    cin >> n;

    ll a[n+1];


    for(int i=0; i<n; i++)
        cin >> a[i];


        ll count = 0;



        ll mn = a[0] , mx = a[0];

        ll count1 = 0;


        for(int i=1; i<n; i++)
        {
            if(mn>=a[i] && mx>=a[i])
            {
                count1++;

                mn = a[i];
                mx = a[i];

               // cout << i << endl;

            }
            else if(a[i]<mn)
            {
                mn = a[i];
            }
            else if(a[i]>mx)
            {
                mx = a[i];
            }

        }

        cout << count1+1 << endl;





    return 0;
}



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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

vector<long long> divisors(long long n) {
    vector<long long> v;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            v.push_back(i);
            if (i * i != n) {
                v.push_back(n / i);
            }
        }
    }
    return v;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    int s = 0;
    REP(i, n) {
        cin >> a[i];
        s += a[i];
    }

    vector<ll> d = divisors(s);
    sort(ALL(d), greater<int>());
    REP(i, d.size()) {
        vector<int> mn;
        int x;
        REP(j, n) {
            x = a[j] % d[i];
            if (x != 0) {
                mn.push_back(x);
            }
        }
        sort(ALL(mn));
        vector<int> mx(mn.size());
        REP(j, mn.size()) {
            mx[j] = d[i] - mn[j];
        }
        sort(ALL(mx));

        vector<int> smin(mn.size() + 1, 0);
        REP1(j, mn.size()) {
            smin[j] = smin[j - 1] + mn[j - 1];
        }
        vector<int> smax(mn.size() + 1, 0);
        REP1(j, mx.size()) {
            smax[j] = smax[j - 1] + mx[j - 1];
        }
        int sz = smin.size();
        REP(j, sz) {
            if (smin[j] == smax[sz - 1 - j] && k >= smin[j]) {
                cout << d[i] << endl;
                return 0;
            }
        }
    }
    cout << 1 << endl;
}


Measured memory_bytes: 256
def func(x):
  if(x % 2 == 0):
    return x / 2
  else:
    return 3 * x + 1

s = int(input())
if((s == 1) or (s == 2)):
  print(4)
  exit()
  
cnt = 1
while(s != 1):
  s = func(s)
  cnt += 1
print(cnt + 1)



Measured memory_bytes: 2940
from math import ceil


def five_transportations(N: int, A: int, B: int, C: int, D: int, E: int)->int:
    return 5 + ceil(N / min(A, B, C, D, E)) - 1


if __name__ == "__main__":
    inputs = [int(input()) for _ in range(6)]
    N, A, B, C, D, E = inputs
    ans = five_transportations(N, A, B, C, D, E)
    print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll n; cin >> n;
    ll v[n];
    ll ac[200010];
    memset(ac, 0, sizeof ac);
    for(int i = 0; i < n; i++){
        cin >> v[i];
        ac[v[i]]++;
    }
    ll ans = 0;
    for(int i = 0; i < 200010; i++)
        ans += (ac[i] * (ac[i] - 1)) / 2;
    for(int i = 0; i < n; i++){
        ll rta = ans - (ac[v[i]] - 1);
        cout << rta << "\n";
    }
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (n); i++)
 
int main(){
    int N;
    string S,T;
    cin >> N;
    cin >> S >> T;
    rep(i,N){
        cout << S[i];
        cout << T[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
a=list(reversed(input()))
num=len(a)
mod_map={0:1}
moji_int=0
Sn=0
tens=1
for i in a:
    tmp=int(i)*(tens)
    Sn=(Sn+tmp)%2019
    mod=Sn
    tens=tens*10%2019
    if mod not in mod_map:
        mod_map[mod]=1
    else:
        mod_map[mod]+=1


res=0
for i in mod_map.values():
    res+=int(i*(i-1)/2)
print(res)


Measured memory_bytes: 10652
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	int ans = 0;
	vector<vector<int>> con(10, vector<int>(10));
	
	cin>>N;
	
	for(int i = 1; i <= N; i++){
		int a = i%10, b = i%10, c = i;
		
		while(c){
			b = c%10;
			c /= 10;
		}
		con[a][b]++;
	}
	
	for(int i = 1; i <= N; i++){
		int a = i%10, b = i%10, c = i;
		
		while(c){
			b = c%10;
			c /= 10;
		}
		ans += con[b][a];
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}



int main() {
	int a, b, c,d; cin >> a>>b>>c;
	//string s,t,u; cin >> s>>t>>u;
	if (a + b == c || a + c == b || b + c == a)cout << "Yes";
	else cout << "No";

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;


int main() {
    int K, T;
    cin >> K >> T;
    vector<int> a(T);
    for (int i = 0; i < T; i++){
        cin >> a.at(i);
    }
    sort(rALL(a));
    if (K % 2 == 0){
        if (a.at(0) * 2 <= K){
            cout << 0 << endl;
        }
        else {
            cout << 2 * a.at(0) - K - 1<< endl;
        }
    }
    else {
        if (a.at(0) * 2 - 1 <= K){
            cout << 0 << endl;
        }
        else {
            cout << 2 * a.at(0) - K << endl;
        }
    }
}


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

ans = 1e+9

for si in range(len(s)):
    if si + len(t) > len(s):
        continue
    cnt = 0
    for ti in range(len(t)):
        if s[si+ti] != t[ti]:
            cnt += 1
    ans = min(ans, cnt)

print(ans)

Measured memory_bytes: 9064
A,B,C,X,Y = map(int, input().split())
minAB = min(X,Y)
maxAB = max(X,Y) - minAB
ans = 0
# C2枚のほうがお得
if A + B > C * 2:
    ans = minAB * C * 2
else:
    ans = minAB * A + minAB * B

# X or Y の残りをCと比較して計算
if X > Y:
    # C2枚のほうがお得
    if A > C * 2:
        ans += maxAB * C * 2
    else:
        ans += maxAB * A
else:
    # C2枚のほうがお得
    if B > C * 2:
        ans += maxAB * C * 2
    else:
        ans += maxAB * B

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
	int w,h,c,x;
	scanf("%d%d%d",&w,&h,&c);
	if(w<h) x=h;
	else x=w;
	while(w%x!=0||h%x!=0) x--;
	printf("%d\n",((w/x)*(h/x)*c));
	return 0;
}

Measured memory_bytes: 2736
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    String str = sc.next();
    char[] ch = new char[str.length()];
    for(int i = 0; i < str.length(); i++) ch[i] = str.charAt(i);
    for(int i = 0; i < str.length(); i++) {
      if(ch[i] + n <= 'Z') ch[i] += n;
      else ch[i] -= (26 - n);
    }
    System.out.println(ch);
  }
}


Measured memory_bytes: 23124
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Scanner;

public class Main{
	public static int n;
	public static final int max = 1000000;
	public static ArrayList<Integer> all;
	public static ArrayList<Integer> odd;
	public static void main(String[] args){
		all = new ArrayList<Integer>();
		odd = new ArrayList<Integer>();
		for(int i=1; i<=1000; i++){
			long num = (long)i*(i+1)*(i+2)/6;
			if(num > max) break;
			all.add((int)num);
			if(num % 2 == 1){
				odd.add((int)num);
			}
		}
		Scanner in = new Scanner(System.in);
		while(true){
			n = in.nextInt();
			if(n == 0) return;
			resall = max;
			resodd = max;
			dfsall(all.size()-1, 0, 0);
			dfsodd(odd.size()-1, 0, 0);
			System.out.println(resall+" "+resodd);
		}
	}
	
	public static int resodd;
	public static void dfsodd(int start, int sum, int depth){
		if(sum == n){
			resodd = Math.min(resodd, depth);
			return;
		}
		if(sum > n || depth >= resodd) return;
		for(int i=start; i>=0; i--){
			dfsodd(i, sum+odd.get(i), depth+1);
		}
	}
	
	public static int resall;
	public static void dfsall(int start, int sum, int depth){
		if(sum == n){
			resall = Math.min(resall, depth);
			return;
		}
		if(depth >= 5 || sum > n) return;
		for(int i=start; i>=0 && sum+all.get(i)*(5-depth)>=n; i--){
			dfsall(i, sum+all.get(i), depth+1);
		}
	}
}

Measured memory_bytes: 20236
/*
 * ITP1_6_B.cpp
 *
 *  Created on: Apr 20, 2018
 *      Author: 13743
 */

#include<iostream>

using namespace std;

void printSeq(int *s, int n) {
	cout << s[0];
	for(int i=1; i<n; i++) {
		cout << " " << s[i];
	}
	cout << endl;
}

int main() {
	int N;
	int seq[100];
	cin >> N;
	for(int i=0; i<N; i++) {
		cin >> seq[i];
	}
	printSeq(seq, N);
	for(int i=1; i<N; i++) {
		int key = seq[i];
		int j = i - 1;
		while(j >= 0 && seq[j] > key) {
			seq[j+1] = seq[j];
			j--;
		}
		seq[j+1] = key;
		printSeq(seq, N);
	}
}



Measured memory_bytes: 3100
N,M,Q = gets.split.map(&:to_i)
Constraints = $<.map{|ln| ln.split.map(&:to_i) }.sort_by{|a,b,| a<<4|b }

def each(arr, &block)
	if arr.size == N+1
		yield arr
	else
		arr.last.upto(M){|a|
			each arr+[a], &block
		}
	end
end

max = 0
each([1]){|arr|
	max = [Constraints.sum{|a,b,c,d|
		arr[a] + c == arr[b] ? d : 0
	},max].max
}
p max


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  // 「1の個数」と「0の個数」を交互に記録しておく
  vector<int> nums;
  if (S[0] == '0')
    nums.push_back(0);

  for (int i = 0; i < S.size();)
  {
    int j = i;
    while (j < S.size() && S[j] == S[i])
      ++j;
    nums.push_back(j - i);
    i = j;
  }

  if (S.back() == '0')
    nums.push_back(0);

  // 累積和
  vector<int> sums((int)nums.size() + 1, 0);

  for (int i = 0; i < nums.size(); i++)
    sums[i + 1] = sums[i] + nums[i];

  // 偶数番目の添え字から始まる，長さ2K + 1（以下）の区間の総和のうち，最大値を求める
  int res = 0;
  for (int left = 0; left < sums.size(); left += 2)
  {
    int right = left + 2 * K + 1;
    if (right >= sums.size())
      right = sums.size() - 1;
    res = max(res, sums[right] - sums[left]);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1272
#include<iostream>
#include <string>
using namespace std;
int main(){
    int D;
    cin >> D;
    if (D == 25){
        cout << "Christmas" << endl;
    }
    else if (D == 24){
        cout << "Christmas Eve" << endl;
    }
    else if (D == 23){
        cout << "Christmas Eve Eve" << endl;
    }
    else{
        cout << "Christmas Eve Eve Eve" << endl;
    }
    return 0;

}


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

ld dp[3010][3010];
ll N;

int main(int argc, char **argv)
{
	cin >> N;
	vector<ld> P(N);
	for (ll i = 0; i < N; ++i) cin >> P[i];

	dp[0][0] = 1.f;
	for (ll i = 0; i < N; ++i)
	{
		for (ll j = 0; j <= i; ++j)
		{
			dp[i+1][j+1] += dp[i][j] * P[i];
			dp[i+1][j] += dp[i][j] * (1 - P[i]);
		}
	}

	ld res{0.0};
	for (ll i = (N+1)/2; i <= N; ++i) res += dp[N][i];
	std::cout << fixed << setprecision(10) << res << std::endl;
}

Measured memory_bytes: 139776
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    A, B, C, D, E, F = map(int, input().split())

    w_list, s_list = [False] * 3001, [False] * 3001
    for i in range(F // (A * 100) + 1):
        for j in range(F // (B * 100) + 1):
            w = 100 * A * i + 100 * B * j
            if w <= 3000:
                w_list[w] = True
    for i in range(F // C + 1):
        for j in range(F // D + 1):
            s = C * i + D * j
            if s <= 3000:
                s_list[s] = True

    best = -INF
    ans = 0, 0
    for s in range(len(s_list)):
        for w in range(len(w_list)):
            if s + w <= F and s_list[s] and w_list[w]:
                total = s + w
                if total > 0 and s <= w // 100 * E:
                    if s / total > best:
                        best = s / total
                        ans = total, s

    print(ans[0], ans[1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

vector<vi> G(100100);
int d[3][100100];
int main() {
  int n,u,v;
  cin >> n >> u >> v;
  u--;v--;
  rep(i,n-1){
    int x,y;
    cin >>x >>y;
    x--;y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  queue<int> q;
  q.push(u);
  rep(i,3)rep(j,100100)d[i][j] = -1;
  d[0][u] = 0;
  while(!q.empty()){
    int a = q.front();
    q.pop();
    for(auto b: G[a]){
      if(d[0][b] == -1){
        d[0][b] = d[0][a]+1;
        q.push(b);
      }
    }
  }
  //show("ok");
  d[1][v] = 0;
  q.push(v);
  while(!q.empty()){
    int a = q.front();
    q.pop();
    for(auto b: G[a]){
      if(d[1][b] == -1){
        d[1][b] = d[1][a]+1;
        q.push(b);
      }
    }
  }

  int mi = INT_MAX;
  rep(i,n){
    if(d[0][i] < d[1][i])
      mins(mi,i);
  }

  d[2][v] = d[2][mi];
  q.push(v);
  while(!q.empty()){
    int a = q.front();
    q.pop();
    for(auto b: G[a]){
      if(d[2][b] == -1){
        d[2][b] = d[2][a]+1;
        q.push(b);
      }
    }
  }
  int mx = 0;
  rep(i,n){
    if(d[0][i] < d[1][i])
    maxs(mx,d[2][i]);
  }
  if(sz(G[u]) == 1 && G[u][0] == v)mx=0;
  cout<<mx<<endl;
  return 0;
}

Measured memory_bytes: 7040
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;


Int n, a, b, c, d;

vector<int> edge[220000], dists;
set<int> blue[220000], red[220000];
Int parent[30][220000];
Int dep[220000];

vector<Int> u(220000, -1);

Int r(int x){
    if(u[x] == -1)return x;
    return u[x] = r(u[x]);
}

void unite(int x, int y){
    x = r(x);
    y = r(y);
    u[x] = y;
}


void ok(){
    cout << "YES" << endl;
    exit(0);
}

void ng(){
    cout <<  "NO" << endl;
    exit(0);
}



int main(){
    cin >> n;
    for(int i = 0;i < n-1;i++){
        cin >> a >> b;
        blue[a].insert(b);
        blue[b].insert(a);
    }

    queue<P> q;
    for(int i = 0;i < n-1;i++){
        cin >> c >> d;
        red[c].insert(d);
        red[d].insert(c);
        if(blue[c].count(d)){
            q.push(P(c,d));
        }
    }

    int cnt = 0;
    
    while(!q.empty()){
        auto tmp = q.front();q.pop();
        int x = tmp.first, y = tmp.second;
        x = r(x);
        y = r(y);
        if(red[x].empty() || red[y].empty())continue;
        cnt++;
        if(red[x].size() + blue[x].size() > red[y].size() + blue[y].size())swap(x, y);

        for(auto r:red[x]){
            if(blue[y].count(r)){
                q.push(P(y, r));
            }
        }
        for(auto b:blue[x]){
            if(red[y].count(b)){
                q.push(P(y, b));
            }
        }
        for(auto r:red[x]){
            red[r].erase(x);
            if(y != r){
                red[r].insert(y);
                red[y].insert(r);
            }
        }
        for(auto b:blue[x]){
            blue[b].erase(x);
            if(y != b){
                blue[y].insert(b);
                blue[b].insert(y);
            }
        }
        red[x].clear();
        blue[x].clear();
        unite(x,y);
    }

    if(cnt == n-1)ok();
    else ng();
    return 0;
}

Measured memory_bytes: 37632
chomp($n = <>);
if($n <= 8){
	print "0\n";
	exit;
}

$r = 0;
for $i (9 .. $n){
	next if($i % 2 == 0);
	$cnt = 0;
	for $p (1 .. $i){
		$cnt++ if($i % $p == 0);
	}
	$r++ if($cnt == 8);
}

print "$r\n";


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int inf = 1e9;
int n;
string s;

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	cin>>n;
	map<string,int> m;
	for(int i = 0; i < n; ++i){
		cin>>s;
		m[s]++;
	}
	cout<<m.size()<<endl;
	return 0;
}


Measured memory_bytes: 19276
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n){
    int a;
    cin >> a;
    mp[a]++;
  }
  int ans = 0;
  for(auto p : mp){

    int add = p.second;
    if(mp.count(p.first-1) == 1) add += mp[p.first-1];
    if(mp.count(p.first+1) == 1) add += mp[p.first+1];
    ans = max(ans, add);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3200
/*
  ∧,,∧
( 'ω' )つ ＜またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()

typedef long long LL;
typedef long double LD;

int main()
{
    int N, M;
    cin >> N >> M;
    int pr[N][M] = {};

    int K, temp;
    for (int i = 0; i < N; i++) {
        cin >> K;
        for (int j = 0; j < K; j++) {
            cin >> temp;
            pr[i][temp-1] = 1;
        }
    }

    int ans, cnt = 0;
    for (int j = 0; j < M; j++) {
        cnt = 0;
        for (int i = 0; i < N; i++) {
            if (pr[i][j]) cnt++;
        }
        if (cnt >= N) ans++;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define ll long long
#define mod 1000000007
int Pow(int a, int k)
{
	if (!k)
		return 1;
	int p = Pow(a, k / 2);
	if (k & 1)
		return (ll)p * p % mod * a % mod;
	return (ll)p * p % mod;
}
void Add(int &a, int b)
{
	a += b;
	if (a >= mod)
		a -= mod;
}
int fac[N], inv[N];
int n, m, A[25], dp[1 << 16];
int main()
{
	fac[0] = 1;
	for (int i = 1; i <= 100000; i++)
		fac[i] = (ll)i * fac[i - 1] % mod;
	inv[100000] = Pow(fac[100000], mod - 2);
	for (int i = 100000; i >= 1; i--)
		inv[i - 1] = (ll)i * inv[i] % mod;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
		scanf("%d", &A[i]);
	sort(A + 1, A + m + 1);
	dp[0] = 1;
	for (int i = m; i >= 1; i--)
	{
		for (int j = (1 << n) - 1; j >= 0; j--)
		{
			int lst = (1 << n) - A[i] + 1 - j;
			if (lst < 0)
				continue;
			for (int k = 0; k < n; k++)
				if ((lst >> k) && !((j >> k) & 1))
					Add(dp[j | (1 << k)], (ll)dp[j] * fac[lst - 1] % mod * inv[lst - (1 << k)] % mod * (1 << k) % mod);
		}
	}
	int ans = 0;
	for (int j = 0; j < (1 << n); j++)
	{
		int now = (ll)dp[j] * fac[(1 << n) - j - 1] % mod;
		int bit = 0;
		for (int k = 0; k < n; k++)
			if (j & (1 << k))
				bit++;
		if (bit & 1)
			Add(ans, mod - now);
		else
			Add(ans, now);
	}
	ans = (ll)ans * (1 << n) % mod;
	printf("%d\n", ans);
}


Measured memory_bytes: 1280
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(h, w) = in.readLine().split("\\s+").map(_.toLong)

    out.println(
      if (h == 1 || w == 1) {
        1
      } else {
        ((w + 1) / 2) * ((h + 1) / 2) + (w / 2) * (h / 2)
      }
    )
    out.flush()
  }
}


Measured memory_bytes: 25544
#include <iostream>
#include <cstdlib>

using namespace std;



int main(){


  int H,W,a;
  char graph[64][64];
  int cou[64][64] = {{}};
  string c;

  cin >> H >> W;

  for(int i = 0;i < H;i++){
    for(int j = 0;j < W;j++){
      cin >> graph[i][j];
    }
  }


  for(int i = 0;i < H;i++){
    for(int j = 0;j < W;j++){
      c ="";
      c += graph[i][j];
      a = atoi(c.c_str());

      if(i == 0 && j == 0) cou[i][j] = 0;
      else if(j == 0) cou[i][j] = cou[i - 1][j] + a;
      else if(i == 0) cou[i][j] = cou[i][j - 1] + a;
      else cou[i][j] = min(cou[i - 1][j],cou[i][j - 1]) + a;

    
    }
  }




  cout << cou[H - 1][W - 1] << endl;

}

Measured memory_bytes: 3176
n,k=map(int,input().split())
lst=list(map(int,input().split()))
mod=10**9+7

plst=sorted([x for x in lst if x>=0],reverse=True)
nlst=sorted([abs(x) for x in lst if x<0],reverse=True)
out=[None for _ in range(k)]
lenn=len(nlst)
lenp=len(plst)



if lenp==0 and k%2==1:
    sm=1
    for i in range(lenn-1,lenn-k-1,-1):
        sm*=-nlst[i]
        sm%=mod
    print(sm)
    exit()

if n==k:
    sm=1
    for x in lst:
        sm*=x
        sm%=mod
    print(sm)
    exit()



ptoken=0
ntoken=0
token=0
pm=0



while token<k:
    if ptoken==lenp:
        out[token]=nlst[ntoken]
        pm=(pm+1)%2
        ntoken+=1
    elif ntoken==lenn:
        out[token]=plst[ptoken]
        ptoken+=1
    elif plst[ptoken]>nlst[ntoken]:
        out[token]=plst[ptoken]
        ptoken+=1
    else :
        out[token]=nlst[ntoken]
        pm=(pm+1)%2
        ntoken+=1
    token+=1

if pm==1:
    if ptoken==lenp:          
        out.remove(plst[ptoken-1])
        out.append(nlst[ntoken])
    elif ntoken==lenn:
        out.remove(nlst[ntoken-1])
        out.append(plst[ptoken])
    elif ptoken==0 : 
        out.remove(nlst[ntoken-1])
        out.append(plst[ptoken])
    else : 
        if nlst[ntoken-1]*nlst[ntoken]>=plst[ptoken-1]*plst[ptoken]:
            out.remove(plst[ptoken-1])
            out.append(nlst[ntoken])
        else :
            out.remove(nlst[ntoken-1])
            out.append(plst[ptoken])               

sm=1
for x in out:
    sm*=x
    sm%=mod

print(sm)
    

Measured memory_bytes: 31944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9;
const int MOD = 1e9 + 7;

int n, k;
int r, s, p;
string t;
string u;
ll ans = 0;

int main(){
  cin >> n >> k;
  cin >> r >> s >> p;
  cin >> t; 
  rep(i, n){
   char hand;
    if(t.at(i) == 'r'){
      hand = 'p';
    }else if(t.at(i) == 's'){
      hand = 'r';
    }else{
      hand = 's';
    }
    if(i >= k && u.at(i - k) == hand){
      hand = 'a';
    }
    if(hand == 'r'){
      ans += r;
    }else if(hand == 's'){
      ans += s;
    }else if(hand == 'p'){
      ans += p;
    }
    u += hand;
  }

  cout << ans <<endl;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		boolean[] data=makePrime();
		
		while(true) {
			int n=in.nextInt();
			if(n==0)break;
			
			int cnt=0;
			for(int i=n+1;i<=n*2;i++) {
				if(data[i])cnt++;
			}
			
			System.out.println(cnt);
		}
	}
	
	static boolean[] makePrime() {
		int n=123456*2+1,E=(int)Math.sqrt(n);
		boolean primes[]=new boolean[n];
		Arrays.fill(primes, true);
		
		for(int i=2;i<=E;i++) {
			if(primes[i]) {
				for(int j=i*2;j<n;j+=i)primes[j]=false;
			}
		}
		
		return primes;
	}

}



Measured memory_bytes: 27712