akhauriyash/Code-Regression huggingface dataset:
N ,D = map(int,input().split())

X = [list(map(int, input().split())) for i in range(N)]
count=0

sum=0
#for i in range(N):
  #print(i,X[i])
#print('i','j','k','X[i][k]','X[i+j][k]')
for i in range(N):
  for j in range(1,N-i):
    for k in range(D):
      #print(i,j,k,' ',X[i][k],'     ',X[i+j][k],'     ',(X[i][k]-X[i+j][k])**2)
      sum=sum+(X[i][k]-X[i+j][k])**2
    #print(sum)
    if sum**(0.5)==int(sum**(0.5)):
      count=count+1
    sum=0    
    
print(count)

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;

ll gcd( ll a, ll b ){//最大公約数
    ll tmp;
    if( a < b ) { tmp = a; a = b; b = tmp; }
    if( b < 1 ) return -1;

    if( a % b == 0 ) return b;
    return gcd( b, a % b );
}
ll lcm(ll a, ll b){//最小公倍数
    return a * b / gcd(a, b);
}
ll sosuu(ll x){
    for(int i = 2; i < x; i++){
        if(x % i == 0) return false;
    }

    return true;
}


//入力


int main(){

    int a, b;
    cin >> a >> b;

    if(a > b){
        for(int i = 0; i < a; i++){
            cout << b;
        }
        cout << endl;
    }
    else{
        for(int i= 0; i < b; i++){
            cout << a;
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M=702;
bool adj[M][M],vis[M];
int col[M],dp[M],tp[M],n;
set<int> st[2];
void dfs(int x,int cl)
{
	col[x]=cl;
	vis[x]=1;
	st[cl].insert(x);
	for(int i=1;i<=n;i++)
	{
		if(i==x || adj[x][i])
			continue;
		if(vis[i]==0)
			dfs(i,1-cl);
		else if(col[i]==cl)
		{
			cout<<"-1\n";
			exit(0);
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int m;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		adj[u][v]=1;
		adj[v][u]=1;
	}
	dp[0]=1;
	for(int i=1;i<=n;i++)
	{
		if(vis[i])
			continue;
		st[0].clear();
		st[1].clear();
		dfs(i,0);
		memset(tp,0,sizeof(tp));
		for(int j=sz(st[0]);j<=n;j++)
			if(dp[j-sz(st[0])])
				tp[j]=1;
		for(int j=sz(st[1]);j<=n;j++)
			if(dp[j-sz(st[1])])
				tp[j]=1;			
		for(int j=0;j<=n;j++)
			dp[j] = tp[j];
	}
	int res=(n*(n-1))/2;
	for(int i=0;i<=n;i++)
	{
		if(dp[i])
		{
			int x=i,y=n-i;
			res = min(res,(x*(x-1))/2+(y*(y-1))/2);
		}
	}
	cout<<res<<"\n";
	return 0;
}

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

struct StCoord
{
  StCoord() : m_nx(0), m_ny(0), m_nOpe(0) { }

  int m_nx;
  int m_ny;
  int m_nOpe;
};

void fnInput(vector<StCoord>& rvoCoord, StCoord& roCrdEnd)
{
  int nCrdSiz;
  cin >> roCrdEnd.m_nx >> roCrdEnd.m_ny >> nCrdSiz;

  rvoCoord.resize(nCrdSiz);
  for (StCoord& roCoord : rvoCoord)
    cin >> roCoord.m_nx >> roCoord.m_ny >> roCoord.m_nOpe;
}

int fnRectPaint(const vector<StCoord>& cnrvoCoord,
                 StCoord& roCrdBgn, StCoord& roCrdEnd)
{
  for (StCoord oCoord : cnrvoCoord)
    if      (oCoord.m_nOpe == 1)  roCrdBgn.m_nx = max(roCrdBgn.m_nx, oCoord.m_nx);
    else if (oCoord.m_nOpe == 2)  roCrdEnd.m_nx = min(roCrdEnd.m_nx, oCoord.m_nx);
    else if (oCoord.m_nOpe == 3)  roCrdBgn.m_ny = max(roCrdBgn.m_ny, oCoord.m_ny);
    else if (oCoord.m_nOpe == 4)  roCrdEnd.m_ny = min(roCrdEnd.m_ny, oCoord.m_ny);

  if (roCrdBgn.m_nx >= roCrdEnd.m_nx ||
      roCrdBgn.m_ny >= roCrdEnd.m_ny   )
    return 0;
  else
    return (roCrdEnd.m_nx - roCrdBgn.m_nx) * (roCrdEnd.m_ny - roCrdBgn.m_ny);
}

int main()
{
  vector<StCoord> voCoord;
  StCoord oCrdBgn, oCrdEnd;

  fnInput(voCoord, oCrdEnd);
  cout << fnRectPaint(voCoord, oCrdBgn, oCrdEnd) << endl;

  return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
ans = 0
A = [str(i).zfill(3) for i in range(0,1000)]

cnt = 0
for v in A:
    id_1 = s.find(v[0])
    if id_1 == -1:
        continue
    id_2 = s.find(v[1], id_1 + 1)
    if id_2 == -1:
        continue
    id_3 = s.find(v[2], id_2 + 1)
    if id_3 == -1:
        continue
    cnt += 1

print(cnt)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,num=1;
  cin >> n;
  while(num<n) {
    num*=2;
  }
  if(num<=n) {
    cout << num << endl;
  }
  else {
    cout << num/2 << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][][] room = new int[4][3][10];
        	for(int a=0;a<n;a++){
                int i = sc.nextInt();
        		int j = sc.nextInt();
        		int k = sc.nextInt();
        		int v = sc.nextInt();
        			room[i-1][j-1][k-1] += v;
            }
         for(int i=0;i<4;i++){
            for(int j=0;j<3;j++){
                for(int k=0;k<10;k++){
                    System.out.print(" " + room[i][j][k]);
                }
                System.out.println();
            }
             if(i<3){
             for(int c=0;c<20;c++){
            	 System.out.print("#");
             }
             System.out.println();
            }
         }
    }
}


Measured memory_bytes: 29796
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>

int main()
{
	int k, a, b;	
  	std::cin >> k >> a >> b;
  
    for(int i = k; i <= b; i += k)
    {
       if(a <= i && i <= b)
       {
         	std::cout << "OK" << std::endl;
         	return 0;
       }
    }
  
  	std::cout << "NG" << std::endl;
    return 0;
}


Measured memory_bytes: 3636
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        private const long COMDIV = 1000000007;

        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var prices = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();
            Console.WriteLine(prices.Take(NK[1]).Sum());
        }
    }
}

Measured memory_bytes: 28568
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    let s = n * (n + 1) / 2;
    let t = v.iter().cloned().sum::<usize>();
    if t % s != 0 {
        println!("NO");
        return;
    }
    let p = t / s;
    let mut w = v.clone();
    w.push(v[0]);
    for i in 0..n {
        if (w[i] + p) % n != w[i + 1] % n || w[i] + p < w[i + 1] {
            println!("NO");
            return;
        }
    }
    println!("YES");
}


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

ll mod = 1e9+7;

int main(){
    int N;
    cin >> N;
    vector<int> dif(N+1, 0);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        dif[a]++;
    }
    if (N % 2 == 0) {
        for (int i = 1; i <= N; i+=2) {
            if (dif[i] != 2) {
                cout << 0 << endl;
                return 0;
            }
        }
    } else {
        if (dif[0] != 1) {
            cout << 0 << endl;
            return 0;
        }
        for (int i = 2; i < N; i+=2) {
            if (dif[i] != 2) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    ll ans = 1;
    for (int i = 0; i < N / 2; i++) ans = ans * 2 % mod;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
template<typename T> T ctmax(T &x, const T &y){ return x = max(x, y); }
template<typename T> T ctmin(T &x, const T &y){ return x = min(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n;
	cin >> n;
	vector<pair<int, int>> a(n);
	for(int i = 0; i < n; ++ i){
		cin >> a[i].first, a[i].second = i;
	}
	sort(a.begin(), a.end());
	vector<int> res(n);
	for(int i = 0; i < n / 2; ++ i){
		res[a[i].second] = a[n / 2].first;
	}
	for(int i = n / 2; i < n; ++ i){
		res[a[i].second] = a[n / 2 - 1].first;
	}
	for(int i = 0; i < n; ++ i){
		cout << res[i] << "\n";
	}
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 4608
// How many ways?
// 所要時間 分
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()

int main() {

    while(true){
        int n, x;
        cin >> n >> x;
        if(n == 0 && x == 0){
            break;
        }
        int cnt = 0;
        for(int i=1; i<n-1; ++i){
            for(int j=i+1; j<n; ++j){
                int dif = x - i - j;
                if(dif > j && dif <= n){
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }

    return 0;
}


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; cin >>n;
	VI a(n);
	rep(i, n) cin >>a[i];
	vector<pii> ans;
	int imx = max_element(all(a)) - a.begin();
	int imn = min_element(all(a)) - a.begin();
	int sw = 1;
	if(abs(a[imx]) >= abs(a[imn])){
		rep(i, n) if(a[i] != a[imx]){
			a[i] += a[imx]; ans.emplace_back(imx+1, i+1);
		}
	}else{
		rep(i, n) if(a[i] != a[imn]){
			a[i] += a[imn]; ans.emplace_back(imn+1, i+1);
		}
		sw=0;
	}
	if(sw){
		rep(i, n-1){
			a[i+1] += a[i]; ans.emplace_back(i+1, i+2);
		}
	}else{
		repr(i, n-1, 1){
			a[i-1] += a[i]; ans.emplace_back(i+1, i);
		}
	}
	//for(auto x :a) cerr<<x<<" "; dbg();	
	cout<< sz(ans)<<"\n";
	for(auto x :ans) cout<<x.first<<" "<<x.second<<"\n";
	return 0;
}


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

int main(){
  int s[14]={},h[14]={},c[14]={},d[14]={};
  char des;
  int num,n,i;
  scanf("%d",&n);
  for(i=1;i<=2*n;i++){
    scanf("%c %d",&des,&num);
    if(des=='S'){
      //      printf("des=%c, num = %d\n",des,num);
      s[num] = 1;
    }else if(des=='H'){
      //printf("des=%c, num = %d\n",des,num);
      h[num] = 1;
    }else if(des=='C'){
      //printf("des=%c, num = %d\n",des,num);
      c[num] = 1;
    }else if(des=='D'){
      //printf("des=%c, num = %d\n",des,num);
      d[num] = 1;
    }
    //printf("s[13]=%d\n",s[13]);
  }

  for(i=1;i<=13;i++){
    if(s[i]!=1){
      printf("S %d\n",i);
    }
  }

   for(i=1;i<=13;i++){
    if(h[i]!=1){
      printf("H %d\n",i);
    }
  }

   for(i=1;i<=13;i++){
    if(c[i]!=1){
      printf("C %d\n",i);
    }
  }

   for(i=1;i<=13;i++){
    if(d[i]!=1){
      printf("D %d\n",i);
    }
  }

   return 0;
  
}



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

using namespace std;

#define ll long long

#define DEBUG (0)

int main()
{
  ll N = 0, K = 0;
  cin >> N >> K;

  vector<ll>H(N,0);
  ll sum = 0;

  for(ll i = 0; i < N; i++){
    cin >> H[i];
  }

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

  for(ll i = 0; i < N-K; i++){
    sum += H[i];
  }

  cout << sum << "\n";

#if DEBUG
  for(ll i = 0; i < N; i++){
    cout << H[i] << endl;
  }
#endif



}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#define ll long long
using namespace std;
int a[100010];
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);
	sort(a, a + n);
	printf("%d\n", a[(n / 2)] - a[(n / 2)-1]);
}

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

using namespace std;

int main() {
    int n, d;
    cin >> n >> d;
    int count = 0;
    for (int i = 0; i < n; i++) {
        long long x, y;
        x = 0;
        y = 0;
        cin >> x >> y;
        double ans;
        ans = 0;
        ans = std::sqrt(x * x + y * y);
        if (ans <= d) {
            count += 1;
        } else {
            count += 0;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;
#define endl '\n'
#define pb(a) push_back(a)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) int(x.size())
#define IOS ios::sync_with_stdio(0);


int main() {
	char ch;
	cin>>ch;
	if(isupper(ch)) putchar('A');
	else putchar('a');
	return 0;
	
} 

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

const int MAX = 200000 + 1;
const int SENTINEL = 2000000000;
int a[MAX];
int L[MAX/2+2], R[MAX/2+2];

long long merge(int a[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    L[n1] = R[n2] = SENTINEL;
    for (int i = 0; i < n1; ++i) L[i] = a[left+i];
    for (int i = 0; i < n2; ++i) R[i] = a[mid+i];
    long long count = 0;

    int p = 0, q = 0;
    for (int k = left; k < right; ++k) {
        if (L[p] <= R[q]) {
            a[k] = L[p++];
        } else {
            a[k] = R[q++];
            count += n1 - p;
        }
    }

    return count;
}

long long merge_sort(int a[], int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        long long v1 = merge_sort(a, left, mid);
        long long v2 = merge_sort(a, mid, right);
        long long v3 = merge(a, left, mid, right);
        return v1 + v2 + v3;
    } else return 0;
}

int
main(int argc, const char *argv[])
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    long long v = merge_sort(a, 0, n);
    cout << v << endl;

    return 0;
}

Measured memory_bytes: 4652
#include <iostream>
using namespace std;
int main(){
  long long in;
  int count = 0;
  cin >> in;
  for(int a=1; a <= in; a++){
      for(int b = 1;b <= (in/a); b++){
          int c = in - a*b;
          if(c != 0)  count++;
      }
  }
  cout << count << endl;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
    ll n, m;
    string s, t;
    cin >> n >> m >> s >> t;
    for (ll i = 0; i < gcd(n, m);i++) {
        if(s[n*i/gcd(n,m)]!=t[m*i/gcd(n,m)]){
            cout << "-1" << endl;
            return 0;
        }
    }
    cout << lcm(n, m) << endl;
}

Measured memory_bytes: 3764
DBG = !true
n,m = gets.split.map{|z| z.to_i}
child = Array.new(n)
child.map!{[]}
parent = Array.new(n)
parent.map!{[]}
for i in 0...(n-1+m)
  #a,b = gets.split.map{|z| z.to_i}
  a,b = gets.split
  a = a.to_i - 1
  b = b.to_i - 1
  child[a] << b
  parent[b] << a
end
print parent if DBG

nchild = Array.new(n)
height = Array.new(n,-1)
height_done = Array.new(n,false)
proc = []
for i in 0...n
  nchild[i] = child[i].size
  if child[i].size == 0
    proc << i
    height[i] = 0
  end
end

while !proc.empty?
  i = proc.shift
  for j in parent[i]
    nchild[j] -= 1
    proc << j if nchild[j] == 0  #!height_done[j]
    height_done[j] = true
    height[j] = height[i] + 1 if height[j] < height[i] + 1
  end
end

ht_suf = []
for i in 0...n
  ht_suf << [i, height[i]]
end
ht_suf.sort_by!{|z| z[1]}

realParent = Array.new(n,-1)
for i in 0...n
  j = ht_suf[i][0]
  if parent[j].size == 1
    realParent[j] = parent[j][0]
  elsif parent[j].size > 1
    mnht = 9999999
    mnsuf = -1
    for p in parent[j]
      if height[p] < mnht
        mnht = height[p]
        mnsuf = p
      end
    end
    realParent[j] = mnsuf
  end
  # do nothing if parent.sz == 0 i.e. root -> -1
end

for i in 0...n
  puts "#{realParent[i]+1}"
end


Measured memory_bytes: 31504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN=2e3+5;
const ll MOD=1e9+7;
const ll INF=1e18;
const double eps=1e-10;
ll n,m,s[MAXN],t[MAXN],dp[MAXN][MAXN];
ll add(ll x,ll y)
{
    if(y<0)
    {
        y+=MOD;
    }
    ll ret=x+y;
    if(ret>=MOD)
    {
        return ret-MOD;
    }
    return ret;
}
ll mul(ll x,ll y)
{
    return x*y%MOD;
}
void solve()
{
    for(ll i=0;i<=n;i++)
    {
        dp[i][0]=1;
    }
    for(ll i=0;i<=m;i++)
    {
        dp[0][i]=1;
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            if(s[i]==t[j])
            {
                dp[i][j]=add(dp[i][j],mul(dp[i-1][j-1],2));
                dp[i][j]=add(dp[i][j],add(dp[i][j-1],-dp[i-1][j-1]));
                dp[i][j]=add(dp[i][j],add(dp[i-1][j],-dp[i-1][j-1]));
            }
            else
            {
                dp[i][j]=add(add(dp[i-1][j],dp[i][j-1]),-dp[i-1][j-1]);
            }
        }
    }
    printf("%lld\n",dp[n][m]);
}
int main()
{
//    freopen("c://duipai//data.txt","r",stdin);
//    freopen("c://duipai//wa.txt","w",stdout);
    while(~scanf("%lld %lld",&n,&m))
    {
//        string ss;
//        cin>>ss;
//        cout<<ss<<endl;
        for(ll i=1;i<=n;i++)
        {
            scanf("%lld",&s[i]);
        }
        for(ll i=1;i<=m;i++)
        {
            scanf("%lld",&t[i]);
        }
        solve();
    }
}
/*

*/


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

int main() {
    int y, m, d;
    char c1, c2;  cin >> y >> c1 >> m >> c2 >> d;
    cout << (m <= 4 ? "Heisei" : "TBD") << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

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;
}

/*
 * ref. http://drken1215.hatenablog.com/entry/2018/06/08/210000
 *
 * usage:
 *
 * Combination *c;
 * 
 * const int MOD = 1000000007;
 * const int MAX_N = 100000;
 * 
 * int main(void) {
 *     int n, k;
 *     cin >> n >> k;
 *     c = new Combination(2 * MAX_N, MOD);
 *     cout << c->com(n + k - 1, k) << endl;
 *     delete(c);
 *     return 0;
 * }
 */
class Combination {
    public:
        const int max;
        const int mod;
        vector<ll> fac, finv, inv;

        Combination(int max, int mod) : max(max), mod(mod), fac(max), finv(max), inv(max) {
            init();
        }

        ll com(int n, int k) {
            if (n < k) return 0LL;
            if (n < 0 || k < 0) return 0LL;
            // return (fac[n] * ((finv[k] * finv[n - k]) % mod)) % mod;
            return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
        }

    private:
        void init() {
            fac[0] = fac[1] = 1;
            finv[0] = finv[1] = 1;
            inv[1] = 1;
            for (int 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;
            }
        }
};

Combination *c;

const int MOD = 1000000007;
const int MAX_N = 4000;

ll solve(const int N, const int K, const int i) {
    ll ans = (c->com(N - K + 1, i)) % MOD;
    ans = (ans * c->com(K - 1, i - 1)) % MOD;
    return ans;
}

int main(void) {
    int N, K;
    cin >> N >> K;
    c = new Combination(2 * MAX_N, MOD);

    for (int i = 1; i <= K; i++) {
        cout << solve(N, K, i) << endl;;
    }

    delete(c);
    return 0;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	private static int counter = 0;
	private static int upperOrder = 0;
	private static int lowerOrder = 0;
	
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] nums = new int[n];
		
		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		
		Arrays.sort(nums);
		int pos = 0;
		int res = 0;
		while (k > 0) {
			res += nums[pos];
			pos++;
			k--;
		}
		
		System.out.println(res);
	}
	
	public static void permuteHelper(int[] nums, int start, int end, List<String> ans) {
        if (start == end) {
            String str = "";
            for (int num: nums) {
                str += ("" + num);
            }
            ans.add(str);
        } else {
            for (int i = start; i < end; i++) {
                swap(nums, i, start);
                permuteHelper(nums, start + 1, end, ans);
                swap(nums, i, start);
            }
        }
    }
	
	static public void swap(int[] nums, int i, int j) {
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }
	
	static boolean isEqual(int[] a, int[] b) {
		for (int i = 0; i < a.length; i++) {
			if (a[i] != b[i]) {
				return false;
			}
		}
		return true;
	}
	
	static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


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

int main(){
    string s;
    cin >> s;
    int tuki = (s[5] - '0')*10 + (s[6] - '0');
    if (tuki <= 4) {
        cout << "Heisei" << endl;
    }
    else
    {
        cout << "TBD" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    double t, x;
    cin >> t >> x;
    cout << precise(10) << t / x << endl;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin>>n;
	for(long long i=-5000;i<5000;i++){
		for(long long j=-5000;j<5000;j++){
			if(n==(i*i*i*i*i)-(j*j*j*j*j)){
				cout<<i<<" "<<j<<endl;
				return(0);
			}

		}
	}
  return(0);
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long int lli;
const lli mod = 1e9+7;
const lli inf = 1e18;
typedef pair<int ,int> pii;
typedef pair<lli, lli> pll;

lli ExGCD(lli a, lli b, lli &x, lli &y){
    lli d=a;
    x=1; y=0;
    if(b!=0){ d=ExGCD(b, a%b, y, x); y-=a/b*x; }
    return d;
}
lli inverse(lli a){
    lli x,y;
    ExGCD(a, mod, x, y);
    return x>0? x: mod+x;
}

lli fact[2000001];
void maketable(){
    fact[0] = 1;
    for(int i=0; i<2000000; i++){
        fact[i+1] = fact[i]*(i+1) %mod;
    }
}
lli combination(lli n, lli r){
    return fact[n] *inverse(fact[n-r]) %mod *inverse(fact[r]) %mod;
}

lli modpow(lli a, lli p){
    lli ret = 1;
    for(int i=63; i>=0; i--){
        ret *= ret;
        ret %= mod;
        if((1LL<<i & p) != 0){
            ret *= a;
            ret %= mod;
        }
    }
    return ret;
}

int main(){
    maketable();
    lli n;
    string s;
    cin >> n >> s;
    lli m = s.length();
    lli ans = 0;
    for(int i=0; i<=n; i++){
        lli sub = modpow(26, i);
        sub *= modpow(25, n-i) *fact[n-i+m-1] %mod *inverse(fact[n-i]) %mod *inverse(fact[m-1]) %mod;
        sub %= mod;
        ans += sub;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 20896
N,M=map(int,input().split())
P_list=[int(p) for p in input().split()]

class Unionfind:
  def __init__(self,n):
    self.Tree=[i for i in range(n)]
  
  def find(self,x):
    if x==self.Tree[x]:
      return x
    else:
      root=self.find(self.Tree[x])
      self.Tree[x]=root
      return root
    
  def unite(self,x,y):
    s1=self.find(x)
    s2=self.find(y)
    if s1==s2:
      pass
    else:
      self.Tree[s1]=s2
    
T=Unionfind(N)
for m in range(M):
  x,y=map(int,input().split())
  T.unite(x-1,y-1)
ans=0
for i in range(N):
  if T.find(P_list[i]-1)==T.find(i):
    ans+=1
print(ans)

Measured memory_bytes: 13812
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long InF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


int main() {
	int n, a, b;
	cin >> n;
	a = n % 100; b = (n - a) / 100;
	string ans;
	if (1 <= b && b <= 12) { if (1 <= a && a <= 12) { ans = "AMBIGUOUS"; } else { ans = "MMYY"; } }else { if (1 <= a && a <= 12) { ans = "YYMM"; } else { ans = "NA"; } }cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int n,d[100],a=0;
  cin>>n;
  for(int i=1;i<=n;i++)
    cin>>d[i];
  sort(d,d+n+1);
  for(int i=1;i<=n;i++){
    if(d[i]!=d[i+1])
      a++;
  }
  cout<<a<<endl;
    
  return(0);
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {

	var n int
	fmt.Scan(&n)

	s := make([]int, n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()

	for i, v := range strings.Split(sc.Text(), " ") {
		s[i], _ = strconv.Atoi(v)
	}

	result := true
	for _, i := range s {
		if i%2 == 1 {
			continue
		}
		if i%3 != 0 && i%5 != 0 {
			result = false
		}
	}
	if result {
		fmt.Println("APPROVED")
	} else {
		fmt.Println("DENIED")
	}
}


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

int main(){
    ll a;
    double b;
    cin >> a >> b;
    ll ib = b * 100 + 0.5;
    a *= ib;
    a /=100;
    cout << a << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{
    int n, x, y;    cin >> n >> x >> y;

    vector <int> Ans(n);

    for(int i = 1; i < n; i++)
    {
        for(int j = i + 1; j <= n; j++)
        {
            int Dist = min({abs(j - i), abs(i - x) + 1 + abs(j - y), abs(i - y) + 1 + abs(j + x)});

            Ans[Dist]++;
        }
    }

    for(int k = 1; k < n; k++)  printf("%d\n", Ans[k]);
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <queue>
using namespace std;

namespace zyt
{
	template<typename T>
	inline bool read(T &x)
	{
		char c;
		bool f = false;
		x = 0;
		do
			c = getchar();
		while (c != EOF && c != '-' && !isdigit(c));
		if (c == EOF)
			return false;
		if (c == '-')
			f = true, c = getchar();
		do
			x = x * 10 + c - '0', c = getchar();
		while (isdigit(c));
		if (f)
			x = -x;
		return true;
	}
	template<typename T>
	inline void write(T x)
	{
		static char buf[20];
		char *pos = buf;
		if (x < 0)
			putchar('-'), x = -x;
		do
			*pos++ = x % 10 + '0';
		while (x /= 10);
		while (pos > buf)
			putchar(*--pos);
	}
	typedef long long ll;
	const int N = 1e3 + 10, P = N << 1, M = P * 5, INF = 0x3f3f3f3f;
	const ll LINF = 0x3f3f3f3f3f3f3f3fll;
	struct edge
	{
		int to, w, c, next;
	}e[M << 1];
	int n, s, t, p1, p2, p3, p4, head[P], ecnt;
	void add(const int a, const int b, const int c, const int d)
	{
		e[ecnt] = (edge){b, c, d, head[a]}, head[a] = ecnt++;
	}
	void addtw(const int a, const int b, const int c, const int d)
	{
		add(a, b, c, d), add(b, a, 0, -d);
	}
	namespace EK
	{
		int pre[P];
		ll dis[P];
		bool vis[P];
		bool SPFA()
		{
			static queue<int> q;
			memset(pre, -1, sizeof(int[t + 1]));
			memset(vis, 0, sizeof(bool[t + 1]));
			for (int i = 1; i <= t; i++)
				dis[i] = -LINF;
			q.push(s);
			dis[s] = 0;
			vis[s] = true;
			while (!q.empty())
			{
				int u = q.front();
				q.pop();
				vis[u] = false;
				for (int i = head[u]; ~i; i = e[i].next)
				{
					int v = e[i].to;
					if (e[i].w && dis[v] < dis[u] + e[i].c)
					{
						dis[v] = dis[u] + e[i].c, pre[v] = i;
						if (!vis[v])
							q.push(v), vis[v] = true;
					}
				}
			}
			return dis[t] > -LINF;
		}
		ll EK()
		{
			ll ans = 0;
			while (SPFA())
			{
				int i = pre[t], minn = INF;
				while (~i)
					minn = min(minn, e[i].w), i = pre[e[i ^ 1].to];
				i = pre[t];
				while (~i)
					e[i].w -= minn, e[i ^ 1].w += minn, i = pre[e[i ^ 1].to];
				ans += (ll)minn * dis[t];
			}
			return ans;
		}
	}
	int work()
	{
		read(n);
		p1 = (n << 1) + 1, p2 = p1 + 1, p3 = p2 + 1, p4 = p3 + 1, s = p4 + 1, t = s + 1;
		memset(head, -1, sizeof(int[t + 1]));
		for (int i = 1; i <= n; i++)
		{
			int x, y, c;
			read(x), read(y), read(c);
			addtw(i, p1, c, x + y);
			addtw(i, p2, c, x - y);
			addtw(i, p3, c, -x + y);
			addtw(i, p4, c, -x - y);
			addtw(s, i, c, 0);
		}
		for (int i = 1; i <= n; i++)
		{
			int x, y, c;
			read(x), read(y), read(c);
			addtw(p1, i + n, c, -x - y);
			addtw(p2, i + n, c, -x + y);
			addtw(p3, i + n, c, x - y);
			addtw(p4, i + n, c, x + y);
			addtw(i + n, t, c, 0);
		}
		write(EK::EK());
		return 0;
	}
}
int main()
{
	return zyt::work();
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 0,i;
  for(i=0;i<n;++i) {
    if( s[i] == 'x' ) {
      ++cnt;
      if( cnt == 2 ) break;
    } else {
      cnt = 0;
    }
  }
  cout << i << endl;
  return 0;
}

Measured memory_bytes: 3308
using System;

namespace ITP1_5_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= n; i++)
            {
                if (i % 3 == 0 || i.ToString().Contains("3")) Console.Write(" " + i);
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 6424
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n,m;cin>>n>>m;
    bool ka[n+1];
    fill(ka,ka+n+1,false);
    ka[1]=true;
    ll ko[n+1];
    fill(ko,ko+n+1,1);
    rep(i,0,m){
        ll a,b;cin>>a>>b;
        ko[a]--;
        ko[b]++;
        if(ka[a])ka[b]=true;
        if(ko[a]==0)ka[a]=false;
    }
    int ans=0;
    rep(i,1,n+1)ans+=ka[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main(void) {
  int N;
  cin >> N;
  vector<P> A(N);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A[i] = P(a, i + 1);
  }
  sort(A.begin(), A.end());
  cout << A[0].second;
  for (int i = 1; i < N; i++) {
    cout << " " << A[i].second;
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ll long long
#define pb push_back
#define F first
#define S second
#define ld long double
#define vi vector<ll>
const int INF = 1e9;
const int N = 100005;
vi h(N, 0);
vi dp(N, 0);
void solve() {
	ll n; cin >> n;
	for (ll i = 0; i < n; i++) cin >> h[i];

	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for (ll i = 2; i < n; i++) {
		dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
	}
	cout << dp[n - 1];
}

int main() {

	FASTIO;
/*
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
*/
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	int around[3];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> around[j];
		}
		for (int j = 0; j < 2; j++){
			for (int k = 0; k < 2; k++) {
				if (around[k] < around[k + 1])swap(around[k], around[k + 1]);
			}
		}
		if (around[0] * around[0] == around[1] * around[1] + around[2] * around[2])cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

Measured memory_bytes: 2980
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
map<int,int> dp;
int f(int x)
{
	if(dp[x])return dp[x];
	return dp[x]=(f(x-1>>1)+f(x>>1)+f(x-2>>1))%mod;
}
signed main()
{
	dp[0]=1;
	dp[1]=2;
	int n;
	cin>>n;
	cout<<f(n);
}

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

#define MAX 1000000
#define OVER 10000

int main(void) {
    int sieve[MAX+1]={0},count=0,i,j,num,sum[OVER+1]={0};
    sieve[1]=1;
    for (i=2; ; i++) {
        if (sieve[i]==0) {
            for (j=2*i; j<=MAX; j+=i) sieve[j]=1;
            sum[count+1]=i+sum[count];
            count++;
        }
        if (count==OVER) break;
    }
    while (1) {
        scanf("%d",&num);
        if (num==0) break;
        printf("%d\n",sum[num]);
    }
    return 0;
}

Measured memory_bytes: 4552
#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 IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
const ll md = 1e9 + 7;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
 
ll po(ll x,ll n){
    if(n==0) return 1;
    if(n%2==1) return (x*po(x,n-1))%md;
    else {
        ll k=po(x,n/2);
        return (k*k)%md;
    }
}
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return po(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
 
int32_t main(){
    IOS;
    ll i,j,k,n,m=1;
    cin >> n;
    if(n<2) cout <<"0\n";
    else if(n==2) cout <<"2\n";
    else {
        // n -= 2;
        m = po(10,n);
        k = ( ((2*po(9,n))%md-po(8,n) )%md+md) %md;
        m = (m - k +md )%md;
         // k = (n*(n-1))%md;
         // m = (m*k)%md;
         cout << m <<"\n";
    }
} 

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

int main() {
  int A, B;
  cin >> A >> B;
  if(A>=13){
    cout << B << endl;
  }
  else if(6 <= A){
    cout << B/2 << endl;
  }
  else{
    cout << 0 << endl;
  }

}


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

#define NIL -1

struct Node { int parent, right, left; };
Node T[30];
int H[30];
int D[30];

int getSibling(int u) {
    if (T[u].parent == NIL) return NIL;
    if (T[T[u].parent].left != NIL && T[T[u].parent].left != u) return T[T[u].parent].left;
    if (T[T[u].parent].right != NIL && T[T[u].parent].right != u) return T[T[u].parent].right;
    return NIL;
}

int getDegree(int u) {
    int deg = 0;
    if (T[u].left != NIL) { deg++; }
    if (T[u].right != NIL) { deg++; }
    return deg;
}

void rec(int u, int d) {
    D[u] = d;
    if (T[u].right != NIL) { rec(T[u].right, d + 1); }
    if (T[u].left != NIL) { rec(T[u].left, d + 1); }
}

int getHeight(int u, int h) {
    int hr = 0, hl = 0;
    if (T[u].right != NIL) { hr = getHeight(T[u].right, h + 1) + 1; }
    if (T[u].left != NIL) { hl = getHeight(T[u].left, h + 1) + 1; }
    return H[u] = max(hr, hl);
}

void print(int u) {
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "sibling = " << getSibling(u) << ", ";
    cout << "degree = " << getDegree(u) << ", ";
    cout << "depth = " << D[u] << ", ";
    cout << "height = " << H[u] << ", ";
    if (T[u].parent == NIL) { cout << "root" << endl; }
    else if (T[u].left != NIL || T[u].right != NIL) { cout << "internal node" << endl; }
    else { cout << "leaf" << endl; }
}

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        T[i].parent = T[i].left = T[i].right = H[i] = D[i] = NIL;
    }
    for (int i = 0; i < n; ++i) {
        int id, right, left; cin >> id >> left >> right;
        T[id].right = right;
        T[id].left = left;
        if (left != NIL) { T[left].parent = id; }
        if (right != NIL) { T[right].parent = id; }
    }
    int u = 0;
    for (int i = 0; i < n; ++i) { if (T[i].parent == NIL) { u = i; } }
    rec(u, 0);
    getHeight(u, 0);
    for (int i = 0; i < n; ++i) { print(i); }
}

Measured memory_bytes: 3092
def main():
    H, W = (int(i) for i in input().split())
    c = [input() for i in range(H)]
    dp = [[10**3]*W for _ in range(H)]
    if c[0][0] == "#":
        dp[0][0] = 1
    else:
        dp[0][0] = 0
    for h in range(H):
        for w in range(W):
            if c[h][w] == ".":
                if w < W-1 and c[h][w+1] == ".":
                    dp[h][w+1] = min(dp[h][w+1], dp[h][w])
                elif w < W-1 and c[h][w+1] == "#":
                    dp[h][w+1] = min(dp[h][w+1], dp[h][w] + 1)
                if h < H-1 and c[h+1][w] == ".":
                    dp[h+1][w] = min(dp[h+1][w], dp[h][w])
                elif h < H-1 and c[h+1][w] == "#":
                    dp[h+1][w] = min(dp[h+1][w], dp[h][w] + 1)
            else:
                if w < W-1:
                    dp[h][w+1] = min(dp[h][w+1], dp[h][w])
                if h < H-1:
                    dp[h+1][w] = min(dp[h+1][w], dp[h][w])
    print(dp[H-1][W-1])
    # print(*dp, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 42480
import itertools
from pprint import pprint
n,m = map(int,input().split())
klist = []
slist = []
for i in range(m):
    s = list(map(int,input().split()))
    klist.append(s[0])
    slist.append(s[1:])
plist = list(map(int,input().split()))
kklist = klist[:]

status = [(0, 1) for _ in range(n)]
system_status = list(itertools.product(*status))
ans = 0
for i in range(len(system_status)):#順列列挙の中の順列
    for j in range(n):#注目してる順列の要素
        for k in range(m):#slist
            if system_status[i][j] == 1 and j+1 in slist[k]:
                klist[k] -= 1
    for l in range(m):
        if (kklist[l] - klist[l]) % 2 != plist[l]:
            klist = kklist[:]
            break
    else:
        ans += 1
        klist = kklist[:]
print(ans)


Measured memory_bytes: 42352
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	vector<vector<int>> bingo(3, vector<int>(3));
	vector<vector<bool>> is_open(3, vector<bool>(3, false));
	rep(i, 3) rep(j, 3) cin >> bingo[i][j];
	int n;
	cin >> n;
	rep(i, n)
	{
		int tmp;
		cin >> tmp;
		rep(j, 3)
		{
			rep(k, 3)
			{
				if (tmp == bingo[j][k])
				{
					is_open[j][k] = true;
				}
			}
		}
	}
	rep(i, 3)
	{
		bool is_bingo = true;
		rep(j, 3)
		{
			if (is_open[i][j] == false)
			{
				is_bingo = false;
			}
		}
		if (is_bingo)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	rep(j, 3)
	{
		bool is_bingo = true;
		rep(i, 3)
		{
			if (is_open[i][j] == false)
			{
				is_bingo = false;
			}
		}
		if (is_bingo)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	if (is_open[0][0])
	{
		if (is_open[1][1])
		{
			if (is_open[2][2])
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	if (is_open[2][0])
	{
		if (is_open[1][1])
		{
			if (is_open[0][2])
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3596
#pypyは内包表記使わない
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    A, B, X = map(int, input().split())
    if A<=X<=A+B:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316