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

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

    private static void solve(Scanner in) {
        int N = in.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();
        }
        System.out.println(ans(A) ? "YES" : "NO");
    }

    private static boolean ans(int[] A) {
        long N = A.length;
        if (N == 1) {
            return true;
        }

        long sum = 0;
        for (long a : A) {
            sum += a;
        }

        final long round = (N * (N + 1)) / 2L;
        if (sum % round > 0) {
            return false;
        }

        final int K = (int) (sum / round);

        long k = K;

        for (int i = 0; i < N; i++) {
            int d = A[(int) ((i + 1) % N)] - A[i];
            if (d > K) {
                return false;
            }
            if (d < K) {
                int yobun = (K - d);
                if (yobun % N > 0) {
                    return false;
                }
                k -= yobun / N;
            }
            if (k < 0) {
                return false;
            }
        }

        return true;
    }
}

Measured memory_bytes: 46560
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int MAX=1e5+5;
const int INF=1e9;
int n,m;
int edge[20][20];
int total;
int cost[1<<16][16],dp[1<<16][16];
int inner[1<<16];//内部的边
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int x,y,price;
        scanf("%d%d%d",&x,&y,&price);
        --x;--y;
        edge[x][y]=edge[y][x]=price;
    }
    total=1<<n;
    for(int i=0;i<total;i++)//计算某点集内部所有边权值之和
        for(int a=0;a<n;a++)
            if(i&(1<<a))
                for(int b=0;b<a;b++)
                    if(i&(1<<b))
                        if(edge[a][b])
                            inner[i]+=edge[a][b];
    for(int i=0;i<total;i++)//计算某点集到点集外某点所有边的权值之和
        for(int a=0;a<n;a++)
            if(!(i&(1<<a)))
                for(int b=0;b<n;b++)
                    if((i&(1<<b))&&edge[a][b])
                        cost[i][a]+=edge[a][b];
    memset(dp,-1,sizeof(dp));
    dp[1][0]=0;//只有1个点的集合dp值显然为0
    for(int i=0;i<total;i++)
    {
        /*只加入一个点*/
        for(int a=0;a<n;a++)
        {
            if((i&(1<<a))&&dp[i][a]!=-1)
            {
                for(int b=0;b<n;b++)
                    if(!(i&(1<<b)))
                        if(edge[a][b])
                            dp[i|(1<<b)][b]=max(dp[i|(1<<b)][b],dp[i][a]+edge[a][b]);
                /*加入一个点集*/
                int left=total-1-i;
                for(int now=left;now!=0;now=(now-1)&left)
                {
                    int num=inner[now]+cost[now][a];
                    dp[i|now][a]=max(dp[i|now][a],dp[i][a]+num);
                }
            }
        }
    }
    printf("%d\n",inner[total-1]-dp[total-1][n-1]);


    return 0;
}


Measured memory_bytes: 8320
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;

ll gcd(ll a,ll b){
    if(a<b) gcd(b,a);
    else{
        if(b==0) return a;
        else return gcd(b,a%b);
    }
}

int main(){
    ll a,b;
    cin>>a>>b;
    ll c=gcd(a,b);
    ll s=1;
    for(ll i=2;i*i<=c;i++){
        if(c%i==0){
            while(c%i==0){
                c /= i;
            }
            s++;
        }
    }
    if(c>1) s++;
    cout<<s<<endl;
}


Measured memory_bytes: 256
def main():
    N, A, B, C = map(int, input().split())
    L = [int(input()) for _ in range(N)]
    #print(L)

    cur = dict()
    cur[(0, 0, 0)] = 0
    for i in range(N):
        temp = dict()
        for t in cur:
            for j in range(3):
                cost = cur[t]
                lv = list(t)
                merge = False
                if lv[j] != 0:
                    merge = True
                lv[j] += L[i]
                newt = tuple(lv)
                if newt not in temp:
                    temp[newt] = cost + 10 * (merge == True)
                else:
                    temp[newt] = min(temp[newt], cost + 10 * (merge == True))
        for t in temp:
            if t not in cur:
                cur[t] = temp[t]
            else:
                cur[t] = min(cur[t], temp[t])

    ans = float('inf')
    for t in cur:
        lv = list(t)
        if lv[0] > 0 and lv[1] > 0 and lv[2] > 0:
            v = abs(lv[0]-A) + abs(lv[1]-B) + abs(lv[2]-C) + cur[t]
            ans = min(ans, v)

    return ans

if __name__ == '__main__':
    print(main())

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

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

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int h, w; cin >> h >> w;
  char c[h][w];

  rep(i, h) rep(j, w) cin >> c[i][j];
  queue<pii> que;
  que.em(0, 0);

  int vs[h][w];
  rep(i, h) rep(j, w) vs[i][j] = 0;
  vs[0][0] = 1;

  while (!que.empty()) {
    pii v = que.front(); que.pop();
    int x = v.fi, y = v.se;

    rep(i, 2) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
      if (vs[ny][nx] || c[ny][nx] == '.') continue;

      vs[ny][nx] = 1;
      que.em(nx, ny);
      break;
    }
  }

  rep(i, h) rep(j, w) {
    if (vs[i][j] == 0 && c[i][j] == '#') {
      cout << "Impossible" << endl;
      return 0;
    }
  }

  cout << "Possible" << endl;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
vector<int> vr, vg, vb;
int main()
{
    string s;
    int n;
    long long ans = 0;
    cin >> n >> s;
    for (int i = 0; i < n;i++)
    {
        if(s[i]=='R')
            vr.push_back(i);
        else if(s[i]=='G')
            vg.push_back(i);
        else
            vb.push_back(i);
    }
 
    int r = vr.size(), g = vg.size(), b = vb.size();
    for (int i = 0; i < r;i++)
    {
        for (int j = 0; j < g;j++)
        {
          ans+=b;
            int dist = abs(vr[i] - vg[j]);
            int left = min(vr[i], vg[j]), right = max(vr[i], vg[j]);
            if((dist%2==0)&&(s[left+dist/2]=='B'))
                ans--;
            if(left-dist>=0)
                ans = s[left - dist] == 'B' ? ans - 1 : ans;
            if(right+dist<n)
                ans = s[right + dist] == 'B' ? ans - 1 : ans;
        }
    }
    cout << ans;

}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,st,en) for(i=st;i<=en;i++)
#define repv(i,en,st) for(i=en;i>=st;i--)
#define fout cout<<fixed<<setprecision(7)
#define bi(n) __builtin_popcount(n)
#define bil(n) __builtin_popcountll(n)


typedef long long ll;
typedef pair<int,int> pii;
const int N = 1000010;
ll mod = 1e6+3;
ll ffmod(ll b,ll exp){
    ll res =1;
    while(exp){if(exp&1ll)res=(res*b)%mod;
    b =(b*b)%mod;exp/=2ll;
    }
    return res;
}
ll fac[N],inv[N];


int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //ios_base::sync_with_stdio(false);cin.tie(NULL);
    int m,i,j,k,q;
    int t=1;
    cin>>t;
    fac[0]=1;
    rep(i,1,mod-1)fac[i]=(1ll*i*fac[i-1])%mod;
    inv[mod-1]=ffmod(fac[mod-1],mod-2);
    for(int i=mod-2;i>=0;i--)inv[i]=(1ll*inv[i+1]*1ll*(i+1))%mod;
    while(t--){
        ll x,d;
        ll n;
        cin>>x>>d>>n;
        if(d==0)cout<<ffmod(x,n)<<"\n";
        else{
            ll curnum = (x*ffmod(d,mod-2))%mod;
            ll pw = ffmod(d,n);
            if(curnum+n-1>=mod)cout<<"0\n";
            else{
                ll ans=fac[curnum+n-1];
                if(curnum>0)ans=(ans*inv[curnum-1])%mod;
                cout<<(ans*pw)%mod<<"\n";
            }
        }
    }



    
    return 0;
}


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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
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>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int a, b, c, d;
void in(){
    cin >> a >> b >> c >> d;
}

void solve(){
    
    print(a * b - (c * b) - (d * a) + c * d);


}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

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

int main(void){
	long long int N,A,B;
	long long int ans=0;
	scanf("%lld %lld %lld",&N,&A,&B);
	ans+=(N/(A+B))*A;
	if(A<N%(A+B)){
		ans+=A;
	}else{
		ans+=N%(A+B);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 128
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

a,b,c,d = gi
puts case
when a+b > c+d then 'Left'
when a+b < c+d then 'Right'
when a+b == c+d then 'Balanced'
end


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define _for(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FOR(...)   _for (__VA_ARGS__)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;

#define dump(x) cerr << #x << " = " << (x) << endl

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  int k;
  cin >> k;
  -- k;

  set <ll> runrun;
  auto runrun_f = [&] (auto self, ll now, int keta) -> void
  {
    if (keta > 10) return;
    runrun.emplace (now);
    int z = now % 10;
    FOR (i, max (0, z - 1), min (10, z + 2))
    {
      auto v = now * 10 + i;
      self (self, v, keta + 1);
    }
  };
  FOR (i, 1, 10)
  {
    runrun_f (runrun_f, i, 1);
  }
#ifdef LOCAL
  for (auto ite = begin (runrun), last = next (begin (runrun), k); ite != last; ++ ite)
  {
    cout << * ite << ",";
  }
#endif
  auto ans = * next (runrun.begin (), k);
  cout << ans << endl;
}


Measured memory_bytes: 9600
#include <vector>
#include <string>
#include <iostream>
using namespace std;

int main(){
  int h;
  cin >> h;
  int w;
  cin >> w;
  vector<string> a(h);
  for (int i = 0; i < h; i++){
    cin >> a[i];
  }
  
  vector<bool> row(h,false);
  vector<bool> col(w,false);
  
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      if (a[i][j] == '#'){
        row[i] = true;
        col[j] = true;
      }
    }
  }
  
  for (int i = 0; i < h; i++){
    if (row[i]){
      for (int j = 0; j < w; j++){
        if(col[j]){
          cout << a[i][j];
        }
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 3604
#include <stdio.h>

int main(void)
{
	int a, b;
	char c;
	
	a = 0;
	while (1){
		scanf("%c", &c);
		if (c == '\n') {
			break;
		}
		if (c >= 'a' && c <= 'z') {
			c -= 0x20;
		}
		printf("%c", c);
	}
	
	printf("\n");
	
	return (0);
}	

Measured memory_bytes: 524
N, Y = gets.split.map(&:to_i)

flag = false
result = [-1, -1, -1]
(0..N).each do |i|
  (0..(N - i)).each do |j|
    if i * 10000 + j * 5000 + (N - i - j) * 1000 == Y
      flag = true
      result = [i, j, N - i - j]
      break
    end
  end
  break if flag
end

puts "#{result[0]} #{result[1]} #{result[2]}"

Measured memory_bytes: 1788
mod = 10 ** 9 + 7
max_kai = 5*10**6
kai = [1]
for i in range(1, max_kai):
    kai.append(kai[-1] * i % mod)
kkai = [0] * max_kai
kkai[-1] = pow(kai[-1], mod - 2, mod)
for i in reversed(range(1, max_kai)):
    kkai[i - 1] = kkai[i] * i % mod


def comb(a, b):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= kai[a]
    c *= kkai[b]
    c *= kkai[a - b]
    return c % mod


k = int(input())
s = input()

ans = 0
for i in range(len(s), len(s) + k + 1):
    ans += pow(25, i - len(s), mod) * pow(26, len(s) + k - i, mod) * comb(i-1,len(s)-1)
    ans %= mod
print(ans)


Measured memory_bytes: 164672
#include <atcoder/dsu>
#include <cstdio>

using namespace std;
using namespace atcoder;

int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    dsu d(n);
    for (int i = 0; i < q; i++) {
        int t, u, v;
        scanf("%d %d %d", &t, &u, &v);
        if (t == 0) {
            d.merge(u, v);
        } else {
            if (d.same(u, v)) {
                printf("1\n");
            } else {
                printf("0\n");
            }
        }
    }
    return 0;
}

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

vector<ll>a;
vector<ll>b;
int main() {
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		ll z;
		cin>>z;
		a.push_back(z);
		b.push_back(z);
	}
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	for(int i=0;i<b.size();i++){
		if(b[i]==a[0]){
			cout << a[1];
		}
		else{
			cout << a[0];
		}
		cout << endl;
	}
}

Measured memory_bytes: 4964
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(void) {
    ll A, B;
    cin >> A >> B;

    vector<int> digits;
    ll twos = 1;
    for (int i = 0; i < 42; i++) {
        ll one_cnt = 0;

        if (i == 0) {
            one_cnt = (B + 1) / 2 - A / 2;
        } else {
            // ll f_low = (i == 0) ? (A + 1) : ((((A + 1) + twos - 1) / twos) * twos);
            ll f_low = (((A + 1) + twos - 1) / twos) * twos;
            if ((f_low & twos) == 0) {
                one_cnt += f_low - A;
            }

            ll c_high = (B / twos) * twos;
            if (c_high & twos) {
                one_cnt += B - c_high + 1;
            }

            if (B - A < twos && (A & twos) && (B & twos)) {
                one_cnt -= twos;
            }
        }

#ifdef DEBUG
        printf("i: %d, one_cnt: %lld\n", i, one_cnt);
#endif

        if (one_cnt % 2 == 1) {
            digits.push_back(1);
        } else {
            digits.push_back(0);
        }

        twos *= 2;
    }

    reverse(digits.begin(), digits.end());

#ifdef DEBUG
    printf("0b");
    for (int i = 0; i < (int) digits.size(); i++) {
        cout << digits[i];
    }
    cout << endl;
#endif

    ll ans = 0;
    for (int i = 0; i < (int) digits.size(); i++) {
        ans *= 2;
        if (digits[i]) {
            ans += 1;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>

using ll=long long int;

constexpr ll mod = 1e9+7;

int n,k;

int main() {

    std::cin>>n>>k;

    ll ans=0;

    for(ll i=k;i<=n+1;++i){
        ans+=1+i*(n-i+1);
        ans%=mod;
    }

    std::cout<<ans<<std::endl;

    return 0;
}

Measured memory_bytes: 3160
// atcodeer

#include <stdio.h>

int main(void){
	int a, b, c;
	int ans;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if(a == b){
		if(b == c){
			ans = 1;
		}else{
			ans = 2;
		}
	}else{
		if((c == a) || (c == b)){
			ans = 2;
		}else{
			ans = 3;
		}
	}
	
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

int main() {
	int n, x;
	cin >> n >> x;
	int m;
	int minD = 10001;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> m;
		if (minD > m) minD = m;
		sum += m;
	}
	int ans = 0;
	ans = n + (x - sum) / minD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;

ll x, y, z, k, a[1000], b[1000], c[1000], s[9000000], r[9000000];
int main() {
    cin >> x >> y >> z >> k;
    for(int i = 0; i < x; ++i)
        cin >> a[i];
    for(int i = 0; i < y; ++i)
        cin >> b[i];
    for(int i = 0; i < z; ++i)
        cin >> c[i];
    sort(c, c + z, [](ll a, ll b){ return a > b; });
    for(int i = 0; i < x; ++i) {
        for(int j = 0; j < y; ++j) {
            s[i * y + j] = a[i] + b[j];
        }
    }
    sort(s, s + (x * y), [](ll a, ll b){ return a > b; });
    for(int i = 0; i < min(k, x * y); ++i)
        for(int j = 0; j < z; ++j)
            r[i * z + j] = s[i] + c[j];
    sort(r, r + (k * k), [](ll a, ll b){ return a > b; });
    for(int i = 0; i < k; ++i)
        cout << r[i] << endl;
    return 0;
}

Measured memory_bytes: 80128
K = int(input())


def all_eq(K):
    return K*(K+1)/2

def eq_2(K):
    answer = 0
    for i in range(1, K+1):
        for j in range(i+1, K+1):
            answer =answer +gcd(j,i)
    return answer

def not_eq(K):
    answer = 0
    for i in range(1, K+1):
        for j in range(i+1, K+1):
            for k in range(j+1, K+1):
              answer = answer + gcd(gcd(i,j), k)
    return answer

def gcd(a,b):
    if a<b:
        a,b = b, a
    while a%b != 0 :
        a, b = b,a%b
    return b

print(int(all_eq(K)+eq_2(K)*6+not_eq(K)*6))

Measured memory_bytes: 9232
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

let main() =
    let [|n;m|] = reada int
    if n = m then "Yes" else "No"
    |> puts
    ()

main()
writer.Close()


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

#define endl '\n'

using namespace std;

vector <long long> find_divisors(long long n)
{
    vector <long long> ans;
    for (long long i = 2; i * i <= n; i++)
        if (n % i == 0)
    {
        ans.push_back(i);
        if (i * i != n)
            ans.push_back(n / i);
    }

    ans.push_back(n);

    return ans;
}

long long n;
void read()
{
    cin >> n;
}

void solve()
{
    auto div1 = find_divisors(n);
    auto div2 = find_divisors(n-1);

    int ans = 0;
    for (auto i: div1)
    {
        long long curr = n;
        while (curr % i == 0)
            curr /= i;

        if (curr % i == 1)
            ans++;
    }

    for (auto i: div2)
        if (n % i == 1)
        ans++;

    cout << ans << endl;
}

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

    read();
    solve();
}


Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <class T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

bool isPrime(ll num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    for (ll i = 3; i * i <= num; i += 2) {
        if (num % i == 0) { return false; }
    }

    return true;
};

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
bool is_integer(T x) {
    return std::floor(x) == x;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    int M1, D1, M2, D2;
    cin >> M1 >> D1 >> M2 >> D2;

    if (M1 + 1 == M2) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


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

#define y1 GKK
#define Set(a, b) memset(a, b, sizeof (a))
#define For(i, j, k) for (register int i = j; i <= k; ++ i)
#define Forr(i, j, k) for (register int i = j; i >= k; -- i)

using namespace std;

template <typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }

const int N = 40 + 2, inf = 0x3f3f3f3f;
char str[N][N];

int n, m, sx, sy, s[N][N], f[N][N][N][N];

inline int sum(int a, int b, int c, int d) {
	if (a > c || b > d) return 0;
	return s[c][d] - s[a - 1][d] - s[c][b - 1] + s[a - 1][b - 1];
}

int main() {

	cin >> n >> m;
	For(i, 1, n) scanf("%s", str[i] + 1);

	For(i, 1, n) For(j, 1, m) {
		if (str[i][j] == 'P') sx = i, sy = j;
		s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (str[i][j] == '#');
	}

	Set(f, inf), f[1][1][n][m] = 0;
	
	int ans = inf;

	For(x1, 1, sx) For(y1, 1, sy) Forr(x2, n, sx) Forr(y2, m, sy) {

		int t = min(min(sum(x1, y1, sx, sy), sum(sx, sy, x2, y2)), min(sum(sx, y1, x2, sy), sum(x1, sy, sx, y2)));
		ans = min(ans, f[x1][y1][x2][y2] + t);

		For(mx, x1, x2) For(my, y1, y2) {
			if (mx >= sx && my >= sy)
				chkmin(f[x1][y1][mx][my], f[x1][y1][x2][y2] + sum(x1, my + 1, mx, y2) + sum(mx + 1, y1, x2, my));

			if (mx >= sx && my <= sy)
				chkmin(f[x1][my][mx][y2], f[x1][y1][x2][y2] + sum(x1, y1, mx, my - 1) + sum(mx + 1, my, x2, y2));

			if (mx <= sx && my <= sy)
				chkmin(f[mx][my][x2][y2], f[x1][y1][x2][y2] + sum(x1, my, mx - 1, y2) + sum(mx, y1, x2, my - 1));

			if (mx <= sx && my >= sy)
				chkmin(f[mx][y1][x2][my], f[x1][y1][x2][y2] + sum(x1, y1, mx - 1, my) + sum(mx, my + 1, x2, y2));
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 12544
#include <bits/stdc++.h>
 
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
#define pll pair<ll,ll>

#define si set<int>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
using namespace std;

void solve(){
	int x,n;
	cin>>x>>n;
	set<int> s;
	for(int i=0,x;i<n;i++){
		cin>>x;
		s.insert(x);
	}
	int ans=1e6;
	for(int i=0;i<=100;i++){
		if(s.find(x-i)==s.end()){
			ans=min(ans,x-i);
			break;
		}
		else if(s.find(x+i)==s.end()){
			ans=min(ans,x+i);
			break;
		}
	}

	cout<<ans<<endl;

}
 
int main(){
    IOS;
    int q=1;
    
    while(q--){
        solve();
    }
}


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

dp = [[0]*(d+2) for i in range(c+1)]
dp[a][b] = 1

for i in range(a,c+1):
    for j in range(b,d+1):
        dp[i][j] += (dp[i][j-1]*i+dp[i-1][j]*j-dp[i-1][j-1]*(i-1)*(j-1))%mod
        dp[i][j]%=mod
print(dp[-1][-2]%mod)

Measured memory_bytes: 136884
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s , s1; //akasaka -> 0123456 len = 7 
    cin >> s ;
    s1 = s ;
    reverse(s1.begin(), s1.end());
    if(s1 == s) 
    {
        string s2 = "", s3 = "", s4, s5 ; 
        int mid = s.size()/2;
        for(int i = 0 ; i < mid ; i++) s2 += s[i];
        s4 = s2 ;
        reverse(s4.begin(), s4.end());
        if(s4 == s2)
        {
            for(int i = ( (s.size()+3) / 2 -  1) ; i < s.size() ; i++) s3 += s[i];
            s5 = s3;
            reverse(s5.begin(), s5.end());
            if(s5 == s3) cout << "Yes";
            else cout << "No";
        }
        else cout << "No";
    }
    else
    {
        cout << "No";
    }
}

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

int main(void){
  int A, B, cp;
  int x[3];
  cin >> A >> B;
  x[0] = A + B;
  x[1] = A - B;
  x[2] = A * B;
  for(int i = 0; i < 3; i++){
    if(i % 2 == 0){
      if(x[0] <= x[1]){
	cp = x[0];
	x[0] = x[1];
	x[1] = cp;
      }
    }
    else{
      if(x[1] <= x[2]){
	cp = x[1];
	x[1] = x[2];
	x[2] = cp;
      }
    }
  }
  cout << x[0] << "\n";
  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
char cf[1000000];
int d = 0, k = 0, j = 0, l = 0;
int main()
{
	cin >> cf;
	int ls = strlen(cf);
	for(int i = 0; i < ls;i ++)
	{
		if(cf[i] == 'C')
		{
			d ++;
			j = i;
		}
		else if(cf[i] == 'F')
		{ 
			k ++;
			if(l <= i) l = i;
		}
	}
	if(d > 0 && k > 0 && l > j) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        if (n == 0) {
            System.out.println(0);
            return;
        }
        StringBuilder sb = new StringBuilder();
        while (n < 0 || n > 1) {
            if (n >= 0) {
                sb.append(n % 2);
            } else {
                sb.append(-n % 2);
            }
            if (n % 2 != 0) {
                n = (n - 1) / -2;
            } else {
                n /= -2;
            }
        }
        sb.append(1);
        System.out.println(sb.reverse());
    }

}


Measured memory_bytes: 35736
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
//栈-计算面积 
int main()
{
	stack<int>s1;//s1 保存左边‘\’的位置 
	stack<pair<int,int> >s2;//s2 保存各处大面积
	int sum=0;
	char ch;
	for(int i=0;cin>>ch;i++)
	{
		if(ch=='\\')s1.push(i);
		else if(ch=='/'&&s1.size()>0)//***************&&s1.size()>0
		{
			int j=s1.top();
			s1.pop();
			sum+=i-j;
			int a=i-j;
			//s1.push(a);
			while(s2.size()>0&&j<s2.top().first)
			{
				a+=s2.top().second;
				s2.pop();
			}
			s2.push(make_pair(j,a));
		}
	}
	vector<int>ans;
	while(s2.size())
	{
		ans.push_back(s2.top().second);
		s2.pop();
	}
	reverse(ans.begin(),ans.end());
	cout<<sum<<endl<<ans.size();
	for(int i=0;i<ans.size();i++)
	{
		cout<<' '<<ans[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 3216
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int H = Integer.parseInt(S[0]);
    int W = Integer.parseInt(S[1]);
    int count = 0;
    for(int i = 0; i < H; i++){
      String T = sc.nextLine();
      for(int j = 0; j < W; j++){
        if(T.charAt(j) == '#'){
          count++;
        }
      }
    }
    System.out.println(count == (H + W - 1) ? "Possible" : "Impossible");
  }
}

Measured memory_bytes: 23764
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
A.sort()
ma = max(A)

prime = [0 for i in range(ma)]

for a in A:
    for j in range(a, ma+1, a):
        prime[j-1] += 1

cnt = 0
for i in A:
    if(prime[i-1] == 1):
        cnt += 1
       
print(cnt)

Measured memory_bytes: 34168
// https://beta.atcoder.jp/contests/abc112

#define SUBMIT

#include <bits/stdc++.h>
using namespace std;

template <typename T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
vector<T> divisor(T x) {
    vector<T> d;
    for (T i = 1; i * i <= x; ++i) {
        if (x % i == 0) {
            d.emplace_back(i);
            if (i * i != x) d.push_back(x / i);
        }
    }
    sort(d.begin(), d.end());
    return move(d);
}

int main() {
#ifdef SUBMIT
    auto& in = cin;
#else
    stringstream in(R"(3 14
)");
#endif
    unsigned long long n, m;
    in >> n >> m;

    decltype(m) ans = 1;
    auto d = divisor(m);
    for (auto di : d) {
        if (di * n <= m) ans = max(ans, di);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
from bisect import bisect_left
def main():
    n, *l = map(int, read().split())
    l.sort()
    r = n * (n - 1) * (n - 2) // 6
    for i1 in range(n - 2):
        for i2 in range(i1 + 1, n - 1):
            r -= (n - bisect_left(l, l[i1] + l[i2]))
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 73784
// --------------
// Tejas Pandey  |
// 28 - 06 - 19  |
// Atcoder #132  |
// --------------

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define vi vector<int>
typedef long long int ll;

int main (void)
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	char s[5];
	cin >> s;
	sort(s,s+4);
	if(s[0] == s[1] && s[2] == s[3] && s[1] != s[3])
	cout << "Yes";
	else
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

char s[200'009];
int f[10'009];

int main() {
  int n, mod;
  scanf("%d%d%s", &n, &mod, s);
  if (mod == 2 || mod == 5) {
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
      if ((int)(s[i] - '0') % mod == 0) {
        ans += i + 1;
      }
    }
    printf("%lld\n", ans);
    return 0;
  }
  for (int i = 0; i < mod; ++i) {
    f[i] = 0;
  }
  f[0] = 1;
  long long ans = 0;
  long long sum = 0;
  long long pw = 1;
  for (int i = n - 1; i >= 0; --i) {
    sum = (sum + (int)(s[i] - '0') * pw) % mod;
    int x = (int)((mod - sum) % mod);
    ans += f[x];
    ++f[x];
    pw = pw * 10 % mod;
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {

  int N, M, C; std::cin >> N >> M >> C;

  std::vector<int> B(M);
  for(int i=0; i<M; i++) std::cin >> B[i];

  int ans = 0;
  for(int i=0; i<N; i++) {
    int judge = C;
    for(int j=0; j<M; j++) {
      int A; std::cin >> A;
      judge += (A * B[j]);
    }
    if ( judge > 0 ) ans++;
  }

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

Measured memory_bytes: 256
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

void IO(){
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
#endif 
}

int R,C,K;
int memo[3001][3001][4];
int g[3001][3001];


int solve(int x, int y, int z){
	if(x==R && y==C) return 0;
	if(memo[x][y][z]!=-1) return memo[x][y][z];
	int ans=0;
	if(x<R) ans=max(ans,solve(x+1,y,0));
	if(x<R && g[x+1][y]!=-1) ans=max(ans,solve(x+1,y,1)+g[x+1][y]);
	if(y<C) ans=max(ans,solve(x,y+1,z));
	if(y<C && z<3 && g[x][y+1]!=-1) ans=max(ans,solve(x,y+1,z+1)+g[x][y+1]);
	return memo[x][y][z]=ans;
}

int32_t main(){
   boost;
   IO();

   memset(memo,-1,sizeof(memo)); 
   cin>>R>>C>>K;
   for(int i=1; i<=R; i++) for(int j=1; j<=C; j++) g[i][j]=-1;
   for(int i=1; i<=K; i++){
   	int x,y,v; cin>>x>>y>>v;
   	g[x][y]=v;
   }

   int ans=0;
   ans=max(ans,solve(1,1,0));
   if(g[1][1]!=-1) ans=max(ans,solve(1,1,1)+g[1][1]);
   cout << ans << endl;


   return 0;
}



Measured memory_bytes: 355748
//AtCoder ABC047 C - 一次元リバーシ / 1D Reversi
#include <bits/stdc++.h>
using namespace std;
using lli=int64_t;

int main() {
    string S;
    cin>>S;
    string cmp;
    char p=0;
    for(auto c:S){
        if(p!=c){
            cmp.push_back(c);
            p=c;
        }
    }
    cout<<cmp.size()-1<<endl;
    return 0;
}

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

using namespace std;

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

ll gcd(ll m,ll n){
    if(n == 0)return m;
    else if(m>n){return gcd(n,m%n);
    }else{return gcd(m,n%m);}}

ll lcm(ll m,ll n){return m*n/gcd(m,n);}

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    ll a,b;
    cin >>a>>b;

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << lcm(a,b) << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    vector<int> count(200001, 0);
    set<int> s;
    rep(i, n) {
        ll a; cin >> a;
        count[a]++;
        s.insert(a);
    }
    sort(RALL(count));
    int ans = 0;
    int tmp = max((int)s.size()-k, 0);
    for (int i=s.size()-1; i>k-1; --i) ans += count[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define rrep(i,n) for(int i = (n-1); i>=0; --i)
#define PI 3.14159265
#define INF 1e9
#define LINF 1e18
using namespace std;
using ll = long long;
void self_max(int &a,int b){
	a = max(a,b);
}
void self_min(int &a,int b){
	a = min(a,b);
}

int main(){
	string s,t; cin >> s >> t;

	if(s.size()> t.size()){
		string tmp = s;
		s = t;
		t = tmp;
	}

	int n = s.size(), m =t.size();

	int dp[n+1][m+1];

	rep(i,n+1) rep(j,m+1){
		if(i==0 or j==0 ){
			dp[i][j] = 0;
		}else{
			if(s[i-1] == t[j-1]){
				dp[i][j] = dp[i-1][j-1] + 1;
			}else{
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}

	int i = n,j=m;
	stack<int> st;
	while(i!=0 && j!=0){
		if(dp[i][j] == dp[i-1][j]){
			i--;
		}else if(dp[i][j] == dp[i][j-1]){
			j--;
		}else if(dp[i][j] == dp[i-1][j-1] +1){
			st.push((int)s[i-1]);
			i--;
			j--;
		}
	}

	while(!st.empty()){
		cout<< (char)st.top();
		st.pop();
	}

	return 0;
}

Measured memory_bytes: 35456
/*input

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

void solve(){
  	int n,d;
  	cin >> n >> d;
  	d*= d;
  	int ans = 0;
  	RE(i,n){
  		int x,y;cin >> x >> y;
  		if(x*x + y*y <= d)ans++;
  	}
  	cout << ans << endl;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 3640
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int cnt[4];

int main() {
	minit(cnt, 0);
	for (int i=0; i<3; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		++cnt[a];
		++cnt[b];
	}
	
	bool isok = true;
	for (int i=0; i<4; ++i) isok &= (cnt[i] <= 2);
	puts(isok ? "YES" : "NO");
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System .in));

		String str=br.readLine();
		long S=Integer.parseInt(str);
		long h=S/3600;
		long m=S%3600/60;
		long s=S%60;

		System.out.println(h+":"+m+":"+s);
	}

}


Measured memory_bytes: 24412
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int n;
vector<int> to[100010];
vector<int> col(100010,-1);
map<pair<int,int>, ll> cost;
void dfs(int now, int p, ll dis){
    for(auto u : to[now]){
        if(u == p){
            continue;
        }else{
            if(dis+cost[{now,u}] & 1){
                col[u] = 1;
                dfs(u, now, dis+cost[{now,u}]);
            }else{
                col[u] = 0;
                dfs(u, now, dis+cost[{now,u}]);
            }
        }
    }
}
int main(){
    cout << fixed << setprecision(10);
    cin >> n;
    rep(i,n-1){
        ll u,v,w;
        cin >> u >> v >> w;
        u--;
        v--;
        cost[{u,v}] = w;
        cost[{v,u}] = w;
        to[u].push_back(v);
        to[v].push_back(u);
    }
    col[0] = 0;
    dfs(0,-1,0);
    rep(i,n)cout << col[i] << endl;
    return 0;
}

Measured memory_bytes: 26660
import numpy as np
N = int(input())

txy = [[0,0,0]]
for i in range(N):
    txy.append(list(map(int,input().split())))

out='Yes'
for i in range(1,N+1):
    x = np.array(txy[i])
    y = np.array(txy[i-1])
    mv = abs(x-y)
    # print(mv)
    dam = mv[0] - (mv[1] + mv[2])
    if dam%2==1 or dam<0:
        out='No'

print(out)


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

int main(){
  int a, b;
  int sqare;
  
  cin >> a >> b;
  sqare = a*b;
  
  if(sqare % 2 == 0){
    cout << "Even" << endl;
  }else{
    cout << "Odd" << endl;
  }
  
  return 0;
}

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

int main()
{
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    ll count = A;
    if( A >= K )
        count = K;
    else
        count = 2*A + B - K;
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3600