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

/*

*/

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        String t = sc.next();

        String[] temp = t.split("");

        String[] ans = new String[t.length()];
        String flg = "";

        // flgはひとつ前の文字列PかDかを保持
        // pointは判定文字を保持
        for (int i = 0; i < t.length(); i++) {
            String point = temp[i];
            if (!point.equals("?")) {
                flg = point;
            } else {
                if (i == 0) {
                    flg = "D";
                    ans[i] = flg;
                    continue;
                }
                if (i != t.length() -1) {
                    if (flg.equals("P") && temp[i+1].equals("P")) {
                        flg = "D";
                    } else if (flg.equals("P") && temp[i+1].equals("D")) {
                        flg = "D";
                    } else if (flg.equals("D") && temp[i+1].equals("D")) {
                        flg = "P";
                    } else if (flg.equals("D") && temp[i+1].equals("P")) {
                        flg = "D";
                    } else if (flg.equals("D") && temp[i+1].equals("?")) {
                        flg = "P";
                    } else if (flg.equals("P") && temp[i+1].equals("?")) {
                        flg = "D";
                    }    
                }
                if (i == t.length() -1) {
                    flg = "D";
                }
            }
            ans[i] = flg;
        }

        String answer = String.join("", ans);
        System.out.println(answer);
    }
}

Measured memory_bytes: 68140
#include<cstdio>
int main ()
{
    int p,q,r;
    scanf("%d%d%d",&p,&q,&r);
    int ans1,ans2,ans3;
    ans1=p+q;
    ans2=p+r;
    ans3=q+r;
    int k;
    k=ans1<ans2?ans1:ans2;
    printf("%d\n",ans3<k?ans3:k);
    return 0;
}


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

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

template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
struct Unionfind {
    vector<int> par;
    vector<int> sizes;

    Unionfind(int n) : par(n), sizes(n, 1) {
        for(int i = 0; i < n; ++i) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        if(sizes[x] < sizes[y]) swap(x, y);
        par[ry] = rx;
        sizes[rx] += sizes[ry];
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return sizes[root(x)];
    }

};

int keta(ll x) {
    int cnt = 0;

    while(x > 0) {
        x /= 10;
        ++cnt;
    }

    return cnt;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    ll n;
    cin >> n;

    int ans = keta(n);

    for(ll i = 1; i*i <= n; ++i) {
        if(n % i != 0) continue;
        ll b = n / i;

        int c = max(keta(i), keta(b));

        ans = min(ans, c);
    }

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

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

using namespace std;

int main()
{
    int A, B, T; cin >> A >> B >> T;
    int ans = 0;

    for (int i = 1; i*A <= T; i++)
    {
        ans += B;
    }

    cout << ans << endl;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

constexpr char sp = ' ';
constexpr char cmm = ',';
constexpr int MOD = 1e9+7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
inline void Yes(){cout << "Yes" << endl;}
inline void No(){cout << "No" << endl;}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){cout << "YES" << endl;}
inline void NO(){cout << "NO" << endl;}
inline void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){
    
    int n;
    scanf("%d", &n);
    vector<int> d(n);
    rep(i, n) scanf("%d", &d[i]);
    int ans = 0;
    rep(i, n){
        for(int j = i+1; j < n; ++j){
            ans += d[i]*d[j];
        }
    } 
    ppp(ans);
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 998244353;
const int maxn = 2e5+10;
const int N = 1e6+10;
const int E = 1e6+10;  
ll n,m,k;
string s;
string t;
int main(){
	double l;cin>>l;
	l = (l/3.0)*(l/3.0)*(l/3.0);
	printf("%.7lf\n",l);
}

/*
cin>>s;
	n = s.size();
	dF(i,n-1,0){
		t+=s[i];
	}
	bool flg = 1;
	F(i,0,n-1){
		if(t[i]!=s[i]){
			flg = 0;
			break;
		}
	}
	F(i,0,(n-1)/2-1){
		if(s[i]!=s[i+(n+3)/2 -1]){
			flg = 0;
			break;
		}
	}
	if(flg){
		printf("Yes\n"); 
	}
	else printf("No\n");
*/

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


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

	string ss = s;
	reverse(ss.begin(), ss.end());
	int l_cnt = 0;
	int r_cnt = 0;
	for (int i=0; i<s.size()-1; i++) {
		if (s[i]==s[i+1]) {
			if (s[i]=='0') s[i+1] = '1';
			else s[i+1] = '0';
			l_cnt++;
		}
	}
	for (int i=0; i<ss.size()-1; i++) {
		if (ss[i]==ss[i+1]) {
			if (ss[i]=='0') ss[i+1] = '1';
			else ss[i+1] = '0';
			r_cnt++;
		}
	}
	cout << min(l_cnt, r_cnt) << endl;
}

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

const int N = 2e5 + 5;
vector< vector<int> > g (N);

vector<int> ans (N);

void dfs (int node, int p) {
  ans[node] += (p != -1 ? ans[p] : 0);
  for (auto to : g[node]) {
    if (to != p) {
      dfs (to, node);
    }
  }
}

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n - 1; i++) {
    int st, et;
    cin >> st >> et;
    st--; et--;
    g[st].emplace_back(et);
    g[et].emplace_back(st);
  }
  while (q--) {
    int s, add;
    cin >> s >> add;
    s--;
    ans[s] += add;
  }
  dfs (0, -1);
  for (int i = 0; i < n; i++) {
    cout << ans[i] << ' ';
  }
  cout << '\n';
  return 0;
}

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

//count1...先頭＝＝末尾, count2...先頭！＝末尾
int count1 = 0, count2 = 0;

//先頭と末尾の判定
bool test1(long long A, long long B)
{
    string a = to_string(A), b = to_string(B);

    if (a.at(0) == b.at(b.length() - 1) && a.at(a.length() - 1) == b.at(0))
    {
        return true;
    }

    else
    {
        return false;
    }
}

//先頭と末尾の判定カウント
long long test2(long long A, long long B)
{
    string a = to_string(A), b = to_string(B);

    if (a.at(0) == b.at(b.length() - 1) && a.at(a.length() - 1) == b.at(0))
    {

        if (a.at(0) == a.at(a.length() - 1))
        {
            count1++;
        }

        else
        {
            count2++;
        }
    }
}

int main()
{
    long long N, ans = 0, count3 = 0;
    cin >> N;

    if (N < 100)
    {
        for (long long A = 1; A < N + 1; A++)
        {
            for (long long B = 1; B < N + 1; B++)
            {
                if (test1(A, B))
                {
                    ans++;
                }
            }
        }
    }

    else
    {

        ans += pow(N / 10, 2) + 8;

        if (N > (N % 10) * 10)
        {
            for (int j = (N / 10) * 10 + 1; j < N + 1; j++)
            {
                string a = to_string(j);

                if (a.at(0) == a.at(a.length() - 1))
                {
                    count3++;
                }

                for (int i = 1; i < N + 1; i++)
                {
                    test2(j, i);
                }
            }
        }

        ans += (count1 * 2 - count3) + count2 * 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
ll D = 1000000007;

ll factor(ll n){
  if(n==1) return 1;
  else return (n*factor(n-1))%D;
}

int main(){
  ll N, M;
  cin >> N >> M;

  int gap = abs(N-M);

  ll ans = factor(N)*factor(M)%D;
  //cout << ans <<endl;

  if(gap>=2){
    cout << 0 <<endl;
  }else if(gap==1){
    cout << ans <<endl;
  }else{
    cout << (2*ans)%D <<endl;
  }

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

int main() {
        string a, b;
        cin >> a >> b;
        string c = a + b;
        int d = stoi(c);
        for (int i = 2; i * i <= d; i ++) {
                if (d % i == 0) {
                        if (d / i == i) {
                                puts("Yes");
                                return 0;
                        }
                }
        }
        puts("No");
        return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;

void insertion_sort(int array[],int n){
    for(int i = 1;i<n;i++){
       int key = array[i];
       int j = i-1;
       while(j>=0 && array[j] > key){
           array[j+1] = array[j];
           j = j-1;
       }
       array[j+1] = key;
       for(int k =0;k<n;k++){
           
           if(k == n-1){
               cout<<array[k]<<endl;
           }else{
               cout<<array[k]<<" ";
           }
       }
    }
}

int bubble_sort(int array[],int n){
    int count = 0;
   for(int i = 0;i < n;i++){
       for(int j = n-1;j> i;j--){
           if(array[j] < array[j-1]){
               int temp = array[j];
               array[j] = array[j - 1];
               array[j - 1] = temp;
               count++;
           }
       }
   }
   for(int k = 0;k<n;k++){
       if(k < n-1){
        cout<<array[k]<<" ";
       }
       else{
           cout<<array[k]<<endl;
       }
   }
   cout<<count<<endl;
   return count;
}


int main(){
    int n,a,b;
    cin>>n;
    int array[100] = {0};
    for(int i = 0;i<n;i++){
        cin>>array[i];           
    }
    int count = bubble_sort(array,n);
    
}


Measured memory_bytes: 3084
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        String a = scanner.next();
        String b = scanner.next();
        String c = scanner.next();
        long ans = 0;
        for (int i = 0; i < n; i++) {
            boolean f1 = a.charAt(i) != b.charAt(i);
            boolean f2 = b.charAt(i) != c.charAt(i);
            boolean f3 = c.charAt(i) != a.charAt(i);
            if (f1 && f2 && f3) {
                ans += 2;
            } else if (f1 || f2 || f3) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22740
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);i--)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef pair<string,P> Q;
typedef vector<vector<P> > Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n;
  cin >> n;

  vector<Q> a(n);
  REP(i,n){
    cin >> a[i].fs >> a[i].sc.fs;
    a[i].sc.sc = i;
    a[i].sc.fs *= -1;
  }

  sort(a.begin(),a.end());

  vec ans(n);
  REP(i,n) ans[a[i].sc.sc] = i+1;

  REP(i,n ) cout << a[i].sc.sc+1 << endl;

  return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> ans(n, 0);
    for (int i = n; i > 0; i--){
        int tmp = 0;
        for (int j = i * 2; j <= n; j += i) tmp += ans[j-1];
        if (tmp % 2 != a[i-1]) ans[i-1]++; 
    }
    int m = 0;
    for (int i = 0; i < n; i++) if (ans[i] % 2 == 1) m++;
    cout << m << endl;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (ans[i] % 2) {
            cout << i + 1;
            cnt++;
            if (cnt != m) cout << " ";
            else cout << endl;
        }
    }
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll INF = 1000000000000000LL;
int main() {
  while (true) {
    ll n, m;
    cin >> n >> m;
    if (n == 0)
      break;
    vector<ll> mins(n), maxs(n);
    for (int i = 0; i < m; i++) {
      int k;
      ll s;
      cin >> s >> k;
      vector<int> ids(k);
      for (int j = 0; j < k; j++)
        cin >> ids[j];
      for (int j = 0; j < k; j++)
        ids[j]--;
      if (k == 1)
        mins[ids[0]] += s;
      for (auto &j : ids)
        maxs[j] += s;
    }
    ll ans = 0;
    vector<ll> maxs2 = maxs;
    sort(maxs2.begin(), maxs2.end());
    ll fst = maxs2[n - 1];
    ll snd = maxs2[n - 2];
    for (int i = 0; i < n; i++) {
      if (maxs[i] == fst) {
        ans = max(ans, snd - mins[i] + 1);
      } else {
        ans = max(ans, fst - mins[i] + 1);
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    string S,T;
    cin >> S >> T;
    int ans = 0;
    int n = S.size();
    REP(i, n){
        if(S[i]!=T[i])ans++;
    }
    pr(ans);
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  if((a + b == c) or (b + c == a) or (c + a == b))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
#include <memory>
#include <queue>
#include <vector>

struct Robot;
struct RobotParam {
    int begin;
    int end;
    std::shared_ptr<Robot> robot{nullptr};
};
std::istream& operator>>(std::istream& is, RobotParam& robot)
{
    is >> robot.begin >> robot.end;
    robot.end += robot.begin;

    return is;
}

struct Robot : std::enable_shared_from_this<Robot> {
    std::shared_ptr<Robot> parent;
    int rank;
    long cases = 1;

private:
    Robot()
        : parent{nullptr}, rank{0}
    {
    }

    explicit Robot(std::shared_ptr<Robot> const& _parent)
        : parent{_parent}, rank{_parent->rank + 1}
    {
    }

public:
    static std::shared_ptr<Robot> base;

    static std::shared_ptr<Robot> create(std::shared_ptr<Robot> const& parent)
    {
        return std::shared_ptr<Robot>{new Robot{parent}};
    }
};
std::shared_ptr<Robot> Robot::base = std::shared_ptr<Robot>{new Robot};

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

    std::vector<std::shared_ptr<Robot>> robots;
    robots.reserve(N);

    {
        std::vector<RobotParam> params;
        params.reserve(N);

        std::copy(std::istream_iterator<RobotParam>{std::cin}, std::istream_iterator<RobotParam>{},
            std::back_inserter(params));

        std::sort(params.begin(), params.end(), [](auto const& lhs, auto const& rhs) {
            return lhs.begin < rhs.begin;
        });

        std::vector<RobotParam> movement;
        movement.reserve(N);

        for (auto& param : params) {
            // std::cout << "thinking about: [" << param.begin << ", " << param.end << ')' << std::endl;

            while (!movement.empty() && movement.back().end <= param.begin) {
                // std::cout << "\t\trobot won't reach: [" << movement.back().begin << ", " << movement.back().end << ')' << std::endl;
                movement.pop_back();
            }

            std::shared_ptr<Robot> new_robot;
            if (movement.empty()) {
                // std::cout << "\tno robots reach" << std::endl;
                new_robot = Robot::create(Robot::base);
            } else {
                // std::cout << "\trobot reach: [" << movement.back().begin << ", " << movement.back().end << ')' << std::endl;
                new_robot = Robot::create(movement.back().robot);
            }

            param.robot = new_robot;
            robots.push_back(new_robot);
            movement.push_back(param);
        }
    }

    std::sort(robots.begin(), robots.end(),
        [](auto const& lhs, auto const& rhs) {
            return lhs->rank > rhs->rank;
        });

    for (auto const& robot : robots) {
        robot->parent->cases *= robot->cases + 1;
        robot->parent->cases %= 998244353;
    }

    std::cout << Robot::base->cases;

    return 0;
}

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

int main() {
    int a = 0, b = 0, ans;
    string str;
    cin >> str;
    rep(i, str.length()) {
        if(str.at(i) == '0') a++;
        else b++;
    }
    ans = 2 * min(a, b);
    cout << ans << endl;
}

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

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

  int ans[n];
  for(int i=0; i<n; i++) ans[i]=0;

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

  for(int i=0; i<n; i++) cout<<ans[i]<<endl;

  return 0;
}

Measured memory_bytes: 5148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> P1;
typedef pair<P,P> P2;
typedef pair<double,int>Q;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef complex<double> pt;
int dist[100005],n;
int main(){
	cin>>n;
	priority_queue<P,vector<P>,greater<P> >que;
	fill(dist,dist+100005,INF);
	for(int i=1;i<=9;i++){
		que.push(mp(i,i%n));
		dist[i%n] = min(dist[i%n],i);
	}
	while(!que.empty()){
		P p = que.top(); que.pop();
		if(p.fi != dist[p.sc]) continue;
		//cout<<p.fi<<" "<<p.sc<<endl;
		for(int i=0;i<=9;i++){
			int nxt = p.sc*10+i;
			int val = p.fi+i;
			nxt %= n;
			if(dist[nxt] > val){
				dist[nxt] = val;
				que.push(mp(val,nxt));
			}
		}
	}
	cout<<dist[0]<<endl;
}

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

int main(){
  string W ;
  cin >> W ; 
  int N = W.size() ; 
  vector<int> C(N);
  
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < N ; j++){
      
        if(W.at(i) == W.at(j)){
          C.at(i)++ ; 
        }

    }
  }
  
  
  for(int i = 0 ; i < N ; i++){
    if( C.at(i) % 2 != 0 ){
      cout << "No" << endl ; 
      return 0 ; 
    }
    
  }
  
  cout << "Yes" << endl ; 
           
           

}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
  int n,m; cin>>n>>m;
  vector<int> h(n);
  for(int i=0;i<n;i++)cin>>h[i];
  
  Graph G(n);
  for (int i=0;i<m;++i) {
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  queue<int> que;
  int count=0;
  que.push(0);
  while(!que.empty()){
    int v=que.front();que.pop();
    bool ok=true;
    for(auto nv:G[v]){
      if(h[v]<=h[nv]){
        ok=false;
        break;
      }
    }
    if(ok)count++;
    if(v<n-1)que.push(v+1);
  }
  cout << count << endl;
}

Measured memory_bytes: 8800
def solve(S):
    chars = [chr(c) for c in range(ord("a"), ord("z") + 1)]
    cs = dict((c, S.count(c)) for c in chars)
    l = len(S) 
    if l < len(chars):
        return S + sorted(c for c, n in cs.items() if n == 0)[0]
    for i in range(2, l + 1):
        sl = S[:l - i]
        sc = S[l - i]
        sr = S[l - i + 1:]
        msrs = [c for c in sr if c > sc]
        if msrs:
            return sl + sorted(msrs)[0]
    return -1

S = input()
print(solve(S))


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

using namespace std;

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

    string s;
    cin >> s;

    int p = 0;
    int x =0;

    for(int i=0;i<n;i++)
    {
        if(s[i] == 'I')
            x++;
        else
            x--;

        if(x > p)
            p = x;
    }

    cout << p << endl;
}

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,a,n) for(int i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;

const int INF=2000000000;
const ll LINF = 1e18+5;

int main() {
    int N;
    cin >> N;
    int a[200000] = {};
    rep(i,N) cin >> a[i];
    int now = 0;
    rep(i,N) {
        if(a[i] == now+1) now++;
    }
    if(now==0) cout << -1 << endl;
    else cout << N - now << endl;
    return 0;
}

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

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

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

signed main()
{
    int S; cin >> S;
    int u = S / 100;
    int l = S % 100;
    if (u > 12){ // YY**
        if (l == 0) puts("NA");
        else if (l <= 12) puts("YYMM");
        else puts("NA");
    } else if (u == 0) { // YY**
        if (l == 0) puts("NA");
        else if (l <= 12) puts("YYMM");
        else puts("NA");
    } else { // 0 < u <= 12 ; MM**, YY**
        if (l > 12) puts("MMYY");
        else if (l == 0) puts("MMYY");
        else puts("AMBIGUOUS");
    }

    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()

left = 0
p = 0
for i in range(n):
    if s[i] == '(':
        p += 1
    else:
        if p == 0:
            left += 1
        else:
            p -= 1
right = p

res = ""
for i in range(left):
    res += '('
res += s
for i in range(right):
    res += ')'
print(res)


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

int n;
int k;
int card[201];

void rifl(int cd[201] )
{
	int i;
	for (i = 1; i <= n*2; i+=2)
	{
		card[i] = cd[i / 2 + 1];
		card[i + 1] = cd[n + (i / 2 + 1)];
	}
}

void ksf(int cd[201])
{
	int i;
	for (i = k+1; i <= n*2; i++)
	{
		card[i - k] = cd[i];
	}
	for (i = 1; i <= k; i++)
	{
		card[n*2 - k + i] = cd[i];
	}
}

int main()
{
	int m;
	int cd[201];

	int i,j;

	scanf("%d %d", &n, &m);

	for (i = 1; i <= n * 2; i += 2)
	{
		card[i] = i;
		card[i + 1] = i + 1;
	}

	for (i = 0; i < m; i++)
	{
		for (j = 1; j <= n * 2; j++)
		{
			cd[j] = card[j];
		}

		scanf("%d",&k );

		if (k == 0)
		{
			rifl(cd);
		}
		else
		{
			ksf(cd);
		}

	}

	for (i = 1; i <= n * 2; i++)
	{
		printf("%d\n", card[i]);
	}

	return 0;
}


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

int main()
{
	int k,n;
	cin>>k>>n;
	vector<int> a(2*n);
	for(size_t i = 0; i<n; i++)
	{
		cin>>a[i];
		a[n+i] = a[i]+k;
	}
	int ans = a[n-1]-a[0];
	for(size_t i = 1; i<n; i++)
	{
		if(ans>a[n+i-1]-a[i])
		{
			ans = a[n+i-1]-a[i];
		}

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

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll a,b,c,i,j,k,l,m,n,ans,tmp,hoge,fuga,piyo;
ll x[10010],y[10010];
ll aa[110][110];
string s,str;
int main(){
  cin>>n>>k;
  for(int i=0;i<k;i++){
    cin>>a;
    for(int j=0;j<a;j++){
      cin>>b;
      x[b-1]++;
    }
  }
  for(int i=0;i<n;i++){
    if(x[i]==0)ans++;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3644
#cocoinit23

n = int(input())

table = [[0] * 10 for _ in range(10)]

for i in range(1, n + 1):
    sentou = int(str(i)[0])
    matsubi = int(str(i)[-1])
    table[sentou][matsubi] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += table[i][j] * table[j][i]

print(ans)

Measured memory_bytes: 40428
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>
#include<queue>
#include<set>


#define MOD 1000000007
#define DEBUG 0


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

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

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}

	return true;
}



bool comp(const pair<long long int, vector<int>> a, const pair<long long int, vector<int>> b) {
	if (a.first != b.first) {
		return a.first < b.first;
	}
	else {
		return a.second < b.second;
	}

}







bool isReversible(string str) {

	int index1 = 0, index2 = str.size() - 1;

	while (index1 < index2) {
		if (str[index1] != str[index2])return false;
		index1++;
		index2--;
	}

	return true;


}



int main(){

	string str;
	cin >> str;

	int n = str.size();

	string mae = str.substr(0, (n - 1) / 2);
	string usiro = str.substr((n + 3) / 2 - 1, n - (n + 3) / 2 + 1);

	if (isReversible(str) && isReversible(mae) && isReversible(usiro)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}



	return 0;
}



Measured memory_bytes: 256
N = int(input())
S = input()

W = [0]

for i in S:
    if i == 'W':
        W.append(W[-1]+1)
    else:
        W.append(W[-1])

answer = W[-1]
for i in range(1, N+1):
    answer = min(answer, W[i-1] + N - i - (W[-1] - W[i]))

print(answer)

Measured memory_bytes: 15400
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int main(){
    fast_io
   
   int n;
   cin>>n;
   vector<ll> L(n);
   rep(i,n) cin>>L[i];
   sort(L.begin(), L.end());
   ll ans=0;
   for(int i=0;i<n-2;i++){
       for(int j=i+1;j<n-1;j++){
           for(int k=j+1;k<n;k++){
               if(L[i]!=L[j] && L[i]!=L[k] && L[j]!=L[k]){
                   if(L[i]+L[j]>L[k]) ans++;
               }
           }
       }
   }    
   cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

#include <functional>
template<typename T>
class SegmentTreeOneAll {
    using Func = function<T(T, T)>;

public:
    vector<T> data;
    int n;
    T init;
    Func update_func;
    Func query_func;
    SegmentTreeOneAll(int _n, T _init, Func up, Func qu) {
        init = _init;
        update_func = up;
        query_func = qu;
        for (n = 1; n < _n; n *= 2)
            ;
        data.resize(2 * n - 1, init);
    }
    void update(int pos, T val) {
        pos += n - 1;
        data[pos] = update_func(data[pos], val);
        while (pos > 0) {
            pos = (pos - 1) / 2;
            data[pos] = query_func(data[2 * pos + 1], data[2 * pos + 2]);
        }
    }
    T query(int l, int r) {
        T res = init;
        for (l += n - 1, r += n - 1; l < r; l = l / 2, r = (r - 1) / 2) {
            if (!(l & 1)) {
                res = query_func(res, data[l]);
            }
            if (!(r & 1)) {
                res = query_func(res, data[r - 1]);
            }
        }
        return res;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    auto SUM = [](ll a, ll b) { return a + b; };
    SegmentTreeOneAll<ll> segtree(n, 0, SUM, SUM);
    REP(i, 0, q) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com) {
            cout << segtree.query(x - 1, y) << endl;
        } else {
            segtree.update(x - 1, y);
        }
    }
    return 0;
}



Measured memory_bytes: 4952
def main():
  import sys
  n,s,_,*t=sys.stdin.buffer.read().split()
  n=int(n)
  d=[0]*n+[1<<c-97for c in s]
  for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i]
  for q,a,b in zip(*[iter(t)]*3):
    i,s=int(a)+n-1,0
    if q<b'2':
      d[i]=1<<ord(b)-97
      while i>1:
        i//=2
        d[i]=d[i+i]|d[i-~i]
      continue
    j=int(b)+n
    while i<j:
      if i&1:
        s|=d[i]
        i+=1
      if j&1:
        j-=1
        s|=d[j]
      i//=2
      j//=2
    print(bin(s).count('1'))
main()

Measured memory_bytes: 45536
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>

using namespace std;

#define int long long
#define ll long long
#define double long double
#define pii pair<int, int>
#define vec vector
#define u_map unordered_map
#define u_set unordered_set
#define str string
#define all(el) el.begin(), el.end()
#define allr(el) el.rbegin(), el.rend()
#define sz(el) (int)el.size()
#define f first
#define s second
#define pb push_back
#define in insert
#define mp make_pair
#define endl "\n"
#define forn(i, n) for (int i = 0; i < n; ++i)

inline int maxi(int &a, int b) { if (b > a) { a = b; return 1; } return 0; }

inline int mini(int &a, int b) { if (b < a) { a = b; return 1; } return 0; }

inline int maxi(double &a, double b) { if (b > a) { a = b; return 1; } return 0; }

inline int mini(double &a, double b) { if (b < a) { a = b; return 1; } return 0; }

int bin_pow(int x, int p) {
    if (p < 0) {
        return 0;
    }
    if (p == 0) {
        return 1;
    }
    if (p % 2 == 0) {
        int ans = bin_pow(x, p / 2);
        return ans * ans;
    }
    return x * bin_pow(x, p - 1);
}

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

const int maxH = 1e4 + 1;

int dp[maxH];

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int h, n;
    cin >> h >> n;
    vec<int> a(n), b(n);

    for (int i = 0; i < maxH; i++) {
        dp[i] = 1e18;
    }
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    for (int i = 0; i < maxH; i++) {
        for (int j = 0; j < n; j++) {
            if (i - a[j] >= 0) {
                mini(dp[i], dp[i - a[j]] + b[j]);
            }
        }
    }

    int ans = 1e18;
    for (int i = h; i < maxH; i++) {
        mini(ans, dp[i]);
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 3752
import sys

def scp(a, b):
    if b > a:
        tmp_a = a
        a = b
        b = tmp_a
    while b:
        r = a % b
        a = b
        b = r
    return a
    #for i in xrange(100000, 2, -1):
    #    if a % i == b % i == 0:
    #        return a * b / i
    #return a * b

N = int(raw_input())
array = []
for i in range(N):
    array.append(int(raw_input()))

array.sort()

#if array[-1] > pow(10, 9):
#    print array[-1]
#    sys.exit(0)

result = array[0]
for i in array[1:]:
    result = result / scp(result, i) * i
print result

Measured memory_bytes: 2568
N=int(input())
a=[input() for i in range(N)]
blackExistCol=[False for i in range(N)]
blackNumRow=[0 for i in range(N)]


flag=False
Max=-1
already=0

for i in range(N):
  for j in range(N):
    if a[i][j]=="#":
      blackExistCol[j]=True
      blackNumRow[i]+=1
      flag=True

if flag==False:
  print("-1")
else:
  for i in range(N):
    if blackExistCol[i]:
      if Max<blackNumRow[i]:
        Max=blackNumRow[i]
  Min=N-Max
  for j in range(N):
    for i in range(N):
      if a[i][j]==".":
        break
    else:
      already+=1
  temp=max(blackNumRow)
  Min2=N-temp+1
  
  ans=min(Min,Min2)+N-already
  
  print(ans)

Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;

public class ABC0126_A1 {
    private static void Main(string[] args) {
        var inputs = new List<string>() {
            Console.ReadLine().Trim(),
            Console.ReadLine().Trim(),
        };

        Prepare(inputs);
    }

    private static void Prepare(List<string> inputs) {
        var numbersStr = inputs[0].Split();
        var index = int.Parse(numbersStr[1]) - 1;
        var word = inputs[1].ToCharArray();

        Compute(index, word);
    }

    private static void Compute(int index, char[] word) {
        word[index] = char.ToLower(word.ElementAt(index));
      
        OutputAnswer(new String(word));
    }

    private static void OutputAnswer(string text) => Console.WriteLine(text);
}

Measured memory_bytes: 11220
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map { it.toInt() }
    val iter = 1250
    var count = 0;
    for(i in 1..iter){
        var tax_a = Math.floor(i*0.08).toInt()
        var tax_b = Math.floor(i*0.1).toInt()
        if(tax_a == a && tax_b == b){
            println(i)
            count++
            break
        }
    }
    if(count == 0) println(-1)
}

Measured memory_bytes: 37872
from itertools import product
N, M = map(int, input().split())
S = []
for i in range(M):
    inp = list(map(int, input().split()))
    S.append(inp[1:])
P = list(map(int, input().split()))

ans = 0
for perm in product([0, 1], repeat=(N + 1)):
    on_light = 0
    for i, s in enumerate(S):
        on_switch = 0
        for si in s:
            if perm[si] == 1:
                on_switch += 1

        if on_switch % 2 == P[i]:
            on_light += 1

    if on_light == M:
        ans += 1

print(ans // 2)


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

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

int main(){
  int t;
  cin >> t;
  vector<bool> ans(t,false);
  rep(i,t) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if(c >= b && d >= b && a >= b) {
      ans[i] = true;
    } else if(a >= b && d >= b) {
      ll m = a % b;
      ll g = gcd(b,d);
      ll l = (c-m+g)/g, r = (b-1-m)/g;
      if(!(r >= l)) ans[i] = true;
    }
  }
  for(auto k : ans) cout << (k? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,idx[3];
int d[3][100050];
bool u[100050];
vector<int> v[100050];
void dfs(int x,int p,int w){
  d[w][p]=x;u[p]=true;
  if(d[w][p]>d[w][idx[w]]) idx[w]=p;
  for(int i=0;i<v[p].size();i++) if(!u[v[p][i]]) dfs(x+1,v[p][i],w);
}
void calc(){
  
}
int main(){
  cin>>n;
  int i,j,k;
  for(i=0;i<n-1;i++){
    cin>>j>>k;
    j--;k--;
    v[j].push_back(k);
    v[k].push_back(j);
  }
  idx[0]=idx[1]=idx[2]=0;
  memset(d,0,sizeof(d));
  memset(u,0,sizeof(u));
  dfs(0,0,0);
  memset(u,0,sizeof(u));
  dfs(0,idx[0],1);
  memset(u,0,sizeof(u));
  dfs(0,idx[1],2);
  for(i=0;i<n;i++){
    //cout << d[1][i] << ":" << d[2][i] << endl;
    cout << 2*(n-1) - max(d[1][i],d[2][i]) << endl;
  }
  return 0;
}



Measured memory_bytes: 14436
#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;
  ll L[2*N];
  rep(i,2*N) cin >> L[i];
  sort(L,L+2*N);
  ll ans =0;
  rep(i,N){
    ans += L[i*2];
  }
  cout << ans << endl;
  return 0;

}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  vector<int> a(n + 1);
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '<') a[i + 1] = a[i] + 1;
  }
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == '>') a[i] = max(a[i], a[i + 1] + 1);
  }
  int ans = 0;
  for (auto &i : a) ans += i;
  cout << ans << '\n';
}


Measured memory_bytes: 7696
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int h=sc.nextInt();
    int w=sc.nextInt();
    int n=sc.nextInt();
    int[] a=new int[n];
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
    }
    Stock st=new Stock(a);
    int[][] c=new int[h][w];
    for(int i=0;i<h;i++){
      if(i%2==0){
        for(int j=0;j<w;j++){
          c[i][j]=st.get();
        }
      }else{
        for(int j=w-1;j>=0;j--){
          c[i][j]=st.get();
        }
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w-1;j++){
        System.out.print(c[i][j]+" ");
      }
      System.out.println(c[i][w-1]);
    }
  }
  static class Stock{
    int[] a;
    int idx=0;
    Stock(int[] a){
      this.a=a;
    }
    int get(){
      if(idx>=a.length){
        return -1;
      }
      int res=idx;
      a[idx]--;
      if(a[idx]==0){
        idx++;
      }
      return res+1;
    }
  }
}

Measured memory_bytes: 34500
import java.util.*;
public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    String str = sc.next();
	    String[] array = str.split("");
        int count = 0;
        for (int i=1; i<4; i++) {
        	if (array[i].equals(array[i-1])) {
            	count++;
            } else if (i == 2) {
            	break;
            }
        }
        String ans = (count >= 2)? "Yes": "No";
      	System.out.println(ans);
	}
}

Measured memory_bytes: 35704
#include<bits/stdc++.h>
using namespace std;
typedef pair<string,int> P;
int n,qt;
vector<P> vec;

int main(){
	cin>>n>>qt;
	queue<pair<string,int> > que;
	for(int i=0;i<n;i++){
		string s;
		int t;
		cin >> s >> t;
		que.push(make_pair(s,t));
	}
	int now=0;
	while(!que.empty()){
		pair<string,int> q=que.front();
		que.pop();
		if(q.second<=qt){
			//vec.push_back(pair<string,int>(q.first,now+q.second));
			now+=q.second;
			cout<<q.first<<" "<<now<<endl;

		}else{
            q.second-=qt;
			now+=qt;
			que.push(q);
			//que.push(pair<string,int>(q.first,q.second-qt));
		}
	}
	/*for(int i=0;i<n;i++){
		cout << vec[i].first << " " << vec[i].second << endl;
	}*/
	return 0;
}


Measured memory_bytes: 6340
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <cstdio>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> s;
  int alp[n][26];

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < 26; j++) {
      alp[i][j] = 0;
    }
  }

  for(int i = 0; i < n; i++) {
    string t;
    cin >> t;
    for(int j = 0; j < t.size(); j++) {
        //cout << t[j]-'a' << endl;
        //cout << t[j] << endl;
        alp[i][t[j]-'a']++;
    }
    s.push_back(t);
  }

  string ans = "";
  int alp_num[26];
  for(int i = 0; i < 26; i++) alp_num[i] = alp[0][i];

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < 26; j++) {
      alp_num[j] = min(alp_num[j], alp[i][j]);
      //cout << alp_num[j] << " ";
    }
    /*
    cout << endl;
    for(int j = 0; j < 26; j++) {
      cout << alp[i][j] << " ";
    }
    cout << endl;
    */
  }

  for(int i = 0; i < 26; i++) {
    if(alp_num[i] != 0) {
      for(int j = 0; j < alp_num[i]; j++) {
        ans += (i+'a');
      }
    }
  }
  cout << ans << endl;
/*
  int p = s.size();
  for(int i = 0; i < 26; i++) alp[i] = 0;
  for(int i = 0; i < p; i++) {
    for(int j = 0; j < s[i].size(); j++) {
      alp[s[j]]++;
    }
  }
  */
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] pn = new int[n+1];
        for (int i = 1; i <= n; i++) {
            pn[i] = sc.nextInt();
        }

        int sw = 0;
        for (int i = 1; i <= n; i++) {
            if (pn[i] == i) {
                if (i != n) {
                    int t = pn[i];
                    pn[i] = pn[i+1];
                    pn[i+1] = t;
                }
                sw += 1;
            }
        }

        System.out.println(sw);
    }

}

Measured memory_bytes: 50932
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <algorithm>

using namespace std;

void print(const vector<int> &data) {
	if (data.empty()) return;
	for (int i = 0; i < data.size(); ++i) {
		cout << data[i];
		if (i != data.size() - 1) cout << " ";
		else cout << endl;
	}
}


void insSort(vector<int> &data){
	int n = data.size();
	for (int i = 0; i < n; ++i){
		int tmp = data[i];
		int j = i - 1;
		while ( j >= 0 && (data[j] > tmp)){
			data[j + 1] = data[j];
			--j;
		}
		data[j + 1] = tmp;
		print(data);
	}
}


int main(){
	int n; cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) cin >> v[i];
	insSort(v);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pi;

vector<pi> AdjList[100005];
int colour[100005], visit[100005];

void dfs(int x){
	visit[x] = 1;
	for (auto it : AdjList[x]){
		if (visit[it.first]) continue;
		if (!it.second){
			colour[it.first] = colour[x];
		}
		else{
			colour[it.first] = 1 - colour[x];
		}
		dfs(it.first);
	}
}

ll N, M, Q, A, B, C;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i < N; ++i){
		cin >> A >> B >> C;
		AdjList[A].push_back(pi(B,C%2));
		AdjList[B].push_back(pi(A,C%2));
	}
	for (int i = 1; i <= N; ++i){
		if (!visit[i]) dfs(i);
	}
	for (int i = 1; i <= N; ++i){
		cout << colour[i] << '\n';
	}
}

Measured memory_bytes: 8704
N = int(input())
A = list(map(int,input().split()))
S = sum(A)
M = (S+1)//2

dp = 1
for a in A:
    dp |= (dp<<a)
ans = M
while 1:
    if dp&(1<<ans):
        print(ans)
        exit()
    ans += 1

Measured memory_bytes: 5460