akhauriyash/Code-Regression huggingface dataset:
from sys import stdin


def readline_from_stdin() -> str:
    return stdin.readline().rstrip


if __name__ == '__main__':
    N, D = input().split()
    N, D = int(N), int(D)

    c = 0
    for i in range(N):
        X, Y = input().split()
        X, Y = int(X), int(Y)
        if X*X + Y*Y <= D*D:
            c += 1
    print(c)


Measured memory_bytes: 69876
#include<iostream>
using namespace std;
int main()
{
  int k;
  cin>>k;
 
  int A[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout<<A[k-1];
}


Measured memory_bytes: 256
// Author: Jinhai Chen
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long ll;



int main() {
#ifdef CJHCJH
//	freopen("data.in","r",stdin);
#endif
double a,b;
cin>>a>>b;
printf("%.8lf\n",a/b);



	return 0;
}














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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

int h, w, k;
int ans[300][300];

void paint(int sy, int sx, int gy, int gx, int n) {
  for (int y = sy; y <= gy; y++) {
    for (int x = sx; x <= gx; x++) {
      ans[y][x] = n;
    }
  }
}

// ====================================================================

int main() {
  cin >> h >> w >> k;
  vector<string> g(h);
  for (int i = 0; i < h; i++) {
    cin >> g[i];
  }

  int sy = 0, sx = 0, gx = 0, gy = 0, count = 1;

  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (g[y][x] == '#') {  // その行にあった
        gy = y;
        for (x += 1; x < w; x++) {  // 右に当たるか苺に当たるまで伸ばす
          if (g[y][x] == '#') {     // もし途中で苺に当たったら
            gx = x - 1;
            paint(sy, sx, gy, gx, count);
            count++;
            sx = gx + 1;
          }
        }
        paint(sy, sx, gy, w - 1, count);
        count++;
        sx = 0, sy = y + 1;
      }
    }
  }

  for (int x = 0; x < w; x++) {
    if (ans[h - 1][x] == 0) {
      int c = -1;
      while (ans[h - 1 + c][x] == 0) c--;
      paint(h - 1 + c + 1, x, h - 1, x, ans[h - 1 + c][x]);
    }
  }

  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      cout << ans[y][x] << " ";
    }
    cout << endl;
  }
}


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

using namespace std;

int main()
{
	long long n, k;
	long long sum = 0;
	multiset< pair<long long, long long> >m;
	scanf("%lld%lld", &n, &k);
	while(n--)
	{
		long long a, b;
		scanf("%lld%lld", &a, &b);
		m.insert(make_pair(a, b));	
	}
	for(auto it = m.begin();it!=m.end();it++)
	{
		sum += it->second;
		if(sum >= k)
		{
			cout << it->first << endl;
			break;			
		}
	}	
	return 0;
} 

Measured memory_bytes: 6528
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A&lang=jp
 */
import java.util.*;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int[] stack = new int[200];
		int sp = 0;
		while (scan.hasNext()) {
			String tok = scan.next();
			if (tok.equals("+")) {
				int b = stack[--sp];
				int a = stack[--sp];
				stack[sp++] = a + b;
			} else if (tok.equals("-")) {
				int b = stack[--sp];
				int a = stack[--sp];
				stack[sp++] = a - b;
			} else if (tok.equals("*")) {
				int b = stack[--sp];
				int a = stack[--sp];
				stack[sp++] = a * b;
			} else {
				int x = Integer.parseInt(tok);
				stack[sp++] = x;
			}
			//System.out.println(sp);
		}
		System.out.println(stack[0]);
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 26116
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll A, B, K;

int main() {
	scanf("%lld %lld %lld", &A, &B, &K);
	for(int i = 0; i < K; i++) {
		if(i % 2 == 0) {
			if(A % 2 != 0 && A != 0) {
				A -= 1;
				A -= A / 2;
				B += A;
			}
			else if(A % 2 == 0 && A != 0){
				A -= A / 2;
				B += A;
			}
		}
		else {
			if(B % 2 != 0 && B != 0) {
				B -= 1;
				B -= B / 2;
				A += B;
			}
			else if(B % 2 == 0 && B != 0){
				B -= B / 2;
				A += B;
			}
		}
		// cout << A << " " << B;
	}
	printf("%lld %lld\n", A, B);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
#define endl '\n'
#define next next_
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define newline putchar('\n')
#define leave_space puthchar(' ')
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = f; it <= e; ++it)
#define per(it, f, e) for (rint it = f; it >= e; --it)
const int MAXN = 5e5 + 20;
char s[MAXN], t[MAXN];
int n, fail1[MAXN], fail2[MAXN];
inline void getfail(int fail[], char s[]) {
	int j = 0;
	fail[0] = -1;
	rep (i, 1, n - 1) { 
		while (j && s[i] != s[j]) j = fail[j];
		fail[i + 1] = s[i] == s[j] ? ++j : 0;
	}
}
inline bool check_cyc1(int x) {
	return fail1[x] == 0 || x % (x - fail1[x]);
}
inline bool check_cyc2(int x) {
	if (x == 0) return false;
	return fail2[x] == 0 || x % (x - fail2[x]);
}
int main() {
	scanf("%s", s);
	n = strlen(s);
	memcpy(t, s, sizeof(t));
	reverse(t, t + n);
	getfail(fail1, s);
	getfail(fail2, t);
	int res = check_cyc1(n) ? 1 : 2;
	bool flag = true;
	rep (i, 1, n - 1) {
		if (s[i] != s[i - 1]) {
			flag = false;
			break;
		}
	}
	if (flag) {
		cout << n << endl;
		cout << 1 << endl;
	} else if (res == 1) {
		cout << 1 << endl;
		cout << 1 << endl;
	} else {
		int ans = 0;
		rep (i, 0, n - 1) {
			ans += (check_cyc1(i + 1) && check_cyc2(n - i - 1));
		}
		cout << 2 << endl;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 5120
using System;

class solution
{
    static void Main()
    {
        string str = Console.ReadLine();
        char[] ca = str.ToCharArray();
        for(int i =0;i<ca.Length;i++)
        {
            if(char.IsLower(ca[i]))
            {
                ca[i] = char.ToUpper(ca[i]);    
            }
            else if(char.IsUpper(ca[i]))
            {
                ca[i] = char.ToLower(ca[i]);
            }
        }
        string s = new string(ca);
        Console.WriteLine(s);
    }
}

Measured memory_bytes: 9188
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int f[100005];
long long ans;

int main () {
	
	int n; scanf ("%d",&n);
	for (int i=1,j;i<=n;i++) {
		scanf ("%d",&j);
		f[j]++; ans+=j;
	}
	int q; scanf ("%d",&q);
	while (q--) {
		int a,b; scanf ("%d%d",&a,&b);
		ans=ans-f[a]*(long long)a+f[a]*(long long)b;
		f[b]+=f[a]; f[a]=0;
		printf ("%lld\n",ans);
	}
	
	return 0;
}



Measured memory_bytes: 2068
s=gets.chomp.split("").map { |e| e.to_i  }
k=gets.chomp.to_i

leng = s.length
ans = 0

leng.times do |i|
  if s[i] == 1 && k>0
      ans = 1
      k -= 1
  end

  if s[i] != 1 && k > 0
    puts s[i]
    exit
  end
end

puts 1


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int r;
    cin>>r;
    cout<<3*r*r<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>v;
#define tc int t; cin>>t; while(t--)
#define an long long n; cin>>n; long long a[n]; for(int i=0;i<n;i++) cin>>a[i];
int main()
{ 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);

    long long a,b,c,d,ar[4]; string s; bool flag;
    cin>>a>>b>>c>>d;
    ar[0]=a*c; ar[1]=a*d; ar[2]=b*c; ar[3]=b*d;
    cout<<*max_element(ar,ar+4)<<endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include<stdio.h>
using namespace std;

int main()
{
    int sum=700;
    char Str[3];
    int i;
    scanf("%s",Str);
    for(i=0;i<3;i++)
	{
		if(Str[i]=='o')
			sum+=100;
	}
	cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define NUM 100
int main()
{
  int K;
  int c[NUM];
  int i;
  int sum;
  while(scanf("%d",&K), K!=0){
    sum=0;
    for(i=0; i<K*(K-1)/2; i++){
      scanf("%d",&c[0]);
      sum+=c[0];
    }
    printf("%d\n", sum/(K-1));
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int N;
vector<map<string,int>> memo;

// 長さ4の部分文字列について，2文字を入れ替えてAGCを含むならfalse
// (GAC, ACG, A?GC, AG?C を含まない)
bool check(string last4)
{
  REP(i,0,4) {
    string t = last4;
    if (i >= 1) swap(t[i-1], t[i]);
    if (t.substr(0,3) == "AGC" || t.substr(1,3) == "AGC")
      return false;
  }
  return true;
}

// last3: i-3,i-2,i-1文字目
int dfs(int i, string last3)
{
  if (memo[i].find(last3) != memo[i].end()) {
    // Found
    return memo[i][last3];
  }
  if (i == N) return 1;

  int res = 0;
  // ACGTのみからなる文字列を探索
  for (char& c : (string)"ACGT") { // prevent null char
    // cout << c << endl;
    // i文字目をcにする
    if (check(last3 + c)) {
      res += dfs(i+1, last3.substr(1,2) + c);
      res %= MOD;
    }
  }
  return memo[i][last3] = res;
}

int main()
{
  cin >> N;
  memo.resize(N+1); // initialize with empty map??

  // checkでの場合分けを防ぐために，3文字以上の適当な文字列を渡す
  cout << dfs(0, "XXX") << endl;

  return 0;
}


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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> void chmax(T& a,const T& b){if(a < b) a = b;}
template<typename T> void chmin(T& a,const T& b){if(b < a) a = b;}
typedef long long ll;

int N,A,B;
string S;

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

	cin >> N >> A >> B;
	cin >> S;

	int x = 0,y = 0;
	FOR(i,0,N){
		if(S [i] == 'a' && x + y < A + B){
			cout << "Yes" << endl;
			x++;
		}
		else if(S [i] == 'b' && x + y < A + B && y < B){
			cout << "Yes" << endl;
			y++;
		}
		else{
			cout << "No" << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 848
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,k;
  cin>>n>>k;
  vint a(n);
  rep(i,n){
      cin>>a[i];
  }
  sort(all(a));
  ll sum=0;
  rep(i,k){
      sum+=a[i];
  }
  cout<<sum<<'\n';
  return(0);
}


Measured memory_bytes: 3648
def run():
  N = int(input())
  xy_li = [list(map(int, input().split())) for i in range(N)]
  d_sum = 0
  for i in range(N):
    for j in range(i+1, N):
      d_sum += ((xy_li[i][0]-xy_li[j][0])**2+(xy_li[i][1]-xy_li[j][1])**2)**(1/2)
      #print(i, j, d_sum)
  print(2*d_sum/N)
  
if __name__ == '__main__':
  run()

Measured memory_bytes: 3060
import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
def main():
    h, w, m = map(int, input().split())
    b_row = [0] * h
    b_col = [0] * w
    b_coor = set()
    m = map(int, read().split())
    for a, b in zip(m, m):
        a -= 1
        b -= 1
        b_row[a] += 1
        b_col[b] += 1
        b_coor.add((a, b))

    row_max = max(b_row)
    col_max = max(b_col)
    rows = [i for i, v in enumerate(b_row) if v == row_max]
    cols = [i for i, v in enumerate(b_col) if v == col_max]

    for r in rows:
        for c in cols:
            if (r, c) not in b_coor:
                print(row_max + col_max)
                sys.exit()
    print(row_max + col_max - 1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 181800
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=1e6+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------
void solve()
{
    ll a;
    ld b;
    cin>>a>>b;
    ll q=b*100;
    ll a1 = (a*q)/100;
    
    ld p=a*b;
    ll ans=p;
    cout <<max(ans,a1)<<"\n";

}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 3744
#include <iostream>
using namespace std;
int main(void){
    long long int n,ans=0;
    
    cin>>n;
    
    for(int i=1;i<=n;i++){
        if(i%3!=0&&i%5!=0){
            ans+=i;
        }
    }
    
    cout<<ans;
    
}


Measured memory_bytes: 3588
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N, A, B, C;
vector<ll> L;
ll calc(vector<ll> groups, ll cost)
{
    if (groups.size() < 3)
    {
        return LL_INF;
    }
    ll result = LL_INF;
    sort(groups.begin(), groups.end());
    for (int i = 0; i < groups.size(); i++)
    {
        ll med = abs(groups[i] - B);
        ll left = INF;
        ll right = INF;
        for (int l = 0; l < i; l++)
        {
            left = min(left, abs(groups[l] - C));
        }
        for (int r = i + 1; r < groups.size(); r++)
        {
            right = min(right, abs(groups[r] - A));
        }
        result = min(result, cost + med + left + right);
    }
    return result;
}
ll ans = LL_INF;
void dfs(int pos, vector<ll> &groups, ll cost)
{
    if (pos >= N)
    {
        ans = min(ans, calc(groups, cost));
        return;
    }
    //not merge
    groups.push_back(L[pos]);
    dfs(pos + 1, groups, cost);
    groups.pop_back();
    //merge
    for (int i = 0; i < groups.size(); i++)
    {
        groups[i] += L[pos];
        dfs(pos + 1, groups, cost + 10LL);
        groups[i] -= L[pos];
    }
    return;
}
int main()
{
    cin >> N >> A >> B >> C;
    L.resize(N);
    for (auto &val : L)
    {
        cin >> val;
    }
    sort(L.begin(), L.end());
    vector<ll> groups;
    dfs(0, groups, 0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl
#define all(v) v.begin(), v.end()
#define rsort(v) sort(v.rbegin(), v.rend())


int main() {
  int N, ans = 0;
  ll D;
  cin >> N >> D;
  D *= D;
  rep(i,N) {
    ll x,y;
    cin >> x >> y;
    x *= x; y *= y;
    ans += (x+y<=D) ? 1 : 0;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
static const int MAX_N = 1000;
static const int MAX_M = 1000;

int N, M;
ll D[MAX_N + 1], C[MAX_M + 1];
ll memo[MAX_N + 1][MAX_M + 1];

int main(){
	cin >> N >> M;
	for(int i = 1; i <= N; i++) cin >> D[i];
	for(int i = 1; i <= M; i++) cin >> C[i];
	fill(memo[0], memo[N + 1], 0);
	for(int i = 1; i <= N; i++) memo[i][i] = memo[i - 1][i - 1] + D[i] * C[i];
	for(int i = 1; i <= N; i++){
		for(int j = i + 1; j <= M; j++){
			memo[i][j] = min(memo[i][j - 1], memo[i - 1][j - 1] + D[i] * C[j]);
		}
	}
	cout << memo[N][M] << endl;
	return 0;
}



Measured memory_bytes: 9372
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	double[] GR => Strs.Select(double.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	// public const int MOD = 1000000007;
	public const long INFL = 4011686018427387913L;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int V, Mod;
	List<int>[] es;
	int[] par;
	// dp0[u]=(uを黒, par[u]を白に塗る場合の数)
	// dp1[u]=(uを白, par[u]を黒に塗る場合の数)
	long[] dp0, dp1;
	void Solve()
	{
		var I = G;
		V = I[0];
		Mod = I[1];
		es = new List<int>[V];
		par = new int[V];
		dp0 = new long[V];
		dp1 = new long[V];
		x = new long[V + 1];
		y = new long[V + 1];
		for (var u = 0; u < V; u++) es[u] = new List<int>();
		for (var e = 0; e < V - 1; e++)
		{
			I = G;
			es[I[0] - 1].Add(I[1] - 1);
			es[I[1] - 1].Add(I[0] - 1);
		}
		DFS1(0, -1);
		DFS2(0);
		DFS3(0);
		for (var u = 0; u < V; u++) WriteLine(dp0[u] * (dp1[u] + 1) % Mod);
	}
	long DFS2(int u)
	{
		dp0[u] = 1L;
		foreach (var v in es[u]) dp0[u] = dp0[u] * (DFS2(v) + 1) % Mod;
		return dp0[u];
	}
	long[] x, y;
	void DFS3(int u)
	{
		var W = es[u].Count;
		//var x = new long[W + 1]; // x[i] = t[0]*...*t[i-1], x[i+1]=x[i]*t[i]
		//var y = new long[W + 1]; // y[i] = t[i]*...*t[W-1], y[i]=y[i+1]*t[i]
		x[0] = y[W] = 1;
		for (var i = 0; i < W; i++) x[i + 1] = x[i] * (dp0[es[u][i]] + 1) % Mod;
		for (var i = W - 1; i >= 0; i--) y[i] = y[i + 1] * (dp0[es[u][i]] + 1) % Mod;
		for (var i = 0; i < W; i++) dp1[es[u][i]] = (dp1[u] + 1) * x[i] % Mod * y[i + 1] % Mod;
		foreach (var v in es[u]) DFS3(v);
	}
	void DFS1(int u, int p)
	{
		par[u] = p;
		es[u].Remove(p);
		foreach (var v in es[u]) DFS1(v, u);
	}
}


Measured memory_bytes: 40720
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back
#define sz size

/*
author: Basel
*/


using namespace std;

int n,ans;

int f(int x)
{
    int ret=0;
    while(x)
    {
        ret++;
        x/=10;
    }
    return ret%2;
}

int main()
{
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        ans+=f(i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  ll n;
  std::cin >> n;
  int a[n];
  for(int i=1; i<=n; i++) std::cin >> a[i];

  int cnt=0,j=1;

  while(j!=2 && cnt<n){
    j=a[j];
    cnt++;
  }

  if(cnt>=n) cnt=-1;
  std::cout << cnt ;
  return 0;
}


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

using namespace std;

typedef unsigned  LL;
const int mod=1e9+7;

#define FOR(i,bg,ed) for(int i=bg;i<ed;i++)
#define REP(i,n) FOR(i,0,n)


constexpr int SZ=2123;
LL comb[SZ][SZ];
LL csum[SZ][SZ];
LL c[SZ][SZ];
struct init{
    init(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        REP(i,SZ)comb[i][i]=1,comb[i][0]=1;
        FOR(i,2,SZ)FOR(j,1,i){
            comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%mod;
        }
        REP(i,SZ){
            csum[i][0]=1;
            FOR(j,1,i+1)
                csum[i][j]=(comb[i][j]+csum[i][j-1])%mod;
        }
        FOR(t,1,SZ)c[0][t]=1;
        FOR(s,1,SZ){
            FOR(t,1,SZ){
                c[s][t]=(csum[t-1][min(s,t-1)]+c[s-1][t])%mod;
            }
        }
    }
}iinit;

int main(){
    int A,B;
    cin>>A>>B;
    unsigned long long ret=A+1;
    FOR(a,0,A+1){
        FOR(b,1,B){
            int na=B-b;
            if(na>A-a)continue;
            int ra=A-a-na;
            int rb=B-b;
            long long x=comb[B-1][na];
            long long y=c[ra][rb];
                
            long long z=x*y%mod;
            ret+=z;
        }
    }
    cout<<ret%mod<<endl;
    return 0;
}


Measured memory_bytes: 53120
#include <cstdio>
#include <algorithm>

using LL = long long;

LL power(LL a, LL b) {
  if (a == 0) return 0;
  LL ret = 1;
  while (b) {
    if (b & 1) ret = ret * a;
    a = a * a;
    b >>= 1;
  }
  return ret;
}

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  LL result = power(n / k, 3);
  if (k % 2 == 0) {
    int c = 0;
    for (int i = 1; i <= n; ++ i) {
      c += i % k == k / 2;
    }
    result += power(c, 3);
  }
  printf("%lld\n", result);
}


Measured memory_bytes: 128
#!/usr/bin/env python3
N, K = [int(str) for str in input().strip().split()]


def solve():
    is_have = [False] * N
    for k in range(K):
        d = int(input().strip())
        A = [int(str) - 1 for str in input().strip().split()]
        for a in A:
            is_have[a] = True
    print(sum([1 for a in is_have if not a]))


solve()


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

#define pb push_back

#define ll long long

#define ft first

#define sd second

using namespace std;

const int N = 5050 ;

bool used[N];

ll z , r , w ;

int main(){

    ll n , m ;
    cin >> n >> m ;
    ll k = n * 500 ;
    if(k >= m ){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

}


Measured memory_bytes: 256
n, k = map(int, input().split())
x = n
r = 0
x = n - (n // k) * k
pre_x = x
while True:
	if k == 1 or n == 0:
		break
	pre_x = x
	x = abs(x - k)
	if pre_x < x:
		r = pre_x
		break
print(r)

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

const int MaxN=2e5;
const int MaxV=1e9;
const int M=1e9+7;

int main(){
	int N;
	long x;
	__int128 OneSum=0;
	__int128 SQRSum=0;
	
	scanf("%d\n",&N);
	while(N-->0){
		scanf("%ld",&x);
		OneSum+=x;
		SQRSum+=x*x;
	}
	__int128 ans=( (OneSum*OneSum-SQRSum)>>1 )%M;
	printf("%d\n",(int)ans);
}

Measured memory_bytes: 3752
N, X = list(map(int, input().split()))
L = list(map(int, input().split()))
# N += 1
# L.insert(0, 0)
# %%
cnt = 0
d = 0
curr = [0]
for n in range(N):
    if d <= X:
        cnt += 1
        d += L[n]
        curr.append(d)
    else:
        break
if d <= X:
    cnt += 1
print('{}'.format(cnt))


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  ll res = 0;
  for(int i = 0;i < s.size();i++){
    //if(s[i] == 'P' && s[i + 1] == 'D'){
      //res++;
      //i++;
    //}
    //else if(s[i] == 'P' && s[i + 1] == '?'){
      //res++;
      //i++;
      //s[i] = 'D';
    //}
    if(s[i] == '?'){
      s[i] = 'D';
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 3752
//1.read question_2.read I/O_3.read test cases_4.read constraints(to decide TC of solution)_5.decide method_6.dry run_
//7.code_8.test_9.submit
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
#define F first
#define S second
#define _READ freopen("input.txt","r", stdin);
#define pb push_back
#define MP make_pair
#define _FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{
   
    _FAST
    lli n,t,i,j,k,ans=0,flag=0,a,b,m;
    cin>>n;vector<lli> ar(n);
    for(auto &i:ar)
        cin>>i;
    vector<vector<lli>> dp(n,vector<lli>(n,LONG_LONG_MAX));
    //dp[i][j]- min costin comnbining from i to j
    vector<lli> prefixSum(n+1,0);
    for(i=1;i<=n;i++)
        prefixSum[i]=prefixSum[i-1]+ar[i-1];
    for(i=n-1;i>=0;i--)
        for(j=i;j<n;j++)
        if(i==j)
        dp[i][j]=0;
        else
            for(k=i;k<=j-1;k++)
                dp[i][j]=min(dp[i][k]+dp[k+1][j]+prefixSum[j+1]
                             -prefixSum[i],
                        dp[i][j]);
    cout<<dp[0][n-1];
    return 0;
}


Measured memory_bytes: 1536
a,b,c,d=map(int,input().split())

k=0

while(1):
    c=c-b
    a=a-d
    if(c <=0):
        k=1
        break
    if(a<=0):
        k=2
        break
#print(k)
if(k==1):print("Yes")
else:print("No")

Measured memory_bytes: 9176
c = [list(map(int,input().split())) for i in range(3)]
ans = "No"
for a1 in range(100):
	b1 = c[0][0] - a1
	b2 = c[0][1] - a1
	b3 = c[0][2] - a1
	a2 = c[1][0] - b1
	a3 = c[2][0] - b1
	if a2+b2 == c[1][1] and a2+b3 == c[1][2] and a3+b2 == c[2][1] and a3+b3 == c[2][2]:
		ans = "Yes"
print(ans)

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

int main() {
  ll L, R;
  cin >> L >> R;
  if (R * L < 2019) {
    cout << L * (L + 1) << endl;
    return 0;
  }

  ll mn = LLONG_MAX;
  for (ll i = L; i <= R; i++) {
    for (ll j = i + 1; j <= R; j++) {
      if (mn > (i * j) % 2019) {
        mn = (i * j) % 2019;
        if (mn == 0) {
          cout << mn << endl;
          return 0;
        }
      }
    }
  }
  cout << mn << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

////////// 二項係数(N<=10^7) //////////

ll fac[MAX],finv[MAX],inv[MAX];
// fac[i] i!
// finv[i] i!の逆元
// inv[i] iの逆元

// テーブルを作る前処理
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(ll i=2; i<MAX; ++i){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

// 二項係数計算
ll COM(ll n,ll k){
  if(n<k) return 0;
  if(n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

//////////////////////////////////////////////////

int main(){
  ll N,M,ans=0;
  cin>>N>>M;
  COMinit();
  
  for(int i=0; i<=N; ++i){
    ll cnt=COM(N,i)*fac[M-i]%MOD*finv[M-N]%MOD;
    if(i%2==1) cnt*=-1;
    ans+=cnt;
    ans%=MOD;
    if(ans<0) ans+=MOD;
  }
  
  ans=ans*fac[M]%MOD*finv[M-N]%MOD;
  co(ans);
  return 0;
}

Measured memory_bytes: 123148
N,M = map(int, input().split())
P_S = [input().split() for _ in range(M)]
ac = [0]*(N)
wa = [0]*(N)
for i in range(M):
    no = int(P_S[i][0])
    result = P_S[i][1]
    if ac[no-1] ==0 and result == "AC":
        ac[no-1] =1    
    elif ac[no-1] ==0 and result =="WA":
        wa[no-1] += 1
for i in range(N):
    if ac[i] != 1:
        wa[i] = 0
print(sum(ac),sum(wa))

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

void solve() {
	string s, t;
	cin >> s >> t;
	int count = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) count++;
	}
	cout << count << endl;
}

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

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

Measured memory_bytes: 3776
#include<stdio.h>
int main()
{
	int n;
	int i,t;
	int count=0;
	int prime=0;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&t);
		for(i=2;i*i<=t;i++)
		{
			if(t%i==0)
				count++;
		}
		if(count==0)
			prime++;
		
		count=0;
	}
	printf("%d\n",prime);
	return 0;
}

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

const string YES = "YES";
const string NO = "NO";

void solve(long long A, long long V, long long B, long long W, long long T){
    if (W >= V) {
        cout << NO << endl;
    } else {
        if ((V - W) * T >= abs(B - A)) {
            cout << YES << endl;
        } else {
            cout << NO << endl;
        }
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long V;
    scanf("%lld",&V);
    long long B;
    scanf("%lld",&B);
    long long W;
    scanf("%lld",&W);
    long long T;
    scanf("%lld",&T);
    solve(A, V, B, W, T);
    return 0;
}


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

using lint = long long;
const lint modnum = 1e9+7;

lint factorialmod(int N){
    lint ans = 1;
    for(int i=1;i<=N;i++){
        ans = (ans * i) % modnum;
    }
    return ans;
}

int main(){
    int N, M;
    cin >> N >> M;

    if(M == N){
        cout << (2 * ((factorialmod(N) * factorialmod(M)) % modnum)) % modnum << endl;
    }
    else if(M == N+1 || M == N-1){
        cout << (factorialmod(N) * factorialmod(M)) % modnum << endl;
    }
    else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<int>
using namespace std;
using ll = long long;


int main() {
    ll a,b,c;
    cin>>a>>b>>c;
    if(c>a+b&&4*a*b<(c-a-b)*(c-a-b))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


Measured memory_bytes: 256
import Control.Applicative
import Text.Printf

-- + gcd(a, b) = m * a + n * b を満たす (gcd(a, b), m, n) を計算する。
extendedEuclideanAlgorithm :: Integral a => a -> a -> (a, a, a)
extendedEuclideanAlgorithm a b = loop [(a, b), (1, 0), (0, 1)]
  where
    loop [(u1, 0), (u2, _), (u3, _)] = (u1, u2, u3)
    loop ls@((u1, v1) : _) = loop $ map (\(u, v) -> (v, u - (div u1 v1) * v)) ls

main :: IO ()
main = do
  [a, b] <- map (read :: String -> Int) . words <$> getLine
  let (_, x, y) = extendedEuclideanAlgorithm a b
  printf "%d %d\n" x y



Measured memory_bytes: 3768
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#include <numeric>

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

int main()
{
  int n;
  cin >> n;
  ll jpy = 0;
  double btc = 0, sum, x;
  string u;

  for (int i = 0; i < n; i++)
  {
    cin >> x >> u;

    if (u == "JPY")
    {
      jpy += x;
    }
    else
    {
      btc += x;
    }
  }

  sum = jpy + 380000 * btc;
  cout << fixed << sum << endl;

  return 0;
}

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

bool ch=true;
void dep(string u){
	string v=u;
	reverse(u.begin(),u.end());
	if(u!=v){
		ch=false;
	}	
}
int main() {
	string s;
	cin>>s;
	dep(s);
	string u;
	for(ll i=0;i<=(s.size()-1)/2-1;i++){
		u.push_back(s[i]);
	}
	dep(u);
	string k;
	for(ll i=(s.size()+3)/2-1;i<s.size();i++){
		k.push_back(s[i]);
	}
	dep(k);
	cout << (ch?"Yes":"No");
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int a[501][501];
string ans[250001];

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  set<int> s;
  rep(i, k){
    if(a+i > b) continue;
    s.insert(a+i);
  }
  rrep(i, k){
    if(b- i <a) continue;
    s.insert(b-i);
  }
  for(auto a: s)
    cout << a << endl;
}


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main() {
	string s;
	cin >> s;
	int sz = s.size();
	if (sz%2==0) {
		if (s[0] == s[sz-1]) {
			cout << "First" << endl;
		} else {
			cout << "Second" << endl;
		}
	} else {
		if (s[0] == s[sz-1]) {
			cout << "Second" << endl;
		} else {
			cout << "First" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <map>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <stack>
#include <queue>
#include <cstring>
#include <iterator>

#define FOR(n) for(int cnt=0;cnt<(n);++cnt)
#define FOR_R(it,cont) for(auto it=rbegin(cont);it!=rend(cont);++it)
#define FOR_F(it,cont) for(auto it=begin(cont);it!=end(cont);++it)
#define ALL(cont) begin(cont), end(cont)
#define LB(b,e,v) lower_bound(b,e,v)
#define UB(b,e,v) upper_bound(b,e,v)

using namespace std;
typedef pair<int,int> P;
int N;
int A[100010];
long long dp[100010][10];
long long INF= 1ll * 1000 * 1000 * 1000* 1000* 1000;
int pow1(int i) {
  return i%2==0?1:-1;
}
long long doDP(int current, int brackets) {
  if (brackets < 0) {
    return 0;
  }
  if (brackets > 2) {
    return 0;
  }
  if (dp[current][brackets]!=-INF) {
    return dp[current][brackets];
  }
  if (current == N) {
    return dp[current][brackets]=0;
  }
  long long sub=-INF;
  if (A[current] < 0) {
    for(int i=0;i<=brackets+1;++i) {
      sub = max(sub, 1ll * pow1(brackets) * A[current] + doDP(current+1, i));
    }
  } else {
    for(int i=0;i<=brackets;++i) {
      sub = max(sub, 1ll * pow1(brackets) * A[current] + doDP(current+1, i));
    }
  }
  return dp[current][brackets] = sub;
}
int main() {
  scanf("%d", &N);
  FOR(N) {
    int factor=1;
    if (cnt > 0) {
      char buf[2];
      scanf("%s", buf);
      if (buf[0]=='-') {
        factor=-1;
      }
    }
    scanf("%d", &A[cnt]);
    A[cnt] *= factor;
  }
  for(int i=0;i<N;++i) {
    for(int j=0;j<5;++j) {
      dp[i][j] = -INF;
    }
  }

  doDP(0,0);

  long long answer=0;
  for(int i=0;i<3;++i) {
    answer = max(answer, dp[0][i]);
  }
  printf("%lld\n", answer);
  return 0;
}


Measured memory_bytes: 16128
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef unsigned long ul;
typedef pair<ul, ul> P;
map<int, int> dp;
#define REP(i, n) for (int i = 0; i < n; i++)
ul H, W;

const int MOD = 1000000007;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}
// long long modinv(long long a, long long m) {
//   long long b = m, u = 1, v = 0;
//   while (b) {
//     long long t = a / b;
//     a -= t * b;
//     swap(a, b);
//     u -= t * v;
//     swap(u, v);
//   }
//   u %= m;
//   if (u < 0) u += m;
//   return u;
// }
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  string S;
  cin >> N;
  cin >> S;
  vector<ul> alphabet(27, 0);
  ul ans = 1;
  auto chara = 'a';
  auto chara_end = 'z'+1;
  while (chara != chara_end) {
    ans = mod(1 + count(S.begin(), S.end(), chara), MOD) * mod(ans, MOD);
    ans = mod(ans,MOD);
    ++chara;
  }
  ans -= 1;
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	string s;
	cin>>s;
	int ans=10000;
	rep(i,s.size()-2){
	    ans=min(ans, abs(753-stoi(s.substr(i,3))));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 3e3 + 10;
int r, c, k, val[maxn][maxn];
LL dp[maxn][maxn][4], g[maxn][maxn];

int main() {
  scanf("%d%d%d", &r, &c, &k);
  for (int i = 1, x, y, v; i <= k; ++i) {
    scanf("%d%d%d", &x, &y, &v);
    val[x][y] = v;
  }
  for (int i = 1; i <= r; ++i)
    for (int j = 1; j <= c; ++j) {
      if (val[i][j]) {
        for (int x = 1; x <= 3; ++x)
          dp[i][j][x] = max(dp[i][j][x], dp[i][j - 1][x - 1] + val[i][j]);
        dp[i][j][1] = max(dp[i][j][1], g[i - 1][j] + val[i][j]);
      }
      dp[i][j][0] = max(dp[i][j][0], g[i - 1][j]);
      for (int x = 0; x <= 3; ++x)
        dp[i][j][x] = max(dp[i][j][x], dp[i][j - 1][x]);
      for (int x = 0; x <= 3; ++x)
        g[i][j] = max(g[i][j], dp[i][j][x]);
    }
  cout << max(max(dp[r][c][0], dp[r][c][1]), max(dp[r][c][2], dp[r][c][3]));
  return 0;
}

Measured memory_bytes: 391536
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
  int a,b;
  char op;
  cin >> a >> op >> b;
  while(op!='?'){
    int c;
    if(op=='+') c=a+b;
    if(op=='-') c=a-b;
    if(op=='*') c=a*b;
    if(op=='/') c=a/b;
    cout << c << endl;
    cin >> a >> op >> b;
  }
  return 0;
}



Measured memory_bytes: 3084
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;

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

        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int count = 0;
        for(int i = 0; i < 1000 ; i++){
            if(k * i >= a && k * i <= b){
                count++;
            }
        }
        if(count > 0){
            System.out.println("OK");
        }else{
            System.out.println("NG");
        }

        
        






    }
}

Measured memory_bytes: 35816
#include <cstdio>
#include <iostream>
using namespace std;
int f(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0) return 0;
    }
    return 1;
}
int main(){
    int n,t,ans;
    cin>>n;
    ans=0;
    while(n--){
        cin>>t;
        if(f(t)) ans++;
    }
    cout<<ans<<endl;
    return 0;
}



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

int main() {
	int n;
	double v[50];
	double ans = 0;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}

	sort(v, v + n);

	ans = (v[0] + v[1]) / 2;

	for (int i = 2; i < n; i++) {
		ans = (ans + v[i]) / 2;
	}

	cout << fixed << setprecision(7) << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

int main()
{
	int a,b,c,i,j,k,n;

	scanf("%d",&n);
	k=0;
	for(i=1;i<=9;i++)
		if(i<=n)
			k++;
	for(i=10;i<=n;i++)
	{
		b=0;j=i;
		while(j)
		{
			j/=10;
			b++;
		}
		if(b%2==1)
			k++;
	}
	printf("%d\n",k);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int inf = 1<<30;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

Measured memory_bytes: 384
import sys
# input = sys.stdin.buffer.readline
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

S = input()
n = len(S)//2
ans = 0
for i in range(n):
    if S[i] != S[-1-i]:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
int gcd(int a, int b) 
{ 
	if (a == 0) 
		return b; 
	return gcd(b % a, a); 
} 
int invertBits(int num) 
{  
    int x = log2(num) + 1; 
    for (int i = 0; i < x; i++)  
       num = (num ^ (1 << i));  
   
    return num; 
} 
///////////////////////////////////////////////////////////////////////////////////////////////////////////
map<pair<int,int> ,int> m;
int solve(int *h,int curr,int prev,int n)
{
	if(m.find(mp(curr,prev))!=m.end())
	{
		return m[mp(curr,prev)];
	}
	if(curr>n-1)
	{
		return -1;
	}
	if(curr==n-1)
	{
		return abs(h[curr]-h[prev]);
	}
	int ans=abs(h[curr]-h[prev]);
	int a1=solve(h,curr+1,curr,n);
	int a2=solve(h,curr+2,curr,n);
	if(a1!=-1 && a2!=-1)
	return m[mp(curr,prev)]=ans+min(a1,a2);
	else if(a1==-1)
	return m[mp(curr,prev)]=ans+a2;
	else if(a2==-1)
	return m[mp(curr,prev)]=ans+a1;
}
int main()
{
	int n;
	cin>>n;
	int h[n];
	int i;
	for(i=0;i<n;i++)
	{
		cin>>h[i];
	}
	cout<<solve(h,0,0,n);
	return 0;
}

Measured memory_bytes: 24064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const double PI=3.14159265358979323846;

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

int main()
{
	REP(i, 20001){
		int a, b;
		char op;
		cin >> a >> op >> b;

		if(op == '?')
			break;

		if(op == '+'){
			cout << a + b << endl;
		}
		else if(op == '-'){
			cout << a - b << endl;
		}
		else if(op == '*'){
			cout << a * b << endl;
		}
		else if(op == '/'){
			cout << a / b << endl;
		}
	}


	return 0;
}




Measured memory_bytes: 3084
from collections import defaultdict
def inpl(): return list(map(int, input().split()))
MOD = 998244353

S = input()
N = len(S)
B = [0]*N
R = [0]*N

for i in range(N):
    b = int(S[i])
    B[i] = b
    R[i] = 2 - b

DP = defaultdict(int)
DP[(B[0], R[0])] = 1

for i in range(1, N):
    DP2 = defaultdict(int)
    b1, r1 = B[i], R[i]
    for (b0, r0), v in DP.items():
        b2, r2 = b0+b1, r0+r1
        if b0:
            DP2[(b2-1, r2)] = (DP2[(b2-1, r2)] + v)%MOD
        if r0:
            DP2[(b2, r2-1)] = (DP2[(b2, r2-1)] + v)%MOD
    DP = DP2

for _ in range(N+1):
    DP2 = defaultdict(int)
    for (b, r), v in DP.items():
        if b:
            DP2[(b-1, r)] = (DP2[(b-1, r)] + v)%MOD
        if r:
            DP2[(b, r-1)] = (DP2[(b, r-1)] + v)%MOD
    DP = DP2

print(sum(DP.values()))

Measured memory_bytes: 90204