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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt();
		int R = sc.nextInt();
		int d = sc.nextInt();
		int ans = 0;
		for (int i = L; i <= R; i++) {
			if (i % d == 0) {
				ans++;
			}
		}
		System.out.println(ans);
	}

}


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

#define all(v) v.begin(), v.end()
#define mp make_pair
#define EPS (int)1e-9
#define PI acos(-1)
#define endl '\n'
#define pb push_back
#define fi first
#define se second

using namespace std;
using ld = long double;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

const int mod = 1000000007;


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

	vi a(n+1);
	for(int i = 1; i <= n; i++)
		cin >> a[i];

	int pos = 1, moves = 0;
	set<int> seen;

	while(true)
	{
		if(pos == 2)
		{
			cout << moves << endl;
			return 0;
		}
		if(seen.count(pos))
		{
			cout << -1 << endl;
			return 0;
		}

		seen.insert(pos);
		pos = a[pos];
		moves++;
	}

	return 0;	
}

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

int pow(int a,int b){
	int c = 1;
	for(int i = 0 ; i < b ; i++) c *= a;
	return c;
}


int get(string a){
	int ans = 0;
	for(int i = 0 ; i < a.size() ;){
		if('2' <= a[i] && a[i] <= '9'){
			ans += pow(10,string("ixcm").find(a[i+1])) * (a[i] - '0');
			i+=2;
		}else{
			ans += pow(10,string("ixcm").find(a[i]));
			i++;
		}
	}
	return ans;
}

string X(char a,int b){
	if(b == 0) return "";
	if(b == 1 ) return string(1,a);
	return string(1,b+'0') + string(1,a);
}

string to(int n){
	int A = n / 1000;
	n -= A * 1000;
	
	int B = n / 100;
	n -= B * 100;
	
	int C = n / 10;
	n -= C * 10;
	
	int D = n / 1;
	n -= D;
	
	//cout << A << " " << B << " " << C << " " << D << endl;
	return X('m',A) + X('c',B) + X('x',C) + X('i',D);
	
}

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	while(n--){
		string a,b;
		cin >> a >> b;
		//cout << a << " " << b << " " << get(a) << " " << get(b) << endl;
		cout << to(get(a)+get(b)) << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#include <atcoder/all>

#define FOR_LT(i, beg, end) for (decltype(end) i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (decltype(end) i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (decltype(beg) i = beg; end <= i; i--)
#define REP(n)              for (decltype(n) repeat_index = 0; repeat_index < n; repeat_index++)

using namespace std;

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

	int n, d; cin >> n >> d;
	vector<pair<int64_t, int64_t>> ps(n); for (auto& p : ps) { cin >> p.first >> p.second; }

	atcoder::two_sat ts(n);
	FOR_LT(i, 0, n) {
		auto& sp = ps[i];
		FOR_LT(j, i + 1, n) {
			auto& tp = ps[j];
			if (abs(sp.first - tp.first) < d) {
				ts.add_clause(i, false, j, false);
			}
			if (abs(sp.first - tp.second) < d) {
				ts.add_clause(i, false, j, true);
			}
			if (abs(sp.second - tp.first) < d) {
				ts.add_clause(i, true, j, false);
			}
			if (abs(sp.second - tp.second) < d) {
				ts.add_clause(i, true, j, true);
			}
		}
	}
	bool ret = ts.satisfiable();
	if (!ret) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;

	auto ans = ts.answer();
	FOR_LT(i, 0, n) {
		if (ans[i]) cout << ps[i].first << endl;
		else cout << ps[i].second << endl;
	}

	return 0;
}

Measured memory_bytes: 3740
from collections import defaultdict
from operator import mul
from functools import reduce
def C(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

N = int(input())
d = defaultdict(int)
for _ in range(N):
    s = input()
    s = tuple(sorted(list(s)))
    d[s] += 1
ans = 0
for v in d.values():
    if v > 1:
        ans += C(v, 2)
print(ans)


Measured memory_bytes: 28332
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;
vector<ll> all(55);
vector<ll> p(55);

ll search(ll n, ll x) {
  if (x <= 0) {
    return 0;
  }
  if (n == 0) {
    return 1;
  }
  if (all[n] == x) {
    return p[n];
  }
  ll mid = (all[n] + 1) / 2;
  if (mid == x) {
    return p[n - 1] + 1;
  }
  if (mid > x) {
    return search(n - 1, x - 1);
  }
  return p[n - 1] + 1 + search(n - 1, x - all[n - 1] - 2);
}

int main() {
  ll n, x;
  cin >> n >> x;
  
  // 初期値
  all[0] = 1;
  p[0] = 1;
  for (ll i = 1; i <= 50; i++) {
    all[i] = all[i - 1] * 2 + 3;
    p[i]   = p[i - 1] * 2 + 1;
  }
  cout << search(n, x) << endl;
  return 0;
}


Measured memory_bytes: 256
import heapq
#標準入力受け取り
N, M = list(map(int, input().split()))
jobs = [[] for _ in range(M)]

for i in range(N):
    d, r = list(map(int, input().split()))
    if d-1 < M:
        jobs[d-1].append(-r)

#解法
rewards = 0
heap = []
for i in range(M):
	for reward in jobs[i]:
		heapq.heappush(heap,reward)

	if len(heap)>0:
		reward = heapq.heappop(heap)
		rewards += -reward

print(rewards)

Measured memory_bytes: 23752
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    int whi,hhi,n,wlo=0,hlo=0;
    cin>>whi>>hhi>>n;
    For(i,0,n){
        int x,y,a;
        cin>>x>>y>>a;
        if(a==2){
            whi=min(whi,x);
        }
        else if(a==1){
            wlo=max(wlo,x);
        }
        else if(a==4){
            hhi=min(hhi,y);
        }
        else if(a==3){
            hlo=max(hlo,y);
        }
    }
    cout<<max(whi-wlo,0)*max(hhi-hlo,0)<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template<class A, class B>
inline bool chmax(A &a, const B &b) { return b > a ? a = b, 1 : 0; }

template<class A, class B>
inline bool chmin(A &a, const B &b) { return b < a ? a = b, 1 : 0; }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

//IN
void IN() {}
template<class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

//OUTS
template<size_t> struct int_{};
template<class Tuple, size_t Pos>
ostream& print_tuple(ostream& out, const Tuple& t, int_<Pos>) {
  out << get<tuple_size<Tuple>::value-Pos>(t) << " ";
  return print_tuple(out, t, int_<Pos-1>());
}

template <class Tuple>
ostream& print_tuple(ostream& out, const Tuple& t, int_<1>) {
  return out << get<tuple_size<Tuple>::value-1>(t);
}

template<class... Args>
ostream& operator<<(ostream& out, const tuple<Args...>& t) {
  return print_tuple(out, t, int_<sizeof...(Args)>());
}

#define OUTS(...) cout << make_tuple(__VA_ARGS__) << "\n";

//OUTL
void OUTL() {}
template<class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  VAR(int, n, h, w);
  i64 res = 0;
  rep(i, n) {
    VAR(int, a, b);
    res += (h <= a && w <= b);
  }
  OUTL(res);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0) break;
		int c=0;
		while(1){
			if(n==1) break;
			if(n%2) n=3*n+1;
			else n/=2;
			c++;
		}
		o(c);
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()


char ba[8][8];

void go(int x, int y) {
  REP(i,7) {
    if (x-3+i>=0 && x-3+i<8 && ba[x-3+i][y] == '1') {
      ba[x-3+i][y] = '0';
      go(x-3+i,y);
    }
    if (y-3+i>=0 && y-3+i<8 && ba[x][y-3+i] == '1') {
      ba[x][y-3+i] = '0';
      go(x,y-3+i);
    }
  }
}
int main() {
  int n;
  cin >> n;
  REP(datan, n) {
    REP(i,8)
      REP(j,8)
      cin >> ba[j][i];
    int sx,sy;
    cin >> sx;
    cin >> sy;
    sx--;sy--;
    ba[sx][sy] = '0';
    
    go(sx,sy);

    printf ("Data %d:\n", datan+1);
    REP(y,8) {
      REP(x,8) {
        cout << ba[x][y];
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 0
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve(args);
			Console.Out.Flush();
		}

		private const int mod = 1000000007;  // 10^9+7

		static public void Solve(string[] args)
		{
			//int t = int.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			//long x = long.Parse(Console.ReadLine());
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int a = vs[0];
			int b = vs[1];

			int ans = a * b;
			Console.WriteLine(ans);
		}
	}
}


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

#define ll long long
#define ull unsigned ll

#define vi vector <int>
#define ii pair <int, int>
#define vii vector <ii>
#define INFLL 9e18
#define INF 2e9
#define EPS 1e-9
#define pb push_back
#define emp emplace_back
#define PI acos(-1.0)
#define endl "\n"
#define mp make_pair
#define DEBUG 0

ll log(ll number, ll base){
   return (ll)log2(number)/(ll)log2(base); 
}

ll power(ll x, ll y){
    return (ll)(pow(x, y) + EPS);
}

int main ()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    
    int t;
    cin >> t;

    int digit = t%10;
    switch(digit)
    {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
        cout << "hon" << endl;
        break;
        case 0:
        case 1:
        case 6:
        case 8:
        cout << "pon" << endl;
        break;
        default:
        cout << "bon" << endl;
        break;
    }
    
    return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define pb push_back
#define F first
#define S second
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)

# define M_PIl          3.141592653589793238462643383279502884L /* pi */

const ll M=1e9+7;
const int MaxM=100005;


void SieveOfEratosthenes(int n)                                   //all prime <= n
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}


bool isPowerOfTwo (int x)
{
    return x && (!(x&(x-1)));
}



bool comp(pair<int,int> a,pair<int,int> b){
  if(a.F==b.F){
    return a.S>b.S;
  }
  return a.F<b.F;
}




void solve(){

int n,m;cin>>n>>m;

char a[n][m];
for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
          cin>>a[i][j];
    }
}


int dp[n+1][m+1]={0};
for(int i=0;i<=n;i++){dp[i][0]=0;}
    for(int j=0;j<=m;j++){dp[0][j]=0;}

dp[1][1]=1;
for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
       // if(i==0|| j==0){dp[i][j]==0;}

        if(a[i-1][j-1]=='.'){dp[i][j]=dp[i-1][j]+dp[i][j-1];}
        else{dp[i][j]=0;}
        if(i==1&&j==1){dp[i][j]=1;}
       dp[i][j]%=M;
    }
}



cout<<dp[n][m];

}

int main(){


   int t=1;
//  cin>>t;
   while(t--){
      solve();
       }

 }


Measured memory_bytes: 8512
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &os, const tuple<T, U, V> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef tuple<int, int, int> TT;
typedef pair<int, TT> PT;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);


signed main(){
  int n, k;cin >> n >> k;
  cout << (n-k+1) << endl;
  return 0;
}






Measured memory_bytes: 256
import java.util.*;
public class Main { 
	final static int maxn=(int)2e5+10;
	static int vis[]=new int [maxn];
	static int a[]=new int [maxn];
	static int b[]=new int [maxn];
	static int f[][]=new int [maxn][3];
 public static void main(String args[])
 {
	 Scanner input=new Scanner(System.in);
      int n,x,y;
      n=input.nextInt();x=input.nextInt();y=input.nextInt();
      for(int i=1;i<=n-1;i++)
      {
    	  for(int j=i+1;j<=n;j++)
    	  {
    		  int num=Math.min(j-i, Math.abs(i-x)+Math.abs(j-y)+1);
    		  a[num]++;
    	  }
      }
      for(int i=1;i<=n-1;i++)
      {
    	  System.out.println(a[i]);
      }
}
}

Measured memory_bytes: 33492
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define re(i,a,n) for(i=a;i<=n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second


ll binpow(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
   while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return binpow(n, p-2, p);
}

vector<ll> used;
vector<vector<ll>> adj;
ll res;

void dfs(ll u)
{
      res++;
      used[u]=1;
      for(auto v:adj[u])
      {
            if(!used[v]) dfs(v);
      }
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll m,n,i,f=0,j,ans=0,k,x,r,l,t;
    cin >> n >> m ;
    adj.resize(n+1);
    used.resize(n+1);
    used.assign(n+1,0);
    rep(i,m)
    {
          cin >> x >> r ;
          adj[x].pb(r);
          adj[r].pb(x);
    }
    for(i=1;i<=n;++i)
    {
          if(!used[i])
          {
                res=0;
                dfs(i);
                ans=max(ans,res);
          }
    }
    cout << ans ;
    return 0;
}

Measured memory_bytes: 21916
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    s = S()
    d = defaultdict(int)
    for i in s:
        d[i] += 1
    ans = 1
    for di in d.values():
        ans *= di + 1
        ans %= mod
    print((ans - 1) % mod)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 50800
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
void read(int &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
void read(ll &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
using namespace std;
const int maxn = 3000;
int n;
double p[maxn], dp[maxn][maxn];
int main()
{
    read(n);
    rep(i, 1, n) scanf("%lf", &p[i]);
    dp[0][0] = 1;
    rep(i, 1, n) {
        dp[i][0] = dp[i - 1][0] * (1 - p[i]);
        rep(j, 1, i)
            dp[i][j] += dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
    }
    double ans = 0;
    rep(i, n / 2 + 1, n) ans += dp[n][i];
    printf("%.12lf\n", ans);
    return 0;
}

Measured memory_bytes: 68864
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <cstring>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rep(i,n) for(int i=0;i<(int)n;i++)

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};

const double EPS = 1e-9;

struct singer{
    int cost,pop;
    singer() {};
    singer(int cost,int pop) : cost(cost),pop(pop) {};
};

int main(){
    while(true){
        int LIMIT,N,M,X;
        cin >> LIMIT >> N >> M >> X;
        if(LIMIT == 0) break;

        vector<singer> secret(N);
        vector<singer> normal(M);

        for(int i=0;i<N;i++){
            string name;
            cin >> name >> secret[i].cost >> secret[i].pop;
        }

        for(int i=0;i<M;i++){
            string name;
            cin >> name >> normal[i].cost >> normal[i].pop;
        }

        vector<vector<int> > vec(M+1,vector<int>(LIMIT+1));

        for(int i=0;i<N;i++){
            for(int j=i;j<N;j++){
                if(i == j){
                    int cost = secret[i].cost;
                    int pop = secret[i].pop;
                    if(cost > LIMIT) continue;
                    vec[0][cost] = max(vec[0][cost],pop);
                }else{
                    int cost = secret[i].cost + secret[j].cost;
                    int pop = secret[i].pop + secret[j].pop;
                    if(cost > LIMIT) continue;
                    vec[0][cost] = max(vec[0][cost],pop);
                }
            }
        }
        for(int i=0;i<M;i++){
            vector<vector<int> > next = vec;
            for(int j=0;j<M;j++){
                for(int k=0;k<=LIMIT;k++){
                    if(vec[j][k] == 0) continue;
                    if(k + normal[i].cost > LIMIT) continue;
                    next[j+1][k+normal[i].cost] = max(vec[j+1][k+normal[i].cost],
                            vec[j][k]+normal[i].pop);

                }
            }
            vec = next;
        }
        int maxi = 0;
        for(int i=X;i<=M;i++){
            for(int j=0;j<=LIMIT;j++){
                maxi = max(maxi,vec[i][j]);
            }
        }
        cout << maxi << endl;
    }
    return 0;
}

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

int main(){
	int n,q;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}

	cin >> q;
	for(int i=0;i<q;i++){
		int com,b,e;
		cin >> com >> b >> e;
		if(com){
			cout << *max_element(a.begin()+b,a.begin()+e) << endl;
		}else{
			cout << *min_element(a.begin()+b,a.begin()+e) << endl;
		}
	}

}


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

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

const long long INF = 1LL << 60;
const int ELENUM = 110000;


// prototype
void show(long long int* dp_h, int N);

int main() {
	int N;
	int K;

	long long int dp_h[ELENUM];
	int cost[ELENUM];

	cin >> N >> K;

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

	for (int i = 0; i < ELENUM; i++) {
		dp_h[i] = INF;
	}

	dp_h[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 1; j <= K; j++) {
			chmin(dp_h[i+j], dp_h[i] + abs(cost[i+j] - cost[i]));
		}


	}

	cout << dp_h[N - 1] << endl;

}


void show(long long int* dp_h, int N){
	cout <<"dp is ";

	for(int l = 0; l < N; l++){
		cout <<  dp_h[l] << " ";
	}
	cout << endl;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n, m;
int x[50], y[50], xx[50], yy[50];

int main() {
    cin >> n >> m;
    forn(i, n) cin >> x[i] >> y[i];
    forn(i, m) cin >> xx[i] >> yy[i];
    forn(i, n) {
        int best = -1;
        int bestVal = int(2e9);
        forn(j, m) {
            int cur = abs(x[i] - xx[j]) + abs(y[i] - yy[j]);
            if (cur < bestVal) {
                bestVal = cur;
                best = j;
            }
        }
        printf("%d\n", best + 1);
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
string s;int tot,ans; 
int main()
{
	cin>>s;
	for(int i=0;i<s.size();++i)
	 if(s[i]=='R') ++tot,ans=max(ans,tot);
	 else tot=0;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3632
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list -- START --
def summarizeList(l):
  sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res
# Summarize count of factor within list --- END ---

def main():
  n=I()
  l=LI()

  l=[0]+l
  for i in range(n):
    l[i+1]+=l[i]

  sl=summarizeList(l)
  ans=0

  for x,c in sl:
    ans+=c*(c-1)//2

  return ans

# main()
print(main())


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

using namespace std;

long long n,k;
vector<int> a,f;

bool ok(long long x) {
  long long cnt=k;
  for(int i=0;i<n;++i) {
    long long tmp=a[i]-x/f[i];
    if(tmp>0) cnt-=tmp;
    if(cnt<0) return false;
  }
  return true;
}

int main(){
  cin >> n >> k;
  a.resize(n); f.resize(n);
  for(int i=0;i<n;++i) cin >> a[i];
  for(int i=0;i<n;++i) cin >> f[i];
  sort(a.begin(),a.end());
  sort(f.begin(),f.end(),greater<>());
  long long l=0,r=1e13;
  while(l!=r) {
    long long mid=(l+r)/2;
    if(ok(mid)) r=mid;
    else l=mid+1;
  }
  cout << r << endl;
  
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(void)
{
    int N, sumL = 0;
    int max = 0;
    int L[11];

    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> L[i];
        sumL +=L [i];
        if(L[i] > max)max = L[i];
    }

    if (max < sumL - max)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int dxx[8] = { 1, 1, 1, 0, 0, -1, -1, -1 }, dyy[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    if (a >= k) ans = k;
    else if (a + b >= k)
        ans = a;
    else
        ans = 2 * a + b - k;
    cout << ans << "\n";
}

Measured memory_bytes: 3636
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in xrange(1, n + 1):
        for j in xrange(i, n + 1, i):
            table[j] += 1
    
    return table
  
n = int(input())  
a =  num_divisors_table(n)
ans = 0
for i in range(n+1):
  ans += i*a[i]
print(ans)  

Measured memory_bytes: 150648
import math
N, M = map(int, input().split())
S = str(input())
T = str(input())

cnt = math.gcd(N, M)
ans = N * M // cnt
a, b = 0, 0
flag = False
for i in range(cnt):
  if S[a] != T[b]:
    flag = True
    break
  a += N//cnt
  b += M//cnt
  
if flag:
  ans = -1
print(ans)

Measured memory_bytes: 9284
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>

using namespace std;

typedef long long ll;

const int maxn = 1e5 + 10;

int root[maxn];

int get_root(int x){
	return root[x] = root[x] == x ? x : get_root(root[x]);
}

int N , Q;
ll M;
int l[maxn] , r[maxn] , cnt = 0;
int v[maxn];

void output(int x){
	cout << (x ? "Yes" : "No") << endl;
	exit(0);
}

int main(){
	cin >> N >> M >> Q;
	for(int i = 0 ; i < N ; ++ i)
		root[i] = i;
	for(int i = 1 ; i <= Q ; ++ i){
		int a , b , c;
		cin >> a >> b >> c;
		if(c == 0){
			int a1 = get_root(a) , b1 = get_root(b);
			if(a1 != b1)
				root[a1] = b1;
		}
		else{
			++ cnt;
			l[cnt] = a , r[cnt] = b;
		}
	}
	int sum = 0;
	for(int i = 0 ; i < N ; ++ i)
		if(root[i] == i)
			sum ++;
	if(sum == 1){
		if(cnt > 0)
			output(0);
		else if(M != N - 1)
			output(0);
		output(1);
	}
	else if(sum == 2){
		if(cnt > 0)
			output(0);
		else if(M != N - 2)
			output(0);
		output(1);
	}
	else{
		for(int i = 1 ; i <= cnt ; ++ i){
			int a1 = get_root(l[i]) , b1 = get_root(r[i]);
			if(a1 == b1)
				output(0);
			v[a1] = v[b1] = 1;
		}
		int s1 = 0;
		for(int i = 0 ; i < N ; ++ i)
			if(v[i] > 0)
				s1 ++;
		ll MINN = N - sum + (s1 == 2 ? 3 : s1) , MAXN = N - sum + 1ll * sum * (sum - 1) / 2;
		if(M >= MINN && M <= MAXN)
			output(1);
		output(0); 
	}
	return 0;
}

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

struct RQ {
 struct RQV{ ULL n[2], x; };
 using RQRV = bool;
 static RQV Zero(){ return RQV{{0,0},0}; }
 static RQRV RZero(){ return false; }
 // addition
 static RQV f(RQV a,RQV b){
  return {
    {a.n[0]+b.n[0],a.n[1]+b.n[1]},
    a.x+b.x+a.n[1]*b.n[0]
  };
 }
 // update function
 static void uf(RQV& a,RQV b){ a = b; }
 // effect of range queries n-sized
 static void ef(RQV& a,RQRV b,int n){
  if(b){
   swap(a.n[0],a.n[1]);
   a.x = a.n[0]*a.n[1] - a.x;
  }
 }
 // range query update
 static void ruf(RQRV& a,RQRV b){ a = (a != b); }
 // comparation
 static bool cmp(RQV l,RQV r){ return false; }
 struct Node{
  RQV v; RQRV r;
 };
 int N;
 vector<Node> V;

 void init(int n){
  N=1; while (N<n) N*=2;
  V.assign(N*2,{Zero(),RZero()});
 }

 void spread(int i,int z){
  if (z!=1) {
   ef(V[i*2].v,V[i].r,z/2);
   ruf(V[i*2].r,V[i].r);
   ef(V[i*2+1].v,V[i].r,z/2);
   ruf(V[i*2+1].r,V[i].r);
  }
  V[i].r = RZero();
 }

 void upd(int p,RQV v){
  for(int d=N; d>=1; d/=2) spread(p/d,d);
  p+=N; uf(V[p].v,v);
  int z=1;
  while(p!=1){
   p/=2; z*=2;
   V[p].v = f(V[p*2].v,V[p*2+1].v);
   ef(V[p].v,V[p].r,z);
  }
 }

 void updr(int l,int r,RQRV v,int a=0,int b=0,int i=-1){
  if(i==-1){ a=0; b=N; i=1; }
  spread(i,b-a);
  if(r<=a || b<=l) return;
  if(l<=a && b<=r){
   ruf(V[i].r,v);
   ef(V[i].v,V[i].r,b-a);
   return;
  }
  updr(l,r,v,a,(a+b)/2,i*2);
  updr(l,r,v,(a+b)/2,b,i*2+1);
  V[i].v = f(V[i*2].v,V[i*2+1].v);
  ef(V[i].v,V[i].r,b-a);
 }

 RQV query(int l,int r,int a=0,int b=0,int i=-1){
  if(i==-1){ a=0; b=N; i=1; }
  if(r<=a || b<=l) return Zero();
  if(l<=a && b<=r) return V[i].v;
  RQV q1 = query(l,r,a,(a+b)/2,i*2);
  RQV q2 = query(l,r,(a+b)/2,b,i*2+1);
  q1 = f(q1,q2);
  ef(q1,V[i].r,min(r,b)-max(l,a));
  return q1;
 }

 int find(int l,RQV v,int a=0,int b=0,int i=-1){
  static RQV x;
  if(i==-1){ a=0; b=N; i=1; x=Zero(); }
  spread(i,b-a);
  if(b<=l) return N;
  if(l<=a && !cmp(v,f(x,V[i].v))){ x=f(x,V[i].v); return N; }
  if(b-a==1) return a;
  int q1 = find(l,v,a,(a+b)/2,i*2);
  if(q1!=N) return q1;
  return find(l,v,(a+b)/2,b,i*2+1);
 }
};

int N,Q;
RQ G;

int main(){
 scanf("%d%d",&N,&Q);
 G.init(N);
 rep(i,N){
  int a; scanf("%d",&a);
  if(a==0) G.upd(i,{{1,0},0});
  else G.upd(i,{{0,1},0});
 }
 rep(q,Q){
  int c; scanf("%d",&c);
  if(c==1){
   int l,r; scanf("%d%d",&l,&r); l--;
   G.updr(l,r,true);
  }
  if(c==2){
   int l,r; scanf("%d%d",&l,&r); l--;
   printf("%llu\n",G.query(l,r).x);
  }
 }
 
 return 0;
}


Measured memory_bytes: 19624
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 11000


int dp[MAX];



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

	int hoge[10] = {INF,2,5,5,4,5,6,3,7,6};
	int N, M, n;
	vector<int> A;
	int nd, a;

	
	cin>>N>>M;
	
	n = N;
	
	for(int i = 0; i < M; i++){
		cin>>a;
		A.push_back(a);
	}
	sort(A.begin(),A.end());
	
	dp[0] = 0;
	
	for(int i = 1; i <= N; i++){
		dp[i] = -INF;
		for(int j = 0; j < A.size(); j++){
			if(hoge[A[j]] > i) continue;
			dp[i] = max(dp[i-hoge[A[j]]]+1,dp[i]);
		}
	}
	
	for(int i = N; i;){
		int num = -1;
		for(int j = 0; j < A.size(); j++){
			if(i-hoge[A[j]] < 0 ) continue;
			if(dp[i-hoge[A[j]]] == dp[i]-1)num = j;
		}
		i -= hoge[A[num]];
		cout<<A[num];
	}
	cout<<endl;
	
	return 0;
}

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

int main() {
    long a[101][101], b[101][101], c[101][101], n, m, l, i, j, k;

    cin >> n >> m >> l;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            cin >> a[i][j];
        }
    }

    for(i=1;i<=m;i++){
        for(j=1;j<=l;j++){
            cin >> b[i][j];
        }
    }

    for(i=1;i<=n;i++){
        for(j=1;j<=l;j++){
            c[i][j]=0;
            for(k=1;k<=m;k++){
                c[i][j]= c[i][j] + a[i][k]*b[k][j];
            }
        }
    }

    for(i=1;i<=n;i++){
        cout << c[i][1];
        for(j=2;j<=l;j++){
            cout << " " << c[i][j];
        }
        cout << endl;
    }

    return 0;
}


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

struct lr{
    ll left, right;
};

bool comp(const lr& lr1, const lr& lr2) {
  	if (lr1.right == lr2.right) return lr1.left > lr2.left;
    return lr1.right < lr2.right;
}

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

    ll n;
    cin >> n;
    vector<lr> p(n);
    ll x, l;
    REP(i, n) {
        cin >> x >> l;
        p[i] = {x - l, x + l};
    }

    sort(p.begin(), p.end(), comp);
    ll res = 0, curr = -1e15;
    REP(i, n) {
        if (p[i].left >= curr) {
            curr = p[i].right;
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
     int n;
     long long a[100005];
     cin >> n;
     long long ans=0;
     for (int i=1;i<=n;i++){
        cin >> a[i];
        ans+=a[i];
     }
     if (ans%2==0) cout << "YES\n";
     else cout << "NO\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<int, int> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	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;
	}
}

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

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


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

int main() {
ll n;
cin>>n;
ll a[n+1];
rep(i, n){
	cin>>a[i];
}

ll n4=0;
ll n2=0;
ll n1=0;
rep(i, n){
	if(a[i]%4==0) n4++;
	else if(a[i]%2==0) n2++;
	else n1++;
}

if(n2>=1 && n1<=n4){cout<<"Yes"<<endl;}
else if(n2==0 &&n1<=n4+1){cout<<"Yes"<<endl;}
else cout<<"No"<<endl;
return 0;



}




Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
	
int main(){
    ll N,min = 0,ans = 1,mini;
    ll i;
    cin >> N;
    vector<ll> P(N,0);
    for(i = 0;i < N;i++){
        cin >> P[i];
    }

    mini = P[0];

    for(i = 1;i < N;i++){
        if(P[i] <= mini){
            ans += 1;
            mini = P[i];
        }
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;


int main(){
    int n,k;
    cin >> n >> k;
    if(k==1) cout << 0 <<endl;
    else cout << n-k << endl;
    return 0;
    
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>
#include <utility>
#include <list>
#include <cmath>
#include <unordered_map>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const int INF = 1 << 29;
const LL MOD = 100000;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ int to, cost; edge(int t, int c) :to(t), cost(c){} };

int main()
{
	//while (cin >> n)
	stringstream ss;
	//ss << "result" << i + 1 << ".txt";
	//FILE* fp_out = freopen(ss.str().c_str(), "w", stdout);

	int n;
	while (cin >> n && n)
	{
		int k; cin >> k;
		vector<string> cards(n);
		rep(i, n) cin >> cards[i];

		vector<bool> used(n);
		set<string> memo;
		function<void(int, string)> dfs = [&](int rem, string str)
		{
			if (rem == 0)
			{
				memo.insert(str);
				return;
			}

			rep(i, n)
			{
				if (used[i]) continue;
				used[i] = true;
				dfs(rem - 1, str + cards[i]);
				used[i] = false;
			}
		};

		dfs(k, "");
		cout << memo.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 1472
import numpy as np

N, M, C, *_BA = map(int, open(0).read().split())
B = np.array(list(zip(*[map(int, iter(_BA))]*M))[0])
A = np.array(list(zip(*[map(int, iter(_BA))]*M))[1:])

print(sum(np.dot(A, B)+C > 0))

Measured memory_bytes: 12488
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
#define INF	100000000
#define pb	push_back
#define fi first
#define sec second
#define SS stringstream
using namespace std;
typedef pair<int, int> P;
typedef long long int	ll;

int a[3] = { 1, 0, 0};

int main(){
	string s;
	while(cin >> s){
		int temp1, temp2;
		if(s[0] == 'A') temp1 = 0;
		else if(s[0] == 'B') temp1 = 1;
		else if(s[0] == 'C') temp1 = 2;	
		if(s[2] == 'A') temp2 = 0;
		else if(s[2] == 'B') temp2 = 1;
		else if(s[2] == 'C') temp2 = 2;		
		swap(a[temp1], a[temp2]);
	}
	for(int i = 0; i < 3; i++){
		if(a[i] == 1){
			if(i == 0) cout << "A" << endl;
			if(i == 1) cout << "B" << endl;
			if(i == 2) cout << "C" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1176
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

ans = 1
dif = abs(A - (T - H[0] * 0.006))
for i in range(1, N):
    if dif > abs(A - (T - H[i] * 0.006)):
        dif = abs(A - (T - H[i] * 0.006))
        ans = i + 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  ll N, M; cin >> N >> M;
  ll c = N*2 + M;
  cout << min(c/4, M/2) << endl;
  return 0;
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define PB push_back
#define F first
#define S second

typedef unsigned long long llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int INF = 1e9+10;
const ll MOD = 1e9+7;

int dp[10007][107][2];
string s; int d;

int calc(int pos, int mod, int f){
	if(pos == (int)s.size())
		return (mod==0);
	if(dp[pos][mod][f] != -1)
		return dp[pos][mod][f];
	int mx = (f ? 9 : s[pos]-'0');

	int res = 0;
	for(int i = 0; i <= mx; i++){
		int ff;
		if(i < s[pos]-'0') ff = 1;
		else ff = f;
		res = ((ll) res + 1LL*calc(pos+1, (mod+i)%d, ff)) % MOD;
	}
	return dp[pos][mod][f] = res;
}

void solve(){
	cin >> s;
	cin >> d;

	memset(dp, -1, sizeof(dp));

	cout << (calc(0, 0, 0)-1 + MOD) % MOD << '\n';

}

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

	int t=1; //cin >> t;
	FOR(i, t){
	    solve();
	}

	return 0;
}

Measured memory_bytes: 9600
#include <cstdio>

bool check(int rest, int value)
{
    if (value == 105)
    {
        if (rest % 105 == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    for (int i = 0; rest - value * i >= 0; i++)
    {
        if (check(rest - value * i, value + 1))
            return true;
    }
    return false;
}

int main()
{
    int X;
    scanf("%d", &X);

    if (check(X, 100))
    {
        printf("%d\n", 1);
    }
    else
    {
        printf("%d\n", 0);
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int diff (int x, int y) {
	return (x > y) ? (x - y) : (y - x);
}

int main(void){
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	if ((diff(a, b) <= d && diff(b, c) <= d) || diff(a, c) <= d) {
		puts("Yes");
	} else {
		puts("No");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main() {
	cin.tie(0);ios::sync_with_stdio(false);
	int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
	string S;
	int dx = tx - sx;
	int dy = ty - sy;
 
	for (int i = 0; i < dy;i++) {
		S += "U";
	}
	for (int i = 0; i < dx; i++) {
		S += "R";
	}
	for (int i = 0; i < dy;i++) {
		S += "D";
	}
	for (int i = 0; i <= dx; i++) {
		S += "L";
	}
	for (int i = 0; i <= dy;i++) {
		S += "U";
	}
	for (int i = 0; i <= dx; i++) {
		S += "R";
	}
	S += "D";
	S += "R";
	for (int i = 0; i <= dy;i++) {
		S += "D";
	}
	for (int i = 0; i <= dx; i++) {
		S += "L";
	}
	S += "U";

	cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;
multiset<int> M;

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

    int n;
    cin >> n;
    REP(i, n){
        int x;
        cin >> x;
        M.insert(x);
    }
    auto itr = M.begin();
    int now = -1, ct = -1, ans = 0;
    while(itr != M.end()){
        if(*itr != now){
            ans += (ct - now >= 0 ? ct - now : ct);
            now = *itr;
            ct = 1;
            itr++;
        }else{
            ct++;
            itr++;
        }
    }
    ans += (ct - now >= 0 ? ct - now : ct);
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
#include<string>
#include <cstring>
#include <stack>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <cmath>
using namespace std;
#define INF 0x3f3f3f3f
#define mod 998244353
int main() {
	int q;
	long long a, b;
	cin >> q;
	while (q--) {
		cin >> a >> b;
		if (a > b) {
			swap(a, b);
		}
		long long t = a * b;
		long long s = sqrt(t);
		if (s * (s + 1) < t) {
			printf("%lld\n", s * 2 - 1);
		}
		else if (s * s == t) {
			if (a == b) {
				printf("%lld\n", (s - 1) * 2);
			}
			else
				printf("%lld\n", (s - 1) * 2 - 1);
		}
		else {
				printf("%lld\n",(s - 1) * 2);
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << c+b-d << " "<< d+c-a << " ";
    cout << a+b-d << " " << b+c-a << endl;
    return 0;
}

Measured memory_bytes: 256