akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace A
{

    class Program
    {
        public static void Main(string[] args)
        {
            var n = ReadLineIntSpilit();
            var a = ReadLineIntSpilit();

            var result = -1;
            var total = 0;

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

            if(total <= n[0]) {
                result = n[0] - total;
            }

            Console.WriteLine(result);
            ReadLine();

        }

        //最大公約数
        static int gcd(int a, int b)
        {
            if (a > b) {
                return gcd(b, a);
            }

            while (b != 0) {
                var remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }

        //最小公倍数
        static int lcm(int a, int b) => a * b / gcd(a, b);

        /// <summary>
        /// コンビネーション
        /// </summary>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        public static string ReadLine() => Console.ReadLine();
        public static int ReadLineInt() => int.Parse(Console.ReadLine());
        public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray();
        public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray();
        static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
        static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }
}

Measured memory_bytes: 20384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
  string s, t; cin >> s >> t;
  int ans = (int)t.size();
  for(int i = 0; i <= (int)s.size() - (int)t.size(); i++){
    int count = 0;
    rep(j,(int)t.size()) if(s[i+j] != t[j]) count++;
    chmin(ans,count);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
import sys
import numpy as np

def main():
  input = sys.stdin.readline
  d = int(input())
  c = np.array([int(x) for x in input().split()])
  
  last = np.zeros(26, dtype="int64")
  
  for i in range(d):
    s = np.array([int(x) for x in input().split()])
    key, value = -1, -1
    for i in range(26):
      if value < s[i] + last[i]:
        key = i
        value = s[i] + last[i]
    last[key] = 0
    print(key+1)
    last += c

if __name__ == "__main__":
  main()

Measured memory_bytes: 27308
// Example program
#include <iostream>
#include <string>
using namespace std;
int mat[5000][5000];
string a, b, kon;

void rek(int broj, int red, int kolona)
{
    for(int i= red; i>0; i--)
    {
        for(int j=kolona; j>0; j--)
        {
            if(mat[i][j]==broj && mat[i-1][j]<broj && mat[i][j-1]<broj && mat[i-1][j-1]<broj)
            {
                kon+=a[i-1];
                return rek(broj-1, i-1, j-1);
                
            }
        
        }
    }
    
}

int main()
{
    cin>>a>>b;
    
    for(int i=0; i<a.size()+1; i++) mat[i][0]=0;
    for(int i=0; i<b.size()+1; i++) mat[0][i]=0;
    
    
    for(int i=1; i<a.size()+1; i++)
    {
        for(int j=1;j<b.size()+1; j++)
        {
            if(a[i-1]==b[j-1])
            {
            mat[i][j]= max(mat[i-1][j], mat[i][j-1]);
            mat[i][j]= max(mat[i][j], mat[i-1][j-1]+1);    
            }
            else mat[i][j]= max(mat[i-1][j], mat[i][j-1]);
     //   cout<<mat[i][j]<<" ";
        }
       // cout<<endl;
    }
    
    rek(mat[a.size()][b.size()], a.size(), b.size());
    
    for(int i=kon.size()-1; i>=0; i--) cout<< kon[i];
    cout<<endl;
    }


Measured memory_bytes: 59392
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AABCSwap solver = new AABCSwap();
        solver.solve(1, in, out);
        out.close();
    }

    static class AABCSwap {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int x = in.nextInt();
            int y = in.nextInt();
            int z = in.nextInt();

            out.println(z + " " + x + " " + y);
        }

    }

    static class Scanner {
        private final InputStream in;
        private final byte[] buffer;
        private int ptr;
        private int buflen;

        public Scanner(InputStream in) {
            this.in = in;
            this.buffer = new byte[1024];
            this.ptr = 0;
            this.buflen = 0;
        }

        private boolean hasNextByte() {
            if (ptr < buflen) return true;
            else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) return false;
            }
            return true;
        }

        private byte readByte() {
            if (hasNextByte()) return buffer[ptr++];
            return -1;
        }

        private boolean isPrintableChar(byte c) {
            return '!' <= c && c <= '~';
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
                ptr++;
            }
        }

        public boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public int nextInt() {
            if (!hasNext()) throw new NoSuchElementException();
            int n = 0;
            boolean minus = false;
            byte b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 23252
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

LL mod = 998244353;

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

  LL N, M;
  cin >> N >> M;
  vector<LL> v(M, 0);
  REP(i,N){
    LL K;
    cin >> K;
    REP(j,K){
      LL a;
      cin >> a;
      v[a - 1]++;
    }
  }

  LL cnt = 0;
  REP(i, M)
  {
    if(v[i]==N){
      cnt++;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
c = [input() for _ in range(H)]
dist = [[-1]*W for _ in range(H)]

now = 0
for h in range(H):
    now = min(now,W-1)
    if c[h][now]!="#":
        print("Impossible")
        exit()
    for w in range(now,W):
        if c[h][w]==".":
            now-=1
            break
        else:
            dist[h][w]=0
            now+=1

for h in range(H):
    for w in range(W):
        if c[h][w]=="#" and dist[h][w]==-1:
            print("Impossible")
            exit()

if c[H-1][W-1]=="#":
    print("Possible")
else:
    print("Impossible")

Measured memory_bytes: 3064
#include <stdio.h>
int main(void) {
int A,B,C,K;
scanf("%d%d%d%d",&A,&B,&C,&K);
if(K<=A){
	printf("%d\n",K);
}else if(A<K&&K<=A+B){
	printf("%d\n",A);
}else{
	printf("%d\n",A-(K-(A+B)));
}
	return 0;
}


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

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
#define exit(a, b) return cout << a, b;

#define PB push_back
#define MP make_pair

#define sd(n) scanf("%lld", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

#define int long long
#define float long double 

const int upper = 4e5 + 2;
const int M = (int) 1e9 + 7;
const int inf = (int) 1e17;
const double eps =  1e-8;

int pw[100001];
int dp[10001][101][2];

signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif

	string k; 
	int d;
	cin >> k >> d;

	vector<int> n;
	for (auto i: k) {
		n.push_back(i - '0');
	}

	pw[0] = 1; 
	for (int i = 1; i <= 100000; i++) {
		pw[i] = (pw[i - 1] * 10) % d;
	}
	memset(dp, 0LL, sizeof dp);
	int sz = (int) k.size();

	for (int i = 0; i <= n[0]; i += 1) {
		dp[0][i % d][1 - (int) (i == n[0])] += 1;
	}
	for (int j = 1; j < sz; j += 1) {
		for (int newdig = 0; newdig < 10; newdig += 1) {
			for (int rem = 0; rem < d; rem += 1) {
				dp[j][(rem + newdig) % d][1] += ((newdig < n[j]) ? (dp[j - 1][rem][0]) : 0);
				dp[j][(rem + newdig) % d][1] += dp[j - 1][rem][1];
				dp[j][(rem + newdig) % d][0] += ((newdig == n[j]) ? (dp[j - 1][rem][0]) : 0);  

				dp[j][(rem + newdig) % d][1] %= M;
				dp[j][(rem + newdig) % d][0] %= M;
			}
		}
	}

	cout << (dp[sz - 1][0][1] + dp[sz - 1][0][0] - 1 + M) % M;
 	end_routine();	
}

Measured memory_bytes: 17024
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    string s;
    long long k;
    cin>>s>>k;
    int ans=1;
    
    for(int i=0;i<k;i++){
        if(s.at(i)!='1'){
            ans=s.at(i)-'0';
            break;
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}

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

int main() {
  vector<long> vin;
  long N;
  cin >> N;
  long vread;
  for (long i = 0; i < N; ++i) {
    cin >> vread;
    vin.push_back(vread);
  }
  sort(vin.begin(), vin.end());

  vector<long> coef;

  // でこぼこの形で2通り
  if (N % 2 == 0) {
    coef.push_back(1);
    coef.push_back(-1);
    for (long i = 0; i < N / 2; ++i) {
      coef.push_back(2);
    }
    for (long i = 0; i < (N - 2) / 2; ++i) {
      coef.push_back(-2);
    }
  } else {
    coef.push_back(-1);
    coef.push_back(-1);
    for (long i = 0; i < N / 2; ++i) {
      coef.push_back(2);
    }
    for (long i = 0; i < (N - 2) / 2; ++i) {
      coef.push_back(-2);
    }
  }

  long maxscore = 0;
  sort(coef.begin(), coef.end());
  long score = 0;
  for (long i = 0; i < N; ++i) {
    score += vin[i] * coef[i];
    maxscore = max(maxscore, score);
  }
  coef.clear();

  // 2通り目
  if (N % 2 == 0) {
    coef.push_back(1);
    coef.push_back(-1);
    for (long i = 0; i < N / 2; ++i) {
      coef.push_back(-2);
    }
    for (long i = 0; i < (N - 2) / 2; ++i) {
      coef.push_back(2);
    }
  } else {
    coef.push_back(1);
    coef.push_back(1);
    for (long i = 0; i < N / 2; ++i) {
      coef.push_back(-2);
    }
    for (long i = 0; i < (N - 2) / 2; ++i) {
      coef.push_back(2);
    }
  }

  sort(coef.begin(), coef.end());
  score = 0;
  for (long i = 0; i < N; ++i) {
    score += vin[i] * coef[i];
    maxscore = max(maxscore, score);
  }

  cout << maxscore << endl;

  return 0;
}

Measured memory_bytes: 2676
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int m500;
    int m100;
    int m50;
    int money;

    cin>>m500>>m100>>m50>>money;

    int x,y,z;
    int ans=0;

    for(x=0;x<=m500;x++){
        for(y=0;y<=m100;y++){
            for(z=0;z<=m50;z++){
                if(money==(x*500 + y*100 + z*50)){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;

void Calculate_Depth(vector<vector<int>>&edge, vector<int>&depth, int stnode) {
	depth[stnode] = 0;
	queue<int>Q;
	Q.push(stnode);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (auto i : edge[cn]) {
			if (depth[i] > depth[cn] + 1) {
				depth[i] = depth[cn] + 1;
				Q.push(i);
			}
		}
	}
	return;
}

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

	cin >> N >> K;
	vector<vector<int>>edge(N);
	for (int i = 1; i < N; i++) {
		cin >> L >> R;
		L--;
		R--;
		edge[L].push_back(R);
		edge[R].push_back(L);
	}
	if (K & 1) {
		int ans = MOD;
		for (int i = 0; i < N; i++) {
			for (auto j : edge[i]) {
				vector<int>v(N, MOD);
				vector<int>w(N, MOD);
				Calculate_Depth(edge, v, i);
				Calculate_Depth(edge, w, j);
				auto depth = v;
				for (int k = 0; k < N; k++)depth[k] = min(depth[k], w[k]);
				int box = 0;
				for (auto j : depth)box += j > K / 2;
				ans = min(ans, box);
			}
		}
		cout << ans << endl;
	}
	else {
		int ans = MOD;
		for (int i = 0; i < N; i++) {
			vector<int>depth(N, MOD);
			Calculate_Depth(edge, depth, i);
			int box = 0;
			for (auto j : depth)box += j > K / 2;
			ans = min(ans, box);
		}
		cout << ans << endl;
	}
	return 0;
};

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    map<ll, ll> m;
    rep(i, n) {
        ll a; cin >> a;
        m[a]++;
    }
    ll ans = 0;
    each(p, m) {
        if (p.second >= p.first) {
            ans += p.second - p.first;
        }
        else {
            ans += p.second;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6272
H, W = list(map(int, input().split()))
rows = []
for i in range(H):
    rows.append(input())

flag = True
output_rows = [['#' for _ in range(W)] for __ in range(H)]

for i in range(H):
    for j in range(W):
        if rows[i][j] != '#':
            continue
        else:
            found = False
            for (dx, dy) in [[0, -1], [0, 1], [-1, 0], [1, 0]]:
                y, x = i + dy, j + dx
                if x < 0 or x > W - 1 or y < 0 or y > H - 1:
                    continue
                else:
                    if rows[y][x] == '#':
                        found = True
            if not found:
                flag = False
                break

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
const int N=705,low=700;
int n,m,sum,c[N];
bool vis[N][N];
void dfs(int u,int x)
{
    c[u]=x;
    if(x==1) sum++;
    else sum--;
    for(int i=1;i<=n;i++)
        if(vis[u][i])
    {
        if(c[i])
        {
            if(c[i]==c[u])
            {
                printf("-1\n");exit(0);
            }
        }
        else dfs(i,c[u]==1?2:1);
    }
}
vector<int>v;
bool dp[N<<1],f[N<<1];
int main()
{
    memset(vis,true,sizeof(vis));
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) vis[i][i]=false;
    for(int i=1;i<=m;i++)
    {
        int u,v;scanf("%d%d",&u,&v);
        vis[u][v]=vis[v][u]=false;
    }
    for(int i=1;i<=n;i++)
        if(!c[i]) sum=0,dfs(i,1),v.push_back(sum);
    dp[0+low]=true;
    for(int i=0;i<v.size();i++)
    {
        memset(f,false,sizeof(f));
        for(int j=-n;j<=n;j++)
            if(dp[j+low])
        {
            f[j+low-v[i]]=true;
            f[j+low+v[i]]=true;
        }
        for(int j=-n;j<=n;j++)
            dp[j+low]=f[j+low];
    }
    int ans=inf;
    for(int i=-n;i<=n;i++)
        if(dp[i+low])
        {
            int a=(n+i)/2,b=n-a;
            if(a==0||b==0) continue;
            ans=min(ans,a*(a-1)/2+b*(b-1)/2);
        }
    if(ans==inf) ans=-1;
    printf("%d\n",ans);
}


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

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

    int N;
    string S, T;
    cin >> N >> S >> T;

    for (int i = 0; i < N; i++)
        cout << S[i] << T[i];

    cout << '\n';
}


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

int main() {
  int n;
  while(cin >> n && n) {
    vector<int> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i];
    int ans = 0;
    for(int i = 0; i < n; ++i) {
      for(int j = 0; j+1 < n-i; ++j) {
        if(a[j] > a[j+1]) {
          swap(a[j], a[j+1]);
          ++ans;
        }
      }
    }
    cout << ans << endl;
  }
}

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

int n, a[200004], l[200004], r[200004];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n;
	for(int i = 1;i<=n;i++)	cin>>a[i];
	
	// l[i] : maximum of a[1], a[2], ..., a[i]
	l[0] = 0;
	for(int i = 1;i<=n;i++)	l[i] = max(l[i-1], a[i]);
	
	// right[i] : maximum of a[i], a[i+1], ..., a[n]
	r[n+1] = 0;
	for(int i = n; i>=1; i--)	r[i] = max(r[i+1], a[i]);
	
	for(int i = 1;i<=n;i++)
		cout<<max(l[i-1], r[i+1])<<'\n';
	return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <cstdio>
#include <math.h>
 
using namespace std;  
typedef long long LL;
 
int N, A, B, h[(int)1e5];
 
bool judge(LL K) {
    LL sum = 0;
    for(int i = 0; i < N; i++) {
        LL t = (LL)h[i]-K*B;
        if (t > 0) {
            sum += (int)ceil(t*1.0/(A-B));
            if(sum > K)
                return false;
        }
    }
    return true;
}
 
int main()
{
    cin >> N >> A >> B;
 
    for (int i = 0; i < N; i++)
        scanf("%d", &h[i]);
 
    LL low = 0, high = (int)1e9;
 
    while (low < high) {
        LL mid = (low + high) / 2;
        if (judge(mid))
            high = mid;
        else
            low = mid+1;
    }
 
    cout << low << endl;
 
    return 0;
}

Measured memory_bytes: 640
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 2000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

ll fact[NMAX];

ll multiply(ll a, ll b)
{
	return (a*b) % MOD;
}

ll my_pow(ll n, ll x)
{
	ll y = 1;

	while(x)
	{
		if(x&1)
		{
			y = (y * n) % MOD;
		}
		n = (n * n) % MOD;
		x >>=1;
	}
	return y % MOD;
}

ll inv_fact(ll x)
{
	return my_pow(x,MOD-2);
}

ll combinari(ll n, ll k)
{
	if(n < k)
		return 0;
	if(n == k)
		return 1;
	
	ll res = 1;
	for(int i = n; i>= n - k + 1; --i)
	{
		res = (res * i) % MOD;
	}
	ll res2 = 1;
	for(int i = 1; i<= k; ++i)
	{
		res2=(res2*i) % MOD;
	}
	res2 = inv_fact(res2);
	return (res * res2) % MOD;
}

int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);

	fact[1] = 1;
	fact[0] = 1;
	for(int i = 2; i< NMAX; ++i)
	{
		fact[i] = (fact[i-1] * i) % MOD;
	}

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

	ll res = my_pow(2,n) - combinari(n,a);
	if(res < 0)
	{
		res+= MOD;
		
	}
	res%=MOD;
	res = res - combinari(n,b);
	if(res < 0)
	{
		res+= MOD;
	}
	res%=MOD;

	cout << res-1;



    return 0;
}

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

const int Nmax=200010;

int main() {
	int N;
	int A;
	cin >> N >> A;
	if(N % 500 <= A) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

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

#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

void solve()
{
	ll l,r,d,cnt=0;
	cin>>l>>r>>d;
	for(ll i=l;i<=r;i++) if(i%d==0) cnt++;
	cout<<cnt;
}

int main()
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

Measured memory_bytes: 3632
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvld;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    int N, K;
    cin >> N >> K;

    vi h(N);
    rep(i, N) cin >> h[i];

    vll dp(N, INF);
    dp[0] = 0;

    rep(i, N)
    {
        reple(k, 1, K)
        {
            //配るdp
            if(i + k < N) chmin(dp[i + k], dp[i] + abs(h[i] - h[i + k]));
        }
    }

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

    return 0;
}

Measured memory_bytes: 1408
// Problem : B - Minor Change
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s,t;
	cin>>s>>t;
	long long int ans = 0;
	for(int j = 0 ;  j < s.size(); j++)
	{
		if(s[j] != t[j])
		{
			ans += 1;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <vector>
#include <string>
#include <iterator>
#include <algorithm>

using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	vector<string> a(n), b(m);
	copy_n(istream_iterator<string>(cin), n, a.begin());
	copy_n(istream_iterator<string>(cin), m, b.begin());
	for(int i = 0; i < n - m + 1; i++){
		for(int j = 0; j < n - m + 1; j++){
			bool same = true;
			for(int k = 0; k < m; k++){
				for(int l = 0; l < m; l++){
					if(a[i + k][j + l] != b[k][l]){
						same = false;
						break;
					}else if(!same){
						break;
					}
				}
			}
			if(same){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

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

int main(){
	string s;cin>>s;
	string t="AKIHABARA";
	if(s.size()>t.size()){
		puts("NO");return 0;
	}
	rep(i,1<<(s.size()+1)){
		string a;
		rep(j,s.size()+1){
			if(i>>j&1)a+="A";
			if(j<s.size())a+=s[j];
		}
		if(a==t){
			puts("YES");
			return 0;
		}
	}
	puts("NO");
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a, b;

  scanf("%d %d", &a, &b);

  if(a<b)
    printf("a < b\n");
  if(a>b)
    printf("a > b\n");
  if(a==b)
    printf("a == b\n");

  return 0;
}

Measured memory_bytes: 580
#include <cstdio>
#include <iostream>

using namespace std;

int isi1[11];
int isi2[11];
int main(){
   int k,banyak,isi,i,faktorial,j,urutan1,urutan2,angka;
   urutan1=0;
   urutan2=0;
   scanf("%d", &k);
   getchar();
   faktorial=1;
   for(j=1;j<k;j++){
      faktorial=faktorial*(j+1);
   }
   for(i=1;i<=k;i++){
      isi1[i]=1;
      isi2[i]=1;
   }
   for(i=1;i<=k;i++){
      scanf("%d", &angka);
      getchar();
      isi1[angka]=0;
      banyak=0;
      for(j=1;j<angka;j++){
         banyak=banyak+isi1[j];
      }
      faktorial=faktorial/(k+1-i);
      urutan1=urutan1+(banyak*faktorial);
   }
   urutan1=urutan1+1;
   for(j=1;j<k;j++){
      faktorial=faktorial*(j+1);
   }
   for(i=1;i<=k;i++){
      scanf("%d", &angka);
      getchar();
      isi2[angka]=0;
      banyak=0;
      for(j=1;j<angka;j++){
         banyak=banyak+isi2[j];
      }
      faktorial=faktorial/(k+1-i);
      urutan2=urutan2+(banyak*faktorial);
   }
   urutan2=urutan2+1;
   if(urutan2>urutan1){
      cout<<urutan2-urutan1<<endl;
   }
   else{
      cout<<urutan1-urutan2<<endl;
   }
   
}

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

using ll = long long;
#define rep(n, i) for(ll i = 0; i < n; ++i)

void solve(void) {
  ll N, M, X; cin >> N >> M >> X;

  vector<ll> price(N, 0);
  vector<vector<ll>> textbook(N, vector<ll>(M, 0));
  for(ll i = 0; i < N; ++i) {
    cin >> price[i];
    for(ll j = 0; j < M; ++j) cin >> textbook[i][j];
  }

  ll res = 10000000;
  for(ll bit = 0; bit < (1 << N); ++bit) {

    ll cost = 0;
    vector<ll> exp(M, 0);
    ll count = 0;
    for(ll i = 0; i < N; ++i) {
      if(bit & (1 << i)) {
        cost += price[i];
        for(ll j = 0; j < M; ++j) exp[j] += textbook[i][j];
      }
    } 
    for(ll mi = 0; mi < M; ++mi) {
      if (exp[mi] >= X) count++;
    }
    if(count == M) res = min(res, cost); 
  }


  if (res != 10000000) cout << res << endl;
  else cout << "-1" << endl;
}

int main(void) {
  solve();
  return 0;
}

Measured memory_bytes: 3632
n=input()
l,r=int(n[:2]),int(n[2:])
if (r>12 or r==0) and l<=12 and l>0:
  print("MMYY")
elif r<=12 and r>0 and (l>12 or l==0):
  print("YYMM")
elif r<=12 and l<=12 and r>0 and l>0:
  print("AMBIGUOUS")
else:
  print("NA")

Measured memory_bytes: 3064
#include<cstdio>

int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}

int Pow(int x,int y){
    int ret=1;
    while(y){
        if(y&1) ret*=x;
        y>>=1;
        x=x*x;
    }
    return ret;
}

int main(){
    int N=read(),K=read();
    printf("%d",K*Pow(K-1,N-1));
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int a,b;
 	cin >> a >>b;
 	int x[a];
 	for (int i = 0; i < a; i++) {
 		cin >> x[i];
 		b=b-x[i];
 	}
 	sort(x,x+a);
 	cout << b/x[0]+a << endl;
 }

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

int main(){
    int n; cin >> n;
    int ans = 0;
    if(n >= 105)ans++;
    if(n >= 135)ans++;
    if(n >= 165)ans++;
    if(n >= 189)ans++;
    if(n >= 195)ans++;
    cout<<ans<<endl;
    return 0;
}


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

int main(){
   int N;
   std::cin >> N;

   int x0, y0, h0;
   int N1 = 0;
   int N2 = 0;
   int x1[N], y1[N], h1[N];
   int x2[N], y2[N], h2[N];
   for(int i=0; i<N; ++i){
      std::cin >> x0 >> y0 >> h0;
      if(h0>0){
	 x1[N1] = x0;
	 y1[N1] = y0;
	 h1[N1] = h0;
	 ++N1;
      }else{
	 x2[N2] = x0;
	 y2[N2] = y0;
	 h2[N2] = h0;
	 ++N2;
      }
   }

   std::vector<std::pair<int,int> > C;
   for(int j=0; j<=100; ++j){
      for(int k=0; k<=100; ++k){
	 if(N1>1){
	    if(h1[0]+abs(j-x1[0])+abs(k-y1[0]) == h1[1]+abs(j-x1[1])+abs(k-y1[1])) C.push_back(std::make_pair(j,k));
	 }else{
	    C.push_back(std::make_pair(j,k));
	 }
      }
   }
   
   for(int i=1; i<N1-1; ++i){
      for(int j=0; j<C.size(); ++j){
	 if(h1[i]+abs(C[j].first-x1[i])+abs(C[j].second-y1[i]) != h1[i+1]+abs(C[j].first-x1[i+1])+abs(C[j].second-y1[i+1])){
	    C.erase(C.begin()+j);
	    --j;
	 }

      }
      
   }
   for(int i=0; i<N2; ++i){
      for(int j=0; j<C.size(); ++j){
	 int H = h1[0] + abs(x1[0]-C[j].first) + abs(y1[0]-C[j].second);
	 if(H - abs(x2[i]-C[j].first) - abs(y2[i]-C[j].second)>0) {
	    C.erase(C.begin()+j);
	    --j;
	 }
      }
      if(C.size()==1) break;
   }

   std::cout << C[0].first << ' ' << C[0].second << ' ' << h1[0]+abs(x1[0]-C[0].first)+abs(y1[0]-C[0].second) << std::endl;
   return 0;
}


Measured memory_bytes: 512
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

int main() {
    string s, t; cin >> s >> t;
    int n = s.size(), m = t.size();
    int ans = 10000;
    rip(i, n-m+1,0) {
        int tmp = 0;
        rip(j,m,0) {
            if(s[i+j] != t[j]) ++tmp;
        }
        chmin(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3588
I=lambda:[int(i)for i in input().split()]
n,m=I()
P=I()
D={i:i for i in range(n+1)}
def U(x):
  if D[x]!=x:D[x]=U(D[x])
  return D[x]
for _ in [0]*m:
  x,y=I();D[U(x)]=U(y)
print(sum(U(i)==U(p)for i,p in enumerate(P,1)))

Measured memory_bytes: 20704
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
    int A,B,C,X,Y;
    int ans=INF;
    int N,M;
    cin >> A >> B >> C >> X >> Y;
    for(int i=0;i<=max(X,Y);i++){
        if(X-i<0)N=0;
        else N=X-i;
        if(Y-i<0)M=0;
        else M=Y-i;
        ans = min(ans,2*C*i+A*N+B*M);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back


int main(){

 int n,t;
 cin>>n>>t;

 cout<<max(0,n-t)<<endl;


return 0;
}













Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int n,i,kin=100000;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        kin*=1.05;
        if(kin%1000!=0){
            kin=kin-(kin%1000)+1000;
        }
    }
    printf("%d\n",kin);
	return 0;
}

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

/** Application main entry point. */
int main (
  int argc,
  char *argv[ ]
  )
{
  double a, b, c, d, e, f;

  while ( scanf ( "%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f ) == 6 )
  {
    printf ( "%.3lf %.3lf\n"
      , round ( ( c * e - b * f ) / ( a * e - b * d ) * 1000. ) / 1000. + 0.
      , round ( ( a * f - c * d ) / ( a * e - b * d ) * 1000. ) / 1000. + 0. );
  }

  return ( 0 );
}

Measured memory_bytes: 0
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

string S;
 
int ans = 0;

void solve(){
	int N = S.size();
	//Sの下からi(0<=i<=N-1)桁目をS[i]で取り出せるようにする
	reverse(S.begin(),S.end());
	int digit = 1;

	//Sを下からi桁目(1<=i<=N)まで見た時、13で割った余りがjとなるような
	//数値の数をdp[i][j]とおく
	vector<vector<int>> dp(N+1,vector<int>(13));
	dp[0][0] = 1;
	//ばらまくイメージのDP
	for(int i=0;i<N;i++){
		if(S[i]=='?'){
			for(int j=0;j<13;j++){
				for(int d=0;d<10;d++){
					dp[i+1][(j+d*digit)%13] += dp[i][j];
					dp[i+1][(j+d*digit)%13] %= mod_int;
				}
			}
			digit = (digit*10)%13;
			continue;
		}

		for(int j=0;j<13;j++){
			dp[i+1][(j+(S[i]-'0')*digit)%13] += dp[i][j];
			dp[i+1][(j+(S[i]-'0')*digit)%13] %= mod_int;
		}
		digit = (digit*10)%13;
	}
	ans = dp[N][5];
}

int main(){
    cin >> S;
 
    solve();
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8960
n,k = map(int,input().split())
mod = 10**9+7
l = [0]*(k+1)
ans = 0
for i in range(k,0,-1):
    a1 = k//i
    a2 = pow(a1,n,mod)
    j = 2
    while i*j <= k:
        a2 -= l[i*j]
        j += 1 

    ans += i*a2
    l[i] = a2
    ans %= mod
    
print(ans)

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

int GetDigit(const int n)
{
	int Digit = 1;
	int m = n;
	while(true){
		m /= 10;
		if(m == 0) break;
		Digit++;
	}
	return Digit;
}

int main()
{
	int a, b;
	while(true){
		cin >> a >> b;
		if(cin.eof()) break;
		cout << GetDigit(a+b) << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
N = int(input())

a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
check = []
for i in a:    
    ans += b[i-1]
    check.append(i)
    if check[check.index(i)-1] + 1 == check[check.index(i)]:
        ans += c[i-2]
    
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
	int moun[10];
	int loop_i;
	int temp[3];
	int top[3]={};
	for(loop_i = 0;loop_i < 10;loop_i++){
		fscanf(stdin,"%d",&moun[loop_i]);
		if(top[0] < moun[loop_i]){
			temp[0] = top[0];
			top[0] = moun[loop_i];
			temp[1] = top[1];
			top[1] = temp[0];
			top[2] = temp[1];
		}else if(top[1] < moun[loop_i]){
			temp[1] = top[1];
			top[1] = moun[loop_i];
			top[2] = temp[1];
		}else if(top[2] < moun[loop_i]){
			top[2] = moun[loop_i];
		}
	}
	printf("%d\n",top[0]);
	printf("%d\n",top[1]);
	printf("%d\n",top[2]);

	return 0;
}

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

int main(){
  int N; cin>>N;
  long long x; cin >>x;
  vector<long long> a(N);
  for (int i=0;i<N;++i)cin>>a[i];
  sort(a.begin(), a.end());
  int res=0;
  for (int i=0;i<N;++i){
    if (x>=a[i])++res,x-=a[i];
    else break;
  }
  if (res==N&& x) --res;
  cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}
  
int main() {
  int n, k, r, s, p;
  cin >> n >> k >> r >> s >> p;
  string ss;
  cin >> ss;
  vector<char> f(n, 'x');
  ll count = 0;
  for (int i = 0; i < k; i++) {
    if (ss[i] == 'r') {
      count += p;
      f[i] = 'r';
    }
    else if (ss[i] == 's') {
      count += r;
      f[i] = 's';
    }
    else {
      count += s;
      f[i] = 'p';
    }
  }
  for (int i = k; i < n; i++) {
    if (ss[i] == 'r' && f[i-k] != 'r') {
      count += p;
      f[i] = 'r';
    }
    else if (ss[i] == 's' && f[i-k] != 's') {
      count += r;
      f[i] = 's';
    }
    else if (ss[i] == 'p' && f[i-k] != 'p') {
      count += s;
      f[i] = 'p';
    }
  }
  printf("%lld\n", count);
} 


Measured memory_bytes: 512
import sys
input = sys.stdin.readline


def switches():
    n, m = map(int, input().split())
    states = [input().split() for _ in range(m)]
    p = list(map(int, input().split()))

    ans = 0
    for i in range(2 ** n):
        on_off = ['off'] * n
        count = [0] * m
        for j in range(n):
            if i >> j & 1:
                on_off[j] = 'on'
        for k in range(len(states)):
            v = states[k]
            for l in range(len(v)):
                if l == 0:
                    continue
                if on_off[int(v[l])-1] == 'on':
                    count[k] += 1
        count = [w % 2 for w in count]
        if count == p:
            ans += 1

    print(ans)


if __name__ == '__main__':
    switches()


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

int main(){
  int n,m,x[10000000],y[10000000],v=0;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    cin >> x[i];
  }
  sort(x,x+m);
  for(int i=0;i<m-1;i++){
    y[i]=abs(x[i+1]-x[i]);
    v+=y[i];
  }
  sort(y,y+(m-1),greater<int>());
  for(int i=0;i<n-1;i++){
    v-=y[i];
  }
  cout << v << endl;
} 


Measured memory_bytes: 4480
// ConsoleApplication2.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>

int main()
{
	int a, b, c, d, e,k;
	std::cin >> a;
	std::cin >> b;
	std::cin >> c;
	std::cin >> d;
	std::cin >> e;
	std::cin >> k;
	if (e-a <= k)
	{
		std::cout << "Yay!";
	}
	else
	{
		std::cout << ":(";
	}
}


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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P = pair<int, int>;

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

template <class T>
void dump_vec(const vector<T>& v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == (int)len - 1 ? "\n" : " ");
    }
}

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} FASTIO;

//---------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------

signed main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    rep(i, 0, N) cin >> A[i];
    auto sum = accumulate(all(A), 0);
    double d = (double)sum / (4.0 * M);
    int cnt = 0;
    rep(i, 0, N) {
        if (A[i] >= d) cnt++;
    }
    cout << (cnt >= M ? "Yes" : "No") << "\n";
}


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

int main()
{
    int n,m;
    cin >> n >> m;
    vector<vector<char>> a(n+10,vector<char>(n+10)),b(m+10,vector<char>(m+10));
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
        cin >> a[i][j];
        }
    }
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= m; j++){
        cin >> b[i][j];
        }
    }
    bool flag;
    int ans = 0;
    for(int i = 1; i <= n-m+1; i++){
        for(int j = 1; j <= n-m+1; j++){
            flag = true;
            for(int k = 1; k <= m; k++){
                for(int h = 1; h <= m; h++){
                    if(a[k+i-1][h+j-1] != b[k][h]){
                        flag = false;
                    }
                }
            }
            if(flag){
                ans++;
            }
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#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; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef pair<int, int> ii;
typedef long double ld;


int main() {
    int A,B;
    cin >>A>>B;
    int a,b,c,maxx;
    a=A+B;
    b=A-B;
    c=A*B;
    maxx=max({a,b,c});

    cout<<maxx<<endl;
    

  
}

Measured memory_bytes: 256
gets
l=gets.split.map{|c|[c.to_i]}
i=0
l.sort.map{|a|a[0]=i+=1}
b=[s=0]*(1+r=l.size)
l.reverse_each{|n,|i=n;(s+=b[i];i&=i-1)while i>0;(b[n]+=1;n+=n&-n)until n>r}
p s

Measured memory_bytes: 32612
#include <bits/stdc++.h>
using namespace std;
#define INF 100000000000

int main()
{
  int N, K;
  cin >> N >> K;
  vector<long long> a(N);
  long long ans = INF;
  for (int i = 0; i < N; ++i)
  {
    cin >> a.at(i);
  }
  for (int i = 0; i < 1 << N; ++i)
  {
    if (__builtin_popcountll(i) != K)
    {
      continue;
    }
    long long ans_i = 0, max_hight = 0;
    for (int j = 0; j < N; ++j)
    {
      if (1 << (N - j - 1) & i)
      {
        if (max_hight >= a.at(j))
        {
          ans_i += max_hight - a.at(j) + 1;
          max_hight += 1;
        }
      }
      max_hight = max(max_hight,a.at(j));
    }
    // bitset<15> bs(i);
    // cout << bs << endl;
    // cout << ans_i << endl;
    ans = min(ans, ans_i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	char s1, s2, s3;
	int count = 0;
	cin >> s1 >> s2 >> s3;

	count += (s1 == '1') ? 1 : 0;
	count += (s2 == '1') ? 1 : 0;
	count += (s3 == '1') ? 1 : 0;

	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include <vector>
#include <cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;

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;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
  	ci(n);
  vll A(n);
  FOR(i,0,n){
    ci(A[i])
  }
  SORT(A);
  co(A[n/2]-A[n/2-1])
}

Measured memory_bytes: 1024
import sys
from io import StringIO
import unittest

def resolve():
    s, w = map(int, input().split())

    if w >= s:
        print('unsafe')
    else:
        print('safe')

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """4 5"""
        output = """unsafe"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """100 2"""
        output = """safe"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """10 10"""
        output = """unsafe"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 16344