akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    double n,m;
    cin >> n >> m;
    double t = 1900 * m + 100 * (n-m);
    double sum = 0;
    double prob_prev = 1.0;
    double d = pow(2.0, m);
    reppp(i, 1, 100000){
        double diff = t * i * prob_prev;
        prob_prev *= 1.0 - 1.0/d;
        sum += diff;
        //cout << prob_prev << " " << diff << endl;
    }
    cout << (int)(sum+EPS)/d << endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define chmin(x,y) x = min(x, y)
#define chmax(x,y) x = max(x, y)
vector<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
vector<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    int n, m; cin >> n >> m;
    vector<vector<bool>> to(n, vector<bool> (n, false));
    rep(i, m) {
        int a, b; cin >> a >> b; a--; b--;
        to[a][b] = to[b][a] = true;
    }
    vector<int> vec(n);
    rep(i, n) vec[i] = i;
    int ans = 0;
    do {
        if (vec[0] != 0) continue;
        bool flag = true;
        rep(i, n-1) {
            if (!to[vec[i]][vec[i+1]]) flag = false;
        }
        if (flag) ans++;
    } while (next_permutation(all(vec)));

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

Measured memory_bytes: 3600
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 998244353;
const int IMAX = 100000;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

int dp[3001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N, S;
	scanf("%d %d", &N, &S);

	int A[3000];
	rep(i, N) scanf("%d", A + i);
	sort(A, A + N);

	ll k2 = modpow(2, mod - 2);
	dp[0] = modpow(2, N);
	int s = 0;
	ll kotae = 0;
	rep(i, N) {
		s = min(S - A[i], s + A[i]);

		if (S >= A[i]) kotae += dp[S - A[i]];
		for (int j = s; j >= A[i]; j--) {
			dp[j] = (dp[j] + dp[j - A[i]] * k2) % mod;
		}
	}

	printf("%lld\n", kotae % mod * k2 % mod);

	Would you please return 0;
}

Measured memory_bytes: 1748
#include <stdio.h>
#include <stdlib.h>
#define N 1000000
int partition(int *,int,int);
int main(){
  int i,j,n,*A;
  scanf("%d",&n);
  A=malloc(sizeof(int)*n+1);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  j=partition(A, 0, n-1);
    for(i=0;i<n-1;i++){
      if(i==j)printf("[%d] ",A[i]);
      else printf("%d ",A[i]);    
    }
  printf("%d\n",A[n-1]);
  return 0;
}
int partition(int *A,int p,int r){
  int x=A[r],i=p-1,j,temp;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
    }
  }
    temp=A[i+1];
    A[i+1]=A[r];
    A[r]=temp;
  
    return i+1;
  }



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

const long double pi = 3.14159265358979323865;

int main(){
  int a,b,h,m;
  cin >> a >> b >> h >> m;
  int minuits = h*60 + m;
  long double l_angle = 0.5*minuits;
  int s_angle = minuits*6%360;
  long double angle = min(abs(l_angle-s_angle),abs(360-(l_angle-s_angle)));
  long double cosain = cos(angle*pi/180);
  long double ans = sqrt(a*a + b*b - 2*a*b*cosain);
  cout << fixed << setprecision(9) << ans << endl;
}

Measured memory_bytes: 4152
#define _USE_MATH_DEFINES

#include <iostream>
#include <iterator>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <ctime>

using namespace std;
using ll = long long;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;

void solve() {
	ll cost[4];
	ll N;
	for (int i = 0; i < 4; i++)
		cin >> cost[i];
	cin >> N;
	N *= 4;
	for (int i = 1; i < 4; i++) {
		cost[i] = min(cost[i], cost[i - 1] * 2);
	}
	ll total = 0;
	for (int i = 3; i >= 0; i--) {
		ll q = N / (1 << i);
		total += cost[i] * q;
		N %= (1 << i);
	}
	cout << total;
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	solve();

#ifdef LOCAL
	cerr << double(clock()) / CLOCKS_PER_SEC << " sec" << endl;
#endif
	return 0;
}

Measured memory_bytes: 256
def main():
    k = int(input())
    lunluns = [i for i in range(1, 10)]
    if k <= len(lunluns):
        print(lunluns[k - 1])
        return

    while True:
        if k <= len(lunluns):
            print(lunluns[k - 1])
            return
        k -= len(lunluns)
        olds = lunluns
        lunluns = []
        for old in olds:
            for i in (-1, 0, 1):
                digit_next = old % 10 + i
                if digit_next < 0 or digit_next > 9:
                    continue
                new = old * 10 + digit_next
                lunluns.append(new)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11156
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int num=in.nextInt();
        int hw=in.nextInt();
        int sum=0;
        for (int i = 0; i <hw; i++) {
            int x=in.nextInt();
            sum=sum+x;
        }
        int ans=num-sum;
        if(ans<0){
            System.out.println(-1);
        }else{
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 46268
import Control.Applicative

solve :: Integer -> [[Integer]] -> Integer
solve c [] = c
solve c ([a,b]:ablist) = solve (c+e) ablist
  where d = a+c
        e = head [b*x-d|x<-[d`div`b..],b*x>=d]

main = do
  _ <- read <$> getLine :: IO Integer
  ablist <- reverse.map (map read.words).lines <$> getContents :: IO [[Integer]]
  print $ solve 0 ablist


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

int main()
{
    int d;
    cin >> d;
    int c[26];
    for(int i = 0; i < 26; i++) cin >> c[i];
    int s[400][26];
    for(int i = 0; i < d; i++){
        for(int j = 0; j < 26; j++) cin >> s[i][j];
    }
    for(int i = 0; i < d; i++){
        cout << i % 26 + 1 << endl;
    }
}


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

int main() {

    int K, A, B;
    cin >> K;
    cin >> A;
    cin >> B;
    
    for(int i = A; i <= B; i++){
        
        if(i % K == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    
     cout << "NG" << endl;
    return 0;
 
}

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

int main() {
  string A;
  cin >> A;
  vector<string> str = {"a", "e", "i", "o", "u"};
  bool x = false;
  for (string n : str) {
    if (A == n) {
      x = true;
    }
  }
  if (x) {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
def main():
    import heapq

    x, y, z, k, *abc = map(int, open(0).read().split())
    a = sorted(abc[:x], reverse=True)
    b = sorted(abc[x:x + y], reverse=True)
    c = sorted(abc[x + y:], reverse=True)
    s = set()

    h = [(-(a[0] + b[0] + c[0]), 0, 0, 0)]
    heapq.heapify(h)
    num = []
    for _ in range(k):
        p, i, j, k = heapq.heappop(h)
        num.append(-p)
        for p, q, r in [(1, 0, 0), (0, 1, 0), (0, 0, 1)]:
            if i + p < x and j + q < y and k + r < z:
                if (i + p, j + q, k + r) not in s:
                    s.add((i + p, j + q, k + r))
                    v = - (a[i + p] + b[j + q] + c[k + r])
                    heapq.heappush(h, (v, i + p, j + q, k + r))

    ans = '\n'.join(map(str, num))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5360
#include <stdio.h>
     
    int main(){
      int n;
      int i;
      int count=0;
      
      scanf("%d",&n);
      
      for(i=1;i<=n;i++){
        if(i>=1 && i<10){
          count++;
        } else if(i>=100 && i<1000){
          count++;
        } else if(i>=10000 && i<100000){
          count++;
        }
      }
      printf("%d",count);
    }

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

signed main(){
#ifdef _DEBUG
	freopen("_in" , "r", stdin );
	//freopen("_out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int a, b; cin >> a >> b;
	if (a >= 1 && a <= 9 && b >= 1 && b <= 9) cout << a * b << '\n';
	else cout << -1 << '\n';
}



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

using namespace std;

namespace IO {
	const int SIZE = 1 << 20;
	char buf[SIZE + 10], *iS, *iT;
	inline char Getc() {
		return iS == iT && (iT = (iS = buf) + fread(buf, 1, SIZE, stdin), iS == iT) ? EOF : *iS++;
	}
	template <class TT>
	inline void Read(TT &x) {
		x = 0; register char cc = '\0'; TT fff = 1;
		for (; cc < '0' || cc > '9'; cc = Getc())
			if (cc == '-') fff = -1;
		for (; cc >= '0' && cc <= '9'; cc = Getc())
			x = (x << 1) + (x << 3) + (cc & 15);
		x *= fff;
	}
}
using IO::Read;

const int N = 2e5 + 10, M = 1e6 + 10;

vector<int> bel[N];
pair<int, int> bufans[N]; int ctnum, Connect[N]; bool vis[N];
int n, tot, stp, edp, hd, tl, fans, Q[N + 10], dep[N], Cur[N], Head[N], Next[M], Adj[M], W[M];

inline void Addedge(int x, int y, int z) {
/*
	printf("%d %d %d\n", x, y, z);
*/
	Next[++tot] = Head[x]; Head[x] = tot; Adj[tot] = y; W[tot] = z;
	Next[++tot] = Head[y]; Head[y] = tot; Adj[tot] = x; W[tot] = 0;
}

inline bool BFS() {
	fill(dep, dep + 1 + edp, -1), hd = tl = 0;
	Q[++tl] = stp, dep[stp] = 0;
	while (hd != tl) {
		int x = Q[++hd];
		for (int e = Head[x]; e; e = Next[e])
			if (W[e] > 0 && dep[Adj[e]] == -1) {
				dep[Adj[e]] = dep[x] + 1;
				Q[++tl] = Adj[e];
			}
	}
	return dep[edp] != -1;
}

int DFS(int x, int mxflow) {
	if (x == edp || !mxflow) return mxflow;
	for (int &e = Cur[x]; e; e = Next[e])
		if (W[e] > 0 && dep[Adj[e]] == dep[x] + 1) {
			int ntflow = DFS(Adj[e], min(mxflow, W[e]));
			if (ntflow > 0) {
				W[e] -= ntflow;
				W[e ^ 1] += ntflow;
				return ntflow;
			}
		}
	return 0; /* star! */
}

inline void Dinic() {
	fans = 0;
	while (BFS()) {
		int nflow = 0;
		copy(Head, Head + 1 + edp, Cur);
		while ((nflow = DFS(stp, 0x3f3f3f3f)) != 0)
			fans += nflow;
	}
}

inline void Extend(int x) {
	for (int j = 0; j < (int)bel[x].size(); ++j)
		if (!vis[bel[x][j]]) {
			bufans[bel[x][j] - n] = make_pair(x, Connect[bel[x][j]]);
			vis[bel[x][j]] = true, Q[++tl] = Connect[bel[x][j]];
		}
}

inline void Solve() {
	for (int i = 1; i < n; ++i)
		for (int e = Head[n + i]; e; e = Next[e])
			if (Adj[e] <= n && W[e] > 0)
				Connect[n + i] = Adj[e];
	hd = tl = 0;
	Q[++tl] = 1;
	while (hd != tl) {
		int x = Q[++hd];
		++ctnum;
		Extend(x);
	}
}

int main()
{
	Read(n), tot = 1 /* !!! */;
	stp = 2 * n, edp = 2 * n + 1;
	for (int i = 2; i <= n; ++i) Addedge(stp, i, 1);
	for (int i = 1; i < n; ++i) Addedge(n + i, edp, 1);
	for (int i = 1, ilen; i < n; ++i) {
		Read(ilen);
		for (int j = 1, x; j <= ilen; ++j) {
			Read(x);
			bel[x].push_back(n + i);
		}
	}
	for (int i = 2; i <= n; ++i)
		for (int j = 0; j < (int)bel[i].size(); ++j /* not i */)
			Addedge(i, bel[i][j], 1);
	Dinic();
	if (fans < n - 1) {
		printf("-1\n");
		return 0;
	}
	Solve();
	if (ctnum < n) {
		printf("-1\n");
		return 0;
	}
	for (int j = 1; j < n; ++j)
		printf("%d %d\n", bufans[j].first, bufans[j].second);

	return 0;
}


Measured memory_bytes: 30464
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

struct dsu {
    vector<int> p;
    vector<int> sz;
    int n;

    dsu(int _n) : n(_n) {
        p.resize(n);
        iota(p.begin(), p.end(), 0);
        sz.assign(n, 1);
    }

    inline int get(int x) {
        if (p[x] == x) {
            return x;
        } else {
            return p[x] = get(p[x]);
        }
    }
    inline bool unite(int x, int y) {
        x = get(x);
        y = get(y);
        if (x == y) {
            return false;
        }
        if (sz[x] < sz[y]) {
            swap(x, y);
        }
        p[x] = y;
        sz[y] += sz[x];
        return true;
    }
    inline bool same(int x, int y) {
        return (get(x) == get(y));
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    dsu uf(n);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }
    vector<vector<ll>> tmp(n);
    for (int i = 0; i < n; i++) {
        tmp[uf.get(i)].emplace_back(a[i]);
    }
    vector<vector<ll>> c;
    for (int i = 0; i < n; i++) {
        if (!tmp[i].empty()) {
            sort(tmp[i].begin(), tmp[i].end());
            c.emplace_back(tmp[i]);
        }
    }
    int k = c.size();
    if (2 * (k - 1) > n) {
        cout << "Impossible" << '\n';
        return 0;
    } else if (k == 1) {
        cout << 0 << '\n';
        return 0;
    }
    ll ans = 0;
    vector<ll> t;
    for (int i = 0; i < k; i++) {
        ans += c[i][0];
        for (int j = 1; j < c[i].size(); j++) {
            t.emplace_back(c[i][j]);
        }
    }
    sort(t.begin(), t.end());
    for (int i = 0; i < k - 2; i++) {
        ans += t[i];
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 15840
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
using namespace std;

int main() {
    double N, K;
    cin >> N >> K;
    double ans = 0;
    for (ll i = 1; i <= N; ++i) {
        long double res = 1.0 / N;
        ll num = i;
        while (num < K) {
            num *= 2;
            res *= 0.5;
        }
        ans += res;
    }
    cout<<fixed;
    cout<<setprecision(10);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,t,p=0;
  cin>>n;t=n;
  r(i,1e9){
    t-=i;
    if(t<=0)break;
    p++;
  }
  t=abs(t);
  string s;
  r(i,p)s+=')';
  r(i,p)s+='(';
  if(t){
    s[p-t]='(',s[p-t+1]=')';
    for(int i=p-t+2;i<=p;i++)
      s[i]=')';
  }
  cout<<s<<endl;
}

Measured memory_bytes: 3292
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;
int main(){
    int N, count = 0;
    int a[100]={};
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < N; i = i+2)
    {
        if (a[i] % 2 != 0) count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using  namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	int ar[n];
	int dp[n];
	for(int i=0;i<n;i++)
		cin>>ar[i];
	if(n<=1){
		cout<<abs(ar[n-1]-ar[0]);
		return 0;
	}
	dp[0]=0;
	dp[1]=abs(ar[1]-ar[0]);
	for(int i=2;i<n;i++)
		dp[i]=min(abs(ar[i]-ar[i-1])+dp[i-1],abs(ar[i]-ar[i-2])+dp[i-2]);
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
from collections import deque
S=list(input())
Q=int(input())
A=deque()
O=deque()
flag=0
for i in range(Q):
    q=input()
    if q=='1':
        if flag==0:
            flag=1
        else:
            flag=0
    else:
        t,f,c=q.split()
        if flag==0:
            if f=='1':
                A.appendleft(c)
            else:
                O.append(c)
        else:
            if f=='1':
                O.append(c)
            else:
                A.appendleft(c)
if flag==0:
    R=list(A)+S+list(O)
else:
    R=list(O)[::-1]+S[::-1]+list(A)[::-1]  
print(''.join(R))

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

int main() {
  int N, Y; cin >> N >> Y;
  int a=-1, b=-1, c=-1;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      if (Y == 10000*i + 5000*j + 1000*(N-i-j) && N-i-j >=0) {
        a = i; b = j; c = N-i-j;
      }
    }
  }
  cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>

using namespace std;

const int MAX_V = 101;
const int INF = 1000000000;
vector <pair<int, int>> adj[MAX_V];
int V, E, K;
int dist[MAX_V];

void dijkstra(int s)
{
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
	fill(dist, dist + MAX_V, INF);
	dist[s] = 0;
	que.push(make_pair(s, 0));

	while (!que.empty())
	{
		pair <int, int> p = que.top();
		que.pop();
		int from = p.first;

		if (dist[from] < p.second)
		{
			continue;
		}


		for (auto it : adj[from])
		{
			int to = it.first;
			int cost = it.second;

			if (dist[to] > dist[from] + cost)
			{
				dist[to] = dist[from] + cost;
				que.push(make_pair(to, dist[to]));
			}
		}
	}
}

int main(void)
{
	int n, m;
	int a, b, c;
	int count = 0;

	cin >> n >> m;

	for (int i = 0; i < m; i++)
	{
		cin >> a >> b >> c;
		adj[a].push_back(make_pair(b, c));
		adj[b].push_back(make_pair(a, c));
	}

	for (int i = 0; i < 101 ; i++)
	{
		if (adj[i].size() != 0)
		{
			dijkstra(i);
			for (auto iter : adj[i])
			{
				if (iter.second > dist[iter.first])
				{
					count++;
				}
			}
		}
	}

	cout << count/2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int N, M;
std::string A[100];
int B[100];

bool match(const std::string& a, const std::string& s){
    REP(i, 8){
        if(a[i] == '*' || a[i] == s[i]);
        else{return false;}
    }
    return true;
}

int main(){
    while(std::cin >> N >> M, N){
        REP(i, N){
            std::cin >> A[i] >> B[i];
        }
    
        int res = 0;
        REP(i, M){
            std::string s;
            std::cin >> s;

            REP(j, N){
                if(match(A[j], s)){res += B[j];}
            }
        }

        std::cout << res << std::endl;
    }
}

Measured memory_bytes: 1208
def main():
    from builtins import int, map, list, print, len
    import sys
    sys.setrecursionlimit(10 ** 6)

    X = int(input())
    t = []
    i = 0
    while True:
        x = i ** 5
        t.append(x)
        if x > 10 ** 12:
            break
        i += 1
    d = {}
    for i in range(len(t)):
        for j in range(len(t)):
            d[t[i] - t[j]] = [i, j]
            d[t[i] + t[j]] = [i, -j]
            d[-t[i] - t[j]] = [-i, j]
            d[-t[i] + t[j]] = [-i, -j]
    print(d[X][0], d[X][1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 33216
N = int(input())
playlist = [input().split() for _ in range(N)]
X = input()
sleep = 0
ans = 0
for i in range(N):
  if(sleep == 1):
    ans += int(playlist[i][1])
  if(playlist[i][0] == X):
    sleep = 1
print(ans)
  

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  int n, q, ans = 0;
  int i, j;
  int S[10001], T[500];
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &T[i]);
  }

  for (i = 0; i < q; i++) {
    S[n] = T[i];
    j = 0;
    while (S[j] != T[i]) {
      j++;
    }
    if (j != n) {
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {

  string s;
  long long int k;
  cin >> s >> k;
  k--;
  int n = s.size();
  bool f = true;
  for(int i=0; i<n; i++){
    if( s[i] == '1' && i == k ) {
      cout << s[i] << endl;
      return 0;
    }else if(s[i] == '1'){
      continue;
    }else{
      cout << s[i] << endl;
      return 0;
    }
  }

  return 0;
}




//


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <unordered_map>

using namespace std;

const int64_t MOD = 998244353;

int main() {
	int a, b, t;
	cin >> a >> b >> t;
	int rep = (int)((t + 0.5) / a);
	cout << b * rep << endl;
	return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
const int INF=2012345678;
const ll LLINF=4012345678012345678LL;
const ll MOD=1000000007; //998244353; //
const ld PI=3.1415926535898;
const ld EPS=1e-9;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll expo(ll b,ll p,ll m){ll res=1; while(p){if(p&1)res=(res*b)%m; b=(b*b)%m; p>>=1;} return res;}
inline ll modinv(ll a,ll m){return expo(a,m-2,m);}

int main(){
	int h,w,k;scanf("%d%d%d",&h,&w,&k);
	int xa,ya,xb,yb;scanf("%d%d%d%d",&xa,&ya,&xb,&yb);xa--;ya--;xb--;yb--;
	char grid[h+5][w+5];
	for(int i=0;i<h;i++){
		scanf("%s",grid[i]);
	}
	pair<int,int> dist[4][h][w];
	for(int a=0;a<4;a++){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				dist[a][i][j]=mp(INF,INF);
			}
		}
	}
	int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
	deque<pair<int,int> > q;
	q.push_back(mp(xa,ya));for(int a=0;a<4;a++)dist[a][xa][ya]=mp(0,k);
	while(!q.empty()){
		pair<int,int> cur=q.front();q.pop_front();
		for(int i=0;i<4;i++){
			int nx=cur.fi+dx[i],ny=cur.se+dy[i];
			if(nx<0||ny<0||nx>=h||ny>=w)continue;
			if(grid[nx][ny]=='@')continue;
			for(int j=0;j<4;j++){
				if(i==j){
					if(dist[j][cur.fi][cur.se].se==k){
						if(dist[i][nx][ny].fi>dist[j][cur.fi][cur.se].fi+1){
							dist[i][nx][ny]=mp(dist[j][cur.fi][cur.se].fi+1,1);
							q.push_back(mp(nx,ny));
						}else if(dist[i][nx][ny].fi==dist[j][cur.fi][cur.se].fi+1){
							if(dist[i][nx][ny].se>1){
								dist[i][nx][ny]=mp(dist[j][cur.fi][cur.se].fi+1,1);
								q.push_back(mp(nx,ny));
							}
						}
					}else{
						if(dist[i][nx][ny].fi>dist[j][cur.fi][cur.se].fi){
							dist[i][nx][ny]=mp(dist[j][cur.fi][cur.se].fi,dist[j][cur.fi][cur.se].se+1);
							q.push_back(mp(nx,ny));
						}else if(dist[i][nx][ny].fi==dist[j][cur.fi][cur.se].fi){
							if(dist[i][nx][ny].se>dist[j][cur.fi][cur.se].se+1){
								dist[i][nx][ny]=mp(dist[j][cur.fi][cur.se].fi,dist[j][cur.fi][cur.se].se+1);
								q.push_back(mp(nx,ny));
							}
						}
					}
				}else{
					if(dist[i][nx][ny].fi>dist[j][cur.fi][cur.se].fi+1){
						dist[i][nx][ny]=mp(dist[j][cur.fi][cur.se].fi+1,1);
						q.push_back(mp(nx,ny));
					}else if(dist[i][nx][ny].fi==dist[j][cur.fi][cur.se].fi+1){
						if(dist[i][nx][ny].se>1){
							dist[i][nx][ny]=mp(dist[j][cur.fi][cur.se].fi+1,1);
							q.push_back(mp(nx,ny));
						}
					}
				}
			}
		}
	}
	/*
	for(int a=0;a<4;a++){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++)printf("%d ",dist[a][i][j].fi);
			printf("\n");
		}
		printf("\n");
	}
	 */
	int ans=INF;
	for(int i=0;i<4;i++)ans=min(ans,dist[i][xb][yb].fi);
	if(ans>=INF)printf("-1");
	else printf("%d",ans);
}


Measured memory_bytes: 36032
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long 
#define ll long long 
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair 
#define INF 1000000000
#define MOD 1000000007 
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)

using namespace std;

inline int getint()
{
	int x=0,p=1;char c;
	c=getchar();
	while (c<=32)c=getchar();
	if(c==45)p=-p,c=getchar();
	while (c>32)x=x*10+c-48,c=getchar();
	return x*p;
}

const int maxn=2e5+5;
int n,m=1,dat[4*maxn],a[maxn],cnt,dp[maxn],t;
vector<pii >v;


void fM(int k,int x)
{
	k+=m-1;
	dat[k]=x;
	while (k>0)
	{
		k=(k-1)/2;
		dat[k]=min(dat[2*k+1],dat[2*k+2]);
	}
}
int fQ(int x,int y,int l,int r,int k)
{
	if(y<=l||x>=r)return INF;
	else if(x<=l&&r<=y)return dat[k];
	else
	{
		int lx=fQ(x,y,l,(l+r)>>1,2*k+1);
		int ly=fQ(x,y,(l+r)>>1,r,2*k+2);
		return min(lx,ly);
	}
}


int main()
{
	n=getint();
	while (m<n+1)m<<=1;
	for(int i=0;i<2*m-1;i++)dat[i]=INF;
	for(int i=1;i<=n;i++)dp[i]=INF;
	 
	for(int i=1;i<=n;i++)
	{
	 	a[i]=getint();
	 	if(!a[i])a[i]--,dp[0]++;
	}
	 
	t=getint();
	rep(i,t)
	{
	 	int x=getint(),y=getint();
	 	v.push_back(mp(x,-y));
	}
	 
	sort(v.begin(),v.end());
	fM(0,dp[0]);

	 
	int p=0;
	for(int i=1;i<=n;i++)
	{
	 	while(p<t&&v[p].first==i)
		{
			int y=-v[p++].second;
			dp[y]=fQ(i-1,y+1,0,m,0);
			fM(y,dp[y]);
		}
		dp[i]=min(dp[i-1]+a[i],dp[i]);
		fM(i,dp[i]);
	}
	 
	printf("%d\n",dp[n]);

	return 0;	
} 

Measured memory_bytes: 6516
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(p) p.begin(), p.end()
#define pop_count(p) __builtin_popcountll(p)
#define len(s, e) ((e)-(s)+1)
#define mid(s, e) ((s)+((e)-(s))/2)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int oo = 987654321;
const ll OO = 1e18;
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
template <typename A, typename B>
std::ostream& operator <<(std::ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
std::ostream& operator <<(std::ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
std::ostream& operator <<(std::ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
std::ostream& operator <<(std::ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
template <typename T>
std::istream& operator >>(std::istream& in, vector<T>& a) {
  for (auto& v : a) in >> v;
  return in;
}
#ifdef ANEEE_LOCAL
template <typename T>
std::ostream& operator <<(std::ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
#else
template <typename T>
std::ostream& operator <<(std::ostream& out, const vector<T>& a) {
  for (const auto& v : a) out << v << ' ';
  return out;
}
#endif
#ifdef ANEEE_LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 7
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " | ";
  __f(comma + 1, args...);
}

class Timer {
	clock_t start;
public:
	Timer() {start = clock();}
	~Timer() {cerr << (double)(clock() - start)/CLOCKS_PER_SEC << "\n";}
};

#ifdef ONLINE_JUDGE
#undef CASE_INFO
#endif

void solve() {
	ll n, x, t;
	cin >> n >> x >> t;
	cout << (n+x-1)/x*t << endl;
}

signed main() {
	Timer ti;
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int T = 1;
	#ifdef TEST_CASES
	cin >> T;
	#endif
	for(int t = 1; t <= T; t++) {
		#ifdef CASE_INFO
		cout << "Case #" << t << ": ";
		#endif
		solve();
	}
	return 0;
}


Measured memory_bytes: 3848
import sys

[H,W,K]=[int(i) for i in sys.stdin.readline().split()]

arr=[]

for x in range(H):
	tmp=sys.stdin.readline().strip()
	arr.append(tmp)

rows=[0]*H
cols=[0]*W

total=0

for g in range(H):
	su=0
	for h in range(W):
		if(arr[g][h]=="#"):
			su+=1
			total+=1
	rows[g]=su

for p in range(W):
	su2=0
	for q in range(H):
		if(arr[q][p]=="#"):
			su2+=1
	cols[p]=su2

n1=pow(2,H)
n2=pow(2,W)

ans=0

for a in range(n1):
	for b in range(n2):
		rs=bin(a)[2:]
		cs=bin(b)[2:]
		
		rs="0"*(H-len(rs))+rs
		cs="0"*(W-len(cs))+cs

		num=total

		for p in range(len(rs)):
			if(rs[p]=="1"):
				num-=rows[p]

		for q in range(len(cs)):
			if(cs[q]=="1"):
				num-=cols[q]
				for g in range(len(rs)):
					if(rs[g]=="1" and arr[g][q]=="#"):
						num+=1

		if(num==K):
			ans+=1

print(ans)


Measured memory_bytes: 68880
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
vector<ll> v[4];
vector<ll> sum[4];

int main(int argc, char const* argv[])
{
  int n;
  ll W;
  cin >> n >> W;
  ll w0;
  for(int i = 0; i < n; i++){
    ll ww, vv;
    cin >> ww >> vv;
    if(i == 0)w0 = ww;
    v[ww - w0].pb(vv);
  }
  for(int i = 0; i < 4; i++){
    if(v[i].size() == 0)continue;
    sort(v[i].begin(), v[i].end(), greater<ll>());
    sum[i].pb(v[i][0]);
    for(int j = 1; j < v[i].size(); j++){
      sum[i].pb(sum[i][j-1] + v[i][j]);
    }
  }
  ll res = 0;
  for(int i = 0; i <= v[0].size(); i++){
    for(int j = 0; j <= v[1].size(); j++){
      for(int k = 0; k <= v[2].size(); k++){
        ll rem = W - i * w0 - j * (w0 + 1) - k * (w0 + 2);
        int remat = min((rem / (w0 + 3)), (ll)v[3].size());
        if(rem < 0)continue;
        ll tmp = 0;
        if(i > 0)tmp += sum[0][i - 1];
        if(j > 0)tmp += sum[1][j - 1];
        if(k > 0)tmp += sum[2][k - 1];
        if(remat > 0)tmp += sum[3][remat - 1];
        res = max(res, tmp);
      }
    }
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#define INF 10e10

using namespace std;

//  #define y cout << "yes"<< endl
  #define Y cout << "YES" << endl
  #define y cout << "Yes" << endl
//  #define n cout << "no"<< endl
  #define N cout << "NO" << endl
  #define n cout << "No" << endl
  #define pu(q) cout << q ;
  #define put(q) cout << q << " ";
  #define puts(q) cout << q << endl;
  
  
//	int a,b,c,d,e,f,g,h,ans,res;
	char a,b,c,d,e,f,g,h,ans,res;
//	string a,b,c,d,e,f,g,h,ans,res;
//	double a,b,c,d,e,f,g,h,ans,res;
	
void take(int x);
  
int main(void){
	take(4);//数
	
	
	if((a==b || b== c)||c==d){
		
		puts("Bad");
	//	y;	//Yes
	//	Y;	//YES
	//	n;	//No
	//	N;	//NO
	}
	/*
	else if(){
		
		
	//	y;
	//	Y;
	//	n;
	//	N;
		
	}
	else if(){
		
		
	//	y;
	//	Y;
	//	n;
	//	N;
		
	}
	else if(){
		
		
	//	y;
	//	Y;
	//	n;
	//	N;
		
	}
	*/
	else{
	puts("Good");	
		
	//	y;
	//	Y;
	//	n;
	//	N;
		
	}
//	cout << ans << endl;
	
	return 0;
}
void take(int x){
	if(x==1)
		cin >> a;
	else if(x==2)
		cin >> a >> b;
	else if(x==3)
		cin >> a >> b >> c;
	else if(x==4)
		cin >> a >> b >> c >> d;
	else if(x==5)
		cin >> a >> b >> c >> d >> e;
	else if(x==6)
		cin >> a >> b >> c >> d >> e >> f;
	else if(x==7)
		cin >> a >> b >> c >> d >> e >> f >> g;
	else if(x==8)
		cin >> a >> b >> c >> d >> e >> f >> g >> h;
	return ;
}

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

int main() {
	int n,k,m;
	while(scanf("%d%d%d",&n,&k,&m),n){
		m--;
		vector<int>v(n);
		iota(v.begin(),v.end(),1);
		while(v.size()>1){
			v.erase(v.begin()+m);
			m=(m+k-1)%v.size();
		}
		cout<<v[0]<<endl;
	}	
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  cin>>k;
  string s;
  cin>>s;
  if(s.size()<=k)cout<<s<<endl;
  else{
    string t(s.begin(),s.begin()+k);
    cout<<t<<"..."<<endl;
  }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define int long long 
int n,k,a[100005];
signed main()
{
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{
		int u,v;
		cin>>u;
		for(int i=1;i<=u;i++)
		{
			cin>>v;
			a[v]=1;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(!a[i])ans++;
	cout<<ans;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

void solve() {
  ll h, w; cin >> h >> w;
  ll cntw = 0;
  vector<string> grid(h);
  rep(i, h) {
    cin >> grid[i];
    rep(j, w) if (grid[i][j] == '.') cntw++;
  }

  const ll MAX = 50;
  ll mins[MAX][MAX] = {{}};
  rep(i, MAX)rep(j, MAX) mins[i][j] = INF;

  queue<ll> qx, qy, qc;
  qx.push(0); qy.push(0); qc.push(0);
  mins[0][0] = 0;

  while (!qx.empty()) {
    ll x = qx.front(); qx.pop();
    ll y = qy.front(); qy.pop();
    ll c = qc.front(); qc.pop();

    if (y == h-1 && x == w-1) {
      outl(cntw - c - 1);
      return;
    }

    for (int i = 0; i < 4; i++) {
      ll nx = x + dx[i];
      ll ny = y + dy[i];
      if (nx >= 0 && nx < w && ny >= 0 && ny < h && grid[ny][nx] == '.' && c + 1 < mins[ny][nx]) {
        mins[ny][nx] = c + 1;
        qx.push(nx);
        qy.push(ny);
        qc.push(c+1);
      }
    }
  }

  outl(-1);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> P;
int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n){
        cin >> a[i];
    }
    int ma = *max_element(a.begin(),a.end());
    int mi = *min_element(a.begin(),a.end());
    if(ma-mi > 1){
        puts("No");
        return 0;
    }
    if(ma==mi){
        if(ma*2<=n || ma==n-1){
            puts("Yes");
        }else puts("No");
        return 0;
    }
    if(ma==mi+1){
        int cnt = 0;
        rep(i,n){
            if(a[i] == mi)cnt++;
        }
        if(cnt < ma && 2*(ma-cnt)+cnt <= n){
            puts("Yes");
        }else puts("No");
        return 0;
    }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int v[n][3],p=0;
for(int i=0;i<n;i++)
{
    for(int j=0;j<3;j++)
        cin>>v[i][j];
}
int f[n][3];
f[0][0]=v[0][0],f[0][1]=v[0][1],f[0][2]=v[0][2];
for(int j=1;j<n;j++)
{
    for(int k=0;k<3;k++)
        f[j][k]=0;
}
if(n==1)
{
    int d=max(v[0][0],v[0][1]);
    int e=max(d,v[0][2]);
    cout<<e;
}
else
{
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<3;k++)
            {
                if(k==j)
                    continue;
                f[i][k]=max(f[i][k],f[i-1][j]+v[i][k]);
            }
        }
    }
    for(int j=0;j<3;j++)
    {
        if(f[n-1][j]>p)
            p=f[n-1][j];
    }
    cout<<p;
}
}


Measured memory_bytes: 2560
#include "stdio.h"

int main(){
  char a[5];
  scanf("%s", a);
  if((a[0] == a[1] && a[1] == a[2]) || (a[0] == a[1] && a[1] == a[3]) || (a[0] == a[2] && a[2] == a[3]) || (a[1] == a[2] && a[2] == a[3])){
    printf("No");
    return 0;
  }
  if(a[0] == a[1]){
    if(a[2] == a[3]){
      printf("Yes");
      return 0;
    }
  }
  if(a[0] == a[3]){
    if(a[1] == a[2]){
      printf("Yes");
      return 0;
    }
  }
  if(a[0] == a[2]){
    if(a[1] == a[3]){
      printf("Yes");
      return 0;
    }
  }
  printf("No");
  return 0;
 }


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

import javax.print.attribute.HashAttributeSet;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        HashSet<Integer>  a = new HashSet<>();
        for (int i = 0; i < N; i++) {
            a.add(ni());
        }
        
        long ans = a.size();
        out.println(ans);
    }

    final int mod = 1000000007;
    int mul(int x, int y){
        return (int)((x * 1L * y) % mod);
    }
    int add(int x, int y) {
        x += y;
        return x >= mod ? (x - mod) : x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        return x >= mod ? (x - mod) : x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 33036
def main():
    n, x, y = map(int,input().split())
    ans = [0] * n
    dp = [[0] * (n - 1) for i in range(n)]
    for i in range(1,n+1):
        for j in range(i,n+1):
            dirct = abs(i-j)
            mid_x = abs(x-i) + 1 + abs(y - j)
            mid_y = abs(y-i) + 1 + abs(x - j)
            ans[min(dirct, mid_x, mid_y)] += 1
    for i in range(1, n ):
        print(ans[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 78044
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
  return (a=a%b)?gcd(b,a):b;
}
int main(){
  int K,i,j,k,A=0;
  cin >> K;
  for(i=1;i<=K;i++){
    for(j=i;j<=K;j++){
      for(k=j;k<=K;k++){
        if(k==i)
          A+=k;
        else if(k==j)
          A+=3*gcd(j,i);
        else if(j==i)
          A+=3*gcd(k,j);
        else
          A+=6*gcd(k,gcd(j,i));
      }
    }
  }
    
  cout << A;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>

using namespace std;
typedef long long ll;

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

int main()
{
	int K;
	cin >> K;
	
	ll sum = 0;
	for(int a = 1; a <= K; a++){
		for(int b = 1; b <= K; b++){
			for(int c = 1; c <= K; c++){
				int ab = myGCD(a, b);
				int abc = myGCD(ab, c);
				sum += abc;
			}
		}
	}
	
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 3636
from math import gcd
from functools import reduce


def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    if K > max(A):
        print('IMPOSSIBLE')
        exit()
    if N == 1:
        if A[0] == K:
            print('POSSIBLE')
        else:
            print('IMPOSSIBLE')
        exit()
    
    A.sort()
    B = A[0]
    for i in range(N):
        B = gcd(B, A[i])

    if B == 1:
        print('POSSIBLE')
        exit()
    
    if K % B == 0:
        print('POSSIBLE')
        exit()

    print('IMPOSSIBLE')

    



if __name__ == "__main__":
    main()

Measured memory_bytes: 81128
#include <bits/stdc++.h>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
int main(void){
    int n,m,ans=0;
    cin>>n>>m;
    vector<int> a(n),b(n),c(m),d(m);
    rep(i,0,n)cin>>a[i]>>b[i];
    rep(i,0,m)cin>>c[i]>>d[i];
    rep(i,0,n){
        int minv=INF,id;
        rep(j,0,m){
            int num=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(num<minv){
                id=j;
                minv=num;
            }
        }
        cout<<id+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

map<ll, ll> mp;

void prime_factorize(ll n) {
    while (n % 2 == 0) mp[2]++, n /= 2;

    for (ll i = 3; i <= sqrt(n); i+=2) {
        while (n % i == 0) mp[i]++, n /= i;
    }

    if (n > 2) mp[n]++;
}

int main()
{
    ll N; cin >> N;
    for (ll i = 1; i <= N; i++) {
        prime_factorize(i);
    }

    ll o75 = 0, o25 = 0, o15 = 0, o5 = 0, o3 = 0;
    for (auto p : mp) {
        if (p.second + 1 >= 75) o75++;
        if (p.second + 1 >= 25) o25++;
        if (p.second + 1 >= 15) o15++;
        if (p.second + 1 >=  5)  o5++;
        if (p.second + 1 >=  3)  o3++;
    }

    ll ans = 0;
    ans += o75;
    ans += o25 * (o3 - 1);
    ans += o15 * (o5 - 1);
    ans += (o5 * (o5 - 1) / 2) * (o3 - 2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
const int inf = 1000000000; //10^9
using ll = long long;
using P = pair<int,int>;
//加算代入演算子は+=！！！！！

int main() {
    string s;
    cin >> s;
    if(s.at(2) == s.at(3) && s.at(4) == s.at(5)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: str):
    return YES if sum(map(int, N)) % 9 == 0 else NO

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = next(tokens)  # type: str
    print(solve(N))

def test():
    import doctest
    doctest.testmod()

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


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

using namespace std;

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}

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

	vector<int> health(n, k - q);

	for(int i = 0; i < q; ++i){
		health[a[i]]++;
	}

	for(int i = 0; i < n; ++i){
		cout << (health[i] > 0 ? "Yes" : "No") << endl;
	}

    return 0;
}


Measured memory_bytes: 1408