akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    string s;
    int f, l;
    cin >> s;
    f = s.find("A");
    reverse(s.begin(), s.end());
    l = s.find("Z");
    cout << s.size() - f - l << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
struct edge{ll to,cost;};
vector<vector<edge>> graph;
vector<int> d1;
int n,m;
int s,t;
void dijkstra(ll s){
    d1.resize(3*n);
    for(int i=0;i<3*n;i++)d1[i]=INT_MAX;//訪れていない頂点をinfで初期化
    d1[s]=0;
    priority_queue<P,vector<P>,greater<P>> q;
    q.push(P(0,s));//始点を０で置く
    while(!q.empty()){
        P a=q.top();
        q.pop();
        if(d1[a.se]<a.fi)continue;
        for(int i=0;i<graph[a.se].size();i++){
            edge e=graph[a.se][i];
            if(d1.at(e.to)>d1[a.se]+e.cost){
                d1.at(e.to)=d1[a.se]+e.cost;//訪れていないorより低いコストの経路を発見した時、値を更新
                q.push(P(d1[e.to],e.to));//コストの低いところ優先のbfs
            }
        }
    }
}
int main(){
   cin>>n>>m;
   graph.resize(3*n);
   for(int i=0;i<m;i++){
       int a,b;
       cin>>a>>b;
       a--;b--;
       graph[a].push_back(edge{b+n,1});
       graph[a+n].push_back(edge{b+2*n,1});
       graph[a+2*n].push_back(edge{b,1});
   }
   cin>>s>>t;
   //t=t+2*n;
   s--;t--;
   dijkstra(s);
   if(d1[t]%3!=0){
       cout<<-1<<endl;
   }
   else cout<<d1[t]/3<<endl;
}

Measured memory_bytes: 17792
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAX_N = 105;
const int MAX_K = 100005;
const int MOD = 1000000007;

int n,k,a[MAX_N];
int dp[MAX_N][MAX_K],sum[MAX_K];

int main()
{
	scanf("%d %d",&n,&k);
	for (int i=1; i<=n; i++)
		scanf("%d",a+i);
	dp[0][0]=1;
	for (int i=1; i<=n; i++)
	{
		for (int j=1; j<=k+1; j++)
			sum[j]=(sum[j-1]+dp[i-1][j-1])%MOD;
		for (int j=0; j<=k; j++)
			dp[i][j]=(sum[j+1]-sum[max(0,j-a[i])]+MOD)%MOD;
	}
	printf("%d\n",dp[n][k]);
	return 0;
}


Measured memory_bytes: 40704
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		BigDecimal three = BigDecimal.valueOf(3);
		BigDecimal maxlength = BigDecimal.valueOf(num).divide(three, 9, BigDecimal.ROUND_DOWN);
		System.out.println(maxlength.pow(3));
		
	}
}

Measured memory_bytes: 23636
#include <stdio.h>

int main(void) {
	int N,i,t;
	scanf("%d",&N);
	for(i=3;i<=N;i++){
		if(i%3==0){
			printf(" %d", i);
		}else {
			t=i;
			while(t>0){
				if(t%10==3){
					printf(" %d", i);
					break;
				}else{
					t /= 10;
				}
			}
		}
	}
	printf("\n");
	return 0;
}

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

// using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"

void Main() {
  int n, a, b, c, d;
  std::cin >> n >> a >> b >> c >> d;
  std::string s;
  s.reserve(n);
  std::cin >> s;

  for (int i = b; i < d - 1; ++i) {
    if (s[i] == '#' && s[i + 1] == '#') {
      std::cout << "No\n";
      return;
    }
  }
  for (int i = a; i < c - 1; ++i) {
    if (s[i] == '#' && s[i + 1] == '#') {
      std::cout << "No\n";
      return;
    }
  }
  if (c > d) {
    for (int i = b - 2; i < d - 1; ++i) {
      if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
        std::cout << "Yes\n";
        return;
      }
    }
  } else {
    std::cout << "Yes\n";
    return;
  }
  std::cout << "No\n";
  return;
}

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


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

const ll INF = 1e9+5;

void solution(){
	ll n,k;
	cin>>n>>k;
	vector<ll> h(n);
	for(ll& x: h)
		cin>>x;
	vector<ll> dp(n,INF);
	dp[0] = 0;
	for(ll i=0;i<n;++i)
		for(ll j=i+1; j<= i+k;++j)
			if(j < n)
				dp[j] = min(dp[j],dp[i] + abs(h[i] - h[j]));
	cout<<dp[n-1]<<'\n';
	
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cerr.tie(0);
	solution();
	return 0;
}

Measured memory_bytes: 4744
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
    #define debug(...) printf(__VA_ARGS__)
#else
    #define debug(...) (void)0
#endif
#define MP make_pair
#define PB push_back
#define LL long long
#define pii pair<int,int>

#define F first
#define S second
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
//const int inf = 0x7fffffff; //beware overflow
//const LL INF = 0x7fffffffffffffff; //beware overflow
#define mem(x, y) memset(x, (y), sizeof(x) );
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) {
     return s<<"("<<p.first<<","<<p.second<<")";
}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c) {
    s << "[ ";
    for (auto it : c) s << it << " ";
    s << "]";
    return s;
}
template<typename T>
ostream& operator << (ostream &o, const set<T> &st) {
    o << "{";
    for (auto it=st.begin(); it!=st.end(); it++) o << (it==st.begin() ? "" : ", ") << *it;
    return o << "}";
}
template<typename T1, typename T2>
ostream& operator << (ostream &o, const map<T1, T2> &mp) {
    o << "{";
    for (auto it=mp.begin(); it!=mp.end(); it++) {
        o << (it==mp.begin()?"":", ") << it->fi << ":" << it->se;
    }
    o << "}";
    return o;
}
inline LL getint(){
   LL _x=0,_tmp=1; char _tc=getchar();
   while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
   if( _tc == '-' ) _tc=getchar() , _tmp = -1;
   while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
   return _x*_tmp;
}
#define maxn 100005
int main() {
    int n=getint();
    LL A = getint(), B = getint();
    LL ans=0;
    int now = getint();
    for(int i=1;i<n;i++) {
        int x = getint();
        ans += min(A*(x-now), B);
        now = x;
    }
    cout << ans << endl;



}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();

        System.out.println(c + " " + a + " " + b);
        scan.close();
    }
}

Measured memory_bytes: 21844
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();

        long cnt = 0;

        for (int i=1; i<n; i++) {
            int a = i;
            int diff = n - a;
            int tmpC = (diff % a == 0) ? diff / a : diff / a + 1;
            cnt += tmpC;
//            System.out.println(tmpC);
        }

        System.out.println(cnt);


    }


}



Measured memory_bytes: 35656
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define maxN 207
using namespace std;
int main() {
  fastio;
  int x = 0;
  cin >> x;
  cout << !x;
}

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

int main()
{
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < D; j++)
    {
      cin >> X.at(i).at(j);
    }
  }
  int ans = 0;
  for (int i = 0; i < N - 1; i++)
  {
    for (int j = i + 1; j < N; j++)
    {
      int square_sum = 0;
      for (int k = 0; k < D; k++)
      {
        square_sum += pow((X.at(i).at(k) - X.at(j).at(k)), 2);
      }
      if (ceil(sqrt(square_sum)) == floor(sqrt(square_sum)))
        ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
inline int rd(){
	int x=0,p=1;
	char a=getchar();
	while((a<48||a>57)&&a!='-')a=getchar();
	if(a=='-')p=-p,a=getchar();
	while(a>47&&a<58)x=(x<<1)+(x<<3)+(a&15),a=getchar();
	return x*p;
}
int n;
int main(){
	scanf("%d",&n);
	printf("%.10lf\n",1.0*(n/2+(n%2))/n);
	return 0;
}

Measured memory_bytes: 128
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
//* vamsicool007    You are never wrong to do the right thing    vamsicool007 *
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
const int N=200005;
vector<int>vis(N);
vector<vector<int>>adj(N);
void dfs(int v){vis[v]=1;for(auto i:adj[v]){if(!vis[i]){dfs(i);}}return;}
bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll ans=a>b?a:b;return ans;}
ll min(ll a,ll b){ll ans=a<b?a:b;return ans;}
int root(int a[],int i){while(a[i]!=i){a[i]=a[a[i]];i=a[i];}return i;}
void unionn(int a[],int i,int j){int root_i=root(a,i);int root_j=root(a,j);a[root_i]=root_j;return;}
// void fun()
// {
//     #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
//     #endif
// }

int f1(int n)
{
    n--;
    n=(n*(n+1))/2;
    return n;
}
signed main()
{
    flash;
    //fun();
    int tt=1;
    //cin>>tt;
    while(tt--)
    {
        int n;
        cin>>n;
        int a[n];
        map<int,int>m;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            m[a[i]]++;
        }
        map<int,int>m1;
        int sum=0;
        for(auto i:m)
        {
            if(i.S>0)
            {
                m1[i.F]=f1(i.S);
                sum+=f1(i.S);
            }
        }
        for(int i=0;i<n;i++)
        {
            int s=sum;
            s=s-m1[a[i]];
            s+=f1(m[a[i]]-1);
            cout<<s<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 25216
#include<stdio.h>
#define IN 2000

int main()
{
  int n,i,j,k,minj,min,total=0;
  int A[101][101];
  int a[101];
  int flag[101];
  
  scanf("%d",&n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      
      scanf("%d",&A[i][j]);
    }
  }

  for(i=0; i<n; i++){
    a[i] = IN;
    flag[i] = 0;
  }
  a[0] = 0;
  

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

    flag[minj] = 1;

    for(k = 0; k<n; k++){
      if((A[minj][k]<a[k]) && (A[minj][k] != -1) && (flag[k] == 0)){
	a[k] = A[minj][k];
      }
    }
  }
  
  for(i=0; i<n; i++){
    total += a[i];
  }
  
  printf("%d\n",total);
  return 0;
}



Measured memory_bytes: 2084
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pii pair<ll,ll>
#define F first
#define S second
#define pb push_back
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll mod1=998244353,mod2=(ll)1e9+7;
ll power(ll n,ll k,ll mod){ll ans=1; n=n%mod;while(k>0){if(k&1)ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return (ans+mod)%mod;}//negative nos & 0^0
struct triplet{ll a,b,c;};bool operator < (const triplet &t1,const triplet &t2){if(t1.a<t2.a)return true;if(t1.a==t2.a && t1.b <t2.b)return true;if(t1.a==t2.a && t1.b ==t2.b && t1.c<t2.c)return true;return false;}

int main()
{
    fio;
    string s;
    cin>>s;
    string ans="";
    int got=0;
    for(int i=0;i<s.size()/2;i++)
        {
            ans+="hi";
            if(ans==s)
              got=1;
        }
    if(got)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 256
N = int(input())
L = [int(i) for i in input().split()]

from bisect import bisect_left

L.sort()

count = 0
for i in range(0, N - 2):
    for j in range(i + 1, N - 1):
        length = L[i] + L[j]
        idx = bisect_left(L, length)
        count += idx - j - 1

print(count)


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

int main()
{
    int i,j,n,t,a,b,c=0;
    int ara[6];
    for(i=1;i<=5;i++)
        cin>>ara[i];
        
     for(i=1;i<=5;i++)
        {
            if(ara[i]==0){
                cout<<i<<"\n";
                break;
            }
        }
    return 0;
    
}


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

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

template<class T> class RangeMinQuery {
private:
	vector<T> dat;
	int n;
	T INF;
public:
	RangeMinQuery(int n_) {
		INF = numeric_limits<T>::max();
		n = 1;
		while (n < n_) n *= 2;
		dat.assign(2*n-1,INF);
	}
	void update(int k, T a) {
		k += n - 1;
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	T query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)return INF;
		if (a <= l && r <= b)return dat[k];
		else {
			T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return min(vl, vr);
		}
	}
	T query(int a, int b) {
		return query(a, b, 0, 0, n);
	}
};

int main() {

	int n, q; cin >> n >> q;
	RangeMinQuery<ll> S(n);

	ll inf = (1LL << 31) - 1;
	REP(i, n) S.update(i, inf);

	REP(_, q) {
		ll c, x, y; cin >> c >> x >> y;
		if (c == 0) {
			S.update(x, y);
		} else {
			cout << S.query(x, y + 1) << '\n';
		}
	}
}


Measured memory_bytes: 4964
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

/* Trie 木： 文字の種類(char_size)、int型で0に対応する文字(base)
   insert(word): 単語 word を Trie 木に挿入する
   search(word): 単語 word が Trie 木にあるか判定する
   start_with(prefix):  prefix が一致する単語が Trie 木にあるか判定する
   count(): 挿入した単語の数を返す
   size(): Trie 木の頂点数を返す
   計算量：insert, search ともに O(M)（Mは単語の長さ）
*/
template <int char_size, int base>
struct Trie {
  struct Node {            // 頂点を表す構造体
    vector<int> next;    // 子の頂点番号を格納。存在しなければ-1
    vector<int> accept;  // 末端がこの頂点になる単語の word_id を保存
    int c;               // base からの間隔をint型で表現したもの
    int common;          // いくつの単語がこの頂点を共有しているか
    Node(int c_) : c(c_), common(0) {
      next.assign(char_size, -1);
    }
  };

  vector<Node> nodes;  // trie 木本体
  int root;
  Trie() : root(0) {
    nodes.push_back(Node(root));
  }

  void insert(const string &word, int word_id) {
    int node_id = 0;
    for (int i = 0; i < (int)word.size(); i++) {
      int c = (int)(word[i] - base);
      int &next_id = nodes[node_id].next[c];
      if (next_id == -1) {  // 次の頂点が存在しなければ追加
        next_id = (int)nodes.size();
        nodes.push_back(Node(c));
      }
      ++nodes[node_id].common;
      node_id = next_id;
    }
    ++nodes[node_id].common;
    nodes[node_id].accept.push_back(word_id);
  }
  void insert(const string &word) {
    insert(word, nodes[0].common);
  }

  bool search(const string &word, bool prefix = false) {
    int node_id = 0;
    for (int i = 0; i < (int)word.size(); i++) {
      int c = (int)(word[i] - base);
      int &next_id = nodes[node_id].next[c];
      if (next_id == -1) {  // 次の頂点が存在しなければ終了
        return false;
      }
      node_id = next_id;
    }
    return (prefix) ? true : nodes[node_id].accept.size() > 0;
  }

  bool start_with(const string &prefix) {
    return search(prefix, true);
  }

  int count() const {
    return (nodes[0].common);
  }
  int size() const {
    return ((int)nodes.size());
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<string> S(n);
  Trie<26, 'a'> trie;
  rep(i, n) {
    cin >> S[i];
    reverse(all(S[i]));
    trie.insert(S[i]);
  }
  ll ans = 0;
  rep(i, n) {
    vector<vector<int>> alpha(S[i].size(), vector<int>(26));
    rrep(j, S[i].size()) {
      alpha[j][S[i][j]-'a']++;
      if(j) rep(k, 26) alpha[j-1][k] += alpha[j][k];
    }
    auto node = trie.nodes[0];
    rep(j, S[i].size()) {
      rep(k, 26) {
        if(alpha[j][k]) {
          int next_id = node.next[k];
          if(next_id != -1) ans += trie.nodes[next_id].accept.size();
        }
      }
      int next_id = node.next[S[i][j]-'a'];
      if(next_id == -1) break;
      node = trie.nodes[next_id];
    }
  }
  ans -= n;
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 295552
n = gets.to_i

hs = [0] + gets.split.map(&:to_i) + [0]
i = 0
loop do
  if hs.all?{ |h| h <= 0 }
    puts i
    break
  end
  s = 0
  t = 0
  
  (0..n+1).each do |i|
    if s == 0 && hs[i] != hs[i+1]
      s = i + 1
    elsif s != 0 && hs[i] == 0
      t = i
    end
    if s != 0 && t != 0
      break
    end
  end

  dif = hs[s...t].min
  i += dif
  (s...t).each do |j|
    hs[j] -= dif
  end
end

Measured memory_bytes: 1788
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <list>
#include <deque>
#include <set>
#include <map>
#include <cstdlib>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-9

LL f(LL n,LL x)
{
	if(n%x == 0) return n*2ll-x;
	return n/x*x*2ll+f(x,n%x);
}

int main()
{
	LL n,x;
	cin>>n>>x;
	cout<<f(x,n-x) + n<<endl;
	return 0;
}


Measured memory_bytes: 256
import math
from functools import lru_cache
from operator import mul
from functools import reduce


def resolve():
    import sys
    input = sys.stdin.readline
    MOD = 10**9 + 7
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    A.sort()
    B = A[::-1]

    @lru_cache(maxsize=None)
    def combinations_count__(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    @lru_cache(maxsize=None)
    def combinations_count____(n, r):
        r = min(r, n - r)
        numer = reduce(mul, range(n, n - r, -1), 1)
        denom = reduce(mul, range(1, r + 1), 1)
        return numer // denom

    def combinations_count_(n, r):
        if n - r < r: r = n - r
        if r == 0: return 1
        if r == 1: return n

        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]

        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot

        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])

        return result

    def modinv(a, mod=10**9+7):
        return pow(a, mod-2, mod)

    def combinations_count(n, r, mod=10**9+7):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n-r)
        return fact[n] * factinv[r] * factinv[n-r] % mod
    
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)

    sum = 0
    for i in range(K-1, N):
        sum += combinations_count(i, K-1) * A[i] % MOD - combinations_count(i, K-1) * B[i] % MOD

    print(sum % MOD)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 22064
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

bool solve(LL m, string &s, bool isL, vector<char> &t, vector<char> &d) {
    int q = t.size(), n = s.size();
    REP(i,0,q) {
        if (m < 0 || m >= n) break;
        if (t[i] != s[m]) continue;
        if (d[i] == 'L') --m;
        else ++m;
    }
    if (isL) return m < 0;
    else return m >= n;
}

long long meguru_bin(string &s, bool isL, vector<char> &t, vector<char> &d) {
    long long ok = -1;
    long long ng = s.size();
    if (isL == false) swap(ok, ng);

    while (abs(ok - ng) > 1) {
        long long mid = ng + (ok - ng) / 2;
        //cerr << ok << " " << mid << " " << ng << endl;
        if (solve(mid, s, isL, t, d)) ok = mid;
        else ng = mid;
    }

    return ok;
}

void solve() {
    LL n,q;
    string s;
    cin >> n >> q >> s;
    vector<char> t(q), d(q);
    REP(i,0,q) cin >> t[i] >> d[i];
    VVI m(q, VI(26));
    cout << meguru_bin(s, false, t, d) - meguru_bin(s, true, t, d) - 1 << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 27396
H, N = map(int, input().split())
A_list = []
for i in range(1, N+1):
    A_list.append("A_" + str(i))

A_list = map(int, input().split())
A_total = sum(A_list)

if A_total >= H:
    print("Yes")
else:
    print("No")

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> graph(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }

    vector<int> dist(n, -1);
    queue<int> que;
    dist[0] = 0;
    que.emplace(0);
    while (not que.empty()) {
        int v = que.front(); que.pop();
        for (int nv : graph[v]) {
            if (dist[nv] != -1) continue;
            dist[nv] = v + 1;
            que.emplace(nv);
        }
    }

    cout << "Yes" << endl;
    for (int v = 1; v < n; ++v) {
        cout << dist[v] << endl;
    }
    return 0;
}

Measured memory_bytes: 10076
#include <bits/stdc++.h>
/*
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
*/
#define nl "\n"
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define p_un(a) ((void)a)
#define p_st(a) string(a)
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define naj ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define NL cout << endl;
#define sqr(x) (sqrt(x) * 1LL)
#define pcnt(i) __builtin_popcount(i)
#define up_b upper_bound
#define low_b lower_bound
#define lcm(a,b) (a * b) / __gcd(a, b)
#define REVERSE(a, n) reverse(a + 1, a + n + 1);
#define SORT(a, n) sort(a + 1, a + n + 1);
#define rsz resize

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ul;
typedef vector <ll> vl;
typedef vector <bool> vb;
typedef vector <char> vc;
typedef vector <int> vi;
typedef vector <string> vs;
typedef pair <ll, ll> pll;
typedef map <ll, ll> mll;
typedef set <ll> sl;
typedef set <char> sc;
typedef map <string, ll> msl;
typedef map <string, bool> msb;
typedef map <char, ll> mcl;
typedef map <string, string> mss;
typedef vector <vl> vvl;

const ll mxn = 1e6 + 1;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ld eps = 1e-9;
const ld PI = acos(-1);

#define FLN "LOL"

//int dx[]= {1,0,-1,0}; int dy[]= {0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

inline void joji(bool ok = 0) {naj;if(ok){freopen(FLN".in","r",stdin);freopen(FLN".out","w",stdout);}}

map <int, int> m;
              
main () {

	joji();        	
	ll h;
	cin >> h;
	m[h] = 1;
	ll cnt = 0;
	ll x = 1;
	while(h) {
		cnt += x;
		x += x;
		h /= 2;
	}
	cout << cnt;
	return 0;
}





        
                                                             


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

const ll MAXN = 200000;
const ll INF = 1001001001;

ll X, N, ans=0, tmp=10000;
vector<ll> A;

signed main(){
    cin >> X >> N;
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        A.push_back(a);
    }
    for(int i=-2;i<105;i++) {
        if(find(A.begin(), A.end(), i)==A.end()) {
            if(tmp>abs(X-i)) {
                tmp = abs(X-i);
                ans = i;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    k,x = LI()
    if k*500 >= x:
        print("Yes")
    else:
        print("No")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 39024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n;
int ans;

signed main() {
	cin >> n;
	if (n % 2) {
		cout << 0 << endl;
		return 0;
	}
	int k = 10;
	while (k <= n) {
		ans += n / k;
		k *= 5;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	int ans = 0;

	if (A < C) {
		if (B > C) {
			if (B < D) {
				ans = B - C;
			}
			else {
				ans = D - C;
			}
		}
	}
	else {
		if (D > A) {
			if (D < B) {
				ans = D - A;
			}
			else {
				ans = B - A;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

// dp[i][j][pre][eq or low][up or down or first]
int dp[2][500][10][2][3];
const int mod = 10000;

inline void add(int &a, int b) {
  a = (a+b) % mod;
}

int solve(const string &s, int m) {
  memset(dp,0,sizeof(dp));
  REP(i,s.size()) {
    int now = i&1;
    int nxt = (i+1)&1;
    REP(j,m)REP(pre,10)REP(low,2)REP(up,3) dp[nxt][j][pre][low][up]=0;
    REP(j,m) {
      REP(pre,10) {
        REP(k,10) {
          // first digit
          if (k>0 && (i!=0 || k<=s[i]-'0')) {
            bool eqlow = 1;
            if (i==0 && k==s[i]-'0') eqlow = 0;
            dp[nxt][k%m][k][eqlow][2] = 1;
          }
          // other
          if (k<pre) {
            add(dp[nxt][(j*10+k)%m][k][1][1], dp[now][j][pre][1][0]);
            add(dp[nxt][(j*10+k)%m][k][1][1], dp[now][j][pre][1][2]);
            if (k<=s[i]-'0') {
              add(dp[nxt][(j*10+k)%m][k][k!=s[i]-'0'][1], dp[now][j][pre][0][0]);
              add(dp[nxt][(j*10+k)%m][k][k!=s[i]-'0'][1], dp[now][j][pre][0][2]);
            }
          }
          if (k>pre) {
            add(dp[nxt][(j*10+k)%m][k][1][0], dp[now][j][pre][1][1]);
            add(dp[nxt][(j*10+k)%m][k][1][0], dp[now][j][pre][1][2]);
            if (k<=s[i]-'0') {
              add(dp[nxt][(j*10+k)%m][k][k!=s[i]-'0'][0], dp[now][j][pre][0][1]);
              add(dp[nxt][(j*10+k)%m][k][k!=s[i]-'0'][0], dp[now][j][pre][0][2]);
            }
          }
        }
      }
    }
  }
  int ans = 0;
  REP(pre,10) {
    REP(low,2) {
      REP(up,3) {
        // if (dp[s.size()&1][0][pre][low][up]) {
        //   cout << pre << " " << low << " "<< up << endl;
        // }
        add(ans, dp[s.size()&1][0][pre][low][up]);
      }
    }
  }
  return ans;
}

string sub1(string s) {
  for (int i=s.size()-1; i>=0; --i) {
    if (s[i]-'0'-1 < 0) {
      s[i] = '9';
    } else {
      s[i] -= 1;
      return s;
    }
  }
  return s;
}

int main() {
  
  string a, b;
  cin >> a >> b;
  int m;cin >> m;
  // cout << solve(sub1("1"), 1) << endl;
  // cout << solve(string("10"),2) << endl;
  cout << (solve(b,m)-solve(sub1(a),m)+mod)%mod << endl;
}

Measured memory_bytes: 1456
N,M = map(int,input().split())
k = []
for i in range(M):
    k.append(list(map(int,input().split())))
p = list(map(int,input().split()))

ans = 0
for i in range( 1 << N):
    t = [0]*M
    for j in range(N):
        if ((i >> j) & 1) == 1:
            for x in range(M):
                for y in range(k[x][0]):
                    if k[x][y+1] == j+1:
                        t[x] += 1
    c = 0
    for q in range(M):
        if t[q] % 2 == p[q]:
            c += 1
    if c == M:
        ans += 1
print(ans)


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

using namespace std;

const int MOD=1000000007;
int N, K;
int chain[2001];
int tree[2001];
int dp[2001][2001];
int fact[4000001];
int ifact[4000001];

int powmod(int a, int b)
{
    int ret=1;
    for(; b>0; b/=2)
    {
        if(b&1)
            ret=1LL*ret*a%MOD;
        a=1LL*a*a%MOD;
    }
    return ret;
}

int C(int n, int k)
{
    return 1LL*fact[n]*ifact[k]%MOD*ifact[n-k]%MOD;
}

int main()
{
    scanf("%d%d", &N, &K);
    if(K==1)
        return printf("1\n"), 0;
    fact[0]=1;
    for(int i=1; i<=4000000; i++)
        fact[i]=1LL*fact[i-1]*i%MOD;
    ifact[4000000]=powmod(fact[4000000], MOD-2);
    for(int i=3999999; i>=0; i--)
        ifact[i]=1LL*ifact[i+1]*(i+1)%MOD;
    dp[0][0]=1;
    for(int i=1; i<=N; i++)
    {
        if(i==1)
            tree[i]=1;
        else
            tree[i]=1LL*tree[i-1]*C(i*(K-1)-1, K-2)%MOD;
        dp[0][i]=tree[i];
    }
    chain[0]=1;
    for(int i=1; i<=N; i++)
        chain[i]=1LL*chain[i-1]*C(i*(K-2), K-2)%MOD;
    for(int i=1; i<=N; i++)
    {
        for(int j=i; j<=N; j++)
        {
            dp[i][j]=(dp[i-1][j]+1LL*dp[i][j-1]*C(i+(j-1)*(K-1)+K-2, K-2))%MOD;
        }
    }
    printf("%lld\n", 1LL*dp[N][N]*fact[N]%MOD);
    return 0;
}


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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

struct union_find {
	vector<int> v;
	union_find(int n) : v(n, -1) {}
	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(N);
    rep(u, N) cin >> a[u];
    vector<int> x(M), y(M), z(M);
    rep(i, M) {
        cin >> x[i] >> y[i] >> z[i];
        x[i]--; y[i]--;
    }
    vector<i_i> zi(M);
    rep(i, M) zi[i] = i_i(z[i], i);
    sort(all(zi));
    union_find uf(N);
    vector<ll> A(N);
    rep(u, N) A[u] = a[u];
    vector<int> E(N), unko(N);
    int ans = 0;
    for (auto p: zi) {
        int i = get<1>(p);
        int u = x[i], v = y[i], w = z[i];
        if (uf.same(u, v)) {
            E[uf.find(u)]++;
            if (w <= A[uf.find(u)]) {
                unko[uf.find(u)]++;
                ans++;
            }
        }
        else {
            ll tmp = A[uf.find(u)] + A[uf.find(v)];
            ll hoge = E[uf.find(u)] + E[uf.find(v)];
            ll kuso = unko[uf.find(u)] + unko[uf.find(v)];
            uf.unite(u, v);
            A[uf.find(u)] = tmp;
            E[uf.find(u)] = hoge + 1;
            unko[uf.find(u)] = kuso;
            if (tmp >= w) {
                ans += E[uf.find(u)] - unko[uf.find(u)];
                unko[uf.find(u)] = E[uf.find(u)];
            }
        }
    }
    cout << M - ans << endl;
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>  
#define mod 1000000007
#define mp make_pair
#define pb push_back
 
using namespace std;
typedef long long ll;
 
int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	ll n,d;
	cin >> n >> d;
    ll a=2*d+1;
    ll ans= (n+2*d)/a;
    cout << ans << endl;
}


Measured memory_bytes: 256
// Tazoe

#include <iostream>
using namespace std;

int main()
{
while(true){
	int total;
	cin >> total;
if(total==0)  break;
	int p1, p2, p3, p4, p5, p6, p7, p8, p9;
	cin >> p1;
	cin >> p2;
	cin >> p3;
	cin >> p4;
	cin >> p5;
	cin >> p6;
	cin >> p7;
	cin >> p8;
	cin >> p9;

	int p10 = total-p1-p2-p3-p4-p5-p6-p7-p8-p9;

	cout << p10 << '\n';
}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int n, k;

int main()
{
	cin >> n >> k;
	int a = 1;
	for (int i = 0; i < n; i++) {
		if (a + k > 2 * a)a = 2 * a;
		else a += k;
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = n; i <= 999; i++) {
        int k3 = i / 100;
        int k2 = (i - k3 * 100) / 10;
        int k1 = (i - k3 * 100 - k2 * 10);
        if (k1 == k2 && k2 == k3) {
            cout << i << endl;
            break;
        }
        
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    val aa = scan.nextLine().split(" ").map{ it.trim().toInt() }.toTypedArray()
    var ab  = scan.nextLine().split(" ").map{ it.trim().toInt() }.toTypedArray()
    var n=aa[0]
    var k= aa[1]

    ab=ab.sortedDescending().toTypedArray()

    for(i in 0..k-1)
    {
        if(i<=ab.size-1)
            ab[i]=0
    }
    var z : Long = 0
    for(x in ab)
        z+=x
    print(z)
}


Measured memory_bytes: 97316
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p=sorted(p,reverse=True)
q=sorted(q,reverse=True)
r=sorted(r)
p=p[:x]
q=q[:y]

import heapq
from collections import deque

heapq.heapify(p)
heapq.heapify(q)
r=deque(r)

for i in range(c):
    v_p=heapq.heappop(p)
    v_q=heapq.heappop(q)

    v_r=r.pop()
    if v_p<=v_q:
        heapq.heappush(q,v_q)
        if v_p<v_r:
            heapq.heappush(p,v_r)
        else:
            heapq.heappush(p,v_p)
    else:
        heapq.heappush(p,v_p)
        if v_q<v_r:
            heapq.heappush(q,v_r)
        else:
            heapq.heappush(q,v_q)

ans=sum(p)+sum(q)

print(ans)

Measured memory_bytes: 29732
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
const int MOD = 1000000007;
typedef pair<long long,long long> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}



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

    string S;cin >> S;
    long long now = 0;
    for(int i = 0;i<S.size();i++){
        now += S.at(i)-'0';
    }
    if(now % 9 == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
#define ll  long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD = 1000000007;
ll cnt =0,ans=0;
const int MAX = 510000;

int main(){

  ll n;cin >> n;

    string s;   cin >> s;
    ll r=0,g=0,b=0;

    for(int i=0;i<n;i++){
        if(s.at(i) == 'R')r++;
        if(s.at(i) == 'G')g++;
        if(s.at(i) == 'B')b++;
    }

    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            int k = j+(j-i);
            if(k>=n)break;
            if(s.at(i) != s.at(j) && s.at(j) != s.at(k) && s.at(k) != s.at(i))cnt++;
        }


    }
    cout << r*g*b - cnt << endl;
}
       


Measured memory_bytes: 3624
/**
  @file a.cpp
  @title A - Red or Not
  @url https://atcoder.jp/contests/abc138/tasks/abc138_a
**/

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

typedef long long LL;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, N) for (int i = 0; i < (N); ++i)

int main() {
  int a;
  string s;
  cin >> a;
  cin >> s;

  if (a >= 3200) {
    cout << s << endl;
  } else {
    cout << "red" << endl;
  }

  return 0;
}


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

int main() {
	int K;
  	string S;
  	cin>> K >> S;
  	
  	if(S.size()<=K){
      	cout<<S<<endl;
    }	
  	else{
     	 for(int i=0;i<K;i++){
          	 cout<<S[i];
         }
      	
      	 cout<<"..."<<endl;
    }
  	
  	
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
	return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
	return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef EZZAT
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#else
#endif
}


int main() {
	run();
	string s;
	cin >> s;
	s[1] =(s[1] == 'R'?'B':'R');
	cout << s;
}


Measured memory_bytes: 3636
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;
class UnionFind
{
public:
	int p[N];
	void init(int n = N)
	{
		memset(p, -1, sizeof(int) * n);
	}
	int treesize(int x)
	{
		return -p[Find(x)];
	}
	int Find(int x)
	{
		int s = x;
		while (p[s] >= 0) s = p[s];
		while (x != s)
		{
			int t = p[x];
			p[x] = s;
			x = t;
		}
		return s;
	}
	void Union(int x, int y)
	{
		int px = Find(x);
		int py = Find(y);
		if (p[px] > p[py]) swap(px, py);
		p[px] += p[py];
		p[py] = px;
	}
} uf;
vector<tuple<int, int, int>> vt;
void solve(vector<pair<int, int>>& vp)
{
	sort(vp.begin(), vp.end());
	for (int i = 0; i + 1 < vp.size(); i++)
	{
		vt.emplace_back(vp[i + 1].first - vp[i].first, vp[i].second, vp[i + 1].second);
	}
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	uf.init();
	vector<pair<int, int>> vp1, vp2;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int x, y;
		cin >> x >> y;
		vp1.emplace_back(x, i);
		vp2.emplace_back(y, i);
	}
	solve(vp1);
	solve(vp2);
	LL ans = 0;
	sort(vt.begin(), vt.end());
	for (auto& p : vt)
	{
		int x, y, w;
		tie(w, x, y) = p;
		if (uf.Find(x) == uf.Find(y)) continue;
		uf.Union(x, y);
		ans += w;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7528
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np

H, W = MAP()
if H == 1 or W == 1:
	print(1)
else:
	print(-(-H*W//2))

Measured memory_bytes: 5392
from collections import defaultdict
h,w,m = [int(x) for x in input().split()]
hc = [0]*h
wc = [0]*w
d = defaultdict(int)
for i in range(m):
    hh,ww = [int(x) for x in input().split()]
    wc[ww-1] += 1
    hc[hh-1] += 1
    d[(hh-1)*3*(10**5)+ww-1] = 1
mhc = max(hc)
mwc = max(wc)
mhcIndex = [i for i, x in enumerate(hc) if x == mhc]
mwcIndex = [i for i, x in enumerate(wc) if x == mwc]
ans = mhc + mwc
for i in mhcIndex:
    for j in mwcIndex:
        if d[i*3*(10**5)+j] == 0:
            print(ans)
            exit()
print(ans-1)

Measured memory_bytes: 57264
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

template<class T>bool chmax(T &a, const T &b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}

template<class T>bool chmin(T &a, const T &b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

LL lcm(LL a,LL b){
	return a*b/gcd(a,b);
}

int main(){
	cout<<fixed;
	//cout<<setprecision(9)<<...
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double t = 60 * h + m;
	double spm = 0.5, lpm = 6.0;
	double theta = (lpm-spm) * t;
	while(theta > 360){
		theta -= 360;
	}
	theta = theta * acos(-1) / 180;

	double ans = 0;
	ans = a*a + b*b - 2*a*b * cos(theta);
	ans = sqrt(ans);
	cout<<setprecision(9)<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4188