akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <vector>
#include <map>

using namespace std;

#define cn cout << '\n'
#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define ii pair < int, int >
#define iii pair < int, ii >
#define INF 987654321
#define LINF 987654321987654321

ll bin() {

    return INF;
}

int main() {
    cio;
    ll H;
    cin >> H;
    ll l = 0;
    ll pw = 1;
    while (H >= 1) {
        H /= 2;
        l += pw;
        pw *= 2;
    }
    cout << l;
    cn;
}


Measured memory_bytes: 3148
#include <iostream>
using namespace std;
int main(void){
    
    int N;
    string S;
    cin >> N >> S;
    
    int ans = 0;
    
    for(int i = 0; i < N; i++){
        if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C'){
            ans++;
            i += 2;
            continue;
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

N, M, Q = parseMap(split(readline()))

A = zeros(Int, Q)
B = zeros(Int, Q)
C = zeros(Int, Q)
D = zeros(Int, Q)

for i in 1:Q
    A[i], B[i], C[i], D[i] = parseMap(split(readline()))
end



function dfs(v, result)
    if length(result) == N
        score = 0
        for i in 1:Q
            a, b, c, d = A[i], B[i], C[i], D[i]
            if result[b] - result[a] == c
                score += d
            end
        end
        return score
    end         

    ans = -1
    for next_v in v:M
        push!(result, v) 
        ans = max(dfs(next_v, result), ans)
        pop!(result)
    end
    return ans
end

function main()
    max_score = -1
    for i in 1:M
        score = dfs(i, [])
        if score > max_score
           max_score = score
        end
    end

println(max_score)
end

main()  

Measured memory_bytes: 206232
#include<bits/stdc++.h>
#define pie 3.141592653589
using namespace std;

int main()
{
double a,b,x,ans=0;scanf("%lf %lf %lf",&a,&b,&x);
double h=x/(a*a);double w=x/a*2/b;
if(b-h<=b/2){ans=asin((b-h)*2/pow(a*a+(b-h)*(b-h)*4,0.5));}
else ans=asin(b/pow(w*w+b*b,0.5));
printf("%f\n",ans/pie*180);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#include<regex>
#include<ctype.h>
using namespace std;

int main(void) {
	int h, w;
	char a[100][100];
	int ck_h[100] = {}, ck_w[100] = {};
	cin >> h >> w;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
			if (a[i][j] == '#') {
				ck_h[i] = 1;
				ck_w[j] = 1;
			}
		}
	}

	for (int i = 0; i < h; i++) {
		int ln = 0;
		for (int j = 0; j < w; j++) {	
			if (ck_h[i] != 0 && ck_w[j] != 0) {
				cout << a[i][j] << flush;
				ln = 1;
			}
		}
		if (ln == 1) cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String[] line;
      MyList list = new MyList();

      for(int i=0; i<n; i++) {
        line = br.readLine().split(" ");
        switch( line[0] ) {
          case "insert" :
            list.insertFirst( Integer.parseInt(line[1]) );
            break;
          case "deleteFirst" :
            list.deleteFirst();
            break;
          case "deleteLast" :
            list.deleteLast();
            break;
          case "delete" :
            list.delete( Integer.parseInt(line[1]) );
            break;
          default :
            System.out.println("n:" + i + " is failed.");
        }
      }

      System.out.println ( list.getAllElements() );
    }
  }
}

class Node {
  Node next,prev;
  int key;

  public Node(int key) {
    this.key = key;
  }
}

class MyList {
  Node nil;
  Node current;
  int size;

  public MyList() {
    nil = new Node(0);
    nil.next = nil.prev = nil;
    size = 0;
  }

  public String getAllElements() {
    StringBuilder buf = new StringBuilder(size*3);

    if(size > 0){
      current = nil.next;
      for(int i=0; i<size; i++){
        buf.append(current.key).append(" ");
        current = current.next;
      }
    }
    buf.setLength(buf.length()-1);

    return buf.toString();
  }
  public void insertFirst(int x) {
    if(size == 0) {
      current = new Node(x);
      nil.next = current;
      nil.prev = current;
      current.prev = nil;
      current.next = nil;
      size++;
    }
    else {
      Node add = new Node(x);
      
      current.prev.next = add;
      add.prev = current.prev;

      add.next = current;
      current.prev = add;

      current = add;
      size++;
    }
  }
  public void deleteFirst() {
    nil.next = current.next;
    current.next.prev = current.prev;

    current = current.next;
    size--;
  }
  public void deleteLast() {
    current = nil.prev;

    nil.prev = current.prev;
    current.prev.next = current.next;

    current = nil.next;
    size--;
  }
  public void delete(int x) {
    Node target = findFirst(x);

    if(target == nil) current = current.next;
    else {
      current.prev.next = target.next;
      current.next.prev = target.prev;
      current = nil.next;
      size--;
    }
  }
  private Node findFirst(int x) {
    while(current != nil) {
      if(current.key == x) break;
      current = current.next;
    }

    return current;
  }
}


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

int main(){
  int X,Y;
  cin >> X >> Y;

  int ans=0;
  vector<int> a={0,300000,200000,100000};
  if(X<=3)  ans+=a.at(X);
  if(Y<=3)  ans+=a.at(Y);
  if(X==1 && Y==1)  ans+=400000;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
int n;
vector<int> arr,v;
int nxt[200005];
int last[200005];
int memo[200005];
int MOD=1000000007;
int main(){
    scanf("%d",&n);
    int t;
    for (int x=0;x<n;x++){
        scanf("%d",&t);
        arr.push_back(t);
    }
    v.push_back(arr[0]);
    for (int x=1;x<n;x++){
        if (v.back()!=arr[x]) v.push_back(arr[x]);
    }

    n=v.size();
    memset(nxt,-1,sizeof(nxt));
    memset(last,-1,sizeof(last));

    for (int x=0;x<n;x++){
        if (last[v[x]]!=-1) nxt[last[v[x]]]=x;
        last[v[x]]=x;
    }

    //for (int x=0;x<n;x++) printf("%d ",nxt[x]);

    memo[0]=1;
    for (int x=0;x<n;x++){
        if (nxt[x]!=-1) memo[nxt[x]]=memo[x];
        memo[x+1]=(memo[x+1]+memo[x])%MOD;
    }

    printf("%d\n",memo[n-1]);
}


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

long long N, A, B;

long long sovle() {
    cin >> N >> A >> B;
    if (A > B) return 0;
    if (A == B) return 1;
    if ((A != B) && N == 1) return 0;
    if (N == 2) return 1;
    return (N - 2) * (B - A) + 1;
}

int main() {
    cout << sovle() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, d;
  cin >> n;
  
  vector<int> diam(n);
  for(int i = 0; i < n; i++){
    cin >> d;
    diam.at(i) = d;
  }
  
  sort(diam.begin(), diam.end());
  
  int count = 1;
  for(int j = 0; j < n - 1; j++){
    if(diam.at(j) != diam.at(j + 1)) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);

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

    vl a(n), b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }
    sort(all(a));
    sort(all(b));

    if(n%2 == 1) {
        out(b[n/2] - a[n/2] + 1);
    }
    else {
        out(b[n/2] + b[n/2 - 1] - (a[n/2] + a[n/2 - 1]) + 1);
    }

    re0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(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);}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    int n;cin>>n;
    vector<string>s(n);
    vector<pair<int,char>> a;
    int l=51;
    string t;
    rep(i,n){
        cin>>s[i];
        int x=s[i].size();
        if(l>x){
            l=x;
            t=s[i];
        }
        sort(s[i].begin(),s[i].end());
    }
    sort(all(t));
    char c=t[0];
    int cnt=1;
    for(int i=1;i<l;++i){
        if(c==t[i]){
            cnt++;
        }
        else{
            a.PB(MP(cnt,c));
            cnt=1;
            c=t[i];
        }
    }
    a.PB(MP(cnt,c));
    int m=a.size();
    rep(i,n){
        int x=s[i].size();
        rep(j,m){
            int co=0;
            rep(k,x){
                if(s[i][k]==a[j].S){
                    co++;
                }
            }
            if(co<a[j].F){
                a[j].F=co;
            }
        }
    }
    string ans="";
    rep(i,m){
        rep(j,a[i].F){
            ans.PB(a[i].S);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
// E, N, W, S
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
string ENWS = "ENWS";

int main(){
  int W, H;
  while(cin >> W >> H && W){
    vector<string> grid(H);
    REP(y, H) cin >> grid[y];
    REP(y, H) REP(x, W) if(grid[y][x] == 'X') grid[y][x] = '%';
    int rest = 0;
    REP(y, H) REP(x, W) if(isupper(grid[y][x])) rest++;
    int ans = INF;
    REP(time, 181){
      if(rest == 0) {
        ans = time;
        break;
      }
      REP(y, H) REP(x, W){
        REP(i, 4) if(grid[y][x] == ENWS[i]){
          REP(r, 4){
            int rr = (i + r + 3) % 4;
            int nx = x + dx[rr];
            int ny = y + dy[rr];
            if(valid(nx, ny, W, H) && (grid[ny][nx] == '.' || grid[ny][nx] == '%')){
              grid[y][x] = ENWS[rr];
              goto LOOPOUT;
            }
          }
        }
        LOOPOUT:;
      }
      vector<string> next = grid;
      REP(y, H) REP(x, W) if(grid[y][x] == '.' || grid[y][x] == '%') REP(r, 4){
        int nx = x + dx[r];
        int ny = y + dy[r];
        if(valid(nx, ny, W, H) && grid[ny][nx] == ENWS[(r + 2) % 4]){
          next[ny][nx] = '.';
          if(grid[y][x] == '.') next[y][x] = grid[ny][nx];
          else rest--;

          break;
        }
      }
      grid = next;
    }
    if(ans == INF) cout << "NA" << endl;
    else cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include<stdio.h>

int main(void){

	int n,i,maney=100000;

	scanf("%d",&n);

	for(i=0;i<n;i++){
		maney+=maney*0.05;
		if(maney%1000!=0){
			maney=maney-(maney%1000)+1000;
		}

	}

	printf("%d\n",maney);
	scanf("%d",&i);
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

int c[500],s[500],f[500];
int main() {
    int n;
    cin >> n;
    for (int i=0;i<n-1;i++) {
        cin >> c[i] >> s[i] >> f[i];
    }
    for (int i=0;i<n-1;i++) {
        int t = 0;
        for (int j=i;j<n-1;j++) {
            int x = max(t,s[j]);
            int y = (((x-1)/f[j])+1)*f[j];
            t = y + c[j];
        }
        cout << t << endl;
    }
    cout << 0 << endl;
    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 H = 0;
		int W = 0;
		String sh = "#";
		String dot = ".";
		while(true) {
			H = sc.nextInt();
			W = sc.nextInt();
			if(H == 0 && W ==0)break;
			
			for(int i = 0; i < H; i++) {
				if(i%2==0) {
					for(int j = 0; j < W; j++) {
						if(j%2==0) {
							System.out.print(sh);
						} else {
							System.out.print(dot);
						}
					}
					System.out.println("");
				} else {
					for(int j = 0; j < W; j++) {
						if(j%2==0) {
							System.out.print(dot);
						} else {
							System.out.print(sh);
						}
					}
					System.out.println("");
				}
			}
			System.out.println("");
		}
		sc.close();
	}
}



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

int main()
{
	int n,m;
	cin >> n;
	for (int q = 1; q <= n; q++)
	{
		int sum = 0;
		for (m = 3;; m++)
		{
			if (m * m + m * (m / 3.0) > 2 * q) break;
			for (int i = 1;; i++)
			{
				if (i > m - 2) break;
				for (int j = 1;; j++)
				{
					int k = m - i - j;
					if (k < 1) break;
					int ans = m * m + i * i + j * j + k * k;
					//if ( ans> 2 * n) break;
					if (ans == 2 * q) sum++;
				}
			}
		}
		cout << sum << endl;
	}
	


	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int k;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%k;
    }
    return n*rep_jijo(n,x-1)%k;
}

int main(){
    ll sum=0;
    cin >> k;
    vector<ll>num(1001000,0);
    rep(i,1001000){
        num[i] = 7*rep_jijo(10,i);
    }
    rep(i,1001000){
        sum+=num[i];
        sum %= k;
        if(sum%k==0){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 11156
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  long long sum = 0;
  for (int i = 0; i <= N; i++){
    if (((i % 3) != 0) && ((i % 5) != 0))
      sum += i;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;
using i64 = long long int;

int main() {
    i64 n;
    cin >> n;
    vector<i64> a(n);
    unordered_map<i64, i64> mp;
    for (i64 i = 0; i < n; ++i) {
        cin >> a[i];
        mp[a[i]]++;
    }
    i64 ans = 0;
    for (i64 i = 0; i < n; ++i) {
        if (mp[a[i]]) {
            if (mp[a[i]] % 2) {
                ++ans;
            }
            mp[a[i]] = 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5156
#include<bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    int ans=0,anss=0;
    REP(i,N-1)ans+=(i+1);
    REP(i,M-1)anss+=(i+1);
    cout<<ans+anss<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define nil -1
#define mp make_pair
typedef long long ll;
using namespace std;

template <typename T>
inline void output(T a, int p) {
    if(p){
        cout << fixed << setprecision(p)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}
// end of template

class topological_sort{
public:
    int V;
    vector<int> vis, indeg, sorted;
    vector<vector<int>> edge;
    topological_sort(int v){
        V = v;
        vis.resize(v, 0);
        indeg.resize(v, 0);
        edge.resize(v);
    }
    
    void add(int from, int to){
        edge[from].push_back(to);
        indeg[to]++;
    }
    
    void bfs(int s){
        queue<int> q;
        q.push(s);
        vis[s] = 1;
        while (!q.empty()) {
            int f = q.front();
            q.pop();
            sorted.push_back(f);
            rep(i, edge[f].size()){
                int e = edge[f][i];
                indeg[e]--;
                if (indeg[e] == 0 && !vis[e]) {
                    vis[e] = 1;
                    q.push(e);
                }
            }
        }
    }
    
    void sort(){
        rep(i, V){
            if (indeg[i] == 0 && !vis[i]) {
                bfs(i);
            }
        }
    }
    
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int V, E;
    cin >> V >> E;
    topological_sort ts(V);
    rep(i, E){
        int s, t;
        cin >> s >> t;
        ts.add(s, t);
    }
    ts.sort();
    
    rep(i, ts.sorted.size()){
        cout << ts.sorted[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3668
n, m = map(int, input().split())
mod = 10**9+7

if abs(n - m) >= 2:
   print(0)
   exit()

if n > m:
   n, m = m, n
ans = 1
for i in range(1, n+1):
   ans *= i
   ans %= mod

if n == m:
   print(2*pow(ans, 2, mod)%mod)
else:
   print(pow(ans, 2, mod)*m%mod)


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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    int ans = false;
    rep(i, 9) {
        rep(j, 9) {
            if ((i + 1) * (j + 1) == N) ans = true;
        }
    }

    if (ans) {
        puts("Yes");
    } else {
        puts("No");
    }
}

Measured memory_bytes: 256
#include <queue>
#include <cstdio>

using namespace std;

int main()
{
	char Query[7]; int Number;

	priority_queue<int> que;

	while (Query[2] != 'd')
	{
		scanf("%s", Query);

		if (Query[0] == 'i') { scanf("%d", &Number); que.push(Number); }
		if (Query[1] == 'x') { printf("%d\n", que.top()); que.pop(); }
	}

	return 0;
}

Measured memory_bytes: 6548
#include<cstdio>

int par[100500];

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

void unite(int x,int y) {
    x = find(x);
    y = find(y);
    par[x] = y;
}

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

int main(void) {
    int n,q;
    scanf("%d%d",&n,&q);
    init();
    for(int i=0; i<q; i++) {
        int c,x,y;
        scanf("%d%d%d",&c,&x,&y);
        if(c)
            puts(find(x)==find(y) ? "1" : "0");
        else
            unite(x,y);
    }
    return 0;
}

Measured memory_bytes: 3196
program prob2
    implicit none
    integer :: N, M
    integer, allocatable, dimension(:) :: T, P, X
    integer :: ans, i, j
    read(*,*) N
    allocate(T(N))
    read(*,*) T
    read(*,*) M
    allocate(P(M))
    allocate(X(M))
    do i = 1, M
        read(*,*) P(i), X(i)
    end do
    do i = 1, M
        ans = 0
        do j = 1, N
            if(j == P(i)) then
                ans = ans + X(i)
            else
                ans = ans + T(j)
            end if
        end do
        write(*,*) ans
    end do

    deallocate(T, P, X)


    stop
contains
end program prob2

Measured memory_bytes: 2836
N, T = map(int, input().split())
A = list(map(int, input().split()))

B = []
Amin = A[0]

for i in range(1, N):
  if A[i] < Amin:
    Amin = A[i]
  else:
    B.append(A[i] - Amin)

result = B.count(max(B))
print(result)

Measured memory_bytes: 14252
N, M, C = map(int, input().split())
*L, = map(int, input().split())
B = []
for i in range(N):
    c, w = map(int, input().split())
    B.append((w, c))
B.sort(reverse=1)

ans = 0
for w, c in B:
    if L[c-1] > 0:
        ans += w
        M -= 1
        if M == 0:
            break
        L[c-1] -= 1
print(ans)



Measured memory_bytes: 21852
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

long pow(long x, long n, long M) {
    if (n == 0) return 1;
    if (n & 1) return x * pow(x, n - 1, M) % M;
    auto y = pow(x, n / 2, M);
    return y * y % M;
}

void main() {
    int N, M; scanf("%d %d\n", &N, &M);
    auto s = readln.chomp;

    long[] MOD = [999999883, 1000000093, 1000000097];
    long B = 100000007;

    auto H = new long[3];
    auto T = new long[][](3, N + 1);
    foreach (h; 0 .. 3) {
        foreach (i; 0 .. N) {
            T[h][i + 1] = (T[h][i] * B + cast(long)(s[i])) % MOD[h];
        }
    }

    long[3] hash(size_t lb, size_t ub) {
        long[3] ret;
        foreach (i; 0 .. 3) {
            ret[i] = (MOD[i] + T[i][ub] - (B.pow(ub - lb, MOD[i]) * T[i][lb] % MOD[i])) % MOD[i];
        }
        return ret;
    }

    int L, R;
    bool[long[3]] set;
    foreach (m; 0 .. M) {
        auto q = readln.chomp;
        if (q[0] == 'L') {
            if (q[1] == '+') {
                L++;
            } else {
                L--;
            }
        } else { assert(q[0] == 'R');
            if (q[1] == '+') {
                R++;
            } else {
                R--;
            }
        }
        //writeln([L, R], hash(L, R + 1));
        set[hash(L, R + 1)] = true;
    }
    writeln(set.length);
}

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

int main() {
  string N;
  cin >> N;
  bool good = false;
  for (int i = 0; i < 2; i++) {
    if (N.at(i) == N.at(i+1) && N.at(i) == N.at(i+2)) {
      good = true;
    }
  }
  if (good) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*
	Failure is not the reason for you to stop trying 
	   it is actually a remainder that you should 
			KEEP GOING 
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define E endl
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
pair < int,int > getFirstDigit(int n){
	int f = 0;
	int a = n%10;
	while(n){
		f = n;
		n/=10;
	}
	return {a,f};
}
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n;
		cin >> n ;
		map<pair<int,int>,int>mp;
		for(int i =1;i<=n;i++){
			pair < int,int > p = getFirstDigit(i);
			// trace(p.fi,p.se);
			mp[p]++;	
		}
		int ans =0;
		for(int i =1;i<=n;i++){
			pair<int,int> p = getFirstDigit(i);
			int x = p.fi;
			int y = p.se;
			ans+=mp[{y,x}];
		}
		cout <<ans<<endl;
	}
	
	cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

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

#define lli long long int
#define endl "\n"

int ans(int n, int k, vector<int> &h, vector<int>&dp, int i){
	if(i==n-1)
		return 0;

	else if(i >=n)
		100000;

	if(dp[i] != -1)
		return dp[i];

	else{

		int answer = INT_MAX;
		for(int j = 1; j <= k; j++){
			if(i+j >= n)
				break;

			else{
				answer = min(answer, abs(h[i] - h[i+j]) + ans(n, k, h, dp, i+j));
			}
		}
		dp[i] = answer;
	}
	return dp[i];
}


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

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

	vector<int>dp(n, -1);

	int a = ans(n, k, h, dp, 0);

	cout << a << endl;
}

Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <ios>
#include <iomanip>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;

void solve() {
    int n,q;
    cin >> n;
    vi A(n);
    rep(i,n){
        cin >> A[i];
    }
    cin >> q;
    vi m(q);
    rep(i,q){
        cin >> m[i];
    }
    // DEBUG_VEC(A);
    // DEBUG_VEC(m);
    set<int> total;
    rep(bit,pow(2,n)){
        int tot = 0;
        rep(j,n){
            if(bit>>j&1) tot += A[j];
        }
        total.insert(tot);
    }
    for(auto mi:m){
        bool ok = total.find(mi) != total.end();
        print(ok?"yes":"no");
    }
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}


Measured memory_bytes: 3360
#include<cstdio>
#include<iostream>
#include<fstream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define Set(a) memset(a,0,sizeof(a))
#define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i)
#define openf(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define re register
#define ri re int
#define il inline
typedef long long ll;
typedef unsigned long long ull;
template<typename T> inline T rd(T& x)
{
	T f=1;x=0;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(T)(c-'0');
	x*=f;
	return x;
}
ll rd(){ll x;rd(x);return x;}
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
const int inf=1<<30;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main()
{
	int n;cin>>n;ll ans=0;
	F(i,1,n) F(j,1,n) F(k,1,n) ans+=gcd(gcd(i,j),k);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
#pragma GCC optimize(2)
#include<iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <cstring>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <map>
#include <unordered_map>
#include <vector> 
#include <bitset>
#include <cctype>
#include <set>
#include <stack>
#include <queue>
#include <fstream>
#include <numeric>
#include <random>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAXN = 5005;
const int MAXM = 20500;
const ll MOD = 1e9+7;

#define MP make_pair
#define INF 0x3f3f3f3f
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template <typename T> inline T min(T a, T b, T c,T d) { return min(min(a, b), min(c,d)); }
template <typename T, typename T1> inline T qpower(T x, T p, T1 mod) { T re = 1; x %= mod; while (p) { if (p & 1)re = (re * x) % mod; x = (x * x) % mod; p >>= 1; }return re; }
#define mst(X,Y) memset(X,Y,sizeof(X)) 
#define rep(i, a, n) for (int i=(a); i<=(n); i++)
#define per(i, a, n) for (int i=(a); i>=(n); i--)
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) { cerr << " " << to_string(H);    debug_out(T...);}


// int solve(int l,int r)
// {
		
// }
inline int check(string a,string b)
{
	int len = a.size();
	int cnt = 0;
	rep (i,0,len-1)
	{
		if (a[i] != b[i])
			cnt++;
	}
	return cnt;
}

int main()
{//closeSync;
#ifdef DEBUG
	//freopen("C:/Users/86159/Desktop/input.txt", "r", stdin);
	//freopen("C:/Users/86159/Desktop/output.txt", "w", stdout);
#endif
	//clock_t c1 = clock();

	string s,t;
	cin>>s>>t;
	int lent = t.size();
	int lens = s.size();
	int ans = INF;
	rep (i,0,lens - lent)
	{	
		ans = min(ans,check(t,s.substr(i,lent)));
	}
	cout<<ans<<endl;




	//cerr << "Time:" << clock() - c1 << "ms" <<endl;
    return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
  int a, b, c;
  while(cin>>a>>b>>c){
        if(a==b&&b==c)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
  }
  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull uint64_t
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mx5 100005
#define mx6 1000005
#define mod 1000000007
#define nfs ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main() {
    nfs
    int n, w;
    ll dp[mx5] = {};
    cin >> n >> w;
    for (int i = 0, wi, vi; i < n; i++) {
        cin >> wi >> vi;
        for (int j = w; j >= wi; j--) {
            dp[j] = max(dp[j], dp[j - wi] + vi);
        }
    }
    cout << dp[w];
}

Measured memory_bytes: 4456
N,M = list(map(int,input().split()))
ks =  [list(map(int,input().split())) for _ in range(M)]
p = list(map(int,input().split()))

Nlen = 2**N
ans = 0

for i in range(Nlen):
    total = 0
    for j in range(M):
        count = 0
        for k in range(1,ks[j][0]+1): 
            if i & 2**(ks[j][k]-1) == 2**(ks[j][k]-1):
                count += 1
        if count % 2 == p[j]:
            total += 1
    if total == M:
        ans += 1

print(ans)

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

int main(){
int n,i,sum=0;
cin>>n;
int a[n];

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

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

cout<<sum;





return 0;
}


Measured memory_bytes: 256
while True:
    x=int(input())
    y=1000-x
    a=y//500
    b=(y-500*a)//100
    c=(y-500*a-100*b)//50
    d=(y-500*a-100*b-50*c)//10
    e=(y-500*a-100*b-50*c-10*d)//5
    f=(y-500*a-100*b-50*c-10*d-5*e)//1
    n=a+b+c+d+e+f
    if x==0:
        break
    
    print(n)


Measured memory_bytes: 5592
#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 main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    bool a = false;
    bool b = false;
    string S;
    cin >> S;
    if(S.substr(0, 2) <= "12" && S.substr(0, 2) >= "01") a = true;
    if(S.substr(2, 2) <= "12" && S.substr(2, 2) >= "01") b = true;
    if(a && b) cout << "AMBIGUOUS" << endl;
    if(!a && b) cout << "YYMM" << endl;
    if(a && !b) cout << "MMYY" << endl;
    if(!a && !b) cout << "NA" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<ll>
#define vvint vector<vint>
#define P pair<ll,ll>
#define INT_MAX 2147483647
#define MOD 998244353
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;

#define MAX 1000000000000

int main(void) {
	int x, n, t; cin >> x >>n >> t;
	cout << (x + n - 1) / n *t << endl;

	return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll prime(ll x) {
	ll i;
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i*i <= x; i += 2) {
		if (x%i == 0) return 0;
	}
	return 1;
}
int main() {
	int Q;
	cin >> Q;
	ll A[100010], B[100010];
	for (ll i = 3; i <= 100000; i += 2) {
		if (prime(i) && prime((i + 1) / 2))
			A[i] = 1;
		else
			A[i] = 0;
	}
	for (int i = 3; i <= 100000; i += 2) {
		B[i] = B[i - 2] + A[i];
	}
	for (int i = 0; i<Q; i++) {
		int l, r;
		cin >> l >> r;
		cout << B[r] - B[l - 2] << endl;
	}
}









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

#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;
using ll = long long;

int main(){
	//fastIO;
	int y,m,d;
	scanf("%d/%d/%d",&y,&m,&d);
	if(y > 2019 || m > 4)
		cout << "TBD\n";
	else
		cout << "Heisei\n";
	return 0;
}

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

int main(){
  int N;
  int happy[3][100001];
  int sumhappy[3][2];

  cin >> N;

  for(int j=0; j < 3; j++){
    sumhappy[j][0] = 0;
  }

  for(int i=1; i <= N; i++){
    for(int j=0; j < 3; j++){
      cin >> happy[j][i];
    }
  }
  
  for(int i=1; i <= N; i++){
    for(int j=0; j < 3; j++){
      sumhappy[j][1] =
        max(sumhappy[(j+1)%3][0], sumhappy[(j+2)%3][0]) + happy[j][i];
    }
    for(int j=0; j < 3; j++) sumhappy[j][0] = sumhappy[j][1];
  }
  cout << max(sumhappy[0][1], max(sumhappy[1][1], sumhappy[2][1]));
}


Measured memory_bytes: 1408
Option Strict On

Module Module1
    Const n As Int32 = 3
    Dim X, A, B, tmp(n - 1), ans As Long

    Sub Main()
        For i As Int32 = 0 To n - 1
            tmp(i) = CLng(Console.ReadLine())
        Next

        'let'
        X = tmp(0) : A = tmp(1) : B = tmp(2)

        ans = X
        ans -= A
        ans = ans Mod B

        Console.WriteLine(ans)

    End Sub

End Module

Measured memory_bytes: 13268
#Python Competetive Programming Template

from sys import stdin, stdout
from math import *

testing = True

def tp(s="\n"):
	if testing:
		stdout.write(s)

def main():
	n = int(stdin.readline())
	occurs = False
	doubles = 0
	for i in range(n):
		d1, d2 = [int(i) for i in stdin.readline().split()]
		if d1 == d2:
			doubles += 1
			if doubles == 3:
				occurs = True
				break
		else:
			doubles = 0
	if occurs:
		stdout.write('Yes\n')
	else:
		stdout.write("No\n")
        
main()

Measured memory_bytes: 9188
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string.h>
#include <math.h>
typedef long long ll;
#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define MIN(x, y)	(((x) < (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define REPI(x,y)	for (int i=(x);i<(y);i++)
#define REPJ(x,y)	for (int j=(x);j<(y);j++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;
typedef pair<int, int> Point;
typedef vector<vector<Point>> Graph;

int i,j,N,Z,W,ans;
int a[2005];
int main() {
	cin >> N >> Z >> W;
	
	REPI(0, N) cin >> a[i];
	if ( N != 1)
		cout << MAX(ABS(a[N-1] - a[N-2]),ABS(a[N-1] - W));
	else cout << ABS(a[0] - W);
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[100005]={0};
int n;
int main(){
    cin>>n;
    for(int i=0;i<n;++i)  cin>>a[i];
    int ans=1;
    bool x1= false, x2 = false;
    for(int i=1;i<n;i++){
        if(x1==false&&x2==false)
		{
            if(a[i]<a[i-1])       x2=true;
            else if(a[i]>a[i-1])  x1=true;
        }
		else if(x1==true)
		{
            if(a[i]<a[i-1])
			{
                ans++;
                x1=false;
            }
        }
		else if(x2==true)
		{
            if(a[i]>a[i-1])
			{
                ans++;
                x2=false;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<ll> a(3*n);
    for (int i=0; i<3*n; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    int cnt = 0;
    auto now = a.end()-2;
    while (cnt < n) {
        cnt++;
        ans += *now;
        now -= 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int x[100];
  x[1] = 1;
  x[2] = 3;
  x[3] = 1;
  x[4] = 2;
  x[5] = 1;
  x[6] = 2;
  x[7] = 1;
  x[8] = 1;
  x[9] = 2;
  x[10] = 1;
  x[11] = 2;
  x[12] = 1;
  int a, b;
  cin >> a >> b;
  if (x[a] == x[b]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
    int A,B;
 
    cin>>A>>B;
    int y=A*B;
    int z=A-B;
    int e=A+B;
    int max=-100000;
    if(z > max)
        max=z;
    if(y>max)
        max=y;
    if (e>max)
        max=e;
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
bulbs = []
for _ in range(m):
    b = tuple(map(int, input().split()))
    bulbs.append(b[1:])

p = list(map(int, input().split()))

ans = 0

for switch in range(2**n):
    check = [0] * m
    for i, bulb in enumerate(bulbs):
        cnt = 0
        for b in bulb:
            if switch >> (b-1) & 1:
                cnt += 1
            
        if cnt % 2 == p[i]:
            check[i] = True
        else:
            check[i] = False
    
    if  all(check):
        ans += 1

print(ans)

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

int n, m;
int table[2000];
int ans;

int main(){
	scanf("%d%d",&n,&m);
	ans = n+1;
	rep(i,m){	
		int c, d;
		scanf("%d%d",&c,&d);
		table[c]++;
		table[d]--;
	}
	for(int i = 1; i < 2000; i++) table[i] += table[i-1];
	for(int i = 0; i < 2000; i++) if(table[i]) ans += 2;
	cout << ans << endl;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int V, E;
    cin >> V >> E;
    int es[V][V];
    fill(es[0], es[V], inf);
    rep(i, E){
        int u, v, c; cin >> u >> v >> c;
        es[u][v] = c;
    }
    int dp[1<<V][V];
    fill(dp[0], dp[1<<V], inf);
    dp[1][0] = 0;
    rep(i, 1<<V){
        rep(j, V){
            rep(k, V){
                if(i&(1<<k)) continue;
                chmin(dp[i|(1<<k)][k], dp[i][j]+es[j][k]);
            }
        }
    }
    int ans = inf;
    rep(i, V) chmin(ans, dp[(1<<V)-1][i]+es[i][0]);
    cout << (ans == inf? -1 : ans) << endl;
}


Measured memory_bytes: 5016
use proconio::*;
use std::cmp::*;

#[derive(Clone, Copy)]
struct Top2<T> {
    val: [T; 2],
}

impl<T: Ord + Copy> Top2<T> {
    fn new(a: T, b: T) -> Self {
        assert!(a > b);
        Top2 {
            val: [a, b],
        }
    }
    fn merge(self, rhs: Self) -> Self {
        match self.val[0].cmp(&rhs.val[0]) {
            Ordering::Equal => {
                Top2::new(self.val[0], max(self.val[1], rhs.val[1]))
            },
            Ordering::Less => {
                Top2::new(rhs.val[0], max(self.val[0], rhs.val[1]))
            },
            Ordering::Greater => {
                Top2::new(self.val[0], max(self.val[1], rhs.val[0]))
            },
        }
    }
}

#[fastout]
fn run() {
    proconio::input! {
        n: usize,
        a: [u32; 1 << n],
    }
    let mut dp = a.iter().enumerate().map(|a| Top2::new((*a.1, a.0), (0, 0))).collect::<Vec<_>>();
    for i in 0..n {
        for j in 1..(1 << n) {
            if j >> i & 1 == 1 {
                dp[j] = dp[j].merge(dp[j ^ (1 << i)]);
            }
        }
    }
    let mut ans = 0;
    for Top2{val} in dp.into_iter().skip(1) {
        ans = max(ans, val[0].0 + val[1].0);
        println!("{}", ans);
    }
}

fn main() {
    run();
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

struct point {
  int x;
  int y;
  int h;
};

// ====================================================================

int main() {
  int n;
  cin >> n;
  vector<point> v(n);
  int high = -INF;
  for (int i = 0; i < n; i++) {
    cin >> v[i].x >> v[i].y >> v[i].h;
    high = max(high, v[i].h);
  }

  point ans = {0, 0, 0};
  for (int i = 0; i <= 100; i++) {    // xpos
    for (int j = 0; j <= 100; j++) {  // ypos
      int k = high + 250;             // 一番低い高さの候補が本当の高さの候補（？）
      for (int l = 0; l < n; l++) {
        k = min(k, v[l].h + abs(i - v[l].x) + abs(j - v[l].y));
      }
      bool can = true;
      for (int l = 0; l < n; l++) {
        if (max(k - abs(i - v[l].x) - abs(j - v[l].y), 0) != v[l].h) can = false;
      }
      if (can) {
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
}


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

using namespace std;

int main(void){
    int N, W;
    cin >> N >> W;
    vector<int> v(N), w(N);
    for (int i = 0; i < N; i++) cin >> v[i] >> w[i];
    
    vector<vector<int> > dp(N+1, vector<int>(W+1, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < W+1; j++) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            if (j && !dp[i][j]) continue;
            if (j + w[i] > W) continue;
            dp[i+1][j + w[i]] = max(dp[i+1][j + w[i]], dp[i][j] + v[i]);
        }
    }
    cout << *max_element(dp[N].begin(), dp[N].end()) << endl;
}

Measured memory_bytes: 6752
#include<iostream>
#include<cstring>
#include<cstdio>
#define max_n 100001
using namespace std;
struct edge{
	int u,v,w,next;
}e[max_n*2];
int g[max_n];
int n;
bool vis[max_n];
int dp[max_n][3];
int dfs(int u){
	vis[u]=true;
	for(int i=g[u];i>0;i=e[i].next){
		int v=e[i].v,w=e[i].w;
		if(!vis[v]){
			int now=dfs(v)+w;
			if(now>dp[u][1]){
				dp[u][2]=dp[u][1];
				dp[u][1]=now;
			}else{
				if(now>dp[u][2])
					dp[u][2]=now;
			}
		}
	}
	
	return dp[u][1];
}
int main(){
	scanf("%d",&n);
	int x,y,w;
	for(int i=1;i<n;i++){
		scanf("%d%d%d",&x,&y,&w);
		e[i*2-1]=(edge){x,y,w,g[x]}; g[x]=i*2-1;
		e[i*2]=(edge){y,x,w,g[y]}; g[y]=i*2;
	}
	memset(vis,0,sizeof(vis));
	dfs(1);
	int ans=0;
	for(int i=0;i<n;i++){
		ans=max(ans,dp[i][1]+dp[i][2]);
	}
	printf("%d\n",ans);
	return 0;
}	

Measured memory_bytes: 12664
/**
 * author: Behradm
 * Created: 2020.08.22 16:29:33
 * In The Name of God
**/
#include <bits/stdc++.h>

using namespace std;

int main() {   
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x, t;
  cin >> n >> x >> t;
  cout << (int) ceil(n / (double) x) * t << '\n';
  return 0;
}


Measured memory_bytes: 3608
{-# OPTIONS_GHC -O #-}
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Control.Monad.ST
import Data.List
import Data.Array.Unboxed
import Data.Array.ST
import Control.Monad.Trans.State.Strict
import Data.Char (isSpace)
import Data.Maybe (fromJust)
import qualified Data.ByteString.Lazy.Char8 as B

type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT (B.readInt . B.dropWhile isSpace)

parseInt2 :: Parser (Int,Int)
parseInt2 = liftM2 (,) parseInt parseInt

parse :: Parser (Int, [(Int,Int)], [(Int,Int)])
parse = do
  n<-parseInt
  m<-parseInt
  q<-parseInt
  lrs<-replicateM m parseInt2
  pqs<-replicateM q parseInt2
  return (n,lrs,pqs)

main=do
  (n,lrs,pqs) <- fromJust.evalStateT parse <$> B.getContents
  let !ar = f n lrs
  putStr.unlines $ map (\(p,q)->show $ ar ! (p,q)) pqs
--
f n lrs = runSTUArray $ do
  ar <- newArray ((1,1),(n+1,n)) 0 :: ST s (STUArray s (Int,Int) Int)
  forM_ lrs $ \(l,r) -> do
    writeArray ar (1,r) =<< succ <$> readArray ar (1,r)
    writeArray ar (l+1,r) =<< pred <$> readArray ar (l+1,r)
  forM_ [(l,r)|l<-[2..n],r<-[1..n]] $ \(l,r) -> do
    writeArray ar (l,r) =<< (+) <$> readArray ar (l,r) <*> readArray ar (l-1,r)
  forM_ [(l,r)|l<-[1..n],r<-[2..n]] $ \(l,r) -> do
    writeArray ar (l,r) =<< (+) <$> readArray ar (l,r) <*> readArray ar (l,r-1)
  pure ar


Measured memory_bytes: 53756