akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
from operator import itemgetter


def main():
    N, M = [int(x) for x in input().split()]
    PY = []
    for i in range(M):
        PY.append([int(x) for x in input().split()] + [i])


    PY_sorted = sorted(PY, key=itemgetter(0, 1))

    ans = [""] * M
    prev = 0
    yid = 0
    for i, v in enumerate(PY_sorted):
        if prev == 0 or prev == v[0]:
            yid += 1
        else:
            yid = 1
        prev = v[0]
        ans[v[2]] += str(v[0]).zfill(6) + str(yid).zfill(6)


    for a in ans:
        print(a)


if __name__ == '__main__':
    main()



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

 int main()
 {
 	int n;
 	cin>>n;
 	if(n%10 == 7 || n/10%10 == 7 || n/100 == 7)
 	    cout<<"Yes"<<endl;
 	else cout<<"No"<<endl;
 	
 	return 0;
 }

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

using namespace std;

set<string> cj;
string s;
int n;

int main() {
    ios_base::sync_with_stdio(0);

    cin >> n;
    while(n--) {
        cin >> s;
        cj.insert(s);
    }
    cout << cj.size() << endl;
    return 0;
}


Measured memory_bytes: 19252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,s,t) for(int i=s;i<t;i++)
const int MAXNUM = 150005;
int n;ll x;
struct node{
    ll b,l,r;
    bool operator<(const node &nn)const
    {
        return x*r-b*(r-l)>x*nn.r-nn.b*(nn.r-nn.l);
    }
};
node alln[MAXNUM];
int main()
{
    scanf("%d%lld",&n,&x);ll sum=0;
    rep(i,1,n+1)scanf("%lld%lld%lld",&alln[i].b,&alln[i].l,&alln[i].r),sum+=alln[i].b*alln[i].l;
    sort(alln+1,alln+n+1);
    ll nownum=0,r=0;int k=0;
    rep(i,1,n+1)
    {
        if(nownum+x*alln[i].r-alln[i].b*(alln[i].r-alln[i].l)>sum){k=i;break;}
        nownum+=x*alln[i].r-alln[i].b*(alln[i].r-alln[i].l),r+=x;
    }
    if(nownum==sum){printf("%lld\n",r);return 0;}
    ll res=1e18;
    rep(i,1,k)
    {
        ll xx=sum-(nownum-x*alln[i].r+alln[i].b*(alln[i].r-alln[i].l));
        xx-=x*alln[k].r-alln[k].b*(alln[k].r-alln[k].l);
        res=min(res,r+(xx/alln[i].l+(xx%alln[i].l!=0)));
        xx+=alln[i].b*(alln[i].r-alln[i].l);
        res=min(res,r+(xx/alln[i].r+(xx%alln[i].r!=0)));
    }
    rep(i,k,n+1)
    {
        ll xx=sum-nownum;
        res=min(res,r+(xx/alln[i].l+(xx%alln[i].l!=0)));
        xx+=alln[i].b*(alln[i].r-alln[i].l);
        res=min(res,r+(xx/alln[i].r+(xx%alln[i].r!=0)));
    }
    printf("%lld\n",res);
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//~ using namespace __gnu_pbds; 
#define mp make_pair
#define endl '\n'
typedef long long ll;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=1e6+5;
const int mod=1e9+7;	
const ll oo=1e18+5;

//~ typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	string s;
	int k;
	cin>>s>>k;
	int n=(int)s.size();
	vector<vector<vector<ll>>> dp(n+5,vector<vector<ll>>(k+5,vector<ll>(2)));
	dp[0][0][0]=1;
	for(int i=0;i<n;++i){
		for(int j=0;j<2;++j){
			for(int cnt=0;cnt<k+1;++cnt){
				int pre_num;
				if(j) pre_num=9;
				else pre_num=s[i]-'0';
				for(int dig=0;dig<=pre_num;++dig){
					dp[i+1][cnt+(dig!=0)][j||dig<pre_num]+=dp[i][cnt][j];
				}
			}
		}
	}
	cout<<dp[n][k][0]+dp[n][k][1];
	return 0;	
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b,num[1000],sum=0,i;
  scanf("%d %d",&a,&b);
  for(i=1;i<1000;i++){
    sum+=i;
    num[i]=sum;
  }
  printf("%d",(num[b-a]-b));
  return 0;
}
  


Measured memory_bytes: 128
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;
const int MOD = 1000000007;

int main() {
	int K, S, ans = 0;
	cin >> K >> S;
	FOR(X, 0, K) {
		FOR(Y, 0, K) {
			if (0 <= S - X - Y && S - X - Y <= K) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<ll>> matrix;
const int MOD = 1000000007;


string s;
int d;

int dp[105][2];
int ndp[105][2];

void solve() {
  cin >> s >> d;
  dp[0][1] = 1;
  for(int i = 0; i < s.size(); i++) {
    memset(ndp, 0, sizeof(ndp));
    for(int a = 0; a < d; a++) {
      for(int b = 0; b < 2; b++) {
        int bound = b == 1 ? s[i] - '0' : 9;
        for(int x = 0; x <= bound; x++) {
          ndp[(a+x)%d][b && x == bound] += dp[a][b];
          if(ndp[(a+x)%d][b && x == bound] >= MOD) ndp[(a+x)%d][b && x == bound] -= MOD;
        }
      }
    }
    memcpy(dp, ndp, sizeof(dp));
  }
  cout << (dp[0][0] + dp[0][1]+MOD-1)%MOD << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int m, f, r, sum = 0;
    
    while(1){
        scanf("%d %d %d", &m, &f, &r);
        if((m==-1) && (f==-1) && (r==-1)){
            break;
        }
        sum = m + f;
        if((m == -1)||(f == -1)) printf("F\n");
        else if(80 <= sum) printf("A\n");
        else if((65 <= sum) && (sum < 80)) printf("B\n");
        else if((50 <= sum) && (sum < 65)) printf("C\n");
        else if((30 <= sum) && (sum < 50)){
            if(r >= 50) printf("C\n");
            else printf("D\n");
        }
        else printf("F\n");
    }
    return 0;
}

Measured memory_bytes: 584
//AUTHOR: *Akash Shrivastva*
//Birla Institute of Technology,Mesra,India
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define M 1000000007
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define pll vector< pair <ll,ll> >
#define F first
#define S second
#define PII pair <ll,ll>
ll n,h[100003],dp[100003];
ll f(ll i)
{
	if (i>=n)	return 0;
	else if (dp[i]!=-1)	return dp[i];
	else
	{
		if (i+2<=n)	dp[i]=min(abs(h[i]-h[i+1])+f(i+1),abs(h[i]-h[i+2])+f(i+2));
		else	dp[i]=f(i+1)+abs(h[i]-h[i+1]);
		return dp[i];
	}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
  
    cin>>n;
    h[n+1],dp[n+1];
    memset(dp,-1,sizeof(dp));
    ll i;
    for (i=1;i<=n;i++)	cin>>h[i];
    cout<<f(1)<<endl;
}

Measured memory_bytes: 4224
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
ll N, M;

int main()
{
    cin >> N >> M;
    if (M % 2 == 1) {
        for (int i = 0; i < M / 2; i++) {
            cout << i + 1 << " " << M - i << endl;
        }
        for (int i = 0; i < M / 2 + 1; i++) {
            cout << M + 1 + i << " " << M * 2 + 1 - i << endl;
        }
    } else {
        for (int i = 0; i < M / 2; i++) {
            cout << i + 1 << " " << M - i << endl;
        }
        for (int i = 0; i < M / 2; i++) {
            cout << M + 1 + i << " " << 2 * M + 1 - i << endl;
        }
    }
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_E
#define M_E 2.71828182845904523536
#endif

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(x)
#endif

#define pln(x) cout << (x) << endl
#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

//template <typename T, typename U> T& chmin(T &a, const U &b){return a = (a<=b?a:b);}
template <typename T, typename U> bool chmax(T &a, const U &b){if(a<=b){a=b; return true;} return false;}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

const int c[10] = {0,2,5,5,4,5,6,3,7,6};

LLI dp[11000][10];
int restore[11000][10];

int main(){
 // cin.tie(0);
 // ios::sync_with_stdio(false);
  
  int N,M;
  while(cin >> N >> M){
    vector<int> A(M); cin >> A;
    sort(ALL(A));
    
    fill_array(dp, 0);
    fill_array(restore, 0);

    REPE(i,N){
      REP(j,M){
        if(dp[i][j] == 0 && i != 0) continue;
        REP(k,M){
          if(dp[i+c[A[k]]][k] == dp[i][j]+1){
            //cerr << i+c[A[k]] << " " << k << endl;
            chmax(restore[i+c[A[k]]][k], j);
          }else if(dp[i+c[A[k]]][k] < dp[i][j]+1){
            dp[i+c[A[k]]][k] = dp[i][j] + 1;
            restore[i+c[A[k]]][k] = j;
          }
        }
      }
    }
    
    //REP(i,M) cerr << dp[N][i] << " " ;
    //cerr << endl;
    
    string ans = "";
    
    int prev = 0;
    int mx = 0;
    REP(i,M) if(dp[N][i] >= mx){mx = dp[N][i]; prev = i;}
    
    int i = N;
    while(1){
      ans += ('0'+A[prev]);
      int t = prev;
      prev = restore[i][t];
      i -= c[A[t]];
      if(i <= 0) break;
    }
    
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

int n, m, cnt[32], ans;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
	{
		int k, cur;
		cin >> k;
		for (int j = 0; j < k; ++j) {
			cin >> cur;
			++cnt[cur];
		}
	}

	for (int i = 1; i <= m; ++i)
		if (cnt[i] == n)
			++ans;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {	
		int n;cin>>n;
		ll a[n];
		map<ll,ll>mp;
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			mp[a[i]]++;
		}
		vector<int>ans;
		ll tot=0;
		for(auto x: mp)
		{
			ll v=x.second;
			tot+=(v*1LL*(v-1))/2;
		}
		//cout<<tot;
		ll res=tot;
		for(int i=0;i<n;i++)
		{
			ll u=mp[a[i]];
			ll ways=(u*1LL*(u-1))/2;
			u--;
			ll sec=(u*1LL*(u-1))/2;
			tot-=ways;
			tot+=sec;
		
			cout<<tot<<endl;
			tot=res;
		}
		
}

Measured memory_bytes: 11008
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vdewansa
 */
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);
        CVacation solver = new CVacation();
        solver.solve(1, in, out);
        out.close();
    }

    static class CVacation {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int h[][] = new int[N][3];
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < 3; j++) {
                    h[i][j] = in.nextInt();
                }
            }
            long[][] best = new long[N][3];
            for (int j = 0; j < 3; j++) {
                best[0][j] = h[0][j];
            }
            for (int i = 1; i < N; i++) {
                for (int j = 0; j < 3; j++) {
                    for (int k = 0; k < 3; k++) {
                        if (k != j) {
                            best[i][j] = Math.max(best[i][j], best[i - 1][k] + h[i][j]);
                        }
                    }
                }
            }
            long res = 0;
            for (int j = 0; j < 3; j++) {
                res = Math.max(res, best[N - 1][j]);
            }
            out.println(res);
        }

    }
}



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

int main(){
  
  long long N, K, a, b, i, Num=0;
  cin>>N>>K;
  map<long long, long long> Data;
  
  for(i=0; i<N; i++){
    cin>>a>>b;
    Data[a]+=b;
  }
  
  for(auto p : Data){
    Num+=p.second;
    if(Num>=K){
      cout<<p.first<<endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 7520
#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

struct unionfind{
  vector<int> par;
  vector<int> rank;
  unionfind(int n=1){
    init(n);
  }
  void init(int n=1){
      par.resize(n); rank.resize(n);
      for(int i=0;i<n;++i) par[i]=i,rank[i]=0;
  }
  int root(int x){
    if(par[x]==x){
      return x;
    }
    else{
      int r=root(par[x]);
      return par[x]=r;
    }
  }
  bool issame(int x,int y){
    return root(x)==root(y);
  }
  bool merge(int x,int y){
    x=root(x); y=root(y);
    if(x==y) return false;
    if(rank[x]<rank[y]) swap(x,y);
    if(rank[x]==rank[y]) ++rank[x];
    par[y]=x;
    return true;
  }
};

int main(){
  itn n,q; cin >> n >> q;
  unionfind uf(n);
  rep(i,q){
    itn t,u,v;
    cin >> t >> u >> v;
    if(t==0) uf.merge(u,v);
    else cout << uf.issame(u,v) << endl;
  }
  
}

Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  string s, t;
  cin >> s >> t;
  ll ans = 1e18;

  ll n = SZ(s), m = SZ(t);
  for (ll i = 0; i + m - 1 < n; i++) {
    ll cnt = 0;
    FOR(j, i, i + m) {
      if (t[j - i] != s[j]) {
        cnt++;
      }
    }
    ans = min(ans, cnt);
  }

  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000


int main(){

	int n,m;
	cin>>n>>m;
	
	cout<<(n-1)*(m-1)<<endl;
	
    return 0;
}



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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

#define P pair<lli,lli>

signed main(){

	lli n,q;
	cin>>n>>q;

	priority_queue<P,vector<P>,greater<P>> sq;
	priority_queue<P,vector<P>,greater<P>> tq;


	REP(i,0,n){
		lli s,t,x;
		cin>>s>>t>>x;
		sq.push({s-x,x});
		tq.push({t-x,x});
	}

	multiset<lli> ms;
	REP(i,0,q){
		lli d;
		cin>>d;
		while(sq.size() && sq.top().first<=d){ms.insert(sq.top().second);sq.pop();}
		while(tq.size() && tq.top().first<=d){ms.erase(ms.find(tq.top().second));tq.pop();}
		if(ms.size()==0){
			cout<<-1<<endl;
		}
		else{
			auto itr = ms.begin();
			cout<<(*itr)<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 17884
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int n;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	long long sum = 0;
	for(int i = 1; i <= n; i++)
		if(i % 5 && i % 3) sum += i;
	cout << sum << "\n";
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
using namespace std;
char ch[12][12];
int dh[]={1,0,-1,0},dw[]={0,-1,0,1};
void dfs(int h,int w){
	  ch[h][w]='0';
	  for(int i=0;i<4;i++){
			int nx=h+dh[i],ny=w+dw[i];
			if(nx>=0&&nx<12&&ny>=0&&ny<12&&ch[nx][ny]=='1')dfs(nx,ny);
	  }
	  return ;
}
int main(){
	  while(cin>>ch[0]){
			int solve=0;
			for(int i=1;i<12;i++)cin>>ch[i];
			for(int i=0;i<12;i++){
				  for(int j= 0;j<12;j++)
				  if(ch[i][j]=='1'){dfs(i,j);solve++;}
			}
			cout << solve << endl;
	  }
}

Measured memory_bytes: 1140
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

const int MAX_N=16;
const int INF=1<<30;
int memo[1<<MAX_N];

int t[MAX_N][MAX_N+1];

int getMin(int n){
  for(int i=1;i<=n;i++){
    int a[MAX_N];
    fill_n(a,MAX_N,1);
    fill_n(a,i,0);
    do{
      int comb=0; REP(j,n)comb=(comb<<1)+a[j];
      int minimum=INF;
      REP(j,n){
	int lowlevel=1<<(n-j-1);
	if((comb&lowlevel)==0){
	  int lowcomb=comb|lowlevel;
	  int lmin=memo[lowcomb]+t[j][0];
	  // cout<<"---->>>>";
	  // for(int k=n-1;k>=0;k--)cout<<(((lowcomb&(1<<k))!=0)?1:0);
	  // cout<<endl;
	  REP(k,n)
	    if(a[k]==1){
	      lmin=min(lmin,memo[lowcomb]+t[j][k+1]);
	    }
	  minimum=min(minimum,lmin);
	}
      }
      memo[comb]=minimum;
      // REP(j,n)cout<<a[j];
      // cout<<" "<<minimum<<endl;
    }while(next_permutation(a,a+n));
  }
  return memo[0];
}

int main(){ _;
  int n;
  while(cin>>n,n!=0){
    memo[(1<<n)-1]=0;
    REP(i,n)REP(j,n+1)cin>>t[i][j];
    cout<<getMin(n)<<endl;
  }
}

Measured memory_bytes: 1452
import math

A, B, H, M = map(int, input().split())
vh = (360 * H /12 )%360
vl = (360 * M /60 )%360
vh += (30 * M /60 )%30
X= abs(vh-vl)
print((A**2 +B**2 - 2 * A * B * math.cos(math.radians(X)))**0.5)

Measured memory_bytes: 9516
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i,k) for(i=0;i<k;i++)
ll n, k, b,l,r, e = 2019, f = 0, i, j, g=1000000007, m,a,c,d;


int main() {
	a = 2019;
	cin >> l >> r;
	b = l % a;
	c = r % a;
	if (b > c || (r - l) >= a)e = 0;
	else {
		for (i = b; i < c; i++) {
			for (j = i + 1; j <= c; j++) {
				f = (i * j) % a;
				e = min(f, e);
			}
		}

	}
	cout << e;

	return 0;
}

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

#define ll long long int
#define f(i,n) for(ll i = 0; i < n ; i++)
#define fn(i,n) for(ll i = 1; i <= n ; i++)
#define F first 
#define pb push_back
#define S second
using namespace std;
ll dp[100005][4];
ll n,W;
ll mn = INT_MAX;
ll sol(ll a[], ll w[], ll W)
{
   ll dp[n+1][W+1];
   memset(dp,0,sizeof(dp));
   fn(i,n)
   {
     for(ll j = 1; j <= W ; j++)
     {
        if(j >= w[i-1])
          dp[i][j] = max(dp[i-1][j], a[i-1] + dp[i-1][j - w[i-1]]);

        else
          dp[i][j] = dp[i-1][j];

     }
   }
   return dp[n][W];
}


 
int main()
{

     #ifndef ONLINE_JUDGE
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
     #endif
     
         //ll n;
         cin>>n>>W;
         ll p[n],w[n];
        
         f(i,n)
         {
            cin>>w[i]>>p[i];
         }
         //f(i,10) dp[i] = 100;
         memset(dp,-1,sizeof(dp));
         cout<<sol(p,w,W);
         //cout<<dp[0][3]<<endl;
         
        
         
   return 0;
}


Measured memory_bytes: 85544
S = list(input())
T = list(input())
n = len(S)
if S == T :
    print('Yes')
else :
    for i in range(n-1) :
        a = S[n-1]
        S[1:n] = S[0:n-1]
        S[0] = a
        if S == T :
            print('Yes')
            break
    else :
        print('No')

Measured memory_bytes: 3064
//エイシングコンテスト A
#include<bits/stdc++.h>
using namespace std;

int main(){
    int a,b,c,d,e;
    cin >> a >> b >>c;
    d = a / c;
    e = b / c;
    if(a % c==0){
      d = e - d+1;}else{
    d = e -d;
    }
    cout << d <<endl;
}

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

int main() {
 
  string s;
  cin >> s;
  int n=s.length();
  int p=2019;
  vector<int> d(n+1);
  int ten = 1;
  for (int i = n-1; i >= 0; --i) {
    int a = (s[i]-'0') * ten % p;
    d[i] = (d[i+1]+a) % p;
    ten *= 10; ten %= p;
  }
  vector<int> cnt(p);
  ll ans = 0;
  for (int i = n; i >= 0; --i) {
    ans += cnt[d[i]];
    cnt[d[i]]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4468
#include<stdio.h>

int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if((x+r)<=W && (x-r)>=0 && (y+r)<=H && (y-r)>=0){
        printf("Yes\n");
        }else{printf("No\n");
    }
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const int MAX_N = 2e5+7;

ll N;
vvl G(MAX_N);
vl cs(MAX_N), tree_size(MAX_N), color_cnts(MAX_N,0);
vl ans(MAX_N);

ll nc2(ll x) { return x*(x-1)/2; }

void calc_size(int v, int par = -1) {
    tree_size[v] = 1;
    for (auto to : G[v]) {
        if (to == par) continue;
        calc_size(to, v);
        tree_size[v] += tree_size[to];
    }
}
void dfs(int v, int par = -1) {
    ll prev_cnt = color_cnts[cs[v]];
    for (auto to : G[v]) {
        if (to == par) continue;
        ll prev = color_cnts[cs[v]];
        dfs(to, v);
        ll diff = color_cnts[cs[v]] - prev;
        ll cnt = tree_size[to] - diff;
        cerr << v << "->" << to << ": " << cnt << "\n";
        ans[cs[v]] -= nc2(cnt);
    }
    color_cnts[cs[v]] = prev_cnt + tree_size[v];
}

int main() {
    cin >> N;
    ans.assign(MAX_N, nc2(N));
    rep(i,N) cin >> cs[i+1], ans[cs[i+1]]++;
    rep(i,N-1) {
        int u, v; cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    calc_size(1);
    dfs(1);
    rep(c,N) ans[c+1] -= nc2(N-color_cnts[c+1]);
    rep(i,N) cout << ans[i+1] << "\n";
    return 0;
}


Measured memory_bytes: 42120
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

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


def dfs(v, v_p, target):
    if v == target:
        return True, 0

    path = 0
    for v_next, edge_idx in graph[v]:
        if v_next == v_p:
            continue
        is_target, path = dfs(v_next, v, target)
        if is_target:
            return is_target, path | (1 << edge_idx)
    return False, 0


m = int(input())
cond = []
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    _, path = dfs(u, -1, v)
    # print(u, v, bin(path))
    cond.append((u, v, path))

ans = 1 << (n - 1)
for bit in range(1, 1 << m):
    cnt = [0] * n
    l = 0
    path = 0
    for i, (u, v, path_i) in enumerate(cond):
        if (bit >> i) & 1:
            l += 1
            path = path | path_i

    # print(bin(bit), cnt)
    c = n - 1 - bin(path).count('1')
    # print(bin(bit), cnt, c, l)
    ans += ((-1)**(l % 2)) * (1 << c)

print(ans)


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

int main() {
  int N = 1, A = 0, num_500_coin = 0;

  cin >> N >> A;
  num_500_coin = N / 500;

  if ((N - num_500_coin * 500) <= A){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define enum(i,x,y) for(int i=(x);i<=(y);++i)
#define try(i,x,y) for(int i=(x);i>=(y);--i)
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=305;

int n,m;
char s[MAXN];
int f[MAXN][MAXN][MAXN];

int main()
{
	#ifndef ONLINE_JUDGE
    //freopen("code.in","r",stdin);
    //freopen("code.out","w",stdout);
	#endif
	scanf("%s",s+1);readint(m);n=strlen(s+1);
	enum(i,1,n)
		enum(k,0,m)
			f[i][i][k]=1;
	enum(len,2,n)
		enum(i,1,n-len+1)
		{
			int j=i+len-1;
			enum(k,0,m)
			{
				f[i][j][k]=max(f[i+1][j][k],f[i][j-1][k]);
				if(s[i]==s[j])chkmax(f[i][j][k],f[i+1][j-1][k]+2);
				if(k)chkmax(f[i][j][k],f[i+1][j-1][k-1]+2);
			}
		}
	printf("%d\n",f[1][n][m]);
    return 0;
}

Measured memory_bytes: 110464
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  int N;
  cin >> N;
  int s[N];
  int sum=0;
  int smin=INT_MAX;
  rep(i,N){
    cin >> s[i];
    sum += s[i];
    if(s[i]%10!=0) smin = min(smin,s[i]);
  }
  if(sum%10!=0) cout << sum << endl;
  else if(smin!=INT_MAX) cout << sum - smin << endl;
  else cout << 0 << endl;
  return 0;

}


Measured memory_bytes: 256
fun main() {
  val N = readInt()
  val CN = readString().toMutableList()
  var l = 0
  var r = N - 1
  var cnt = 0
  while (true) {
    while (l < N) if (CN[l] == 'W') break else l++
    while (r >= 0) if (CN[r] == 'R') break else r--
    if (l >= r) break
    CN[l] = 'R'
    CN[r] = 'W'
    cnt++
  }
  println(cnt)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 42028
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
#include<utility>
#include<vector>
using namespace std;
//--------------------

int main() {

	long res = 0;
	long N, D; cin >> N >> D;
	long X[100][100]; for (int i = 1; i <= N; i++) for (int j = 1; j <= D; j++) cin >> X[i][j];

	for (int p = 1; p <= N; p++) for (int q = p + 1; q <= N; q++) {

		long sqdis = 0;

		for (int s = 1; s <= D; s++) sqdis += (X[p][s] - X[q][s]) * (X[p][s] - X[q][s]);

		if ((long)sqrt((double)sqdis) * (long)sqrt((double)sqdis) == sqdis) res++;

	}


	cout << res << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0; i < N; ++i){
        cin >> vec[i];
    }
    int count = 0;
    bool isOdd = false;
    while(true){
        for(int i = 0; i < N; ++i){
            if(vec[i]%2 != 0){
                isOdd = true;
                break;
            }
            vec[i] = vec[i]/ 2;
        }
        if(isOdd)
            break;
        ++count;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#define FAST ios::sync_with_stdio(false)
typedef long long ll;
const int maxn = (int)1e5 + 5;
using namespace std;

int length(ll n){
	return log10(n) + 1;
}

bool cmp(int x, int y){
	return x > y;
}

ll quickpow(ll x, ll y, ll mod){
	ll res = 1;
	while(y){
		if(y & 1) res = (res * x) % mod;
		y >>= 1;
		x = (x * x) % mod;
	}
	return res;
}


int main()
{
	FAST;
	int t;
	cin >> t;
	while(t--){
		ll a, b;
		cin >> a >> b;
		ll c = (int)sqrt(a*b);
		if(c * (c + 1) < a * b) cout << 2 * c - 1 << endl;
		else if(c * c == a * b){
			if(a == b) cout << 2 * c - 2 << endl;
			else  cout << 2 * c - 3 << endl;
		}
		else cout << 2 * c - 2 << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<int,pair<int,int>> iii;
typedef vector<pair<int,int>> vii;
typedef vector<vector<int>> vvi;

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

const int MAXN = 1e5+10;
int a[MAXN];
int k,n,m;

int main (void) {
    ios_base::sync_with_stdio(false);

    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == 1) m = i;
    }

    int result = (int)1e6;
    for (int i = 0; i < k; i++) {
        int left = max(0, (m-i+k-2)/(k-1));
        int right = max(0, (n-(m+k-i)+k-2)/(k-1));
        result = min(result, left+right+1);
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace std;
#define int long long
#define double long double
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> new_data_set;
bool isprime(int n)
	{
    	if(n==1) return true;
    	for(int i = 2;i*i<=n;i++){
    		if(n%i==0) return false;
		}
		return true;
	}
int lcm(int a,int b){
	return (a*b)/__gcd(a,b);
}
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
unsigned int factorial(unsigned int n) 
{ 
    if (n == 0) 
    return 1; 
    return n * factorial(n - 1); 
} 
const int inf=1e17+7;
//const int N=2e5+5;
bool visited[100005] = {false};
signed main(){
	FAST
	int n;
	cin>>n;
	vector<int> ans(3,0);
	for(int i = 0;i<n;i++){
		vector<int> dp(3,0);
		vector<int> b(3);
		for(int i = 0;i<3;i++) cin>>b[i];
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(j!=k){
					dp[k]=max(dp[k],ans[j]+b[k]);
				}
			}
		}
		ans=dp;
	}
	cout<<max({ans[0],ans[1],ans[2]});
}

Measured memory_bytes: 256
#include<stdio.h>
int med(int x, int y, int z); //x,y,zの中間値を返す
void quicksort(int a[], int left, int right); //ソート
int main(void){
    int N, K;
    scanf("%d %d",&N, &K);
    int h[N];
    for(int i = 0; i < N; i++){
        scanf("%d",&h[i]);
    }
    quicksort(h, 0, N-1);

    int dif[N-K+1];
    for(int i = 0; i < N-K+1; i++){
        dif[i] = h[i+K-1] - h[i];
    }

    int min = dif[0];
    for(int i = 0; i < N-K+1; i++){
        if(min > dif[i]) min = dif[i];
    }
    printf("%d\n",min);
    return 0;
}

int med(int x, int y, int z){
    if(x < y){
        if(y < z) return y; else if(z < x) return x; else return z;
    }else{
        if(z < y) return y; else if(x < z) return x; else return z;
    }
}

void quicksort(int a[], int left, int right){
    if(left < right){
        int i = left, j = right;
        int tmp, pivot = med(a[i], a[i+(j-i)/2],a[j]);
        while(1){
            while(a[i] < pivot) i++;
            while(pivot < a[j]) j--;
            if(i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp;
            i++; j--;
        }
        quicksort(a, left, i-1);
        quicksort(a, j+1, right);
    }
}

Measured memory_bytes: 896
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> x(100010);
	vector<int> y(100010);
	vector<int> t(100010);
	rep(i, 1, n + 1) {

		cin >> t[i] >> x[i] >> y[i];


	}
	t[0] = 0;
	x[0] = 0;
	y[0] = 0;
	bool ans = true;
	rep(i, 0, n) {
		int dt = t[i + 1] - t[i];
		int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
		if (dt < dist)ans = false;
		if (dt % 2 != dist % 2)ans = false;
	}

	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 1408
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s
}

fn main() {
	let n = read_line().split_whitespace().map(|e|e.parse().unwrap())
	.collect::<Vec<i32>>();
	if (n[1] - n[0]) == (n[2] - n[1]) {
		println!("YES");
	}else{
		println!("NO");
	}

}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int i, n, k ,arr[1001];
  long sum = 0;
  scanf("%d %d", &n, &k);
  for(i = 0 ; i < n ; i++)
    scanf("%d", &arr[i]);
  sort(arr, arr + n);
  for(i = 0 ; i < k ; i++)
    sum += arr[i];
 	printf("%ld", sum);
}

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

int main() {
  int h, w;
  cin>>h>>w;
  string a[h];
  for (int i=0; i<h; i++) cin>>a[i];

  set<int> row;
  for (int i=0; i<h; i++) {
    bool ok = true;
    for (int j=0; j<w; j++) {
      if (a[i][j] == '#') {
        ok = false;
        break;
      }
    }
    if (ok) {
      row.insert(i);
    }
  }
  set<int> column;
  for (int j=0; j<w; j++) {
    bool ok = true;
    for (int i=0; i<h; i++) {
      if (a[i][j] == '#') {
        ok = false;
        break;
      }
    }
    if (ok) {
      column.insert(j);
    }
  }
  for (int i=0; i<h; i++) {
    if (row.find(i) != row.end()) {
      continue;
    }
    for (int j=0; j<w; j++) {
      if (column.find(j) != column.end()) {
        continue;
      }
      cout<<a[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >>s;
  for(int i=0;i<5;i++) cout <<s[i];
  cout <<" ";
  for(int i=6;i<13;i++) cout << s[i];
  cout <<" ";
  for(int i=14;i<19;i++) cout << s[i];
  cout <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
    ll n;
    cin>>n;
    ll a[n];
    ll b[n];
    for(ll i=0;i<n;i++)   cin>>b[i],a[i]=b[i];
    sort(a,a+n);
  
    	for(ll i=0;i<n;i++)   if(b[i]==a[n-1])   cout<<a[n-2]<<"\n"; else  cout<<a[n-1]<<"\n";
    
}


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

typedef long long ll;

#define PB push_back

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m, x; cin >> n >> m >> x;
    int total_possible[m] = {0};
    int ans = 0;
    vector<pair<int, vector<int>>> books;
    for (int i = 0; i < n; ++i) {
        int c; cin >> c; 
        ans += c;
        vector<int> a; 
        for (int j = 0; j < m; ++j) {
            int ai; cin >> ai;
            total_possible[j] += ai;
            a.PB(ai);
        }
        books.PB(make_pair(c, a));
    }
    for (int i = 0; i < m; ++i) {
        if (total_possible[i] < x) {
            cout << -1 << "\n";
            return 0;
        }
    }
    for (int mask = 0; mask < (1 << n); ++mask) {
        int level[m] = {0}; 
        int cost = 0;
        for (int i = 0; i < n; ++i) {
            if (mask & (1 << i)) {
                cost += books[i].first;
                for (int j = 0; j < m; ++j) {
                    level[j] += books[i].second[j];
                }
            }
        }
        bool ok = true;
        for (int i = 0; i < m; ++i) {
            if (level[i] < x) {
                ok = false;
                break;
            }
        }
        if (ok) ans = min(ans, cost);
    }
    cout << ans << "\n";
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* print new lines
*/

Measured memory_bytes: 3640
(n, m) = list(map(int,input().split()))
ac = {}
pe = {}
for i in range(m):
    (p, s) = input().split()
    if(s=='AC'):
        ac[p] = True
    elif(p not in ac):
        if(p not in pe):
            pe[p] = 1
        else:
            pe[p] += 1
ac_num = 0
pe_num = 0
for k in ac.keys():
    ac_num += 1
    if k in pe:
        pe_num += pe[k]
print("%s %s" % (ac_num, pe_num))


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

typedef long long int lli;

const int N = 1005;
const int MOD = 1e9+7;
int n, a, b, c, d;
lli fact[N];
lli invFact[N];
lli dpt[N][N]; //first index is size of a group, second is num of people "used"

int inv(int a);

void initFact() {
	fact[0]=fact[1] = 1;
	invFact[0]=invFact[1] = 1;
	for(int i = 2; i < N; i++) {
		fact[i]=i*fact[i-1];
		fact[i] %= MOD;
		invFact[i] = inv(fact[i]);
	}
}

int powe(int a, int b) {
	if(b < 2) return b? a:1;
	else {
		lli base = powe(a, b/2);
		lli ans = base*base; ans %= MOD;
		if(b%2) {ans *= a; ans %=MOD;}
		return ans;
	}
}

int inv(int a) {
	return powe(a, MOD-2);
}

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

	initFact();

	cin >> n >> a >> b >> c >> d;
	for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) dpt[i][j] = 0;
	dpt[0][0] = 1;
	for(int i = 1; i <= n; i++) {
		if(i < a || i > b)
			for(int j = 0; j <= n; j++) {
				dpt[i][j]=dpt[i-1][j];
			}
		else {
			//How many groups of size i to add?
			//Add none
			for(int j = 0; j <= n; j++) {
				dpt[i][j]=dpt[i-1][j];
			}
			
			//Add k of them
			for(int k = c; k <= d && i*k <= n; k++) {
				for(int j = 0; i*k + j <= n; j++) {
					//Multiplier should be (n-j)!/((i!)^k k! (n-j-i*k)!)
					lli multiplier = fact[n-j];
					multiplier *= inv(powe(fact[i], k));
					multiplier %= MOD;
					multiplier *= invFact[k];
					multiplier %= MOD;
					multiplier *= invFact[n-j-i*k];
					multiplier %= MOD;
					dpt[i][i*k+j] += multiplier*dpt[i-1][j];
					dpt[i][i*k+j] %= MOD;
				}
			}
		}
	}

	cout << dpt[n][n] << endl;
	

	return 0;
}

Measured memory_bytes: 8192
n = int(input())
s= list(input())
ans = []
tmp = s[0]

if len(set(s)) == 1:
    print(1)
    exit()

for i in range(1, n):
    if s[i] == tmp:
        continue
    else:
        ans.append(tmp)
        tmp = s[i]

if ans[-1] == s[-1]:
    print(len(ans))
else:
    ans.append(s[-1])
    print(len(ans))

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

using namespace std;

#define ll long long
#define debug(n) cerr << #n << ':' << n << endl;
#define MP make_pair
#define PB push_back
#define pll pair<long long, long long>
#define pii pair<int, int>

template<class T>
void chmax(T&a, const T&b){if(a < b)a = b;}
template<class T>
void chmin(T&a, const T&b){if(a > b)a = b;}

int main(){
  int a, b;cin >> a >> b;
  if(a < b)cout << 0 << endl;
  else cout << 10 << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;


using B = bitset<401>;
bool solve(){
    int h, w;
    cin >> h >> w;
    if(!h) return 0;
    B x;
    int cnt = 0;
    for (int i = 0; i < h; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < w; ++j) {
            if(s[j] == '#') {
                x.set(i*w+j);
                cnt++;
            }
        }
    }
    int n;
    cin >> n;
    vector<vector<B>> piece(n);
    vector<int> cnts(n);
    vector<int> ok(1 << n);
    for (int i = 0; i < n; ++i) {
        int hh, ww;
        cin >> hh >> ww;
        vector<string> v(hh);
        for (auto &&j : v) {
            cin >> j;
            for (auto &&k : j) {
                if(k == '#') cnts[i]++;
            }
        }
        for (int _ = 0; _ < 4; ++_) {
            for (int j = 0; j+hh <= h; ++j) {
                for (int k = 0; k+ww <= w; ++k) {
                    B y{};
                    for (int l = 0; l < hh; ++l) {
                        for (int m = 0; m < ww; ++m) {
                            if(v[l][m] == '#'){
                                y.set((j+l)*w+k+m);
                            }
                        }
                    }
                    piece[i].emplace_back(y);
                }
            }
            auto vv = vector<string>(ww, string(hh, ' '));
            for (int j = 0; j < hh; ++j) {
                for (int k = 0; k < ww; ++k) {
                    vv[ww-k-1][j] = v[j][k];
                }
            }
            swap(vv, v);
            swap(hh, ww);
        }
    }
    B MX{};
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            MX.set(i*w+j);
        }
    }
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i) {
        int p;
        cin >> p;
        vector<int> v(p);
        for (auto &&j : v) scanf("%d", &j), j--;
        sort(v.begin(),v.end(), [&](int x, int y){ return cnts[x] > cnts[y]; });
        int dif = h*w-cnt;
        for (auto &&k : v) dif -= cnts[k];
        auto dfs = [&](int cur, B x, auto &&f) -> bool {
            if(cur == p) return 1;
            B xx = x;
            for (auto &&i : v) {
                for (auto &&j : piece[i]) {
                    if((x&j).none()){
                        xx |= j;
                    }
                }
            }
            if(xx != MX) return 0;
            for (auto &&j : piece[v[cur]]) {
                if((x&j).none()){
                    if(f(cur+1, x|j, f)) return 1;
                }
            }
            return 0;
        };
        if(!dif && dfs(0, x, dfs)) puts("YES");
        else puts("NO");
    }
    return 1;
}

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


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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<int> ans(n);

    rep(i,n) ans[i] = 0;

    int j[2] = {0,0};
    int border;
    for(int i = 0; i < n - 1; i++){
        if(s[i] == 'R' && s[i+1] == 'L'){
            j[i%2]++;
            border = i+1;
        }else if(s[i] == 'L' && s[i+1] == 'R'){
            j[i%2]++;
            ans[border] = j[border%2];
            ans[border-1] = j[1-border%2];
            j[0] = j[1] = 0;
        }else{
            j[i%2]++;
        }
    }
    j[(n-1)%2]++;
    ans[border] = j[border%2];
    ans[border-1] = j[1-border%2];

    rep(i,n) printf("%d ",ans[i]);
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){
	int n;
	while(cin >> n){
		int mat, eng, jap;
		rep(i, n){
			cin >> mat >> eng >> jap;
			int sum = mat + eng + jap;
			if(mat == 100 || eng == 100 || jap == 100 || sum >= 240 || sum-jap >= 180){
				cout << "A" << endl;
				continue;
			}else if(sum >= 210||(sum >= 150 && (mat >= 80 || eng >= 80))){
				cout << "B" << endl;
				continue;
			}else{
				cout << "C" << endl;
			}
		}
	}

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 1160
from collections import defaultdict
D1 = defaultdict(int)

N, M = map(int, input().split())
A = list(map(int, input().split()))

for i in A:
  D1[i] += 1

for _ in range(M):
  B, C = map(int, input().split())
  D1[C] += B

D2 = sorted(D1.items(), reverse=True)

ans = 0
temp = N

for i in range(len(D2)):
  if temp <= D2[i][1]:
    ans += D2[i][0] * temp
    break
  else:
    ans += D2[i][0] * D2[i][1]
    temp -= D2[i][1]

print(ans)

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

int main(){
	int c=0;
	int n=0;
	int i=0;
	int j=0;
	int k=0;
	int l[100];
	
	string x;
	x="NA";
	
	for(i=0;i<100;i++){
		int a=0;
		int b=0;
		cin>>n;
		if(n==0){
			break;
		}

		for(j=0;j<n;j++){
			cin>>k;
			if(k!=0){
				a++;
			}
			if(k>=2){
				b++;
			}
		}
		
		if(b!=0){
			l[i]=a+1;
		}else{
			l[i]=0;
		}
		
		c++;
	}
	
	for(i=0;i<c;i++){
		if(l[i]==0){
			cout<<x<<endl;
		}else{
			cout<<l[i]<<endl;
		}
	}
}
		

Measured memory_bytes: 1200
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int64_t solve(const int64_t h) {
  if (h == 1) {
    return 1;
  }
  return 2 * solve(h / 2) + 1;
}

int main() {
  int64_t H;
  cin >> H;

  cout << solve(H) << endl;

  return 0;
}

Measured memory_bytes: 256