akhauriyash/Code-Regression huggingface dataset:
//MondSum
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();

    long total=0;
    for (int i=0;i<n;i++) {
      total=total+i;
    }
     System.out.println(total);
  }
}


Measured memory_bytes: 23892
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>

using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main()
{
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> hs(h), ws(w);
    set<P> s;
    for (int i = 0; i < n; i++)
    {
        int r, c;
        cin >> r >> c;
        r--;
        c--;
        hs[r]++;
        ws[c]++;
        s.emplace(r, c);
    }
    int mh = 0, mw = 0;
    for (int i = 0; i < h; i++)
    {
        mh = max(mh, hs[i]);
    }
    for (int i = 0; i < w; i++)
    {
        mw = max(mw, ws[i]);
    }
    vector<int> is, js;
    for (int i = 0; i < h; i++)
    {
        if (mh == hs[i])
        {
            is.push_back(i);
        }
    }
    for (int i = 0; i < w; i++)
    {
        if (mw == ws[i])
        {
            js.push_back(i);
        }
    }
    int ans = mh + mw;
    for (int i = 0; i < is.size(); i++)
    {
        for (int j = 0; j < js.size(); j++)
        {
            if (s.count(P(is[i], js[j])))
            {
                continue;
            }
            cout << ans << endl;
            return 0;
        }
    }
    --ans;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 23812
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20,mod=1e9+7;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

ll n,m,s[N],ans;

int main() {
	qr(n); qr(m); n++;
	for(int i=1;i<=n;i++) {
		s[i]=(s[i-1]+i)%mod;
		if(i>=m) (ans+=i*(n+1)-2*s[i]+1)%=mod;
	}
	pr2(ans);
	return 0;
}



Measured memory_bytes: 5132
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 100010
#define inf 0x7fffffff
/*------------------------------------------------------------*/

int main(){
	string s;
	cin>>s;
	out(s[0]+s[1]+s[2]-48-48-48);
}

Measured memory_bytes: 256
#include <cstdio>

int main(void) {
  int N;
  scanf("%d", &N);
  char reply[N+2];
  scanf("%s", reply);
  reply[N] = reply[0]; reply[N+1] = reply[1];// reply N, N+1を忘れないように
  
  int animal[N+2];

  for (int initial = 0; initial < 4; initial++) {
    animal[0] = initial / 2;
    animal[1] = initial % 2;

    for (int i = 0; i < N; i++) {
      if (animal[i+1] == 0) {
        if (reply[i+1] == 'o') animal[i+2] = animal[i]; 
        else animal[i+2] = 1-animal[i];
      } else {
        if (reply[i+1] == 'o') animal[i+2] = 1-animal[i];
        else animal[i+2] = animal[i];
      }
    }
    if (animal[0] == animal[N] && animal[1] == animal[N+1]) {
      for (int j = 0; j < N; j++) {
        if (animal[j] == 0) printf("S");
        else printf("W");
      }
      printf("\n");
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
 


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> swi(n);

    for (int i = 0; i < m; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int tmp;
            cin >> tmp;
            swi[tmp - 1].push_back(i);
        }
    }

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

    int ret = 0;
    for (int i = 0; i < 1 << n; i++) {

        vector<int> count(m);
        for (int j = 0; j < n; j++)
            if ((i & (1 << j)) > 0)
                for (auto x:swi[j])count[x]++;

        bool flag = true;
        for (int j = 0; j < m; j++) {
            if (count[j] % 2 != p[j])flag = false;
        }

        if (flag)ret++;
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define MAX_N 200000

ll mod = 1000000007;

ll factorial[MAX_N + 1];
ll factorial_inverse[MAX_N + 1];

ll extgcd(ll a,ll b,ll &x,ll & y) {
    if(b == 0) {
        x = 1,y = 0;
        return a;
    }

    ll d = extgcd(b,a % b,y,x);
    y -= (a / b) * x;
    return d;
}

void precom(ll N) {
    factorial[0] = factorial_inverse[0] = 1;

    for(ll i = 1;i <= N;i++) {
        factorial[i] = factorial[i - 1] * i % mod;
    } 
    ll y;
    extgcd(factorial[N],mod,factorial_inverse[N],y);

    for(ll i = N - 1;i > 0;i--){
        factorial_inverse[i] = factorial_inverse[i + 1] * (i + 1) % mod;
    }
}

ll C(ll n,ll k) {
    return factorial[n] * factorial_inverse[k] % mod * factorial_inverse[n - k] % mod;
}

vector<ll> ps;
vector<ll> e;

void div(ll n) {
    for(int i = 2;i <= sqrt(n);i++) {
        if(n % i == 0) {
            div(i);
            div(n / i);
            return;
        }
    }
    ps.pb(n);
    return;
}
ll n,m;
int main(){
    cin >> n >> m;
    if(m == 1) {
        cout << 1 << endl;
        return 0;
    }
    div(m);

    sort(ps.begin(),ps.end());

    ll c = 0;
    rep(i,ps.size()) {
        c++;
        if(i == ps.size() - 1 || ps[i] != ps[i + 1]) {
            e.pb(c);
            c = 0;
        }
    }

    precom(200000);

    ll ans = 1;

    for(auto v : e) {
        (ans *= C(n + v - 1,v)) %= mod;
    }

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



Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> set(5,0);
  for(int i=0; i<N; i++){
    string s;
    cin >> s;
    if(s[0]=='M') set[0]++;
    if(s[0]=='A') set[1]++;
    if(s[0]=='R') set[2]++;
    if(s[0]=='C') set[3]++;
    if(s[0]=='H') set[4]++;
  }
  long long ans=0; 
  for(int i=0; i<(1<<5); i++){
    int num=0;
    long long temp=1;
    for(int j=0; j<5; j++){
      if(1& i>>j){
        num++;
        temp*=set[j];
      }
    }
    if(num!=3) continue;
    ans+=temp;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
// https://atcoder.jp/contests/abc145/tasks/abc145_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

const int MOD = 1e9 + 7;
const int SZ = 1e6;

template <int N, typename T, T M> struct factorial_mod {
    T mod[N + 1];
    T inv_mod[N + 1];

    constexpr factorial_mod() : mod(), inv_mod() {
        mod[0] = 1;
        for (int i = 0; i < N; ++i) {
            mod[i + 1] = (mod[i] * (i + 1)) % M;
        }
        inv_mod[N] = power(mod[N], M - 2);
        for (int i = N - 1; i >= 0; --i) {
            inv_mod[i] = (inv_mod[i + 1] * (i + 1)) % M;
        }
    }

    constexpr T power(T a, T b) {
        T r = 1;
        while (b > 0) {
            if ((b & 1) != 0)
                r = (r * a) % M;
            a = (a * a) % M;
            b >>= 1;
        }
        return r;
    }

    constexpr T permutation(T n, T r) { return (mod[n] * inv_mod[n - r]) % M; }
    constexpr T combination(T n, T r) {
        return (((mod[n] * inv_mod[r]) % M) * inv_mod[n - r]) % M;
    }
    constexpr T homogenious(T n, T r) {
        return (n == 0 and r == 0 ? 1 : combination(n + r - 1, r));
    }
};
factorial_mod<SZ, long long, MOD> facmod;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int X, Y;
    cin >> X >> Y;
    if (X > Y) {
        swap(X, Y);
    }
    // 今後X < Yとする
    if ((X + Y) % 3 != 0) {
        cout << "0\n";
        return 0;
    }
    // 移動回数は(n + m) = (X + Y) / 3;
    // X座標は n + 2m = X;
    // Y座標は 2n + m = Y;
    // 以上から
    // m = X - (X + Y)/3;
    // n = Y - (X + Y)/3;
    int m = X - (X + Y) / 3;
    int n = Y - (X + Y) / 3;
    if (m < 0 || n < 0) {
        cout << "0\n";
        return 0;
    }
    cout << facmod.combination(m + n, m) << endl;

    return 0;
}


Measured memory_bytes: 19140
#include <iostream>
#include <string>

using namespace std;

int main() {
  string N;
  cin >> N;
  
  if (N == "Sunny") {
    cout << "Cloudy" << endl;
  } else if (N == "Rainy") {
    cout << "Sunny" << endl;
  } else {
     cout << "Rainy" << endl;
  }
  return 0;
}

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

set<long long> all;
void calc(int x, int y) {
	if(x == 0) {
		return;
	}
	for(int i = 3; i <= 7; i += 2) {
		all.insert(y * 10 + i);
		calc(x - 1, y * 10 + i);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	
	int n; cin >> n;
	calc(9, 0);
	vector<long long> e;
	for(auto i = all.begin(); i != all.end(); i++) {
		set<int> s;
		long long tmp = *i;
		while(tmp > 0) {
			s.insert(tmp % 10);
			tmp /= 10;
		}
		if(*i > n || s.size() != 3) {
			e.push_back(*i);
		}
	}
	for(int i = 0; i < e.size(); i++) {
		all.erase(e[i]);
	}
	cout << all.size() << endl;
		
	return 0;	
}


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

using namespace std;

set <string> substrs;
vector <string> smallest_K;
int main(){
    string S;
    int K;
    cin >> S;
    cin >> K;


    for(int i = 0; i < S.size(); i++){
        for(int j = i + 1; j <= S.size(); j++){
            string cur = S.substr(i, j - i);
            if(find(smallest_K.begin(), smallest_K.end(), cur) != smallest_K.end()){
                continue;
            }
            if(smallest_K.size() < K){
                smallest_K.push_back(cur);
                sort(smallest_K.begin(), smallest_K.end());
            } else {
                if(smallest_K[K - 1] > cur){
                    smallest_K[K - 1] = cur;
                    sort(smallest_K.begin(), smallest_K.end());
                }
            }
        }
    }
    cout << smallest_K[K - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>

using namespace std;


class Node{
public:
  vector< pair<int,int> > v;
  long long dist;
  bool check=false;
};

void depth_search(vector<Node>& V,int k,long long d){
  V[k].dist=d;
  V[k].check=true;
  int l=V[k].v.size();
  for(int i=0;i<l;i++){
    if(V[V[k].v[i].first].check==false){
      depth_search(V,V[k].v[i].first,V[k].v[i].second+d);
    }
  }
  //cout <<0;
}



int main(){
  int n;cin >> n;
  vector<Node> V(n);
  for(int i=0;i<n-1;i++){
    int a,b,c;cin >> a >> b >> c;
    V[a-1].v.push_back(make_pair(b-1,c));
    V[b-1].v.push_back(make_pair(a-1,c));
  }
  int q,k;cin >> q >> k;k-=1;
  //cout << q << k;
  depth_search(V,k,0);
  vector<long long> Q(q);
  //cout <<0;
  int x,y;
  for(int i=0;i<q;i++){
    cin >> x >> y;
    Q[i]=V[x-1].dist+V[y-1].dist;
    //cout << x << y;
  }
  //cout <<0;
  for(int i=0;i<q;i++){
    cout << Q[i] << endl;
  }

}


Measured memory_bytes: 14336
n,y = gets.chomp.split(" ").map(&:to_i);

flg = 0

for a in 0..n do 
  for b in 0..n do

    c = n - (a + b)
    
    if (y == 10000 * a + 5000 * b + 1000 * c) && (a + b + c == n) && (c >= 0)
      puts "#{a} #{b} #{c}"
      flg = 1
      exit
    end
  end
end
puts "-1 -1 -1" if flg == 0


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007

ll N,K;
ll search(ll key,mat& alp,ll now){
  ll M=alp[key].size();
  if(M==1){
    cout<<-1<<endl;
    exit(0);
  }
  ll ok=M-1,ng=0;
  while(ok-ng>1){
    ll mid=(ok+ng)/2;
    if(alp[key][mid]>=now){
      ok=mid;
    }else{
      ng=mid;
    }
  }
  return alp[key][ok];
}
int main(){
  ll i,now=-1,ans=0;
  string s,t;cin>>s>>t;
  N=s.size();K=t.size();
  mat alp(26);
  rep(i,26)alp[i].push_back(-5);
  rep(i,N){
    alp[s[i]-'a'].push_back(i);
  }
  rep(i,26){
    if(alp[i].size()>1)alp[i].push_back(alp[i][1]+N);
  }
  rep(i,K){
    now=search(t[i]-'a',alp,now+1);
    if(now>=N){
      ans++;
      now-=N;
    }
  //cout<<ans*N+now+1<<endl;
  }
  cout<<ans*N+now+1<<endl;
  return 0;
}

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

using namespace std;

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

	string s, t;
	cin >> s >> t;
	int cnt = 0;
	for(int i = 0; i < 3; i++) {
		if(s[i] == t[i]) cnt++;
	}
	cout << cnt;
}

Measured memory_bytes: 256
def cycle(x):
    result = 0
    for y in range(int(x), 0, -1):
        result += y - 1
    return result


def main():
    input()
    a_list = list(map(int, input().split(' ')))
    dict_a_list = dict()
    dict_result = dict()
    for a in a_list:
        if a in dict_a_list:
            dict_a_list[a] += 1
            continue
        dict_a_list[a] = 1
    for a in a_list:
        result = 0
        if dict_a_list[a] in dict_result:
            print(dict_result[dict_a_list[a]])
            continue
        dict_a_list[a] -= 1
        for v in dict_a_list.values():
            result += cycle(v)
        print(result)
        dict_a_list[a] += 1
        dict_result[dict_a_list[a]] = result


if __name__ == '__main__':
    main()


Measured memory_bytes: 25732
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf 2000000000
#define EPS 1e-7
#define MOD (ll)1e15
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;
typedef pair<int, int> pr;
typedef pair<int, pair<int, int>> tup;

inline void solve()
{
	string s;
	cin >> s;
	cout << string(s.size(), 'x');
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
}

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

long long mod = 2019;

long long power(long long x, long long y)
{
    long long ret = 1;
    while(y > 0)
    {
        if (y & 1)
        {
            ret = (ret * x) % mod;
        }
        x = (x * x) % mod;
        y >>= 1;
    }
    return ret;
}

int main(void)
{
    string S;
    cin >> S;
    vector<long long> count(2019);
    for (long long i = 0; i < 2019; i++)
    {
        count[i] = 0;
    }

    count[0]++;
    long long pre = 0;

    for (long long i = S.size() - 1; i > -1; i--)
    {
        pre = ((S[i]-'0') * power(10, S.size() - 1 - i) + pre) % mod; 
        count[pre]++;
    }

    long long ans = 0;

    for (long long i = 0; i < 2019; i++)
    {
        ans += count[i] * (count[i] - 1) / 2;
    }
    cout << ans << endl;
}

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

int main() {
    int P, Q, R;
    cin >> P >> Q >> R;
    int a[3] = {P, Q, R};

    sort(a, a+3);

    int ans = a[0] + a[1];

    cout << ans;

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(true){
        c-=b;
        if(c<=0){
            cout<<"Yes"<<endl;
            return 0;
        }
        a-=d;
        if(a<=0){
            cout<<"No"<<endl;
            return 0;
        }
    } 
    return 0;
}

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

#define ll long long
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); (i)++)
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

struct Edge{
   int from, to, cost;
};

const ll INF = (ll)4e18;
int N, M;
vector<vector<Edge>>  G;
bool ok = true;

void dfs(vector<ll> &dist, int pos) {
   for (auto e : G[pos]) {
      if (dist[e.to] != INF) continue;
      dist[e.to] = dist[pos] + e.cost;
      dfs(dist, e.to);
   }
}

int main() {
   cin >> N >> M;
   G = vector<vector<Edge>>(N);
   rep (i, 0, M) {
      int l, r, d;
      cin >> l >> r >> d;
      l--, r--;
      G[l].push_back(Edge{l, r, d});
      G[r].push_back(Edge{r, l, -d});
   }
   vector<ll> dist(N, INF);
   rep (i, 0, N) {
      if (dist[i] != INF) continue;
      dist[i] = 0;
      dfs(dist, i);
   }

   rep (i, 0, N) {
      for (auto e : G[i]) {
         if (dist[e.to] - dist[e.from] != e.cost) {
            puts("No");
            return 0;
         }
      }
   }
   puts("Yes");

   return 0;
}

Measured memory_bytes: 14208
using System;

namespace abc070A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string A = Console.ReadLine();
            string[] B = new string[3]; 
            for(int i = 0; i < 3; i++)
            {
                B[i] = A.Substring(i, 1);
            }
            if (A == B[2] + B[1] + B[0])
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <string.h>
using namespace std;
int main(int argc, char* argv[])
{
	char p[201];
	string S;
	cin>>S;
	int SLen=S.size();

	char *pStr=(char*)S.c_str();
	pStr[SLen-1]=0;
	string s;
	int i=0;
	int maxNum=0;
	int maxLen=0;
	for (int len=1;len<=SLen;len++){
		memset(p,0,201);
		strncpy(p,pStr,len);
		int num=0;
		for (i=0;i<SLen;i+=len){
			if (memcmp(pStr+i,p,len)){
				break;
			}
			num++;
		}
		if (num>1){
			if (maxLen<len){
				maxLen=len;
				maxNum=num;
			}
		}
	}
	if (maxNum==1){
		cout<<0<<endl;
		return 0;
	}
	if (maxNum==SLen){
		if (maxNum%2==1){
			maxNum--;
		}
		cout<<maxNum/2<<endl;
		return 0;
	}
	if (maxNum%2==1){
		maxNum--;
	}
	cout<<maxNum*maxLen<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

int main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];

  string ans = "second";
  rep(i, N) {
    if (a[i] % 2 == 1)
      ans = "first";
  }
  cout << ans << endl;
}

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

int main(){
    int k,s;
    cin>>k>>s;
    
    int ans = 0;
    for(int x = 0;x<=k;x++){
        for(int y=0;y<=k;y++){
            int z = s-x-y;;
            
            if(0 <= z && z <= k){
                ans++;
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int A[10][10];

void solve() {
    int n;
    cin >> n;
    REP(i, 1, n + 1) {
        string s = to_string(i);
        if (s.back() == '0') continue;
        A[s[0] - '0'][s.back() - '0']++;
    }
    int ans = 0;
    rep(i, 10) rep(j, 10) {
        ans += A[i][j] * A[j][i];
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3756
#include<stdio.h>
int main(void) {
	int i,j,k,l,N, M, A[50][50],B[50],C,sum,count=0;
	scanf("%d %d %d", &N, &M, &C);
	sum = C;
	for (i = 1; i <= M; i++)
		scanf("%d", &B[i]);
	for (i = 1; i <= N; i++) {
		for (j = 1; j <= M; j++)
			scanf("%d", &A[i][j]);
	}
	for (k = 1; k <= N; k++) {
		for (l = 1; l <= M; l++) {
			sum += A[k][l] * B[l];
		}
		if (sum > 0)
			count += 1;
		sum = C;
	}
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
 using namespace std;
int data[101];
 
int main(){
    int n,max=0;
    while(cin>>n){
        data[n]++;
        if(max<data[n])max=data[n];
    }
    for(int i=1;i<=100;i++){
        if(data[i]==max)cout<<i<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>
#define N 100

int main(){
  int i,j,n,minj,flag =0,tmp,count=0;
  int a[N];
  
  scanf("%d",&n);
  for( i=0 ; i<n ; i++ ){
    scanf("%d",&a[i]);
  }

  for( i=0 ; i<=n-1 ; i++ ){
    minj = i;
    for( j=i ; j<=n-1 ; j++ ){
      if( a[j] < a[minj] ){
	minj = j;
	if(flag == 0){
	  flag = 1;
	  count++;
	}
      }
    }
    tmp = a[i];
    a[i] = a[minj];
    a[minj] = tmp;

    flag = 0;
  }


  for( i=0 ; i<n ; i++ ){
    if( i == n-1 ){
      printf("%d\n",a[i]);
    }
    else{
      printf("%d ",a[i]);
    }
  }
  
  printf("%d\n",count);
  

  return 0;
}

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

ll dp[61][3];
int main() {
	ll n; scanf("%lld", &n);
	dp[60][0] = 1;
	for (int i = 60; i > 0; i--)rep(j, 3)rep(k, 3) {
		ll a = min(2LL, j * 2 + (n >> (i - 1) & 1) - k);
		if (a >= 0)(dp[i - 1][a] += dp[i][j]) %= MOD;
	}
	printf("%lld\n", (dp[0][0] + dp[0][1] + dp[0][2]) % MOD);
}

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

int main(){
    int n;
    cin >> n;
    vector<char> s(n);
    for(int i = 0;i < n;i++)cin >> s.at(i);
    sort(s.begin(), s.end());
    int ans = 1;
    for(int i = 1;i < n;i++){
        if(s.at(i - 1) != s.at(i))ans++;
    }
    if(ans == 3)cout << "Three" << endl;
    else cout << "Four" << endl;
}

Measured memory_bytes: 3632
from collections import deque

n = int(input())
l = [[int(i)-1 for i in input().split()] for i in range(n)]
# 選手の番号をindexと一致させる

q = deque(range(n))
days = [0 for i in range(n)]
pairs = [-1 for i in range(n)]
while q:
    a = q.popleft() #qの左端の選手のindexをpopleft
    if len(l[a]) == 0: #a番の選手のリクエストがない
        continue #skip
    b = l[a].pop(0)
    #l[a]:a番の選手のリクエストリスト
    #l[a]の最初のリクエストをpop

    #a:ある選手のindex
    #b:a番の選手が最初にリクエストした選手のindex
    if pairs[b] == a: # bのリクエストがaなら
        days[a] = days[b] = max(days[a],days[b]) +1
        q.append(a)
        q.append(b)
    else:
        pairs[a] = b #
print(max(days) if not any(l) else -1)



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

int main(){
  int c[3][3];
  rep(i, 3){
    rep(j, 3){
      cin >> c[i][j];
    }
  }
  int a[3];
  int b[3];
  bool flag;
  rep(p, 101){
    rep(q, 101){
      rep(r, 101){
        flag = true;
        a[0] = p;
        a[1] = q;
        a[2] = r;
        b[0] = c[0][0] - a[0];
        b[1] = c[1][1] - a[1];
        b[2] = c[2][2] - a[2];
        rep(i, 3){
          rep(j, 3){
            if(c[i][j] != a[i] + b[j]){
              flag = false;
            }
          }
        }
        if(flag){ cout << "Yes" << endl;
        return 0;}
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
import math as m

def isltK(K,X):
    ccut=0
    for Ai in As:
        ccut += m.ceil(Ai/X)-1
    if ccut <=K:
        return True
    else:
        return False


N,K=map(int,input().split())
As=list(map(int,input().split()))

l=1
h=max(As)
while l < h:
    mid = (l+h)//2
    if isltK(K,mid):
        h=mid
    else:
        l=mid+1
print(l)

Measured memory_bytes: 31248
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EDP_A solver = new EDP_A();
        solver.solve(1, in, out);
        out.close();
    }

    static class EDP_A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] h = new int[n + 1];
            int[] cost = new int[100010];
            Arrays.fill(cost, Integer.MAX_VALUE);
            cost[0] = 0;
            cost[1] = 0;
            for (int i = 1; i <= n; i++) {
                h[i] = in.nextInt();

            }


            for (int i = 1; i <= n; i++) {
                if (i > 1) {
                    cost[i] = Math.min(cost[i], cost[i - 1] + Math.abs(h[i] - h[i - 1]));
                }

                if (i > 2) {
                    cost[i] = Math.min(cost[i], cost[i - 2] + Math.abs(h[i] - h[i - 2]));
                }
            }

            out.print(cost[n]);


        }

    }
}



Measured memory_bytes: 51192
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
const int N=2e5+5;
vector<int> e[N];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    for (int i=2; i<=n; i++) {
        int boss;
        cin >> boss;
        e[boss].push_back(i);
    }

    for (int i=1; i<=n; i++) {
        cout << e[i].size() << '\n';
    }
    
    return 0;
}

Measured memory_bytes: 14592
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        int debt = 100000;
        int wk = Integer.parseInt(new BufferedReader(new InputStreamReader(
                System.in)).readLine());
        for (; wk > 0; wk--) {
            debt *= 1.05;
            if (debt % 1000 != 0) {
                debt = ((debt / 1000) + 1) * 1000;
            }
        }

        System.out.println(debt);
    }
}

Measured memory_bytes: 16860
/*  Bismillahir Rahmanir Rahim  */

#include <bits/stdc++.h>

using namespace std;

typedef pair <long long, int> pii;

struct data{
	long long val;
	int pos;
	bool operator < (const data &p) const{
		if(val == p.val) return pos < p.pos;
		return val > p.val;
	}
};

const int N = 100005;

int x, y, z;
int n, used[N];
long long a[N], b[N], c[N];
long long B[N], C[N];
long long ans;
set <data> BB, CC, change;

void Erase(int pos){
	BB.erase({b[pos] - a[pos], pos});
	CC.erase({c[pos] - a[pos], pos});
}

int main(){
	scanf("%d %d %d", &x, &y, &z);
	n = x + y + z;
	for(int i = 1; i <= n; ++i){
		scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);
		ans += a[i];
		BB.insert({b[i] - a[i], i});
		CC.insert({c[i] - a[i], i});
	}
	for(int i = 1; i <= y; ++i){
		auto it = BB.begin();
		Erase(it->pos);
		ans += it->val;
		change.insert( {c[it->pos] - a[it->pos] - it->val, it->pos} );
	}
	for(int i = 1; i <= z; ++i){
		long long aa, bb;
		{
			auto it1 = change.begin();
			auto it2 = BB.begin();
			aa = it1->val + it2->val;
		}
		{
			auto it = CC.begin();
			bb = it->val;
		}
		if(aa > bb){
			ans += aa;
			auto it1 = change.begin();
			auto it2 = BB.begin();
			change.erase(it1);
			int pos = it2->pos;
			Erase(pos);
			change.insert({c[pos] - a[pos] - it2->val, pos});
		}
		else{
			ans += bb;
			auto it = CC.begin();
			Erase(it->pos);
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 15232
//R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first 
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double 
#define pii std::pair<int, int> 
#define pll std::pair<ll, ll>  
#define vi vector<int>  
#define vl vector<ll>
#define vvi vector<vi > 
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>


using namespace std;

void solve()
  {
	int k;
	cin>>k;
	if(k%2==0){cout<<-1;return;}
	int cnt=1,mod=7%k;
	mii m;
	
	while(mod!=0)
	{
		// cout<<mod<<endl;
		if(m.find(mod)!=m.end()){cout<<-1;return;}
		m[mod]++;
		cnt++;
		mod=((mod*10)%k+7%k)%k;
	}
	cout<<cnt;
  }



signed main()
{
   std::ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t;
   t=1;
   //cin>>t;
   while(t--)
    {
        solve();
    }


   return 0;
}


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


int main(){
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for(auto& s : S){
    cin >> s;
  }
  for(int row=0; row<H; row++){
    for(int col=0; col<W; col++){
      if(S[row][col] == '.'){
        S[row][col] = '0';
      }
    }
  }
  for(int row=0; row<H; row++){
    for(int col=0; col<W; col++){
      if(S[row][col] != '#') continue;
      for(int dr=-1; dr<2; dr++){
        for(int dc=-1; dc<2; dc++){
          if(row+dr < 0) continue;
          if(row+dr > H-1) continue;
          if(col+dc < 0) continue;
          if(col+dc > W+1) continue;
          if(dr==0 && dc==0) continue;
          if(S[row+dr][col+dc] == '#') continue;
          S[row+dr][col+dc]++;
        }
      }
    }
  }
  for(auto& s : S){
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String s = scanner.nextLine();
		int n = Integer.parseInt(s);
		s = scanner.nextLine();
		int count = 0;
		char last_char = '\0';
		for(int i = 0; i < n; i++){
			char c = s.charAt(i);
			if(last_char != c) {
				count++;
				last_char = c;
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 27072
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int main(){
    int N;
    cin >> N;
    map<char, long> first_character;
    for(int i = 0; i < N; i++){
        string name;
        cin >> name;
        first_character[name[0]]++;
    }
    char march[5] = {'M', 'A', 'R', 'C', 'H'};
    long ans = 0;
    for(int i = 0; i < 5; i++){
        for(int j = i + 1; j < 5; j++){
            for(int k = j + 1; k < 5; k++){
                ans += first_character[march[i]] * first_character[march[j]] * first_character[march[k]];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
module Sort_Module
    implicit none
    public
    contains
    recursive subroutine mergesort(a, p, r, b)
        integer(8) a(:), b(:)
        integer(8) p, r
        integer(8) q
        if (p < r) then
            q = (p+r)/2
            call mergesort(a, p, q, b)
            call mergesort(a, q+1, r, b)
            call merge(a, p, q, r, b)
        end if
    end subroutine mergesort
    subroutine merge(a, p, q, r, b)
        integer(8) a(:), b(:)
        integer(8) p, r, q, i, j, k
        integer(8) t
        k = p;   i = p;   j = q+1
        do
            if (.not. (k <= r)) exit
            if (j > r) then
                t = a(i);   i = i+1
            else if (i > q) then
                t = a(j);   j = j+1
            else if (a(i) <= a(j)) then
                t = a(i);   i = i+1
            else
                t = a(j);   j = j+1
            end if
            b(k) = t;   k = k+1
        end do
        do i = p, r
            a(i) = b(i)  
        end do
    end subroutine merge
    subroutine sort(a)
      integer(8) a(:),b(ubound(a,1)-size(a)+1:ubound(a,1)),n,k
      n = ubound(a,1)
      k = ubound(a,1)-size(a)+1
      call mergesort(a,k,n,b)
    end subroutine sort
    function POSL(a,v) result(r)!find first i:a(i)>=v
        implicit none
        integer(8) :: a(:),l,r,idx,v
        r = ubound(a,1) + 1
        l = ubound(a,1)-size(a)
        do while(r-l>1)
            idx = l + (r-l)/2
            if(a(idx) >= v)then
                r = idx
            else
                l = idx
            endif
        enddo
    end function
    function POSU(a,v) result(r)!find first i:a(i)>v
        implicit none
        integer(8) :: a(:),l,r,idx,v
        r = ubound(a,1) + 1
        l = ubound(a,1)-size(a)
        do while(r-l>1)
            idx = l + (r-l)/2
            if(a(idx) > v)then
                r = idx
            else
                l = idx
            endif
        enddo
    end function
    function NUM(a,v) result(n)
        implicit none
        integer(8) :: a(:),v,n
        n = POSU(a,v) - POSL(a,v)
    end function
end module Sort_Module
  

program atcoder
    use Sort_Module
    implicit none
    integer(8) :: k,t,i,maxa,ans
    integer(8),allocatable,dimension(:) :: a
    read*,k,t
    allocate(a(t))
    read(*,*)(a(i),i=1,t)
    call sort(a)
    maxa = a(t)
    ans = max(0_8,2*maxa-k-1)
	write(*,'(i0)')ans
    stop 
contains
end program atcoder

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    int r = n % 10;
    if (r == 2 or r == 4 or r == 5 or r == 7 or r == 9) cout << "hon" << endl;
    else if (r == 3) cout << "bon" << endl;
    else cout << "pon" << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int n,m;
int a[110000];
bool b[110000];

int main(){
  cin>>n>>m;
  rep(i,n+1){
    a[i]=1;
  }
  b[1]=true;

  rep(i,m){
    int x,y;
    cin>>x>>y;
    a[x]--;
    a[y]++;
    if(b[x]){
      b[y]=true;
      if(a[x]==0)
        b[x]=false;
    }
  }
  int ans = 0;
  rep(i,n+1){
    if(b[i]){
      ans++;
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 768
import java.util.*;
 
public class Main {
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		int max = 0;
		for (int i = 0; i < N; i++) {
			int[] alp = new int[26];
			int[] alp2 = new int[26];
			String front = S.substring(0,i+1);
			String back = S.substring(i+1,N);
			for (int j = 0; j < front.length(); j++) {
				alp[front.charAt(j) - 'a']++;
			}
			for (int j = 0; j < back.length(); j++) {
				alp2[back.charAt(j) - 'a']++;
			}
			int count = 0;
			for (int j = 0; j < alp.length; j++) {
				if (0 < alp[j] && 0 < alp2[j]) {
					count++;
				}
			}
			if (max < count) {
				max = count;
			}
		}
		System.out.println(max);
	}
}

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

#define rep1(i, a, n) for (int i = a; i < n; i++)
#define rep2(i, a, n) for (int i = n; i >= a; i--)
#define asc(v) sort(v.begin(), v.end())
#define desc(v) sort(v.begin(), v.end(), greater<int>())

using namespace std;

int main() {
  int N, K;
  double ans = 0;
  cin >> N >> K;
  rep1(i, 1, N + 1) {
    int cur = i;
    double p = 1.0 / N;
    while (cur < K) {
      cur *= 2;
      p *= 0.5;
    }
    ans += p;
  }
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int nmax=500005;
ll fac[nmax],finv[nmax],inv[nmax];
 
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<nmax;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(int n,int k){
  if(n<k||n<0||k<0){
    return 0;
  }
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(){
    ll n,k;cin >> n >> k;
    COMinit();
    if(n<=k){
        cout << com(n+n-1,n-1) << endl;
    }
    else{
        ll ans=0;
        for(int i=n-k;i<=n;i++){
            
            ans+=com(n,i)*com(k-(i-(n-k))+i-1,i-1)%mod;
            ans%=mod;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 11904
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[h,w]=i2()
a=[]
for i in range(h):
 a.append(i2())
z=[]
for i in range(h):
 for j in range(w-1):
   if a[i][j]%2==1:
      a[i][j+1]+=1
      z.append([i+1,j+1,i+1,j+2])
for i in range(h-1):
 if a[i][w-1]%2==1:
    a[i+1][w-1]+=1
    z.append([i+1,w,i+2,w])

print(len(z))
for i,j,k,l in z:
  print(i,j,k,l)

Measured memory_bytes: 70108
from  bisect import bisect_left

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

l.sort()
for i in range(n-2):
  for j in range(i+1, n-1):
    ans += bisect_left(l, l[i]+l[j]) - j - 1
print(ans)

Measured memory_bytes: 3188
//### In The Name Of GOD ###

//%% Remember; (((He))) is The (((Accepter))) %%

// GOD IS GREATER ...

#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef long double ld ;

#define int ll
#define pb push_back
#define bp pop_back
#define pf push_front
#define fp pop_front
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);
#define sz(a) (int)(a.size())
#define sg(a, b) (a + b - 1) / b

const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 8 * 1000 * 1000 + 200;
const int MAXN = 1000 + 1;
const int MLOG = 18;
const int NMAX = 20;

vector<int> prime;

int is_p(int a){
	for(int i : prime)
		if(a % i == 0) return false;
	return true;
}

signed main(){
	IO;
	for(int i = 2; i <= MAXN; i++){
		if(is_p(i)) prime.pb(i);
	}
	//cout << prime[0] << prime[1] << prime[2] << prime[3];
	int cnt[sz(prime)] = {};
	int n;
	cin >> n;
	for(int l = 1; l <= n; l++){
		int r = l;
		for(int i = 0; i < sz(prime); i++){
			while(r % prime[i] == 0) {
				cnt[i]++;
				r /= prime[i];
			}
		}
	}
	int ans = 1;
	for(int i = 0; i < sz(prime); i++){
		ans *= ++cnt[i];
		ans %= MOD;
	}
	cout << ans;
}

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

int main(){
	int n, m, sum=0;
	cin>>n;
	m=n;
	for(;;){
		if(m==0) break;
		sum+=m%10;
		m/=10;
	}
	(n%sum==0) ? cout<<"Yes"<<endl : cout<<"No"<<endl;
	return 0;
}

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

bool even(string s) {
    int len = s.size();
    return s.substr(0, len/2) == s.substr(len/2, len/2);
}

int main() {
    string s; cin >> s;
    for (int i = (int)s.size() - 2; i > 1; i -= 2) {
        string sub = s.substr(0, i);
        if (even(sub)) {
            cout << sub.size() << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
local mfl, mce = math.floor, math.ceil
local n = io.read("*n")
local t = {}
for i = 1, n do
  t[i] = io.read("*n")
end
local curmin, curmax = 2, 2
-- a[n] = k * t[n] + l (0 <= k, 0 <= l < t[n])
-- a[n+1] = k * t[n]
if t[n] == 2 then
  for i = n, 1, -1 do
    local a = curmin
    local b = curmax + t[i] - 1
    if 1 < i then
      curmin = t[i - 1] * mce(a / t[i - 1])
      curmax = t[i - 1] * mfl(b / t[i - 1])
    else
      curmin, curmax = a, b
    end
    if curmax < curmin then break end
  end
else
  curmin = 3
end
if curmax < curmin then
  print(-1)
else
  print(curmin .. " " .. curmax)
end


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

int main(){
    int N;
    string S;
    cin >> N >> S;
    int ans = N;
    for(int i=0;i<N-1;i++){
        if(S[i] == S[i+1]){
            ans--;
        }
    }
    cout << ans <<endl;
}


Measured memory_bytes: 892
# -*- coding: utf-8 -*-
# 文字列の入力
a = int(input())
li = list(map(int, input().split()))
li2 = []

for i in range(a):
    li2.append(li[i])

if len(li2) != len(set(li2)):
    print('NO')
else:
    print('YES')


Measured memory_bytes: 26812
import sys
sys.setrecursionlimit(10 ** 6)


class UnionFindTree:
    """Disjoint-Set Data Structure
       Union-Find Tree
       complexity:
          init: O(n)
          find, unite, same: O(alpha(n))
       used in SRM505 div.2 900, ATC001 A, DSL1A(AOJ)
    """
    def __init__(self, n):
        self.par = list(range(n))  # parent
        self.rank = [0] * n  # depth of tree

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


while True:
    N, Q = map(int, input().split())
    if N == Q == 0:
        break
    parents = [0] + [int(input()) - 1 for _ in range(N - 1)]
    queries = []
    marked = set()
    for _ in range(Q):
        k, v = input().split()
        v = int(v) - 1
        if k == "Q":
            queries.append((k, v))
        elif k == "M" and v not in marked:
            marked.add(v)
            queries.append((k, v))

    uf = UnionFindTree(N)
    for i in range(1, N):
        if i not in marked:
            p_root = uf.find(parents[i])
            uf.par[i] = p_root
            uf.rank[p_root] = max(uf.rank[p_root], uf.par[i] + 1)
    ans = 0
    for k, v in reversed(queries):
        if k == "Q":
            ans += uf.find(v) + 1
        elif not uf.same(v, parents[v]):
            p_root = uf.find(parents[v])
            uf.par[v] = p_root
            uf.rank[p_root] = max(uf.rank[p_root], uf.par[v] + 1)
    print(ans)



Measured memory_bytes: 30648