akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 1e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int n,k;
int a[200010];
int mi[200010], ma[200010];
int increase[200010];

void input() {
  cin>>n>>k;
  REP(i,n) cin>>a[i];
}

void solve(){
  int ans=n-k+1;
  
  // 不連続部分を引く
  REP(i,n-1){
    if(a[i+1]>a[i]) increase[i]++;
  }
  
  int blocks=0;
  int cnt=0;
  REP(i,n){
    if(increase[i]){
      cnt++;
    }
    else{
      if(cnt>=k-1){
        blocks++;
      }
      cnt=0;
    }
  }
  ans-=max(0,blocks-1);
  
  // 連続部分を引く
  set<int> st;
  REP(i,k) st.insert(a[i]);
  REP(i,n-k){
    int mi=*st.begin();
    st.erase(a[i]);
    st.insert(a[i+k]);
    auto it=st.end();
    it--;
    int ma=*it;
    ans-=(mi==a[i]&&ma==a[i+k]);
  }
  
  cout<<ans<<endl;
}

int main(int argc,char *argv[]){
  input();
  solve();
  return 0;
}

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

int main() {
  ll n;
  cin >> n;

  for (ll i = 1; i <= 9; i++) {
    for (ll j = 1; j <= 9; j++) {
      if (i * j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
int main()
{
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i = 0; i < n; i++){
        cin>>a[i];
    } 
    for(int i = 0; i < n; i++){
        cin>>b[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(a[i] >= b[i]){
            ans += a[i] - b[i];
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3572
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin>>n;
    if(n%1000==0)
        cout<<0<<endl;
    else cout<<1000-(n%1000)<<endl;
    return 0;
}



Measured memory_bytes: 3632
/*----------------by syr----------------*/
/*

         iii                  ii
     rBQBBBBBBE       BBR iBBBBQBBL     XBBBBBBQBBBBB
   iBBQJ    7BBB      BBsSBBr   BBQ      i      cBBB
  rBBU       iBBw     BBBQi     HBBi           KBBi
  BBH         BB5    iBBB       isL          wBB5
 GBB         iBBi    6BB                   iBBB
 BBQ         BQB     BBD                  QBBi
 BBB        BQB     iQBi                1BBv
 sBBg     wBBB      QBB               iBBB
  7BBBBBBBBBi       BBR              wBBBBBBBBBBBBB
     irvi           ii               ii    i i iii
                i5U
               BBB
               BB7
              1BB
      iPBBBBBKBBR    JBR1       rQBO   BR  UBQP  iBBQi
    7BBBGs7sXBBBi     QBBr     gBBE   rBB BB2BB7HBZQBB
   QBBi      sBQ       BBB   iBBB     SQBBR  BBBB  cBQ
  gBQ        BBg        BBB KBBi      MBBH   BBB   BBs
 iBBv       iBBi         QBBBL        BBR   pBB   iBB
 pBB        BBB         iBBBB        iBB    BBL   KBB
 MBB       BBBR        BBB JBBi      DBR   iBQ    BBL
 GBB     7BBBB2      PBBH   BBBi     BQr   DBB   iBB
  BQBXwgBBP BB7    1BBB      BBQ7   1BB    BBc   BBB
   2BBBBw   BB    EBBS        QBBi  HBa   iBB    BB7
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int maxn = 1e5 + 5;
const ll INF = 1e12 + 7;

int n;
int par[maxn], sz[maxn];
bool used[maxn];
ll mn = INF, sum = 0;
ll d[maxn], sub[maxn], dis[maxn];
vector<pair<ll, int> > vec;

int main(){
	scanf("%d", &n);
	FOR(i, 0, n){
		scanf("%lld", d + i);
		vec.PB(MP(d[i], i));
		mn = min(d[i], mn);
	}
	sort(vec.begin(), vec.end());
	FOR(i, 0, n) sz[i] = 1;
	FOR(i, 0, n) sub[i] = -INF;
	memset(par, -1, sizeof(par));
	for(int i = vec.size() - 1; i >= 0; --i){
		int id = vec[i].snd;
		//printf("i = %d id = %d (%d, %d)\n", i, id, vec[i].fst, vec[i].snd);
		if(d[id] == mn){
			FOR(i, 1, vec.size()){
				int u = vec[i].snd;
				dis[u] = dis[par[u]] + 1;
				sum += dis[u];
			}
			if(sum != d[id]){
				puts("-1");
				return 0;
			}
			break;
		}
		if(sub[id] == -INF) sub[id] = n - 2;
		int pos = lower_bound(vec.begin(), vec.end(), MP(d[id] - sub[id], -1)) - vec.begin();
		//printf("id = %d %d %d\n", id, d[id] - sub[id], pos);
		if(pos >= i || vec[pos].fst != d[id] - sub[id]){
			puts("-1");
			return 0;
		}
		par[id] = vec[pos].snd;
		sz[par[id]] += sz[id];
		sub[par[id]] = (n - sz[par[id]] - sz[par[id]]);
	}
	FOR(i, 0, n) if(d[i] != mn) printf("%d %d\n", i + 1, par[i] + 1);
	return 0;
}



Measured memory_bytes: 6640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define in_range(x,l,r) (l<=x && x<r)
using namespace std;
typedef pair<int,int> pii;

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

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

  int h,w;
  cin >> h >> w;

  vector<string> g(h);
  rep(i,h)cin >> g[i];

  map<pii,int> dif;
  int init = -1, last = 1;
  rep(i,h+1)rep(j,w+1){
    
    int cnt = 0;
    rep(d,4){
      int flag = 0;
      int ny = i + dy[d], nx = j + dx[d];
      if(in_range(ny,0,h) && in_range(nx,0,w) && g[ny][nx]=='#')flag++;
      ny = i + dy[(d+1)%4]; nx = j + dx[(d+1)%4];
      if(in_range(ny,0,h) && in_range(nx,0,w) && g[ny][nx]=='#')flag++;

      //cout << i << " " << j << " " << d << " " << flag << endl;
      if(flag==1){
	if((d+1)%4>=2)cnt--;
	else cnt++;
      }
    }

    int y = h-i, x = j;
    if(y==0 && x==0)continue;
    else if(y==0)init += cnt;
    else if(x==0)last += cnt;
    else{
      int gcd = __gcd(y,x);
      pii key = pii(y/gcd, x/gcd);
      dif[key] += cnt;
    }
  }

  vector< pair<double,int> > event;
  for(auto p : dif){
    event.push_back( make_pair( (double)p.first.first/p.first.second, p.second ) );
  }
  sort(event.begin(), event.end());
  
  int res = init, cur = init;
  //cout << init << endl;
  for(auto p : event){
    //cout << p.first << " " << p.second << endl;
    cur += p.second;
    res = max(res, cur);
  }
  //cout << last << endl;

  res = max(res, res+last);
  cout << (res+1)/2 + 1 << endl;
}

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

struct StNode
{
  StNode* m_poParnt;
  StNode* m_poLeft;
  StNode* m_poRigt;
  int m_nKey;

  StNode(int nNo) :
    m_poParnt(nullptr), m_poLeft(nullptr), m_poRigt(nullptr), m_nKey(nNo)
  { }
};

void fnInsert(StNode*& rpoRoot, StNode* poNewMe)
{
  StNode*  poParnt = nullptr;
  StNode** ppoNode = &rpoRoot;

  while (*ppoNode)
  {
    poParnt = *ppoNode;
    if (poNewMe->m_nKey < poParnt->m_nKey)
      ppoNode = &poParnt->m_poLeft;
    else
      ppoNode = &poParnt->m_poRigt;
  }
  poNewMe->m_poParnt = poParnt;
  *ppoNode = poNewMe;
}

void fnInOrder(StNode* poNode)
{
  if (!poNode)  return;

  fnInOrder(poNode->m_poLeft);
  cout << " " << poNode->m_nKey;
  fnInOrder(poNode->m_poRigt);
}

void fnPreOrder(StNode* poNode)
{
  if (!poNode)  return;

  cout << " " << poNode->m_nKey;
  fnPreOrder(poNode->m_poLeft);
  fnPreOrder(poNode->m_poRigt);
}

void fnBinSchTree(StNode*& rpoRoot)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  for (int i = 0; i < nMaxSiz; ++i)
  {
    string sCmd;
    cin >> sCmd;
    if (sCmd[0] == 'i')
    {
      int nNo;
      cin >> nNo;
      StNode* poNewNod = new StNode(nNo);
      fnInsert(rpoRoot, poNewNod);
    }
    if (sCmd[0] == 'p')
    {
      fnInOrder(rpoRoot);
      cout << endl;
      fnPreOrder(rpoRoot);
      cout << endl;
    }
  }
}

void fnPstOrder(StNode* poNode)
{
  if (!poNode)  return;

  fnPstOrder(poNode->m_poLeft);
  fnPstOrder(poNode->m_poRigt);
  delete poNode;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  StNode* poRoot = nullptr;

  fnBinSchTree(poRoot);
//fnPstOrder(poRoot);
  return 0;
}

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

int to_int(string s){
  int num = 1, res = 0;
  for(int i = 0; i < s.size(); i++){
    if('a' <= s[i] && s[i] <= 'z'){
      if(num == 0) num = 1;
      if(s[i] == 'm') res += num * 1000;
      if(s[i] == 'c') res += num * 100;
      if(s[i] == 'x') res += num * 10;
      if(s[i] == 'i') res += num * 1;
      num = 0;
    }else{
      num = s[i] - '0';
    }
  }
  return res;
}

void print(int num){
  int res = num / 1000;
  if(res > 1) cout << res;
  if(res > 0) cout << 'm';
  num %= 1000;

  res = num / 100;
  if(res > 1) cout << res;
  if(res > 0) cout << 'c';
  num %= 100;

  res = num / 10;
  if(res > 1) cout << res;
  if(res > 0) cout << 'x';
  num %= 10;

  if(num > 1) cout << num;
  if(num > 0) cout << 'i';
  cout << endl;
}

int main(){
  int n, num1, num2;
  string s1, s2;
  cin >> n;
  for(int i = 0; i < n; i++){
    string res = "";
    cin >> s1 >> s2;
    num1 = to_int(s1);
    num2 = to_int(s2);
    print(num1 + num2);
  }
  return 0;
}



Measured memory_bytes: 3020
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <numeric>

int main()
{
    int n;
    int hp[100000];
    
    scanf("%d", &n);
    
    for(int i = 0;i < n;i++)
    {
        scanf("%lld", &hp[i]);
    }

    if(n == 1)
    {
        printf("%d",hp[0]);
        return 0;
    }

    int result = std::__gcd(hp[0], hp[1]);
    for(int i = 2;i < n;i++)
    {
        result = std::__gcd(result, hp[i]);
    }
    printf("%d",result);
    
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

int keta(int x){
	if(!x) return 1;
	int t = 0;
	while(x) x /= 10,t++;
	return t;
}

signed main(){
	int n,m,s[10],c[10];
	cin >> n >> m;
	for(int i = 0;i < m;i++) cin >> s[i] >> c[i];
	int pow10[] = {1,10,100,1000};
	for(int i = 0;i < 1000;i++){
		if(keta(i) == n){
			bool isOK = true;
			for(int j = 0;j < m;j++){
				if(i / pow10[n - s[j]] % 10 != c[j]) isOK = false;
			}
			if(isOK){
				cout << i << endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

int main()
{
  int N;
  cin >> N;

  unsigned sum = 0;

  int b_prev;
  for (int n=0; n<N-1; ++n) {
    int b;
    cin >> b;
    if (n==0)
      sum += b;
    else
      sum += min(b, b_prev);
    b_prev = b;
  }
  sum += b_prev;

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <utility>
#include <bitset>

using namespace std;

typedef pair <int, int> ii;

int N;
vector <ii> adjList[20];
int ans;

int main()
{
    scanf("%d", &N);
    for (int i = 1; i <= N; i++)
    {
        int A; scanf("%d", &A);
        for (int j = 0; j < A; j++)
        {
            int x, y; scanf("%d%d", &x, &y);
            adjList[i].emplace_back(x, y);
        }
    }
    for (int i = 0; i < (1 << N); i++)
    {
        bool possible = true;
        for (int j = 1; j <= N && possible; j++)
        {
            if (i & (1 << (j - 1)))
            {
                for (ii neighbour : adjList[j])
                {
                    int v = neighbour.first, state = neighbour.second;
                    if ((i & (1 << (v - 1)) && state == 0) || (!(i & (1 << (v - 1))) && state == 1))
                    {
                        possible = false;
                        break;
                    }
                }
            }
        }
        if (possible)
        {
            //printf("%s\n", bitset<20>(i).to_string().c_str());
            ans = max((int) bitset<20>(i).count(), ans);
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;
};
using Graph = vector<vector<Edge>>;
// 深さ優先探索
vector<bool> seen;  // 探索したか記録
void dfs(const Graph &G, int v) {
    seen[v] = true;
    for (auto e : G[v]) {
        if (!seen[e.to]) {  // 訪問済みでなければ探索
            dfs(G, e.to);
        }
    }
}
int main() {
    int n, m;
    cin >> n >> m;
    Graph G(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
      a--;
      b--;
        G[a].push_back({b});
        G[b].push_back({a});
    }
    seen.assign(n, false);  // 初期化
    int cnt = 0; 
    for (int i = 0; i < n; i++) {
        if (!seen[i]) {
            dfs(G, i);
            cnt++; // dfsした回数をカウント
        }
    }
    cout << cnt - 1 << endl;
    return 0;
}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int k,a,b;
    cin >> k >> a >> b;
    int sho1 = a/k;
    int sho2 = b/k;
    if(a%k==0 || b%k==0 || sho2-sho1>=1)
    {
        cout << "OK" << endl;
    }else
    {
        cout << "NG" << endl;
    }


}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int N;
  cin >> N;
  vector<int> t(N), v(N+1);
  rep(i, N) {
    cin >> t[i];
    if(i)
      t[i] += t[i-1];
  }
  rep(i, N) cin >> v[i];
  vector<double> graph(t[N-1]*2+1);
  int p = 0;
  rep(i, t[N-1]*2+1) {
    while(i/2.0 > t[p]) p++;
    double mn = i/2.0;
    rep(j, p)
      chmin(mn, v[j]+i/2.0-t[j]);
    chmin(mn, (double)v[p]);
    for(int j=p; j<N; j++)
      chmin(mn, v[j+1]+t[j]-i/2.0);
    graph[i] = mn;
  }
  double ans = 0;
  rep(i, t[N-1]*2)
    ans += (graph[i]+graph[i+1])*0.5/2;
  cout << fixed << setprecision(6) << ans << endl;
  return 0;
}

Measured memory_bytes: 512
import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29

def main():
    n = int(input())
    s = input()
    ans = 0
    x = 0
    for i in s:
        if i=='I':
            x += 1
            ans = max(ans,x)
        else:
            x -= 1
    print(ans)
    return

if __name__=='__main__':
    main()


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

#define ll long long
#define pb push_back
#define ins insert
#define mp make_pair
#define pii pair<int, int>
#define pil pair<int, ll>
#define pib pair<int, bool>
#define SET(a, c) memset(a, c, sizeof(a))
#define MOD 1000000007
#define enld endl
#define endl "\n"
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define FOUND(u, val) u.find(val) != u.end()
#define max_self(a, b) a = max(a, b);

#include <string>
#include <vector>
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
//#include <algorithm>
//#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//#include <cmath>
//#include <cstring>
//#include <sstream>
//#include <stack>
//#include <queue>

ll dp[405][405];
//dp[i][j] will be the minimum total cost of combining [i,j] into one vertex

ll sum(int L, int R, ll ar[]) {
    ll s = 0;
    for (int i = L; i <= R; i++) {
        s += ar[i];
    }
    return s;
}

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

    int n;
    cin >> n;
    ll ar[n];
    for (ll &x : ar) cin >> x;
    // for (int i = 0; i < n; i++) cin >> ar[i];

    /* 
4
10 20 30 40
 */

    for (int L = n - 1; L >= 0; --L) {
        for (int R = L; R < n; ++R) {
            if (L == R) {
                dp[L][R] = 0;
            } else {
                dp[L][R] = 1e18;
                for (int i = L; i < R; i++) {
                    dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R] + sum(L, R, ar));
                }
            }
        }
    }

    cout << dp[0][n - 1];
}

Measured memory_bytes: 4912
package main

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

const mod = 998244353
const facNum = 300001

func main() {
	sc := newScanner(os.Stdin)
	K := sc.i()
	sum := 0
	for i := 1; i <= K; i++ {
		for j := 1; j <= K; j++ {
			for k := 1; k <= K; k++ {
				a := Gcd(i, j)
				b := Gcd(k, a)
				sum += b
			}
		}
	}
	fmt.Println(sum)
}

// fmt.Println("Yes")
// fmt.Println("No")

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}

// vs: sorted slice int value
func lowerBound(vs []int, v int) (index int) {
	n := len(vs) / 2
	m := len(vs)
	for m != n {
		if vs[n] < v {
			n = (m-n+1)/2 + n
			//m = m
		} else {
			m = n
			n = n / 2
		}
	}
	return n
}

func IntSlice(n, init int) []int {
	r := make([]int, n)
	for i := range r {
		r[i] = init
	}
	return r
}


Measured memory_bytes: 1776
#include<iostream>
#include<cstdio>
using namespace std;
int a,b,c,i,j,n,s;
int main()
{
    scanf("%d%d%d%d",&a,&b,&c,&n);
    for (i=0;i<=a;i++)
     for (j=0;j<=b;j++)
      if ((n-i*500-j*100>=0)&&(n-i*500-j*100<=c*50)) ++s;
    printf("%d\n",s);
    return 0;
}

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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int x, t;
	cin >> x >> t;
	print(max(0, x - t));
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll, ll> m;
map<ll, ll> res;

int main(){
  int n;
  cin>>n;
  vector<ll> vec(n, 0);
  for(int i = 0; i < n; ++i)cin>>vec[i];
  for(int i = 0; i < n; ++i){
    m[vec[i]]++; // count occurances
  }
  ll total = 0;
  for(auto x: m){
    ll xp = x.second;
    total += (xp * (xp - 1)) / 2;
  }
  for(auto x : m){
    ll y = x.second;
    ll r = (y * (y - 1)) / 2; 
    y--;
    ll p = (y * (y - 1)) / 2; // count number of pairs with one less occurance of that number
    res[x.first] = total - (r - p);
  }
  for(int i = 0; i < n; ++i){
    cout<<res[vec[i]]<<endl;
  }
  return 0;
}


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

int main(){
  vector<vector<int> > A(3, vector<int>(3));
  int N;
  for(int i=0; i<3; i++){
    for(int j=0;j<3;j++)cin>> A[i][j]; 
  }
  cin >> N;
  vector<int> b(N);
  for(int i=0; i<N; i++)cin >> b[i];

  bool appear[3][3];
  for(int i=0; i<3; i++){
    for(int j=0; j<3;j++){
      appear[i][j]=false;
      for(int k=0; k<N; k++){
        if(b[k]==A[i][j])appear[i][j] = true;
      }
    }
  }
  string ANS = "No";
  for(int i=0; i<3; i++){
    if(appear[i][0] and appear[i][1] and appear[i][2])ANS="Yes";
    if(appear[0][i] and appear[1][i] and appear[2][i])ANS="Yes";
  }
  if(appear[0][0] and appear[1][1] and appear[2][2])ANS = "Yes";
  if(appear[0][2] and appear[1][1] and appear[2][0])ANS = "Yes";
  cout << ANS << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
import copy
def main():
    N = int(input())
    S = []
    for i in range(N):
        s = input()
        S.append(s)
    S.sort()
    count = N
    for i in range(1, len(S)):
        if S[i - 1] == S[i]:
            count -= 1
    print(count)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 24392
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int h, w, a[80][80], b[80][80], dp[80][80][25610];
int main() {
  int ans = 1000000000;
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      scanf("%d", &b[i][j]);
      b[i][j] -= a[i][j];
    }
  }
  dp[0][0][12800 + b[0][0]] = 1;
  dp[0][0][12800 - b[0][0]] = 1;
  for (int i = 1; i < h; i++) {
    for (int j = 0; j <= 25600; j++) {
      if (dp[i - 1][0][j]) {
        dp[i][0][j + b[i][0]] = 1;
        dp[i][0][j - b[i][0]] = 1;
      }
    }
  }
  for (int i = 1; i < w; i++) {
    for (int j = 0; j <= 25600; j++) {
      if (dp[0][i - 1][j]) {
        dp[0][i][j + b[0][i]] = 1;
        dp[0][i][j - b[0][i]] = 1;
      }
    }
  }
  for (int i = 1; i < h; i++) {
    for (int j = 1; j < w; j++) {
      for (int k = 0; k <= 25600; k++) {
        if (dp[i - 1][j][k]) {
          dp[i][j][k + b[i][j]] = 1;
          dp[i][j][k - b[i][j]] = 1;
        }
        if (dp[i][j - 1][k]) {
          dp[i][j][k + b[i][j]] = 1;
          dp[i][j][k - b[i][j]] = 1;
        }
      }
    }
  }
  for (int i = 0; i <= 25600; i++) {
    if (dp[h - 1][w - 1][i]) {
      ans = min(ans, abs(12800 - i));
    }
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 638592
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

void count(
  map<pair<int, int>, bool>& edges,
  const vector<vector<int>>& middle,
  int src, int dst
) {
  int m = middle[src][dst];
  int min = src < dst ? src : dst;
  int max = src < dst ? dst : src;
  if (m < 0) {
    edges[make_pair(min, max)] = true;
  } else {
    count(edges, middle, src, m);
    count(edges, middle, m, dst);
  }
}

int main()
{
  int N, M;
  cin >> N >> M;
  if (N - M == 1) {
    cout << 0 << endl;
    return 0;
  }

  vector<vector<int>> distance(N, vector<int>(N, -1));
  for (int i = 0; i < M; ++i) {
    int src, dst, length;
    cin >> src >> dst >> length;
    --src; --dst;
    distance[src][dst] = distance[dst][src] = length;
  }

  vector<vector<int>> middle(N, vector<int>(N, -1));
  for (int k = 0; k < N; ++k) {
    for (int s = 0; s < N; ++s) {
      for (int t = 0; t < N; ++t) {
        if (distance[s][k] < 0 or distance[k][t] < 0) continue;
        int sum = distance[s][k] + distance[k][t];
        if (distance[s][t] < 0 or sum < distance[s][t]) {
          distance[s][t] = distance[t][s] = sum;
          middle[s][t] = middle[t][s] = k;
        }
      }
    }
  }

  map<pair<int, int>, bool> edges;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      count(edges, middle, i, j);
    }
  }

  cout << (M - edges.size()) << endl;
  return 0;
}

Measured memory_bytes: 384
import sys

def get_height(h, x, y, cx, cy):
	for i in range(len(h)):
		if h[i] == 0:
			continue
		return h[i] + abs(x[i] - cx) + abs(y[i] - cy)

n = int(input())
x = []
y = []
h = []
for _ in range(n):
	xi, yi, hi = map(int, input().split())
	x.append(xi)
	y.append(yi)
	h.append(hi)

for cx in range(101):
	for cy in range(101):
		height = get_height(h, x, y, cx, cy)
		for i in range(n):
			if h[i] != max(0, height - abs(x[i] - cx) - abs(y[i] - cy)):
				break
		else:
			print(cx, cy, height)
			sys.exit()

Measured memory_bytes: 43628
#include<cstdio>
#include<cmath>
using std::abs;
int main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	int ans=abs(abs(x)-abs(y));
	if(1ll*x*y<0)++ans;
	else if(x>y)
	{
		ans+=2;
		if(x==0||y==0)--ans;
	}return printf("%d\n",ans),0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

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

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

#define rep(i,n) for(auto i=0; i<(n); i++)

const int mod = 1000000007;


struct mint {
    ll x;
    mint(ll x=0):x(x%mod){}

    mint& operator+=(const mint a) {
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint& operator-=(const mint a) {
        if((x -= mod-a.x) >= mod) x -= mod;
        return *this;
    }

    mint& operator*=(const mint a) {
        x = (x * a.x) % mod;
        return *this;
    }

    mint& operator/=(const mint a) {
        *this *= a.inv();
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }

    mint pow(ll n) const {
      mint a(*this);
      mint res = 1;
      while (n > 0) {
          if (n & 1) res *= a;
          a *= a;
          n >>= 1;
      }
      return res;
    }

    mint inv() const {
      return pow(mod - 2);
    }
};

mint dp[100][2];

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

  int n;
  cin >> n;

  string s1, s2;
  cin >> s1;
  cin >> s2;

  int i = 1;
  if (s1[0] == s2[0]) {
    dp[0][0] = 3;
  } else {
    dp[1][1] = 6;
    i++;
  }
  
  for(; i < n; i++) {
    if (s1[i] == s2[i]) {
      dp[i][0] += dp[i-1][0] * 2;
      dp[i][0] += dp[i-1][1];
    } else {
      i++;
      dp[i][1] += dp[i-2][0] * 2;
      dp[i][1] += dp[i-2][1] * 3;
    }
  } 

  cout << dp[n-1][0].x + dp[n-1][1].x << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int H,W;
int taka[509][509], aoki[509][509];
int dh[] = { -1, 0, 1, 0};
int dw[] = { 0, 1, 0, -1};

bool ck(int i,int j){
    return (i>=0&&i<H&&j>=0&&j<W&&aoki[i][j]==1);
}

void bfs(int i,int j){
    aoki[i][j]=2;
    rep(l,4){
        int ni=i+dh[l], nj=j+dw[l];
        if(ck(ni,nj)) bfs(ni,nj);
    }
}

void pr(int ans[509][509]){
    rep(i,H){
        rep(j,W){
            cout<<(ans[i][j]?'#':'.');
        }
        cout<<endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>H>>W;
    rep(i,H)rep(j,W){
        char c; cin>>c;
        if(c=='#'){
            taka[i][j]=aoki[i][j]=1;
            continue;
        }
        if(j==0){
            taka[i][j]=1;
        }else if(j==W-1){
            aoki[i][j]=1;
        }else if(i%2){
            taka[i][j]=1;
        }else{
            aoki[i][j]=1;
        }
    }
    
    pr(taka);
    cout<<endl;
    pr(aoki);
}

Measured memory_bytes: 2816
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	int N;
	cin >> N;
	for (int A = 1; A < 10; A++) {
		for (int B = 1; B < 10; B++) {
			if (N == A * B) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;

	return 0;
}

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

int main()
{
  int n, ans = 0;
  cin >> n;
  vector<int> p(n);
  vector<int> q(n);
  for (int i = 0; i < n; i++)
  {
    cin >> p.at(i);
    q.at(i) = i + 1;
  }
  for (int i = 0; i < n; i++)
  {
    if (p.at(i) != q.at(i))
      ans++;
  }
  if (ans > 2)
  {
    cout << "NO" << endl;
  }
  else
  {
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
  string s[3];cin>>s[0]>>s[1]>>s[2];
  int turn=0;
  while(true){
    if(s[turn].size()==0)break;
    string &t=s[turn];
    turn=int(t[0]-'a');
    t=t.substr(1, t.size()-1);
  }
  cout << char('A'+turn) << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        int tmp;
        int output=0;
        for(int i=0;i<n;i++){
            tmp=sc.nextInt();
            output+=Math.min(tmp,k-tmp);
        }
        System.out.println(output*2);
    }
 
    
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int d[100001], deg[100001], used[100001], ans = 0;
typedef pair<int, int> P;

int main(){
	int N, K; cin >> N >> K;
	vector<int> G[N];
	int g[N];
	for(int i=0; i<N; i++){
		int a; cin >> a;
		a--;
		g[i] = a;
		if(i != 0){
			G[a].push_back(i);
			deg[a]++;
		}else{
			if(a != 0) ans++;
		}
	}
	priority_queue<P> pq;
	vector<int> d(N, INF);
	d[0] = 0;
	queue<int> que;
	que.push(0);
	while(que.size()){
		int now = que.front(); que.pop();
		for(int i=0; i<G[now].size(); i++){
			if(d[G[now][i]] == INF){
				d[G[now][i]] = d[now] + 1;
				que.push(G[now][i]);
			}
		}
	}
	for(int i=0; i<N; i++){
		if(deg[i] == 0 && d[i] > K){ pq.push(P(d[i], i));}
	}
	while(pq.size()){
		P p = pq.top(); pq.pop();
		if(p.first <= K){
			break;
		}
		if(used[p.second] == 1){
			continue;
		}
		int up = p.second;
		for(int i=0; i<K-1; i++){
			up = g[up];
		}
		ans++;
		queue<int> qu;
		qu.push(up);
        used[up] = 1;
		while(qu.size()){
			int aa = qu.front(); qu.pop();
			for(int i=0; i<G[aa].size(); i++){
				if(used[G[aa][i]] == 0){
					qu.push(G[aa][i]);
					used[G[aa][i]] = 1;
				}
			}
		}
		pq.push(P(d[g[up]], g[up]));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7296
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll INF = 1e17;
const int MOD = 1e9 + 7;

int A, B,K;
ll S[1000],cnt;

int main(void) {
	
	cin >> A >> B>>K;
	FOR(i, 1, max(A,B)+1) {
		if (A%i == 0 && B%i == 0) {
			S[cnt] = i;
			cnt++;
		}
	}
	sort(S,S + cnt);
	reverse(S, S + cnt);
	ct(S[K - 1]);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  vll S(N);
  REP(i, 0, N) {
    cin >> S[i];
  }
  sort(S.begin(), S.end(), less<>());

  ll sum = accumulate(S.begin(), S.end(), 0);
  if (sum % 10 != 0) {
    cout << sum << endl;
    return 0;
  }

  REP(i, 0, S.size()) {
    ll remain = sum - S[i];
    if (remain % 10 != 0) {
      cout << remain << endl;
      return 0;
    }
  }

  cout << 0 << endl;

  return 0;
}


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

#define ll long long
#define sc(n) int n; scanf("%d",&n);
#define mod 10000007
#define N 100001
#define MX 1000000001
#define log(n) (int)log2(n)
#define logg(a)(b) log(b)/log(a)
#define pb(x) push_back(x);
#define T int t, q=0; scanf("%d", &t); while(q++<t)
#define pi acos(-1)
#define flag bool fl=true;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

int main() {


    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(1)
    {
       c=c-b;
       if(c<=0)
       {
           cout<<"Yes"<<endl;
           return 0;
       }
       a=a-d;
       if(a<=0)
       {
           cout<<"No"<<endl;
           return 0;
       }
    }
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int n,q;
string s;
vector<char> t(200010),d(200010);

bool left(int x){
  int now=x;
  rep(i,q){
    if(s[now]==t[i]){
      if(d[i]=='L') now--;
      else now++;
    }
    if(now==-1) return true;
  }
  return false;
}

bool right(int x){
  int now=x;
  rep(i,q){
    if(s[now]==t[i]){
      if(d[i]=='L') now--;
      else now++;
    }
    if(now==n) return true;
  }
  return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>q>>s;
    rep(i,q) cin>>t[i]>>d[i];
    int low=-1,high=n,mid;
    while(high-low>1){
      mid=(low+high)/2;
      if(left(mid)) low=mid;
      else high=mid;
    }
    int low2=-1,high2=n,mid2;
    while(high2-low2>1){
      mid2=(low2+high2)/2;
      if(right(mid2)) high2=mid2;
      else low2=mid2;
    }
    if(low>=high2) cout<<0<<endl;
    else cout<<n-(low+1)-(n-high2)<<endl;
}

Measured memory_bytes: 1104
import math
a, b, x = map(int, input().split())
h = x / (a ** 2)
if h > b / 2:
    l = (2 * b) - (2 * x / a / a)
    ans = math.degrees(math.atan(l / a))
elif 2 * x == a * a * b:
    ans = math.degrees(math.atan(b / a))
else:
    l = 2 * x / a / b
    ans = math.degrees(math.atan(b / l))
print("{:.10f}".format(ans))

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

int main(){
  string s;
  int count=0;
  cin >> s;
  if(s[0]=='1'){
    count++;
  }
  if(s[1]=='1'){
    count++;
  }
  if(s[2]=='1'){
    count++;
  }
  cout << count <<endl;
}

Measured memory_bytes: 256
let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let solve n k =
  let a = Array.init n (fun _ -> read_int ()) in
  let rec count_n = function
    | (i, j, _, _) when i = n || j = k -> i
    | (i, j, s, p) when s + a.(i) <= p -> count_n (i + 1, j, s + a.(i), p)
    | (i, j, _, p) -> count_n (i, j + 1, 0, p) in
  let rec bin_search l r =
    if r < l then l
    else
      let p = (l + r) / 2 in
      if count_n (0, 0, 0, p) >= n then bin_search l (p - 1)
      else bin_search (p + 1) r in
  Printf.printf "%d\n" (bin_search 0 (100000 * 10000))

let () =
  match List.map int_of_string (split (read_line ()) ' ') with
  | [n; k] -> solve n k
  | _ -> exit 1

Measured memory_bytes: 5236
#include <cstdio>
#include <utility>
#include <cctype>
#include <vector>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;char c;while(isspace(c = gcu()));do{s+=c;}while(c=gcu(),c!=' '&&c!='\n'&&c!=EOF);return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H &&h, T... t){out(h);out(t...);}
template <typename... T> _OUTL(T... t){out(t...);outl();}
struct range{
	int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

using V = vector<long>;

struct RSAQ {
	int n;
	V b0, b1;
	RSAQ(int s) : n {s}, b0(s + 1), b1(s + 1) {}
	long sum(V &b, int i) {
		long r {};
		for (; i > 0; i -= i & -i)
			r += b[i];
		return r;
	}
	long sum(int s, int t) {
		s--;
		return sum(b0, t) + sum(b1, t) * t - sum(b0, s) - sum(b1, s) * (s);
	}
	void add(V &b, int i, int v) {
		for (; i <= n; i += i & -i)
			b[i] += v;
	}
	void add(int s, int t, int v) {
		add(b0, s, -v * (s - 1));
		add(b1, s, v);
		add(b0, t + 1, v * t);
		add(b1, t + 1, -v);
	}
};

int main() {
	RSAQ r((int) in);
	times(i, in) {
		int o {in}, s {in}, t {in};
		if (o)
			outl(r.sum(s, t));
		else
			r.add(s, t, in);
	}
}


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

int main() {
  string S;
  cin >> S;
  
  vector<char> vec = {S.at(0), S.at(1), S.at(2), S.at(3)};
  int a = 0;
  
  for (int i = 0; i < 4; i++){
    for (int j = i + 1; j < 4; j++){
      if (vec.at(i) == vec.at(j)){
        a++;
      }
    }
  }
  if (a == 2){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N, D = map(int, input().split())
points = []
for _ in range(N):
    point = list(map(int, input().split()))
    points.append(point)

ans = 0
for i in range(N):
    for j in range(i+1, N):
        dis = 0
        for y, z in zip(points[i], points[j]):
            dis += (y - z) ** 2
        dis = dis ** 0.5
        if dis.is_integer():
            ans += 1
print(ans)

Measured memory_bytes: 9472
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://tenka1-2017.contest.atcoder.jp/tasks/tenka1_2017_c>
問題文============================================================
 整数 N が与えられる。
 
 4⁄N=1⁄h+1⁄n+1⁄w を満たす正整数 h,n,w を求めよ。
 
 条件を満たす解が複数ある場合、どれを出力しても良い。
 
 制約
 N に対して h,n,w≤3500 となる解が存在することが保証される。

 
=================================================================

解説=============================================================

 4/N = 1/h + 1/n + 1/w
 x4hnwN
 4hnw = nwN + whN + hnN
 移行
 4hn*w - nN*w - hN*w = hnN
 wについてまとめる
 (4hn - nN - hN)*w = hnN
 よって、 h,nを決めうちした時, w を推測できる。
 
 制約より O(3500^2)
 
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    for(int i = 1; i <= 3500;i++){
        for(int j = 1;j<=3500; j++){
            ll X = 4*i*j - i*N - j*N;
            ll Y = i*j*N;
            if(X <= 0) continue;
            if(Y%X == 0){
                cout << i << " " << j << " " << Y/X << endl;
                return 0;
            }
        }
    }
	return 0;
}


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

int main(){
    ll abc[10][10]={0},ans=0;
    ll n;
    cin >> n;
    for(ll i=1;i<=n;i++){
        ll now=i;
        ll first,end;
        end=now%10;
        while(now!=0){
            first=now%10;
            now=now/10;
        }
        if(first==0||end==0) continue;
        if(first==end) ans++;
        ans+=abc[end][first]*2;
        abc[first][end]++;
    }
    
    cout << ans << endl;
    

    return 0;
}






Measured memory_bytes: 256