akhauriyash/Code-Regression huggingface dataset:
// file creato da gio il 2020-03-25 09:50:14.760054

#include <bits/stdc++.h>
#define FAST 

#ifdef FAST
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define S second
#define F first
#define PB push_back
using namespace std;

bool isPAl(string inp,int f,int e){
	for(int i=0;i<(e-f+1)/2;i++){
		if(inp[f+i]!=inp[e-i]){
			return false;
		}
	}
	return true;
}


int main(){
	//freopen("output","w",stdout);
	//freopen("input","r",stdin);
#ifdef FAST
	ios::sync_with_stdio(0);
  	cin.tie(0);
#endif

	string inp;
	cin >> inp;
	if(isPAl(inp,0,inp.size()-1)&&isPAl(inp,0,(inp.size()-2)/2)&&isPAl(inp,(inp.size()+1)/2,inp.size()-1))
		cout <<"Yes";
	else
		cout <<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>
#include <math.h>  /* M_PI */

const ll MOD = 1000000007;
int main(){

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

Measured memory_bytes: 3676
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		
//	 		String input1 = bf.readLine().trim();
//	 		String input2 = bf.readLine().trim();
	 		StringTokenizer st = new StringTokenizer(bf.readLine());
	 		int d = Integer.parseInt(st.nextToken());
	 		int s = Integer.parseInt(st.nextToken());
	 		int t = Integer.parseInt(st.nextToken());
 		
 		
 		out.println((d+0.0)/(s+0.0)<=t ? "Yes" : "No");
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 25332
n, k, *a = $stdin.read.split.map(&:to_i)

b = Array.new(n+1, 0)
a.each do |x|
  b[x] += 1
end

b.delete(0)
len = b.length
c = b.sort.reverse
if c.length <= k
  p 0
else
  p c[k, len - k].inject(:+)
end

Measured memory_bytes: 21480
//Attack Survival

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
struct edge{int to;ll cost;};
const int inf = 2147483647;

int main (){
    int n,k,q;cin>>n>>k>>q;
    vector<int> m(n,k-q);
    rep(i,0,q){
        int c;cin>>c;
        m[c-1]++;
    }
    rep(i,0,n){
        cout << (m[i]>0 ? "Yes" : "No") << endl;
    }    
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class C
{
    static void Main()
    {
        long h = long.Parse(Console.ReadLine().Trim());

        var answer = CalcAttackCount(h);
        Console.WriteLine(answer.ToString());
    }

    private static long CalcAttackCount(long h)
    {
        long count = 0;

        if (h == 1)
        {
            count += 1;
        }
        else if (h == 2 || h == 3)
        {
            count += 3;
        }
        else
        {
            count++;
            var remainingHP = h / 2;
            count += CalcAttackCount(remainingHP) * 2;
        }

        return count;
    }
}

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

using namespace std;

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;

const int MX = 705;
int n, adj[MX][MX], x, y, col[MX], cn[2][MX], par[2], m;
int dp[MX][MX];
bitset<MX> bs;

bool dfs (int u, int c) {
	bs[u] = 1;
	col[u] = c;
	par[c]++;

	for (int v = 1; v <= n; v++)
		if (adj[u][v]) {
			if (bs[v]) {
				if (col[v] == col[u]) return 0;
			} else {
				if (!dfs(v, 1-c)) return 0;
			}
		}

	return 1;
}

int obtRes (int i, int j) {
	if (j > n / 2) return 0;
	if (i == m) return j;

	int &res = dp[i][j];
	if (res != -1) return res;
	return res = max(obtRes(i+1, j+cn[0][i]), obtRes(i+1, j+cn[1][i]));
}

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

	cin >> n >> m;

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			adj[i][j] = i != j;

	while (m--) {
		cin >> x >> y;
		adj[x][y] = 0;
		adj[y][x] = 0;
	}

	m = 0;
	for (int i = 1; i <= n; i++)
		if (!bs[i]) {
			par[0] = par[1] = 0;
			if (!dfs(i, 0)) {
				cout << -1 << endl;
				return 0;
			}
			cn[0][m] = par[0];
			cn[1][m] = par[1];
			m++;
		}

	for (int i = 0; i < MX; i++)
		for (int j = 0; j < MX; j++)
			dp[i][j] = -1;

	int a = obtRes(0, 0);
	int b = n - a;

	cout << a * (a - 1) / 2 + b * (b - 1) / 2 << endl;

	return 0;
}


Measured memory_bytes: 4224
#include<stdio.h>
#define N 10000

int parent(int );
int left(int );
int right(int);

int main(){  
  int H,i,A[N+1];


  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }


  
  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=H)printf("left key = %d, ",A[left(i)]);
    if(right(i)<=H)printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }

  return 0;
}


int parent(int i){
  return i/2;
}
 
int left(int i){
  return 2*i;
}
 
int right(int i){
  return 2*i+1;
}



Measured memory_bytes: 2048
class Stack:
    def __init__(self, full_idx=10):
        self.stack = [None] * full_idx
        self.top = 0
        self.MAX = full_idx

    def is_empty(self):
        return self.top == 0

    def is_full(self):
        return self.top >= self.MAX - 1

    def push(self, x):
        if self.is_full():
            raise IndexError

        self.top += 1
        self.stack[self.top] = x

    def pop(self):
        if self.is_empty():
            raise IndexError

        self.top -= 1
        return self.stack[self.top+1]


def main():
    e = input().split()
    s = Stack(101)

    for i in range(len(e)):
        if e[i].isdigit():
            s.push(int(e[i]))
        elif e[i] == '+':
            a, b = s.pop(), s.pop()
            s.push(a+b)
        elif e[i] == '-':
            a, b = s.pop(), s.pop()
            s.push(b-a)
        else:
            a, b = s.pop(), s.pop()
            s.push(a*b)

    print(s.pop())


if __name__ == '__main__':
    main()



Measured memory_bytes: 5612
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class BSportsFestival {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    vector<vector<int>> A;
    int open[301];
    int N, M;

    P calc() {
        map<int, int> cnt;
        REP(i, N) {
            REP(j, M) {
                if (open[A[i][j]]) {
                    cnt[A[i][j]]++;
                    break;
                }
            }
        }

        int num = 0;
        int sports = -1;
        for (auto kv : cnt) {
            if (kv.second > num) {
                sports = kv.first;
                num = kv.second;
            }
        }

        return {sports, num};
    }

    void solve(std::istream& cin, std::ostream& cout) {
        cin >> N >> M;
        A = vector<vector<int>>(N, vector<int>(M));
        REP(i, N) REP(j, M) {
            cin >> A[i][j];
            A[i][j]--;
        }

        REP(i, M) open[i] = 1;

        int cur = INF;
        REP(i, M) {
            int num, sports;
            tie(sports, num) = calc();
            if (num < cur) {
                cur = num;
            }
            open[sports] = 0;
        }
        cout << cur << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    BSportsFestival solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1024
num_s = gets.chomp.to_i
array_s = gets.chomp.split.map(&:to_i)
num_t = gets.chomp.to_i
array_t = gets.chomp.split.map(&:to_i)

count = 0
array_t.each do |item_t|
  array_s.each do |item_s|
    if (item_t == item_s) then
      count += 1
      break
    end
  end
end

puts count

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

int main()
{
    ll n,i;
    cin>>n;
    ll A[n+1],dp[n+1];
    for(i=1;i<=n;i++)
        cin>>A[i];

    dp[1]=0;
    dp[2]=abs(A[2]-A[1]);
    for(i=3;i<=n;i++)
        dp[i]=min(dp[i-1]+abs(A[i]-A[i-1]),dp[i-2]+abs(A[i]-A[i-2]));
    cout<<dp[n]<<"\n";    
}


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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    vector<ll> A;
    for (int i = 0; i < 3; i++) {
        ll a; cin >> a;
        A.pb(a);
    }
    asort(A);
    ll ans = A[2] - A[1];
    A[1] += ans;
    A[0] += ans;
    ll d = A[2] - A[0];
    if(d % 2 == 0){
        ans += d/2;
    } else {
        ans += d/2+2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

const ll INF = 1LL << 50;

ll f(ll x, ll A, ll X) {
  return max(A - (x - X) * (x - X), 0LL);
}

ll diff(ll x, ll A, ll X) {
  ll y3 = f(x - 3, A, X), y2 = f(x - 2, A, X), y1 = f(x - 1, A, X), y0 = f(x - 0, A, X);
  ll v2 = y2 - y3, v1 = y1 - y2, v0 = y0 - y1;
  ll a1 = v1 - v2, a0 = v0 - v1;
  return a0 - a1;
}

ll ok(ll k, ll a, ll n, ll *sum) {
  ll l = -INF, r = INF;
  REP(i, 1, n + 1) {
    if(sum[i] < k) {
      ll s = k - sum[i];
      ll x1 = ceil(i - sqrt(a - s));
      ll x2 = floor(i + sqrt(a - s));
      l = max(l, x1);
      r = min(r, x2);
    }
  }
  return l <= r;
}

ll s[3000001];
ll *sum = s + 1000000;

int main(void) {
  ll N, M;
  while(cin >> N >> M, N && M) {
    vector<ll> A(M), X(M - 1);
    REP(i, 0, M - 1) cin >> A[i] >> X[i];
    cin >> A[M - 1];

    REP(i, 0, 3000001) s[i] = 0;
    REP(i, 0, M - 1) {
      ll x1 = X[i] - sqrt(A[i]);
      ll x2 = X[i] + sqrt(A[i]);
      set<ll> candidate;
      REP(k, 0, 5) {
        candidate.insert(x1 + k);
        candidate.insert(x2 + k);
      }
      for(ll x : candidate) {
        sum[x] += diff(x, A[i], X[i]);
      }
    }
    REP(k, 0, 3) REP(i, 0, 3000000) s[i + 1] += s[i];

    ll l = 0, h = INF;
    while(h - l > 1) {
      ll m = (l + h) / 2;
      if(ok(m, A[M - 1], N, sum)) l = m; else h = m;
    }
    cout << l << endl;
  }
}


Measured memory_bytes: 27808
#include<bits/stdc++.h>
using namespace std;
#define INFTY 10000000000
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
using ipair = pair<ll,ll>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main(){
  
  int n;cin>>n;
  vector<ll> ans(1000005,INFTY);
  ans[0] = 0;
  rep(i,100003){
    ans[i+1] = min(ans[i+1],ans[i]+1);
    int l=6;
    while(i+l<=n){
      ans[i+l] = min(ans[i+l],ans[i]+1);
      l *= 6;
    }
    l=9;
    while(i+l<=n){
      ans[i+l] = min(ans[i+l],ans[i]+1);
      l *= 9;
    }   
  }
  cout<<ans[n]<<endl;
  return 0;
}

Measured memory_bytes: 8064
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#include"bits/stdc++.h"
using namespace std;

int32_t main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(auto &i:a)cin>>i;
	sort(a,a+n);
	int ans=accumulate(a,a+k,0);
	cout<<ans;
	
}

Measured memory_bytes: 3644
N, Q = list(map(int, input().strip().split()))
S = input()
rangeList = [list(map(int, input().strip().split())) for i in range(Q)]

Accumulation = [0]*N
flag = False

if (S[0] == "A"):
    flag = True

for i in range(1,N):
    if (flag):
        if (S[i] == "C"):
            Accumulation[i] = Accumulation[i-1] + 1
            flag = False
            continue
        elif (S[i] == "A"):
            Accumulation[i] = Accumulation[i-1]
            continue
        else:
            flag = False
            Accumulation[i] = Accumulation[i-1]
            continue
    elif (S[i] == "A"):
        flag = True
    Accumulation[i] = Accumulation[i-1]

for eachRange in rangeList:
    print(Accumulation[eachRange[1]-1] - Accumulation[eachRange[0]-1])


Measured memory_bytes: 30696
'use strict';
function Main(input) {
  const ar = input.split("\n").map(x => x.split(" "));
  const X = Number(ar[0]);

  const ans = [3, 5, 7].indexOf(X) >= 0 ? "YES" : "NO";
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum ^= a[i];
    }
    cout << (sum != 0 ? "No": "Yes") << endl;
    return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
//---------------------------------------------------------------------------------------------------

int dp[1000][2004];

int main(void){
    // Your code here!
    int s; cin >> s;
    memset(dp,0,sizeof(dp));
    FOR(i,3,2000) dp[0][i] =1;
    FOR(i,1,s/3 + 1) {
        FOR(j,3,2000) {
            dp[i][j] = dp[i][j-1]+ dp[i-1][j-3];
            dp[i][j] %= MOD;
            // FOR(k,3,j-3){
            //     dp[i][j] += dp[i-1][j-k];
            //     dp[i][j] %= MOD;
            // }
        }
    }
    ll ans = 0;
    rep(i,668) {
        ans += dp[i][s];
        ans %= MOD;
    }
    cout << ans << endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) cin >> A.at(i);

  for (int i = K; i < N; i++) {
    if (A.at(i - K) < A.at(i)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


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

using namespace std;

int n;
long long a[200001], ans;

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

        if (i > 0 && a[i] < a[i-1]) {
            ans += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 5176
N,M=map(int,input().split())
s=[]
for i in range(M):
    s.append(list(map(int,input().split())))
p=list(map(int,input().split()))
count=0
for state in range(1<<N):
    flag = 0
    for i in range(M):
        count_ = 0
        flag=1
        for j in range(1, s[i][0]+1):
            if (1 << (s[i][j] - 1)) & state:
                count_ += 1
        if count_ % 2 != p[i]:
            flag = 0
            break
    if flag:
        count += 1
print(count)

Measured memory_bytes: 3188
//C

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

#define MAX 200002

int n;
long long int k;


vector<long long int> v;

vector<long long int> im;
map<long long int, int> mp;

struct BIT{
	vector<int> bit;
	void resize(int N){
		bit.assign(N, 0);
	}
	void add(int i, int j){
		i++;
		while (i < bit.size()){
			bit[i] += j;
			i += i&-i;
		}
	}
	int sum(int i){
		int r = 0;
		i++;
		while (i){
			r += bit[i];
			i -= i&-i;
		}
		return r;
	}
	int rng(int lef, int rig){
		int F = sum(rig);
		if (lef){
			F -= sum(lef - 1);
		}
		return F;
	}
};

BIT b;

int main(){
	cin >> n;
	cin >> k;
	for (int i = 0; i < n; i++){
		long long int a;
		scanf("%lld", &a);
		a -= k;
		v.push_back(a);
	}
	im.push_back(0);
	for (int i = 0; i < n; i++){
		im.push_back(v[i]);
		im.back() += im[im.size() - 2];
		mp[im.back()] = 0;
	}
	mp[0] = 0;
	int dd = 0;
	for (auto it = mp.begin(); it != mp.end(); it++){
		(*it).second = dd;
		dd++;
	}
	b.resize(dd + 10);
	long long int way = 0;
	b.add(mp[0], 1);
	for (int i = 1; i <= n; i++){
		//im[i]-a=0
		int maxt = mp[im[i]];
		way += b.sum(maxt);
		b.add(maxt, 1);
	}
	printf("%lld\n", way);
	return 0;
}

Measured memory_bytes: 16624
import math

n,a,b = map(int,input().split())

p = 10**9 + 7


def cmb(n, r):
    total = 1
    for i in range(r):
        total = total * (n - i) % p
        
    return total * pow(math.factorial(r), p - 2, p) % p

total = pow(2, n, p)-1
a_total = cmb(n, a)
b_total = cmb(n, b)
print((total - a_total - b_total) % p)

Measured memory_bytes: 5440
#include <iostream>
using namespace std;
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long ll;

vector<vector<ll>> dp_arr;

ll countWays(vector<vector<int>>& G, vector<bool>& visited, int index, int color)
{

	if(dp_arr[index][color] != -1)
		return dp_arr[index][color];
	visited[index] = true;
	dp_arr[index][color] = 1;
	for(auto i : G[index])
	{
		if(!visited[i])
		{
			dp_arr[index][color] = (dp_arr[index][color]%MOD *
									(countWays(G, visited, i, !color)%MOD + (color ? countWays(G, visited, i, color) : 0)%MOD)%MOD)%MOD;
		}
	}
	// cout << "index: " << index << " color: " << color << " dp: " << dp_arr[index][color] << endl;
	visited[index] = false;
	return dp_arr[index][color];
}

int main()
{
	int n;
	cin >> n;
	vector<vector<int>> G(n);
	for(int i = 1; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		G[a-1].push_back(b-1);
		G[b-1].push_back(a-1);
	}
	dp_arr.resize(n, vector<ll>(2,-1));
	vector<bool> visited(n,false);
	cout << (countWays(G, visited, 0, 0)%MOD + countWays(G, visited, 0, 1)%MOD)%MOD << endl;
	return 0;
}


Measured memory_bytes: 22272
n = gets.to_i
ary = []
ans = []
k = 0
n.times do
  x = gets.chomp
  ary << x
end
count = Hash.new(0)
ary.each do |elem|
  count[elem] += 1
end
count = count.sort_by { |_, v| v }.reverse.to_h
i = 0
name = ""
count.each do |c|
  if k == 0
    ans << c[0]
    k = c[1]
    name = c[0]
  elsif k == c[1] && c[0] != name
    ans << c[0]
    name = c[0]
  end  
end
puts ans.sort

Measured memory_bytes: 74048
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int n, m;
	cin >> n >> m;
	if (m <= n) { cout << 0 << endl; return 0; }
	vector<int>x(m),xs(m-1);
	rep(i, m)cin >> x[i];
	sort(all(x));
	rep(i, m-1) {
		xs[i] = x[i + 1] - x[i];
	}
	sort(rall(xs));
	cout << accumulate(xs.begin() + n-1, xs.end(), 0) << endl;;
	return 0;
}



Measured memory_bytes: 3960
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	long long k;
	cin>>s>>k;
	int n=0;
	for(int i=0;i<s.size();i++){
		if(s[i]!='1')
			break;
		n++;
	}
	cout<<(k<=n?'1':s[n])<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';

int main(){
        string s;ll n,i,b;
        cin>>s;
        n=s.size();
        vl a(n);
        for(i=n-1;i>=0;i--){
            if(s[i]=='L')b=i;
            else a[b-((b-i)&1)]++;
        }
        for(i=0;i<n;i++){
            if(s[i]=='R')b=i;
            else a[b+((i-b)&1)]++;
        }
        rep(i,n)cout<<a[i]<<" ";
        cout<<endl;
}


Measured memory_bytes: 1408
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
using namespace std;
int main() {
	int A;
	int B;
	cin>>A>>B;
	if(B%A==0)
		cout<<A+B<<endl;
	else
		cout<<B-A<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    int a=0;
    if(n==1)a++;
    if(n==2)a++;
    if(n==3)a++;
    if(n==5)a++;
    if(n==6)a++;
    if(n==9)a++;
    if(n==10)a++;
    if(n==13)a++;
    if(n==17)a++;
    if(a)printf("No\n");
    else printf("Yes\n");
}

Measured memory_bytes: 128
n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
An = [sum(A[:i]) for i in range(1, n+1)]
Bn = [sum(B[i:]) for i in range(0, n)]
ans = 0
for i in range(n):
    ans = max(ans, An[i] + Bn[i])
print(ans)

Measured memory_bytes: 3064
#include<iostream>
 
using namespace std;
 
int main(){
    double d,t,s;
    double time;
 
    cin >> d >> t >> s;
    time = d/s;
 
    if(time <= t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
 
    return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
int main() {
  int N,M;
  cin>>N>>M;
  vector<int>L(M);
  vector<int>R(M);
  for(int i=0;i<M;i++){
    cin>>L[i]>>R[i];
  }
  int l=*max_element(L.begin(),L.end());
  int r=*min_element(R.begin(),R.end());

  if(r-l<0){cout<<0<<endl;}
  else{cout<<r-l+1<<endl;}
  return 0;}

Measured memory_bytes: 1024
N = int(input())
D = []
for i in range(N):
    d1, d2 = map(int, input().split())
    D.append([d1, d2])

flag = False

for i in range(N - 2):
    if D[i][0] == D[i][1] and D[i+1][0] == D[i+1][1] and D[i+2][0] == D[i+2][1]:
        flag = True

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9196
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード

//ループ
#define REP(i, n) for(int i = 0; i < n; i++) //普通のループ
#define REPR(i, n) for(int i = n; i >= 0; i--) //逆ループ
#define FOR(i, m, n) for(int i = m; i < n; i++) //最初の数値を指定したループ

//型名省略
typedef long long ll;

using namespace std;

int main(){
    ll N, ans, tmp, l=0, m=0,cnt=0;
    ll a[3][3], chk[3][3];
    
    REP(i, 3){
        REP(j, 3){
            cin >> a[i][j];
            if(a[i][j]<1 || a[i][j]>100){
                printf("No");
                return 1;
            }
        }
    }

    cin >> N;
    if(N<1 || N>10){
        printf("No");
        return 1;
    }

    ll b[N];
    REP(i, N){
        cin >> b[i];
        if(b[i]<1 || b[i]>100){
            printf("No");
            return 1;
        }
    }

    REP(i, 9){
        tmp = a[l][m];
        REP(j, 3){
            REP(k,3){
                if(tmp==a[j][k]){
                    cnt++;
                }
            }
        }
        if(cnt>1){
            printf("No");
            return 1;
        }else{
            cnt = 0;
        }

        if(m==2){
            l++;
            m=0;
        }else{
            m++;
        }
    }

    l = 0;
    cnt = 0;
    REP(i, N){
        tmp = b[l];
        REP(j, N){
            if(tmp==b[j]){
                cnt++;
            }
        }
        if(cnt>1){
            printf("No");
            return 1;
        }else{
            cnt=0;
        }
        l++;
    }

    REP(i, 3){
        REP(j, 3){
            chk[i][j] = 0;
        }
    }

    REP(i, N){
        tmp = b[i];
        REP(j, 3){
            REP(k, 3){
                if(tmp==a[j][k]){
                    chk[j][k] = 1;
                }
            }
        }
    }

    REP(i, 3){
        if(chk[i][0]==1 && chk[i][1]==1 && chk[i][2]==1){
            printf("Yes");
            return 0;
        }

        if(chk[0][i]==1 && chk[1][i]==1 && chk[2][i]==1){
            printf("Yes");
            return 0;
        }
    }

    if(chk[0][0]==1 && chk[1][1]==1 && chk[2][2]==1){
        printf("Yes");
        return 0;
    }

     if(chk[0][2]==1 && chk[1][1]==1 && chk[2][0]==1){
        printf("Yes");
        return 0;
    }

    printf("No");

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
	if(a.size()==0)
		cout << endl;
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}



int main()
{
	int n, q;
	cin >> n >> q;
	vector<vector<int>> a(n);
	rep(_,q){
		int c;
		cin >> c;
		if(c == 0){
			int t, x;
			cin >> t >> x;
			a[t].push_back(x);
		} else if (c == 2){
			int t;
			cin >> t;
			a[t].clear();
		} else {
			int t;
			cin >> t;
			print(a[t]);
		}
	}

	return 0;
}


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

int main(){
	string s;
	cin>>s;
	int x=s.size();
	int n[x-2];
	for(int i=0;i<x-2;i++){
		n[i]=(int)(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
		n[i]=abs(n[i]-753);
	}
	sort(n,n+x-2);
	cout<<n[0]<<endl;
	return 0;
}


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

#define PI acos(-1)
#define pb push_back
#define int long long int
#define mp make_pair
#define pi pair<int, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 100001
#define MAXL 20
#define mod 1000000007

signed main()
{
  int a;
  cin >> a;
  cout << a + (a * a) + (a * a * a) << endl;
  return 0;
}

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


class Program
{
    public static void Main()
    {
        var s = Console.ReadLine();
        bool f = false;
        for(int i = 0; i < 3; i++)
        {
            if (s[i] == s[i + 1])
                f = true;
        }
        if (f)
            Console.WriteLine("Bad");
        else
            Console.WriteLine("Good");
    }
}

Measured memory_bytes: 13140
fun main(args: Array<String>){
    val n = readLine()!!.toLong()

    val list = mutableListOf<Long>()
    for(i in 1..Math.sqrt(n.toDouble()).toInt()){
        if(n % i == 0L){
            list.add(i.toLong())
            list.add(n / i)
        }
    }
    var min = Long.MAX_VALUE / 10
    list.forEach {
        val a = it
        val b = n / it
        min = Math.min(min, a + b - 2)
    }
    println(min)
}

Measured memory_bytes: 33720
/// In The Name Of God

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

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

const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

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

using namespace std;

int n, k;
int m1, m2;
ll p1[N], p2[N];
int main() {
	#ifdef wws
		freopen ("in.txt", "r", stdin);
	#endif
	Kazakhstan
	cin >> n >> k;
	rep(i, 1, n) {
		int val;
		cin >> val;
		if (val >= 0) p2[++m2] = val;
		else p1[++m1] = -val;
	}
	if (m1) {
		reverse (p1 + 1, p1 + 1 + m1);
	}
	ll ans = linf;
	rep(i, 0, k) {
		if (i <= m1 && k - i <= m2) {
			ans = min(ans, min(p1[i], p2[k - i]) + p1[i] + p2[k - i]);
		}
	}
	cout << ans;
	ioi
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h,a;
    cin>>h>>a;
    if(h<=a) cout<<"1"<<endl;
    else{
        int x=h%a;
        if(h%a==0) cout<<h/a<<endl;
        else cout<<h/a+1<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

int main(void){
    int X, ans;
    std::cin >> X;

    for (int i=X; X<100004; ++i){
        int tmp =  sqrt(i);
        bool flg = false;
        for (int j=2; j<tmp; ++j){
            if (i % j == 0){
                flg = true;
                break;
            }
        }
        if (flg == false){
            ans = i;
            break;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

long long SumOfDigits(long long n) {
    long long sum = 0LL;
    while (n) {
        sum += n%10LL;
        n /= 10LL;
    }
    return sum;
}

int main() {
    long long N, minimum = 1e7;
    cin >> N;
    for (long long a = 1; a < N; a++) {
        long long b = N - a;
        long long ab = SumOfDigits(a) + SumOfDigits(b);
        if (ab < minimum) { minimum = ab; }
    }
    cout << minimum << endl;
}

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

int P[10010];

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

int root(int a)
{
	if(P[a]==a)   
	   return a;
	else  return(P[a]=root(P[a]));
}
 
bool is_same_set(int a,int b)
{
	return(root(a)==root(b));
}

void unite(int a,int b)
{
	P[root(a)]=root(b);
}

int main()
{
	int n,q;
	cin >> n >> q;
	init(n);
	for(int i=0;i<q;i++)
	{
		int com,m,n;
		cin >> com >> m >> n;
		if(!com)
		   unite(m,n);
		else
			cout << is_same_set(m,n) << endl;	
	}
}


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

string Echo(string s, int n)
{
	if (n % 2) return "No";
	if (s.substr(0, n / 2) == s.substr(n / 2)) return "Yes";
	return "No";
}

int main()
{
	string S;
	int N;
	cin >> N >> S;
	cout << Echo(S, N);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
pt = pa = 0
for _ in range(N):
    t,a = map(int,input().split())
    if pt == 0:
        pt,pa = t,a
    else:
        #print(pt,pa,t,a)
        if (pt <= t) and (pa <= a):
            pt,pa = t,a
        else:
            '''
            i = 2
            while True:
                if (pt <= t*i) and (pa <= a*i):
                    pt,pa = t*i,a*i
                    break
                i += 1
            '''
            if t == a:
                #that is t = a = 1
                maxta = max(pt,pa)
                pt = pa = maxta
            else:
                w1 = -1 * ((-1 *pt) // t)
                w2 = -1 * ((-1 *pa) // a)
                w = max(w1,w2)
                pt = w * t
                pa = w * a
                #print(pt,pa)
print(pt+pa)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>

typedef long long ll;
using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    if((a*b)%2==0) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}


int main(){
        int q,l,r,num,temp;
        vector<double> v(1000000,0);
        for(int i=1;i<v.size();i+=2){
          if(IsPrime(i)&&IsPrime((i+1)/2))v[i]=1;
        }
        for(int i=1;i<v.size();i++){
          v[i]=v[i]+v[i-1];
        }
        cin >> q;
        for(int i=0; i<q; i++) {
          cin >>l>>r;
          cout<<(v[r]-v[l-1])<<endl;
        }
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
#define mp make_pair
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const dou pi = 3.14159265358;
const ll mod = 1000000007LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a / gcd(a,b) * b;
}

//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n,ll m,ll MOD){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,M;
    cin >> N >> M;
    map<ll,ll> ma;
    ll n,m;
    rep(i,N){
        cin >> n;
        rep(j,n){
            cin >> m;
            ma[m]++;
        }
    }
    ll ans = 0;
    for(auto x : ma){
        if(x.second == N)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  int C, D, E, F;
  cin >> A >> B;
 
  C = A + B;
  D = A - B;
  E = A * B;
  
  F = C;
  
  if(F < D)
  {
    F = D;
  }
  
  if(F < E)
  {
    F = E;
  }
  
   cout << F << endl;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i, n) cin >> d[i];
	sort(d.begin(), d.end());
	int ans = 0;
	for (int i = n - 1; i >= 0; --i) {
		for (int j = i - 1; j >= 0; --j) {
			int p = d.end() - lower_bound(d.begin(), d.end(), d[i] + d[j]);
			ans += (n - 1 - i) - p;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
list = [chr(i) for i in range(65, 65+26)]

x = int(input())
list_before = input()

list_after = []
count = 0

for i in list_before:
    count = int(list.index(i)) + x
    while count >= 26:
        count -= 26

    list_after.append(list[count])

moji = ''.join(list_after)
print(moji)


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

int main(void)
{
	long int A, B, C, K;

	cin >> A >> B >> C >> K;

	int ans = 0;
	int remainder = K;

	if (remainder > A) {
		ans += A;
		remainder -= A;
	}
	else if (remainder == A) {
		ans += A;
		remainder = 0;
	}
	else if (remainder < A) {
		ans += remainder;
		remainder = 0;
	}

	if (remainder > B) {
		remainder -= B;
	}
	else if (remainder == B) {
		remainder = 0;
	}
	else if (remainder < B) {
		remainder = 0;
	}

	if (remainder > C) {
		ans -= C;
		remainder -= C;
	}
	else if (remainder == C) {
		ans -= C;
		remainder = 0;
	}
	else if (remainder < C) {
		ans -= remainder;
		remainder = 0;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <climits>
#include <sstream>

using namespace std;

double EPS = 1e-12;

//誤差を考慮して足し算を行う
double add(double a, double b) {
	if( abs(a + b) < EPS * (abs(a) + abs(b))) {
		return 0;
	}

	return a + b;
}

//二次元ベクトル構造体
struct P {
	double x, y;

	P() {};
	P(double x, double y) : x(x), y(y) {
	}
	P operator + (P p) {
		return P(add(x, p.x), add(y, p.y));
	}
	P operator - (P p) {
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator * (double d) {
		return P(x * d, y * d);
	}
	double dot(P p) {	//　内積
		return add(x * p.x, y * p.y);
	}
	double det(P p) {	//　外積
		return add(x * p.y, -y * p.x);
	}
};

//　線分p1-p2上に点qがあるか判定
bool on_seg(P p1, P p2, P q) {
		return (p1 - q).det(p2 - q) == 0 && (p1 - q).dot(p2 - q) <= 0;
}

//　直線p1-p2と直線q1-q2の交点
P intersection(P p1, P p2, P q1, P q2) {
	return p1 + (p2 - p1) * ((q2 - q1).det(q1 - p1) / (q2 - q1).det(p2 - p1));
}

int ccw(P a, P b, P c) {
	a = b - a;
	b = c - b;

	if(a.det(b) < 0) {
		return -1;
	} else if(a.det(b) > 0) {
		return 1;
	}

	return 0;
}


int main() {

	string str;
    while (getline(cin, str)) {
        replace(str.begin(), str.end(), ',', ' ');
        stringstream buf(str);
        P p[4];
        for (int i = 0; i < 4; i++) {
            buf >> p[i].x >> p[i].y;
        }
 
        int cnt = 0, n = 0;
        for (int i = 0; i < 4; i++) {
            int c = ccw(p[i], p[(i+1)%4], p[(i+2)%4]);
            cnt += c;
            n += abs(c);
        }
 
        cout << (abs(cnt) == n ? "YES" : "NO") << endl;
    }
}

Measured memory_bytes: 1236
N, M = map(int, input().split())
# 始点を0にするため1を引く
# kを除くために[1:]
connected_switches = [[int(i) - 1 for i in input().split()[1:]]
                      for _ in range(M)]
ps = list(map(int, input().split()))

# https://atcoder.jp/contests/abc128/submissions/9251177 がとてもわかりやすいので参考にする

ans = 0
# どのスイッチがONになっているかの全パターン
for bit in range(2 ** N):
    ok = True
    # 各電球について回す、これは電球個（M個）あるpsが全て条件を満たしているかを確認するため
    for i in range(M):
        # i番目の電球に繋がっている、状態onのスイッチ個数
        connected_on_num = 0
        for s in connected_switches[i]:
            # 今確認しているパターン（bit）で
            # i番目の電球に繋がっているスイッチsがonとなる場合
            # 例: Nが4、bitが3
            # 0番目: ON
            # 1番目: ON
            # 2番目: OFF
            # 3番目: OFF
            # となるケースで、forで回しているs（i番目の電球に繋がっているスイッチ）が
            # 0番目もしくは1番目のとき、connected_numを加算
            if bit & (1 << s):
                connected_on_num += 1
        if connected_on_num % 2 != ps[i]:
            ok = False
            break
    # 今確認しているパターン（bit）で
    # すべての電球が点灯している場合（connected_on_num % 2 != ps[i] が全てFalseだった場合）
    if ok:
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define lop(i, n) for(i=0; i<n; i++)

int main()
{
	int n, i;
	scanf("%d", &n);
	long int h[100000];
	lop(i, n){ scanf("%ld", &h[i]); }
	if(n==1){ printf("Yes"); return 0; }
	
	for(i=1; i<n; i++){
		if(h[i-1]>h[i]){
			h[i]=h[i]+1;
			if(h[i-1]>h[i]){
				printf("No"); return 0;
			}
		}
	}
	
	printf("Yes");
	
return 0;
}

Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std ;

const int MAX = 3010 ;

string a, b ;
int dp[ MAX ][ MAX ] ;

int sol( int m, int n ){
	if(	!m  or !n )
		return 0 ;
	int &ans = dp[ m ][ n ] ;
	if( ans != -1 )
		return ans ;
	if( a[ m - 1 ] == b[ n - 1 ] )
		ans = 1 + sol( m - 1, n - 1 ) ;
	else
		ans = max( sol( m, n - 1 ), sol( m - 1, n ) ) ;
	return ans ;
}

int main( ){
	cin >> a >> b ;
	memset( dp, -1, sizeof dp ) ;
	sol( a.size( ), b.size( ) ) ;
	string ans = "" ;
	int i = a.size( ), j = b.size( ) ;
	while( i > 0 and j > 0 ){
		if( a[ i - 1 ] == b[ j - 1 ] ){
			i--, j-- ;
			ans.push_back( a[ i ] ) ;
		}
		else if( dp[ i - 1 ][ j ] > dp[ i ][ j - 1 ] )
			i-- ;
		else
			j-- ;
	}
	reverse( ans.begin( ), ans.end( ) ) ;
	cout << ans << endl ;
}

Measured memory_bytes: 36096
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int main(){
  string S;
  cin>>S;
  if(S[0]==S[1]){
    cout<<"1 2"<<endl;
    return 0;
  }
  FOR(i,1,(int)S.size()-1){
    if(S[i-1]==S[i]||S[i]==S[i+1]||S[i-1]==S[i+1]){
      cout<<i<<" "<<i+2<<endl;
      return 0;
    }
  }
  cout<<"-1 -1"<<endl;
  return 0;
}


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

int main(){
	cin.tie(false);
	ios_base::sync_with_stdio(false);
	int n, m, d, q, l, r, inp;
	cin >> n >> m >> d;
	map<int, pair<int, int>> ma;
	int memo[n*m+1];

	for ( int i = 0; i < n; i++ ){
		for( int j = 0; j < m; j++ ){
			cin >> inp;
			inp--;
			ma[inp] = make_pair(i, j);
		}
	}

	cin >> q;

	for( int i = 0; i < d; i++ ){
		int out = 0, x = ma[i].first, y = ma[i].second;

		for( int j = i; j < n*m; j += d){
			out += abs(ma[j].first - x) + abs(ma[j].second - y);
			x = ma[j].first; y = ma[j].second;
			memo[j] = out;
		}
	}

	for( int i = 0; i < q; i++ ){
		cin >> l >> r;
		l--; r--;
		cout << memo[r] - memo[l] << endl; 
	}
	return 0;
}

Measured memory_bytes: 8320
#![allow(unused)]

use std::{cell, cmp, collections, fmt, ops};

use cell::{Cell, RefCell};
use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use fmt::{Debug, Display};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        _input_inner!(iter, $($r)*)
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        _input_inner!(iter, $($r)*)
    };
}

macro_rules! _input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = _read_value!($iter, $t);
        _input_inner!($iter $($r)*)
    };
}

macro_rules! _read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(_read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| _read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        _read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        _read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[cfg(feature = "debug")]
macro_rules! d {
    ($($args: tt)*) => { dbg!($($args)*) };
}

#[cfg(not(feature = "debug"))]
macro_rules! d {
    ($($args:tt)*) => {};
}

mod num {
    //
}

macro_rules! vmin {
    ($x: expr, $y: expr) => { cmp::min($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::min($x, vmin!($($args),*)) };
}

macro_rules! vmax {
    ($x: expr, $y: expr) => { cmp::max($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::max($x, vmax!($($args),*)) };
}

mod bits {
    pub fn is_high(bits: u64, pos: u64) -> bool {
        bits & (1 << pos) != 0
    }

    pub fn len(bits: u64) -> usize {
        for b in 0..64 {
            if is_high(bits, 63 - b) {
                return (64 - b) as usize;
            }
        }

        return 0;
    }
}

fn main() {
    input!(n: usize, k: u64, nums: [u64; n]);

    let mut x = 0;

    for b in (0..64).rev() {
        if x | 1 << b > k {
            continue;
        }

        let high_num = nums.iter().filter(|&&n| bits::is_high(n, b)).count();
        if high_num < n - high_num {
            x |= 1 << b;
        }
    }

    let ans = nums.iter().map(|n| n ^ x).sum::<u64>();
    println!("{}", ans);
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        //
    }
}


Measured memory_bytes: 6396