akhauriyash/Code-Regression huggingface dataset:
#input
n, a, b = map(int, input().split())

#output
mod = pow(10, 9) + 7

def cmb(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    k = min(n-k,k)
    value = 1
    inv = [1] * (k+1)
    if k >= 1:
        value *= (n-k+1) % mod
    for i in range(2,k+1):
        inv[i] = mod-inv[mod%i]*(mod//i)%mod
        value = value * (n-k+i) * inv[i] % mod
    return value

answer = (pow(2, n, mod) - 1 - cmb(n, a) - cmb(n, b)) % mod
print(answer % mod)

Measured memory_bytes: 10932
#include<bits/stdc++.h>
using namespace std;
main(){
    string s[4] = {"AC", "WA", "TLE", "RE"};
    int a[4] = {0};
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        string b;
        cin >> b;
        for(int j = 0 ;j < 4; j++)
            if(b == s[j]) a[j]++;
    }
    for(int i = 0; i < 4; i++)
        cout << s[i] << " x "<< a[i]<<endl;

}


Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define repr(i, n) for(int i=(n-1); 1<=i; i--)
#define repr2(i, from, to) for(int i=(from-1); (int)(to)<=i; i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int to, cost; };
struct gNode { int from, to, cost; };
struct tNode { int value; int parent; vector<int> child; };


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

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}
ll mod_pow(ll x, ll n){
	if(n == 0) return 1;
	ll res = mod_pow(x*x % MOD, n/2);
	if(n & 1) res = res * x % MOD;
	return res;
}

int main(void){
	int n; cin >> n;
	int now = 0;
	rep(i, n){
		int a; cin >> a;
		now ^= a;
	}

	if(now == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

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

typedef long long ll;

int main() {
	string s; cin >> s;
	string ans;
	bool f=false;
	for (int i = s.length() - 1; i >= 0; i--) {
		if (!f && s[i] == 'F') {
			f = true;
			continue;
		}
		if (f) {
			ans.push_back(s[i]);
		}
	}
	reverse(ans.begin(), ans.end());

	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from functools import lru_cache

def solve(n,x):
    total=[1]
    paty=[1]
    for i in range(50):
        total.append(total[i]*2+3)
        paty.append(paty[i]*2+1)

    @lru_cache(maxsize=None)
    def f(N,X):
        if N==0 and X<=0:
            return 0
        elif N==0 and X>0:
            return 1
        elif X<=total[N-1]+1:
            return f(N-1, X-1)
        else:
            return paty[N-1]+1+f(N-1, X-total[N-1]-2)
    return print(f(n,x))

if __name__=='__main__':
    n,x=map(int,input().split())
    solve(n,x)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const double EPS  = 1e-10;
const bool debug = 0;
//-----------------------//

ll N, M;

int main() {
	cin >> N >> M;
	ll ans = (N - M) * 100;
	ans += M * 1900;
	ans *= 1<<M;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
use itertools::iproduct;
use proconio::input;

fn main() {
    input!(r: usize, c: usize, goods: [(usize, usize, u64)]);

    let mut val = mat![0; r + 1, c + 1];
    for &(r, c, v) in &goods {
        val[r][c] = v;
    }

    let mut dp = mat![0; r + 1, c + 1, 4];
    for (i, j, k) in iproduct!(1..=r, 1..=c, (0..=3).rev()) {
        max_assign!(dp[i][j][0], dp[i - 1][j][k]);
        max_assign!(dp[i][j][k], dp[i][j - 1][k]);
        if val[i][j] != 0 {
            max_assign!(dp[i][j][1], dp[i - 1][j][k] + val[i][j]);
            if k > 0 {
                max_assign!(dp[i][j][k], dp[i][j - 1][k - 1] + val[i][j]);
            }
        }
    }

    println!("{}", dp[r][c].iter().max().unwrap())
}

#[macro_export]
macro_rules! mat {
    ($v:expr; $l:expr, $($r:expr),*) => { vec![mat!($v; $($r),*); $l] };
    ($v:expr; $l:expr) => { vec![$v; $l] };
    () => { vec![] };
}

#[macro_export]
macro_rules! max_assign {
    ($x:expr, $y:expr) => {{
        let rhs = $y;
        if $x < rhs {
            $x = rhs
        }
    }};
}


Measured memory_bytes: 713560
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll INF = 1LL << 30;

int main(void){
    ll N; cin >> N;
    
    ll ans = N*(N-1)/2;
    
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<map>
#include<set> 
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue> 
using namespace std;
int main() 
{int s=1,a,b,c,k;
 cin>>a>>b>>c>>k;
 
 for (int i=1;i<=k;i++)s*=2;
 
 if (a>=b and a>=c){
 cout<<s*a+b+c;
 system("pause");
 return 0;}


 if (b>=c and b>=a){
 cout<<s*b+a+c;
 system("pause");
 return 0;}
 if (c>=a and c>=b){
 cout<<s*c+b+a;
 system("pause");
 return 0;}
 system("pause");
 return 0;}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin >> n >> k;
    cout << 1 + floor(log(n)/log(k));
    return 0;
}



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

int main(){
    int n,d;
    cin>>n>>d;
    double x[n],y[n];
    for(int i=0;i<n;i++) cin>>x[i]>>y[i];
    int ans=0;
    for(int i=0;i<n;i++){
        double num;
        num=sqrt(x[i]*x[i]+y[i]*y[i]);
        if(num<=d){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6924
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
template <char d = ' ', class T>
ostream& operator << (ostream& out, vector<T>& v){ for(auto& e : v){ out << e << d; } return out; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ll n; cin >> n;
    string n; cin >> n;
    int cand = 0;
    for(auto& c : n){
        cand += c - '0';
    }
    cout << max(cand, 9 * int(n.size() - 1) + (n[0] - '1')) << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 4001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll,ll,ll>>>;

// MOD確認

int main(){
    /*ll N;
    cin >> N;
    if(N % 10 == 2 || N % 10 == 4 || N % 10 == 5 || N % 10 == 7 || N % 10 == 9){
        cout << "hon" << endl;
    }else if(N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8){
        cout << "pon" << endl;
    }else{
        cout << "bon" << endl;
    }*/
    ll K;
    string S;
    cin >> K >> S;
    if(S.size() <= K) cout << S << endl;
    else cout << S.substr(0,K) << "..." << endl;
} 


Measured memory_bytes: 3632
import sys
import collections
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10000000)
n,m,k=map(int,input().split())
gf = [[]for i in range(n)]
gb = [[]for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    gf[a-1].append(b-1)
    gf[b-1].append(a-1)

for i in range(k):
    a,b = map(int,input().split())
    gb[a-1].append(b-1)
    gb[b-1].append(a-1)

seen = [0 for i in range(n)]

def dfs(i,k):
    for nec in gf[i]:
        if seen[nec]!=0:
            continue
        seen[nec]=k
        dfs(nec,k)
k=1

for i in range(n):
    if seen[i]==0:
        seen[i]=k
        dfs(i,k)
        k+=1
c = collections.Counter(seen)
lis = []
for i in range(n):
    dec = 0
    for k in gb[i]:
        if seen[i]==seen[k]:
            dec += 1
    lis.append(c[seen[i]]-len(gf[i])-dec-1)
print(*lis)


Measured memory_bytes: 365024
import itertools
 
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
num = [i+1 for i in range(N)]
 
p_ord = 0
q_ord = 0
cnt = 0
for pre in itertools.permutations(num, N):
    if P == list(pre):
        p_ord = cnt
 
    if Q == list(pre):
        q_ord = cnt
    cnt += 1
 
print(abs(p_ord-q_ord))

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

int main()
{
	int a[4];


	for (int i = 0; i < 4; i++) {
		cin >> a[i];
	}
	sort(a, a + 4);
	if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)cout << "YES" << endl;
	else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void){
  cout << std::fixed << std::setprecision(16);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  std::vector<int> b(n-1);
  for(int i=0;i<n-1;i++){
    cin>>b[i];
  }

  int result=b[0];
  for(int i=1;i<n-1;i++){
    result+=std::min(b[i],b[i-1]);
  }
  result+=b[n-2];
  cout<<result<<endl;




  return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:640000000")
#include <bits/stdc++.h>
using namespace std;

const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
const double PI=acos(-1.0);

#define    READ(f) 	         freopen(f, "r", stdin)
#define    WRITE(f)   	     freopen(f, "w", stdout)
#define    MP(x, y) 	     make_pair(x, y)
#define    PB(x)             push_back(x)
#define    rep(i,n)          for(int i = 1 ; i<=(n) ; i++)
#define    repI(i,n)         for(int i = 0 ; i<(n) ; i++)
#define    FOR(i,L,R) 	     for (int i = L; i <= R; i++)
#define    ROF(i,L,R) 	     for (int i = L; i >= R; i--)
#define    FOREACH(i,t)      for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define    ALL(p) 	         p.begin(),p.end()
#define    ALLR(p) 	         p.rbegin(),p.rend()
#define    SET(p) 	         memset(p, -1, sizeof(p))
#define    CLR(p)            memset(p, 0, sizeof(p))
#define    MEM(p, v)         memset(p, v, sizeof(p))
#define    getI(a) 	         scanf("%d", &a)
#define    getII(a,b) 	     scanf("%d%d", &a, &b)
#define    getIII(a,b,c)     scanf("%d%d%d", &a, &b, &c)
#define    getL(a)           scanf("%lld",&a)
#define    getLL(a,b)        scanf("%lld%lld",&a,&b)
#define    getLLL(a,b,c)     scanf("%lld%lld%lld",&a,&b,&c)
#define    getC(n)           scanf("%c",&n)
#define    getF(n)           scanf("%lf",&n)
#define    getS(n)           scanf("%s",n)
#define    bitCheck(a,k)     ((bool)(a&(1<<(k))))
#define    bitOff(a,k)       (a&(~(1<<(k))))
#define    bitOn(a,k)        (a|(1<<(k)))
#define    bitFlip(a,k)      (a^(1<<(k)))
#define    iseq(a,b)         (fabs(a-b)<EPS)
#define    vi 	 vector < int >
#define    vii 	 vector < vector < int > >
#define    pii 	 pair< int, int >
#define    ff 	 first
#define    ss 	 second
#define    ll	 long long
#define    ull 	 unsigned long long
#define    POPCOUNT           __builtin_popcount
#define    POPCOUNTLL         __builtin_popcountll
#define    RIGHTMOST          __builtin_ctzll
#define    LEFTMOST(x)        (63-__builtin_clzll((x)))
#define    UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())

template< class T > inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); }
template< class T > inline T lcm(T a, T b) { return ((a) / gcd((a), (b)) * (b)); }
template <typename T> string NumberToString ( T Number ) { ostringstream ss; ss << Number; return ss.str(); }

#ifdef mamun
     #define debug(args...) {cerr<<"*: "; dbg,args; cerr<<endl;}
#else
    #define debug(args...)  // Just strip off all debug tokens
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;
///****************** template ends here ****************
int t,n,m;


int main() {
    ///check for 0 or -1 if input not specified
    #ifdef mamun
//        READ("in.txt");
//        WRITE("out.txt");
    #endif // mamun
//    ios_base::sync_with_stdio(0);cin.tie(0);
    while(~getI(n))
    {
        ll ans;
        rep(i,n)
        {
            ll x;
            getL(x);
            if(i == 1)ans = x;
            else ans = lcm(ans,x);
        }
        printf("%lld\n",ans);
    }

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int mod97=1000000007;
double pi=3.1415926536;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
bool rev(long long int a,long long int b)
{
    if(a>b)return true;
    else return false;
}
bool compa(pair<string,pair<int,int>>a,pair<string,pair<int,int>>b)
{
    if(a.first==b.first)
    {
        if(a.second.first>b.second.first)
        return true;
        else
        return false;
    }
    if(a.first<b.first)
    return true;
    else 
    return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    long long int n;
    cin>>n;
    long long int a[n];
    for(long long int i=0;i<n;i++)cin>>a[i];
    for(long long int i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            if(a[i]%3!=0 && a[i]%5!=0)
            {
                cout<<"DENIED";return;
            }
        }
    }
    cout<<"APPROVED";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    int count=1;
    while(t--)
    {
        
        solve();
    }
}


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

// THINGS TO REMEMBER
// ENDL is slow, '\n' is fast
// Clear everything (including graphs) between test cases
// use anti-anti-hash: https://codeforces.com/blog/entry/62393
// pb-ds: https://codeforces.com/blog/entry/11080
// check when to use LLONG_MAX/LLONG_MIN vs INT_MAX or INT_MIN
// You frequently suffer from confirmation bias - you trust your initial solution and miss simple things. 
// When you hit a roadblock, remember to rethink the solution ground up, not just try hacky fixes

int main(){
	
	// #ifndef ONLINE_JUDGE
 //    	freopen("input", "r", stdin);
 //    	freopen("output", "w", stdout);
 //    	freopen("error", "w", stderr);
	// #endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll h1,m1,h2,m2,k;

    cin>>h1>>m1>>h2>>m2>>k;

    cout<<max(60*h2+m2-60*h1-m1-k,0ll)<<endl;

}


Measured memory_bytes: 3652
// Last Change: 04/06/2019 18:55:17.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

ll N, M;
int64_t ans = 0;

// vector<ll> A;

int main() {
  cin >> N >> M;
  // A.resize(N + 5);

  ll sum = 0, ipt;
  map<ll, ll> note;
  for (ll i = 0; i <= N; ++i) {
    // A[i] = sum;
    ++note[sum % M];
    if (i == N) {
      break;
    }
    cin >> ipt;
    sum += ipt;
  }

  for (auto itr = note.begin(); itr != note.end(); ++itr) {
    ll p = itr->second;
    ans += p * (p - 1) / 2;
  }
  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}



Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k,a,b;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main (void)
{
  int n, f = 0, tmp;

  scanf("%d", &n);

  tmp = n;
  while (tmp != 0) {
    f += (tmp % 10);
    tmp /= 10;
  }

  printf((n % f == 0)? "Yes": "No");
  
  return 0;
}

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

int main()
{
	string s, t;
	cin >> s >> t;
	int a, b;
	cin >> a >> b;
	string u;
	cin >> u;
	if(u == s) cout << a - 1 << " " << b;
	else cout << a << " " << b - 1;
	return 0;
}



Measured memory_bytes: 256
N,M,*a=map(int,open(0).read().split())

dp=[1]*(N+1)

for i in a:
  	dp[i]=0

for n in range(2,N+1):
    dp[n]=(dp[n-1]+dp[n-2])%1000000007*dp[n]

print(dp[N])
    

Measured memory_bytes: 13940
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int q;
	cin>>s>>q;
	deque<char> chars;
	bool flip = false;
	for(int i=0;i<s.size();i++)chars.push_back(s[i]);
	for(int i=0;i<q;i++)
	{
		int t;
		cin>>t;
		if(t == 1)flip = !flip;
		else
		{
			int fi;
			cin >> fi;
			char c;
			cin >> c;
			if(flip^(fi == 1)) chars.push_front(c);
			else chars.push_back(c);
		}
	}
	string k;
	for(auto a:chars)
	{
		k.push_back(a);
	}
	if(flip)
		reverse(k.begin(),k.end());
	cout<<k<<endl;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
int n,a[15000];
int main() {
//freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    ll sum = 0LL;
    for(int i = 1; i < n; i++){
        sum+=a[i]-a[i-1];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
//#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
int main() {
  int n;
  cin >> n;
  ivec a(n - 1);
  REP(i, n - 1) cin >> a[i];
  ivec ans(n);
  REP(i, n - 1) {
    int num = a[i] - 1;
    ans[num]++;
  }
  REP(i, n) print(ans[i]);
  return 0;
}

Measured memory_bytes: 4788
#include <list>
#include <iostream>

using namespace std;

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

    bool reverse = n % 2 == 1;
    list<unsigned long long> b;
    for (int i = 0; i < n; i++) {
        unsigned long long ai;
        cin >> ai;
        if (i % 2 == 0) {
            b.push_back(ai);
        } else {
            b.push_front(ai);
        }
    }

    if (reverse) {
        b.reverse();
    }

    for (auto bi: b) {
        cout << bi << " ";
    }
    cout << endl;
    return 0;
}

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

struct UnionFind{
    vector<int> par;
    
    UnionFind(int n) : par(n){
        rep(i, n) par[i] = i;
    }
    
    int root(int x){
        if(par[x] == x) return x;
        return root(par[x]);
    }
    
    void unite(int x, int y){
        int root_x = root(x);
        int root_y = root(y);
        if(root_x == root_y) return;
        par[root_x] = root_y;
    }
    
    bool same(int x, int y){
        int root_x = root(x);
        int root_y = root(y);
        return root_x == root_y;
    } 
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<P> v(m);
    rep(i, m) cin >> v[i].first >> v[i].second;
    
    int res = 0;
    rep(i, m){
        UnionFind uf(n);
        rep(j, m) if(i != j) uf.unite(v[j].first-1, v[j].second-1);
        bool bridge = false;
        rep(j, n){
            if(!uf.same(0, j)){
                bridge = true;
                break;
            }
        }
        if(bridge){
            // cout << i << endl;
            res++;
        }
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!


void solve(){
    
    int n;
    cin>>n;
    const ll mod=1e9+7;
    
    ll f=1;
    for(ll i=1;i<=n;i++){
        f=(f%mod * i%mod)%mod;
    }
    cout<<f<<endl;
}





int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3624
n,m=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]
x.sort()
p,c=0,0

for a,b in x:
  if c+b<=m:
    p+=a*b
    c+=b
  else:
    p+=a*(m-c)
    c+=m-c
    break
print(p)

Measured memory_bytes: 27756
N,M=map(int,input().split())
bridge=[]
size=[1]*(N+1)
tree=list(range(N+1))
def find(a):
    x=tree[a]
    if a==x:
        return a
    y=find(x)
    tree[a]=y
    return y
for i in range(M):
    A,B=map(int,input().split())
    bridge.append((A,B))
Ans=N*(N-1)//2
ans=[]
for a,b in bridge[::-1]:
    aroot=find(a)
    broot=find(b)
    if aroot==broot:
        ans.append(Ans)
        continue
    ans.append(Ans)
    sa=size[aroot]
    sb=size[broot]
    Ans-=sa*sb
    if sa>sb:
        tree[broot]=aroot
        size[aroot]+=sb
    else:
        tree[aroot]=broot
        size[broot]+=sa
for i in ans[::-1]:
    print(i)

Measured memory_bytes: 24112
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	if(k>n){
		k =n;
	}
	// memset(dp,-1,sizeof(dp));
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}

	int dp[n];
	dp[0] = 0;
	dp[1] = abs(a[0] - a[1]);
	for(int i=2;i<=k;i++){
		dp[i] = abs(a[0] - a[i]);
	}

	for(int i=k+1;i<n;i++){
		int ans = INT_MAX;
		for(int j=1;j<=k;j++){
			int temp = dp[i-j] + abs(a[i] - a[i-j]);
			if(ans >temp){
				ans = temp;
			}
		}
		dp[i] = ans;
	}
	int ans = dp[n-1] ;
	if(n==k){
		ans = min(ans , abs(a[0] - a[n-1]));
	}

	cout<<ans<<endl;


}

Measured memory_bytes: 1024
import fractions
A,B,C,D = map(int,input().split())
lcmCD = C*D//fractions.gcd(C,D)
ac = (A-1)//C
ad = (A-1)//D
bc = B//C
bd = B//D
acd = (A-1)//(lcmCD)
bcd = B//(lcmCD)
print(B-A+1-(bc+bd-bcd-(ac+ad-acd)))

Measured memory_bytes: 5372
import java.util.Scanner;
 
class Main {
    Scanner sc = new Scanner(System.in);
 
    int[] count = new int[26];
 
    public void run() {
        String s=sc.nextLine().toLowerCase();
        int count=0;
        while(true){
            String str=sc.next();
            if(s.equals(str.toLowerCase()))count++;
            if("END_OF_TEXT".equals(str))break;
        }
        ln(count);
    }
 
    public static void main(String[] args) {
        new Main().run();
    }
 
    public static void pr(Object o) {
        System.out.print(o);
    }
 
    public static void ln(Object o) {
        System.out.println(o);
    }
 
    public static void ln() {
        System.out.println();
    }
}


Measured memory_bytes: 26272
#include<cstdio>

#define MOD (1000000000 + 7)
#define A (0)
#define T (1)
#define G (2)
#define C (3)

// A T G C NULL
int dp[300][3125];

int st(int a, int b, int c, int d, int e) {
    return ((((((a*5)+b)*5+c)*5+d)*5)+e);
}

int main(void) {
    int n;
    scanf("%d",&n);

    dp[0][st(4,4,4,4,4)] = 1;
    for(int i=0; i<=n; i++) {
        for(int s=0; s<3125; s++) {
            for(int ss=0; ss<4; ss++) {
                dp[i+1][(s*5 + ss)%3125] += dp[i][s];
                dp[i+1][(s*5 + ss)%3125] %= MOD;
            }
        }

        for(int x=0; x<5; x++) {
            for(int y=0; y<5; y++) {
                dp[i+1][st(x,A,G,C,y)] = 0;
                dp[i+1][st(A,G,C,x,y)] = 0;
                dp[i+1][st(x,y,A,G,C)] = 0;

                dp[i+1][st(A,x,G,C,y)] = 0;

                dp[i+1][st(x,A,y,G,C)] = 0;

                dp[i+1][st(x,G,A,C,y)] = 0;
                dp[i+1][st(G,A,C,x,y)] = 0;
                dp[i+1][st(x,y,G,A,C)] = 0;

                dp[i+1][st(x,A,C,G,y)] = 0;
                dp[i+1][st(A,C,G,x,y)] = 0;
                dp[i+1][st(x,y,A,C,G)] = 0;

                dp[i+1][st(x,A,G,y,C)] = 0;
                dp[i+1][st(A,G,x,C,y)] = 0;
            }
        }
    }

    int m = 0;
    for(int s=0; s<3125; s++) {
        m += dp[n][s];
        m %= MOD;
    }
    printf("%d\n", m);

}


Measured memory_bytes: 1408
#124-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,k=IL()
S=S()
Sn=[]
cs=S[0]
cn=1
for i in range(1,n):
    if S[i]==cs:
        cn+=1
    else:
        Sn.append(cn)
        cs=S[i]
        cn=1
Sn.append(cn)

if S[0]=='0':
    Sn=[0]+Sn
if S[-1]=='0':
    Sn=Sn+[0]
for i in range(1,len(Sn)):
    Sn[i]+=Sn[i-1]

Sn=[0]+Sn
ans=0
k=min(2*k+1,len(Sn)-1)
for i in range(0,len(Sn)-k,2):
    ans=max(ans,Sn[i+k]-Sn[i])
print(ans)

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

using namespace std;

#define int int64_t
const int N = 16;

int a[N][N], mx[1<<16], val[1<<16];

void precompute(int n) {
	for(int i = 1; i < (1<<n); i++) {
		int temp = i&(-i), p = 31-__builtin_clz(temp), curr = val[i^temp];
		for(int j = 0; j < n; j++)  
			if(i&(1<<j)) curr += a[p][j];			
		val[i] = curr;
	}
}

int solve(int n) {
	for(int i = 1; i < (1<<n); i++) {
		mx[i] = val[i];
		int temp = 0;
		while(temp=(temp-i)&i) {
			if(temp > (i^temp)) break;
			mx[i] = max(mx[i], mx[temp]+mx[i^temp]);
		}
	}
	
	return mx[(1<<n)-1];
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++) cin >> a[i][j];
		
	precompute(n);
	cout << solve(n);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<pair<ll,ll>> p(N);
    rep(i,N){
        ll t,a;
        cin >> t >> a;
        p[i].F = t;
        p[i].S = a;
    }

    ll a,b;
    a = p[0].F,b = p[0].S;

    rep(i,N){
        if(i == 0)continue;
        ll d = max(a/p[i].F,b/p[i].S);
        while (!(a <= p[i].F * d && b <= p[i].S * d)) d += 1;
        a = p[i].F * d;
        b = p[i].S * d;
    }
    cout << a+b << endl;
}

// なんかdoubleにしたら下何桁かがずれる。

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int N = int.Parse(Console.ReadLine());
        long[] A = new long[N];
        bool[] opr = new bool[N-1];
        string[] str = Console.ReadLine().Split(' ');
        for(int i=0;i<2*N-1;i++){
            if(i%2 == 0){
                A[i/2] = int.Parse(str[i]);
            }
            else{
                opr[i/2] = str[i] == "-";
            }
        }
        long[] sum = new long[N];
        sum[0] = A[0];
        for(int i=1;i<N;i++){
            sum[i] = sum[i-1] + A[i];
        }
        long max = 0;
        long minus = 0;
        for(int i=0;i<N-1;i++){
            if(!opr[i]){
                continue;
            }
            long count = 0;
            minus += A[i+1];
            i++;
            for(;i<N-1 && !opr[i];i++){
                count += A[i+1];
            }
            max = Math.Max(max,sum[N-1]-2*minus-2*count);
            i--;
        }
        max = Math.Max(max,sum[N-1]-2*minus);
        sb.Append(max+"\n");
    }
}

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

int main() {
  int a,b,q;
  cin>>a>>b>>q;
  ll s[100005],t[100005];
  rep(i,a) cin>>s[i];
  rep(i,b) cin>>t[i];
  rep(i,q) {
    ll x;
    cin>>x;
    int s_r=upper_bound(s,s+a,x)-s;
    int t_r=upper_bound(t,t+b,x)-t;
    int s_l=s_r-1;
    int t_l=t_r-1;
    ll ans=1e18;
    if (s_l>=0&&t_l>=0) 
      ans=min(ans,max(x-s[s_l],x-t[t_l]));
    if (s_r<a&&t_r<b)
      ans=min(ans,max(s[s_r]-x,t[t_r]-x));
    if (s_l>=0&&t_r<b)
      ans=min(ans,x-s[s_l]+t[t_r]-x+min(x-s[s_l],t[t_r]-x));
    if (s_r<a&&t_l>=0)
      ans=min(ans,s[s_r]-x+x-t[t_l]+min(s[s_r]-x,x-t[t_l]));
    cout<<ans<<endl;
  }  
  return 0;
}

Measured memory_bytes: 2816
import sys
input=lambda:sys.stdin.readline().rstrip()

# BinaryIndexedTree
# O(logN)で累積和取得と値の更新
# add(i,x)...i番目にxを加算
# sum(i,j)...[i,j)の累積和を取得
# sum_sub(i)...[0:i]の累積和を取得
class BinaryIndexedTree:
  def __init__(self, n):
    self.bit = [0] * n

  def add(self, i, x):
    i += 1
    while i <= len(self.bit):
      self.bit[i-1] += x
      i += i & -i

  def sum_sub(self, i):
    a = 0
    i += 1
    while i:
      a += self.bit[i-1]
      i -= i & -i
    return a

  def sum(self, i, j):
    a = 0
    if j != 0:
      a += self.sum_sub(j-1)
    if i != 0:
      a -= self.sum_sub(i-1)
    return a
mod=998244353
n,k=map(int,input().split())
lr=[]
for i in range(k):
  l,r=map(int,input().split())
  lr.append((l,r))
bit=BinaryIndexedTree(2*n+7)
bit.add(0,1)
bit.add(1,-1)
for i in range(n-1):
  x=bit.sum_sub(i)%mod
  for l,r in lr:
    bit.add(i+l,x)
    bit.add(i+r+1,-x)
print(bit.sum_sub(n-1)%mod)

Measured memory_bytes: 71604
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  while(n>0){
    if(n%10==7){
      cout << "Yes" << endl;
      return 0;
    }
    n /= 10;
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3132
import sys
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
table = [0]*26
 
letters = "abcdefghijklmnopqrstuvwxyz"
input_str = sys.stdin.read()
 
for A in input_str:
    index = 0
    for B in letters:
        if A == B or A == B.upper():
            table[index] += 1
            break
        index += 1
 
for i in range(len(letters)):
    print("%s : %d"%(letters[i],table[i]))


Measured memory_bytes: 5576
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pint;
typedef vector<int>vint;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}


int N,Q;

int c[300000];

int latte[300001];

int main(){
    scanf("%d%d",&N,&Q);
    rep(i,N)scanf("%d",&c[i]);

    rep(i,N)latte[c[i]]=c[i];
    rep(i,300000)chmax(latte[i+1],latte[i]);

    while(Q--){
        int x;
        scanf("%d",&x);
        int ans=0;
        for(int i=1;i*x-1<=300000;i++)chmax(ans,latte[i*x-1]%x);
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 3536
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x1,x2,x3,x4,x5;
  cin>>x1>>x2>>x3>>x4>>x5;
  if(x1==0)
    cout<<1<<endl;
   if(x2==0)
    cout<<2<<endl;
  if(x3==0)
    cout<<3<<endl; 
  if(x4==0)
    cout<<4<<endl;
  if(x5==0)
    cout<<5<<endl;
  
}

Measured memory_bytes: 3588
h,n=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
m=[]
for i in range(n):
  m.append(l[i][1])
x=min(m)
dp=[999999999999 for i in range(10**4+1)]
dp[0]=0
for i in range(10**4+1):
  for j in range(n):
    if i>=l[j][0]:
      dp[i]=min(dp[i-l[j][0]]+l[j][1],dp[i])
  dp[i]=min(dp[i-1]+x,dp[i])
ans=[]
for i in range(h,10**4+1):
  ans.append(dp[i])
print(min(ans))

Measured memory_bytes: 42860
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;

class Program
{


	//Main
	static void Main(string[] args)
	{
		//読み込む
		string S = Console.ReadLine();
		if(S.Substring(2, 1) == S.Substring(3, 1) 
		&& S.Substring(4, 1) == S.Substring(5, 1)){
				Console.WriteLine("Yes");
		}else{
				Console.WriteLine("No");
		}
	}
}



Measured memory_bytes: 11092
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int c[5];
    while(cin >> c[0], c[0]){
        range(i,1,5)
            cin >> c[i];
        bool rock, paper, scissors;
        rock = paper = scissors = false;
        rep(i,5){
            if(c[i] == 1){
                rock = true;
            }else if(c[i] == 2){
                scissors = true;
            }else{
                paper = true;
            }
        }
        int r, p ,s;
        if(rock && paper && scissors){
            r = p = s = 3;
        }else if(rock && paper && !scissors){
            p = 1;
            r = 2;
        }else if(rock && scissors && !paper){
            r = 1;
            s = 2;
        }else if(paper && scissors && !rock){
            s = 1;
            p = 2;
        }else if(rock){
            r = 3;
        }else if(paper){
            p = 3;
        }else if(scissors){
            s = 3;
        }
        rep(i,5){
            if(c[i] == 1)
                cout << r << endl;
            else if(c[i] == 2)
                cout << s << endl;
            else if(c[i] == 3)
                cout << p << endl;
        }
    }
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> field(H, vector<char>(W));
    int bcnt = 0;
    rep(i, H) rep(j, W) {
        cin >> field[i][j];
        if(field[i][j] == '#')
            bcnt++;
    }
    vector<vector<int>> dist(H, vector<int>(W, INF));
    queue<pair<int, pii>> que;
    que.push(MP(0, MP(0, 0)));
    dist[0][0] = 0;
    while(!que.empty()) {
        auto p = que.front();
        que.pop();
        int d = p.first;
        int x = p.second.first;
        int y = p.second.second;
        rep(i, 4) {
            int nx = x + dx[i], ny = y + dy[i];
            if(nx >= 0 && nx < W && ny >= 0 && ny < H && field[ny][nx] == '.') {
                que.push(MP(d + 1, MP(nx, ny)));
                dist[ny][nx] = d + 1;
                field[ny][nx] = '#';
            }
        }
    }
    if(dist[H - 1][W - 1] == INF) {
        cout << -1 << endl;
    } else {
        cout << H * W - bcnt - dist[H - 1][W - 1] - 1 << endl;
    }
    return 0;
}

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

int main(){
  int n,m;
  int rc,lc;
  int cnt;
  string str;
  int zen,now;
  while(cin>>n,n){
    rc=lc=0;
    cnt=0;
    for(int i=0;i<n;i++){
      cin>>str;
      if(str[0] == 'r')now = 0;
      else now = 1;
      
      if(str == "lu")lc++;
      if(str == "ru")rc++;
      if(str == "ld")lc--;
      if(str == "rd")rc--;
      if(lc == rc && zen != now)cnt++;
      zen = now;
    }
    cout<<cnt<<endl;
  }
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;

int main() {
	int a, b;
	cin>>a>>b;
	vector<int> v(1000);
	v[1]=1;
	for (int i=2; i<=999; ++i) v[i]=v[i-1]+i;
	int mm=INT_MAX, mmIdx=0;
	for (int i=1; i<999; ++i) {
		int d=v[i]-a;
		if (v[i+1]-b==d) {
			cout<<d<<endl;
			return 0;
		}
	}
	cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 256
N, M, Q = map(int, input().split())


class CumSum2d(object):
    def __init__(self, H, W):
        self.H, self.W = H, W
        self.tiles = [[0] * W for _ in range(H)]

    def add(self, x, y, c=1):
        self.tiles[y][x] += c

    def build(self):
        for y in range(self.H):
            for x in range(1, self.W):
                self.tiles[y][x] += self.tiles[y][x - 1]
        for y in range(1, self.H):
            for x in range(self.W):
                self.tiles[y][x] += self.tiles[y - 1][x]

    def get(self, sx, sy, tx, ty):
        assert sx <= tx and sy <= ty
        cnt = self.tiles[ty][tx]
        if sx > 0:
            cnt -= self.tiles[ty][sx - 1]
        if sy > 0:
            cnt -= self.tiles[sy - 1][tx]
        if sx > 0 and sy > 0:
            cnt += self.tiles[sy - 1][sx - 1]
        return cnt


cs = CumSum2d(N, N)
for i in range(M):
    l, r = map(int, input().split())
    cs.add(l - 1, r - 1)
cs.build()

for _ in range(Q):
    p, q = map(int, input().split())
    ans = cs.get(p - 1, p - 1, q - 1, q - 1)
    print(ans)


Measured memory_bytes: 14816
#include<iostream>
#include<map>
using namespace std;
long long a,b,n;
map<long long,long long>m;
inline long long dp(long long n)
{
	if(m[n])return m[n];
	if(n%2==0)return m[n]=(dp(n/2)%(1000000007))+(dp(n/2-1)%(1000000007))+(dp(n/2-1)%(1000000007));
	return m[n]=(dp(n/2)%(1000000007))+(dp(n/2)%(1000000007))+(dp(n/2-1)%(1000000007));
}
int main()
{
	cin>>n;
	m[0]=1;
	m[1]=2;
	cout<<dp(n)%(1000000007);
	return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
A = [int(i) for i in input().split()]
cnt = 0
for a in sorted(A,reverse=True):
    if (sum(A)/(4 * M)) <= a:
        cnt +=1 
    if cnt == M:
        print('Yes')
        break
    

if cnt < M:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) ((v).begin(), (v).end())
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */
int main() {
    int n, d;
    cin >> n >> d;
    int x[15][15];
    rep(i,n) {
        rep(j, d) cin >> x[i][j];
    }
    int count = 0;
    int sum;
    rep(i, n - 1) {
        for(int j = i + 1;j < n; j++) {
            sum = 0;
            rep(k, d) {
                sum += pow(x[i][k] - x[j][k], 2);
            }
            // cout << sum << endl;
            if(pow((int)sqrt(sum), 2) == sum) count++;
        }
    }
    cout << count << endl;
    return 0;
}


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

int main(){
  int t[201]={};
  int N,M,h,m;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> h >> m;
    t[i]=60*h+m;
  }
  cin >> M;
  for(int i=0;i<M;i++){
    cin >> h >> m;
    t[i+N]=60*h+m;
  }
  sort(t,t+N+M);
  for(int i=0;i<N+M;i++){
    if(i && t[i-1]==t[i])
      continue;
    if(i)
      printf(" ");
    printf("%d:%02d",t[i]/60,t[i]%60);
  }
  cout << endl;
}



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

#define int long long

const int MAX_N = 50;
int n, m;
int a[MAX_N], b[MAX_N];

bool graph[MAX_N][MAX_N];
bool visited[MAX_N];

void dfs(int v) {
    visited[v] = true;
    for(int v2=0; v2<n; ++v2) {
        if(!graph[v][v2]) continue;
        if(visited[v2]) continue;
        dfs(v2);
    }
}

signed main() {
    cin >> n >> m;
    for(int i=0; i<m; ++i) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    int ans = 0;
    for(int i=0; i<m; ++i) {
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
        for(int j=0; j<n; ++j) visited[j] = false;
        dfs(0);
        bool bridge = false;
        for(int j=0; j<n; ++j) if(!visited[j]) bridge = true;
        if(bridge) ans++;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll x;cin>>x;
  ll y=x/11;
  ll z=x%11;
  ll w;
  if(z<=6&&z>0)w=1;
  if(z>=7&&z<=10)w=2;
  if(z==0)w=0;
  cout<<2*y+w<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
	int i,t,j,a[10];
	for (i=0;i<=9;i++)
	{
		scanf("%d",&a[i]);
	}
	for (i=9;i>=0;i--)
	{
		for (j=0;j<i;j++)
		{
			if(a[j]<a[j+1])
			{
				t=a[j];
				a[j]=a[j+1];
				a[j+1]=t;
			}
		}
	}
	printf("%d\n",a[0]);
	printf("%d\n",a[1]);
	printf("%d\n",a[2]);
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[20001],b[20001];

int main() {
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
		a[i]=1+20000*i;
		b[i]=1+(n-1)*20000+(-20000)*i;
	}
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		x--;
		a[x]+=i;
	}
	for(ll i=0;i<n;i++,cout << (i==n?"\n":" ")){
		cout << a[i];
	}
	for(ll i=0;i<n;i++,cout<< (i==n?"\n":" ")){
		cout << b[i];
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 896
import math

n, d = map(int, input().split())
P = [list(map(int, input().strip().split())) for i in range(n)]

out = 0
for i in range(n):
    if math.sqrt((P[i][0]) ** 2 + (P[i][1]) ** 2) <= d:
        out += 1

print(out)

Measured memory_bytes: 45452
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		ArrayList<String> one = nextCharArray();
		ArrayList<String> two = nextCharArray();
		ArrayList<String> three = nextCharArray();
		myout(one.get(0) + two.get(1) + three.get(2));
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 37244