akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

c = []
for i in range(3):
    c.append(list(map(int, input().split())))
diff1 = []
for i in range(3):
    diff1.append([c[i][1] - c[i][0], c[i][1] - c[i][2]])

diff2 = []
for i in range(3):
    diff2.append([c[1][i] - c[0][i], c[1][i] - c[2][i]])
if diff1[0] == diff1[1] and diff1[1] == diff1[2] and \
   diff2[0] == diff2[1] and diff2[1] == diff2[2]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <iomanip>
#include <iostream>
#include <vector>    
#include <cstdlib>
#include <set>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define mod 998244353
typedef long long ll;
typedef long double ld;
using namespace std;
ll qpow(ll a,ll b,ll m)
{
    ll ans=1;
    ll base = a;
    while(b>0)
    {
        if(b&1)
            ans = (ans * base) % m;
        base = (base * base) % m;
        b >>= 1;
    }
    return ans;
}
ll C(ll n,ll m)
{
    ll ans = 1;
    for (ll i = 1;i<=m; i++)
    {
        ll tmp;
        tmp = (n - i + 1) % mod;
        ans *= (tmp * qpow(i, mod - 2, mod)) % mod;
        ans %= mod;
    }
    return ans;
}
int main()
{
    fast_io();
    int n, m;
    cin >> n >> m;
    if(n>1&&m>1)
        cout << C(n, 2) + C(m, 2);
    else if(n>1)
        cout << C(n, 2);
    else if(m>1)
        cout << C(m, 2);
    else
        cout << "0";
    return 0;
}

Measured memory_bytes: 256
n=int(input())
s=[]
ans=0
a=0
b=0
ab=0
for i in range(n):
	x=input()
	s.append(x)
	for j in range(len(x)-1):
		if x[j]=="A" and x[j+1]=="B":
			ans+=1
	if x[0]=="B" and x[-1]=="A":
		ab+=1
	elif x[0]=="B":
		b+=1
	elif x[-1]=="A":
		a+=1
if a==b==0:
	print(ans+max(ab-1,0))
else:
	print(ans+max(0,ab+min(a,b)))

Measured memory_bytes: 3700
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>










const int N = 1000;
ll x, pw[N + 10];



void solve()
{
	cin >> x;
	for(ll i = 1; i <= N; i++)
	{
		pw[i] = 1;
		for(int j = 1; j <= 5; j++)
		{
			pw[i] *= i;
		}
	}
	for(int i = 1; i <= N; i++)
	{
		for(int j = 0; j <= N; j++)
		{
			if(pw[i] + pw[j] == x)
			{
				cout << i << " " << -j << "\n";
				return;
			}
		}
		for(int j = 1; j <= i; j++)
		{
			if(pw[i] - pw[j] == x)
			{
				cout << i << " " << j << "\n";
				return;
			}
		}
	}
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
int main(void)
{
    int a,b,d,r;
    double f;
    scanf("%d%d",&a,&b);
    d=a/b;
    r=a%b;
    f=(double)a/(double)b;
    printf("%d %d %f",d,r,f);
    return 0;
}

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

using ll = long long;
const int mod = 1e9 + 7;

int cnt[2000];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, K;
    cin >> N >> K;
    N %= K;
    cout << min(N, K - N) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String... args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();

		StringBuffer sb1 = new StringBuffer();
		StringBuffer sb2 = new StringBuffer();

		boolean reverse = false;
		int n = scan.nextInt();
		for (int i = 0; i < n; i++) {
			int q = scan.nextInt();
			if (q == 1) {
				reverse = !reverse;
			} else {
				int f = scan.nextInt();
				String c = scan.next();
				if (f == 1) {
					if (!reverse) {
						sb1.insert(0, c);
					} else {
						sb2.append(c);
					}
				} else {
					if (!reverse) {
						sb2.append(c);
					} else {
						sb1.insert(0, c);
					}
				}
			}
		}

		StringBuffer sb = new StringBuffer();
		sb.append(sb1);
		sb.append(s);
		sb.append(sb2);
		if (reverse) {
			sb.reverse();
		}

		System.out.println(sb.toString());
		scan.close();
	}
}

Measured memory_bytes: 112420
from collections import deque

n,m = map(int,input().split())

p = list(map(int,input().split()))

root = [[] for i in range(n)]
for _ in range(m):
    a, b = (int(x) for x in input().split())
    root[b-1].append(a-1)
    root[a-1].append(b-1)

check = [-1]*n

for j in range(n):
    if check[j] != -1:
        continue
    stack=deque([j])
    check[j] = j
    while len(stack)>0:
        v = stack.popleft()
        for i in root[v]:
            if check[i] == -1:
                check[i]=j
                stack.append(i)

ans = 0
for key, value in enumerate(p):
    if check[key] == check[value-1]:
        ans += 1
print(ans)

Measured memory_bytes: 96800
#include <bits/stdc++.h>
#include<cstdio>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
ll mod = 1e18;
map<ll, ll> ma;
void de(ll n) {
	for (int i = 2; i <= sqrt(n); i++) {
		while (n != i) {
			if (n%i == 0) {
				ma[i]++;
				n /= i;
			}
			else {
				break;
			}
		}
	}
	ma[n]++;
}
void solve() {

	ll n;
	cin >> n;
	ll ans = 1, pre = 0;
	vector<ll> a(n);
	rep(i, 0, n) {
		cin >> a[i];
		if (a[i] == 0)ans = 0;
	}
	if (ans == 0) {
		cout << ans << endl;
		return;
	}
	rep(i, 0, n) {
		
		if (to_string(ans).size() + to_string(a[i]).size() - 1 > 19) {
			cout << -1 << endl;
			return;
		}
		ans *= a[i];
		if (ans < pre) {
			cout << -1 << endl;
			return;
		}
		if (ans > mod) {
			//cout << ans << endl;
			cout << -1;
			return;
		}
		pre = ans;
	}
	cout << ((ll)ans) << endl;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}







Measured memory_bytes: 3988
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#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 if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem0521 : Change **/
int main()
{
	int n;
	int c[] = {500, 100, 50, 10, 5, 1};
	while (cin>>n, n) {
		n = 1000 - n;
		
		int ans = 0;
		rep(i, 6) {
			while (n>=c[i]) {
				n-=c[i];
				ans++;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#-------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# ------------------- fast io --------------------

def solve(x, k, d):
    if x > 0:
        req = x // d
        if k <= req:
            return abs(x - k * d)
        else:
            k -= req
            cur = x % d
            return abs(cur) if k % 2 == 0 else abs(cur - d)
    else:
        req = -x // d
        if k <= req:
            return abs(x + k * d)
        else:
            k -= req
            cur = -(-x % d)
            return abs(cur) if k % 2 == 0 else abs(cur + d)


x, k, d = map(int, input().split())
print(solve(x, k, d))


Measured memory_bytes: 62768
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    ll A,B,N;
    cin>>A>>B>>N;
    ll x =min(N,B-1);
    cout<<A*x/B<<endl;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;
//左辺に底　右辺に真数
long double mlog(const long double base, const long double anti) {
	return log(anti) / log(base);
}
int main() {
	int N; cin >> N;
	int a = mlog(3, N) - 1e-5;
	cout << a + 1 << endl;
	return 0;
}

Measured memory_bytes: 3216
import java.util.Scanner;
public class Main {

	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int number[] = new int[30];
		int notSubmitted  = 2;
		
		for(int i = 0 ; i < number.length-notSubmitted  ; i++) {
			int num = scan.nextInt();
			++number[num-1];
		}
		for(int i = 0 ; i < number.length ; i++) {
			if(number[i] == 0) {
				System.out.println(i+1);
			}
		}
	}

}



Measured memory_bytes: 26256
s = int(input())
def f(n):
    if n%2==0:
        return n//2
    else:
        return 3*n+1

a = [s]
i = 1
while True:
    i = i + 1
    ai = f(a[-1])
    if ai in a:
        break
    a.append(ai)
print(i)

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

int main(){
	int n,m,x,a;
	cin>>n>>m>>x;
	int mass[n+1];
	fill(mass,mass+n+1,0);
	rep(i,m){
		cin>>a;
		mass[a]=1;
	}
	int sumr=0,suml=0;
	loop(i,x,n)sumr+=mass[i];
	rep(i,x)suml+=mass[i];
	cout<<((sumr>suml)?suml:sumr)<<endl;
	return 0;
}

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

int sum(int x){
  int s=0;
  while (x!=0){
    s+=(x%10);
    x/=10;
  }
  return s;
}
int main()
{
  int N,mx=100000;
  cin>>N;
  for (int i=1;i<N;i++)
    mx=min(mx,sum(i)+sum(N-i));
  cout<<mx<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
#include <cmath>
#include <limits>
#include <iostream>
#include <assert.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 yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	int x,y,cost;
};
int main(){

	int n;
	int o=0,x=0;
	int e=0;
	cin>>n;
	rep(i,n){
		ll a;
		cin>>a;
		if(a%4==0)o++;
		else if(a%2==0)e++;
		else x++;
	}
	int f=0;
	if(e==1){
		x++;
		e=0;
	}
	if(o+1<x)f=1;
	if(x==o+1){
		if(e>0)f=1;
	}
	if(f==0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;

}




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

#define pb push_back
#define fi first
#define se second


using namespace std;

vector<int> v;

int main()
{
	int n;
	string a,b;

	cin>>n;
	cin>>a>>b;

	for(int i = 0; i<n; i++)
	{
		cout<<a[i]<<b[i];
	}

	cout<<endl;


	return 0;
}


Measured memory_bytes: 3540
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class AMultipleOf2AndN {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    ll n;
	    in >> n;
	    if(n % 2 == 0) out << n << endl;
	    else out << 2*n << endl;
	}
};


int main() {
	AMultipleOf2AndN solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

ll dp[2010];

int main(){
  int s;
  cin >> s;
  int mod = 1000000007;
  
  rep(i, 0, 2010)
    dp[i] = 0;
  
  dp[0] = 1;
  
  rep(i, 3, 2010){
    dp[i] = dp[i-3] + dp[i-1];
    dp[i] %= mod;
    if(dp[i] < 0)
      dp[i] += mod;
  }
  
  cout << dp[s] << endl;
  
  return 0;
  
}

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

using namespace std;

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

  int n;
  cin >> n;
  map<int, int> cnt;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    ++cnt[x];
  }
  int ans = 0;
  for (auto [x, y] : cnt) {
    bool ok = true;
    if (y >= 2) {
      continue;
    }
    for (int j = 1; j * j <= x; ++j) {
      if (x % j) continue;
      if ((cnt.count(j) and x != 1) or (cnt.count(x / j) and j != 1)) {
        ok = false;
      }
    }
    ans += ok;
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 13024
def search_group(a):
    if a in zone_one:
        ret = 1
    elif a in zone_two:
        ret = 2
    else:
        ret = 3
    return ret

zone_one = {1,3,5,7,8,10,12}
zone_two = {4,6,9,11}
zone_three = {2}

x,y = map(int,input().split())

ret_x = search_group(x)
ret_y = search_group(y)

if ret_x == ret_y:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
def resolve():
    N = int(input())
    A = list(map(int,input().split()))
    A.append(A[-1] - 1)
    A_m = [A[0] + 1]
    A_m.extend(A)
    #print(A_m)
    Buy_Sell = [ 0 for _ in range(N)]

    for i in range(1,N+1):
        if A_m[i] >= A_m[i-1] and A_m[i] > A_m[i+1]:
            Buy_Sell[i-1] = -1        #売り時
        if A_m[i] <= A_m[i-1] and A_m[i] < A_m[i+1]: 
            Buy_Sell[i-1] = 1         #買い時
    #print(Buy_Sell)
    money = 1000
    stock = 0
    for i in range(N):
        if(Buy_Sell[i]) == 1:
            stock += money // A[i]
            money = money % A[i]
            
        if(Buy_Sell[i]) == -1:
            money += stock * A[i]
            stock = 0
    print(money)
resolve()

Measured memory_bytes: 9240
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll lcm(ll a, ll b){
  	ll tmp, r, x = a * b;
  	if(a < b){
    	tmp = a;
    	a = b;
    	b = tmp;
  	}
  	r = a % b;
  	while(r != 0){
    	a = b;
    	b = r;
    	r = a % b;
  	}
  	return x / b;
}


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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll g = lcm(c, d), s = b - a + 1;
    vll mem = {c, d, g}, cnt(3);
    REP(i, 3){
        ll p = a / mem[i];
        ll q = b / mem[i];
        ll tmp = q - p;
        if(a % mem[i] == 0) tmp++;
        cnt[i] = tmp;
    }
    ll res = s - (cnt[0] + cnt[1] - cnt[2]);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
using namespace std;
vector<pair<long long,long long> >v;
vector<long long>::iterator it;
map<long long,long long>m;
int main() 
{
    long long c[2],i,j,x,y,x1,y1,flag=0,n,count=0;
    char a[200005];
    cin>>a;
    for(i=0;i<2;i++)
        c[i]=0;
    for(i=0;a[i];i++)
    {
        if(a[i]=='S')
            c[0]++;
        else if(a[i]=='T')
        {
            if(c[0])
            {
                c[0]--;
                c[1]++;
            }
        }
    }
    cout<<strlen(a)-c[1]*2;
     
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#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++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

ll mod,fact[3030],invfact[3030],p[3030],pp[3030],dp[3030][3030];

ll pow(ll n,ll k){
  ll ret=1;
  while(k>0){
    if(k&1)ret=ret*n %mod;
    n=n*n%mod;
    k/=2;
    }
  return ret;
  }

ll comb(int n,int k){
  ll ret=fact[n]*invfact[n-k]%mod;
  return ret*invfact[k] %mod;
  }

int main(){
  int n;cin>>n;
  cin>>mod;
  
  fact[0]=invfact[0]=1;
  pp[0]=2;
  rep(i,3000){
    fact[i+1]=(ll)(i+1)*fact[i] %mod;
    invfact[i+1]=pow(fact[i+1],mod-2);
    pp[i+1]=pp[i]*pp[i] %mod;
    }
  
  rep(i,n+1)dp[0][i]=0;
  dp[0][0]=1;
  REP(i,1,n+1)rep(j,n+1){
    if(j==0)dp[i][j]=1;
    else dp[i][j]=(dp[i-1][j-1]+dp[i-1][j]*(j+1))%mod;
    }
  ll ans=0;
  rep(i,n+1){
    ll ret=0;
    rep(j,i+1){
      ll res=pow(2,(ll)(n-i)*j)*pp[n-i]%mod;
      res=res*dp[i][j]%mod;
      ret=(ret+res)%mod;
      }
    ret=ret*comb(n,i)%mod;
    if(i&1)ans+=mod-ret;
    else ans+=ret;
    ans%=mod;
    }
  cout<<ans<<endl;
  return 0;
  }

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

int main()
{
    long long n,i,ans=0;
    cin>>n;
    int a[n+2];

    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=0;i<n;i++)
    {

        ans++;
        while(a[i+1]==a[i])
        {
            i++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;

int main(void) {
  string s; cin >> s;
  const int N = sz(s);
  Vi a(N+1);
  rep(i,N) if (s[i] == '<') chmax(a[i+1],a[i]+1);
  rrep(i,N) if (s[i] == '>') chmax(a[i],a[i+1]+1);
  ll ans = 0;
  rep(i,N+1) ans += a[i];
  pl(ans)
  return 0;
}


Measured memory_bytes: 5860
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll h,w;
ll direction2[4][2]={{1,0},{0,1},{0,-1},{-1,0}};
bool valid(int a,int b)
{
    if(a>=1&&a<=h&&b>=1&&b<=w)return true;
    else return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,s=0,x;
    cin>>n;x=n;
    ll l1[n+1];
    for(int i=1;i<=n;i++){cin>>l1[i];}
    sort(l1+1,l1+n+1,greater<int>());
    s+=l1[1];
    x-=2;ll j=2;
    while(x>0){
        if(x>=2)s+=(ll)(2ll*l1[j]),x-=2;
        else s+=l1[j],x-=1;
        j++;
    }
    cout<<s;
}


Measured memory_bytes: 5168
n,k = map(int,input().split())
a = list(map(int,input().split()))
dp = ['Second'] * (k+1)
for i in range(1,k+1):
    for j in range(1,n+1):
        if i-a[j-1] >= 0 and dp[i-a[j-1]] == 'Second':
            dp[i] = 'First'
print(dp[k])

Measured memory_bytes: 74300
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL dp[1000001];
LL base[1000001];
bool used[1000001];
typedef pair<LL,LL>P;

LL change(LL x){
   LL ans=0;
   while(x!=0){
      ans+=(x%10);
      x/=10;
   }
   return ans;
}

priority_queue<P,vector<P>,greater<P> >que;
void update(LL a,LL num){
     if(dp[a]>num){
        dp[a]=num;
        used[a]=true;
        que.push(P(num,a));
     }
}

int main(){
    int K;
    cin>>K;
    REP(i,1000001){
        base[i]=change(i);
        dp[i]=1e10;
        used[i]=false;
    }

    /*REP(i,9){
        LL a=K*(i+1);
        //if(a<1000001){
        update(a,0);
        update(a/10,a%10);
        //}else{
        //   update(a/10,a%10);
        //}
    }*/
    {
        LL k=K;
        LL pl=0;
        while(k!=0){
           update(k,pl);
           pl+=k%10;
           k/=10;
        }
    }
    while(!que.empty()){
       P p=que.top(); 
       LL now=p.second;
       que.pop();
       if(used[now]==false)continue;
       used[now]=false;
       LL a=now+K;
       LL pl=0;
       if(a<1000001){
           update(a,dp[now]+0);
       }else{
       }
       pl+=a%10;
       a/=10;
       while(a!=0){
          update(a,dp[now]+pl);
          pl+=a%10;
          a/=10;
       }
       
       
       /*
       REP(i,9){
           LL aa=now+K*(i+1);
           LL bb=0;
           LL cc=0;
           //if(aa>1000000){
              bb=aa/10;
              cc=aa%10;
           //}
           //}else{
           //   bb=aa;
           //}
           if(dp[bb]>cc+dp[now]){
              dp[bb]=cc+dp[now];
              used[bb]=true;
              que.push(bb);
           }
       }
       */
    }
    LL ans=1e10;
    REP(i,1000001){
    //if(ans>dp[i]+base[i])cout<<i<<" "<<dp[i]<<" "<<base[i]<<endl;
        ans=min(ans,dp[i]+base[i]);
        
        //cout<<i<<" "<<dp[i]<<" "<<base[i]<<endl;
    }
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 23024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] k = new int[m];
        int[][] s = new int[m][];
        for (int i = 0; i < m; i++) {
            k[i] = sc.nextInt();
            s[i] = new int[k[i]];
            for (int j = 0; j < k[i]; j++) {
                s[i][j] = sc.nextInt();
            }
        }
        int[] p = new int[m];
        for (int i = 0; i < m; i++) {
            p[i] = sc.nextInt();
        }
        sc.close();

        int ans = 0;
        for (int i = 0; i < pow(2, n); i++) {
            String target = toBinaryString(i);
            boolean isOk = true;
            for (int j = 0; j < m; j++) {
                int count = 0;
                for (int a = 0; a < k[j]; a++) {
                    if (target.charAt((target.length() - 1) - (s[j][a] - 1)) == '1') {
                        count++;
                    }
                }
                if (count % 2 != p[j]) {
                    isOk = false;
                    break;
                }
            }
            if (isOk) {
                ans++;
            }
        }
        System.out.println(ans);
    }

    // intを13桁のbit文字列に変換
    static String toBinaryString(int input) {
        String ret = "";
        int max = 0x00001000;
        for (int i = 0; i < 13; i++) {
            int tmp = input / max;
            ret += tmp;
            input %= max;
            max /= 2;
        }
        return ret;
    }

    // baseのn乗を計算を返す
    static int pow(int base, int n) {
        int ret = 1;
        for (int i = 0; i < n; i++) {
            ret *= base;
        }
        return ret;
    }

}


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

int main() {
  int a, b, cnt = 0;
  cin >> a >> b;
  
  while (a <= b) {
    if (to_string(a).at(0) == to_string(a).at(4))
      if (to_string(a).at(1) == to_string(a).at(3)) cnt++;
    a++;
  }
  cout << cnt << endl;
}

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

vector<int> G[100001];
int gin[100001];
int q[100001];
int ts[100001];
int ans[100001];
int main(int argc, char const *argv[]) {
    int n,m,A,B;
    scanf("%d %d", &n, &m);
    while(m--) {
        scanf("%d %d", &A, &B);
        A--;
        B--;
        G[A].push_back(B);
        gin[B] ++;
    }
    int f,b;
    f = 0;
    b = 0;
    for(int i=0;i<n;++i)
        if(!gin[i])
            q[b++] = i;
    int u, sz = 0;
    while(f < b) {
        u = q[f++];
        //cout << u << endl;
        ts[sz++] = u;
         for(int i=0;i<G[u].size();++i) {
            gin[G[u][i]]--;
            if(!gin[G[u][i]])
                q[b++] = G[u][i];
         }
    }
    for(int i=sz-1;i>=0;--i) {
        u = ts[i];
        ans[u] = 0;
        for(int i=0;i<G[u].size(); ++i)
            ans[u] = max(ans[u], 1 + ans[G[u][i]]);
    }
    printf("%d\n", *max_element(ans,ans+n));
    return 0;
}

Measured memory_bytes: 10744
#include <bits/stdc++.h>
typedef long long  ll;
#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define form for(int j=0;j<n;j++) 
#define fora(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define kek cout<<endl; 
#define all(v) ((v).begin()), ((v).end()) 
#define pob pop_back() 
#define halt {cout<<-1; return 0;}
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const int N = 200010;
const int INF = 1e8;
const ll MOD1=1073741824;
using namespace std;
 
int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
 press_F_to_pay_respect;
 
 ll n;
 cin>>n;
 int otv = 0;
 for (ll x = 2; x * x <= n; x++){
          if (n % x == 0){
                    int mx = 0;
                    int cnt = 0;
                    while(n % x == 0){
                              cnt++;
                              n /=x;
                              if (cnt > mx){
                                        cnt = 0;
                                        mx++;
                                        otv++;
                              }
                    }
          }
 }
 if (n != 1){
           otv++;
 }
 cout << otv;
 
 
 
 
 
 
  // cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;
   
   
 
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;



int main(){
    string t;
    cin >> t;
    for(int i=0;i<(1<<4);i++){
        string s="";
        for(int j=0;j<4;j++){
            if((i>>j)&1) s.push_back('A');
            if(j==0) s=s+"KIH";
            if(j==1) s=s+"B";
            if(j==2) s=s+"R";
        }
        if(t==s){
            puts("YES");
            return 0;
        }
    }
    puts("NO");
    return 0;
}

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

using namespace std;

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

int main(void) {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += i;
  }
  for (int i = 1; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      ans += gcd(i, j) * 6;
    }
  }
  for (int i = 1; i <= n - 2; i++) {
    for (int j = i + 1; j <= n - 1; j++) {
      for (int k = j + 1; k <= n; k++) {
        ans += gcd(k, gcd(i, j)) * 6;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;

string tolower(const string s) {
  string result="";
  for(auto ch: s) {
    result += tolower(ch);
  }
  return result;
}

int main(void) {
  string word;
  cin >> word;

  string s;
  int result=0;
  while(cin >> s, s != "END_OF_TEXT") {
    if(tolower(s) == word) result++;
  }

  cout << result << endl;
}



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

long long x;

long long func(long long n){
  if(n==-1){
    return 0;
  }
  else{
    return n/x+1;
  }
}

int main(){
  long long a,b;
  cin >> a >> b >> x;
  cout <<(long long)(func(b)-func(a-1)) << endl;
}

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

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#define fi first
#define se second
#define x first
#define y second
#define pb push_back
#define last(s) (s)[(s).size()-1]
#define all(a) (a).begin(),(a).end()
#define elif else if
#define left asdasd
#define next zaza
#define prev azaz
#define cclear cout<<flush;
#define x0 kerker
#define time chas
#define y0 lolik
#define kchay ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define files freopen("little.in", "r", stdin);freopen("little.out", "w", stdout);

using namespace std;

using llong = long long;
using ld = long double;
using itn = int;
using ii = pair<int,int>;\
using ull = unsigned long long;
using pll = pair<llong, llong>;
using psi = pair<string, int>;
using ll = pair<llong, llong>;

const llong over999 = 1e9;
const ld over999ld = 1e18+1;
const llong md = 1e9+7;
const ld eps = 1e-9;
const ld Pi = acos(-1);
const llong nich = 0;
const int mnogo = 300;

/**/

llong n;
int32_t main() {
    kchay;
    
    cin >> n;
    cout << n/3;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define fr(i, a, b) for (int i = a; i < b; i++)
using namespace std;
#define mod 1000000007
#define fr(i, a, b) for (int i = a; i < b; i++)
#define fast_io ios::sync_with_stdio(false);cin.tie(0);
ll dp[3001][3001][2];
ll solve(vi &a,int i,int j,bool turn){
    if(i>j){
        return 0;
    }
    if(dp[i][j][turn]!=-1) return dp[i][j][turn];
    if(turn==1){
        return dp[i][j][1]=max(a[i] + solve(a,i+1,j,0),a[j] + solve(a,i,j-1,0));
    } else{
         return dp[i][j][0]=min(solve(a,i+1,j,1),solve(a,i,j-1,1));        
    }
}
int main(){
    fast_io
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif

    int n;cin>>n;
    vi a(n+1);
    ll sum=0;
    fr(i,1,n+1) {
        cin>>a[i];
        sum+=a[i];
    }
    memset(dp,-1,sizeof dp);
    ll x = solve(a,1,n,1);
    ll y = sum-x;
    cout<<x-y<<endl;
    return 0;
}

Measured memory_bytes: 141184
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    cout << ((a*b%2)?"Odd":"Even") << endl;
}

Measured memory_bytes: 256
import sys

input=sys.stdin.readline

S=input()
T=input()
SAdata=[int(S[i]=="A") for i in range(len(S))]
SBdata=[int(S[i]=="B") for i in range(len(S))]
for i in range(1,len(S)):
    SAdata[i]+=SAdata[i-1]
for i in range(1,len(S)):
    SBdata[i]+=SBdata[i-1]
SAdata.append(0)
SBdata.append(0)

TAdata=[int(T[i]=="A") for i in range(len(T))]
TBdata=[int(T[i]=="B") for i in range(len(T))]
for i in range(1,len(T)):
    TAdata[i]+=TAdata[i-1]
for i in range(1,len(T)):
    TBdata[i]+=TBdata[i-1]
TAdata.append(0)
TBdata.append(0)

q=int(input())
for i in range(q):
    a,b,c,d=map(int,input().split())
    SA=SAdata[b-1]-SAdata[a-2]
    SB=SBdata[b-1]-SBdata[a-2]
    TA=TAdata[d-1]-TAdata[c-2]
    TB=TBdata[d-1]-TBdata[c-2]
    if (SA-SB)%3==(TA-TB)%3:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 57632
#include<stdio.h>
#include<string.h>
int main()
{
    int i, l;
    char s[11], t[11];
    scanf("%s",s);
    scanf("%s",t);
    l = strlen(s);
    for(i=0;i<l;i++)
    {
        if(s[i]!=t[i])
        break;
    }
    if(i==l)
    {
        printf("Yes");
    }
    else
    printf("No");
    return 0;
}

Measured memory_bytes: 1692
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x,y;
  cin>>n>>m>>x>>y;
  int xg=x;
  for(int i=0;i<n;i++){
    int xi;
    cin>>xi;
    xg=max(xg,xi);
  }
  int yl=y;
  for(int i=0;i<m;i++){
    int yi;
    cin>>yi;
    yl=min(yl,yi);
  }
  cout<<(xg<yl?"No War":"War")<<endl;
}

Measured memory_bytes: 3632
function Main(input) {
  input = input.trim()
  input = input.split(" ").map(Number);
  if((input[0]>=input[2]&&input[2]>=input[1])||(input[0]<=input[2]&&input[2]<=input[1])) console.log("Yes");
  else console.log("No")
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int main() {
    int N, p, k = 0;
    cin >> N;
    rep(i, N) {
        cin >> p;
        if (p != i + 1) k++;
    }
    cout << (k > 2 ? "NO" : "YES") << endl;
}

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair

#define NEWLINE         cerr << "\n";
#define HOISE           cerr << "hoise " << __LINE__ << "\n"
#define PAUSE           system("pause")
#define DEBUG(x)        cerr << #x << " = " << x << "\n"
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)

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

const int INF = 1e9 + 23;
const ll INFL = 2e18 + 23;

int32_t main()
{
    FASTIO;

    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        ac += (s=="AC");
        wa += (s == "WA");
        tle += (s=="TLE");
        re += (s=="RE");
    }
    cout << "AC x " << ac << "\n";
    cout << "WA x " << wa << "\n";
    cout << "TLE x " << tle << "\n";
    cout << "RE x " << re << "\n";

    return 0;
}

Measured memory_bytes: 3656
N,M=map(int,input().split())
tbl=[[0]*(N+1) for _ in range(N+1)]
for i in range(M):
  a,b=map(int,input().split())
  tbl[a][b]=1
  tbl[b][a]=1            # グラフの行列を用いた表現
def dfs(s,visited):
  if len(visited)==N:
    return 1
  
  ans=0
  for i in range(1,N+1):
    if i==s: continue     # 自己閉路は関係ない
    if tbl[s][i]==1 and (i not in visited):
      visited.append(i)
      ans+=dfs(i,visited)
      visited.pop() #深さ優先探索を考えているから
  return ans 

answer=dfs(1,[1,])
print(answer)
      

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

int main(int argc, char const *argv[])
{
	int n,k;
	cin>>n>>k;
	long long x[n];
	int p=-1;
	for (int i = 0; i < n; ++i)
	{
		cin>>x[i];
		if (x[i]<0)
		{
			p=i;
		}
	}
	long long l[n];
	if (p!=-1)
	{		
		l[0]=abs(0-x[p]);
		for (int i = 1; i <= p; ++i)
		{
			l[i]=l[i-1]+abs(x[p-i+1]-x[p-i]);
		}
	}
	long long r[n];
	if (p!=n-1)
	{
		r[0]=abs(0-x[p+1]);
		for (int i = 1; i < n-p-1; ++i)
		{
			r[i]=r[i-1]+abs(x[p+i+1]-x[p+i]);
		}
	}
	long long ans=10000000000000000LL;
	if (0<=p&&p<n)
	{
		for (int i = 0; i <= min(p,k-2); ++i)
		{
			if (k-i-2>=n-p-1)
			{
				continue;
			}
			ans=min({ans,2LL*l[i]+r[k-i-2],l[i]+2LL*r[k-i-2]});
		}
	}
	if (p+1>=k)
	{
		ans=min(ans,l[k-1]);
	}
	if (n-p-1>=k)
	{
		ans=min(ans,r[k-1]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
int main(){
	char T[1000],P[1000];
	int lp,lt;
	scanf("%s",T);scanf("%s",P);
	lp = strlen(P); lt = strlen(T);
	for(int i=0;i<lt;i++){
		bool same = true;
		for(int j=0;j<lp;j++){
			if(T[i+j] != P[j]){
				same = false;
				break;
			}
		}
		if(same) printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 2756
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k;
  cin >> n >> k;
  
  vector<int> a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  
  int sum=0;
  sort(a.begin(), a.end());
  for(int j=0; j<k; j++){
    sum += a[j];
  }
  
  cout << sum << endl;
  
  
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int h, w, n;
int sr, sc;
string s, t;

int32_t main(){_

   cin>>h>>w>>n;
   cin>>sr>>sc;
   cin>>s>>t;

   int x = sr, y = sc;
   for (int i = 0; i < n; ++i)
   {
      if(s[i] == 'L'){
         y--;
      }
      if(y < 1){
         cout<<"NO";
         return 0;
      }
      if(y <= w-1 and t[i] == 'R'){
         ++y;
      }
   }

   x = sr, y = sc;
   for (int i = 0; i < n; ++i)
   {
      if(s[i] == 'R'){
         y++;
      }
      if(y > w){
         cout<<"NO";
         return 0;
      }
      if(y >= 2 and t[i] == 'L'){
         --y;
      }
   }

   x = sr, y = sc;
   for (int i = 0; i < n; ++i)
   {
      if(s[i] == 'U'){
         x--;
      }
      if(x < 1){
         cout<<"NO";
         return 0;
      }
      if(x <= h-1 and t[i] == 'D'){
         ++x;
      }
   }

   x = sr, y = sc;
   for (int i = 0; i < n; ++i)
   {
      if(s[i] == 'D'){
         x++;
      }
      if(x > h){
         cout<<"NO";
         return 0;
      }
      if(x >= 2 and t[i] == 'U'){
         --x;
      }
   }

   cout<<"YES";

   return 0;
}

// Common sense: do smth instead of nothing
// Even a single second counts...
// If other's can do it, even I can do it. It wouldn't be that tough. Let me give it a try.
// Mistakes made in past
// -Ques. ask for max-min => think binary_search, DP, greedy
// -not reading question properly / skipping to read & understand all samples properly & wasting time in wrong direction.
// -Using wrong indexing in nested loops something like a[i], when it is supposed to be a[j](WA)
// -value of const int N is not correct (WA/RTE).
// -Did you memset dp to -1 ?
// -check for small edges cases and work on small test cases manually if WA
// -not deallocating memory to pointers can lead to MLE. Use delete :))
// -not reading problem statements of harder problems E,..., thinking it couldn't be solved, but it isn't the case.
// -Avoid using #define int long long as much as possible when it's dp problem and requires high memory say, O(N^2, N=5000) (MLE)
// -Check Bitwise Operator Precedence 
// -Use pragmas to optimize (by constant factor) when necessary..
// -Think before coding & starting to debug. Have patience to look inside code and actually see how it works


Measured memory_bytes: 920
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
using namespace std;
#define EPS (1e-10)
#define equals(a,b) (fabs((a) - (b)) < EPS)
class Point{
public:
  double x,y;
  Point(double x = 0, double y = 0):x(x), y(y) {}
  Point operator + (Point p){
    return Point(x+p.x,y+p.y);
  }
  Point operator - (Point p){
    return Point(x-p.x,y-p.y);
  }
  Point operator * (double k){
    return Point(x*k,y*k);
  }
  Point operator / (double k){
    return Point(x/k,y/k);
  }
  bool operator == (const Point &p) const{
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};
typedef Point Vector;
typedef vector<Point> Polygon;
double dot(Vector a,Vector b){
  return a.x * b.x + a.y * b.y;
}
double cross(Vector a,Vector b){
  return a.x * b.y - a.y * b.x;
}
// IN 2 ON 1 OUT 0
int contains(Polygon g,Point p){
  int n=g.size();
  bool x = false;
  for(int i=0;i<n;i++){
    Point a = g[i] - p, b = g[(i+1)%n] - p;
    if(fabs(cross(a,b))<EPS && dot(a,b) < EPS ) return 1;
    if(a.y > b.y ) swap(a,b);
    if(a.y<EPS && EPS < b.y && cross(a,b) > EPS) x = !x;
  }
  return ( x ? 2:0);
}
int main(){
  Point a,b,c,d;
  while(cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y >> d.x >> d.y){
    Polygon g;
    g.push_back(a);g.push_back(b);g.push_back(c);
    if(contains(g,d)==2) cout << "YES" <<endl;
    else cout << "NO" <<endl;
  }
  return 0;
}

Measured memory_bytes: 3172
/********************************************//**
 ****** Author: Shivam Kejriwal *****************
 ****** Handle: techno_phyle    *****************
 ***********************************************/

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long ll;

#define mod 1000000007
#define N 100010
#define M 200010
#define db(a) cout << a << endl
#define db2(a,b) cout << a << " " << b << endl
#define dbp(a) cout << a.first << " " << a.second << endl
#define adb(a) for(auto it:a) cout << it << " "; cout << endl
#define adbp(a) for(auto it:a) cout << it.first << " " << it.second << endl
#define pb push_back
#define mp make_pair
typedef pair<double, long> key;

struct comp {
    bool operator()(pair<int,int> p1, pair<int,int> p2) {
        if (p1.first < p2.first) return false;
        if (p2.first < p1.first) return true;
        return p1.second < p2.second;
    };
};
//greater<pair<int,int> , greater<int>>
const ll INF = 1e18L + 5;
//int dp[N][3];
int main(){
	fastIO;
    //#ifndef ONLINE_JUDGE
    //    freopen("../input.txt", "r", stdin);
    //    freopen("../output.txt","w",stdout);
    //#endif	
    int h,w;
    cin >> h >> w;
    ll dp[h+1][w+1];
    memset(dp,0,sizeof(dp));
    dp[1][1] = 1;
    for(int i=1;i<=h;i++){
        string s;
        cin >> s;
        for(int j=0;j<s.length();j++){
            if(s[j]=='#'){
                dp[i][j+1] = 0;
            }
            else{
                dp[i][j+1] = (dp[i-1][j+1] + dp[i][j])%mod;
                if(i==1&&j==0){
                    dp[1][1] = 1;
                }
            }
        }
    }
    cout << dp[h][w] << endl;
	return 0;

}



Measured memory_bytes: 8064
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  string C;
  cin >> C;

  int left = 0;
  int right = N - 1;
  int answer = 0;
  while (left < right) {
    while (left < N && C[left] == 'R') ++left;
    while (right >= 0 && C[right] == 'W') --right;
    if (left >= right) break;

    swap(C[left], C[right]);
    ++answer;
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3792