akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

const int mN = 100100;
int n, mod;
vector<int> graph[mN];

typedef long long LL;
LL cnt[mN], coef[mN];

int parent[mN];
void dfs(int u) {
    cnt[u] = coef[u] = 1;
    for (int v : graph[u]) if (parent[u] != v) {
        parent[v] = u;
        dfs(v);
        cnt[u] *= cnt[v] + 1;
        cnt[u] %= mod;
    }
}

void reconsider(int u) {
    int id = 0;
    int num = graph[u].size() + 2;
    LL prefix[num], suffix[num];
    fill(prefix, prefix+num, 1);
    fill(suffix, suffix+num, 1);
    prefix[0] = 1;
    for (int j=0; j<graph[u].size(); j++) {
        int v = graph[u][j];
        if (parent[u] == v) continue;
        prefix[++id] = (prefix[id-1] * (cnt[v]+1)) % mod;
    }
//    cerr << "total = " << id << ".";
    suffix[id+1] = 1;
    for (int j=graph[u].size()-1; j>=0; j--) {
        int v = graph[u][j];
        if (parent[u] == v) continue;
        suffix[id] = (suffix[id+1] * (cnt[v]+1)) % mod;
        --id;
    }
//    cerr << "prepare for node " << u << " completed: ";
//    for (int i=0; i<=graph[u].size()+1; i++) cerr << "(" << prefix[i] << "," << suffix[i] << ") ";
//    cerr << "\n";
    for (int j=0; j<graph[u].size(); j++) {
        int v = graph[u][j];
        if (parent[u] == v) continue;
        LL u_as_child = (prefix[id++] * suffix[id+1]) % mod;
        u_as_child *= coef[u], u_as_child %= mod;
        coef[v] = u_as_child + 1;
        cnt[v] *= coef[v];
        cnt[v] %= mod;
        //cnt[v] = cnt[v];
        parent[v] = u;
        reconsider(v);
    }
    //cerr << u << " : " << cnt[u] << " (*=" << coef[u] << " ed)\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
    cin >> n >> mod;
    for (int i=1,x,y; i<n; i++) {
        cin >> x >> y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    fill(parent, parent+mN, 0);
    dfs(1);
    fill(parent, parent+mN, 0);
    reconsider(1);
    for (int i=1; i<=n; i++) cout << cnt[i] << "\n";
	return 0;
}


Measured memory_bytes: 23296
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
using namespace std;
typedef long long ll;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
 
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a,ll b){
	ll g=gcd(a,b);
	return a/g*b;
}
 
ll digitsum(ll a){
	ll x=0;
	while(a>0){
		x+=a%10;
		a/=10;
	}
	return x;
}
int main(){
	string s,t,u;
	cin>>s>>t>>u;
	if(s[s.size()-1]==t[0]&&t[t.size()-1]==u[0])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
}

Measured memory_bytes: 256
a,b=map(int,input().split())
List = [2,3,4,5,6,7,8,9,10,11,12,13,1]
c = 0
d = 0
for i in range(13):
  if a == List[i]:
    c = i
  if b == List[i]:
    d = i
if c == d:
  print("Draw")
elif c < d:
  print("Bob")
else:
  print("Alice")

Measured memory_bytes: 9100
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>

using namespace std;

int main(){
  int N;
  int a[222222];
  int i;
  bool x = false;
  cin >> N;
  for(i=0;i<=N-1;i++)
    cin >> a[i];
  int K = 0;
  for(i=0;i<=N-1;i++)
    if(a[i]==K+1) {
    K++;
    x = true;
    }
  if(x) cout << N - K << endl;
  else cout << -1 << endl;
}



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

using namespace std;

int main() {
    int n;
  
  	cin >> n;
  
  	double sum;
  	int tmp;
  	for (int i = 0; i < n; i++) {
      cin >> tmp;
      sum += 1.0/tmp;
    }
  
  	cout << setprecision(20) << 1.0/sum << endl;
  
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.Arrays;
public class Main {
	
	int N;
	int[] dp;
	
	public int fib(int n){
		
		if(dp[n] != -1){
			return dp[n];
		}
		
		if(n <= 1){
			return 1;
		}
		
		return dp[n] = fib(n - 1) + fib(n - 2);
	}
	
	public void solve() {
		N = nextInt();
		dp = new int[N + 1];
		Arrays.fill(dp,-1);
		dp[0] = dp[1] = 1;
		out.println(fib(N));
	}
 
	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}
 
	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;
 
	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}
 
	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}
 
	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}
 
	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}
 
	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}
 
	public int nextInt() {
		return Integer.parseInt(next());
	}
 
	public long nextLong() {
		return Long.parseLong(next());
	}
 
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 24472
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
A,B = map(int,input().split())

if (A+B)%2 == 0:
    print((A+B)//2)
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 2940
/*
//一生サンプル2が合わなかったけど、3時間のデバッグの末、
//90行目の(count-1)の符号が逆だったことに気づいたのでここに戒めとして記します
*/

#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int N;
  string S;
  cin >> N >> S;
  int count = 0;
  for (auto x : S) {
    if (x == '1') count++;
  }
  if (count == 0) {
    REP(i, N) cout << 1 << endl;
    return 0;
  }
  vi modplus(N), mod(N), modminus(N);
  if (count == 1) {
    REP(i, N) {
      if (S.at(i) == '1')
        cout << 0 << endl;
      else if (i != N - 1)
        cout << 1 << endl;
      else {
        cout << 2 << endl;
      }
    }
    return 0;
  }

  modplus.at(N - 1) = 1 % (count + 1);
  mod.at(N - 1) = 1 % (count);
  modminus.at(N - 1) = 1 % (count - 1);
  for (int i = N - 1; i > 0; i--) {
    modplus.at(i - 1) = (modplus.at(i) * 2) % (count + 1);
    mod.at(i - 1) = (mod.at(i) * 2) % (count);
    modminus.at(i - 1) = (modminus.at(i) * 2) % (count - 1);
  }
  // for (auto x : modminus) cout << x << " ";
  // cout << "\n";
  int tm = 0, t = 0, tp = 0;

  REP(i, N) {
    if (S.at(i) == '0') {
      continue;
    } else {
      tp = (tp + modplus[i]) % (count + 1);
      t = (t + mod[i]) % count;
      tm = (tm + modminus[i]) % (count - 1);
    }
  }
  // cout << tm << " " << t << " " << tp << endl;

  vi table(200010);
  for (int bit = 0; bit <= 200000; ++bit) {
    int sum = 0;
    REP(i, 18) {
      if (bit & (1 << i)) {
        sum++;
      }
    }
    table.at(bit) = sum;
  }

  int ans, num;
  REP(i, N) {
    ans = 1, num = 0;
    if (S.at(i) == '0') {
      // cout << modplus[i] << endl;
      num = (tp + modplus[i]) % (count + 1);
      // cout << num << " " << count + 1 << " ";
    } else {
      num = ((count - 1) + tm - modminus[i]) % (count - 1);
      // cout << num << " " << count-1 << " ";
    }

    while (num) {
      num = num % table.at(num);
      // cout << num << " ";
      ans++;
    }

    cout << ans << endl;
  }

  // cout << bitset<18>(num) << endl;
}

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

int main()
{
  int m,n,t;
  cin>>m>>n>>t;
  int sum=0;
  for(int i=m;i<=n;i++)
  {
    if(i%t==0)
      sum=sum+1;
  }
  cout<<sum;
  return 0;
}
    
      

Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
	int W, H, N;
	int FromX, FromY, ToX, ToY;
	int c = 0;

	scanf("%d %d %d", &W, &H, &N);

	scanf("%d %d", &FromX, &FromY);
	rep(i, N - 1) {
		scanf("%d %d", &ToX, &ToY);
		if ((FromX - ToX <= 0 && FromY - ToY <= 0) || (FromX - ToX >= 0 && FromY - ToY >= 0)) {
			c += max(abs(FromX - ToX), abs(FromY - ToY));
		}
		else {
			c += abs(FromX - ToX) + abs(FromY - ToY);
		}
		FromX = ToX;
		FromY = ToY;
	}

	printf("%d\n", c);

	return 0;
}

Measured memory_bytes: 2704
S = input()

chars = set()
for s in S:
    chars.add(s)

res = len(S)
for char in chars:
    max_c = 0
    c = 0
    for s in S:
        if s != char:
            c += 1
        else:
            max_c = max(c, max_c)
            c = 0
    max_c = max(c, max_c)
    res = min(res, max_c)

print(res)

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

int main() {
    string n;
    string m;
 
   cin >> n >> m;
  
   if (n == "H"){
     
      cout << m << endl;
     
   }else {
     
      if (m == "H"){
        
         cout << "D" << endl;
      }else{
        
        cout << "H" << endl;
      }
     
   }
  
  
  
  return 0;
}

Measured memory_bytes: 256
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

let main() =
    let n = read int
    // 先頭がi, 末尾がjである数値の個数
    let nums = Array2D.init 10 10 (fun _ _ -> 0L)

    for i in 1 .. n do
        let s = string i
        let a = Seq.head s |> fun x -> int x - int '0'
        let b = Seq.last s |> fun x -> int x - int '0'
        nums.[a, b] <- nums.[a, b] + 1L
    let mutable ans = 0L
    for i in 1 .. 9 do
        for j in 1 .. 9 do
            let a = nums.[i, j] * nums.[j, i]
            ans <- ans + a
    puts ans
    ()

main()
writer.Close()
writer.Close()


Measured memory_bytes: 17472
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a%3==0||b%3==0||(a+b)%3==0) cout<<"Possible";
	else cout<<"Impossible" ;
	cout<<"\n";
	return 0;
}


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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n), b(n), c(n);
    for(ll i = 0; i < n; i++) cin >> a[i];
    for(ll i = 0; i < n; i++) cin >> b[i];
    for(ll i = 0; i < n-1; i++) cin >> c[i];
    ll ex = -10, ans = 0;
    for(auto x: a){
        x--;
        ans += b[x];
        if(x == ex+1) ans += c[ex];
        ex = x;
    }
    cout << ans;
    return 0;
}

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

int main(){
  int N,Ma,Mb;cin >> N >> Ma >> Mb;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N);
  int Amax=0,Bmax=0,Cmax=0;
  for(int i=0;i<N;i++){
    cin >> A[i] >> B[i] >> C[i];
    Amax += A[i];
    Bmax += B[i];
    Cmax += C[i];
  }
  int INF = Cmax + 1;
  vector<vector<vector<int>>> DP(N+1,vector<vector<int>>(Amax+1,vector<int>(Bmax+1,INF)));
  DP[0][0][0]=0;
  for(int i=1;i<=N;i++){
    for(int ca=0;ca<=Amax;ca++){
      for(int cb=0;cb<=Bmax;cb++){
        DP[i][ca][cb] = DP[i-1][ca][cb];
        if(ca>=A[i-1]&&cb>=B[i-1]){
          DP[i][ca][cb]=min(DP[i][ca][cb],DP[i-1][ca-A[i-1]][cb-B[i-1]]+C[i-1]);
        }
      }
    }
  }
  int ans = INF;
  //for(int k=1;k*Ma<=Amax&&k*Mb<=Bmax;k++){
  //  ans = min(ans,DP[N][k*Ma][k*Mb]);
  //}
  for(int ca=1;ca<=Amax;ca++){
    for(int cb=1;cb<=Bmax;cb++){
      //cout << DP[N][ca][cb] << " ";
      if(ca*Mb==Ma*cb){
        ans = min(ans,DP[N][ca][cb]);
      }
    }
    //cout << endl;
  }
  if(INF<=ans){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }
}

Measured memory_bytes: 12944
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(){
  int n; cin >> n;
  vector<int> v = {1};
  int i = 6; int j = 9;
  while(i <= 100000){
    v.push_back(i);
    i *= 6;
  }
  while(j <= 100000){
    v.push_back(j);
    j *= 9;
  }
  sort(v.begin(), v.end());
  reverse(v.begin(),v.end());
  
  ll dp[n+1]; 
  rep(i,n+1) dp[i] = MOD;
  dp[0] = 0;
  rep(i,n){
    rep(j,v.size()){
      if(i + v[j] <= n)
        dp[i+v[j]] = min(dp[i]+1, dp[i+v[j]]);
    }
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long  n;
    cin>>n;
    string s;
    cin>>s;
    long long  cnt = 0;
    for(int i = 0; i<s.size(); i++)
    {
        if(s[i]=='R')
        {
            cnt++;
        }
    }
    int cn  =0;
    for(int i =0; i<cnt; i++)
    {
        if(s[i]=='W')
        {
            cn++;
        }

    }
    cout<<cn<<endl;
}


Measured memory_bytes: 3768
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
#define MOD 1'000'000'007
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;

ll N;
ll x[50], y[50];

int main(){
    cin>>N;
    rep(i,N) cin>>x[i]>>y[i];

    map<P,ll> m;
    rep(i,N){
        rep(j,N){
            if(i==j) continue;
            m[P(x[i]-x[j],y[i]-y[j])]++;
        }
    }

    ll ans=0;
    repr(e,m){
        ans=max(ans,e.second);
    }
    ans=N-ans;

    cout<<ans<<endl;
}

Measured memory_bytes: 3508
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;

const int MAXN = 100005;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	setp(10);
	int n; cin>>n;
	cout<<((n+1)/2)*1.0L/n<<'\n';
	
	return 0;
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll tot[51],sz[51],x;
ll recur(int n)
{
    if(x<=0)
        return 0;
    if(sz[n]<=x)
    {
        x-=sz[n];
        return tot[n];
    }
    x--;
    ll y=recur(n-1);
    if(x)
        y++,x--;
    if(x)
        y+=recur(n-1);
    return y;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);

    tot[0]=1;
    sz[0]=1;
    for(int i=1; i<=50; i++)
        tot[i]=tot[i-1]*2ll + 1;
    for(int i=1; i<=50; i++)
    {
        sz[i]=sz[i-1]*2ll + 3;
    }
    ll n,ans=0;
    cin>>n>>x;
    x--;
    if(x)
    {
        ans+=recur(n-1);
    }
    if(x)
    {
        x--;
        ans++;
    }
    if(x)
    {
        ans+=recur(n-1);
    }
    cout<<ans<<endl;





    return 0;
}


Measured memory_bytes: 3620
a, b = gets.split.map(&:to_i)

P = "Positive"
N = "Negative"

if a <= 0 and 0 <= b
  
  puts "Zero"
  
elsif 0 < a

  puts P
  
elsif a < 0 and b < 0

  d = b - a
  if d.odd?
    puts P
  else
    puts N
  end
  
else
  loop{}
end

Measured memory_bytes: 1788
#include <iostream>

using namespace std;

int main(){
    int N;
    string S;
    cin >>N;
    cin >> S;
    int r = 0;
    int b = 0;
    for(int i = 0;i < S.size(); i++){
        if(S[i] == 'R') r++;
        else b++;
    }
    if(r > b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
list = input()

list_int = [int(ele) for ele in list]

min = 10000

for i in range(0, len(list)-2):
    x = abs( list_int[i] * 100 + list_int[i+1] * 10 + list_int[i+2] - 753)
    if x < min:
        min = x

print(min)

Measured memory_bytes: 3060
#include <stdio.h>

long int c2(long int n)
{
   return n*(n-1)/2;
}

int main()
{
   long int i, a[200000], aux[200001], aux2[200000], tam2 = 0, j, n, soma = 0;
   
   scanf ("%ld", &n);

   for (i = 1; i <= n; i++)
      aux[i] = 0;

   for (i = 0; i < n; i++)
   {
      scanf("%ld", a+i);
      if (!aux[a[i]])
         aux2[tam2++] = a[i];
      aux[a[i]]++;
   }

   soma = 0;
   for (j = 0; j < tam2; j++)
      soma += c2(aux[ aux2[j] ]);
   
   for (i = 0; i < n; i++)
      printf("%ld\n", soma - c2(aux[a[i]]) + c2(aux[a[i]] - 1));
   return 0;
}


Measured memory_bytes: 7168
N = int(input())
S1 = input()
S2 = input()

mod = 10**9+7

# Y:横 T:縦
S = ""
flg = False
for i in range(len(S1)):
    if flg:
        flg = False
        continue

    if S1[i] == S2[i]:
        S += "T"
    else:
        S += "Y"
        flg = True

if S[0] == "T":
    ans = 3
    now = "T"
else:
    ans = 6
    now = "Y"

for s in S[1:]:
    if now=="T":
        if s=="T":
            ans *= 2
            now = "T"
        else:
            ans *= 2
            now = "Y"
        ans %= mod

    else:
        if s=="T":
            now = "T"
        else:
            ans *= 3
            ans %= mod
            now = "Y"

print(ans % mod)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }



void solve(void)
{
  int H,N;
  cin>>H>>N;
  for (int i = 0; i < N; i++)
  {
    int A;
    cin>>A;
    H -=A ;
  }
  if(H <= 0)
  cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second

ll p[100002];
ll find(ll x)
{
  return p[x]==x ? x : p[x]=find(p[x]);
}
int main()
{
  ll n,m,i;
  cin>>n>>m;
  ll link[m][2],sum[n],ans[m];
  for(i=0;i<n;i++)
  {
    p[i]=i;
    sum[i]=1;
  }
  for(i=0;i<m;i++)
  {
    cin>>link[i][0]>>link[i][1];
  }
  ans[m-1]=(n*(n-1)/2);
  for(i=m-1;i>=0;i--)
  {
    ll q,w;
    q=find(link[i][0]);
    w=find(link[i][1]);
    if(q!=w)
    {
      ans[i-1]=ans[i]-(sum[q]*sum[w]);
      sum[w]+=sum[q];
      p[q]=w;
    }
    else ans[i-1]=ans[i];
  }
  for(auto g: ans) cout<<g<<endl;
  return 0;
}

Measured memory_bytes: 5248
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r=n(1);n(2)(r.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";var r=n(3),i=n(5);t.exports=function(t){var e=new r(t);i(e)}},function(t,e,n){"use strict";var r=n(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new r(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,n){"use strict";t.exports=function(t){for(var e=t.in(),n=t.inr(),r=t.inr(),i="",s=0;s<e;s++)i+=n[s],i+=r[s];console.log(i)}}]);


Measured memory_bytes: 21064
#include <stdio.h>

int main()
{
  int i;
  char str[1200] = { 0 };
  int count[26] = { 0 };

  while (fgets(str, sizeof(str), stdin) != NULL) {
    i = 0;
    while (str[i] != '\0') {
      if (str[i] >= 0x61 && str[i] <= 0x7a) {
        count[str[i] - 0x61]++;
      } else if (str[i] >= 0x41 && str[i] <= 0x5a) {
        count[str[i] - 0x41]++;
      }
      i++;
    }
  }
  for (i = 0; i < 26; i++) {
    printf("%c : %d\n", 0x61 + i, count[i]);
  }

  return 0;
}



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

int main() {
  int k;
  cin >> k;
  int count = 0;
  for (int i = 1; i <= k; i = i + 1) {
    for (int j = i + 1; j <= k; j = j + 1) {
      if ((i%2 == 0 && j%2 == 1) || (i%2 == 1 && j%2 == 0)) {
        count += 1;
      }
    }
  }
  cout << count << endl;
}
    

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	S = LI()
	S[0],S[1]=S[1],S[0]
	S[0],S[2]=S[2],S[0]
	printH(S)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3316
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
d,g=map(int,input().split())
g//=100
l={}
t=[]
cnt=ans=0
for i in range(d):
    p,c=map(int,input().split())
    c//=100
    l[i+1]=[p,c]
    t.append((i+1)*p+c)
    ans+=p

for i in range(1<<d):
    x=[0,0,0]
    for j in range(d):
        if (i&(1<<j)):
            x[0]+=l[j+1][0]
            x[1]+=t[j]
        else:
            x[2]=j
    if x[1]>=g:
        ans=min(ans,x[0])
    elif ((g-x[1])+x[2])//(x[2]+1)<=l[x[2]+1][0]:
        ans=min(ans,x[0]+((g-x[1])+x[2])//(x[2]+1))
print(ans)


Measured memory_bytes: 3188
import java.util.*;
class Main{
  public static void main(String[] args){
	Scanner stdIn = new Scanner(System.in);
	int N = stdIn.nextInt();
    double[] a=new double[N];
    double sum=0.0;
    for(int i=0;i<N;i++){
      a[i]=Double.parseDouble(stdIn.next());
      sum+=1.0/a[i];
    }
    System.out.println(1.0/sum);
  }
}

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

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

#define roop(i, n) for(int i = 0;i < n;i++)

int main(void){

    char a, b;
    cin >> a >> b;

    if(a == b) cout << 'H' << endl;
    else cout << 'D' << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.lang.Math;

public class Main {

    private static Scanner sc;

    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            int R = sc.nextInt();

            double ans = R*2*Math.PI;
            
            System.out.println(ans);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

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

using namespace std;

bool cmp(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

int main() {
    int n, m;
    cin >> n >> m;

    vector<pair<int, int>> req(m);
    for (int i = 0; i < m; ++i) {
        cin >> req[i].first >> req[i].second;
    }
    sort(req.begin(), req.end(), cmp);

    int ans = 0;
    int pos = 0;
    for (auto & i : req) {
        if (i.first >= pos) {
            pos = i.second;
            ans++;
        }
    }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair <int, int>
#define iiii pair <int, pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i, x) for(int (i) = 0; (i) < (x); (i)++)
inline int getint() {
	int x = 0, p = 1; 
	char c = getchar();	
	while (c <= 32) c = getchar();
	if (c == 45) p = -p, c = getchar();
	while (c > 32) x = x * 10 + c - 48, c = getchar();
	return x * p;
}
using namespace std;
//ruogu_alter
const int N = 1e5 + 5;
int n, m;
vector<pii > q[N];
const ll inf = 2e18;
ll tag[N << 2], f[N];
//
inline void upd(ll &x, ll y) {
	x = min(x, y);
}
inline void pd(int k) {
	if(tag[k] != inf) {
		upd(tag[2 * k + 1], tag[k]);
		upd(tag[2 * k + 2], tag[k]);
		tag[k] = inf;
	}
}
void modify(int l, int r, int x, int y, int k, ll v) {
	if (x >= r || l >= y) return;
	if (x <= l && r <= y) {
		tag[k] = min(tag[k], v);
		return;
	}
	pd(k); int mid = (l + r) >> 1;
	modify(l, mid, x, y, 2 * k + 1, v);
	modify(mid, r, x, y, 2 * k + 2, v);
}
ll qry(int l, int r, int p, int k) {
	if (r - l == 1) return tag[k];
	pd(k); int mid = (l + r) >> 1;
	if (p < mid) return qry(l, mid, p, 2 * k + 1);
	else return qry(mid, r, p, 2 * k + 2);
}
int main() {
	n = getint(); m = getint();
	rep(i, m) {
		int x = getint() - 1, y = getint() - 1, z = getint();
		q[x].push_back(mp(y, z));
	}
	rep(i, N << 2) tag[i] = inf;
	rep(i, n) f[i] = inf;
	f[0] = 0;
	rep(i, n) { 
		f[i] = min(f[i], qry(0, n, i, 0));
		if (f[i] >= inf) continue;
		rep(j, q[i].size()) modify(0, n, i + 1, q[i][j].first + 1, 0, f[i] + q[i][j].second);
	}
	if (f[n - 1] == inf) f[n - 1] = -1;
	cout << f[n - 1];
	return 0;
}


Measured memory_bytes: 9600
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
#include<math.h>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
typedef pair<Q,ll> R;
ll longinf=1ll<<60;
int inf=1<<29;
//mleしなければぜんぶllでかく。
//↑はあんまり気にしなくていい。


class unionFind{
      private:
      vector<int> parent;
      vector<int> rank;
      vector<int> sizes;

      public:
      unionFind(int n){
            rep0(i,n){
                  parent.push_back(i);
                  rank.push_back(0);
                  sizes.push_back(1);
            }
      }
      int root(int x){
            if(parent[x]==x){
                  return x;
            }
            else{
                  parent[x] = root(parent[x]);
                  return parent[x];
            }
      }
      void merge(int x,int y){
            x=root(x);
            y=root(y);
            if(x==y) return;
            if(rank[x]<rank[y]) swap(x,y);
            if(rank[x]==rank[y]) rank[x]++;
            parent[y]=x;
            sizes[x]+=sizes[y];
      }
      bool same(int x,int y){
            return root(x)==root(y);
      }
      int size(int x){
            return sizes[root(x)];
      }
};


int main(){
    int m,k;
    cin>>m>>k;
    int M=(1<<m);
    if(m==1&&k==1) cout<<-1<<endl;
    else if(k>=M){
        cout<<-1<<endl;
    }
    else if(k==0){
        vector<int> ans;
        rep0(i,M){
            cout<<i<<endl;
            cout<<i<<endl;
        }
    }
    else{
        vector<int> ans;
        ans.push_back(0);
        ans.push_back(k);
        ans.push_back(0);
        int i=1;
        while(i<=M-1){
            if(i!=k) ans.push_back(i);
            i++;
        }
        ans.push_back(k);
        while(i>=2){
            i--;
            if(i!=k) ans.push_back(i);
        }
    for(auto a:ans){
        cout<<a<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
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; }



int main()
{
	int n,q;
	cin >> n >> q;	
	string str;
	cin >> str;
	vector<int>s(n+1,0);
	rep(i,n) {
		if(str[i] == 'A' && str[i+1] == 'C' && i+1<n) {
			s[i+1] = s[i]+1;
		}
		else s[i+1] = s[i];
	}
	vector<int>ans(q);
	rep(i,q) {
		int l,r;
		cin >> l >> r;
		ans[i] = s[r-1]-s[l-1];
	}
	rep(i,q) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 1856
s = int(input())
a = [s]

for i in range(1, 1000000):
    if a[i-1]%2 == 0:
        tmp = (a[i-1]//2)
    else:
        tmp = (3*a[i-1] + 1)
    
    if a.count(tmp):
        ans = i+1
        break
    else:
        a.append(tmp)
        
print(ans)

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

int main() {
  int N;
  cin >> N;
  set<int> s;
  rep(i, N) {
    int a;
    cin >> a;
    s.insert(a);
  }

  if ((int)s.size() == N) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 9600
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] count = new int[100003];
		
		for(int i=0; i<n; i++) {
			int a = sc.nextInt();
			count[a]++;
			count[a+1]++;
			count[a+2]++;
		}
		sc.close();
		
		Arrays.sort(count);
		
		System.out.println(count[100002]);

	}

}


Measured memory_bytes: 59472
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

def solve():
    MOD = 10**9 + 7

    N = int(input())
    adjL = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        a, b = a-1, b-1
        adjL[a].append(b)
        adjL[b].append(a)

    def getInvs(n, MOD):
        invs = [1] * (n+1)
        for x in range(2, n+1):
            invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
        return invs
    invs = getInvs(N, MOD)

    dp = [[] for _ in range(N)]
    outdegs = [0] * N
    sizes = [0] * N
    iPars = [-1] * N
    def dfsDP(v, vPar):
        outdeg = outdegs[v] = len(adjL[v])
        dp[v] = [0] * outdeg
        res = 1
        sizes[v] = 1
        for i, v2 in enumerate(adjL[v]):
            if v2 == vPar:
                iPars[v] = i
                continue
            dp[v][i] = dfsDP(v2, v)
            res = res * dp[v][i] % MOD
            sizes[v] += sizes[v2]
        return res * invs[sizes[v]] % MOD

    anss = [0] * N
    def dfsAns(v, vPar, resPar):
        if vPar != -1:
            dp[v][iPars[v]] = resPar

        outdeg = outdegs[v]
        dpL = [1] * (outdeg+1)
        for i in range(outdeg):
            v2 = adjL[v][i]
            dpL[i+1] = dpL[i] * dp[v][i] % MOD
        dpR = [1] * (outdeg+1)
        for i in reversed(range(outdeg)):
            v2 = adjL[v][i]
            dpR[i] = dpR[i+1] * dp[v][i] % MOD
        anss[v] = dpL[-1] * invs[N]

        for i, v2 in enumerate(adjL[v]):
            if v2 == vPar: continue
            dfsAns(v2, v, dpL[i] * dpR[i+1] * invs[N-sizes[v2]] % MOD)


    dfsDP(0, -1)
    dfsAns(0, -1, 0)

    def getFact(n, MOD):
        fact = 1
        for i in range(1, n+1):
            fact = (fact * i) % MOD
        return fact
    factN = getFact(N, MOD)

    for v in range(N):
        anss[v] = anss[v] * factN % MOD
    print('\n'.join(map(str, anss)))


solve()


Measured memory_bytes: 134812
#include<stdio.h>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;

#define INF 987654321
#define ll long long

int N;
vector<int> v;

int main() // O(n^2) solution
{
	scanf("%d", &N);
	v.resize(N);
	for (int i = 0; i < N; i++)
		scanf("%d", &v[i]);
	sort(v.begin(), v.end());

	int res = 0, lo, hi;
	for (int i = 1; i < 24; i++)
	{
		lo = 0, hi = 24;

		int chk = 0;
		for (int j = 0; j < N; j++)
		{
			//둘 다 가능하면 어느 쪽이든 상관없다.
			if (v[j] - lo >= i && hi - v[j] >= i) lo = v[j];
			else if ((24 - v[j]) - lo >= i && hi - (24 - v[j]) >= i) hi = 24 - v[j];
			else
			{
				chk = 1;
				break;
			}
		}

		if (chk) break;

		res = i;
	}

	printf("%d", res);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

typedef long long ll;
ll n, s, c, a[N], b[N];
int main()
{
	ll i;
	cin >> n;
	for (i = 1; i <= n; i++) scanf("%lld", &a[i]), s += a[i], b[i] = a[i] - a[i - 1];
	b[1] = a[1] - a[n];
	if (s % (n * (n + 1) / 2)) {cout << "NO"; return 0;}
	s /= n * (n + 1) / 2;
	for (i = 1; i <= n; i++) {
		if (s < b[i] || (s - b[i]) % n) {cout << "NO"; return 0;}
		c += (s - b[i]) / n;
	}
	if (c != s) {cout << "NO"; return 0;}
    cout << "YES" << endl;
    return 0;
}

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

int main(){
  int n,m;cin >> n >> m;
  int a[m];rep(i,m)cin >> a[i];
  int sum = 0;
  rep(i,m){sum += a[i];}
  if(n < sum)cout << -1 << endl;
  else cout << n-sum << endl;
  return 0;
}

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

int main() {
    int n, q; cin >> n >> q;
    string s; cin >> s;
    vector<char> t(q), d(q);
    for (int i = 0; i < q; i++) {
        cin >> t[i] >> d[i];
    }
    int left = 0; int right = n;
    for (int i = q-1; i >= 0; i--) {
        if (d[i] == 'L') {
            if (s[left] == t[i]) left++;
            if (right != n && s[right] == t[i]) right++;
        } else {
            if (s[right-1] == t[i]) right--;
            if (left != 0 && s[left-1] == t[i]) left--;
        }
        if (left == right) break;
    }
    cout << right - left << endl;
    return 0;
}

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

int main(){
    ll N,K;
    cin >> N >> K;
    if(K==0){
        cout << N*N << endl;
        return 0;
    }
    ll cnt = 0;
    for(ll b=1;b<=N;b++){
        // aをbで割った余りは1,2,..,b-1,0,1,2,...b-1,0,1...
        // 1,2,...b-1,0 を一塊とすると、k以上の数は(b-1)-k+1 = b-k個
        // 塊はN/b個ある
        // 端数はN%bあるのでその中でk以上の数はN%b-k+1個
        cnt += max(b-K,0LL)*(N/b) + max(0LL,N%b-K+1);
    }
    cout << cnt << endl;
    return 0;
}

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

bool check(long a, long b, long c) {
    long d = c - a - b;
    if (d <= 0) {
        return false;
    }
    if (d * d <= 4 * a * b) {
        return false;
    }
    return true;
}

int main() {
    long a, b, c;
    cin >> a >> b >> c;

    cout << (check(a, b, c) ? "Yes" : "No") << endl;

    return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		int[] b = Arrays.copyOf(a, a.length);
		Arrays.sort(b);
		for(int i = 0 ; i < n ; i++) {
			if(a[i] < b[n / 2]) System.out.println(b[n / 2]);
			else System.out.println(b[n / 2 - 1]);
		}
	}
}


Measured memory_bytes: 92080
#include <stdio.h>

int main(void){
  int s;
  double w,h;
  double b;
  while(scanf("%d,%lf,%lf",&s,&w,&h)!=EOF){
    b=w/(h*h);
    if(b>=25) printf("%d\n",s);
  }
  return 0;
}

Measured memory_bytes: 628
d = [0] * 100
for i in range(int(input()) + 1):
	s = str(i)
	d[int(s[0]) * 10 + int(s[-1])] += 1
r = range(1, 10)
print(sum(d[i * 10 + j] * d[j * 10 + i] for i in r for j in r))


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

int score[2][4];
int T[2];
int main()
{
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<4;j++)
		{
			cin >>score[i][j];
			T[i]+=score[i][j];
		}
	}
	if(T[0]>=T[1])
	{
		cout<<T[0]<<endl;
	}
	else
	{
		cout<<T[1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    string s;
    cin >> s;

    int ans = 0;
    if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') ans = 3;
    else if (s[0] == 'R' && s[1] == 'R') ans = 2;
    else if (s[1] == 'R' && s[2] == 'R') ans = 2;
    else
    {
        rep (i, 3) if (s[i] == 'R') ans = 1;
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3648
def bitcnt(n):
  n=(n&0x55555555)+(n>>1&0x55555555)
  n=(n&0x33333333)+(n>>2&0x33333333)
  n=(n&0x0f0f0f0f)+(n>>4&0x0f0f0f0f)
  n=(n&0x00ff00ff)+(n>>8&0x00ff00ff)
  n=(n&0x0000ffff)+(n>>16&0x0000ffff)
  return n
N = int(input())
xy = [[-1 for j in range(N)] for i in range(N)]
for i in range(N):
  for j in range(int(input())):
    x, y = map(int, input().split())
    x -= 1
    xy[i][x] = y
r = 0
for i in range(1<<N):
  t = [i>>j&1 for j in range(N)]
  ok = True
  for j in range(N):
    if t[j]:
      for k in range(N):
        if xy[j][k] == -1:
          continue
        if xy[j][k] != t[k]:
          ok = False
          break
  if ok:
    r = max(r, bitcnt(i))
print(r)

Measured memory_bytes: 45020
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m,k;
P farm[15];
int dp[10001][4];

int func(int v,int rest,int used){
	if(v==n || used==k)return rest;
	int res=max(rest,func(v+1,rest,used));
	int add=min(farm[v].second,rest)*farm[v].first;
	return max(res,func(v+1,rest-min(farm[v].second,rest),used+1)+add);
}

int main(void){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&farm[i].first);
	}
	for(int i=0;i<n;i++){
		scanf("%d",&farm[i].second);
	}
	sort(farm,farm+n,greater<P>());
	printf("%d\n",func(0,m,0));
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};

int main(){
    ll n;   cin >> n;
    vector<ll> a(n);
    rep(i, n)   cin >> a[i];
    vector<ll> csum(n+1, 0);
    rep(i, n)   csum[i+1] = (csum[i]+a[i])%MOD;
    ll res=0;
    rep(i, n){
        res += (a[i]*((csum[n]-csum[i+1]+MOD)%MOD))%MOD;
        res %= MOD;
    }
    cout << res << endl;
}


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

int main() {
  long long N ,M ,K;
  cin >> N >> M >> K;
  
  vector<long long>A(N);
  vector<long long>B(M);
  
  vector<long long>A_sum(N+1);
  vector<long long>B_sum(M+1);
  
  A_sum.at(0) = 0;
  B_sum.at(0) = 0;
  
  for(long long i = 0 ; i < N ; i++){
  	cin >> A.at(i);
    A_sum.at(i+1) = A_sum.at(i) + A.at(i); 
    //cout << A_sum.at(i+1) << endl;
  }
  for(long long i = 0 ; i < M ; i++){
  	cin >> B.at(i);
    B_sum.at(i+1) = B_sum.at(i) + B.at(i);    
  }

  //long long sum = 0;
  long long sum_max = -1;
  long long last_j = 0;
  
  
  for(long long i = 0 ; i <= N ; i++){
  	for(long long j = last_j ; j <= M ; j++){
    	if(A_sum.at(N-i)+B_sum.at(j)<=K){
        	//sum = A_sum.at(N-i)+B_sum.at(j);
          last_j = j;
              if(sum_max < N - i + j){
    			sum_max = N - i + j;
    		  }
        }else{
        	break;
        }
    }
  }
  
  cout << sum_max << endl;
  
}	


Measured memory_bytes: 9500
#include <iostream> 

using namespace std;

int main() {
	long long A,B,C,D,E;
	cin >> A >> B;
	cin >> C >> D;
	long long a,b,c;
	A-=1;
	a = B/C-A/C;
	b = B/D-A/D;

	long long x = C*D;
	if(C<D){
    	long long tmp = C;
    	C = D;
    	C = tmp;
  	}
  	long long r = C % D;
  	while(r!=0){
    	C = D;
    	D = r;
    	r = C % D;
  	}
	E = x/D;
	c = B/E-A/E;
	long long ans = 0;
	ans = B-A-(a+b-c);
	cout <<ans ;
}

Measured memory_bytes: 256