akhauriyash/Code-Regression huggingface dataset:
#include <iostream>


using namespace std;


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



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

int main()
{
   int a,b;
   scanf("%d %d",&a,&b);
   int i,j=0,k[1000],f,y,s=0,x;
   for(i=a;i<=b;i++)
   {
       x=i;f=1;j=1;
       while(x)
       {
          k[j++]=x%10;
          x=x/10;
       }
       for(y=1;y<=j/2;y++)
       {
           if(k[y]!=k[j-y])
           {
               f=0;break;
           }
       }
       if(f)
        s++;
   }
   printf("%d\n",s);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] x = line.split(" ");
		int a = Integer.parseInt(x[0]);
		int b = Integer.parseInt(x[1]);
		int c = Integer.parseInt(x[2]);
		int count = 0;
		a -= 1;
		while (a  < b) {
			a++;

			if (c % a == 0) {
				count += 1;

			}

		}

		System.out.println(count);

	}

}



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

int n, m, q;
int ans = 0;
vector<int> a, b, c, d;

void dfs(vector<int> A) {
  if (A.size() == n+1) {
    int tmp = 0;
    for(int i = 0; i < q; ++i) {
      if (A[b[i]]-A[a[i]] == c[i]) tmp += d[i];
    }
    ans = max(ans, tmp);
    return;
  }
  A.push_back(A.back());
  while(A.back() <= m) {
    dfs(A);
    A.back()++;
  }
}

int main() {
  cin >> n >> m >> q;
  a.resize(q);
  b.resize(q);
  c.resize(q);
  d.resize(q);
  for (int i = 0; i < q; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(vector<int>(1,1));

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

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

int main(){

int k;
cin>>k;
int ec = 0;
int oc = 0;
for(int i = 1;i<=k;i++){
    if(i%2 == 0){
        ec++;
    }
    else{
        oc++;
    }
}

cout<<(ec*oc);
}


Measured memory_bytes: 3188
#include<map>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>

#define maxn 100001
#define int long long 
using namespace std;

int n,m,ans,num[maxn],sum[maxn];
map<int,int> cnt;

signed main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%lld",&num[i]);
	for(int i=1;i<=n;i++)
		sum[i]=sum[i-1]+num[i];
	cnt[0]=1;
	for(int i=1;i<=n;i++){
		int t=sum[i]%m;
		ans+=cnt[t];
		++cnt[t];
	}
	printf("%lld",ans);
	return 0;
}

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


def solve(N: int, S: str):
    w = [0] * N
    e = [0] * N
    wt = 0
    et = 0
    a = [0] * N
    for i in range(N):
        s = S[i]
        w[i] = wt
        if s == "W":
            wt += 1
        if s == "E":
            et += 1
        e[i] = et
    for i in range(N):
        a[i] = w[i] + et - e[i]
    print(min(a))




    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 81048
#include <iostream>
#include <cmath>
using namespace std;
const int N_MAX = pow(10, 5);
int main (void) {
    int N;
    int a[N_MAX + 1];
    int ans = 0;
    int b;

    cin >> N;
    for (int i = 1; i <= N; i++) cin >> a[i];

    b = 1;
    for (int i = 1; i <= N; i++) {
        if (b == 2) {
            cout << ans << endl;
            return 0;
        }
        b = a[b];
        ans++;
    }

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;
lint p=998244353;

int main(){
  lint A,B,C,D;
  cin>>A>>B>>C>>D;
  lint dp[C+1][D+1];
  REP(h,A)REP(w,D+1)dp[h][w]=0;
  REP(h,C+1)REP(w,B)dp[h][w]=0;
  FOR(h,A,C+1)FOR(w,B,D+1){
    if(h==A and w==B){
      dp[h][w]=1;
      continue;
    }
    dp[h][w]=dp[h-1][w]*w+dp[h][w-1]*h-dp[h-1][w-1]*(h-1)*(w-1);
    dp[h][w]%=p;
    if(dp[h][w]<0)dp[h][w]+=p;
  }
  cout<<dp[C][D]<<endl;
  return 0;
}


Measured memory_bytes: 73832
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

total=0
for i in range(N):
    if A[i]-B[i]>=0:
        total+=B[i]
    elif A[i]-B[i]<0:
        total+=A[i]
        if A[i+1]-B[i]+A[i]>=0:
            total+=B[i]-A[i]
            A[i+1]-=B[i]-A[i]
        else:
            total+=A[i+1]
            A[i+1]=0
print(total)


Measured memory_bytes: 81892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == 0) ans = 0;
    }
    if (ans != 0) {
        for (int i = 0; i < n; i++) {
            if (a[i] > (ll)1e18 / ans) {
                ans = -1;
                break;
            } else {
                ans *= a[i];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3948
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    if(n%2==0) {
        printf("%d\n", n);
    }
    else {
        printf("%d\n", n*2);
    }

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
typedef long long ll;
using namespace std;
#define REP(i,n) for(int i=0; i<n;i++)

int main(void)
{
    int n,x,m[101],min,sum;
    sum = 0;
    min = 100000;
    cin >> n >> x;
    REP(i,n)
    {
        cin >> m[i];
        sum += m[i];
        if(m[i] < min)
        {
            min = m[i];
        }
    }
    x = x - sum;
    x = n + x / min;
    
    cout << x << endl;
    
    return 0;
}

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

const ll MOD = 1e9+7;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  int x;
  cin >> x;
  
  int cmp = sqrt(x);
  
  while(true) {
    bool flag = true;
    for(int j = 2; j < cmp+1; ++j) {
      if(x % j == 0) {
        flag = false;
      }
    }
    if(flag) {
      cout << x << endl;
      return 0;
    }
    ++x;
  }
}

Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define ll long long

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int cnt = 0;
    for (int i = a; i <= b; i++) {
        if (c % i == 0) {
            cnt++;
        }
    }
    cout << cnt << "\n";

    return 0;
}



Measured memory_bytes: 3124
import math

s=input()
s=s.split(' ')
honsu = int(s[0])
HP  = int(s[1])

kill=[]
throw=[]
tmp_throw=[]
for i in range(honsu):
	a,b = input().split(' ')
	kill.append(int(a))
	throw.append(int(b))
	tmp_throw.append(int(b))



#
count=0
a_max=max(kill)
b_sum=0

#all throw?
tmp_throw.sort()
tmp_throw.reverse()
suma=0
for i,data in enumerate(tmp_throw):
	if data >=a_max :
		suma+=int(data)
		if suma >= HP:
			print(i+1)
			exit()

for i in tmp_throw:
	if i >=a_max :
		count+=1
		b_sum += i
	else:
		break

HP = HP - b_sum
temp=0
count=count+ math.ceil(HP/a_max)

print(count)


Measured memory_bytes: 15340
#include <stdio.h>

#define MAX 100
#define INFTY 2000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, m[MAX][MAX];

void dijkstra(void);

int main() {

  int i, j, k, c, u, v;

  scanf("%d", &n);
  for( i=0; i<n; i++ ) {
    for( j=0; j<n; j++ ) {
      m[i][j] = INFTY;
    }
  }

  for( i=0; i<n; i++ ) {
    scanf("%d %d", &u, &k);
    for( j=0; j<k; j++ ) {
      scanf("%d %d", &v, &c);
      m[u][v] = c;
    }
  }
  dijkstra();

  return 0;
}

void dijkstra() {

  int i, minv, u, v;
  int d[MAX], color[MAX];

  for( i=0; i<n; i++ ) {
    d[i] = INFTY;
    color[i] = WHITE;
  }
  d[0] = 0;
  color[0] = GRAY;
  while(1) {
    minv = INFTY;
    u = -1;
    for( i=0; i<n; i++ ) {
      if( minv > d[i] && color[i] !=BLACK ) {
	u = i;
	minv = d[i];
      }
    }
    if( u == -1 ) {
      break;
    }
    color[u] = BLACK;
    for( v=0; v<n; v++ ) {
      if( color[v] != BLACK && m[u][v] != INFTY ) {
	if( d[v] > d[u] + m[u][v] ) {
	  d[v] = d[u] + m[u][v];
	  color[v] = GRAY;
	}
      }
    }
  }
  for( i=0; i<n; i++ ) {
    printf("%d ", i);
    if( d[i] == INFTY) {
      printf("-1\n");
    } else {
      printf("%d\n", d[i]);
    }
  }
}

Measured memory_bytes: 636
//It doesn't matter how slow you go, Unless you don't stop.
#include<iostream>
#include<algorithm>
#include<bitset>
 
#include<cmath>
#include<cstring>
#include<climits>
 
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
 
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;
typedef map<LL,LL> mp64;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve()
{
     int n;cin>>n;
     int a[n][3];
     for(int i=0;i<n;i++)
     {
         for(int j=0;j<3;j++)
         {
             cin>>a[i][j];
         }
     }
     int dp[n][3];
     memset(dp,0,sizeof dp);
     //base
     for(int i=0;i<3;i++)
     {
         dp[0][i] = a[0][i];
     }
     //solve
     for(int i=1;i<n;i++)
     {
         dp[i][0] = a[i][0] + max(dp[i-1][1],dp[i-1][2]);
         dp[i][1] = a[i][1] + max(dp[i-1][0],dp[i-1][2]);
         dp[i][2]  =a[i][2] + max(dp[i-1][0],dp[i-1][1]);
     }
     int res = max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
     cout<<res<<endl;
}
 
int main()
{
    DANGER;
    ofstream out("output.txt");
 
    auto start = chrono::high_resolution_clock::now();
    
    LL t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        solve();
    }
    
    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

Measured memory_bytes: 2560
s=input()
N=len(s)
for i in range(N-1):
    if s[i]==s[i+1]:
        print(i+1,i+2)
        exit()
for i in range(N-2):
    if s[i]==s[i+2]:
        print(i+1,i+3)
        exit()
print(-1,-1)

Measured memory_bytes: 3188
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>


#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _Ty> static _Ty tp_abs(const _Ty& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _Ty> static _Ty tp_min(_Ty a, _Ty b) {
	return a < b ? a : b;
}
template <class _Ty> static _Ty tp_max(_Ty a, _Ty b) {
	return a > b ? a : b;
}

static const int EduDp_INF = 101000000;

static void C_task();

int main()
{
	C_task();
	
	fflush(stdout);
	return 0;
}

class HappyAct {
public:
	enum {
		Swim = 0,
		Bug,
		Homework,
		ActKind,
	};

	int hpyVal[ActKind] = { 0 };
	int choice = 0;

	int getMaxHappy(int yesterday) {
		int max = 0;
		for (int i = Swim; i < ActKind; i++) {
			if (i != yesterday) {
				max = std::max(max, hpyVal[i]);
			}
		}
		return max;
	}
};

static void C_task()
{
	int N;
	scanf(" %d", &N);

	auto dp = new int[N + 1][HappyAct::ActKind];
	memset(dp, 0, sizeof(int) * (N + 1) * HappyAct::ActKind);

	auto hpyAct = new HappyAct[N];
	for (int i = 0; i < N; i++) {
		for (int j = HappyAct::Swim; j < HappyAct::ActKind; j++) {
			scanf(" %d", &(hpyAct[i].hpyVal[j]));
		}
	}

	for (int i = HappyAct::Swim; i < HappyAct::ActKind; i++) {
		dp[0][i] = hpyAct[0].hpyVal[i];
	}
	for (int i = 1; i < N; i++) {
		for (int j = HappyAct::Swim; j < HappyAct::ActKind; j++) {
			for (int k = HappyAct::Swim; k < HappyAct::ActKind; k++) {
				if (j != k) {
					dp[i][j] = tp_max<int>(dp[i][j], dp[i - 1][k] + hpyAct[i].hpyVal[j]);
				}
			}
		}
	}

	printf("%d\n", std::max({ dp[N - 1][0],dp[N - 1][1], dp[N - 1][2] }));

	delete[] dp;
	delete[] hpyAct;
}


Measured memory_bytes: 2944
#include<iostream>
using namespace std;
 
int main(){
  int at_taka, hp_taka, at_ao, hp_ao;
  bool win_flag_taka;

  cin >> hp_taka >> at_taka >> hp_ao >> at_ao;
  
  while(1){
    hp_ao -= at_taka;
    if(hp_ao <= 0){
      win_flag_taka = true;
      break;
    }
    hp_taka -= at_ao;
    if(hp_taka <= 0){
      win_flag_taka = false;
      break;
    }
  }

  if(win_flag_taka){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

}

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

int main() {
  int t;
  cin >> t;
  for (int ti = 0; ti < t; ti++) {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    string s;
    cin >> s;
    vector<vector<long long>> dp(n + 1);
    dp[n].push_back(0);
    for (int i = n - 1; i >= 0; i--) {
      if (s[i] == '0') {
        dp[i] = dp[i + 1];
        dp[i].push_back(a[i]);
        int now = 0;
        for (int j = 0; j < 60; j++) {
          bool swp = false;
          for (int k = now; k < (int) dp[i].size(); k++) {
            if (dp[i][k] & 1ll << j) {
              swap(dp[i][now], dp[i][k]);
              swp = true;
              break;
            }
          }
          if (!swp) {
            continue;
          }
          for (int k = 0; k < (int) dp[i].size(); k++) {
            if (k == now) {
              continue;
            }
            if (dp[i][k] & 1ll << j) {
              dp[i][k] ^= dp[i][now];
            }
          }
          now += 1;
        }
        dp[i].resize(now);
      } else {
        long long x = a[i];
        for (int j = 0; j < (int) dp[i + 1].size(); j++) {
          int k = 0;
          for (int l = 0; l < 60; l++) {
            if (dp[i + 1][j] & 1ll << l) {
              k = l;
              break;
            }
          }
          if (x & 1ll << k) {
            x ^= dp[i + 1][j];
          }
        }
        if (x == 0) {
          dp[i] = dp[i + 1];
        } else {
          break;
        }
      }
    }
    if ((int) dp[0].size() == 0) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  }
  return 0;
}

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

int main() {
    //ifstream cin("b.in");

    int h, w; cin >> h >> w;
    int n; cin >> n;
    vector<int> a(n, 0);

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

    int it = 0;

    int x = 0, y = 0;
    int dy = 1;
    
    vector<vector<int>> mat(h, vector<int> (w, 0));

    for(int steps = 0; steps < h * w; ++steps) {
        mat[x][y] = it + 1;
        a[it] -= 1;
        
        if(a[it] == 0) {
            it += 1;
        }

        if(y == w - 1 and x % 2 == 0) {
            x += 1;
            dy = -1;
        } else if(y == 0 and x % 2 == 1) {
            x += 1;
            dy = 1;
        } else {
            y += dy;
        }
    }

    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            cout << mat[i][j] << " ";
        }
        cout << "\n";
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
bool input (std::vector<int> & v)
{
	for (std::vector<int>::size_type i = 0; i < v.size(); i++) {
		if(!(std::cin >> v[i])) return false;
	}
	return true;
}
void get_hit_blow(int & hit, int & blow, std::vector<int> a, std::vector<int> b)
{
	for (int i = 0; i < 4; i++) {
		if (a[i] == b[i]) ++hit;
		for (int j = 0; j < 4; j++) {
			if (a[i] == b[j]) ++blow;
		}
	}
	blow -= hit;
}
int main()
{
	std::vector<int> a(4), b(4);
	while (input(a) && input(b)) {
		int hit = 0, blow = 0;
		get_hit_blow(hit, blow, a, b);
		std::cout << hit << ' ' << blow << std::endl;
	}
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
	ll n, a,b;
	cin >>n>>a>>b;
	ll res=a+b;
	ll cnt=0;
	ll sum=0;
	sum+=n/res*a;
	cnt=n%res;
	if(cnt>=a) cnt=a;
	sum+=cnt;
	cout <<sum<<endl;
}

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

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

Measured memory_bytes: 3596
#include <cstdio>
#include <string>
#include <algorithm>

int main() {
  int w;
  scanf("%d", &w);

  std::string res;
  while (w) {
    switch (w % 3) {
    case 0:
      res += '0';
      break;
    case 1:
      res += '+';
      --w;
      break;
    case 2:
      res += '-';
      ++w;
      break;
    }
    w /= 3;
  }

  std::reverse(res.begin(), res.end());
  printf("%s\n", res.c_str());
}



Measured memory_bytes: 2756
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import perm
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########

r = i_inpl()

print(3*(r**2))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
typedef pair<ll,ll> pll;
typedef vector <ll> vi;
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
const ll N = 15;

int main(){
    FAST;
    ll n, ans = 0, k, m, j = 0, t = 1, x = 0, y = 0, c = 0, i, z = 0;
    cin >> n ;
    ll a[n][n];
    memset ( a , -1 , sizeof(a) );
    for ( i = 0 ; i < n ; i ++ ){
        cin >> x ;
        for ( j = 0 ; j < x ; j ++ ){
            cin >> y >> z ;
            if ( z == 1 ) a[i][y-1] = 1;
            else a[i][y-1] = 0;
        }
    }
    
    for ( i = 0 ; i < pow(2,n) ; i ++ ){
        bitset<N> b(i);
        bool f = 0;
        for ( j = 0 ; j < n ; j ++ ){
            if ( b[j] == 0 ) continue;
            for ( k = 0 ; k < n ; k ++ ){
                if ( (a[j][k] == 0 && b[k] == 1) || (a[j][k]==1 && b[k] == 0) ){
                    f = 1;
                    break;
                }
            }
            if ( f == 1 ) break;
        }
        if ( f == 0 )
            ans = max ( ans ,(ll) b.count() );
    }
    cout << ans ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9,mod=1e9+7;
typedef long long ll;
int read() {
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
int a[1000001];

main() {
	int n=read(),ans=0;
	for(int i=1; i<=n; i++)
		a[i]=read();
	sort(a+1,a+1+n);
	for(int i=1; i<=n; i++)
		for(int j=i+1; j<=n; j++) {
			int l=lower_bound(a+i+1,a+j,a[j]-a[i]+1)-a;
			int r=lower_bound(a+i+1,a+j,a[j]+a[i])-a-1;
			ans+=r-l+1;
		}
	cout<<ans;
}


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

using namespace std;

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

  int a, b;
  cin >> a >> b;
  if (10 <= a + b) {
    cout << "error\n";
  } else {
    cout << (a + b) << "\n";
  }
}


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

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); }

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0) cout
#endif

// ********************** CODE ********************** //

int main()
{
    _upgrade
    string s; cin >> s;
    cout << s[0] << sz(s) - 2 << s.back() << "\n";
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")

#include <cstdio>
#include <cstdlib>
using namespace std;

int N;
int A[200000];
int B[200000];

signed main() {
    scanf("%d", &N);
    for(int i = 0; i < N; ++i)
        scanf("%d", A+i);
    for(int i = 0; i < N; ++i)
        scanf("%d", B+i);

    int ans = 0;

    int m = N/6 * 6;
    for(int i = 0; i < m; i += 6) {
        const int a0 = A[i];
        const int a1 = A[i+1];
        const int a2 = A[i+2];
        const int a3 = A[i+3];
        const int a4 = A[i+4];
        const int a5 = A[i+5];

        for(int j = 0; j < N; ++j) {
            ans ^= a0 + B[j];
            ans ^= a1 + B[j];
            ans ^= a2 + B[j];
            ans ^= a3 + B[j];
            ans ^= a4 + B[j];
            ans ^= a5 + B[j];
        }
    }

    for(int i = m; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
            ans ^= A[i] + B[j];
        }
    }

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

    fflush(stdout);
    _Exit(0);
}


Measured memory_bytes: 1664
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn  main() {
    let a = read::<i32>();
    let b = read::<i32>();
    let c = read::<i32>();
    let d = read::<i32>();
    let e = if a > b {
        b
    } else {
        a
    };
    let f = if c > d{
        d 
    } else {
        c
    };
    println!("{}",e +f );
}

Measured memory_bytes: 4352
#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(){
    string s;
    cin >> s;
    int n = sz(s);
    rep(i, n) if(s[i] == '?') s[i] = 'D';
    cout << s << endl;
}

Measured memory_bytes: 3720
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
//#define sort(v,n) sort(v,v+n)
//#define vsort(v) sort(v.begin(),v.end())
//#define vvsort(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n, m, a;

int main() {
	while (cin >> n >> m >> a, n) {
		vector<tuple<int, int, int>> v;
		for (int i = 0; i < m; i++) {
			int h, p, q; cin >> h >> p >> q;
			v.push_back(tuple<int, int, int>(h, p, q));
		}
		sort rall(v);
		int maxh = 4000000;
		int now = a;
		for (int i = 0; i < m; i++) {
			int b = get<1>(v[i]);
			int c = get<2>(v[i]);
			if (b == now || c == now) {
				int d = get<0>(v[i]);
				if (maxh > d) {
					maxh = d;
					if (b == now)now = c;
					else now = b;
				}
			}
		}
		cout << now << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
using namespace std;
int main(){

	int a, b, c;

	cin >> a >> b >> c;

	if (a<=b&&b<=c){
		cout << a << ' ' << b << ' ' << c << "\n";
	}

	else if (a<=c&&c<=b){
		cout << a << ' ' << c << ' ' << b << "\n";
	}

	else if (b<=a&&a<=c){
		cout << b << ' ' << a << ' ' << c << "\n";
	}

	else if (b<=c&&c<=a){
		cout << b << ' ' << c << ' ' << a << "\n";
	}

	else if (c<=a&&a<=b){
		cout << c << ' ' << a << ' ' << b << "\n";
	}

	else {
		cout <<c << ' ' << b << ' ' << a << "\n";
	}

	return 0;
}

Measured memory_bytes: 3092
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

// just observed things...
// for a formal proof, refer this: https://codeforces.com/blog/entry/72955?#comment-572507

#include<bits/stdc++.h>
using namespace std;

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          (x).begin(),(x).end()
#define     rz(x)           resize(x)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)-1)/(x)+1)
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        ((a)*((b)/gcd((a),(b))))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

int lsb(int x)
{
    int res=log2(x&-x);
    return res;
}

void solve()
{
    int n,m;
    cin>>n>>m;

    set<int> st;
    for(int i=0;i<n;++i)
    {
        int x;
        cin>>x;

        st.ins(x);
    }

    vi v;
    for(auto c:st)
        v.pb(c);
    n=sz(v);

    int arr[32]={0};
    for(int i=0;i<n;++i)
    {
        ++arr[lsb(v[i])];
    }

    for(int i=0;i<32;++i)       // checking, that every a_i has equal no. of 2s in it's prime factorization
                                // doing this might seem complicated at first sight
                                // but yeah, I observed a pattern and didn't go for a formal proof
    {
        if(arr[i])
        {
            if(arr[i]!=n)
            {
                cout<<0;
                return;
            }

            break;
        }
    }

    // this part is actually simple...
    int l=1;
    for(int i=0;i<n;++i)
    {
        l=lcm(l,v[i]);

        if(l/2>m)
        {
            cout<<0;
            return;
        }
    }

    int a=l/2;

    //cout<<pos<<" "<<a<<" "<<l<<"\n";

    m-=a;
    if(m<0)
        cout<<0;
    else
        cout<<m/l+1;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}




Measured memory_bytes: 512
import sys
import math
import bisect

def query_value(s):
    #print('s: %s' % s)
    pos = s.find('.')
    if (pos == -1):
        return int(s) * 10 ** 9
    ans = int(s[:pos])
    #print('ans: %d' % ans)
    for i in range(pos + 1, pos + 10):
        #print('i: %d' % i)
        #print('len(%s): %d' % (s, len(s)))
        if i >= len(s):
            ans *= 10
        else:
            #print('s[%d] = %s' % (i, s[i]))
            ans = ans * 10 + ord(s[i]) - ord('0')
            #ans *= 10
    return ans

def main():
    n = 18
    A = []
    for i in range(2*n):
        A.append([0] * (2*n))
    #print('A: %s' % str(A))
    for _ in range(int(input())):
        a = query_value(input())
        #print('a: %d' % a)
        p2 = 0
        p5 = 0
        while a % 2 == 0:
            p2 += 1
            a /= 2
        while a % 5 == 0:
            p5 += 1
            a /= 5
        A[p2][p5] += 1
        #print('p2: %d, p5: %d' % (p2, p5))
    ans = 0
    for x1 in range(2*n):
        for y1 in range(2*n):
            for x2 in range(2*n):
                for y2 in range(2*n):
                    if x1 == x2 and y1 == y2:
                        if A[x1][y1] > 0 and x1 + x2 >= n and y1 + y2 >= n:
                            #print('A[%d][%d]: %d, A[%d][%d]: %d' % (x1, y1, A[x1][y1], x2, y2, A[x2][y2]))
                            ans += A[x1][y1] * (A[x2][y2] - 1)
                            #print('ans: %d' % ans)
                    else:
                        if A[x1][y1] > 0 and A[x2][y2] > 0 and x1 + x2 >= n and y1 + y2 >= n:
                            #print('A[%d][%d]: %d, A[%d][%d]: %d' % (x1, y1, A[x1][y1], x2, y2, A[x2][y2]))
                            ans += A[x1][y1] * A[x2][y2]
                            #print('ans: %d' % ans)
    ans //= 2
    print(ans)
    '''
    for i in range(n):
        print('A[%d]: %s' % (i, str(A[i])))
    '''

if __name__ == "__main__":
    main()


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

vector<vector<int>> graph_even, graph_odd;
vector<bool> sht;

void dfs(int u, int p, bool color)
{
	sht[u] = color;
	for (int v: graph_even[u])
	{
		if (v == p) continue;
		dfs(v, u, color);
	}
	for (int v: graph_odd[u])
	{
		if (v == p) continue;
		dfs(v, u, 1  - color);
	}
}

signed main()
{
	int n;
	cin >> n;
	graph_even.resize(n);
	graph_odd.resize(n);
	sht.resize(n);
	for (int i = 1; i != n; ++i)
	{
		int u, v, w;
		scanf("%d %d %d", &u, &v, &w);
		--u;
		--v;
		if (w & 1)
		{
			graph_odd[u].push_back(v);
			graph_odd[v].push_back(u);
		}
		else
		{
			graph_even[u].push_back(v);
			graph_even[v].push_back(u);
		}
	}

	dfs(0, -1, 0);

	for (int i = 0; i != n; ++i)
		printf("%d\n", (int) sht[i]);

	return 0;
}

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

long long a[1005];
long long b[1005];
long long dp[20005];
long long n,h,i,j;
long long mini=2e18,maxi;

int main()
{
    cin>>h>>n;
    for(i=1;i<=n;i++){
        cin>>a[i]>>b[i];
        maxi=max(maxi,a[i]);
    }
    for(j=1;j<=h+maxi+1;j++){
        dp[j]=2e18;
    }
    dp[0]=0;
    for(i=1;i<=n;i++){
        for(j=0;j<=h+maxi+1;j++){
            if(a[i]<=j)
                dp[j]=min(dp[j],dp[j-a[i]]+b[i]);
        }
    }
    for(j=h;j<=h+maxi+1;j++){
        mini=min(mini,dp[j]);
    }
    cout<<mini<<'\n';
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int ans;
    for (int i = 0; i <= max(X, Y)*2; i+=2)
    {
        int money;
        int a, b, ab;
        ab = i;
        a = X - i/2;
        b = Y - i/2;
        if(a<0) a=0;
        if(b<0) b=0;
        money = A*a + B*b + C*ab;
        if(i == 0) ans = money;
        else if(ans > money) ans = money;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;



void solve(){

    ll n,k;
    cin >> n >> k;
    ll tmp = n;
    ll ans = 1;
    while(tmp>=k){
        tmp /= k;
        ans++;
    }

    cout << ans << endl;

}

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


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

        int n=gi();
        int m=gi();
        int c=gi();
        int[] B=new int[m];

      for (int j=0; j< m; j++) {
            	B[j]=gi();
        }
        int d=0;
        for (int i=0; i< n; i++) {
        	int s=0;
            for (int j=0; j< m; j++) {
              int a=gi();
            	s+=B[j]*a;
            }
            if(s+c>0) {
            	d++;
            }
        }
      
        
	    System.out.println(d);

//        if (s>L[n-2]) {
//        	System.out.println("Yes");
//        }else {
//        	System.out.println("No");
//        }
	}


	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35716
from itertools import islice
 
R = lambda: map(int, input().split())
n, k = R()
v = list(R())
a = sorted((x, i) for i, x in enumerate(v) if x < 0)
ans = max(sum(v[:i - j] + v[n - j:]) -
          sum(islice((x for x, m in a if m < i - j or m >= n - j), k - i))
          for i in range(1, min(n, k) + 1) for j in range(i))
print(ans)


Measured memory_bytes: 3064
module Main where

import Control.Applicative
import Control.Monad
import Data.Array

lucas :: Int -> Int
lucas n = iter n
  where
    memo = listArray (0, n) $ fmap iter [0 .. n]
    iter 0 = 2
    iter 1 = 1
    iter k = memo ! (k - 1) + memo ! (k - 2)

main :: IO ()
main = do
    n <- readLn :: IO Int
    print $ lucas n

Measured memory_bytes: 508
//Zory-2019
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define double long double
    const int INF=0x3f3f3f3f;
    const ll LLINF=0x3f3f3f3f3f3f3f3fll;
    ll qread()
    {
        ll ans=0;char c=getchar();int f=1;
        while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) {num=-num;putchar('-');}
        if(num>9) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);puts("");}
    #define FR first
    #define SE second
    #define MP make_pair
    #define pr pair<int,int>
    #define PB push_back
    #define vc vector
    void chmax(int &x,const int y) {x=x>y?x:y;}
    void chmin(ll &x,const int y) {x=x<y?x:y;}
    const int MAX_N=2e5+10;
    const ll MOD=1e9+7;
    void add(int &x,int y) {x+=y;if(x>=MOD) x-=MOD;if(x<0) x+=MOD;}

    ll fac[MAX_N],inv[MAX_N],facinv[MAX_N],bin[MAX_N];
    ll C(int n,int m) {return fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
    void main()
    {
        fac[0]=1;for(int i=1;i<MAX_N;i++) fac[i]=fac[i-1]*i%MOD;
        inv[1]=1;for(int i=2;i<MAX_N;i++) inv[i]=ll(MOD-MOD/i)*inv[MOD%i]%MOD;
        facinv[0]=1;for(int i=1;i<MAX_N;i++) facinv[i]=facinv[i-1]*inv[i]%MOD;
        bin[0]=1;for(int i=1;i<MAX_N;i++) bin[i]=bin[i-1]*inv[2]%MOD;

        int B=qread(),W=qread(),fw=0,fb=0;
        for(int i=1;i<=B+W;i++)
        {
            if(W<=i-1) add(fw,C(i-2,W-1)*bin[i-1]%MOD);
            if(B<=i-1) add(fb,C(i-2,B-1)*bin[i-1]%MOD);

            if(i<=W and i<=B) write2(inv[2]);
            else write2( (inv[2]*(MOD*2+1-fw-fb)%MOD+fw)%MOD );
        }
    }
};
int main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 8448
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#define mp(x,y) make_pair(x,y)
using namespace std;

const int N=100005;

int n,a[N],deg[N],f[N];
priority_queue<pair<int,int> > que;

int main()
{
	scanf("%d",&n);
	for (int i=2;i<=n;i++) scanf("%d",&a[i]),deg[a[i]]++;
	int h=0;
	for (int i=1;i<=n;i++) if (!deg[i]) que.push(mp(0,i));
	while (!que.empty())
	{
		int x=que.top().second;que.pop();
		f[a[x]]=max(f[a[x]],f[x])+1;
		deg[a[x]]--;
		if (!deg[a[x]]) que.push(mp(-f[a[x]],a[x]));
	}
	printf("%d",f[1]);
	return 0;
}

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

using namespace std;

typedef long long ll;
set <ll> sa, sb;

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

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

    for (ll d = 2; d <= 1000000; d++)
    {
        while (a % d == 0)
        {
            a /= d;
            sa.insert(d);
        }

        while (b % d == 0)
        {
            b /= d;
            sb.insert(d);
        }
    }

    if (a > 1)
        sa.insert(a);
    if (b > 1)
        sb.insert(b);

    int ans = 0;
    for (auto &it : sb)
        ans += sa.count(it);
    cout << ans + 1 << "\n";


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
  while(true)
    {
  int h,w;
  cin>>h;
  cin>>w;
  if(h==0 && w==0)break;
  for(int i=0;i<h;i++)
    {
      for(int j=0;j<w;j++)
	{
	  if(i==0 || j==0 || i==h-1 || j==w-1)cout<<"#";
	  else cout<<".";
	}
      cout<<endl;
    }
  cout<<endl;
    }
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
/* Data Structure */
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <stack>
#include <queue>

using namespace std;

#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fLL
#define debug cerr << "======= GOT_HERE ======\n"
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef map<int,int> mii;
typedef map<long long,long long> mll;
typedef set<int> si;
typedef set<long long> sll;

int n,a,b;


typedef long long ll;		
		
const int MOD = 1e9 + 7;					
		
int powMod(int u, int v) 
{		
	int res = 1;		
	while (v) 
	{		
		if (v & 1) res = (ll)res * u % MOD;		
		v >>= 1;		
		u = (ll) u * u % MOD;		
	}		
	return res;		
}		
	
int C(int x, int y)
{		
	if (y < 0) return 0;		
	ll ans = 1;
	for(int i=x;i>x-y;--i)
	{
		ans*=i;
		ans%=MOD;
	}
	ll div = 1;
	for(int i=1;i<=y;++i)
	{
		div*=i;
		div%=MOD;
	}
	div = powMod(div,MOD-2);
	ans*=div;
	ans%=MOD;
	return ans;
}		
		

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n>>a>>b;
	int minus = C(n,a)+C(n,b)+1;
	minus%=MOD;
	cout << (powMod(2,n)+MOD-minus)%MOD << endl;
	return 0;
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
string s;
cin>>s;
vector<int> cnt(n);
int r_cnt=0;
rrep(i,n){
    if(s[i]=='R')r_cnt++;
    else cnt[i]=r_cnt;
}
int res=0;
if(r_cnt>0 && cnt.size()>0){
    int w=0;
    rep(i,n){
        if(s[i]=='W'){
            if(cnt[i]-w>0){
                w++;
                res++;
            }
        }
    }
}
cout<<res<<endl;
return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    bool flag = true;
    ll T = 0;
    ll X = 0;
    ll Y = 0;
    rep (i, N) {
        ll t, x, y;
        cin >> t >> x >> y;

        ll dt = t-T;
        ll dist = abs(x-X)+abs(y-Y);
        if ((dt < dist) || (dt%2 != dist%2)) {
            flag = false;
        }

        T = t;
        X = x;
        Y = y;
    }

    if (flag) {
        Yes;
    } else {
        No;
    }
    return 0;
}

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

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

    vector<int> d(N);
    rep(i, N) {
        cin >> d.at(i);
    }

    rep(i, N - 1) {
        rep(j, N - i - 1) {
            if (d.at(j) < d.at(j + 1)) {
                int tmp = d.at(j);
                d.at(j) = d.at(j + 1);
                d.at(j + 1) = tmp;
            }
        }
    }

    int count = 1;
    int top = d.at(0);
    rep(i, N) {
        if (top != d.at(i)) {
            top = d.at(i);
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
import sys
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

x = int(input())

if is_prime(x):
    print(x)
    sys.exit()

for i in range(x,int(1e5)+100):
    for j in range(2,x):
        if i % j == 0:
            break
        elif j == x-1:
            print(i)
            sys.exit()

Measured memory_bytes: 9144
N, M = map(int, input().split())
ns = [1]*N
fs = [False]*N
fs[0] = True
for i in range(M):
  x, y = map(int, input().split())
  x, y = x-1, y-1
  if ns[x] > 1:
    ns[x] -= 1
    ns[y] += 1
    if fs[x]:
      fs[y] = True
  elif ns[x] == 1:
    ns[x] -= 1
    ns[y] += 1
    if fs[x]:
      fs[x] = False
      fs[y] = True
r = fs.count(True)
print(r)


Measured memory_bytes: 4596
/*
* Author : MaxSally
*/
/********   All Required Header Files ********/
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i <= k ; ++i)
#define rrep(i, j, k) for (int i = j; i >= k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define inf (int) (1e9 + 7)
#define epsi 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define read(type) readInt<type>()
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define left tuyiuoi
#define right fgjhk
#define ss second
#define ff first
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) rep(i, l, r) cout << a[i] << " "; cout << endl
#define Flag(n) cout << "here " << n << endl
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

const int N = 100005;

int main(){
    io;
    //freopen("input.txt", "r", stdin);
    int n, a, b;
    int curX;
    cin >> n >> a >> b >> curX;
    ll sum = 0;
    rep(i, 2, n){
        int nxtX; cin >> nxtX;
        sum += min(1LL*a*(nxtX - curX), 1LL*b);
        curX = nxtX;
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=14;
int n,m,x,ans;
int c[N],a[N][N],f[N];

int main(){
	scanf("%d%d%d",&n,&m,&x);
	ans=1e8;
	for (register int i=1; i<=n; ++i)
	{
		scanf("%d",&c[i]);
		for (register int j=1; j<=m; ++j) scanf("%d",&a[i][j]);
	}
	for (register int p=1; p<=(1<<n)-1; ++p)
	{
		memset(f,0,sizeof(f));
		int now=0;
		for (register int i=1; i<=n; ++i) 
		if ((1<<(i-1))&p)
		{
			now+=c[i];
			for (register int j=1; j<=m; ++j) f[j]+=a[i][j];
		}
		bool jay=true;
		for (register int i=1; i<=m; ++i) if (f[i]<x) {jay=false; break;}
		if (jay) ans=min(ans,now);
	}
	if (ans==1e8) ans=-1;
	printf("%d\n",ans);
return 0;
}

Measured memory_bytes: 3784