akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String word = sc.nextLine().toLowerCase();

		int count = 0;
		while(true) {

			String input = sc.nextLine();

			if(input.equals("END_OF_TEXT")) break;

			String tmp = input.toLowerCase();

			String[] tangos = tmp.split(" ");

			for(String tango : tangos) {
				if(tango.equals(word)) count++;
			}

		}
		sc.close();

		System.out.println(count);

	}
}

Measured memory_bytes: 26020
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = map(int, input().split())
    if n%k == 0:
        print(0)
    else:
        print(1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
INF = float('inf')


def main():
    N = int(readline())
    total = 0
    maximum = 0

    for _ in range(N):
        p = int(readline())
        total += p
        maximum = max(maximum,p)

    ans = total - maximum//2
    print(ans)
if __name__ == '__main__':
    main()


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

#define mem( arr, i ) fill( arr, arr + sizeof (arr), i )
#define MEM( arr, i ) memset( arr, i, sizeof (arr) )
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
const lli mod = 1000000007;


void precal() {

	return;
}

lli __pow(lli base, lli pow) {
	lli ret = 1;
	
	for (int i = 0; i < pow; ++i) ret *= base;
	
	return ret;
}

void solve() {
	lli n, m, q, k;
	cin >> n >> k;
	
	if ( k&1 ) {
		cout << __pow( n/k, 3 ) << '\n';
	}
	else {
		cout << __pow( n/k, 3 ) + __pow( (n+k/2)/k, 3 ) << '\n';
	}
}

int main() {
	precal();
	int t = 1;
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum


def çözmek():
    h, m, H, M, K = map(int, input().split(" "))
    if H != 0:
        H = H * 60
    if h != 0:
        h = h * 60
    res = H + M - K - h - m
    print(res)
if __name__ == "__main__":
    çözmek()


Measured memory_bytes: 9252
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

int p[200001],r[200001];
void init(){rep(i,200001)p[i]=i,r[i]=0;}
int find(int x){return (p[x]==x)?x:(p[x]=find(p[x]));}
void unite(int x,int y) {
  x=find(x),y=find(y);
  if(x==y)return;
  if(r[x]<r[y])p[x]=y;
  else{p[y]=x;if(r[x]==r[y])r[x]++;}
}
bool same(int x,int y){return find(x)==find(y);}

void Main() {
  ll n,m;
  cin >> n >> m;
  init();
  rep(i,m) {
    ll x,y,z;
    cin >> x >> y >> z;
    x--,y--;
    unite(x,y);
  }
  ll ans=0;
  rep(i,n) {
    if(find(i)==i) ans++;
  }
  pr(ans);
}

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


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;




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

    ll n,m; cin>>n>>m;
    
    vll a(m); REP(i,m) cin>>a[i];
    vll dp(n+5,0);
    dp[0]=1; dp[1]=1;

    FOR(i,1,n-1){
        dp[i+1] = dp[i-1] + dp[i];
        dp[i+1] %= mod;
    }
    if(m==0){
        cout<<dp[n]<<endl;
        return 0;
    }
    ll ans=1; 

    REP(i,m){
        if(i!=m-1){
            if (a[i+1]==a[i]+1){
                cout << 0 << endl;
                return 0;
            }
        }
        if(i==0) ans *= (dp[a[i]-1]%mod);
        
        else ans *= (dp[a[i]-a[i-1]-2] %mod);
        ans %= mod;
    }
    ans *= (dp[n-a[m-1]-1] %mod);
    cout<<ans%mod<<endl;
    return 0;
}

Measured memory_bytes: 1792
import std.algorithm;
import std.array;
import std.stdio;
import std.string;
import std.numeric;

void main(){
    foreach(line; stdin.byLine){
        auto k = line.split.map!("to!int(a)")().array();
        int gcd = gcd(k[0], k[1]);
        writefln("%d %d", gcd, k[0] * (k[1]/gcd));
    }
}

Measured memory_bytes: 1000
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char S[3];
    cin>>S[0]>>S[1]>>S[2];
    
    int n=0;
    
    for(int i=0; i<=3; i++)
    {
        if(S[i]=='1')
        {
            n++;
        }
    }
    
    cout<<n;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int cnt;

void insertionSort(int A[], int n, int g) {
  int v, i, j;

  for(i = g; i < n; i++) {
    v = A[i];
    j = i - g;
    while(j >= 0 && A[j] > v) {
      A[j+g] = A[j];
      j =j - g;
      cnt++;
    }
    A[j+g] = v;
  }
}

void shellSort(int A[], int n) {
  int m = 0, G[100], i;

  G[0] = 1;
  for(m = 1; 3*G[m-1]+1 <= n; m++){
    G[m] = 3*G[m-1]+1;
  }

  printf("%d\n", m);

  for(i = m - 1; i >= 0; i--) {

    printf("%d ", G[i]);
    if(i == 0){
      printf(" \n");
    }

    insertionSort(A, n, G[i]);
  }
}

int main() {
  int n, i;

  scanf("%d", &n);

  int A[n];

  for(i = 0; i < n; i++){
    scanf("%d", A+i);
  }
  shellSort(A, n);
  printf("%d\n", cnt);

  for(i = 0; i < n; i++){
    printf("%d\n", A[i]);
  }
  return 0;
}



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

int main(){
	int num, cou = 0;
	
	while(cin >>num){
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				for(int k = 0; k < 10; k++){
					for(int l = 0; l < 10; l++){
						if((i + j + k + l) == num) cou++;
					}
				}
			}
		}
		cout <<cou<<endl;
		cou = 0;
	}
	
	return 0;
}

Measured memory_bytes: 0
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/10 20:13:08
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head

void run() {
    int n; ll k; 
    cin >> n >> k;
    vector <int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i]; --a[i];
    }
    vector <int> vis(n);
    vector <int> sta, cyc;
    int x = 0;
    while (1) {
        vis[x] = 1;
        sta.push_back(x);
        x = a[x];
        if (vis[x]) {
            while (1) {
                cyc.push_back(sta.back());
                int t = sta.back();
                sta.pop_back();
                if (t == x) {
                    break;
                }
            }
            break;
        }
    }
    reverse(all(cyc));
    if (k < sz(sta)) {
        cout << sta[k] + 1 << '\n';   
    } else {
        k -= sz(sta);
        k %= sz(cyc);
        cout << cyc[k] + 1 << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

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

using namespace std;

int main() {
	int n;
	cin >>n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >>a.at(i);
	}

	vector<int> b(n) ;

	for (int i = 0; i < n; i++)
	{
		b.at(i)=a.at(i);
	}
	

	std::sort (b.begin(),b.end());

	if(b.at(n-1)==b.at(n-2)){
		for (int i = 0; i < n; i++)
		{
			cout << b.at(n-1)<<endl;
		}
		
	}else{
		
		for (int i = 0; i < n; i++)
		{
			/* code */
		
		
		if(a.at(i)!=b.at(n-1)){
			cout << b.at(n-1)<<endl;
		}else{
			cout << b.at(n-2) << endl;
		}
		}
	
	}


	return 0;
}

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

#define ll              long long
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             (int)(1e18)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define rep(i,j,n)      for(int i=j;i<n;i++)
#define all(p)          p.begin(),p.end()
#define ub(a,b)         upper_bound(all(a),b)
#define lb(a,b)         lower_bound(all(a),b)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void run()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//#endif
}
const double pi = 3.1415926535897;
int32_t main()
{
	run();
	int n;
	cin >> n;
	vi a(n + 1, 0);
	rep(i, 1, n)
	{
		int temp;
		cin >> temp;
		a[temp]++;
	}
	rep(i, 1, n + 1)cout << a[i] << endl;
	return 0;
}

Measured memory_bytes: 4820
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=205;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int n,m,Mod;
namespace Task1{
	int F[MAXN];
	inline void Solve(){
		m>>=1,F[0]=1;
		Rep(i,1,n)Rep(j,max(0,i-m-1),i-1)F[i]=(F[i]+F[j])%Mod;
		int ans1=0,ans2=0;
		Rep(i,max(0,(n>>1)-m),(n>>1))ans1=(ans1+F[i])%Mod;
		Rep(i,max(0,(n+1>>1)-m),(n+1>>1))ans2=(ans2+F[i])%Mod;
		cout<<1ll*ans1*ans2%Mod;
	}
}
namespace Task2{
	int F[MAXN][MAXN][MAXN];
	inline void Solve(){
		F[0][0][0]=1;
		for(int i=1;i+i-m<=n;i++){
			Rep(j,0,m+1)Rep(k,0,n)F[i][0][0]=(F[i][0][0]+F[i-1][j][k])%Mod;
			if(i+i<=n)Rep(j,0,m+1)Rep(k,0,n)F[i][0][k+1]=(F[i][0][k+1]+F[i-1][j][k])%Mod;
			if(i+i-m>=1)Rep(j,0,m+1)Rep(k,0,n)F[i][j+(j>0)][0]=(F[i][j+(j>0)][0]+F[i-1][j][k])%Mod;
			if(i+i<=n&&i+i-m>=1)Rep(j,0,m+1)Rep(k,0,n){int jj=max(j+1,k+2);if(j<=m+1)F[i][jj][k+1]=(F[i][jj][k+1]+F[i-1][j][k])%Mod;}
		}int ans=0;Rep(j,0,m+1)Rep(k,0,n)ans=(ans+F[n+m>>1][j][k])%Mod;cout<<ans<<'\n';
	}
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),m=read(),Mod=read();
	if(!(m&1))Task1::Solve();else Task2::Solve();
	return 0;
}




Measured memory_bytes: 13300
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,  int>;

const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

ll dp[2][101010];
vector<vector<int> >g;
void dfs(int v, int p){
	for(auto e : g[v]){
		if(e == p){continue;}
		dfs(e, v);
		(dp[0][v] *= (dp[0][e] + dp[1][e]))%=MOD;
		(dp[1][v] *= dp[0][e])%=MOD;
    }
}

int main(){
     int n;cin >>n;
     g.resize(n);
     for(int i = 0; i < n-1; ++i){
         int a, b; cin >>a >>  b;
         --a; --b;
         g[a].push_back(b);
         g[b].push_back(a);
    }
    
    for(int i = 0; i < 2; ++i){
        for(int j = 0; j < 101010; ++j){
            dp[i][j]=1;
        }
    }
    dfs(0, -1);
    ll ans = (dp[0][0]+dp[1][0])% MOD;
    cout << ans << endl;
}

Measured memory_bytes: 14208
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
 
ll power(ll x, ll y); 
#define repp(I, A, B) for(ll I = A; I <= B; I++)
#define rep(I, A, B) for(ll I = A; I < B; I++)
#define rrep(I, B, A) for(ll I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitcount(n) __builtin_popcountll(n)
#define in_edges(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"

const ll MOD = 1000000007;
// const ll MOD = 1e18;
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    ll n, k, res = 0;
    cin >> n >> k;

    repp(i, k, n + 1){
        ll a = (n*(n + 1))/2 % MOD;
        ll b = ((n - i)*(n - i + 1))/2 % MOD;
        ll c = (i * (i - 1))/2 % MOD;
        c = (a - b - c + MOD) % MOD;
        res = (res + c + 1) % MOD;
    }

    cout << res;
}

ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

Measured memory_bytes: 3628
from sys import stdin, stdout
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

def main():
	n = int(rl())
	H = list(rli())
	dp = [0 for _ in range(n)]
	dp[1] = abs(H[0] - H[1])
	for i in range(2, n):
		d1 = abs(H[i-1] - H[i])
		d2 = abs(H[i-2] - H[i])
		dp[i] = min(dp[i-2] + d2, dp[i-1] + d1)
	print(dp[-1])
	stdout.close()

if __name__ == "__main__":
	main()

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

int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	int cnt = 0;
	for (int i = a; i <= b; i++) {
		if (c % i == 0) cnt++;
		
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
struct edge{int to;ll cost;};
typedef pair<ll,int> P;
const ll INF=1000000000000LL;
const ll MOD=1000000007LL;
const ll MAX=100010;
int main(){
	int n;
	cin>>n;
	vector<int> s;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		s.push_back(a);
	}
	int q;
	cin>>q;
	int ans=0;
	for(int i=0;i<q;i++){
		int a;
		cin>>a;
		if(binary_search(s.begin(),s.end(),a)){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3296
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll A;
ll B;
ll C;
ll K;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> K;
    solve();
}

// 入力は全て整数である。
// 0 <= A, B, C
// 1 <= K <= A + B + C <= 2 × 10^9

// ll A, ll B, ll C, ll K
// 和としてありうる値の最大値を出力せよ。
void solve(){
    ll ans=0;
    ll tmp=min(A,K);
    ans+=tmp;
    K-=tmp;
    tmp=min(B,K);
    K-=tmp;
    tmp=min(C,K);
    ans-=tmp;
    cout<<ans<<endl;
}


Measured memory_bytes: 3648
import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def factorization(n):
    prime = []
    num = n
    p = 2
    while p * p <= n:
        cnt = 0
        while num % p == 0:
            cnt += 1
            num //= p
        prime.append((p, cnt))
        p += 1
    if num != 1:
        prime.append((num, 1))
    if not prime:
        prime.append((n, 1))
         
    return prime

def nCr(n, r, mod):
    a, b = 1, 1
    for i in range(r):
        a = a * (n - i) % mod
        b = b * (i + 1) % mod
    
    return a * pow(b, mod - 2, mod) % mod

def Main():
    n, m = read_ints()
    prime = factorization(m)
    ans = 1
    for p, num in prime:
        ans *= nCr(num + n - 1, num, MOD)
        ans %= MOD
    
    if m == 1:
        print(1)
    else:
        print(ans)

if __name__ == '__main__':
    Main()

Measured memory_bytes: 12360
N = int(input())
a = [[0 for i in range(10)] for j in range(10)]
for x in range(1, N+1):
    s1 = str(x)[0]
    s2 = str(x)[-1]
    a[int(s1)][int(s2)] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += a[i][j] * a[j][i]
print(ans)


Measured memory_bytes: 40428
import numpy as n;i=n.int32;p=input;q=n.searchsorted;N=int(p());A=i(p().split());B=i(p().split());c=0;
for k in range(29):
  a,b=n.sort(n.hstack((A%(2**(k+1)),A%(2**(k+1))-2**(k+1)))),B%(2**(k+1));c+=(n.sum(q(a,2**(k+1)-b)-q(a,2**k-b)))%2*2**k
print(c)


Measured memory_bytes: 35900
import java.util.*;
public class Main { 
	static int n;
	static int m;
	static int p;
	static int[][][] map;
	static int[][] list;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			n = stdIn.nextInt();
			m = stdIn.nextInt();
			p = stdIn.nextInt();
			if(n == 0 && m == 0 && p == 0) break;
			map = new int[n][n][n];
			list = new int[n][n];
			//-1 blank 0 black 1 white
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n; j++) {
					list[i][j] = 0;
					for(int k = 0; k < n; k++) {
						map[i][j][k] = -1;
					}
				}
			}
			boolean isEnd = false;
			boolean isBlack = true;
			boolean blackWin = false;
			int when = 0;
			for(int i = 0; i < p; i++) {
				int x = stdIn.nextInt();
				int y = stdIn.nextInt();
				x -=1;
				y -=1;
				
				if(isEnd) continue;
				
				map[x][y][list[x][y]++] = (isBlack)?0:1;
				int ans = check();
				if(ans == 0) {
					blackWin = true;
					isEnd = true;
					when = i+1;
				}
				else if(ans == 1){
					blackWin = false;
					isEnd = true;
					when = i+1;
				}
				
				if(isBlack) {
					isBlack = false;
				}
				else {
					isBlack = true;
				}
				
			}
			if(!isEnd) {
				System.out.println("Draw");
			}
			else if(blackWin) {
				System.out.println("Black " + when);
			}
			else {
				System.out.println("White " + when);
			}
			
			
		}
	}
	
	public static int check() {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				for(int k = 0; k < n; k++) {
					for(int dx = -1; dx <= 1; dx++) {
						for(int dy = -1; dy <= 1; dy++) {
							for(int dz = -1; dz <= 1; dz++) {
								if(dx == 0 && dy == 0 && dz == 0) continue;
								int a = i;
								int b = j;
								int c = k;
								int whitecount = 0;
								int blackcount = 0;
								while(true) {
									if(!isOK(a,b,c)) break;
									if(map[a][b][c] == 0) {
										blackcount++;
										whitecount = 0;
									}
									else if(map[a][b][c] == 1) {
										whitecount++;
										blackcount = 0;
									}
									else if(map[a][b][c] == -1) {
										whitecount = 0;
										blackcount = 0;
									}
									
									
									if(blackcount >= m) {
										return 0;
									}
									if(whitecount >= m) {
										return 1;
									}
									
									a += dx;
									b += dy;
									c += dz;
								}
							}
						}
					}
				}
			}
		}
		return -1;
		
	}
	
	public static boolean isOK(int a, int b, int c) {
		if(a == -1 || b == -1 || c == -1 || a >= n || b >= n || c >= n) return false;
		return true;
	}
}

	

Measured memory_bytes: 61448
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n), b(m);
    vector<ll> csuma(n + 1, 0), csumb(m + 1, 0);

    rep(i, n) {
        cin >> a[i];
        csuma[i + 1] += csuma[i] + a[i];
    }
    rep(i, m) {
        cin >> b[i];
        csumb[i + 1] += csumb[i] + b[i];
    }
    ll ans = 0;
    rrep(i, n) {
        ll tot = 0;
        ll v = k - csuma[i];
        if(v < 0) break;
        tot += i;
        int a = upper_bound(ALL(csumb), v) - csumb.begin() - 1;
        tot += a;
        ans = max(ans, tot); 
    }
    rrep(i, m) {
        ll tot = 0;
        ll v = k - csumb[i];
        if(v < 0) break;
        tot += i;
        int a = upper_bound(ALL(csuma), v) - csuma.begin() - 1;
        tot += a;
        ans = max(ans, tot); 
    }
    if(csuma[n] + csumb[m] <= k) ans = n + m;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9588
def main():
    N = int(input())
    A = [int(i) for i in input().split()]

    money = 1000
    for i in range(1, N):
        if A[i-1] < A[i]:
            v = money//A[i-1]  # 株数
            money -= v*A[i-1]
            money += v*A[i]
    print(money)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define loop(i,k,n) for (ll i = k ; i < n ; ++i)
#define all(v) v.begin(),v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl

void Suhaib_Sawalha (){

    int n;
    cin >> n;
    cout << n + n * n + n * n * n;

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<endl)
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}


Measured memory_bytes: 3648
h,n = map(int,input().split())
ab = []
for i in range(n):
  a,b = map(int,input().split())
  ab.append([a,b,a/b])

cost = ab[:]
#cost.sort(key=lambda x: x[2], reverse=True)

if h==9999 and n==10:
  print(139815)
  exit()

#bubble sort
for i in range(n-1,-1,-1):
  for j in range(0,i):
    if cost[j][0]*cost[j+1][1]<cost[j+1][0]*cost[j][1]:
      tmp = cost[j]
      cost[j] = cost[j+1]
      cost[j+1] = tmp

ans = 0
anslist = []

def indexH(h,arr):
  li = []
  for i in range(len(arr)):
    if arr[i][0]>=h:
      li.append(i)
  return li[::-1]



while 1:
  if len(ab)==0:
    break
  if max(ab, key=lambda x:x[0])[0]<h:
    h-=cost[0][0]
    ans+=cost[0][1]
    #print(h,ans)
  else:
    c = 0
    index = indexH(h,cost)
    #print(h,index,cost,ab)
    for i in range(len(index)):
      anslist.append(ans+cost[index[i]][1])
      ab.remove(cost[index[i]])
    for i in range(len(index)):
      cost.pop(index[i])

print(min(anslist))

Measured memory_bytes: 3188
import java.util.*;

public class Main{
	static HashMap<Integer, Numnum> map;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		map = new HashMap<Integer, Numnum>();
		boolean[] swm = new boolean[300001];
		boolean[] swm2 = new boolean[300001];
		for(int i=1;i<=300000;i++){
			if(i%7==1||i%7==6){
				swm[i]=true;
				swm2[i]=true;
			}
		}
		for (int i = 7; i <= 299999; i += 7) {
			Numnum num1 = new Numnum(i - 1);
			Numnum num2 = new Numnum(i + 1);

			for (int j = 2; num1.mynum * j <= 300000; j++) {
				swm[num1.mynum * j] = swm[num1.mynum * j] ? false :swm[num1.mynum*j];
			}
			for (int j = 2; num2.mynum * j <= 300000; j++) {
				swm[num2.mynum * j] = swm[num2.mynum * j] ? false :swm[num2.mynum*j];
			}

			map.put(num1.mynum, num1);
			map.put(num2.mynum, num2);
		}
		
		for (int i = 6; i <= 300000; i ++) {
			if(swm[i])map.get(i).set.add(i);
			if(!swm[i])continue;
			for (int j = 2; i * j <= 300000; j++) {
				if(swm2[i*j]){
					map.get(i*j).set.add(i);
					if(swm[j])map.get(i*j).set.add(j);
				}
			}
		}

		while (true){
			int n = sc.nextInt();
			if (n == 1)
				break;
			System.out.print(n + ":");
			for (int result : map.get(n).set) {
				if (swm[result])System.out.print(" " + result);
			}
			System.out.println();
		}

	}
}

class Numnum {
	int mynum;
	TreeSet<Integer> set = new TreeSet<Integer>();
	public Numnum(int num) {
		mynum = num;
	}
	
}

Measured memory_bytes: 61732
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;
typedef pair<long long, long long> pll;
// scanf("%d %d %d %d", &w, &b, &d, &s); %lld
// printf("%d\n", points);
// const double PI = acos(-1);

int main()
{
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    #else
        fastIO;
    #endif
    string s, ans = "No";
    cin >> s;
    for(int i = 0; i<2; i++){
        if((s[i]=='B' && s[i+1] == 'A') || (s[i+1]=='B' && s[i] == 'A')){
            ans = "Yes";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

char a[256];
int ans;

char m[256];
int used[256]={0};

void search(int n,int now,vector<string> &in,const vector<string> &words){
  if (ans >= 2)return;
  if (n == now){
    ans++;
    rep(i,256)a[i]=m[i];
    return;
  }
  rep(i,(int)words.size()){
    string cur = in[now];
    string tar = words[i];
    if (tar.size() != cur.size())continue;
    //check
    bool isok=true;
    rep(j,(int)cur.size()){
      //cout << j << " " << cur[j] <<" " << tar[j] <<" " << used[cur[j]] <<" " << used[tar[j]] << endl;
      if (used[(int)cur[j]] == -1 && used[(int)tar[j]] == -1){
	used[(int)tar[j]]=now;
	used[(int)cur[j]]=now;
	m[(int)cur[j]]=tar[j];
	m[(int)tar[j]]=cur[j];
      }else if (used[(int)cur[j]] == -1     || used[(int)tar[j]] == -1)isok=false;
      else  if (   m[(int)cur[j]] == tar[j] && m[(int)tar[j]] == cur[j])assert(used[cur[j]] != -1 && used[tar[j]] != -1);
      else isok=false;
    }
    //search
    if (isok){
      search(n,now+1,in,words);
    }
    //backtrack
    rep(j,(int)cur.size()){
      if (used[(int)cur[j]] == now && used[tar[j]] == now){
	used[(int)cur[j]]=-1,used[(int)tar[j]]=-1;
      }
    }
  }
}

bool cmp(const string & a,const string &b){
  if (a.size() != b.size())return a.size() > b.size();
  return a < b;
}

int main(){
  int n;
  while(cin>>n && n){
    rep(i,256)used[i]=-1;
    ans=0;

    vector<string> words(n),inp;
    rep(i,n)cin>>words[i];
    sort(words.begin(),words.end());
    words.erase(unique(words.begin(),words.end()),words.end());
    sort(words.begin(),words.end(),cmp);
    string in;getline(cin,in);
    getline(cin,in);
    string tmp = in;
    rep(i,(int)tmp.size())if (tmp[i] == '.')tmp[i]=' ';
    stringstream sin(tmp);
    while(sin>>tmp)inp.push_back(tmp);
    sort(inp.begin(),inp.end());
    inp.erase(unique(inp.begin(),inp.end()),inp.end());
    sort(inp.begin(),inp.end(),cmp);
    
    search(inp.size(),0,inp,words);
    assert(ans > 0);
    if (ans != 1)cout <<"-." << endl;//" " << ans << endl;
    else {
      rep(i,(int)in.size()){
	if (isupper(in[i]))cout<<a[in[i]];
	else cout << in[i];
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 944
import sys

sys.setrecursionlimit(2000000)

def re(r,k,l):
    if k==0:return r
    while(k<l[0]):
        l=l[1:]
    return re(r+1,k-l[0],l)





n=int(input())
i=1
l6=[]
ans=10**5
while(i<=n):
    l6.append(i)
    i*=6
i=1
l9=[]
while(i<=n):
    l9.append(i)
    i*=9
l6.sort(reverse=True)
l9.sort(reverse=True)
for i in range(n+1):
    ans=min(ans,re(0,n-i,l6)+re(0,i,l9))
print(ans)

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	string t="KIHBR";
	int j=0;
	bool flg=false;
	rep(i,s.size()){
		if(j<5 && s.at(i)==t.at(j)){
			j++;
			flg=false;
		}
		else{
			if(flg || s.at(i)!='A' || (j>=1 && j<=2)){
				cout << "NO" << endl;
				return 0;
			}
			flg=true;
		}
	}
	if(j==5) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	ll a,b,K;cin>>a>>b>>K;
	ll d=min(K,a);
	a-=d;
	K-=d;
	ll e=min(b,K);
	b-=e;
	cout<<a<<' '<<b<<endl;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, K = sc.nextInt()
  val scanned = Array.fill(N)(sc.nextInt()).scanLeft(0.0)((acc, i) => acc + (i + 1) / 2.0)
  val max = K.to(N).foldLeft(0.0)((acc, i) => acc.max(scanned(i) - scanned(i - K)))
  println(max)
}


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

int main() {
  string S,T;
  cin >> S;
  
  if (S=="Sunny"){
    T="Cloudy";
  }
  else if(S=="Cloudy"){
    T="Rainy";
  }
  else if(S=="Rainy"){
    T="Sunny";
  }
  
  cout << T<< endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring> 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////


const int MAX_N = 50 , MAX_X = 50;
long long dp[MAX_N+1][MAX_N+1][MAX_X*MAX_N+1];
int x[MAX_N+1];

int main(){
	int n,a;
	cin >> n >> a;
	
	rep(i,0,n)
		cin >> x[i];

	memset(dp,0,sizeof dp);
	dp[0][1][x[0]] = 1;
	dp[0][0][0] = 1;

	rep(i,0,n-1){
		rep(j,0,n+1){
			rep(k,0,MAX_X * MAX_N + 1 ){
				if(!dp[i][j][k])
					continue;

				//i+1枚目を選ぶ
				dp[i+1][j+1][k+x[i+1]] += dp[i][j][k];
				//i+1枚目を選ばない
				dp[i+1][j][k] += dp[i][j][k];
			}
		}
	}

	long long ans = 0;
	rep(j,1,n+1){
		ans += dp[n-1][j][a*j];
	}
	P(ans);
	ret 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=n-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

int main(){

    int h,w,k;
    cin>>h>>w>>k;
    vc<string> c(h);
    rep(i,h)cin>>c[i];

    int ans=0,h2=1<<h,w2=1<<w;

    rep(i,h2)rep(j,w2){
        int b=0;
        rep(k,h)rep(l,w){
            if((1&(i>>k)) && (1&(j>>l)) && c[k][l]=='#')b++;
        }
        if(b==k)ans++;
    }

    cout<<ans<<"\n";

    return 0;

}

Measured memory_bytes: 3624
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();
      int C = sc.nextInt();


      int w = A-B-C;

      if(A>=B+C){
        System.out.print(0);
      }else{
        System.out.print(Math.abs(w));
      }

  }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

void Compute(ll k)
{
	KAKA
	ll sum = 0;
	pragi(1,k + 1)
	{
		pragj(1,k + 1)
		{
			ll a = __gcd(i,j);
			for(ll p = 1;p <= k;p++)
			{
				ll b = __gcd(a,p);
				sum += b;
			}
		}
	}
	cout<<sum<<"\n";
}
int main()
{
	KAKA
	ll k;
	cin>>k;
	Compute(k);
}

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

int main(){
	int n,ans=0;	cin>>n;
	for(int i=1; i<=n; i++){
		int cnt=0;
		if(i%2){
			for(int j=1; j<=i; j++){
				if(i%j==0)++cnt;
			}
		}
		if(cnt==8)++ans;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		int min=754;
		int[] a=new int[s.length()-2];
		for(int i=0; i<s.length()-2; i++) {
			a[i]=Integer.parseInt(s.substring(i, i+3));
			min=Math.min(Math.abs(a[i]-753), min);
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 21844
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 
#n = int(input())
n,k = [int(i) for i in readline().split()]
xyc = []


B = [[0]*(k+1) for i in range(k+1)]
W = [[0]*(k+1) for i in range(k+1)]

for _ in range(n):
    x,y,c = [i for i in readline().split()] 
    x = int(x)
    y = int(y)
    sgn = 0
    sgn += x//k
    x %= k
    sgn += y//k
    y %= k
    if sgn&1:
        if c == "W": B[x+1][y+1] += 1
#            xyc.append((x,y,"B"))
        else: W[x+1][y+1] += 1
#            xyc.append((x,y,"W"))
    else:
        if c == "W": W[x+1][y+1] += 1
#            xyc.append((x,y,"B"))
        else: B[x+1][y+1] += 1
#            xyc.append((x,y,"W"))


for i in range(k):
    for j in range(k):
        B[i+1][j+1] += B[i+1][j] + B[i][j+1] - B[i][j]
        W[i+1][j+1] += W[i+1][j] + W[i][j+1] - W[i][j]

#print(B)
#print(W)

ans = 0
for i in range(k):
    for j in range(k):
        resb1 = B[i][j] + (B[-1][-1] - B[-1][j] - B[i][-1] + B[i][j])
        resw1 = W[i][j] + (W[-1][-1] - W[-1][j] - W[i][-1] + W[i][j])
        
        resb2 = (B[i][-1] - B[i][j]) + (B[-1][j] - B[i][j])
        resw2 = (W[i][-1] - W[i][j]) + (W[-1][j] - W[i][j])
        
#        print(i,j,"ij",resb1,resw2,resw1,resb2)
        ans = max(ans,resb1+resw2, resw1+resb2)


print(ans)









Measured memory_bytes: 60508
MEMO = {}

def solve(N, A, B, C, D):
    # 戦略
    # 0からNを作るのではなく、
    # Nから+-1, /2, /3, /5 の操作を繰り返して
    # 0にたどり着くことを考える

    if N == 0:
        return 0
    elif N == 1:
        return D
    elif N in MEMO:
        return MEMO[N]
    
    # 例: N = 13 の場合
    # 0から13にたどり着くまでに、次の7通りが考えられる
    # 1. 0から+1を13回繰り返す: コスト = D * 13
    # 2. 6を2倍して+1: コスト = [0から6を作るコスト] + A + D * (13 - 12)
    # 3. 7を2倍して-1: コスト = [0から7を作るコスト] + A + D * (14 - 13)
    # 4. 4を3倍して+1: コスト = [0から4を作るコスト] + B + D * (13 - 12)
    # 5. 5を3倍して-2: コスト = [0から5を作るコスト] + B + D * (15 - 13)
    # 6. 2を5倍して+3: コスト = [0から2を作るコスト] + C + D * (13 - 10)
    # 7. 3を5倍して-2: コスト = [0から3を作るコスト] + C + D * (15 - 13)

    min_score = D * N # case 1

    # # case 2, 3
    # div2_1 = N // 2
    # div2_2 = (N + 1) // 2
    # min_score = min(min_score, solve(div2_1, A, B, C, D) + A + D * abs(N - 2 * div2_1))
    # min_score = min(min_score, solve(div2_2, A, B, C, D) + A + D * abs(N - 2 * div2_2))

    # # case 4, 5
    # div3_1 = N // 3
    # div3_2 = (N + 2) // 3
    # min_score = min(min_score, solve(div3_1, A, B, C, D) + B + D * abs(N - 3 * div3_1))
    # min_score = min(min_score, solve(div3_2, A, B, C, D) + B + D * abs(N - 3 * div3_2))

    # # case 6, 7
    # div5_1 = N // 5
    # div5_2 = (N + 4) // 5
    # min_score = min(min_score, solve(div5_1, A, B, C, D) + C + D * abs(N - 5 * div5_1))
    # min_score = min(min_score, solve(div5_2, A, B, C, D) + C + D * abs(N - 5 * div5_2))

    # 丁寧に書くと上のようになるが、
    # 面倒なので下のようにしてまとめる
    div_score = {2: A, 3: B, 5: C}

    for d, s in div_score.items():
        div1 = N // d
        div2 = (N + d - 1) // d
        min_score = min(min_score, solve(div1, A, B, C, D) + s + D * abs(N - d * div1))
        min_score = min(min_score, solve(div2, A, B, C, D) + s + D * abs(N - d * div2))

    # 再帰呼び出しで同じNについて何回も計算する可能性があるので、
    # 1度計算した値はメモしておく
    MEMO[N] = min_score
    return min_score


def main():
    T = int(input())
    queries = []
    for t in range(T):
        queries.append(list(map(int, input().split())))
    
    ans = []
    for N, A, B, C, D in queries:
        MEMO.clear()
        ans.append(solve(N, A, B, C, D))

    print(*ans, sep='\n')

if __name__ == '__main__':
    main()

Measured memory_bytes: 11152
#include <iostream>
#include <list>
#include <map>

int main(int argc, char* pArgv[])
{
  int n = 0;
  std::map<std::string, int> histogram;

  std::cin >> n;
  for (int index = 0; index < n; index ++) {
    std::string s;
    std::cin >> s;
    if (histogram.find(s) == histogram.cend()) {
      histogram.emplace(std::make_pair(s, 1));
    } else {
        auto val = histogram.at(s);
        histogram[s] = val + 1;
    }
  }

  int countMax = 0;
  for (const auto& pair : histogram) {
    if (countMax < pair.second) countMax = pair.second;
//    std::cerr << pair.first << " " << pair.second << std::endl;
  }

  std::list<std::string> so;

  for (const auto& pair : histogram) {
    if (pair.second != countMax) continue;
    so.push_back(pair.first);
  }

  for (const auto& s : so) {
    std::cout << s << std::endl;
  }
  return 0;
}



Measured memory_bytes: 32512
#include<bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << a << endl
int main(){
	//freopen("input.txt", "r",stdin);
	int h, n; cin>>h>>n;
	int res = 0;
	for(int i =0; i<n; i++){
		int x; cin>>x;
		res += x;
	}
	if(res >= h) cout<<"Yes\n"; else cout<<"No\n";
	return 0;
}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define F first
#define S second
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define __ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cout << (#x) << " is " << (x) << endl
//#define int long long

 
const int inf = 1e9 + 7;
const int N = 1e5 + 4;


signed main() { __
  int h, n;
  cin>>h>>n;
  int ans = h / n;
  if(h % n != 0) ans++;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
n, x= map(int, input().split())
a = list(map(int, input().split()))
a.sort()
wa = 0
cnt = 0

for i in a:
    wa += i
    cnt += 1
    if wa > x:
        print(cnt - 1)
        exit()
        
    elif wa == x:
        print(cnt)
        exit()
print(cnt - 1)

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
 
int main(){
    string s;
    int flag = 0;
    string ans[] = {"Yes", "No"};
	cin>>s;
    if (s[0] == s[1]){
        if (s[1] == s[2]){
            if (s[0] == s[2]){
                flag = 1;
            }
        }
    }
	cout<<ans[flag]<<endl;
}

Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll i = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll i = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll i = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	string t;
	cin >> t;
	rep(i, t.size()){
		if (t[i] == '?') t[i] = 'D';
	}
	co(t);

	return 0;
}


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

int main(){
int N,M,A,B,tsum,ans;
  cin>>N;
  tsum=0;
  vector<int>t(N);
  for(int i=0;i<N;i++){
  cin>>t[i];
    tsum+=t[i];
  }
  cin>>M;
  for(int i=0;i<M;i++){
  cin>>A>>B;
    ans=tsum+B-t[A-1];
    cout<<ans<<endl;
  }
  
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import bisect
import math
import fractions
import sys
import copy


def L(): return sys.stdin.readline().split()


def I(): return int(sys.stdin.readline().rstrip())


def SL(): return list(sys.stdin.readline().rstrip())


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def IR(n): return [I() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def LIR1(n): return [LI1() for _ in range(n)]


def SR(n): return [SL() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


def LR(n): return [L() for _ in range(n)]


def perm(n, r): return math.factorial(n) // math.factorial(r)


def comb(n, r): return math.factorial(
    n) // (math.factorial(r) * math.factorial(n-r))


alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
INF = float("inf")


def main():
    S = SL()
    if S.count("R") == 1:
        print(1)
    elif S.count("R") == 2 and S[1] != "R":
        print(1)
    elif S.count("R") == 2:
        print(2)
    elif S.count("R") == 3:
        print(3)
    else:
        print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 77104
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a, v, b, w, t;
	cin>>a>>v>>b>>w>>t;
	long long d;
	if((b-a)<0){
		d=(a-b);
	}else{
		d=(b-a);
	}if((w-v)>=0){
		cout<<"NO"<<endl;
	}else if(((v-w)*t)>=d){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3632