akhauriyash/Code-Regression huggingface dataset:
# region
import sys
import itertools

DEBUG = True if (len(sys.argv) > 1 and sys.argv[1] == "DEBUG") else False


def dp(value):
    if DEBUG:
        print(value)
    return


def input_text(split=" "):
    # 入力
    result = []
    while True:
        try:
            row = list(
                map(lambda x: int(x) if x.isdecimal() else x, input().split(split))
            )
            result.append(row)
        except EOFError:
            break
    return result


# endregion
it = input_text()

a = it[0][0]
b = it[0][1]
h = it[0][2]
m = it[0][3]

import math

hs = (h / 12 + m / 60 / 12) * 2 * math.pi
ms = (m / 60) * 2 * math.pi

hx = a * math.cos(hs)
hy = a * math.sin(hs)
mx = b * math.cos(ms)
my = b * math.sin(ms)

r = math.sqrt(pow(hx - mx, 2) + pow(hy - my, 2))
print(r)


Measured memory_bytes: 63144
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;

int main() {
	int N,M;
	cin >> N >> M;
	int ans;
	
	cout << N*(N-1)/2 + M*(M-1)/2 << endl;
}

Measured memory_bytes: 256
/**
*    created: 01.07.2020 16:29:39
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int mod = 1000000007;
// const int MOD = 998244353;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int a, b, c;
    cin >> a >> b >> c;
    if (a+b >= c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3560
#include<stdio.h>
int main(){
  char s[100];
  scanf("%s",s);
  for(int i=0;i<100;i++){
    if (i%2==0){
      if(s[i]=='L'){
        printf("No\n");
        break;
      }
    }
    else{
      if(s[i]=='R'){
        printf("No\n");
        break;
      }
    }
    if(i==99){
      printf("Yes\n");
    }
  }
}

Measured memory_bytes: 128
#include <iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include <set>
#include <numeric>
#include<math.h>
#include<queue>
#include<unordered_map>
#include<cmath>
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int i=1;i<=n;i++)
#define ll long long int
#define pi (double)3.14159265359
#define vect vector <int>
#define pb push_back
using namespace std;

void solve() {
	int x, n,temp;
	cin >> x >> n;
	set <int> v;
	fo(i, n) cin >> temp,v.insert(temp);
	if (n==0) cout << x;
	else {
		for (int i = 0;; i++) {
			if (v.find(x-i)== v.end()) {
				cout << (x - i);
				break;
			}
			if (v.find(x + i)== v.end()) {
				cout << (x + i);
				break;
			}
		}
	}
}
int main(){
	solve();
	return 0;
}


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

using namespace std;

// This is the template of Errichto which can be found on https://codeforces.com/submissions/Errichto

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {

sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
#define LOCAL 1
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

//int dirs[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
//int dirs[8][2]={{-1,0},{0,-1},{0,1},{1,0},{1,1},{-1,-1},{-1,1},{1,-1}};

int main()
{
    ios::sync_with_stdio(false);
    //freopen("inp.in","r",stdin);
    //freopen("outp.out","w",stdout);
    int L, R, d;
    cin >> L >> R >> d;
    int ans=0;
    int i=0;
    while(true)
    {
        if(L<=i && i<=R) ans++;
        i+=d;
        if(i>R) break;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>

#define N 100005

struct Node{
  int p, l, r;
};
struct Node T[N];

void inorder(int);
void preorder(int);
void postorder(int);
void aaaaa(int);

int main(){
  int i, v, n, a=10;
  scanf("%d", &n);
  for(i=0; i<n; i++){
    T[i].p = T[i].l = T[i].r=-1;
  }
  for(i=0; i<n; i++){
    scanf("%d", &v);
    scanf("%d %d", &T[v].l, &T[v].r);
    T[T[v].l].p=v;
    T[T[v].r].p=v;
  }
  printf("Preorder\n");
  for(i=0; i<n; i++){
    if(T[i].p==-1)preorder(i);
  }
  printf("\nInorder\n");
  for(i=0; i<n; i++){
    if(T[i].p==-1)inorder(i);
  }
  printf("\nPostorder\n");
  for(i=0; i<n; i++){
    if(T[i].p == -1)postorder(i);
  }
  printf("\n");
  aaaaa(a);
  return 0;
}

void aaaaa(int a){
  int i, count=0;
  for(i=0; i<a; i++){
    count++;
  }
}

void inorder(int u){
  if(u != -1){
    inorder(T[u].l);
    printf(" %d", u);
    inorder(T[u].r);
  }
}

void preorder(int u){
  if(u != -1){
    printf(" %d", u);
    preorder(T[u].l);
    preorder(T[u].r);
  }
}

void postorder(int u){
  if(u != -1){
    postorder(T[u].l);
    postorder(T[u].r);
    printf(" %d", u);
  }
}



Measured memory_bytes: 2128
#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 <cstdio> // printf
#include <cmath> // fabs, pow, sqrt, sin, fmod
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;

string f(ll n) {
    if(n == 0) return "";
    n--;
    return f(n/26) + string(1, 'a'+n%26);
}

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

    cout << f(n) << endl;
    
    return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	for (int c = 0; c < a; c++) {
		for (int d = 0; d < b; d++) {
			string e;
			cin >> e;
			if (e == "snuke") {
				printf("%c%d\n", d + 65, c + 1);
			}
		}
	}

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int l, n; cin >> l >> n;
	vi x(n); rep(i, n) cin >> x[i];
	
	auto solve = [&](){
		vector<ll> sum(n + 1), rsum(n + 1);
		rep(i, n){
			sum[i + 1] = sum[i] + x[i];
			rsum[i + 1] = rsum[i] + l - x[n - i - 1];
		}
		//dbg(sum, rsum);
		ll res = 0;
		rep(i, n){
			int k = min(i, n - i);
			ll tmp = sum[i] - sum[i - k] + rsum[n - i - 1] - rsum[max(0, n - i - 1 - k)];
			res = max(res, 2 * tmp + l - x[i]);
		}
		rep(i, n - 1){ //i, i + 1のこす
			int k = min(i, n - i - 1);
			ll tmp = sum[i] - sum[i - k] + rsum[n - i - 2] - rsum[max(0, n - i - 1 - k)];
			res = max(res, 2 * tmp + l - x[i]);
		}
		return res;
	};
	
	ll ans = solve();
	reverse(all(x)); rep(i, n) x[i] = l - x[i];
	ans = max(ans, solve());
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4224
#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 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 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;

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

void resolve() {
    int n,h;
    cin >> n >> h;
    VI a(n), b(n);
    REP(i,0,n) cin >> a[i] >> b[i];
    sort(all(a));
    sort(all(b));
    reverse(all(a));
    reverse(all(b));
    int sum = 0;
    int cnt= 0;
    REP(i,0,n) {
        if (b[i] >= a[0]) {
            sum += b[i];
            ++cnt;
            if (sum >= h) break;
        } else break;
    }
    cnt += max(0, (h - sum + a[0] - 1) / a[0]);
    cout << cnt << endl;
}

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

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


using namespace std;


#define mod(cans) cans%10**9+7
#define cin_pl(x,y) for(int i=0;i<x;i++){cin>>y[i];}
#define pl_twin(x,y,z) for(int i=0;i<x;i++){cin>>y[i]>>z[i];}
#define debug(x) cout << "Debug" << x << "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define st(s) size_t size = s.length()
#define prians(Answer) cout<<Answer<<"\n"
#define make_pair mp;
#define com_div(x,Co) for(int i=1;i<x+1;i++){if(x%i==0){Co++;}}
#define TF(X) X==1?cout<<"Yes\n":cout<<"No\n"
#define elcon else{continue;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int>> matrix;
typedef pair<int,int> pr;
typedef vector<pr> vpt;
typedef greater<int> gi;

int main()
{
    double w,h,x,y;
    cin>>w>>h>>x>>y;
    double mm=w*h*0.5;
    int tmp=2;
    if(w/x==2&&h/y==2)
    tmp=1;
    else
    {
        tmp=0;
    }
    cout<<mm<<" "<<tmp;
}


Measured memory_bytes: 256
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(e,r){e.exports=function(e){for(var r=e.split("\n"),t=Number(r[0]),n=r[1].split(" ").map(function(e){return Number(e)}),o=new Array(9).fill(0),u=0;u<t;u++){if(n[u]>=3200)o[8]+=1;else o[Math.floor(n[u]/400)]+=1}for(var i=0,f=o[8],l=0;l<8;l++)o[l]>0&&(i+=1);var a=Math.max(1,i);console.log(`${a} ${i+f}`)}},function(e,r){e.exports=require("fs")}]);

Measured memory_bytes: 7372
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let k: u32 = read();

    let mut bv: Vec<bool> = vec![false; k as usize];

    let mut tmp = 0;
    let mut ans = 1;

    loop {
        tmp = (tmp * 10 + 7) % k;
        if tmp == 0 {
            break;
        }
        if bv[tmp as usize] {
            ans = -1;
            break;
        }
        bv[tmp as usize] = true;
        ans += 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 2932
//https://atcoder.jp/contests/abc147/tasks/abc147_b
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    string S; cin>>S;
    ll ans=0;
    for(ll i=0;i<S.size();++i){
        ll p=S.size()-i-1;
        if(S.at(i)!=S.at(p)) ++ans;
    }
    cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX_STR_SIZE (1001)

void f_replace(char * str, int start_index, int end_index, char * replace_str);
void f_reverse(char * str, int start_index, int end_index);
void f_print(char * str, int start_index, int end_index);

int main(void)
{
        char input_str[MAX_STR_SIZE], command_str[MAX_STR_SIZE];
        char replace_str[MAX_STR_SIZE];
        int command_count, command_index, command_str_index;
        int start_index, end_index;

        scanf("%s", input_str);

        scanf("%d", &command_count);

        for(command_index=0; command_index < command_count; command_index++){
                scanf("%s%d%d", command_str, &start_index, &end_index);

                if(command_str[0] == 'p'){
                        f_print(input_str, start_index, end_index);
                }
                else if(command_str[0] == 'r' && command_str[1] == 'e' && command_str[2] == 'p'){
                        scanf("%s", replace_str);
                        f_replace(input_str, start_index, end_index, replace_str);
                }
                else if(command_str[0] == 'r' && command_str[1] == 'e' && command_str[2] == 'v'){
                        f_reverse(input_str, start_index, end_index);
                }

        }

        return 0;
}

void f_replace(char * str, int start_index, int end_index, char * replace_str){
        int index;

        for(index=start_index; index <= end_index; index++){
                str[index] = replace_str[index - start_index];
        }
}
void f_reverse(char * str, int start_index, int end_index){
        int index;
        char work_str[MAX_STR_SIZE];

        for(index=0; index <= (end_index - start_index); index++){
                work_str[index] = str[end_index - index];
        }

        for(index=start_index; index <= end_index; index++){
                str[index] = work_str[index - start_index];
        }
}
void f_print(char * str, int start_index, int end_index){

        int index;

        for(index=start_index; index <= end_index; index++){
                printf("%c", str[index]);
        }

        printf("\n");
}


Measured memory_bytes: 2108
#include <stdio.h>
#include <stdbool.h>

int calculate_digit_sum (int target)
{
    // return value of this function
    int digit_sum;

    // STEP.01
    // initialize the variable to store the digit sum
    digit_sum = (int)0;

    // STEP.02
    // calculate the digit sum
    while (target > (int)0)
    {
        digit_sum += target % (int)10;
        target    /= (int)10;
    }

    // STEP.END
    // declare the return value of this function
    return digit_sum;
}

bool is_multiple (int target, int base)
{
    if (target % base == (int)0) { return true;  }
    else                         { return false; }
}

int main (void)
{
    // variables for `main`
    int int_given;
    int rtvl_scanf;

    // STEP.01
    // read out the given string
    rtvl_scanf = scanf("%d", &int_given);

    // STEP.02
    // output whether the digit sum of given integer is the multiple of the given integer or not
    if ( is_multiple( int_given, calculate_digit_sum(int_given) ) )
    { printf("%s\n", "Yes"); }
    else
    { printf("%s\n", "No"); }

    // STEP.END
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <ctype.h>

using namespace std;
using ll=long long;

int main()
{
    string a, b;
    
    cin >> a >> b;
    
    if (a == "H")
    {
        printf("%s\n", b.data());
    }
    else
    {
        printf("%s\n", b == "H" ? "D" : "H");
    }
    
    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H,W,N;
int M;
int to[500*500];

int id[500*500];

vector<vint>loop;

void findLoop(){
    vector<int>deg(H*W);
    queue<int>que;
    fill_n(id,500*500,-2);
    rep(i,M)deg[to[i]]++;
    rep(i,M)if(deg[i]==0)que.push(i),id[i]=-1;
    while(que.size()){
        int v=que.front();
        que.pop();
        int u=to[v];
        if(--deg[u]==0){
            id[u]=-1;
            que.push(u);
        }
    }

    rep(i,M){
        if(id[i]!=-2)continue;
        loop.pb(vint());
        int v=i;
        while(id[v]==-2){
            id[v]=loop.size()-1;
            loop.back().pb(v);
            v=to[v];
        }
    }
}

vint T[500*500];
int ans;

int dep[500*500];
set<int>ds[500*500];
bool ex[500*500];
void dfs(int v,int d){
    dep[v]=d;
    if(ex[v])ds[v].insert(d);
    for(auto u:T[v]){
        dfs(u,d+1);
        if(ds[v].size()<ds[u].size())swap(ds[v],ds[u]);
        for(auto it=ds[u].begin();it!=ds[u].end();it++){
            if(ds[v].find(*it)!=ds[v].end()){
                chmin(ans,*it-d);
            }
            ds[v].insert(*it);
        }
    }
}

bool C(int t){
    for(auto &vs:loop){
        vint cnt(vs.size());
        rep(i,vs.size()){
            for(auto u:ds[vs[i]]){
                if(u>t)continue;
                cnt[(i+t-u)%vs.size()]++;
            }
        }
        rep(i,vs.size())if(cnt[i]>1)return true;
    }
    return false;
}

signed main(){
    scanf("%lld%lld%lld",&H,&W,&N);
    M=H*W;
    rep(i,H){
        rep(j,W){
            int a,b;
            scanf("%lld%lld",&a,&b);
            to[i*W+j]=a*W+b;
        }
    }
    vint vs;
    rep(i,N){
        int a,b;
        scanf("%lld%lld",&a,&b);
        vs.pb(a*W+b);
        ex[a*W+b]=1;
    }

    findLoop();

    rep(i,M){
        if(id[i]!=-1)continue;
        T[to[i]].pb(i);
    }

    ans=INT_MAX;

    rep(i,M){
        if(id[i]==-1)continue;
        dfs(i,0);
    }

    int lb=0,ub=INT_MAX;
    while(ub-lb>1){
        int mid=(ub+lb)/2;
        if(C(mid))ub=mid;
        else lb=mid;
    }

    chmin(ans,ub);
    if(ans==INT_MAX)cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 54600
s = int(input())
n = []
n.append(s)
i = 0
while True:
    if n[i] % 2 == 0:
        n.append(n[i] / 2)
    else:
        n.append(3 * n[i] + 1)
    if n[:-1].count(n[i + 1]):
        print(i + 2)
        break
    i += 1
    

Measured memory_bytes: 2940
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

string F(ll N){
        if(N==0)return "";
        if(1<=N&&N<=26){
            char c='a'+N-1;
            string ret="";
            ret=ret+c;
            return ret;
        }
        ll d=N%26;
        if(d==0)d=26;
         return F((N-27)/26+1)+F(d);
    }
signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    prt(F(N));

    return 0;
}



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

using namespace std;


int main() {
    int x,n;
    cin >> x >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int ans = 1000000;
    for(int i = -10000; i <= 100000; i++) {
        bool ok = true;
        for(int j = 0; j < n; j++) {
            if(p[j] == i) {
                ok = false;
            }
        }
        if(!ok) {
            continue;
        }
        if(abs(ans - x) > abs(x - i)) {
            ans = i;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	// AtCoder Beginner Contest 129
	// https://atcoder.jp/contests/abc129/tasks
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int prevT = 0;
		int prevX = 0;
		int prevY = 0;
		
		for (int i = 0; i < n; i++) {
			int t = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			
			int dist = Math.abs(x - prevX) + Math.abs(y - prevY);
			int timeDiff = t - prevT;
			
			if (dist > timeDiff || (dist % 2 != timeDiff % 2)) {
				System.out.println("No");
				System.exit(0);
			}
			prevT = t;
			prevX = x;
			prevY = y;
		}
		
		System.out.println("Yes");
	}
	
	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 39100
#define hash
class my_dict():
    def __init__(self, size=1000):
        self.my_list = [[] for i in range(size)]
        self.dict_size = size
    #quaternary A=0 C=1 G=2 T=3
    def acgt_hash(self, input_str):
        output = 0
        for i in input_str:
            if i == 'A':
                output+=1
            elif i == 'C':
                output+=2
            elif i == 'G':
                output+=3
            elif i == 'T':
                output+=4
            output *=5
        return output%self.dict_size
    def insert(self, key):
        hash_val = self.acgt_hash(key)
        if self.my_list[hash_val] == None:
            self.my_list[hash_val]  = [key]
        else:
            for k in self.my_list[hash_val]:
                if k == key:
                    break
            else: self.my_list[hash_val].append(key)
    def find(self, key):
        hash_val = self.acgt_hash(key)
        if self.my_list[hash_val] == None:
            print('no')
        else:
            for k in self.my_list[hash_val]:
                if k == key:
                    print('yes')
                    break
            else: print('no')

#get N
n = int(input())
#create dic
dic1 = my_dict(100000)
#get inputs in N times
for i in range(n):
    #get instructtion and key
    inst, key = input().split(' ')
    #do instructions
    if inst == 'insert':
        dic1.insert(key)
    else:
        dic1.find(key)





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

int main() {
  string S; cin >>S;
  int ans=0;
  rep(i,0,S.size()) {
    if (S[i]=='1') ans++;
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 256
N, M = list(map(int, input().split()))
py = []

for i in range(M):
    py.append(list(map(int, input().split())) + [i])
py.sort()

result = ['' for i in range(M)]

n = 0
count = 1
for i in range(M):
    if py[i][0] != n:
        count = 1
        n = py[i][0]
    result[py[i][2]] = str(py[i][0]).zfill(6) + str(count).zfill(6)
    count += 1

for i in range(M):
    print(result[i])

Measured memory_bytes: 32036
S = input()
N = len(S)
S = list(S.split("T"))
x, y = map(int, input().split())

X_command = sorted([len(i) for i in S[::2]], reverse=True)
Y_command = sorted([len(i) for i in S[1::2]], reverse=True)

nx = X_command.pop(-1)
ny = 0

for xi in X_command:
    if nx > x:
        nx -= xi
    else:
        nx += xi

for yi in Y_command:
    if ny > y:
        ny -= yi
    else:
        ny += yi

if nx == x and ny == y:
    print("Yes")
else:
    print("No")

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    if (k <= a) {
        ans = k;
    } else if (k <= a + b) {
        ans = a;
    } else {
        ans = a - (k - (a + b));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3624
[a, b] = list(map(int, input().split()))
s = str(input())
finalAns = True
for p in range(a + b):
    if p == a:
        if s[p] != "-":
            finalAns = False
    else:
        if s[p].isdigit == False or s[p] == "-":
            finalAns = False

if finalAns == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  cout<<(M+N)*(N+M-1)/2-N*M<<endl;
  return 0;
}


Measured memory_bytes: 256
a,z,u,i,j,k,d[1999][9];main(){scanf("%d ",&a);d[0][2]=1;for(i=0;i<a;i++){u=getchar()%4-1;for(j=8;j--;){for(k=8;k--;)if(j&k&&j>>u&1)d[i+1][j]+=d[i][k]%10007;z+=d[a][j];}}a=!printf("%d\n",z%10007);}

Measured memory_bytes: 632
#include<bits/stdc++.h>
using namespace std;
const int cnt[10]={0,2,5,5,4,5,6,3,7,6};
string dp[10010];
bool ok[10];
int main()
{
	cin.tie();
	cout.tie();
	ios_base::sync_with_stdio(false);
	int N;
	cin>>N;
	int M;
	cin>>M;
	while(M--)
	{
		int x;
		cin>>x;
		dp[cnt[x]]=max(dp[cnt[x]],string(1,'0'+x));
		ok[x]=true;
	}
	for(int i=1;i<=N;i++)
		for(int j=9;j;j--)
			if(ok[j]&&i-cnt[j]>=0&&dp[i-cnt[j]]!="")
				if(dp[i-cnt[j]].length()+1>dp[i].length())
				{
					dp[i]=dp[i-cnt[j]];
					reverse(dp[i].begin(),dp[i].end());
					int pos=lower_bound(dp[i].begin(),dp[i].end(),j+'0')-dp[i].begin();
					dp[i]=dp[i].substr(0,pos)+string(1,j+'0')+dp[i].substr(pos);
					reverse(dp[i].begin(),dp[i].end());
				}
	cout<<dp[N]<<endl;
	return 0;
}

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

int main(){
    string s,t ;
    cin >> s >> t ;
    int ans = 0;
    for (size_t i = 0; i < 3; i++)
    {
        if (s.at(i) == t.at(i))
        {
            ans++ ;
        }
        
    }
    cout << ans << endl ;
    
    
}

Measured memory_bytes: 256
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N;
    cin>>N;
    for(int i=N; i<1000;i++){
        string s=to_string(i);
        if(s[0]==s[1]&&s[0]==s[2]){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int inf=10000000;
typedef pair<int ,int> P;



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

     vector<int> parent(n ,inf);
     queue<int> que ;
     
     for(int i=0;i<to[0].size() ;i++){
         que.push(to[0][i]);
         parent[to[0][i]] = 1;
     }

     while(!que.empty()){
         int k = que.front(); 
         que.pop();
         for(int i=0 ;i<to[k].size();i++){
             if(parent[to[k][i]] == inf ) {
                 que.push(to[k][i]);
                 parent[to[k][i]] = k+1;
             }
         }
     }

     cout << "Yes" <<endl; 

     for(int i=1;i<n;i++) cout << parent[i] << endl;



}

Measured memory_bytes: 10208
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
			System.out.println("Possible");
		} else {
			System.out.println("Impossible");

		}

	}

}

Measured memory_bytes: 22868
#include<iostream>
#include<vector>

using namespace std;

int main()
{
  int n;
  cin>>n;
  vector<int> h(n);
  for(int i=0;i<n;i++)
    cin>>h[i];
  vector<int> dp(n);
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  for(int i=2;i<n;i++)
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define MAX 100000
#define N -1

typedef struct{
  int p,l,r;
}Node;

Node T[MAX];
int n,depth[MAX],height[MAX];

/*void printchild(int x){
  int t = T[x].l;
  int i=0;
  for(;t!=N;t=T[t].r){
    if(i!=0)printf(", ");
    i=1;
    printf("%d",t);
  }
}*/

int getdegree(int x){
  int n=0;
  if(T[x].l!=N)n++;
  if(T[x].r!=N)n++;
  return n;
}

int getsibling(int z){
  if(T[z].p==N)return N;
  if(T[T[z].p].l==z && T[T[z].p].r!=N)return T[T[z].p].r;
  if(T[T[z].p].r==z && T[T[z].p].l!=N)return T[T[z].p].l;
  return N;
}

void print(int x){
  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",x,T[x].p,getsibling(x),getdegree(x),depth[x],height[x]);
  if(T[x].p==N)printf("root");
  else if(T[x].l==N && T[x].r==N)printf("leaf");
  else printf("internal node");
  printf("\n");
}

void getdepth(int x,int y){
  depth[x]=y;
  if(T[x].r!=N)getdepth(T[x].r,y+1);
  if(T[x].l!=N)getdepth(T[x].l,y+1);
}

int getheight(int x){
  int h1=0,h2=0;
  if(T[x].l!=N)h1=getheight(T[x].l)+1;
  if(T[x].r!=N)h2=getheight(T[x].r)+1;
  return height[x]=(h1>h2?h1:h2);
}

int main(){
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++)T[i].p=T[i].l=T[i].r=N;
  for(i=0;i<n;i++){
  int current,left,right;
  scanf("%d %d %d",&current,&left,&right);
  T[current].l=left;
  T[current].r=right;
  if(left!=N)T[left].p=current;
  if(right!=N)T[right].p=current;
}
  int r;
  for(i=0;i<n;i++)if(T[i].p==N)r=i;
  getdepth(r,0);
  getheight(r);
  for(i=0;i<n;i++)print(i);

  return 0;
}



Measured memory_bytes: 2108
#include "bits/stdc++.h"
using namespace std;

// Inserted snippets: bs, io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
template<class T, class U>
T lower_bound_on(T first, T last, const U& value, const function<U(T)>& fn) {
	T it, step, count = last - first;
	while (count > 0) {
		it = first + (step = count / 2);
		if (fn(it) < value)
			first = ++it, count -= step + 1;
		else
			count = step;
	}
	return first;
}
template<class T, class U>
T upper_bound_on(T first, T last, const U& value, const function<U(T)>& fn) {
	T it, step, count = last - first;
	while (count > 0) {
		it = first + (step = count / 2);
		if (!(value < fn(it)))
			first = ++it, count -= step + 1;
		else	
			count = step;
	}
	return first;
}
// End snippets

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	ll n, m, k;
	read(n, m, k);

	vector<ll> a(n), b(m);
	rep(i, 0, n) read(a[i]);
	rep(i, 0, m) read(b[i]);
	int aa = 0, bb = 0;
	ll csum = 0;
	while (bb < m && csum + b[bb] <= k) csum += b[bb++];
	ll ans = bb;
	while (aa < n) {
		csum += a[aa++];
		while (csum > k && bb > 0) csum -= b[--bb];
		if (csum <= k) chmax(ans, (ll)aa + bb);
	}
	write(ans);
}


Measured memory_bytes: 6364
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59


int main(){
  ll i,j;
  ll n,q;
  cin>>n>>q;
  string s;
  cin>>s;
  s='0'+s+'0';
  char t[q],d[q];
  for(i=0;i<q;i++) cin>>t[i]>>d[i];

  ll left2=0,right2=n+1;
  while(right2-left2>1){
    ll mid2=(right2+left2)/2;
    ll m2=mid2;
    ll g=0,g2=0;
    for(i=0;i<q;i++){
      if(s[m2]==t[i]){
        if(d[i]=='L') m2--;
        else m2++;
        if(m2<=0) {
          g=1;
        }
        if(m2>=n+1) {
          g2=1;
        }
      }
    }

    if(g2==0) left2=mid2;
    else right2=mid2;
  }
  ll a2=left2;

  ll left=0,right=n+1;
  while(right-left>1){
    ll mid=(right+left)/2;
    ll m=mid;
    ll f=0,f2=0;
    for(i=0;i<q;i++){
      if(s[m]==t[i]){
        if(d[i]=='L') m--;
        else m++;
        if(m<=0) {
          f=1;
        }
        if(m>=n+1) {
          f2=1;
        }
      }
    }
    if(f==0) right=mid;
    else left=mid;
  }
  ll a1=left;


  cout<<max(0ll,a2-a1)<<endl;
  return 0;
}

Measured memory_bytes: 1088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _201480958125912
{
    class Program
    {
        static void Main(string[] args)
        {
            foreach (var x in Enumerable.Range(1, 9))
            {
                foreach (var y in Enumerable.Range(1, 9))
                {
                    Console.WriteLine("{0}x{1}={2}", x, y, x * y);
                }
            }
        }
    }
}

Measured memory_bytes: 9284
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    float sum;
    sum = 0;
    cin >> n;
    vector<float> vec(n);
    for (int i = 0; i < n; i++){
        cin >> vec.at(i);
    }
    /*for (int i = 0; i < n; i++){
        cout << vec.at(i);
    }*/
    vector<float> rev(n);
    for (int i = 0; i<n; i++){
        rev.at(i) = 1 / vec.at(i);
    }
    /*for (int i = 0; i<n; i++){
        cout << rev.at(i);
    }*/
    for (int i = 0;i < n; i++){
        sum = sum + rev.at(i);
    }
    cout << 1 / sum << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>

using namespace std;

int ans[100001];

int main()
{
	int n;
	cin>>n;
	
	vector <int> v;
	
	for(int i=0;i<n;i++)
	{
		int input;
		cin>>input;
		v.push_back(input);
	}
	
	for(int i=1;i<=n;i++)
	{
		int p = v[i-1];
		ans[p]=i;
	}
	
	for(int i=1;i<=n;i++)
	{
		cout<<ans[i]<<' ';
	}
	
	return 0;
}

Measured memory_bytes: 1784
#include <iostream>
#include <math.h>

using namespace std;
#define ll long long

int main () {
  ll n, k;
  ll ans = 0;
  cin >> n >> k;
  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }
  for (ll i = k + 1; i <= n; i++) {
    ans += i - k;
    ll sub = n % i;
    if (sub >= k) {
      ans += sub - k + 1;  
    }
    sub = n / i - 1;
    ans += sub * (i - k);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll N;
    cin >> N;
    ll ans = 0;
    rep(i, N){
        ll a;
        cin >> a;
        if(a % 2 != 0 && (i+1) % 2 != 0){
            ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 3620
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial, log
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


N, K = Is()
log2k = log(K, 2)
ans = 0
for i in range(1, N+1):
    j = max(0, ceil(log2k - log(i, 2)))
    tmp = N * 2**j
    ans += 1/tmp
print(ans)


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

typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define mkt make_tuple
#define all(x) x.begin(), x.end()

int n;
const int MAXS = 5e5;
int fen[MAXS + 3];
int a[MAXS + 3];
queue<int> elems[MAXS + 3];
vii queries[MAXS + 3];
int ans[MAXS+3];

void update(int pos, int delta){
    while(pos <= n){
        fen[pos] += delta;
        pos += pos & (-pos);
    }
}

int query(int pos){
    int answer = 0;
    while(pos){
        answer += fen[pos];
        pos -= pos & (-pos);
    }
    return answer;
}

int main(){
	ios::sync_with_stdio(false), cin.tie(nullptr);
    cin>>n;
    int q; cin>>q;
    bool vis[n+2] = {};
    for (int i=1; i<=n; i++){
        cin>>a[i];
        elems[a[i]].push(i);
        if (!vis[a[i]]){
            update(i, 1);
            vis[a[i]] = 1;
        }
    }
    for (int i=0; i<q; i++){
        int l,r; cin>>l>>r;
        queries[l].pb(ii(i, r));
    }
    
    for (int i=1; i<=n; i++){
        //first answer all, then update:
        for (int j=0; j<queries[i].size(); ++j){
            int r = queries[i][j].second;
            int index = queries[i][j].first;
            int cans = query(r);
            ans[index] = cans;
        }
        queries[i].clear();
        int el = a[i];
        int pos = elems[el].front();
        elems[el].pop();
        update(pos, -1);
        if (!elems[el].empty()) update(elems[el].front(), 1);
    }
    for (int i=0; i<q; i++){
        cout<<ans[i]<<'\n';
    }
    
	return 0;
}
/*
NARCO
*/


Measured memory_bytes: 369212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 1e6+9;

char s[sz];

typedef pair <int,int> pii;
#define x first
#define y second

vector <pii> a, b;

bool cmp(pii one, pii two)
{
    return (two.y - one.x) < (one.y - two.x);
}

int main()
{
    int n, sum = 0;
    cin >> n;
    for(int i=0; i<n; i++) {
        scanf("%s", s);
        int mn = 0, tot = 0;
        for(int j=0; s[j]; j++) {
            if(s[j] == '(') tot++;
            else tot--;
            mn = min(mn, tot);
        }
        mn = 0 - mn;
        sum += tot;
        if(tot > 0) a.push_back({mn, tot});
        else b.push_back({mn, tot});
    }

    if(sum) {
        puts("No");
        exit(0);
    }

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

    int sofar = 0;
    for(auto p : a) {
        int mn = 0 - p.x;
        if(sofar + mn < 0) {
            puts("No");
            exit(0);
        }
        sofar += p.y;
    }

    sort(b.begin(), b.end(), cmp);

    for(auto p : b) {
        int mn = 0 - p.x;
        if(sofar + mn < 0) {
            puts("No");
            exit(0);
        }
        sofar += p.y;
    }

    puts("Yes");
}


Measured memory_bytes: 11316
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long X,K,D;
  cin>>X>>K>>D;
  X=abs(X);
  if(X/D>=K){
    cout<<X-D*K<<endl;
  }
  if(X/D<K){
    if((K-(X/D))%2==0){
      cout<<X-(X/D)*D<<endl;
    }
    if((K-(X/D))%2==1){
      cout<<abs(X-(X/D)*D-D)<<endl;
    }
  }
}

Measured memory_bytes: 3672
//
//  triangle.cpp
//  my_programs
//
//  Created by Jiatuo Zou on 7/27/20.
//  Copyright © 2020 Jiatuo Zou. All rights reserved.
//

#include <iostream>
#include <algorithm>

int main()
{
    using namespace std;
    
    int n, l[2000], sum = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    sort(l, l + n);
    for(int i = 0; i < n - 2; i++){
        for(int j = i + 1, k = i + 2; j < n - 1; ){
            if(k < n && l[k] < l[i] + l[j]){
                k++;
            } else{
                sum += (k - j - 1);
                j++;
            }
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3612
from collections import deque

h,w=map(int,input().split())
l=[input() for _ in range(h)]

ma=0
dx=[1,0,-1,0]
dy=[0,1,0,-1]

def bfs(sx,sy):
    if l[sy][sx]=="#":
      return 0
    
    d=[[float("inf")]*w for i in range(h)]
    
    que=deque([])
    que.append((sx,sy))
    d[sy][sx]=0

    while que:
      p = que.popleft()
 
      for i in range(4):
          nx=p[0]+dx[i]
          ny=p[1]+dy[i]

          if 0<=nx<w and 0<=ny<h and l[ny][nx] != "#" and d[ny][nx] == float("inf"):
              que.append((nx,ny))
              d[ny][nx] = d[p[1]][p[0]] + 1
              gx=nx
              gy=ny
 
    return d[gy][gx]

for i in range(h):
  for k in range(w):
    ma = max(ma,bfs(k,i))
    
print(ma)

Measured memory_bytes: 3316
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)

	A1, A2, A3 := getInt(), getInt(), getInt()
	sum := A1 + A2 + A3
	if sum >= 22 {
		out("bust")
	} else {
		out("win")
	}
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

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

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}



int main(){

  nCrprep();
  
  ll n,m; cin >> n >> m;
  
  auto vec = prime_factorize(m);
  
  ll ans = 1;
  
  for(auto p : vec){
    ll x = p.second;
    
    ans *= nCr(n-1+x,x);
    ans = mod(ans);
  }
  
  cout << ans << endl;
  
  
}

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

if t in s:
    print(0)
else:
    ans = 10000000
    for i in range(len(s)-len(t)+1):
        tmp = 0
        for j in range(len(t)):
            if s[i+j] != t[j]:
                tmp += 1
        ans = min(ans,tmp)
    print(ans)

Measured memory_bytes: 9132