akhauriyash/Code-Regression huggingface dataset:
H,W,M=map(int,input().split())
Y=[0 for i in range(H+1)]
X=[0 for i in range(W+1)]
HW=[]
for i in range(M):
    h,w=map(int,input().split())
    Y[h]+=1
    X[w]+=1
    HW.append([h,w])

LY=[]
LX=[]
MY=max(Y)
MX=max(X)
for i in range(H+1):
    if Y[i]==MY:
        LY.append(i)
for i in range(W+1):
    if X[i]==MX:
        LX.append(i)

count=0
for i in range(M):
    if Y[HW[i][0]]==MY and X[HW[i][1]]==MX:
        count+=1

if count==len(LY)*len(LX):
    print(MY+MX-1)
else:
    print(MY+MX)

Measured memory_bytes: 164964
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll k;
    string s;
    cin>>s>>k;
    if(s.length()==1)
    {
        cout<<s[0];
        return 0;
    }
    ll i;
    if(s[0]=='1' && k!=1)
    {
        i=0;
        while(s[i]=='1' && i<s.length())
            i++;
        if(i==s.length())
        {
            cout<<1;
            return 0;
        }
        if(k<=i)
        cout<<1;
        else
            cout<<s[i];
        return 0;
    }
    if(s[0]=='1' && k==1)
    {
        cout<<1;
        return 0;
    }
    cout<<s[0];
    return 0;
}


Measured memory_bytes: 256
xy=[(1,0),(-1,0),(0,1),(0,-1)]

h,w=map(int,input().split())
l=[]
for i in range(h):
    l.append(input())
for i in range(h):
    for j in range(w):
        if l[i][j]=="#":
            f=0
            for x,y in xy:
                if 0<=(i+y)<h and 0<=(j+x)<w and l[i+y][j+x]=="#": f=1
            if f==0:
                print("No")
                exit()
                

print("Yes")


Measured memory_bytes: 3064
//ALDS1_3_A Stack - Elementary data structures - Stack
#include <iostream>
#include <string>
using namespace std;

class Stack
{
private:
    static const int MAX = 101;

public:
    Stack()
    {
        inisialize();
    }

private:
    int S[MAX];
    int top;

private:
    void inisialize()
    {
        top = 0;
    }

    bool isEmpty()
    {
        return top==0;
    }

    bool isFull()
    {
        return top >= MAX - 1;
    }

public:
    void push(int x)
    {
        if(isFull())
        {
            //error
            throw runtime_error("Stack is full");
        }
        top++;
        S[top] = x;
    }

    int pop()
    {
        if (isEmpty())
        {
            //error
            throw runtime_error("Stack is empty");
        }
        top--;

        return S[top+1];
    }

    int getTop()
    {
        return top;
    }

    void print()
    {
        cout << "top: " << top << " stack[ ";

        for (int i=0; i<=top; i++ ) {
            cout << S[i] << " ";
        }
        cout << "]" << endl;
    }
};



int main()
{
    Stack stack;
    string str;
    int ans = 0,a,b;

    while(cin >> str)
    {
        if (str == "+") {
            b = stack.pop();
            a = stack.pop();
            stack.push(a+b);
        } else if (str == "-") {
            b = stack.pop();
            a = stack.pop();
            stack.push(a-b);
        } else if (str == "*") {
            b = stack.pop();
            a = stack.pop();
            stack.push(a*b);
        } else {
            stack.push(stoi(str));
        }
    }
    cout << stack.pop() << endl;

    return 0;
}


Measured memory_bytes: 3140
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, M, R; cin >> N >> M >> R;
    vl r(R); REP(i, R) {cin >> r[i]; r[i]--;};
    vvl dist(N, vl(N, LINF)); REP(i, N) dist[i][i] = 0;
    REP(i, M){
        ll a, b, c; cin >> a >> b >> c; a--; b--;
        dist[a][b] = c; dist[b][a] = c;
    }
    REP(k, N) REP(i, N) REP(j, N){
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }
    
    ll ans = LINF;
    sort(r.begin(), r.end());
    do{
        ll cand = 0;
        REP(i, R-1){
            cand += dist[r[i]][r[i+1]];
        }
        ans = min(ans, cand);
    }while(next_permutation(r.begin(), r.end()));
    cout << ans << endl;
    return 0;
}


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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(t, c) for (auto&& t : c)
#define ALL(c) begin(c), end(c)
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define fk first
#define sv second

const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int l[n];

  REP(i, n) {
    cin >> l[i];
  }

  sort(l, l + n);

  int sum = 0;
  REP(i, k) {
    sum += l[n - i - 1];
  }

  cout << sum << endl;
}

Measured memory_bytes: 256
n,p = map(int,input().split())
s = input()

ans = 0
ten = 1
d = 0

if (10%p == 0):
    for i in range(n):
        if int(s[i])%p == 0:
            ans += i+1
    print(ans)

else:
    cntlist = [0]*p
    cntlist[0] = 1
    for i in range(n-1,-1,-1):
        a = int(s[i])*ten%p
        d = (d + a)%p
        ten *= 10
        ten %= p
        cntlist[d] += 1

    for i in cntlist:
        ans += i*(i-1)//2
    print(ans)     

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

using namespace std;

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define ALL(x) (x).begin(),(x).end()

typedef int64_t ll;
typedef vector<int> Vi;

int n;
Vi desc, asc;

int main()
{
	cin >> n;
	desc.resize(n);
	REP(i, n) cin >> desc[i];
	sort(ALL(desc), greater<>());
	asc = desc;
	reverse(ALL(asc));

	ll ans = 0;
	REP(i_c, n - 2)
	{
		int c = desc[i_c];
		for (int i_b = i_c + 1; i_b < n - 1; ++i_b)
		{
			int b = desc[i_b];
			int hi = b;
			int lo = c + 1 - b;

			if (lo > hi)
				break;

			ll cnt = upper_bound(asc.begin(), asc.end() - 1- i_b, hi)\
				- lower_bound(asc.begin(), asc.end() - 1- i_b, lo);
			if (cnt)
				ans += cnt;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
using namespace std;

map<string, vector<string>> word;
set<int> size;

string button(const string& str) {
    string result = "";
    for(const auto& c: str) {
        if('a' <= c && c <= 'o') result += (c - 'a') / 3 + '2';
        if('p' <= c && c <= 's') result += '7';
        if('t' <= c && c <= 'v') result += '8';
        if('w' <= c && c <= 'z') result += '9';
    }
    return result;
}

void dfs(string str, vector<string>& list) {
    if(str.empty()) {
        for(int i = 0; i < list.size(); ++i) cout << (i ? " " : "") << list[i];
        cout << "." << endl;
    }

    for(const auto& s: size) {
        if(str.size() < s) break;
        if(!word.count(str.substr(0, s))) continue;
        for(const auto& w: word[str.substr(0, s)]) {
            list.push_back(w);
            dfs(str.substr(s), list);
            list.pop_back();
        }
    }
}

int main() {
    int n;
    while(cin >> n, n) {
        word.clear();
        size.clear();
        for(int i = 0; i < n; ++i) {
            string s;
            cin >> s;
            word[button(s)].push_back(s);
            size.insert(s.size());
        }
        vector<string> list;
        string str;
        cin >> str;
        dfs(str, list);
        cout << "--" << endl;
    }
}

Measured memory_bytes: 1252
#include <stdio.h>
#include <string.h>

int main(){
	int ining,i,j,tokuten[100],mozisuu,hit,out;
	char mozi[8];
	scanf("%d",&ining);
	
	for(j=0; j<100; j++){
		tokuten[j]=0;
	}

	i=0;
	hit=0;
	out=0;
	
	while(ining>i){
		scanf("%s", mozi);
		mozisuu=strlen(mozi);
		if(mozisuu==7){
			tokuten[i]=tokuten[i]+hit+1;
			hit=0;
		} else {
			if(mozi[0]=='H'){
			hit=hit+1;
			if(hit==4){
				tokuten[i]=tokuten[i]+1;
				hit=hit-1;
			}
			}
			else{
			out=out+1;
			}
		}
	if(out==3){
		hit=0;
		out=0;
		i=i+1;
		}
	}

	for(j=0; j<ining; j++){
		printf("%d\n",tokuten[j]);
	}

	return 0;
}

Measured memory_bytes: 596
def nCr(n, r, mod):
    x, y = 1, 1
    for r_ in range(1, r+1):
        x = x*(n+1-r_)%mod
        y = y*r_%mod
    return x*pow(y, mod-2, mod)%mod

x, y = map(int, input().split())
mod = 10**9+7
if (x+y)%3 or 2*x<y or 2*y<x:
    print(0)
else:
    print(nCr((x+y)//3,(2*x-y)//3, mod))

Measured memory_bytes: 9048
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
a.sort(key=lambda x:-x)
d = defaultdict(int)
for i in a:
    d[i] += 1
beki = [2**i for i in range(32,0,-1)]
ans = 0
for i in a:
    if d[i] == 0:
        continue
    for j in beki:
        if j <= i:
            break
        ni = j - i
        if ni == i:
            if d[i] >= 2:
                ans +=1
                d[i]-=2
                break
        elif d[ni] > 0:
            ans += 1
            d[ni]-=1
            d[i]-=1
            break
print(ans)

Measured memory_bytes: 160628
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

struct score
{
	int team,pro,wrong[11];
	ll _time;
	
	score(int t){team = t;pro = _time = 0;REP(i,11)wrong[i] = 0;}
	
	bool operator<( const score& right ) const
	{
		return pro != right.pro ? pro > right.pro :
		_time != right._time ? _time < right._time : team < right.team;
	}
};

int main()
{
	int t,p,r;
	
	while(cin >> t >> p >> r,t|p|r)
	{
		vector<score> v;
		REP(i,t)
		{
			score tmp(i);
			v.PB(tmp);
		}
		
		REP(i,r)
		{
			int ttmp,ptmp,time;string str;
			cin >> ttmp >> ptmp >> time >> str;
			if(str == "CORRECT")
			{
				v[ttmp-1].pro++;
				v[ttmp-1]._time += time + v[ttmp-1].wrong[ptmp]*1200;
			}
			else
			{
				v[ttmp-1].wrong[ptmp]++;
			}
		}
		
		stable_sort(ALL(v));
		
		REP(i,t)
		{
			cout << v[i].team+1 << ' ' << v[i].pro << ' ' << v[i]._time << endl;
		}

	}		
		
		
			
	
	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int main() {
	cin.tie(0); cin.sync_with_stdio(false);
	int n;
	cin >> n;
	vector<tuple<string, int, int>> a;
	for (int i = 0; i < n; i++) {
		string s; int p;
		cin >> s >> p;
		a.emplace_back(s, -p, i + 1);
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		cout << get<2>(a[i]) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>

using namespace std;

int main() {
	int r, D, x;
	cin >> r >> D >> x;

	for (int i = 0; i < 10; i++) {
		x = r * x - D;
		cout << x << endl;
	}
	return 0;
}

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

using namespace std;

const int MOD = 1e9 + 7 , N = 1e5 + 5;
int memo[N][2];
string s;

int add(int a , int b) {
    a += b;
    while (a >= MOD) a -= MOD;
    return a;
}

int mul(int a , int b) {
    return a * 1ll * b % MOD;
}

int solve (int i , bool l) {
    if (i == s.size())
        return 1;

    int &ret = memo[i][l];
    if (~ret)
        return ret;

    ret = 0;
    int r = l ? 1 : s[i];
    for (int j = 0 ;j <= r ;j++)
        ret = add(ret , mul(solve(i + 1 , l | (j < s[i])) , j + 1));

    return ret;
}

int main() {
    cin >> s;
    for (char &c : s) c -= '0';
    memset(memo , -1 , sizeof memo);
    cout << solve(0 , 0);
}

Measured memory_bytes: 12308
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(),v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<pair<ll, ll> > p;
    for (ll i = 1; i <= n; i++)
    {
        ll temp;
        cin >> temp;
        p.push_back(make_pair(temp, i));
    }
    sort(ALL(p));
    for (auto q : p)
    {
        cout << q.second << " ";
    }
    cout << endl;
}

Measured memory_bytes: 2544
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
map<string,int>m;
int main(){
	int N;
	cin>>N;
	REP(i,N){
		string s;
		cin>>s;
		m[s]++;
	}
	/*int ans=0;
	for(auto it:m){
		ans++;
	}*/
	cout<<m.size()<<endl;
}

Measured memory_bytes: 19200
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a; i<n; i++)
using namespace std;
typedef long long ll;
const int mod=2019;
int main()
{ 

  ll l,r;
  cin>>l>>r;
  if(r-(l-1)>=2030)
  {
    cout<<0<<endl;
  }
  else
  {
    int mn=30000;
     for(int i=l; i<=r; i++)
     {
      for(int j=i+1; j<=r; j++)
      {
        int temp=((i%mod) * (j%mod))%mod;
        mn=min(temp,mn);
      }
     }
     cout<<mn<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
D, G = map(int, input().split())
mat = [[int(i+1)] + list(map(int, input().split())) for i in range(D)]
# 基本は高い得点から順に解いたほうがよいが、コンプリートボーナスは別
# bit全探索をかけるようにする
cost_list = []
for i in range(1<<D):
    point = 0
    cost = 0
    for j in range(D):
        if ((i>>j) & 1) == 1:
            point += 100* mat[j][1] * mat[j][0] + mat[j][2]
            cost += mat[j][1]
    if point < G:
        # iで一番左側にある0を探す。
        for j in range(D)[::-1]:
            if ((i>>j) & 1) == 0: # and論理積は1==1以外はすべてfalse
                for k in range(mat[j][1]):
                    if point < G:
                        point += 100* mat[j][0] 
                        cost += 1
                    else: break
                break
            else: continue
    if point >= G:
        cost_list.append(cost)
print(min(cost_list))

Measured memory_bytes: 3064
///cREATED bY BERNARB.01
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef priority_queue<int,vector<int>,greater<int>> pqil;
typedef priority_queue<int> pqig;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef priority_queue<pii> pqiig;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<int, int> mii;
#define mid ((l+r)/2)
#define PB push_back
#define PP pop_back
#define PF push_front
#define DF pop_front
#define F first
#define S second
#define MP make_pair
#define C continue
#define B break
#define R return
#define sz(v) (int)(v).size()
#define len(s) (int)(s).length()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(arr, x) memset((arr), (x), sizeof (arr))
#define loop(n) for(int i=0; i<(n); i++)
#define lop(a, n) for(int i=(a); i<(n); i++)
#define jloop(n) for(ll j=0; j<(n); j++)
#define kloop(n) for(ll k=0; k<(n); k++)
#define rloop(n) for(ll i=(n)-1; i>=0; i--)
#define sgm(y) (((y)*((y)+1))/2)
const ll INF = 2e17+423;
const ll mod = 1e9+7; //998244353;
const ld pi = acos(-1.0);
const ld cmpf = 1e-9;
//__int128_t
//      -ASCII-
//a -> z | A -> Z | 0 -> 9
//97 122 | 65  90 | 48  57
#define endl '\n'
ll po(ll,ll);












const int N = 1e5+9;
int n, k, r, p, s, res = 0;
string t, pld="";
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k >> r >> s >> p >> t;
  loop(k) {
    if(t[i]=='r') res+=p, pld+='p';
    else if(t[i]=='p') res+=s, pld+='s';
    else res+=r, pld+='r';
  }
  for(int i=k; i<n; i++){
    if(t[i]=='r') {
      if(pld[i-k]!='p') res+=p, pld+='p';
      else{
        if(i+k<n) pld+='z';
        else pld+='r';
      }
    }
    else if(t[i]=='p') {
      if(pld[i-k]!='s') res+=s, pld+='s';
      else{
        if(i+k<n) pld+='z';
        else pld+='p';
      }
    }
    else {
      if(pld[i-k]!='r') res+=r, pld+='r';
      else{
        if(i+k<n) pld+='z';
        else pld+='s';
      }
    }
  }
  cout << res;
  R 0;
}
/*

*/




























































ll po(ll x, ll n){
  if(n==0) R 1;
  ll y = po(x, n/2);
  y = ((y)*(y));
  if(n%2) y = (y*(x));
  R y;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<int> a;
vector<int> b;
int32_t main(){
	int n,k;cin>>n>>k;
	for(int i=0;i<n;i++){
		int t;cin>>t;
		a.push_back(t);
	}
	for(int i=0;i<n;i++){
		int t;cin>>t;
		b.push_back(t);
	}
	sort(a.begin(),a.end(),less<int>());
	sort(b.begin(),b.end(),greater<int>());
	int y=-1;
	for(int i=0;i<n;i++){
		y=max(a[i]*b[i],y);
	}
	int x=0;
	int time=0;
	while(x<y){
		int m=x+(y-x)/2;
		int suc=1;
		int tmpk=0;
		time++;
		////cerr<<"mid "<<m<<endl;
		////cerr<<time<<endl;
		for(int i=0;i<n;i++){
			int res=m/b[i];
			//cerr<<i<<" "<<res<<endl;
			if(res>a[i])continue;
			tmpk+=a[i]-res;
			//cerr<<tmpk<<endl;
			if(tmpk>k){
			suc=0;
			break;}
		}
		if(suc)y=m;
		else x=m+1;
	}
	assert(x==y);
	cout<<x<<endl;
	
	return 0;
}

Measured memory_bytes: 4976
import sys
input = sys.stdin.readline

def solve():
    INF = float('inf')

    def WarshallFloyd(adjList, INF):
        numV = len(adjList)
        D = [[INF]*numV for _ in range(numV)]
        for u, adj in enumerate(adjList):
            for v, wt in adj:
                D[u][v] = wt
            D[u][u] = 0

        for k in range(numV):
            Dk = D[k]
            for i in range(numV):
                Di = D[i]
                Dik = Di[k]
                for j in range(numV):
                    D2 = Dik + Dk[j]
                    if D2 < Di[j]:
                        D[i][j] = D2

        return D

    N, M, L = map(int, input().split())
    adjL = [[] for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        a, b = a-1, b-1
        adjL[a].append((b, c))
        adjL[b].append((a, c))
    Q = int(input())
    querys = [tuple(map(int, input().split())) for _ in range(Q)]

    cost1ss = WarshallFloyd(adjL, INF)

    adjL2 = [[] for _ in range(N)]
    for a in range(N):
        for b in range(a+1, N):
            if cost1ss[a][b] <= L:
                adjL2[a].append((b, 1))
                adjL2[b].append((a, 1))

    cost2ss = WarshallFloyd(adjL2, INF)

    anss = []
    for s, t in querys:
        s, t = s-1, t-1
        cost = cost2ss[s][t]
        if cost == INF:
            anss.append(-1)
        else:
            anss.append(cost-1)

    print('\n'.join(map(str, anss)))


solve()


Measured memory_bytes: 85340
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

bool passed[2][100100];
bool dp[2][100100];
ll A[110];
ll N;

bool win(ll p, ll rem){
    if(passed[p][rem]) return dp[p][rem];
    if(rem == 0) return false;
    
    bool ok = false;
    REP(i, N){
        if(rem >= A[i]){
            if(!win(1-p, rem-A[i])){
                ok = true; break;
            }
        }
    }
    passed[p][rem] = true;
    return dp[p][rem] = ok;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll K; cin >> N >> K;
    REP(i, N) cin >> A[i];
    REP(i, 2) REP(j, 100100) {dp[i][j] = false; passed[i][j] = false;};
    cout << (win(0, K) ? "First" : "Second") << endstr;
    return 0;
}


Measured memory_bytes: 5376
def gcd(a,b)
  return a if(b==0)
  return gcd(b,a%b);
end

def lcm(a, b)
  return a*b/gcd(a,b);
end

A, B, C, D = gets.strip.split.map {|e| (e.to_i) }
CD = lcm(C,D);

part_c = (B/C - (A-1)/C);

part_d = (B/D - (A-1)/D);

part_cd = (B/CD - (A-1)/CD);

part_c = 0 if(C>B)
part_d = 0 if(D>B)
part_cd = 0 if(CD>B)


result = (B-A+1) - (part_c + part_d - part_cd)

puts result



Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const double PI=acos(-1.0);
int main() {
   double A,B,H,M;
   cin>>A>>B>>H>>M;
   double alpha=(H*60+M)/720*(2*PI);
   double beta=M/60*(2*PI);
   double theata=alpha-beta;
   double distance=sqrt(A*A+B*B-2*A*B*cos(theata));
   cout<<fixed<<setprecision(15)<<distance<<endl;
}

Measured memory_bytes: 4296
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	int n;
	cin >> n;
	cout << n / 3 << endl;
	return 0;
}

Measured memory_bytes: 3624
from collections import deque

H, W = map(int, input().split())
mazes = [list(input()) for _ in range(H)]

dis = [[0, 1], [0, -1], [1, 0], [-1, 0]]
answer = 0
for h in range(H):
  for w in range(W):
    if mazes[h][w] == '#':
      continue
    else:
      last = 0
      arrived = [[0 for _ in range(W)] for __ in range(H)]
      routes = deque([[h, w]])
      arrived[h][w] = 1
      while(len(routes) > 0):
        hy, wx = routes.pop()
        move = arrived[hy][wx]
        last = move
        for y, x in dis:
          if 0 <= hy+y < H and 0 <= wx+x < W and mazes[hy+y][wx+x] == '.' and arrived[hy+y][wx+x] == 0:
            routes.appendleft([hy+y, wx+x])
            arrived[hy+y][wx+x] = move + 1
      answer = max(answer, last-1)
print(answer)

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

int main(){
    int a,b;
    cin >> a >> b;
    string s;
    cin >> s;
    if(s[a] != '-' || s.size() != a+b+1){
        goto dame;
    }else{
        s[a] = '2';
    }
    for(int i=0;i<a+b;i++){
        if(s[i] == '-') goto dame;
    }
    cout << "Yes" << endl;
    goto owari;
    dame:
    cout << "No" << endl;
    owari:

    return 0;
    
}

Measured memory_bytes: 256
def main():
    n = int(input())
    ans = 0
    tmpls = []
    for i in range(1,50001):
        tmp = int(i*1.08)
        tmpls.append(tmp)
    for i, p in enumerate(tmpls, 1):
        if n == p:
            ans = i
            break
    if ans == 0:
        print(":(")
    else:
        print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 5016
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	int a, b;
	cin >> a >> b;
	if (a + b == 15)
		cout << "+";
	else if (a * b == 15)
		cout << "*";
	else
		cout << "x";
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) {return log(b) / log(a);}

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}



int main() {
	string s, t;
	cin >> s >> t;
	vector<vector<int>> a(s.size());
	vector<vector<pair<int, int>>> x(s.size());
	rep(i, s.size()) {
		a[i].resize(t.size());
		x[i].resize(t.size());
	}
	rep(i, s.size()) {
		rep(j, t.size()) {
			if (i == 0 && j == 0) {
				if (s[0] == t[0]) {
					a[i][j] = 1;
					x[i][j] = make_pair(-1, -1);
				}
				else {
					a[i][j] = 0;
				}
			}
			else if (i == 0) {
				if (a[i][j - 1] == 1) {
					a[i][j] = a[i][j - 1];
					x[i][j] = make_pair(i, j - 1);
				}
				else if (s[i] == t[j]) {
					a[i][j] = 1;
					x[i][j] = make_pair(-1, -1);
				}
				else {
					a[i][j] = 0;
				}
			}
			else if (j == 0) {
				if (a[i - 1][j] == 1) {
					a[i][j] = a[i - 1][j];
					x[i][j] = make_pair(i - 1, j);
				}
				else if (s[i] == t[j]) {
					a[i][j] = 1;
					x[i][j] = make_pair(-1, -1);
				}
				else {
					a[i][j] = 0;
				}
			}
			else {
				if (s[i] == t[j]) {
					a[i][j] = a[i - 1][j - 1] + 1;
					x[i][j] = make_pair(i - 1, j - 1);
				}
				else {
					if (a[i][j - 1] > a[i - 1][j]) {
						a[i][j] = a[i][j - 1];
						x[i][j] = make_pair(i, j - 1);
					}
					else {
						a[i][j] = a[i - 1][j];
						x[i][j] = make_pair(i - 1, j);
					}
				}
			}
		}
	}
	
	string ans = "";
	int i = s.size() - 1;
	int j = t.size() - 1;

	if (a[i][j] == 0) {
		cout << "" << endl;
		return 0;
	}
	int aq = 0;
	while (aq < 7000) {
		aq++;
		auto z = x[i][j];
		if (z.first == -1) {
			ans.push_back(s[i]);
			break;
		}
		if (z.first == i - 1 && z.second == j - 1) {
			ans.push_back(s[i]);
		}
		i = z.first;
		j = z.second;

	}
	reverse(ans);
	cout << ans << endl;
}


Measured memory_bytes: 105984
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int N;
int R;
int S,T;
int pos[114514];
int bit[(1<<18)+2];
ll kai[114514];
ll mod=1000000007;
int sum(int i){
	int s=0;
	while(i>0){
		s+=bit[i];
		i-=i&-i;
	}
	return s;
}
void add(int i){
	while(i<=(1<<18)){
		bit[i]++;
		i+=i&-i;
	}
}
int main()
{
	while(true){
		scanf("%d",&N);
		for(int i=0;i<N;i++){
			pos[i]=i;
		}
		for(int i=0;i<(1<<18)+2;i++){
			bit[i]=0;
		}
		if(N==0)return 0;
		scanf("%d",&R);
		for(int i=0;i<R;i++){
			scanf("%d%d",&S,&T);S--;T--;
			swap(pos[S],pos[T]);
		}
		kai[1]=1;
		for(int i=2;i<114514;i++){
			kai[i]=(kai[i-1]*(ll)i)%mod;
		}
		ll ans=0;
		for(int i=N-1;i>=0;i--){
			ans+=(kai[N-i-1]*(ll)sum(pos[i]))%mod;
			//printf("%d\n",sum(pos[i]));
			add(pos[i]+1);ans%=mod;
		}
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 5452
/*modintを書く
欲しい機能：
・自動的にmodを取ってくれる:done
・任意modに対応する:done
・負数のmodもいい感じにしてくれる:done
・プリミティブな整数型とも計算ができる:done
・そのまま出力ができる:done
*/

/*行列演算ライブラリを書く
欲しい機能：
・和と差と積を計算できる:done
・行列累乗ができる:done
・任意の型を乗せれる:done
*/

#include<iostream>
#include<vector>
class modint{
    private:
        typedef long long ll;
        ll val;
        ll _mod;
    public:
        modint(ll n=0,ll mod=1e9+7):val(n),_mod(mod){
            while(val<0){
                val+=_mod*_mod;
            }
            val%=mod;
        }
        modint operator+(ll x){return modint(val+x,_mod);}
        modint operator-(ll x){return modint(val-x,_mod);}
        modint operator*(ll x){return *this*modint(x,_mod);}
        modint operator+(modint m){return modint(val+m.val,_mod);}
        modint operator-(modint m){return modint(val-m.val,_mod);}
        modint operator*(modint m){return modint(val*m.val,_mod);}
        modint& operator+=(ll x){return *this=*this+x;}
        modint& operator-=(ll x){return *this=*this-x;}
        modint& operator*=(ll x){return *this=*this*x;}
        modint& operator+=(modint m){return *this=*this+m;}
        modint& operator-=(modint m){return *this=*this-m;}
        modint& operator*=(modint m){return *this=*this*m;}
        friend std::ostream& operator<<(std::ostream &os,modint m){os<<m.val;return os;}
};

template<typename T> 
class Matrix{
    public:
        using MAT = std::vector<std::vector<T>>;
        MAT mat;
        size_t row,col;
        Matrix(size_t r,size_t c):row(r),col(c){
            mat.resize(row,std::vector<T>(col));
        }
        Matrix(MAT &v):mat(v),row(v.size()),col(v.front().size()){}
        Matrix(const Matrix &x){*this =x;}
        Matrix operator+(Matrix &x){
            Matrix res(row,col);
            for(int i=0;i<row;++i) for(int j=0;j<col;++j){
                res.mat[i][j]=mat[i][j]+x.mat[i][j];
            }
            return res;
        }
        Matrix operator-(Matrix &x){
            Matrix res(row,col);
            for(int i=0;i<row;++i) for(int j=0;j<col;++j){
                res.mat[i][j]=mat[i][j]-x.mat[i][j];
            }
            return res;
        }
        Matrix operator*(Matrix &x){
            Matrix res(row,x.col);
            for(int i=0;i<row;++i) for(int j=0;j<x.col;++j) for(int k=0;k<col;++k){
                res.mat[i][j] += mat[i][k]*x.mat[k][j];
            }
            return res;
        }
        Matrix pow(long long n){
            Matrix res(row,col);
            Matrix x=*this;
            for(int i=0;i<row;++i) res.mat[i][i]=1;
            while(n){
                if(n&1) res=x*res;
                x=x*x;
                n>>=1;
            }
            return res;
        }
};

int main(){
    using namespace std;
    long long N,K;
    cin>>N>>K;
    Matrix<modint> A(N,N);
    for(int i=0;i<N;++i) for(int j=0;j<N;++j){
        int a;cin>>a;
        A.mat[i][j]=a;
    }
    A=A.pow(K);
    modint ans(0);
    for(int i=0;i<N;++i) for(int j=0;j<N;++j){
        ans +=A.mat[i][j];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
n = input()
a_list = map(int, raw_input().split())

minus_count = 0
abs_min = 0
has_zero = False
total = 0
for a in a_list:
    if abs_min == 0 or abs(a) < abs_min:
        abs_min = abs(a)
    if a < 0:
        minus_count += 1
        total -= a
    elif a == 0:
        has_zero = True
    else:
        total += a
if not has_zero and minus_count % 2 == 1:
    total -= abs_min * 2
print(total)


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

using namespace std;


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

	string s,t;
	cin>>s>>t;
	int n=s.size();
	int m=t.size();
	int ans=INT_MAX;
	for(int i=0;i+m-1<n;i++)
	{
		int count=0;
		for(int j=0;j<m;j++)
		{
			if(s[i+j]!=t[j])
			{
				count++;
			}
		}
		ans=min(ans,count);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3656
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX 100000
#define INFTY (1<<30)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point& p) const { return fabs(x - p.y) < EPS && fabs(y - p.y) < EPS; } };
typedef Point Vector;
double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a));}
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
struct Segment { Point p1, p2; };
typedef Segment Line;
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;

  char prev = S[0];
  for (int i = 1; i < S.size(); i++) {
    if (prev != S[i]) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=10005;
int a[maxn];
int main(){
	int n,q,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	cin>>q;
	while(q--){
		int sch;
		cin>>sch;
		bool f=false;
		for(int i=1;i<=n;i++){
			if(a[i]==sch){
				f=true;
				break;
			}
		}
		if(f==true) ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3120
#include <stdio.h>

int main ()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if(a < b && b < c)
    {
        printf("Yes\n");
    }
        else
        {
            printf("No\n");
        }
        return 0;
}



Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

const int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int N, M;
    cin >> N >> M;
    vector<tuple<int, int, int>> PY(M);
    rep(i, M) {
        int p, y;
        cin >> p >> y;
        PY[i] = make_tuple(p, y, i+1);
    }

    sort(all(PY));

    int c = 1;

    vector<string> res(M);

    rep(i, M) {
        string p, x;
        if (i > 0 && get<0>(PY[i-1]) != get<0>(PY[i])) c = 1;
        p = to_string(get<0>(PY[i]));
        while (p.size() < 6) p = '0' + p;
        x = to_string(c);
        while (x.size() < 6) x = '0' + x;
        string r = p + x;
        res[get<2>(PY[i])-1] = r;
        c++;
    }

    rep(i, M) cout << res[i] << endl;
    return 0;
}


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

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
  return modpow(a, mod - 2, mod);
}

long long int combination(long long int n, long long int r) {
  if ( r * 2 > n ) r = n - r;
  long long int dividend = 1;
  long long int  divisor  = 1;
  for ( long long  int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= modinv(i, 1000000007);
    divisor  = divisor%(1000000007);
    dividend = dividend%(1000000007);
    //divisor = modinv(divisor, 1000000007);
  }
  //std::cout << divisor << " "<<dividend<<std::endl;
  return dividend * divisor % 1000000007;
}

int main(void){
  long long int X, Y;
  std::cin >> X >>Y;
  long long int Z=X+Y;
  long long int turn =Z/3;
  if(Z%3!=0){
    std::cout << 0;
    return 0;
  }else if(X<turn||Y<turn){
    std::cout << 0;
    return 0;    
  }
  //std::vector<std::vector<long long int> > v=comb(turn, Y-turn);
  std::cout << combination(turn,Y-turn);
  return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if (n<1200&&n<=3000)
    {
        cout<<"ABC"<<endl;
    }
    else if (n>=1200&&n<=3000)
    {
        cout<<"ARC"<<endl;
    }
}


Measured memory_bytes: 3616
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int cnt[SIZE],an;
void dfs(int x,int v){
    if(x==100){
        if(v==1)an++;
        return;
    }
    FOR(i,0,cnt[x]){
        if(v%(i+1)==0){
            dfs(x+1,v/(i+1));
        }
    }
}
int main(){
    int N;
    R(N);
    FOR(i,1,N){
        int now=i;
        FOR(j,2,now){
            while(now%j==0){
                now/=j;
                cnt[j]++;
            }
        }
    }
    dfs(2,75);
    W(an);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
ans = 0
for i in range(61):
    bit = 1 << i
    count = 0
    for j in range(N):
        if bit & A[j]:
            count += 1
    ans += 2**i * count * (N-count) % mod
print(ans % mod)


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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int main(){
    int N, K;
    cin >> N >> K;
    if(K == 1){
        cout << 1 << endl;
        return 0;
    }
    create_mod_tables(N*K);
    static int64_t dp[2001][2001];
    dp[0][0] = fact[N];
    for(int i=0; i<=N; i++) for(int j=0; j<=i; j++){
        if(i<N) add(dp[i+1][j], dp[i][j]);
        if(i>=j+1) add(dp[i][j+1], dp[i][j] * comb_mod(N*K - i - j*(K-1) - 1, K-2));
    }
    cout << dp[N][N] << endl;
    return 0;
}


Measured memory_bytes: 123776
from itertools import accumulate

N = 100000
prime = [True]*(N+1)

prime[0] = prime[1] = False

for i in range(N+1):
    if prime[i]:
        for j in range(2*i, N+1, i):
            prime[j] = False

prime2 = [0] * (N+1)

for i in range(N+1):
    if prime[i] and prime[(i+1)//2]:
        prime2[i] = 1

acc = list(accumulate(prime2))

Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(acc[r]-acc[l-1])


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

struct UnionFind {
	vector<int> r;

	UnionFind(int N) {
		r = vector<int>(N, -1);
	}

	int root(int x) {
		if (r[x] < 0) return x;
		return r[x] = root(r[x]);
	}

	bool unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (r[x] > r[y]) swap(x, y);
		r[x] += r[y];
		r[y] = x;
		return true;
	}

	int size(int x) {
		return -r[root(x)];
	}
};


int main() {
	int N, M;
	cin >> N >> M;
	
	UnionFind UF(N);
	for (int i = 0; i < M; i++)
	{
		int A, B;
		cin >> A >> B;
		A -= 1; B -= 1;
		UF.unite(A, B);
	}

	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		ans = max(ans, UF.size(i));
	}

	cout << ans << endl;
}



Measured memory_bytes: 4052
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int isKaibun(std::string s){
    std::string sc=s;
    std::reverse(sc.begin(),sc.end());
    if(s==sc){
        return 1;
    }
    return 0;
}

int main(){
    int a,b;
    std::cin >> a >> b;

    int ans = 0;
    for(int i=a; i<=b; i++){
        std::string s = std::to_string(i);
        ans += isKaibun(s);
    }

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


Measured memory_bytes: 3592
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<cstring>
#include<sstream>
#include<cassert>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAX_N = 200000;

int main()
{
    int N, T;
    static int t[MAX_N];
    cin >> N >> T;
    rep(i,N) {
        cin >> t[i];
    }
    
    ll ans = 0;
    rep(i, N) {
        if (i != N-1) {
            if (t[i+1] - t[i] <= T) ans += t[i+1] - t[i];
            else ans += T;
        } else {
            ans += T;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 H, W, M;
  cin >> H >> W >> M;
  vector<i64> h(M), w(M);
  for (i64 i = 0; i < M; i++)
    cin >> h[i] >> w[i];
  map<i64, i64> hCnt, wCnt;
  set<pair<i64, i64>> bom;
  for (i64 i = 0; i < M; i++)
  {
    hCnt[h[i]]++;
    wCnt[w[i]]++;
    bom.insert({h[i], w[i]});
  }
  i64 hMax = 0, wMax = 0;
  for (pair<i64, i64> i : hCnt)
    hMax = max(hMax, i.second);
  for (pair<i64, i64> i : wCnt)
    wMax = max(wMax, i.second);
  set<i64> hSet, wSet;
  for (pair<i64, i64> i : hCnt)
    if (hMax == i.second)
      hSet.insert(i.first);
  for (pair<i64, i64> i : wCnt)
    if (wMax == i.second)
      wSet.insert(i.first);
  for (i64 i : hSet)
    for (i64 j : wSet)
      if (bom.count({i, j}) == 0)
      {
        cout << hMax + wMax << endl;
        return 0;
      }
  cout << hMax + wMax - 1 << endl;
  return 0;
}


Measured memory_bytes: 92108