akhauriyash/Code-Regression huggingface dataset:
// #include <bits/stdc++.h>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
// #include <deque>
// #include <queue>
// #include <array>
// #include <ctime>
// #include <list>
#include <map>
#include <set>
// #include <complex>
// #include <cassert>
// #include <sstream>
// #include <forward_list>
// #include <unordered_set>
// #include <unordered_map> 
// #include <ctime>
 
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> // Common file  
// #include <ext/pb_ds/tree_policy.hpp>  
// #include <functional> // for less  
// using namespace __gnu_pbds;  

// // Declaring ordered_set 
// typedef tree<int, 
//     null_type, 
//     less<int>, 
//     rb_tree_tag, 
//     tree_order_statistics_node_update>  
//     ordered_set;  
 
#define int long long
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define scani(n) scanf("%d",&n);
#define EPS 1e-9
#define arrinput for(int i=0; i<n; i++) cin>>arr[i];
#define sumarr for(int i=0; i<n; i++) sum+=arr[i];
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define forr(i,n) for(int i=n-1; i>=0; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
 
typedef long long ll;  
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
 
const int MOD = 1e9+7;
const int n_ = 1e5+1000;
const long double PI = acos(-1.0);
 
ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}

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

	int n, m;
	cin>>n>>m;
	string s;
	cin>>s;
	reverse(all(s));
	vi v, ans;
	for0(i,n) {
		if(s[i] == '0') v.pb(i);
	}
	v.pb(n);
	int i = 0;
	while(i < n) {
		int id = lower_bound(all(v), i+m+1) - v.begin();
		id--; id = v[id];
		if(id == i) {
			cout<<-1;
			return 0;
		}
		ans.pb(id - i);
		i = id;
	}
	reverse(all(ans));
	for(int i: ans) cout<<i<<" ";

	return 0;
}

Measured memory_bytes: 2628
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const LL mod = 1000000007ll;

LL N;
LL X[100];

LL ans = INF;

void solve(){
	for(int i=0;i<=100;i++){
		LL sum = 0;
		for(int k=0;k<N;k++){
			sum += (X[k]-i)*(X[k]-i);
		}
		ans = min(sum,ans);
	}
}
 
int main(){
	cin >> N;
	for(int i=0;i<N;i++) cin >> X[i];
 
	solve();

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from fractions import gcd

from math import floor
# 約数全列挙(ソート済み)
# n = 24 -> [1,2,3,4,6,8,12,24]
def divisor(n):
    left = [1]
    right = [n]
    sup = floor(pow(n,1/2))
    for p in range(2,sup+1):
        if n % p == 0:
            if p == n//p:
                left.append(p)
                continue
            left.append(p)
            right.append(n//p)
    res = left + right[::-1]
    return res

def is_prime(n):
    if n <= 0: return None
    if n == 1: return False
    sup = floor(pow(n,1/2))
    for i in range(2,sup+1):
        if n % i == 0:
            return False
    return True

A, B = map(int,input().split())
G = gcd(A, B)
if G == 1:
    print(1)
    exit()
res = divisor(G)
ans = 0
for d in res:
    if d == 1 or is_prime(d):
        ans += 1

print(ans)

Measured memory_bytes: 5340
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
 
struct sword{
	int a;
	int b;
}kat[200005];
 
int cmp1(sword x,sword y){
	if (x.a>y.a) return 1;
	else if (x.a==y.a&&x.b>y.b) return 1;
	return 0;
}
 
int cmp2(sword x,sword y){
	if (x.b>y.b) return 1;
	else if (x.b==y.b&&x.a>y.a) return 1;
	return 0;
}
 
int main(){
	int n,h;
	cin>>n>>h;
	for (int i=1;i<=n;i++){
		cin>>kat[i].a>>kat[i].b;
	}
	
	int ans=0;

		sort(kat+1,kat+1+n,cmp1);
		sort(kat+2,kat+2+n,cmp2);
			for (int i=1;i<=n&&kat[i].b>=kat[1].a;i++){
				h-=kat[i].b;
				ans++;
				if (h<=0) break;
			}
			if (h>0){
				ans+=h/kat[1].a;
				h%=kat[1].a;
				if (h>0) ans++;
			}
	
	cout<<ans;
	
	
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include<climits>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////
#define pll pair<ll,ll>

ll N,X;

ll i,bp[55], p[55],ans;

int main(){
    scanf("%lld%lld", &N, &X);
    bp[0] = 1;
    p[0] = 1;
    fornum(i,0,N){
        bp[i + 1] = 3 + bp[i] * 2;
        p[i + 1] = 1 + p[i] * 2;
        //printf("%lld,%lld\n", bp[i + 1], p[i+1]);
    }
    ll x=0;
    for (i = N; i >= 0;i--){
        ll sx = X - x;
         //printf("%lld,%lld,%lld %lld %lld\n", i, x, sx,X,bp[i-1]);
        
        if(i==0){
            ans += 1;
            break;
        }
        if(sx==1){
            break;
        }else if(sx<=bp[i-1]+1){
            x = x + 1;
        }else if(sx==bp[i-1]+2){
            ans += p[i - 1]+1;
            break;
        }else if(sx<=bp[i-1]*2+2){
            ans += p[i - 1]+1;
            x=x +bp[i-1]+ 2;
        }else{
            ans += p[i];
            break;
        }
    }
        //dnf(N, 0);
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 256
def ore_comb(n,r,mod):
    '''
    return nCr
    O(min{n-r, r})
    '''
    bunsi=1 
    bunbo=1 
    r = min(r,n-r)
    for i in range(r):#分子
      bunsi = bunsi*(n-i)%mod
      bunbo = bunbo*(i+1)%mod

    ans = (bunsi*pow(bunbo,mod-2,mod))%mod
    return ans

[N,a,b] = list(map(int,input().split()))

mod = 10**9+7

ans = pow(2, N, mod) -1
ans -= ore_comb(N,a,mod)
if ans<0:
    ans += mod
ans -= ore_comb(N,b,mod)
if ans<0:
    ans += mod

print(ans)

Measured memory_bytes: 3064
N, X = list(map(int, input().split()))
l = list(map(int, input().split()))

D=0
i=0
c=0
while D <= X:
    try:
        c+=1
        # if i>len(l):
        #     break
        D+=l[i]
        i+=1
    except IndexError:
        break

print(c)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int h, w;
	cin >> h >> w;
	REP(i, h) {
		string s;
		cin >> s;
		cout << s << endl;
		cout << s << endl;
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  string Ans = "APPROVED";
  
  for(int i = 0; i < N; i++){
  	cin >> A.at(i);
  }
  
  for(int i = 0; i < N; i++){
  	if(A.at(i)%2 == 0){
      if(A.at(i)%3 != 0 && A.at(i)%5 != 0){
      	Ans = "DENIED";
      }
    }
  }
  
  cout << Ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1'000'000'007;
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

int main() {
    vector<string> s(3);
    cin >> s[0] >> s[1] >> s[2];
    vi p = {0, 0, 0};
    int turn = 0;
    while (true) {
        char ss = s[turn][p[turn]];
        p[turn]++;
        if (p[turn] == s[turn].size() + 1)
            break;

        if (ss == 'a') {
            turn = 0;
        } else if (ss == 'b')
            turn = 1;
        else if (ss == 'c')
            turn = 2;
    }
    if (turn == 0)
        cout << "A" << endl;
    else if (turn == 1)
        cout << "B" << endl;
    else
        cout << "C" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define MOD 1000000007
#define INF 1000000000000000000

#define MI modint<MOD>
template<int mod>struct modint{
	int x;
	modint():x(0){}
	modint(LL n):x(n>=0?n%mod:(mod-(-n)%mod)%mod){}
	modint &operator+=(const modint &n){if((x+=n.x)>=mod)x-=mod;return *this;}
	modint &operator-=(const modint &n){if((x+=mod-n.x)>=mod)x-=mod;return *this;}
	modint &operator++(){*this+=1;return *this;}
  modint &operator--(){*this-=1;return *this;}
	modint &operator*=(const modint &n){x=(int)((LL)x*n.x%mod);return *this;}
	modint &operator/=(const modint &n){*this*=n.inv();return *this;}
	modint operator-()const{return modint(-x);}
	modint operator+(const modint &n)const{return modint(*this)+=n;}
	modint operator-(const modint &n)const{return modint(*this)-=n;}
	modint operator++(int){modint ret(*this);*this+=1;return ret;}
  modint operator--(int){modint ret(*this);*this-=1;return ret;}
	modint operator*(const modint &n)const{return modint(*this)*=n;}
	modint operator/(const modint &n)const{return modint(*this)/=n;}
	bool operator<(const modint &n)const{return x<n.x;}
	bool operator>(const modint &n)const{return x>n.x;}
	bool operator<=(const modint &n)const{return x<=n.x;}
	bool operator>=(const modint &n)const{return x>=n.x;}
	bool operator!=(const modint &n)const{return x!=n.x;}
	bool operator==(const modint &n)const{return x==n.x;}
	friend istream &operator>>(istream &is,modint &n){LL l;is>>l;n=modint<mod>(l);return is;}
	friend ostream &operator<<(ostream &os,const modint &n){return os<<n.x;}
	int getmod(){return mod;}
	modint inv()const{int a=x,b=mod,c=1,d=0,n;while(b){n=a/b;swap(a-=n*b,b);swap(c-=n*d,d);}return modint(c);}
	modint pow(LL n)const{modint ret(1),m(x);while(n){if(n&1)ret*=m;m*=m;n>>=1;}return ret;}
};

int main() {
	LL N,ans=0;
	MI m;
	cin>>N;
	for(LL i=1;i<N; i++){
		ans+=(N-1)/i;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3564
#include <iostream>
#include <string.h>
#include <utility>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <queue>
#include <set>
#include <math.h>
#define pp pair<int, int>
#define vpp vector<pp>
#define vecto vector<ll>
#define ll long long
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
using namespace std;
#define ull unsigned long long int
#define f(i, n) for (int i = 0; i < n; i++)
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;
#define mod 1000000007
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)
ll max(ll a, ll b)
{
    if (a > b)
        return a;
    return b;
}

int main()
{
    IOS;
    string s;
    cin >> s;
    ll sum = 0;
    for (int i = 0; i < s.length(); i++)
    {
            sum += s[i] - '0';
            sum = sum % 9;
        
    }

    if (sum == 0)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

   
}

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

int main(void){
  int k,l;
  int x,y,s;
  int p[14][14]; //???????????????????????????[2]~[11]?????????
  for(k=1;k<=14;k++){
    for(l=1;l<=14;l++){
      p[k-1][l-1] = 0;
    }
  }
  // (x,y)???p[x+2][y+2]
  while(scanf("%d,%d,%d",&x,&y,&s)!=EOF){
    if(s==1){ //??????????°?
      for(k=-1;k<=1;k++){
        for(l=-1;l<=1;l++){
          if(abs(k) + abs(l) <= 1){
            p[x+k+2][y+l+2]++;
          }
        }
      }
    }
    else if(s==2){ //????????????
      for(k=-1;k<=1;k++){
        for(l=-1;l<=1;l++){
          p[x+k+2][y+l+2]++;
        }
      }
    }
    else if(s==3){ //???????????§
      for(k=-2;k<=2;k++){
        for(l=-2;l<=2;l++){
          if(abs(k) + abs(l) <= 2){
            p[x+k+2][y+l+2]++;
          }
        }
      }
    }
  }
  int zero=0;
  int max=0;
  for(k=0;k<10;k++){
    for(l=0;l<10;l++){
      if(p[k+2][l+2]==0) zero++;
      if(max < p[k+2][l+2]) max = p[k+2][l+2];
    }
  }
  printf("%d\n%d\n",zero,max);
  return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> ans(n+1);
	for(int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		ans[x] = i;
	}
	for(int i = 1; i <= n; i++) {
		cout << ans[i] << " ";
	}
	return 0;	
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
using namespace std;
typedef long long LL;

int main() {
    int a, b;

    cin >> a >> b;

    if (a == b) {
        cout << "Draw" << endl;
        return 0;
    }

    if (a == 1) {
        cout << "Alice" << endl;
        return 0;
    }

    if (b == 1) {
        cout << "Bob" << endl;
        return 0;
    }

    if (a > b) {
        cout << "Alice" << endl;
        return 0;
    }

    if (b > a) {
        cout << "Bob" << endl;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 256
s = input()

count = 0
pre = ''
movable = 0
for i in reversed(s):
    if pre == '':
        pre = i
    elif pre == 'CB' and i == 'A':
        count += movable
    elif pre == 'CB' and i == 'C':
        pre = 'C'    
    elif pre == 'C' and i == 'B':
        movable += 1
        pre = 'CB'
    else:
        movable = 0
        pre = i   
print(count)

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

int main() {
    int N, M, C, i, j;
    int answer = 0, cnt = 0;
    cin >> N >> M >> C;
    vector<int> vec_B(M);
    vector<vector<int>> code(N, vector<int>(M));
    for (i = 0; i < M; i++) cin >> vec_B.at(i);
    for (i = 0; i < N; i++) {
        for (j = 0; j < M; j++) {
            cin >> code.at(i).at(j);
            answer += code.at(i).at(j) * vec_B.at(j);
        }
        answer += C;
        if (answer > 0) cnt++;
        answer = 0;
    }
    cout << cnt << endl;
}

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

int main() {
   int n;
   cin >> n;
   vector<int> v(n);
   rep(i, n) {
       cin >> v[i];
   }

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

   double ans = v[0];

   rep2(i, 1, n) {
       ans = (ans + v[i]) / 2;
   }

   cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = Integer.parseInt(sc.next());
        int[][][] residents = new int[4][3][10];
        for (int i = 0; i < n; i++) {
            int b = Integer.parseInt(sc.next());
            int f = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            int v = Integer.parseInt(sc.next());
            residents[b-1][f-1][r-1] += v;
        }

        for (int i = 0; i < 4; i++) {
            if (i != 0) {
                out.printf("####################\n");
            }
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 10; k++) {
                    out.printf(" %d", residents[i][j][k]);
                }
                out.printf("\n");
            }
        }
        out.flush();
    }
}


Measured memory_bytes: 29784
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,m,d

    read*, n,m,d
    if (d==0) then
        print"(f20.15)", 1d0/dble(n)*dble(m-1)
    else
        print"(f20.15)", 2d0*(1d0/dble(n)-dble(d)/(dble(n))**2)*dble(m-1)
    end if
end program main

Measured memory_bytes: 3052
import re
def main():
    u = 'UNRESTORABLE'
    S = input()
    T = input()

    n = len(T)
    if len(S)-len(T) < 0:
        print(u)
        return

    for n in range(len(S)):
        s = len(S) - len(T) - n
        if s < 0:
            break
        e = s + len(T)
        U = S[s:e]
        if re.search(U.replace("?","."), T):
            S = S[:s] + T + S[e:]
            S = S.replace("?","a")
            print(S)
            return

    print(u)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); //整数の数
        int[] a = new int[n];
        for (int i=0; i<n; i++) { //整数を読み込む
            a[i] = sc.nextInt();
        }
        //シェルソート
        shellSort(a,n);
    }
    /**
     * シェルそーと
     */
    static void shellSort(int[] a, int n) {
        int g=1;
        int m=1;
        int count=0;
        while(3*g+1<n) {
            g=3*g+1;
            m++;
        }
        System.out.println(m);
        while(g>0) {
            count=count+insertionSort(a,n,g);
            System.out.print(g);
            if(g!=1) System.out.print(" ");
            g/=3;
        }
        System.out.println();
        System.out.println(count);
        for(int i=0; i<n; i++) {
            System.out.println(a[i]);
        }
    }
    /**
     * 挿入ソート
     */
    public static int insertionSort(int[] a, int n, int g) {
        int count = 0;
        for (int i=g; i<n; i++) {
            int v = a[i];
            int j = i-g;
            while(j>=0 && a[j]>v) {
                a[j+g] = a[j];
                j-=g;
                count++;
            }
            a[j+g] = v;
        }
        return count;
    }
}


Measured memory_bytes: 298696
#include <iostream>

using namespace std;


int main()
{
    long long N,A,B,i,j,min,max;
    cin>>N>>A>>B;

    min=(N-1)*A+B;
    max=(N-1)*B+A;


    if(B<A)
        cout<<'0';
    else
        if(B==A)
            cout<<'1';
    else
        if(N==1)
            cout<<'0';
        else
            cout<<max-min+1;

}

Measured memory_bytes: 256
n, *a = $<.read.split.map(&:to_i)

a = a.map.with_index{|t,i| [t,i] }.sort_by{|(t,_)| -t }

dp = [0] * (n+1)

a.each_with_index do |(a, k), i|
  dp_ = [0] * (n+1)
  (i+1).times do |j|
    dp_[j+1] =                  dp[j] + (k      -j) * a
    dp_[j]   = [ dp_[j],    dp[j] + (n-i+j-1-k) * a ].max
  end
  dp = dp_
end

puts dp.max

Measured memory_bytes: 42300
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n, a, b;
  vector<int> v;

  scanf("%d %d %d", &n, &a, &b);
  REP(i,n){
    int t;
    scanf("%d", &t);
    v.pb(t);
  }

  llong left = 0, right = SUR;
  while(right - left > 1){
    llong mid = (left + right) / 2;
    llong num = mid;
    bool bomb = true;
    REP(i,n){
      if(v[i] > b * mid){
        num -= (llong)ceil((double)(v[i] - b * mid) / (double)(a - b));
      }
      if(num < 0){
        bomb = false;
        break;
      }
    }
    if(bomb){
      right = mid;
    }else{
      left = mid;
    }
  }

  printf("%lld\n", right);
  return 0;
}



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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


using vvll = vector< vector<ll> >;
using vll = vector<ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}

ll fact[maxs];
ll ifact[maxs];

void pre(){

    fact[0] = ifact[0] = 1;
    for(ll i=1;i<maxs;i++){
        fact[i] = fact[i-1]*i%mod;
        ifact[i] = inv(fact[i]);
    }

}

ll ncr(ll n,ll r){
    ll tmp  = fact[n]*ifact[n-r]%mod;
    tmp = tmp*ifact[r]%mod;
    return tmp;
}

void solve(){

    ll n,m;
    cin >> n >> m;
    ll ans = ncr(m,n)*fact[n]%mod;
    ll ways = 0;
    ll cur = 1;
    for(ll i=0;i<=n;i++){
        ways += cur*(ncr(n,i)*ncr(m-i,n-i))%mod*fact[n-i]%mod;
        ways %= mod;
        cur = -cur;
    }
    ways %= mod;
    ways += mod;
    ways %= mod;
    ans *= ways;
    ans %= mod;
    cout << ans << endl;

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

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

#define MAX_V 200
#define INF 1000000

typedef tuple<int,int,int,int> Edge; // to,cap,cost,rev
int V;
typedef vector<Edge> Vertex;
vector<Vertex> G(MAX_V);
int dist[MAX_V];
int prev_v[MAX_V], prev_e[MAX_V];

void add_edge(int from, int to, int cap, int cost){
    G[from].emplace_back(to,cap,cost,G[to].size());
    G[to].emplace_back(from,0,-cost,G[from].size()-1);
}

int min_cost_flow(int s, int t, int f){
    int total_cost=0;
    while(f>0){
        fill(dist,dist+V,INF);
        dist[s]=0;
        bool update=true;
        while(update){
            update=false;
            for(int v=0;v<V;v++){
                if(dist[v]==INF) continue;
                for(int i=0;i<G[v].size();i++){
                    auto& e = G[v][i];
                    int to=get<0>(e), cap=get<1>(e), cost=get<2>(e);
                    if(cap>0&&dist[to]>dist[v]+cost){
                        dist[to]=dist[v]+cost;
                        prev_v[to]=v;
                        prev_e[to]=i;
                        update=true;
                    }
                }
            }
        }
        if(dist[t]==INF){
            return -1;
        }
        int d=f;
        for(int v=t;v!=s;v=prev_v[v]){
            d=min(d, get<1>(G[prev_v[v]][prev_e[v]]));
        }
        f-=d;
        total_cost+=d*dist[t];
        for(int v=t;v!=s;v=prev_v[v]){
            auto& e=G[prev_v[v]][prev_e[v]];
            get<1>(e)-=d;
            get<1>(G[v][get<3>(e)])+=d;
        }
    }
    return total_cost;
}

int main(){
    int E,F;
    cin>>V>>E>>F;
    for(int i=0;i<E;i++){
        int u,v,c,d;
        cin>>u>>v>>c>>d;
        add_edge(u,v,c,d);   
    }
    cout<<min_cost_flow(0,V-1,F)<<endl;
}

Measured memory_bytes: 3144
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int a = sc.nextInt();
                int b = sc.nextInt();
                sc.close();
                int yono = 0;
                for(int i = a ; i <= b ; i++){
                        int aa = i / 10000;
                        int bb = (i / 1000) % 10;
                        int dd = (i/ 10) % 10;
                        int ee = i % 10;
                        if(aa == ee && bb == dd)yono++;
                }
                System.out.println(yono);
        }
}
//鶏になれ

Measured memory_bytes: 35156
import itertools
import math

n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
    x[i], y[i] = map(int, input().split())
num = [x for x in range(n)]
permutation = itertools.permutations(num)
total = 0
for turn in permutation:
    for j in range(n - 1):
        total += math.sqrt((x[turn[j + 1]] - x[turn[j]]) ** 2 + (y[turn[j+1]] - y[turn[j]]) ** 2)
ans = total / math.factorial(n)
print(ans)


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

int main() {
	string s;
	getline(cin, s);
	for (int i = 0; i < s.size(); i++) {
		if (s[i] >= 'a' && s[i] <= 'z')
			s[i] += 'A' - 'a';
		else if (s[i] >= 'A' && s[i] <= 'Z')
			s[i] += 'a' - 'A';
	}
	cout << s << endl;
}



Measured memory_bytes: 3156
n = int(input())
d = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = sum(b)
for i in range(n):
    if(i<(n-1) and d[i]==(d[i+1]-1)):
        ans+=c[d[i]-1]
print(ans)

Measured memory_bytes: 3064
x = 0
y = 0
A,B,C,X,Y = map(int,input().split())
if X > Y :
    x = 1
else :
    y = 1
answer = min(X,Y)*min(A+B,C*2) + (max(X,Y)-min(X,Y))*(x*min(A,C*2)+y*min(B,C*2))
print(answer)



Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <set>
using ll = long long;
using namespace std;
#define INF 999999999

int main()
{
    string s;
    cin >> s;
    ll w_c = 0;
    ll ans = 0;
    for (ll i = 0; i < s.size(); i++)
    {
        if (s[i] == 'B')
            continue;
        ans += i - w_c;
        w_c++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
/////////////////////////////////////////////////
//                                             //
//                 _ooOoo_                     //
//                o8888888o                    //
//                88" . "88                    //
//                (| -_- |)                    //
//             ____/`---'\\____                //
//           .'  \|     |//  `.                //
//           /  \|||  :  |||// \               //
//          /  _||||| -:- |||||- \             //
//          |   | \\  -  /// |   |             //
//          | \_|  ''\---/''  |  |             //
//          \  .-\__  `-`  ___/-. /            //
//         ___`. .'  /--.--\  `. . __          //
//      ."" '<  `.___\_<|>_/___.'  >'"".       //
//     | | :  `- \`.;`\ _ /`;.`/ - ` : | |     //
//     \  \ `-.   \_ __\ /__ _/   .-` /  /     //
//=====`-.____`-.___\_____/___.-`____.-'=======//
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^//
//.............................................//
/////////////////////////////////////////////////

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll modn=1000000007;
const ll INF = 0x3f3f3f3f;

ll factinv[2001000];
ll fact[2001000];
ll inv[2001000];

void init(){
    fact[0]=1;
    for(int i=1;i<2001000;i++)fact[i]=fact[i-1]*i%modn;
    inv[1]=1;
    for(ll i=2;i<2001000;i++)
        inv[i] = (modn-modn/i)*inv[modn%i]%modn;
    factinv[0]=1;
    for(int i=1;i<2001000;i++)
        factinv[i]=factinv[i-1]*inv[i]%modn;
}

ll C(int a,int b){
    return fact[a]*factinv[b]%modn*factinv[a-b]%modn;
}

int main(){
    int x,y;
    cin>>x>>y;
    if((x+y)%3 || x<(x+y)/3 || y<(x+y)/3){
        printf("0\n");
        return 0;
    }
    init();
    int sum = x+y;
    x = x-sum/3;
    y = y-sum/3;
    cout<<C(sum/3,x)<<endl;

    return 0;
}
/*
5
1 2 3 4 5
5 3 2 1 4
*/


Measured memory_bytes: 47104
/**
 *      purpose : NIKKEI Programming Contest 2019
 *      author  : kyomukyomupurin
 *      created : 
**/

// in, out
#include <iostream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias templates
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, a, b; cin >> n >> a >> b;

    cout << min(a, b) << " " <<  max(a + b - n, 0) << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define rep(i,a,b) for(int i = (a); i < (b); i++)
using namespace std;

int main() {
  string s;
  cin >> s;
  int l = 0, mx = 0;
  rep(i, 0, s.size()) {
    if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
      l++;
      if(l > mx) {
        mx = l;
      }
    } else {
      l = 0;
    }
  }
  cout << mx;
}

Measured memory_bytes: 256
// by adiforluls
#pragma GCC optimize ("-O2")
#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;
#define FAST         ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll           long long
#define ld           long double
#define pb           push_back
#define mp           make_pair
#define pii          pair<int,int>
#define mii          map<int,int>
#define vi           vector<int>
#define vll          vector<long long>
#define all(a)       (a).begin(),(a).end()
#define clz(a)       __builtin_clz(a) // count leading zeroes
#define ctz(a)       __builtin_ctz(a) // count trailing zeroes
#define popc(a)      __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul          1000000007
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define rfor(i,a,b)  for(int i=a; i>=b; i--)
#define SIZE         1000005
#define F            first
#define S            second
#define mod          998244353
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define endl         '\n'
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

vi fact[200005];
void solve()
{
    int n; cin>>n;
    vi v(n+1);
    rep(i,1,n+1)
    {
        cin>>v[i];
        for(int j=1; j*j<=i; j++)
        {
            if(i%j == 0)
            {
                fact[i].pb(j);
                if(j*j!=i) fact[i].pb(i/j);
            }
        }
    }
    vi check(n+1,0);
    vi ans;
    rfor(i,n,1)
    {
        if(check[i]%2 == v[i]) continue;
        else{
            ans.pb(i);
            check[i]++;
            for(auto j:fact[i])
            {
                check[j]++;
            }
        }
    }
    cout<<(int)ans.size()<<endl;
    for(int i:ans) cout<<i<<" ";

}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  double P=0.0;
  for(int i=1; i<=N; i++) {
    int cnt=0;
    int now=i;
    while(now < K) {
      now*=2;
      cnt++;
    }
    P += pow((double)0.5, (double)cnt);
  }
  printf("%.10f\n", P/N);
  return 0;
}


Measured memory_bytes: 256
// abc059_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

//    print(A);

    ll tmp = 0;
    ll cand1 = 0;
    REP(i, N) {
        tmp += A[i];
//        print(i, A[i], tmp);
        if (tmp == 0 || (i % 2 == 0) != (tmp > 0)){
            ll next_tmp = (i % 2 == 0) ? 1 : -1;
            cand1 += abs(tmp - next_tmp);
            tmp = next_tmp;
        }
//        print("cand1", cand1);
    }

    ll cand2 = 0;
    tmp = 0;
    REP(i, N) {
        tmp += A[i];
//        print(i, A[i], tmp);
        if (tmp == 0 || (i % 2 == 0) != (tmp < 0)){
            ll next_tmp = (i % 2 == 0) ? -1 : 1;
            cand2 += abs(tmp - next_tmp);
            tmp = next_tmp;
        }
//        print("cand2", cand2);
    }

    ll ans = min(cand1, cand2);
    print(ans);

    return 0;
}


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

#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define rrange(v) v.rbegin(), v.rend()
#define mod (int)(1e9 + 7)
#define inf (int)(5e18)
#define N (int)(2e5 + 10)

using namespace std;

void solve() {
#define ff first
#define ss second
	int n; cin >> n;
	vector<pair<int, int>> a(n);
	for (auto &it : a) cin >> it.ff >> it.ss;
	bool is = false;
	for (int i = 0; i < n - 2; i++) {
		bool can = true;
		for (int j = i; j < i + 3; j++)
			can &= (a[j].ff == a[j].ss);
		is |= can;
	}

	cout << (is ? "Yes" : "No") << endl;
}
// Remember to clear the global containers



// Got stuck and want to leave ? look at the bottom once..
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
	// cin >> t_c;
	while (t_c--)
		solve();
}
/* Come on Dude .. Dont get up until u get the solution
 * Giving up not gonna help ryt ? So get ur lazy ass to code already
 * You can do it ... Stay Calm and Dont Panic :)
 */


Measured memory_bytes: 3656
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;

int main(){
	long long a,b,c,d;
	scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
	printf("%lf %d\n", (a*b)/2.0, (c*2==a&&d*2==b)?1:0);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	char c;
	long long int a,b;
	scanf("%d %c %d",&a,&c,&b);
	if(c=='+'){
		printf("%d\n",a+b);
	}
	else{
		printf("%d\n",a-b);
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >>b >> c;
  if((a==b && b != c) ||(a==c&&b!=c)||(b==c&&a!=b)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
typedef long long ll;
const int N=1e5+10;
int f[N],d[N],n,m,u,v,fa[N],cnt,x,y,a[N];
vector<int> G[N];ll ans;int vis[N];
void dfs(int u){
    f[u]=d[u]&1?1:-1;vis[u]=1;
    for(int &v:G[u]) if(v^fa[u])
        if(vis[v]) x=u,y=v;
        else d[v]=d[u]+1,fa[v]=u,dfs(v),f[u]+=f[v];
}
int main(){
    scanf("%d%d",&n,&m);
    rep(i,1,m) scanf("%d%d",&u,&v),G[u].push_back(v),G[v].push_back(u);
    dfs(1);
    if(m==n-1){
        if(f[1]) return puts("-1"),0;
        rep(i,1,n) ans+=abs(f[i]);
    }
    else if(!((d[x]^d[y])&1)){
        if(f[1]&1) return puts("-1"),0;int t=f[1]>>1;
        for(;x;x=fa[x]) f[x]-=t;ans=abs(t);
        for(;y;y=fa[y]) f[y]-=t;
        rep(i,1,n) ans+=abs(f[i]);
    }
    else{
        if(f[1]) return puts("-1"),0;
        if(d[x]<d[y]) swap(x,y);
        for(;x^y;x=fa[x]) a[++cnt]=f[x],vis[x]=2;
        a[++cnt]=0;sort(a+1,a+cnt+1);ans=abs(a[(cnt+1)>>1]);
        rep(i,1,n)
            if(vis[i]==2) ans+=abs(f[i]-a[(cnt+1)>>1]);
            else ans+=abs(f[i]);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 17536
#!/usr/bin/env python3
import sys

def solve(N: int, R: int):
    if N < 10:
        print(R+(100*(10-N)))
    else:
        print(R)

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    solve(N, R)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
def abc168_a():
    N = int(input())
    hon = [2,4,5,7,9]
    pon = [0,1,6,8]
    if N % 10 in hon: ans = 'hon'
    elif N % 10 in pon: ans = 'pon'
    else: ans = 'bon'
    print(ans)

abc168_a()

Measured memory_bytes: 9052
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int N; cin>>N;
  ll ans=0;
  ll a[100001],b[100001],c[100001];
  REP(i,N){
    cin>>a[i];
  }
  REP(i,N){
    cin>>b[i];
  }
  REP(i,N){
    cin>>c[i];
  }
  sort(a,a+N);
  // sort(b,b+N);
  sort(c,c+N);
  // b固定
  for(int i=0; i<N; i++) {
    ll t1=lower_bound(a,a+N,b[i])-a;
    ll t2=upper_bound(c,c+N,b[i])-c;
    // cout<<t1<<" "<<t2<<"\n";
    ans+=t1*(N-t2);
  }
  // // debug
  // int t1=lower_bound(a,a+N,4)-a;
  // int t2=upper_bound(c,c+N,4)-c
  // cout<<t1<<" "<<N-t2<<"\n";

  P(ans);
  return 0;
}


Measured memory_bytes: 2560
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  char c;cin>>c;
  if(c<='Z')cout<<'A'<<endl;
  else cout<<'a'<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    double n, m;
    int d;
    cin >> n >> m >> d;
    double per;
    if (d == 0) {
        per = 1 / n * (m - 1);
    } else {
        per = 2 * (n - d) / n / n * (m - 1);
    }
    cout << fixed << setprecision(10) << per << "\n";
}


Measured memory_bytes: 3788
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 3002;
const int mo = 1e9 + 7;

string s;
int n, ans, f[maxn][maxn];

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
    cin >> n >> s;

    f[0][0] = 1;
    for (int i = 1; i < n; ++i) {
        if (s[i-1] == '<') {
            for (int j = 1; j <= i; ++j)
                f[i][j] = (f[i][j-1] + f[i-1][j-1]) % mo;
        } else {
            for (int j = i-1; j >= 0; --j)
                f[i][j] = (f[i][j+1] + f[i-1][j]) % mo;
        }
    }

    for (int j = 0; j <= n; ++j)
        ans = (ans + f[n-1][j]) % mo;

    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 34176
#include <bits/stdc++.h>
using namespace std;
int a[2000005];
int main()
{
   //freopen("t5.in","r",stdin);
   //freopen("t5.out","w",stdout);
   //ios::sync_with_stdio(false);
   //cin.tie(0); cout.tie(0);
    int i,j,m;
    long long n;cin>>n;
    long long sum=n/500*1000;
    n=n%500;
    n-=n%5;
    sum+=n;
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] arg){
      Scanner sc=new Scanner(System.in);
      int n=sc.nextInt(); 
      int x=sc.nextInt();
      int y=sc.nextInt();
      int dp[][]=new int[n+1][n+1];
      dp[x][y]=1;
      for(int i=1;i<n;i++){
          for(int j=i+1;j<=n;j++){
              dp[i][j]=Math.min((j-i),Math.max(Integer.MIN_VALUE,Math.abs(i-x)+Math.abs(y-j)+1));
          }
      }
      int ans[]=new int[n];
      for(int i=1;i<n;i++){
          for(int j=i+1;j<=n;j++){
              ans[dp[i][j]]++;
          }
      }
      
      for(int i=1;i<n;i++){
        System.out.println(ans[i]);
      }
    }
}

Measured memory_bytes: 53716
def main():
    from itertools import dropwhile

    S = input()
    it = dropwhile(lambda char: char == '9', reversed(S))
    # 末尾から見て9以外の数字が現れたら、以降をiterate

    len_ = len(list(it))
    if len_ <= 1:
        print(sum(map(int, S)))
    else:
        head = S[0]
        body = str(int(head) - 1)
        body += '9' * (len(S) - 1)

        print(sum(map(int, body)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int a = h1 * 60 + m1;
	int b = h2 * 60 + m2;
	cout << (b - a - k) << '\n';
}


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

long long arr[1000010];
int n;

void init() {
	arr[0]=0;
  	for(int i=1; i<=1000000; i++) {
      	if(i%3==0 or i%5==0) arr[i]=arr[i-1];
      	else arr[i]=arr[i-1]+i;
    }
  	return;
}

int main() {
	init();
  	cin>>n;
  	cout<<arr[n]<<"\n";
  	return 0;
}

Measured memory_bytes: 11440
#include <iostream>
#include<cstdio>
#include<algorithm>
typedef long  long ll;
using namespace std;
const int N = 10;
int e[N][N];
int main()
{  // freopen("in.txt", "r", stdin);
    int h,w;cin>>h>>w;
    for(int i = 0;i<N;i++){
        for(int j = 0;j<N;j++){
            cin>>e[i][j];
        }
    }
    for(int k = 0;k<N;k++){
        for(int i =0;i<N;i++){
            for(int j =0;j<N;j++){
                e[i][j] = min(e[i][j] , e[i][k] + e[k][j]);
            }
        }
    }
    ll ans = 0;
    for(int i =0;i<h;i++){
        for(int j =0;j<w;j++){
            int x;cin>>x;
            if(x != -1){
                ans += e[x][1];
            }
        }
    }

    cout<<ans<<endl;


     return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f first
#define se second
#define pb push_back
#define pf push_front
#define eb emplace_back
#define emp emplace
#define ins insert
#define sz(s) (int)s.size()
#define rep(i,a,b) for( int i=a;i<b;i++)
#define repr(i,a,b) for( int i=a;i>=b;i--)
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(n,m) memset(n,m,sizeof(n))
#define ii pair<int,int>
#define iii tuple<int, int, int>
#define si set<int>
#define vi vector<int>
#define vii vector<ii>
#define mi map<int,int>
#define lb lower_bound
#define ub upper_bound
#define present(s,x) (s.find(x) != s.end())
#define ford(container, it) for(auto it:container)
#define fors(container, it, a, b) for(auto it = a; it != b; it++)
#define Anurag_Gupta ios_base::sync_with_stdio(0);
#define IIIT_ALLD cin.tie(0);cout.tie(0);
#define mod 987654319
#define EPSILON 1e-9
#define PI acos(-1)
#define inf 1e17
#define int long long
#define debug(a) cerr<<#a<<": ";for(auto i:a)cerr<<i<<" ";cerr<<'\n';
#define trace(a) cerr<<#a<<": "<<a<<"\n"
#define gcd(a,b) __gcd(a,b)
using namespace std;
int add(int a, int b, int c){int res=a+b;return(res>=c?res-c:res);}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
int mul(int a, int b, int c){int res=(int)a*b;return(res>=c?res%c:res);}
template<typename T>T power(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template<typename T>T mdpower(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
/*------------------------------------------------------------------------------------------------------------------*/

int32_t main()
{
    Anurag_Gupta
    IIIT_ALLD
 
   
    
    string s,t;
    cin>>s>>t;

    int n = s.size();

    cout<<((t.substr(0,n)==s)?"Yes\n":"No\n")<<"\n";
 
 






 
#ifndef LOCAL_DEFINE
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}


Measured memory_bytes: 3768
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    ll cnt=0;
    ll r=0;
    ll g=0;
    ll b=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            r++;
        }else if(s[i]=='G'){
            g++;
        }else{
            b++;
        }
    }
    cnt += r*g*b;
    for(int k=1;k<=(n-1)/2;k++){
        for(int i=0;i<n-2*k;i++){
            char s1 = s[i];
            char s2 = s[i+k];
            char s3 = s[i+2*k];
            if(s1!=s2 && s2!=s3 && s1!=s3) cnt--;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
using namespace std;
int main() {
		int n;
		cin >> n;
		pair<pair<string, int>, int> x[101];
		for(int i = 0; i < n;++i) {
			string s;
			int p;
			cin >> s >> p;
			p *= -1;
			x[i] = make_pair(make_pair(s, p), i + 1);
		}
		sort(x, x + n);
		for(int i = 0; i < n; ++i)
			cout << x[i].second << endl;
}

Measured memory_bytes: 3652