akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    long long n,K;
    cin>>n>>K;
    long long s[n+1];
    s[0]=0;
    rep(i,n){
        long long a;
        cin>>a;
        s[i+1]=s[i]+a;
    }
    vector<long long>beauty((n*(n+1))/2);
    long long cur=0;
    for(int i=0;i<n;i++){
        for(int k=i+1;k<=n;k++){
            beauty[cur]=(s[k]-s[i]);
            cur++;
        }
    }
    long long int second[45];
    int p=0;
    second[0]=1;
    rep(i,44){
        second[i+1]=second[i]*2;
        if(second[i]<0)break;
        //p++;
    }
    //p--;
    //cout<<p<<" "<<second[p]<<endl;
    //cout<<endl;
    
    long long ans=0;
    //rep(i,all)exist[i]=true;
    long long  all=beauty.size();

    //cout<<all<<endl;
    for(int i=44;i>-1;i--){
        
        //bool exist[all]={};
        long long  cnt=0;
        for(int k=0;k<all;k++){
            //if(!exist[k])continue;
            if(beauty[k]<0)continue;
            
            if(((second[i]+ans)&beauty[k])==(ans+second[i])){
                //exist[k]=true;
                cnt++;
            }
        }
        
        if(cnt>=K){
            ans|=second[i];
            /*rep(l,all){
                if(!exist[l]){
                    beauty[l]=-1;
                }
            }
            */
            //cout<<ans<<" ";
        }
    }
    //cout<<endl;
    
    cout<<ans<<endl;
    
    return 0;

}
/*
4 2
2 5 2 5

12


*/


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
main()
{
	long long p=0,va,sm=0;
	int t;
	vector<long long>v;
	scanf("%d%lld",&t,&p);
	for(int i = 0;i < t;i++)
	{
		scanf("%lld",&va);
		v.push_back(va);
		sm+=va;
	}
	sort(v.begin(),v.end());
	if(p==sm)
	printf("%d",t);
	else if(p>sm)
	printf("%d",t-1);
	else
	{
		int co=0;
		while(p>=v[co])
		{
			p-=v[co];
			co++;
		}
		printf("%d",co);
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int train[24*60*60+1];
int main() {
	int n;
	while(scanf("%d",&n),n) {
		memset(train,0,sizeof(train));
		for(int i=0;i<n;i++) {
			int hh,mm,ss;
			scanf("%d:%d:%d",&hh,&mm,&ss);
			int l=hh*60*60+mm*60+ss;
			scanf("%d:%d:%d",&hh,&mm,&ss);
			int r=hh*60*60+mm*60+ss;
			train[l]++;
			train[r]--;
		}
		int ans=0;
		for(int i=0;i<24*60*60;i++) {
			train[i+1]+=train[i];
			ans=max(ans,train[i]);
		}
		printf("%d\n",ans);
	}
}

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

vector<int> mini, maxi, arr;
int a, l;

void num(vector<int> &ll, vector<int> &ss){

  int t = 1;
  int llcp = ll[l-1], sscp = ss[l-1];

  for(int i = l-2; i >= 0; i--){
    t *= 10;
    llcp += ll[i] * t;
    sscp += ss[i] * t;
    // cout << ll[i] << " " << ss[i] << endl;
  }
  // cout << llcp << " " << sscp << endl;
  arr.push_back(llcp - sscp);

  for(int i = 0; i < (int)arr.size(); i++){
    for(int j = i+1; j < (int)arr.size(); j++){
      if(arr[i] == arr[j]){
	cout << i << " " << arr[i] << " " << j-i << endl;
	return;
      }
    }
    // cout << arr[i] << " " << llcp << " " << sscp << endl;
  }

  maxi.clear();
  mini.clear();
  t = 1;
  a = arr[arr.size()-1];
  for(int i = 0; i < l; i++){
    t *= 10;
    mini.push_back((a % t) / (t / 10));
    maxi.push_back((a % t) / (t / 10));
    // cout << (a % t) / (t / 10) << endl;
  }

  sort(maxi.rbegin(),maxi.rend());
  sort(mini.begin(),mini.end());

  num(maxi,mini);

}


int main(){


  while(cin >> a >> l && (a || l)){


    int t = 1;

    arr.push_back(a);

    for(int i = 0; i < l; i++){
      t *= 10;
      mini.push_back((a % t) / (t / 10));
      maxi.push_back((a % t) / (t / 10));
      //cout << (a % t) / (t / 10) << endl;
    }
    sort(maxi.rbegin(),maxi.rend());
    sort(mini.begin(),mini.end());

    num(maxi,mini);

    maxi.clear();
    mini.clear();
    arr.clear();



  }



}

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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

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

    ll k,a,b;
    cin >> k >> a >> b;

    string ans = "NG";
    for(int i = a;i <= b;i++){
        if(i % k == 0){
            ans = "OK";
        }
    }

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

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+5;
const double eps = 1e-6;

ll a[N],b[N];

int main() {
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;++i) scanf("%lld",&a[i]);
	
	ll now = 1000ll;
	for(int i = 1;i < n;++i){
		if(a[i] < a[i+1])
			now = (now%a[i]+now/a[i]*a[i+1]);
	}
	
	printf("%lld\n",now);
    return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair < ll, ll > PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll MOD = 1e9+7;
int main() {
    ll n;
    cin >> n;
    if ( n <= 2 ) {
        cout << 1 << endl;
        return 0;
    }
    vector<pair<ll, ll>> xy(n);
    vector<ll> xdif(n-1);
    vector<ll> ydif(n-1);
    rep(i, n) {
        ll tmp_x, tmp_y;
        cin >> tmp_x >> tmp_y;
        xy[i] = make_pair(tmp_x, tmp_y);
    }
    sort(xy.begin(), xy.end());
    rep(i ,n ) {
        if ( i == 1 ) {
            xdif[0] += xy[1].first - xy[0].first;
            ydif[0] += xy[1].second - xy[0].second;
        }
        else if ( i > 1 ) {
            xdif[i-1] += xy[i].first - xy[i-1].first + xdif[i-2];
            ydif[i-1] += xy[i].second - xy[i-1].second + ydif[i-2];
        }
    }
    map<pair<ll, ll>, int> mp;
    rep(i, n-1) {
        for ( int j = i; j < n - 1; ++j ) {
            if ( i == 0 ) {
//                cout << xdif[j] << " " << ydif[j] << endl;
                ++mp[make_pair(xdif[j], ydif[j])];
            }
            if ( i >= 1 ) {
//                cout << xdif[j] - xdif[i-1] << " " << ydif[j] - ydif[i-1] << endl;
                ++mp[make_pair(xdif[j] - xdif[i-1], ydif[j] - ydif[i-1])];
            }
        }
    }
    int max_num = 0;
    for ( auto tmp_mp : mp ) {
//        cout << tmp_mp.second << endl;
        max_num = max(max_num, tmp_mp.second);
    }
    cout << n - max_num << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#include <functional>
const int INF =1e5;
const int MOD = 1e9 + 7;
using namespace std;
typedef pair<int,int> P;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back

int main(){
    int n;
    cin>>n;
    string s;
    string F="MARCH";
    lint ans=0;
    lint count[5]={};
    rep(i,n){
        cin>>s;
        rep(j,5){
            if(s[0]==F[j]){
                count[j]++;
                break;
            }
     
        }
    }
    for(int i=0;i<3;i++){
        for(int j=i+1;j<4;j++){
            for(int k=j+1;k<5;k++){
                ans+=count[i]*count[j]*count[k];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

#include <math.h>
#include <stdlib.h>


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


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int x; cin >> x;
    int ans = 0;
    ans += 1000 * (x/500);
    x %= 500;
    ans += (x/5) * 5;
    cout <<ans << endl;

    return 0;
}


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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

vector<int> a;
vector<int> d;

void dfs(int v, int dist) {
	if (d[v] != -1) return;
	d[v] = dist;
	dfs(a[v], dist + 1);
	return;
}

int main() {
	int n;
	cin >> n;
	a.resize(n + 1);
	d.resize(n + 1, -1);
	REP(i, n) {
		cin >> a[i];
	}
	dfs(1, 0);
	cout << d[2] << endl;
	return 0;
}



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

int main() {
    int D;
    cin >> D;
    if (D == 25) {
        cout << "Christmas" << endl;
    } else if (D == 24) {
        cout << "Christmas Eve" << endl;
    } else if (D == 23) {
        cout << "Christmas Eve Eve" << endl;
    } else {
        cout << "Christmas Eve Eve Eve" <<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(ll, N, A, B);
  VEC(ll, X, N);

  ll ans = 0;
  rep(i, 1, N) {
    ans += min((X[i] - X[i - 1]) * A, B);
  }

  print(ans);
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

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

    ll N, K;
    cin >> N >> K;
    vec A(N), s(N+1, 0);

    Rep (i, N) {
        cin >> A[i];
        A[i]--;
        s[i+1] = s[i] + A[i];
    }

    Rep (i, N+1) {
        s[i] %= K;
    }

    ll ans = 0;
    map<ll, ll> m;
    Rep (i, min(K, N+1)) {
        m[s[i]]++;
    }

    Rep (i, N+1) {
        ans += m[s[i]] - 1;
        m[s[i]]--;
        if (i+K <= N) {
            m[s[i+K]]++;
        }
    }

    cout << ans << "\n";
}

Measured memory_bytes: 15872
#include<stdio.h>
#include<string>
#include<string.h>
#include<iostream>

using namespace std;

char str1[] = {'.','#','.','#'};
char str2[] = {'.','.','#','#'};

int main()
{
	int n;
//	scanf("%d",&n);
	cin >> n;
	
	string s1,s2;
	
	int toright = 1;
	
	while(1)
	{
		
		int f = 0;
		for(int i = 0; i < 4; i++)
		{
			
			string temp1 = s1;
			string temp2 = s2;
			
			if (toright)
			{
				temp1 += str1[i];
				temp2 += str2[i];
			}
			else
			{
				temp1 = str1[i] + temp1;
				temp2 = str2[i] + temp2;
			}
			
			cout << temp1 << "\n" << temp2 << "\n" << flush;
//			char s[6];
//			scanf("%s",s);
			
			string s;
			cin >> s;
			
			if (s == "end")
				return 0;
			
			if (s == "T")
			{
				f = 1;
				s1 = temp1;
				s2 = temp2;
				break;
			}
			
		}
		
		if (!f)
		 	toright = 0;
	}

	return 0;
}

Measured memory_bytes: 724
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

struct Ed {
  int u, v, w;

  Ed() {}

  Ed(int u, int v, int w) : u(u), v(v), w(w) {}

  bool operator<(const Ed &rhs) const {
    return w < rhs.w;
  }

  bool operator>(const Ed &rhs) const {
    return rhs < *this;
  }

  bool operator<=(const Ed &rhs) const {
    return !(rhs < *this);
  }

  bool operator>=(const Ed &rhs) const {
    return !(*this < rhs);
  }
};

const int N = 100010;

int n, m;
int f[N * 2], ch[N * 2][2];
int rec[N];
ll s[N * 2];
Ed e[N];
int tag[N * 2];

int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }

int main() {


  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    scanf("%lld", &s[i]);
  for (int i = 1; i <= m; ++i)
    scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  sort(e + 1, e + m + 1);
  iota(f + 1, f + n * 2, 1);
  int cnt = n;
  for (int i = 1; i <= m; ++i) {
    int x = find(e[i].u), y = find(e[i].v);
    if (x != y) {
      int t = ++cnt;
      rec[i] = 1;
      f[x] = t;
      f[y] = t;
      ch[t][0] = x;
      ch[t][1] = y;
      if ((s[t] = s[x] + s[y]) < e[i].w)
        tag[t] = -1;
      else
        tag[t] = 1;
    }
  }
  for (int i = n * 2 - 1; i > n; --i) {
    tag[ch[i][0]] = max(tag[ch[i][0]], tag[i]);
    tag[ch[i][1]] = max(tag[ch[i][1]], tag[i]);
  }
  iota(f + 1, f + n + 1, 1);
  int ans = 0;
  cnt = n;
  for (int i = 1; i <= m; ++i) {
    int x = find(e[i].u), y = find(e[i].v);
    if (rec[i]) {
      if (tag[++cnt] == 1) {
        f[x] = y;
        s[y] += s[x];
      } else {
        ++ans;
      }
    }
  }
  for (int i = m; i; --i)
    if (!rec[i]) {
      int x = find(e[i].u), y=find(e[i].v);
      if (x != y || s[x] < e[i].w)
        ++ans;
    }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 6528
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner s=new Scanner(System.in);
		while(true){
			int a=s.nextInt();
			String b=s.next();
			if(a==0&&b.equals("0"))System.exit(a);
			int ans=-1;
			boolean panai=false;
			String ret="";
			for(int i=0;i<(1<<(b.length()-1));i++){
				int now=0;
				int reg=0;
				for(int j=0;j<b.length();j++){
					reg=reg*10+(b.charAt(j)-'0');
					if((i&(1<<j))>0||j==b.length()-1){
						now+=reg;
						reg=0;
					}
				}
				if(ans==now)panai=true;
				if(now<=a&&ans<now){
					ans=now;
					panai=false;
					ret=" ";
					for(int j=0;j<b.length();j++){
						ret=ret+b.charAt(j);
						if((i&(1<<j))>0)ret+=" ";
					}
				}
			}
			if(panai)System.out.println("rejected");
			else if(ans==-1)System.out.println("error");
			else System.out.println(ans+ret);
		}
	}
}

Measured memory_bytes: 0
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

char c(int x){
	switch(x){
		case 0: return 'R';
		case 1: return 'G';
		case 2: return 'B';
		default: return 'Y';
	}
}

int main(){
	int h, w, d;
	cin>>h>>w>>d;
	vector<string> s(h, string(w, 'Y'));
	rep(i, h) rep(j, w){
		int i2 = i+j, j2 = (i-j)%(2*d)+2*d;
		int x = i2/d%2 + j2/d%2*2;
		s[i][j] = c(x);
	}
	rep(i, h) cout<<s[i]<<endl;
	return 0;
}


Measured memory_bytes: 768
#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() {
  int N; 
  int64_t ans1, ans2=0;
  string S;
  cin >> N >> S;

  vector<int> R(0);
  vector<int> G(0);
  vector<int> B(0);

  rep(i,N){
    if(S[i] == 'R') R.push_back(i);
    if(S[i] == 'G') G.push_back(i);
    if(S[i] == 'B') B.push_back(i);
  }

  ans1 = R.size() * G.size() * B.size();

  rep(i, N-2){
    for(int j = i+1; j < N-1; j++){
      int k = 2 * j - i;
      if (k < N && S[k] != S[i] && S[k] != S[j] && S[i] != S[j]) ans2++;
      }
    }


  //cout << R.size() << " " << G.size() << " " << B.size() << endl;

  //cout << ans1 << endl;
  //cout << ans2 << endl;

  cout << ans1 - ans2 << endl;
}


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


int main(){
	
	map<int,bool> mp;
	int N;
	cin>>N;
	mp[N]=true;
	for(int i=2;i!=-1;i++){
		if(N%2==0)N/=2;
		else N=N*3+1;
		if(mp[N]){
			cout<<i<<endl;
			return 0;
		}
		mp[N]=true;
	}

	return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    ai = max(A)
    mi = float("inf")
    aj = 0
    for a in A:
        if ai == a:
            continue
        tmp = mi
        mi = min(mi, abs((ai - a) - a))
        if tmp != mi:
            aj = a

    print(ai, aj)

    

if __name__ == '__main__':
    main()



Measured memory_bytes: 14040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
int A[20];
int x[20][20];
int y[20][20];

int num(int a) {
    if(a == 0) return 0;
    return (a & 1) + num(a / 2);
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        for(int j = 0; j < A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    int ans = 0;
    for(int bits = 0; bits < (1 << N); bits++) {
        bool ok = true;
        for(int i = 0; i < N; i++) {
            if(!(bits & (1 << i))) continue;
            for(int j = 0; j < A[i]; j++) {
                //cerr << bits << " " << x[i][j] << " " << y[i][j] << endl;
                //cerr << ((bits >> x[i][j]) & 1) << endl;
                if(((bits >> x[i][j]) & 1) ^ y[i][j]) ok = false;
            }
        }
        if(ok) chmax(ans, num(bits));
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i = 0; i < n; i++)

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

	rep(i, 5) {
		int a;
		cin >> a;
		if (a == 0) {
			cout << i + 1 << endl;
			return 0;
		}
	}
 	return 0;
}


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

char a[22][22];

int n,m;

struct pos{
	int x;
	int y;
	int step;
};

pos make_pos(int a,int b,int c)
{
	pos ret;
	
	ret.x=a;
	ret.y=b;
	ret.step=c;
	
	return ret;
}

int bfs(int sx,int sy,int ex,int ey)
{
	bool visited[n+2][m+2];
	
	for(int i=0;i<=n+1;i++)
	  for(int j=0;j<=m+1;j++)
	    if(a[i][j]=='#')
	       visited[i][j]=true;
	       
	    else visited[i][j]=false;
	    
	queue<pos> q;
	q.push(make_pos(sx,sy,0));
	visited[sx][sy]=true;
	int dx[4]={0,0,-1,1};
	int dy[4]={-1,1,0,0};
	
	while(!q.empty())
	{
		pos fr=q.  front();
		q.pop();
		
		if(fr.x==ex&&fr.y==ey)
		  return fr.step;
		  
		pos newpo;
		for(int i=0;i<4;i++)
		{
			int nx=fr.x+dx[i];
			int ny=fr.y+dy[i];
			
			if(visited[nx][ny])
			  continue;
			visited[nx][ny]=true;
			
			newpo=make_pos(nx,ny,fr.step+1);
			q.push(newpo);
			
		}
	}
	
	
}
int main() 
{
	for(int i=0;i<22;i++)
	  for(int j=0;j<22;j++)
	      a[i][j]='#';
	
	cin>>n>>m;
	
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++)
	    cin>>a[i][j];
	    
	int maxv=0;
	
	for(int i1=1;i1<=n;i1++)
	  for(int j1=1;j1<=m;j1++)
	  {
	  	if(a[i1][j1]=='#')
	  	  continue;
	  	
	  	for(int i2=1;i2<=n;i2++)
	  	  for(int j2=1;j2<=m;j2++)
	  	  {
	  	  	if(a[i2][j2]=='#')
	  	  	  continue;
	  	  	
	  	  	if(i1==i2&&j1==j2)
	  	  	  continue;
	  	  	  
	  	  	  maxv=max(maxv,bfs(i1,j1,i2,j2));
		  }
	  }
	  cout<<maxv;
	  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
using namespace std;
int main(){
    
    int n;
    cin>>n;
    int ans=10000000;
    for(int i=0;i<=n;i++){
        int sum=0;
        int nn=n;
        int tmp=i;
        while(tmp>0){
            sum+=tmp%6;
            tmp/=6;
        }
        tmp=n-i;
        while(tmp>0){
            sum+=tmp%9;
            tmp/=9;
        }
        ans=min(sum,ans);
        
        
    }
    cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 256
M,K=map(int,input().split())

if 2**M-1<K:
    print(-1)
    exit()
if M==1 and K==0:
    print(0,0,1,1)
    exit()

res=0
li=[]
for i in range(2**M):
    if i==K:
        continue
    res=res^i
    li.append(i)
if res!=K:
    print(-1)
    exit()

ans=[K]+li+[K]+li[::-1]
print(*ans)

Measured memory_bytes: 99812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

// http://luzhiled.hatenablog.com/entry/2017/12/03/124453
string N;
int D;
int dp[10002][2][102];
int rec(int k = 0, bool tight = true, int sum = 0){
	if(k==N.size())return sum%D==0;
	int x = N[k] - '0';
	int r = (tight ? x:9);
	int &res = dp[k][tight][sum];
	if(~res) return res;
	res = 0;
	for(int i=0;i<=r;++i){
		(res += rec(k+1,tight&&i==r,(sum+i)%D) ) %= MOD;
	}
	return res;
}

int main(){
	cin >> N >> D;
	memset(dp, -1, sizeof(dp));
	cout << (rec()-1+MOD)%MOD << endl;
}


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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

vector<int> node[100001];

ll perm_k1[100001] = {}; //(k-1)P_i
ll perm_k2[100001] = {}; //(k-2)P_i

ll ans = 0;

void init(int k){
    ll k1 = k-1; ll k2 = k-2;
    perm_k1[0] = 1;
    perm_k2[0] = 1;
    int idx = 1;
    for(int i = k1; i > 0; i--){
        perm_k1[idx] = (perm_k1[idx-1]*i) % mod;
        idx++;
    }
    idx = 1;
    for(int i = k2; i > 0; i--){
        perm_k2[idx] = (perm_k2[idx-1]*i) % mod;
        idx++;
    }
}

void dfs(int p, int s){
    if(p == -1){
        ans = perm_k1[node[s].size()];
        rep(i, node[s].size()) dfs(s, node[s][i]);
    }
    else{
        int num_child = node[s].size()-1;
        ans = (ans*perm_k2[num_child]) % mod;
        rep(i, node[s].size()){
            if(node[s][i] != p) dfs(s, node[s][i]);
        }
    }
}

int main(void){
    int N, K; cin >> N >> K;
    init(K);
    rep(i, N-1){
        int a, b; cin >> a >> b;
        node[a-1].push_back(b-1);
        node[b-1].push_back(a-1);
    }

    if(K == 1){
        if(N == 1) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }
    else if(K == 2){
        if(N == 1 || N == 2) cout << 2 << endl;
        else cout << 0 << endl;
        return 0;
    }
    else{
        //根を0としてスタート
        dfs(-1, 0);
    }

    cout << (ans*K) % mod << endl;
    
    return 0;
}

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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
  int64_t N, K;
  cin >> N >> K;
  int64_t sum = 0;
  vector<int64_t> vec(K);
  for (int64_t i = K; i >= 1; i--) {
    vec.at(i - 1) = modpow(K / i, N, 1000000007);
    for (int64_t j = 2; j < 1000000; j++) {
      if (j*i <= K) {
        vec.at(i - 1) -= vec.at(j*i - 1);
      }
      else break;
    }
  }
  for (int64_t i = 0; i < K; i++) {
    sum += vec.at(i) * (i+1);
    sum = sum % 1000000007;
  }
  cout << sum << endl;
}


Measured memory_bytes: 4048
/*
    Problem 67
    https://atcoder.jp/contests/abc065/tasks/arc076_b
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* class */
class DisjointSet {
public:
    vector<int> d;
    DisjointSet () {}
    DisjointSet (int len) { d.assign(len, -1); }

    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)];}
};
class Edge {
public:
    int u, v, w;
    Edge () {}
    Edge (int u, int v, int w) : u(u), v(v), w(w) {}
    bool operator < (const Edge &e) const {
        return w < e.w;
    }
};
class Point {
public:
    int x, ind;
    Point () {}
    Point (int x, int ind) : x(x), ind(ind) {}
    bool operator < (const Point &p) const {
        return x < p.x;
    }
};
/* global variables */
/* function */
/* main */
int main() {
    // 点たちを x 座標でソートした列において隣接する 2 点と、y 座標でソートした列において,
    // 隣接2点の間にそれぞれ辺を張ったグラフの最小全域木を求めればよい
    int N;
    cin >> N;
    vector<Point> X(N, Point()), Y(N, Point());
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        X[i] = Point(x, i);
        Y[i] = Point(y, i);
    }
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());

    vector<Edge> edges;
    int cnt = 0;
    for (int i = 0; i < N-1; i++) {
        edges.push_back(Edge(X[i].ind, X[i+1].ind, abs(X[i].x - X[i+1].x)));
        edges.push_back(Edge(Y[i].ind, Y[i+1].ind, abs(Y[i].x - Y[i+1].x)));
    }
    // kruscal
    sort(edges.begin(), edges.end());
    DisjointSet ds = DisjointSet(N);
    int totalCost = 0;
    for (Edge e : edges)
        if (ds.unite(e.u, e.v))
            totalCost += e.w;
    cout << totalCost << '\n';
}

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

using namespace std;

const int limit = 7369791;

int M, N;
int dp[limit + 1];

int main()
{
  memset(dp, -1, sizeof(dp));
  int a = 0;
  while(cin >> M >> N, M) {
    for(int i = M; i <= limit; i++) {
      if(dp[i] != a) {
        if(--N < 0) {
          cout << i << endl;
          break;
        }
        for(int j = i + i; j <= limit; j += i) dp[j] = a;
      }
    }
    ++a;
  }
}

Measured memory_bytes: 31872
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C; cin >> A >> B >> C;
  for (int i = 0; i < B; i++) {
    if(A * i % B == C) {
      cout << "YES" << "\n";
      return 0;
    }
  }
  cout << "NO" << "\n";
}

Measured memory_bytes: 256
S = list(input())
A = []
B = []
Triger = 0

if len(S) == 3:
  if S[0] == S[2]:
    print("Yes")
  else:
    print("No")
else:
  for i in range(0,int((len(S)-1)/2)):
    A.append(S[i])
  for j in range(int((len(S)+3)/2-1),len(S)):
    B.append(S[j])
    
  for k in range(len(S)//2):
    if S[k] == S[len(S)-k-1]:
      continue
    else:
      Triger = 1
      break
  for i in range(len(A)//2):
    if A[i] == A[len(A)-i-1]:
      continue
    else:
      Triger = 1
      break
  for j in range(len(B)//2):
    if B[j] == B[len(B)-j-1]:
      continue
    else:
      Triger = 1
      break
  if Triger == 0:
    print("Yes")
  else:
    print("No")

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

inline int read()
{
	int x=0,f=1,c=getchar();
	while(c<48) c=='-'&&(f=-1),c=getchar();
	while(c>47) x=x*10+c-'0',c=getchar();
	return x*f;
}

const int MAXN = 300005;
std::multiset<string> s;

int main(int argc, char const *argv[])
{
	auto init=[](string t) {for(int i=read(); i; --i) s.insert(t);};
	init("a"); init("b"); init("c");
	while(s.size()>1)
	{
		auto st=*s.begin(),ed=*s.rbegin();
		s.erase(s.lower_bound(st));
		s.erase(s.lower_bound(ed)); s.insert(st+ed);
	}
	printf("%s\n", (*s.begin()).c_str());
	return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<utility>
#include<iterator>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(lli i=0;i<j;i++)
#define rep1(i,j) for(lli i=1;i<=j;i++)
#define rep0d(i,j) for(lli i=j-1;i>=0;i--)
#define MAX 1000000007
typedef struct tree Tree;

using namespace std;


bool cmpf(pair<lli, lli> left, pair<lli, lli> right) {
	return left.first < right.first;
}

int main() {
	lli n,m,ans=0;
	cin >> n >> m;
	rep0(i, n * m) {
		if ((i % m+1) / 10 >= 2) {
			
			if ((i % m+1) % 10 >= 2) {
				if (i / m+1 == ((i % m+1) / 10) * ((i % m+1) % 10)) {
					ans++;
					
				}
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    vector<int> a(N,0);
    for(int n = 0; n < N; ++n){
        cin >> a[n];
    }
    sort(a.begin(), a.end(), greater<int>());
    
    int bob = 0;
    int ann = 0;
    for(int i = 0; i < a.size(); ++i){
        if(i % 2 == 0){
            bob += a[i];
        }
        else{
            ann += a[i];
        }
    }
    int ans = bob - ann;
    cout << ans;
    
    return 0;
}

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

int n;
string s;

void solve()
{
    string ans = "No";
    if (n % 2 == 0)
    {
        if (s.substr(0, n / 2) == s.substr(n / 2, n / 2))
            ans = "Yes";
    }

    cout << ans;
}

int main()
{
    cin >> n >> s;

    solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int s=0;
	for(int i=0;i<4;i++)
	{
		char a;
		cin>>a;
		if(a=='+') s++;
		else if(a=='-') s--;
	}
	cout<<s<<'\n';
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

vector<bool> seen;
vl d, f;

void dfs(ll now, ll &time, vll &G){
    seen[now] = true;
    d[now] = time++;
    for(ll next : G[now]){
        if(seen[next]) continue;
        dfs(next, time, G);
    }
    f[now] = time++;
}

int main() {
    ll N;
    cin >> N;
    vll G(N);
    rep(i, N){
        ll u, k;
        cin >> u >> k;
        u--;
        rep(j, k){
            ll t;
            cin >> t;
            t--;
            G[u].push_back(t);
        }
    }
    seen.assign(N, false);
    d.resize(N);
    f.resize(N);
    ll time = 1;
    rep(i, N){
        if(!seen[i]){
            dfs(i, time, G);
        }
    }
    rep(i, N){
        ll idx = i+1;
        cout << idx << " " << d[i] << " " << f[i] << endl;
    }
}


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

#define ll long long
#define pb push_back

using namespace std;

const ll N = 1e6 + 20;
ll l[N],r[N],a[N],res,x[N];
vector<ll> st;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
    {
        while(!st.empty() && a[st.back()] >= a[i])
            st.pop_back();
        if(!st.empty())
            l[i]=st.back();
        else
            l[i] = -1;
        st.pb(i);
    }
    st.clear();
    for(int i=n-1;i>-1;i--)
    {
        while(!st.empty() && a[st.back()] > a[i])
            st.pop_back();
        if(!st.empty())
            r[i]=st.back();
        else
            r[i]=n;
        st.pb(i);
    }
    for(int i=0;i<n;i++)
    {
        r[i]--;
        l[i]++;
        res+=(r[i]-i+1)*(i-l[i]+1)*a[i];
    }
    cout<<res<<endl;
    return 0;
}


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

int main() {
  long N,A,B;
  cin>>N>>A>>B;
  vector<long> x(N);
  for(int i=0;i<N;i++) cin>>x[i];
  long ans=0;
  for(int i=0;i<N-1;i++){
    long dist=x[i+1]-x[i];
    long walk=dist*A;
    long warp=B;
    if(walk>=warp) ans+=warp;
    else ans+=walk;
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
    int h, w;
    int i, j;
    while(1){
        scanf("%d %d ", &h, &w);
        if(h==0&&w==0)break;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}

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

#define ll long long
#define ull unsigned long long

#define pii pair < int, int >
#define pll pair < ll, ll >
#define pci pair < char, int >
#define psi pair < string, int >

#define vi vector < int >
#define vll vector < ll >
#define vs vector < string >
#define vc vector < char >
#define vpi vector < pii >
#define vpll vector < pll >

#define pb push_back

#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;

bool chkbit(ll n, ll k)
{
    return n & (1LL << k);
}

int main()
{
    fast;

    ll n;

    cin >> n;

    vll a(n);

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

    ll ans = 0;

    for(ll i = 0; i < 61; i++){
        ll cnt = 0;

        for(auto x : a) cnt += chkbit(x, i);

        ll tmp1 = (cnt * (n - cnt)) % mod;
        ll tmp2 = (1LL << i) % mod;
        ll tmp3 = (tmp1 * tmp2) % mod;
        ans += tmp3;
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}



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

int main() {
  int a,b,c;
  long long k;
  cin>>a>>b>>c>>k;
  if(a>=k) {cout<<k<<endl; return 0;}
  if((a+b)>=k) {cout<<a<<endl; return 0;}
  int x=k-a-b;
  cout<<a-x<<endl;
}
  

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct edge {
  int to, cap, rev;
  edge(){}
  edge(int to, int cap, int rev)
    :to(to), cap(cap), rev(rev){}
};

struct Dinic {
  vector< vector<edge> > graph;
  vector<int> iter, level;
  Dinic(){}
  Dinic(int V):graph(V), iter(V), level(V){}
  void add_edge(int from, int to, int cap) {
    graph[from].emplace_back(to, cap, graph[to].size());
    graph[to].emplace_back(from, 0, graph[from].size()-1);
  }
  bool bfs(int s, int t) {
    fill(all(level), -1);
    queue<int> que;
    que.push(s);
    level[s] = 0;
    while(!que.empty()) {
      int v = que.front(); que.pop();
      for(edge &e : graph[v]) {
	if(e.cap > 0 && level[e.to] < 0) {
	  level[e.to] = level[v]+1;
	  que.push(e.to);
	}
      }
    }
    return level[t] >= 0;
  }
  int dfs(int v, int t, int f) {
    if(v == t) return f;
    for(int &i = iter[v]; i < (int)graph[v].size(); i++) {
      edge &e = graph[v][i];
      if(e.cap > 0 && level[e.to] > level[v]) {
	int d = dfs(e.to, t, min(f, e.cap));
	if(d > 0) {
	  e.cap -= d;
	  graph[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }
  int max_flow(int s, int t) {
    int flow = 0;
    while(bfs(s, t)) {
      fill(all(iter), 0);
      int f; while((f = dfs(s, t, inf)) > 0) flow += f;
    }
    return flow;
  }
};

void bfs(vector< vector<int> >& G, vector<int>& vis, int s) {
  queue<int> que;
  que.push(s);
  vis[s] = 0;
  while(!que.empty()) {
    int v = que.front(); que.pop();
    for(int to : G[v]) {
      if(vis[to] < 0) {
	vis[to] = vis[v] + 1;
	que.push(to);
      }
    }
  }
}

int N, M, S, T;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> N >> M >> S >> T, N || M || S || T) {
    --S, --T;
    vector<Pi> vec;
    Dinic graph(N);
    rep(i, M) {
      int a, b;
      cin >> a >> b;
      --a, --b;
      vec.emplace_back(a, b);
      graph.add_edge(a, b, 1);
    }
    int flow = graph.max_flow(S, T);
    vector<int> visS(N, -1);
    vector<int> visT(N, -1);
    auto& rgraph = graph.graph;
    {
      vector< vector<int> > G(N);
      rep(i, N) {
	for(edge& e : rgraph[i]) {
	  if(e.cap > 0) G[i].push_back(e.to);
	}
      }
      bfs(G, visS, S);
    }
    {
      vector< vector<int> > G(N);
      rep(i, N) {
	for(edge& e : rgraph[i]) {
	  if(e.cap > 0) G[e.to].push_back(i);
	}
      }
      bfs(G, visT, T);
    }
    int cnt = 0;
    for(Pi p : vec) {
      if(visS[p.second] >= 0 && visT[p.first] >= 0) cnt++;
    }
    cout << flow+(cnt>0) << " " << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 4080
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define el '\n'
#define MOD 1000000007

int dp[15];
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int r,d,x;
    cin >> r >> d >> x;
    dp[0]=x;
    for(int i=1;i<=10;i++){
        dp[i] = r*dp[i-1]-d;
        cout << dp[i] << el;
    }
    return 0;
}

Measured memory_bytes: 256
n = map(int, input())
p = map(int, input().split())
p = list(p)

cnt = 0
l = len(p)

for i in range(l):
    if i == 0 or i == l - 1:
        continue

    if (p[i - 1] < p[i]) and (p[i] < p[i + 1]):
        cnt += 1
    elif (p[i - 1] > p[i]) and (p[i] > p[i + 1]):
        cnt += 1

print(cnt)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  long long int a[n],b[n];
  for(int i=0;i<n;++i){
    cin>>a[i]>>b[i];
  }
  long long int m=10000000000,tem=0;
  for(int i=0;i<n;++i){
    if(b[i]<m){
      m = b[i];
      tem = i;
    }
  }
  cout<<a[tem]+b[tem];
}


Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>
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;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N,K;
    cin>>N>>K;
    vll d(K);
    vvll A(K);
    for(ll i=0;i<K;i++){
        cin>>d[i];
        A[i].resize(d[i]);
        for(ll j=0;j<d[i];j++)cin>>A[i][j];
    }
    
    vector<bool> n(N,false);
    
    for(ll i=0;i<K;i++){
        for(ll j=0;j<d[i];j++){
            n[A[i][j]-1]=true;
        }
    }
    
    ll ans=0;
    for(ll i=0;i<N;i++){
        if(!n[i])ans++;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
//using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dh[8] = {0, 0, 1, 1, 1, -1, -1, -1};
const int dw[8] = {1, -1, 0, 1, -1, 0, 1, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}
using Graph = vector<vector<int>>;
Graph G;
  
/*------------------------------------------------------------------*/
int main(){
    int n, k; cin >> n >> k;
    vector<int> sc(3);
    rep(i, 3) cin >> sc[i];
    string t; cin >> t;
    int ans = 0;
    rep(i, n){
        if(t[i] == 'r'){
            if(i < k) ans += sc[2];
            else{
                if(t[i - k] == 'r') t[i] = 'x';
                else ans += sc[2];
            }
        }
        if(t[i] == 's'){
            if(i < k) ans += sc[0];
            else{
                if(t[i - k] == 's') t[i] = 'x';
                else ans += sc[0];
            }
        }
        if(t[i] == 'p'){
            if(i < k) ans += sc[1];
            else{
                if(t[i - k] == 'p') t[i] = 'x';
                else ans += sc[1];
            }
        }
    }
    cout << ans << endl;
}

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

    #define ll long long
    #define ff first
    #define ss second
    #define pb push_back
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define MOD 1000000007
    #define pll pair<ll,ll>
constexpr ll INF = 1999999999999999997; 
    #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
    int main() {
      fastio;

      ll n;
      cin>>n;
      ll count=0;
      //int i=1;
      if(n&1)
        cout<<0<<endl;
      else
      {
      n=n/2;
      while(n)
      {  count+=n/5;
        n=n/5;
      }
      cout<<count<<endl;
    }
    }

Measured memory_bytes: 3636
#include<cstdio>
using namespace std;
int main(void)
{
	int n,flg,i,a;
	char s[101];
	scanf("%d %s",&n,s);
	flg=0;
	if(n%2==0){
		a=n/2;
		for(i=0;i<a;i++){
			if(s[i]!=s[i+a]){
				break;
			}
			if(i==a-1){
				flg=1;
			}
		}
	}
	if(flg==0){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

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

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

#define DEBUG(x) cerr << #x << " = " << x << endl

struct Cake {
  int w, h;
  Cake() { }
  Cake(int w_, int h_) : w(w_), h(h_) { }
  bool operator <(const Cake &rhs) const {
    return w*h < rhs.w*rhs.h;
  }
};

pair<Cake, Cake> cake_cut(Cake cake, int s) {
  s %= (2*cake.w + 2*cake.h);
  // 下
  if(cake.w + cake.h <= s && s <= 2*cake.w + cake.h) s -= cake.w + cake.h;
  if(2*cake.w + cake.h <= s) s -= cake.w + cake.h;
  if(s <= cake.w) {
    Cake a, b;
    a.w = s;
    a.h = cake.h;
    b.w = cake.w - s;
    b.h = cake.h;
    return make_pair(a, b);
  }
  else {
    int t = s - cake.w;
    Cake a, b;
    a.w = b.w = cake.w;
    a.h = t;
    b.h = cake.h - t;
    return make_pair(a, b);
  }
}

int main() {
  while(true) {
    int N, W, H; cin >> N >> W >> H;
    if(N == 0 && W == 0 && H == 0) break;
    vector<pair<int, Cake>> vec;
    vec.push_back(make_pair(0, Cake(W, H)));
    int turn = 1;
    for(int i = 0; i < N; ++i) {
      int p, s; cin >> p >> s;
      --p;
      Cake c = vec[p].second;
      vec.erase(vec.begin() + p);
      auto next = cake_cut(c, s);
      vec.push_back(make_pair(turn, next.first));
      vec.push_back(make_pair(turn, next.second));
      ++turn;
      sort(vec.begin(), vec.end());
    }
    vector<int> size(vec.size());
    for(int i = 0; i < (int)vec.size(); ++i) {
      size[i] = vec[i].second.w*vec[i].second.h;
    }
    sort(size.begin(), size.end());
    for(int i = 0; i < (int)size.size(); ++i) {
      if(i != 0) cout << ' ';
      cout << size[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1212
/*
P135
AOJ 0118 Property Distribution
*/

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
using namespace std;

int W, H;
char board[110][110];

bool read()
{
    scanf("%d%d", &H, &W);
    if(W==0 && H==0) return false;
    for(int i=0; i<H; ++i)
        scanf("%s", board[i]);
    return true;
}

bool isVisited[110][110];
int step;

void dfs(int x, int y, char c){
    if(x<0 || x>=H || y<0 || y>=W) return;
    if(board[x][y]!=c) return;
    if(isVisited[x][y]) return;
    isVisited[x][y] = true;
    dfs(x+1, y, c);
    dfs(x-1, y, c);
    dfs(x, y+1, c);
    dfs(x, y-1, c);
}

void solve()
{
    int ans = 0;
    memset(isVisited, 0, sizeof(isVisited));
    for(int i=0; i<H; ++i)
    for(int j=0; j<W; ++j)
    {
        if(!isVisited[i][j]){
            ans++;
            dfs(i, j, board[i][j]);
        }
    }

    printf("%d\n", ans);
}


int main()
{
    while(read())
        solve();
}

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

typedef long long ll;
typedef unsigned long long int ull;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> tii;
typedef vector<pii> vii;

#define pb push_back
#define mp make_pair
#define sq(a) (a)*(a)
#define rep(i,a,b) for (int i = a; i < b; i++)
#define mod 1e9+7
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-7

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);


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

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

	IOS

	long long int s, w;
	cin >> s >> w;
	if (w-s>=0) 
      cout << "unsafe" << endl;
	else
		cout << "safe" << endl;

	return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector< pair<string, int> >vv;
    long long sum = 0;
    for(int i = 1; i <= n; i++)
    {
        string tem;
        int te;
        cin >> tem >> te;
        sum += te;
        vv.push_back(make_pair(tem, te));
    }
    string x;
    cin >> x;
    for(int i = 0; i < vv.size(); i++)
    {
        string tem = vv[i].first;
        int te = vv[i].second;
        if(x.compare(tem) == 0)
        {
            sum -= te;
            break;
        }
        else
        {
            sum -= te;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val as = List.fill(n)(sc.nextInt)

    print {
      val bs = {if (as.length%2 == 0) as else 0 :: as}
        .sorted
        .grouped(2).toList
      bs.map(_(1)).sum - bs.map(_(0)).sum
    }
  }
}


Measured memory_bytes: 27200
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		long[] H = new long[N];
		for(int i = 0;i < N;i++) {
			H[i] = Long.parseLong(sc.next());
		}
		sc.close();
		int[] d = new int[N];
		int cnt = 0;
		for(int i = 0;i < N-1;i++) {
			if(H[i] >= H[i+1]) {
				cnt++;
			}else {
				cnt = 0;
			}
			d[i] = cnt;
		}
		Arrays.sort(d);
		System.out.println(d[N-1]);
	}
}

Measured memory_bytes: 51964