akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define MAX (int)1e+5
#define M 13
typedef long long ll;

char S[MAX];
static const ll p = 1000000007;

void solve() {
    ll dp[MAX+1][M];
    int base = 1;
    int n = strlen(S);
    int c;

    //initialize
    for (int i=1; i<M; i++) dp[0][i] = 0;
    dp[0][0] = 1;

    //dp
    for (int i=1; i<=n; i++) {
        if (S[n-i]=='?') c = -1;
        else c = S[n-i] - '0';

        for (int j=0; j<M; j++) dp[i][j] = 0;

        for (int j=0; j<10; j++) {
            if (c == -1 || c == j) {
                for (int k=0; k<M; k++) dp[i][(k+j*base)%M] += dp[i-1][k];
            }
        }

        for (int j=0; j<M; j++) dp[i][j] %= p;
        base *= 10; base %= M;
    }

    //result
    printf("%lld\n", dp[n][5]);
}

int main() {
    scanf("%s", S);

    solve();

    return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for(int i=0; i<n; i++)
    cin >> h.at(i);
  
  sort(h.begin(), h.end());
  
  long long ans = 0;
  for(int i=0; i<n-k; i++)
    ans += h.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int n=1,o,p;
	do{
		o=n*0.08;
		p=n*0.1;
		n++;
	}while(o<a&&p<b||o==a&&p<b||o<a&&p==b);
	if(o==a&&p==b)
	cout<<n-1;
	else cout<<-1;
}

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

using namespace std;

int idx,size;
string s;

string parse(){
  string res;
  if(idx >= size || s[idx] == ']'){ return res; }
  if(isupper(s[idx])){
    while(idx < size && isupper(s[idx])){
      res += s[idx++];
    }
  }else if(s[idx] == '['){
    idx++;
    string str = parse();
    idx++;
    reverse(str.begin(),str.end());
    res += str;
  }else if(s[idx] == '?'){
    res += 'A'; idx++;
  }else if(s[idx] == '+' || s[idx] == '-'){
    int p[85] = {0}, N = 0;
    while(idx < size && (s[idx] == '+' || s[idx] == '-')){
      if(s[idx] == '+'){
        p[N++] = 1;
      }else{
        p[N++] = -1;
      }
      idx++;
    }
    if(isupper(s[idx])){
      int x = s[idx];
      for(int i = 0 ; i < N ; i++){
        x += p[i];
        if(x > 'Z'){ x = 'A'; }
        else if(x < 'A'){ x = 'Z'; }
      }
      res += (char)x;
    }else if(s[idx] == '?'){
      res += 'A';
    }
    idx++;
  }
  return res + parse();
}

int main(){
  while(cin >> s, s != "."){
    idx = 0; size = s.size();
    cout << parse() << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int n,m; //　バイドルの数、費用
string str;
int c[333],v[333],d[333],l[333];
ll dp[333][333]; 
int solve(int i,ll sum,int *data);
int main(){
 
  while(cin >> n >> m){
    for(int i=0;i<n;i++){
      getchar(); // 最初のごみ取り
      getline(cin , str);
      cin >> c[i] >> v[i] >> d[i] >> l[i];
    }
  
    memset( dp , -1 , sizeof(dp) );
    int A = solve( 0 , 0  , &v[0] );
    memset( dp , -1 , sizeof(dp) );
    int B = solve( 0 , 0  , &d[0] );
    memset( dp , -1 , sizeof(dp) );
    int C = solve( 0 , 0  , &l[0] );
    memset( dp , -1 , sizeof(dp) );
    cout << max( max( A , B ) , C ) << endl;
  }
}
int solve(int i,ll sum,int *data){
  int ret = 0;
  if(i == n)return 0;

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

  for(int j=0;j*c[i]<=(m-sum);j++){
    ret = max( ret , solve( i + 1 , sum + (j*c[i]) , data ) + (data[i] * j));
  }

return dp[i][sum] = ret;
}

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

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

    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    if(0<=x-r and x+r<=w and 0<=y-r and y+r<=h){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> cond(m);
    rep(i, m) {
        int k;
        cin >> k;
        rep(j, k) {
            int tmp;
            cin >> tmp;
            cond[i].push_back(--tmp);
        }
    }
    vector<int> p;
    rep(i, m) {
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }
    int ans = 0;
    rep(i, (1<<n)) {
        rep(j, m) {
            int ctr = 0;
            for (auto au: cond[j]) {
                if (i & (1<<au)) {
                    ctr++;
                }
            }
            if (ctr % 2 != p[j]) {
                break;
            }
            if (j == m - 1) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func IsPrime(n int) bool {
	for i := 2; i <= int(math.Sqrt(float64(n))); i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func main() {
	var n int
	fmt.Scan(&n)

	var count int
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		if IsPrime(x) {
			count++
		}
	}
	fmt.Println(count)
}



Measured memory_bytes: 1724
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

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

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

    return 0;
}


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

int main(){
	map<string,int> m;
	int N;
	cin>>N;
	string S;
	for(int i=0;i<N;i++){
		cin>>S;
		m.insert(make_pair(S,0));
	}
	cout<<m.size();
	return 0;
}

Measured memory_bytes: 18772
#include <bits/stdc++.h>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
using boost::algorithm::split;
using boost::algorithm::join;
using boost::algorithm::replace_all;
using boost::multiprecision::cpp_int;
using boost::multiprecision::cpp_dec_float_50;
#define rep(i, n) for(int i = 0; i < n; ++i)

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}

int main() {
  int n, q;
  cin >> n >> q;
  vector<vector<int>> graph(n, vector<int>{});
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    graph[b - 1].push_back(a - 1);
    graph[a - 1].push_back(b - 1);
  }
  vector<long long> point(n);

  rep(i, q) {
    int p, x;
    cin >> p >> x;
    point[p - 1] += x;
  }

  vector<bool> seen(n, false);
  queue<int> que;
  que.push(0);
  seen[0] = true;

  while (!que.empty()) {
    int curr = que.front();
    que.pop();
    long long curr_point = point[curr];
    for (auto &next : graph[curr]) {
      if (!seen[next]) {
        point[next] += curr_point;
        que.push(next);
        seen[next] = true;
      }
    }
  }
  print(point);
}


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

int main() {
	int H, W;
	string S[500];
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}
	for (int i = 0; i < H; i++) {
		if (i % 2 == 0) {
			for (int j = 0; j < W - 1; j++) {
				cout << '#';
			}
			cout << '.';
		}
		else {
			cout << '#' << S[i].substr(1, W - 1);
		}
		cout << endl;
	}
	cout << endl;
	for (int i = 0; i < H; i++) {
		if (i % 2 == 0) {
			cout << S[i].substr(0, W - 1) << '#';
		}
		else {
			cout << '.';
			for (int j = 1; j < W; j++) {
				cout << '#';
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
  int a, b, c, d;
  
  cin >> a >> b >> c >> d;
  
  if (a + b > c + d)
    cout << "Left" << endl;
  
  else if (a + b < c + d)
    cout << "Right" << endl;
  
  else
    cout << "Balanced" << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define pb push_back
#define MAXN 21010
#define Scan(a) scanf("%I64d", &a)
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<ll, ll> II;
typedef vector<II> vi;

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int x, y, u, v;
    cin >> x >> y >> u >> v;
    FOR(i,1,v-y) cout << "U";
    FOR(i,1,u-x) cout << "R";
    FOR(i,1,v-y) cout << "D";
    FOR(i,1,u-x) cout << "L";
    cout << "L";
    FOR(i,1,v-y+1) cout << "U";
    FOR(i,1,u-x+1) cout << "R";
    cout << "D";
    cout << "R";
    FOR(i,1,v-y+1) cout << "D";
    FOR(i,1,u-x+1) cout << "L";
    cout << "U";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<complex>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
#define EPS (long double) 1e-8
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};

int main(void) {
	while(true) {
		int r, n;
		cin>>r>>n;
		if(r == 0 && n == 0) break;
		vector<int> _h(40, 0);
		REP(i, n) {
			int xl, xr, h;
			cin>>xl>>xr>>h;
			FOR(j, xl, xr) {
				_h[j + 20] = max(h, _h[j + 20]);
			}
		}
		long double lb = 0, ub = 21;
		int cnt = 0;
		while(cnt < 10000) {
			long double mid = (lb + ub) / 2;
			bool def = true;
			REP(i, r) {
				if(_h[19 - i] - ((mid - r) + sqrt(r * r - i * i)) < - EPS) def = false;
				if(_h[20 + i] - ((mid - r) + sqrt(r * r - i * i)) < - EPS) def = false;
			}
			if(def) lb = mid;
			else ub = mid;
			++cnt;
		}
		cout<<fixed<<showpoint<<setprecision(39)<<lb<<endl;
	}
}

Measured memory_bytes: 3272
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3172
import math
a,b,C = map(float, input().split())
print(a*b*math.sin(math.radians(C))/2)
print(a + b + math.sqrt(pow(a,2) + pow(b,2) -2 * a * b * math.cos(math.radians(C))))
print(b*math.sin(math.radians(C)))


Measured memory_bytes: 7704
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    y = list()

    for i in range(n):
        xi, li = map(int, input().split())
        # y.append((xi - li + 1, xi + li - 1))
        y.append((xi - li, xi + li))

    count = 1
    sorted_y = sorted(y, key=lambda x: x[1])
    end_point = sorted_y[0][1]

    for left, right in sorted_y[1:]:
        if left >= end_point:
            end_point = right
            count += 1

    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 19028
def main():

    H, W = map(int, input().split())
    h1, w1 = map(int, input().split())
    h2, w2 = map(int, input().split())
    h1 = h1-1
    w1 = w1-1
    h2 = h2-1
    w2 = w2-1
    S = []
    for _ in range(H):
        S.append(input())

    cur = [[h1, w1]]
    visited = set([(h1, w1)])
    vis = set([(h1, w1)])
    count = 0
    mv = [[-1, 0], [1, 0], [0, 1], [0, -1]]
    while cur:
        while cur:
            temp = []
            for h, w in cur:
                for i, j in mv:
                    x, y = h+i, w+j
                    if 0 <= x < H and 0<= y < W and (x, y) not in visited and S[x][y] == '.':
                        visited.add((x, y))
                        vis.add((x, y))
                        temp.append([x, y])
                        if (x, y) == (h2, w2):
                            return count
            cur = temp

        # print(cur)
        cur = []
        count += 1
        temp = set()
        for h, w in vis:
            for i in range(-2, 3):
                for j in range(-2, 3):
                    x, y = h+i, w+j
                    if 0 <= x < H and 0<= y < W and (x, y) not in visited and S[x][y] == '.':
                        cur.append([x, y])
                        visited.add((x, y))
                        temp.add((x, y))
                        if (x, y) == (h2, w2):
                            return  count
        # print(cur)
        vis = temp
    return -1


if __name__ == '__main__':
    print(main())

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

using namespace std;

#define endl '\n'

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 100000 + 10;

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

    int n; cin >> n;

    int64 answer = 0;
    int64 cumsum = 0;

    map<int64,int> freq;
    freq[cumsum]++;

    for (int i = 0; i < n; ++i){
        int64 v; cin >> v;
        cumsum += v;

        answer += freq[cumsum]++;
    }

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=3005,mod=1e9+7;
int n,q;
int a[N];
int dp[N][N];
int Pow(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=(LL)x*x%mod)
		if (y&1)
			ans=(LL)ans*x%mod;
	return ans;
}
int Div2(int x){
	return (x&1)?((x+mod)>>1):(x>>1);
}
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
int add(int x,int y){
	return x+y>=mod?x+y-mod:x+y;
}
int main(){
	n=read(),q=read();
	for (int i=1;i<=n;i++)
		a[i]=read();
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			dp[i][j]=a[i]<a[j]?1:0;
	for (int t=1;t<=q;t++){
		int a=read(),b=read();
		for (register int i=1;i<=n;i++){
			if (i==a||i==b)
				continue;
			dp[i][a]=dp[i][b]=Div2(add(dp[i][a],dp[i][b]));
			dp[a][i]=dp[b][i]=Div2(add(dp[a][i],dp[b][i]));
		}
		dp[a][b]=dp[b][a]=Div2(add(dp[a][b],dp[b][a]));
	}
	int ans=0;
	for (register int i=1;i<=n;i++)
		for (register int j=1;j<i;j++)
			Add(ans,dp[i][j]);
	ans=(LL)ans*Pow(2,q)%mod;
	cout << ans;
	return 0;
}


Measured memory_bytes: 35456
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 1000000007
using namespace std;
int main()
{
 	speed_up
 	ll r;cin>>r;
 	ll ar=3*r*r;
 	cout<<ar;
	
	
	
	
	
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

typedef pair<int, int> P;
int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, -1, 0, 1 };

int main()
{
    int h, w;
    int ch, cw;
    int dh, dw;
    cin >> h >> w;
    cin >> ch >> cw;
    cin >> dh >> dw;
    ch--; cw--; dh--; dw--;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    
    vector<vector<int>> dist(h, vector<int>(w, INF));
    dist[ch][cw] = 0;
    deque<P> dq;
    dq.push_front(make_pair(ch, cw));
    // 01-BFS
    // コスト0で行けるマスはdequeの先頭に追加、
    // コスト1で行けるマスはdequeの末尾に追加
    while (!dq.empty()) {
        int x = dq.front().first;
        int y = dq.front().second;
        dq.pop_front();
        int dist_now = dist[x][y];
        // 隣接マスへのコスト0移動
        rep(i, 4) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;  // 枠外
            if (s[nx][ny] == '#') continue;  // 壁
            if (dist[nx][ny] <= dist_now) continue;  // 進む予定のマスが現在のコストより既に低い
            dist[nx][ny] = dist_now;  // コストの更新
            dq.push_front(make_pair(nx, ny));  // 先頭に追加
        }
        // 5×5マスへのコスト1移動
        for (int mx = -2; mx <= 2; mx++) {
            for (int my = -2; my <= 2; my++) {
                int nx = x + mx;
                int ny = y + my;
                if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;  // 枠外
                if (s[nx][ny] == '#') continue;  // 壁
                if (dist[nx][ny] <= dist_now + 1) continue;  // 進む予定のマスが現在のコスト+1より既に低い
                dist[nx][ny] = dist_now + 1;  // コストの更新
                dq.push_back(make_pair(nx, ny));  // 末尾に追加
            }
        }
    }
    int ans = dist[dh][dw];
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/b.in", "r", stdin);
//  freopen("../IO/b.in", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


void solve(std::istream &in, std::ostream &out) {
  int n;
  in >> n;
  int64_t sum = 0;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 != 0 && i % 5 != 0) sum +=i;
  }
  out << sum << '\n';
}


Measured memory_bytes: 3640
a,b,c,d = gets.strip.split('').map{|x| x.to_i}

def calc(x, y, op)
  if op == '+'
    x + y
  else
    x - y
  end
end

['+', '-'].each do |op1|
  ['+', '-'].each do |op2|
    ['+', '-'].each do |op3|
      n = calc(calc(calc(a, b, op1), c, op2), d, op3)
      if n == 7
        puts "#{a}#{op1}#{b}#{op2}#{c}#{op3}#{d}=7"
        exit
      end
    end
  end
end


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int main() {
    ios_base::sync_with_stdio(false);
    int ans = 0;
    forn(i, 5) {
        int x;
        cin >> x;
        if (x == 0) {
            ans = i + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h> 
typedef long long ll;
using namespace std;
const ll mod =998244353; 
inline ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll n,k,ans,now,nx;
int main(){
	ll i,j;
    //freopen("a.in","r",stdin);
    n=read();
    ll x=sqrt(n);
    for(i=2;i*i<=n;i++){
    	if(n%i==0){
			now=n;
			while(now%i==0) now/=i;
			if(now%i==1) ans++;
		}
    }
    n--;
    x=sqrt(n);
    for(i=1;i*i<=n;i++){
    	if(n%i==0) {ans+=2;
    	if(i*i==n) ans--;}
    }
    printf("%lld",ans);
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        try(Scanner sc = new Scanner(System.in)){
            int n = sc.nextInt();
            int[] A = new int[n];
            for(int i=0;i<n;i++){
                A[i] = sc.nextInt();
            }
            int m = sc.nextInt();
            int[] B = new int[m];
            for(int i=0;i<m;i++){
                B[i] = sc.nextInt();
            }
            for(int i=0;i<Math.min(n, m);i++) {
            	if(B[i]>A[i]) {
            		System.out.println(1);
            		return;
            	}
            	if(A[i]>B[i]) {
            		System.out.println(0);
            		return;
            	}
            }
            System.out.println(m>n?1:0);
        }
    }
}


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

int main() {
    ll n,b,a,minT,maxT,maxh=0,mid;
    cin>>n>>a>>b;
    vector<ll> h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
        maxh=max(maxh,h[i]);
    }
    minT=0;
    maxT=maxh/b+1;
    while(maxT-minT>1){
        mid=(minT+maxT)/2;
        ll cnt=0;
        for(int i=0;i<n;i++){
            if(h[i]-mid*b>0) cnt+=(h[i]-mid*b-1)/(a-b)+1;
        }
        if(cnt<=mid) maxT=mid;
        else minT=mid;
    }
    cout<<maxT<<endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<map>
#include<set>
using namespace std;

const int MAX = 3e5;
int h, w, m;
int hi[MAX], wi[MAX];
map<int, int> mh, mw;
int xh, xw;
set<int> nh, nw;

int main() {
    scanf("%d %d %d", &h, &w, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &hi[i], &wi[i]);
        mh[--hi[i]]++;
        mw[--wi[i]]++;
        if (xh < mh[hi[i]]) xh = mh[hi[i]];
        if (xw < mw[wi[i]]) xw = mw[wi[i]];
    }
    for (auto &x : mh) {
        if (x.second == xh) nh.insert(x.first);
    }
    for (auto &x : mw) {
        if (x.second == xw) nw.insert(x.first);
    }
    int cnt = 0;
    for (int i = 0; i < m; i++) {
        if (nh.find(hi[i]) != nh.end() && nw.find(wi[i]) != nw.end()) cnt++;
    }
    printf("%d\n", cnt < nh.size() * nw.size() ? xh + xw : xh + xw - 1);
    return 0;
}


Measured memory_bytes: 61888
#include <bits/stdc++.h>
using namespace std;
#define N 400001
#define mod 1000000007
#define inf 1000000000
#define pp pair<ll,ll>
typedef long long int ll;
typedef long double ld;
#define MP make_pair

#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++)     
void fastIO(void);

void decimal(int);
ll modmulti(ll, ll, ll);
ll modadd(ll, ll, ll);
ll modpower(ll, ll, ll);
ll gcd(ll, ll );
ll modinv(ll, ll);
int sum(int,int);



int main()
{  
   fastIO();
   ll a,b;
   cin>>a>>b;

   if((abs(a-b))%2==1)
      cout<<"IMPOSSIBLE\n";
   else cout<<(a+b)/2<<endl;
}























void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}

void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b, ll m){
   return ((a%m)*(b%m))%m;
}
ll modadd(ll a, ll b, ll m){
   return ((a%m)+(b%m))%m;
}
ll modpower(ll a, ll n, ll m){
   if(n==0)
      return 1;
   ll result = 1;
   while(n>0){
      if(n%2==1)
         result = modmulti(result,a,m);
      a = modmulti(a,a,m);
      n = n/2;
   }
   return result;
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a, ll m){
   return modpower(a,m-2,m);
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  
  REP(i,n){
    cin >> h[i];
  }
  
  REP(i,n-1){
    if(h[n-i-2] <= h[n-i-1]) continue;
    else if(h[n-i-2]-h[n-i-1] == 1){
      h[n-i-2]--;
    }
    else{
      cout << "No" << endl;
      return 0;
    }
  }
    

    
  cout << "Yes" << endl;

        
    
}

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

int main(){
  int n;
  cin>>n;
  int x[n];
  int y[n];
  rep(i,0,n){
    cin>>x[i];
    y[i]=x[i];
  }
  sort(y,y+n);
  int a=y[n/2-1];
  int b=y[n/2];
  rep(i,0,n){
    if(x[i]<=a) cout<<b<<endl;
    else cout<<a<<endl;
  }
}

Measured memory_bytes: 3712
#include <iostream>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

// A

bool info[110][110];
int data[110];

int main(){
    int N, M, p, K, i,j;
    
    while( cin >> N, N ){
        memset(info, false, sizeof(info));
        memset(data, 0, sizeof(data));

        for(i=1; i<=N; i++){
            cin >> M;
            for(j=0; j<M; j++){
                cin >> p;
                info[i][p] = true;
            }
        }

        cin >> K;
        for(i=0; i<K; i++){
            cin >> data[i];
        }

        int res = -1;
        int cnt = 0;
        for(i=1; i<=N; i++){
            for(j=0; j<K; j++){
                if( !info[i][data[j]] ) break;
            }
            if( j == K ){
                res = i;
                cnt++;
            }
        }

        cout << (cnt == 1 ? res : -1) << endl;
    }

    return 0;
}

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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())

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

const int MAXN = 1e5 + 5;

int par[MAXN];
int f(int x) {
  return par[x] == x ? x : par[x] = f(par[x]);
}
void spoji(int x, int y) {
  x = f(x); y = f(y);
  if(x == y) return;
  par[x] = y;
}

int p[MAXN];
int where[MAXN];

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

  int n, m; cin >> n >> m;

  REP(i, n) {
    par[i] = i;
    cin >> p[i];
    p[i] --;
    where[p[i]] = i;
  }

  REP(i, m) {
    int x, y; cin >> x >> y;
    x --;
    y --;
    spoji(x, y);
  }

  int sol = 0;
  REP(i, n) {
    if(f(i) == f(where[i])) {
      sol ++;
    }
  }

  cout << sol << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

int matrix[110][110];
int dist[110];
int visited[110];
int n;
queue<int> Q;

int main() {
  REP(x, 110) {
    REP(y, 110) {
      matrix[x][y] = 0;
    }
    dist[x] = (1 << 15);
    visited[x] = 0;
  }

  // int n;
  cin >> n;

  REP(_, n) {
    int v, num;
    cin >> v >> num;

    REP(i, num) {
      int cv;
      cin >> cv;
      matrix[v][cv] = 1;
    }
  }

  dist[1] = 0;
  Q.push(1);

  while (!Q.empty()) {
    int f = Q.front(); Q.pop();
    visited[f] = 1;

    // int updated = 0;
    FOR(v, 1, n + 1) {
      if (matrix[f][v]) {
        if (dist[v] > dist[f] + 1) {
          dist[v] = dist[f] + 1;
          // updated = 1;
          // cout << "update for " << v  << endl;
        }
        if (!visited[v]) {
          Q.push(v);
        }
      }
    }
    // if (updated == 0 && Q.empty()) {
    //   cout << "break!" << endl;
    //   break;
    // }
  }


  FOR(v, 1, n + 1) {
    if (dist[v] == (1 << 15)) {
      cout << v << " -1" << endl;
    } else {
      cout << v << " " << dist[v] << endl;
    }
  }


  return 0;
}

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

int main(){
    int n; cin>>n;
    int ans=1e9;
    for(int i=0;i<n;i++){
        int a; cin>>a;
        int t=0;
        while(a%2==0){
            t++;
            a/=2;
        }
        ans=min(ans,t);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int a[SIZE],b[SIZE],low[SIZE],up[SIZE];
int main(){
    DRI(n);
    REP(i,n)
        RI(a[i]);
    REP(i,n)
        RI(b[i]);
    REP(i,n){
        up[i]=min(a[i],b[i]);
        low[i]=1;
        if(!i||a[i]>a[i-1])low[i]=a[i];
    }
    for(int i=n-1;i>=0;i--){
        if(i==n-1||b[i]>b[i+1])low[i]=max(low[i],b[i]);
    }
    int an=1;
    REP(i,n){
        if(low[i]>up[i])an=0;
        an=an*(LL)(up[i]-low[i]+1)%MOD;
    }
    cout<<an<<endl;


    return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
  vector<P> vec;
  vector<ll> comp;
  ll n;
  cin>>n;
  for(int i=0;i<n;i++){
    ll a,b;
    cin>>a>>b;
    if(a>b) swap(a,b);
    vec.push_back(P(a,b));
    comp.push_back(a);
    comp.push_back(b);
  }
  sort(comp.begin(),comp.end());
  comp.erase(unique(comp.begin(),comp.end()),comp.end());
  sort(vec.begin(),vec.end());
  ll max_max=0,midx=0;
  for(int i=0;i<n;i++){
    if(vec[i].second>=max_max){
      max_max=vec[i].second;
      midx=i;
    }
  }
  ll min_max=0,max_min=174417441744,min_min=vec[0].first;
  for(int i=0;i<n;i++){
    min_max=max(min_max,vec[i].first);
    max_min=min(max_min,vec[i].second);
  }
  ll ans=(min_max-min_min)*(max_max-max_min);
  ll k=(max_max-min_min);
  if(midx!=0){
    ll ridx=1;
    multiset<ll> ms;
    for(int i=1;i<n;i++) ms.insert(vec[i].first);
    ms.insert(vec[0].second);
    for(int i=1;i<n;i++){
      ans=min(ans,k*((*ms.rbegin())-(*ms.begin())));
      ms.erase(ms.find(vec[i].first));
      ms.insert(vec[i].second);
      ans=min(ans,k*((*ms.rbegin())-(*ms.begin())));
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 17628
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    if (N%2!=0){
      System.out.println("No");
      System.exit(0);
    }
    String left = S.substring(0,N/2);
    String right = S.substring(N/2,N);
    String ans =left.equals(right)? "Yes" : "No";
    System.out.println(ans);
  }
}

Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin>>s;
  int res=0;
  rep(i,4){if(s[i]=='+')res++;else res--;}
  cout<<res<<endl;


  return 0;

}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC096_A solver = new ABC096_A();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC096_A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();

            int ans = a;

            if (a <= b) {
                out.print(ans);
            } else {
                out.print(ans - 1);
            }
        }

    }
}



Measured memory_bytes: 22736
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]
ac_list = [0] * (n+1)
for i in range(n):
    ac_list[i+1] = ac_list[i] + (1 if s[i:i+2] == 'AC' else 0)
# print(ac_list)
for i in range(q):
    print(ac_list[lr[i][1]-1] - ac_list[lr[i][0]-1])

Measured memory_bytes: 32308
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
an = 0
bf = 0
for i in a:
    an += b[i - 1]
    if bf != 0 and i == bf + 1:
        an += c[i - 2]
    else:
        pass
    bf = i
print(an)


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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

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

Measured memory_bytes: 256
def selectionSort(A, N):
    swap_count = 0
    for i in range(N):
        minj = i
        for j in range(i + 1, N):
            if A[j] < A[minj]:
                minj = j
        if minj != i:
            A[minj], A[i] = A[i], A[minj]
            swap_count += 1
    return swap_count


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    count = selectionSort(A, N)
    print(' '.join(map(str, A)))
    print(count)



Measured memory_bytes: 5600
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

string str;

void put(char turn) {
    char target = (turn == 'o') ? 'x' : 'o';
    int left = 0, right = 0;
    for (int i = 0; i < str.length(); ++i) {
        if (str[i] == target) left++;
        else break;
    }
    for (int i = str.length() - 1; i >= 0; --i) {
        if (str[i] == target) right++;
        else break;
    }

    if (left == 0 && right == 0) return;
    if (left >= right) {
        for (int i = 0; i < left; ++i) str[i] = turn;
        str = turn + str;
    }
    if (left < right) {
        for (int i = str.length() - 1; i >= str.length() - right; --i) str[i] = turn;
        str = str + turn;
    }
}

bool finish() {
    char c = str[0];
    bool finish = true;
    for (int i = 0; i < str.length(); ++i) {
        if (str[i] != c) finish = false;
    }
    return finish;
}

int main (int argc, char *argv[]) {
    getline(cin, str);
    char turn = 'o';
    while(!finish()) {
        put(turn);
        turn = (turn == 'o') ? 'x' : 'o';
    }
    cout<<str[0]<<endl;
    return 0;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n; i++)
#define all(a) (a).begin(),(a).end()


int main(){
  int n;
  cin >> n;
  vector<int> p(n), f(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> f[i];
  sort(all(f));
  vector<int> p_st = p;
  sort(all(p_st));
  int wins = 0;
  for(int i=0, j=0; j<n; j++){
    if(p_st[i] < f[j]){
      wins++;
      i++;
    }
  }
  int won = 0;
  vector<int> ans(n);
  set<pair<int, int> > s;
  rep(i, n){
    s.insert(make_pair(p[i], i));
  }
  rep(i, n){
    int win_bd = upper_bound(all(f), p[i]) - f.begin();
    auto check = [&](int x){
      if(x >= f.size()) return false;
      int tmp = (f[x] > p[i] ? 1 : 0);
      int k = 0;
      for(auto &y: s){
        if(y.second == i) continue;
        while(k < f.size() && y.first >= f[k] || k == x) k++;
        if(k < f.size()){
          tmp++;
          k++;
        }
      }
      return tmp == (wins - won);
    };
    if(win_bd < f.size() && check(win_bd)){
      // win
      int ok = win_bd;
      int ng = f.size()+1;
      while(abs(ok-ng) > 1){
        int mid = (ok+ng)/2;
        if(check(mid)){
          ok = mid;
        }else{
          ng = mid;
        }
      }
      // cout << f[ok] << " <- OK" << endl;
      ans[i] = f[ok];
      f.erase(f.begin()+ok);
      won++;
    }else{
      // lose
      int ok = 0;
      int ng = f.size();
      while(abs(ok-ng) > 1){
        int mid = (ok+ng)/2;
        if(check(mid)){
          ok = mid;
        }else{
          ng = mid;
        }
      }
      // cout << f[ok] << " <- OK(lose)" << endl;
      ans[i] = f[ok];
      f.erase(f.begin()+ok);
    }
    s.erase(make_pair(p[i], i));
  }

  rep(i, n){
    cout << ans[i] << (i == n-1 ? "\n" : " ");
  }
}



Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
typedef long long 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; }
int main() {
  ll N;
  cin >> N;
  vector<vector<ll>> a(100100, vector<ll>(3));
  vector<vector<ll>> dp(100100, vector<ll>(3));
  for(ll i = 0;i<N;i++){
    for(ll j = 0;j<3;j++){
      cin >> a[i][j];
    }
  }
  for(ll i = 0;i<N;i++){
    for(ll j = 0;j<3;j++){
      for(ll k = 0;k<3;k++){
        if(j == k) continue;
        chmax(dp[i+1][j],dp[i][k] + a[i][j]);
      }
    }
  }
cout << max(dp[N][0],max(dp[N][1],dp[N][2]))<<endl;
  
}

Measured memory_bytes: 11136
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    arms = []
    # 区間スケジューリング
    for _ in range(n):
        x, l = input_int_list()
        arms.append((x - l, x + l))
    arms = sorted(arms, key=lambda x: x[1])
    prev_r = -float("inf")
    cnt = 0
    for left, right in arms:
        if prev_r > left:
            continue
        cnt += 1
        prev_r = right

    print(cnt)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 81088
#include <stdio.h>
  #include <math.h>
  #include <stdlib.h>
  int cmpfunc (const void * b, const void * a) {
   return ( *(int*)a - *(int*)b );
}
  int min(int a,int b){
    return a<b ? a:b;
  }
  int max(int a,int b){
    return a>b ? a:b;
  }

  int main() {
    long long int N,K,max=0;
    int tab[200005]={0};
    scanf("%lld %lld",&N,&K);
    for (int i = 0; i < N; i++) {
      scanf("%lld",&tab[i]);
    }
    qsort(tab, 200005, sizeof(int), cmpfunc);
    for (int i = K; i <200005; i++) {
      max+=tab[i];
    }
    printf("%lld\n",max );
    return 0;
  }


Measured memory_bytes: 1788
// 　　＿＿
// 　／　<＠ﾌ
//  ｜(ﾉﾉハ))
//  ﾉ从ﾟヮﾟ从
// 　ﾉ｜ｿﾉГ|つ author:hotarunx
// 〈_ﾉ^^^ヽ|
// 　~~tｧtｧ~
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

class Combination {
   private:
    long long maxn;
    long long mod;
    vector<long long> fact, rev_fact;

   public:
    // コンストラクタ。maxn: 組み合わせのnの最大値。m: mod
    Combination(long long maxn, long long mod) : maxn(maxn), mod(mod) {
        setFact(maxn);
    }

    // 1からnの階乗とその逆元を前計算
    void setFact(long long n) {
        fact.resize(n + 1);
        rev_fact.resize(n + 1);
        fact[0] = 1;
        for (long long i = 1; i <= n; i++) {
            fact[i] = fact[i - 1] * i;
            fact[i] %= mod;
        }
        rev_fact[n] = modpow(fact[n], mod - 2, mod);
        for (long long i = n - 1; i >= 0; i--) {
            rev_fact[i] = rev_fact[i + 1] * (i + 1);
            rev_fact[i] %= mod;
        }
    }

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

    // n種類のものからk個選ぶ場合の数
    long long c(long long n, long long k) {
        if (!(0 <= n && n <= maxn) || !(0 <= k && k <= maxn)) return -1;
        return (((fact[n] * rev_fact[k]) % mod) * rev_fact[n - k]) % mod;
    }

    // n種類のものから重複を許してk個選ぶ場合の数
    // n+k-1<=maxn とすること
    long long h(long long n, long long k) { return c(n + k - 1, k); }

    // n種類のものからk個選んで並び替える場合の数
    long long p(long long n, long long k) {
        if (!(0 <= n && n <= maxn) || !(0 <= k && k <= maxn)) return -1;
        return fact[n] * rev_fact[n - k] % mod;
    }
};

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

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

    int evens = 0, odds = 0;

    for (auto &&i : a) {
        if (i % 2)
            odds++;
        else
            evens++;
    }

    Combination c(100, 1000000007);

    // 食べるビスケットの枚数を2で割ると余りが1に等しくなる
    // → 奇数枚の袋を奇数個食べた
    // 食べるビスケットの枚数を2で割ると余りが0に等しくなる
    // → 奇数枚の袋を偶数個食べた

    // 偶数枚の袋はどのように食べてもいい

    // 条件を満たすように奇数枚の袋と、偶数枚の袋を選んで食べる場合の数を求める
    // 両方をかける

    int even_ways = 0, odd_ways = 0;

    // p=1のとき、odd_ways は n個の袋から1個を選ぶ+n個の袋から3個を選ぶ+...
    // p=0はにたような感じで
    // つまり
    // odd_ways = Σ nCi (if i%2==p) (nは奇数枚の袋の数)
    for (int i = 0; i <= odds; i++) {
        if (i % 2 == p) {
            odd_ways += c.c(odds, i);
        }
    }

    // 偶数枚の袋を選ぶ場合の数は 2^(evens)
    even_ways = pow(2, evens);

    const int ans = even_ways * odd_ways;

    cout << ans << endl;
}


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


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

    int N, K;
    cin >> N >> K;
    vector<pair<ll, int>> v;
    for(int i=0; i<N; i++){
        ll a, b;
        cin >> a >> b;
        v.push_back(make_pair(b, a));
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    set<int> s;
    priority_queue<ll, vector<ll>, greater<ll>> q;
    ll sum = 0;
    ll kind = 0;
    for(int i=0; i<K; i++){
        sum += v[i].first;
        if(!s.count(v[i].second)){
            s.insert(v[i].second);
            kind++;
        }else{
            q.push(v[i].first);
        }
    }
    ll ans = sum + kind*kind;
    for(int i=K; i<N; i++){
        if(q.empty()) break;
        if(!s.count(v[i].second)){
            kind++;
            sum -= q.top();
            q.pop();
            sum += v[i].first;
            s.insert(v[i].second);
            ans = max(ans, sum+kind*kind);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5232
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int d, t, s;

int main() {
    scanf("%d%d%d", &d, &t, &s);
    if (t * s >= d) printf("Yes\n");
    else 
        printf("No\n");
    return 0;
}

Measured memory_bytes: 3188
from __future__ import division
import io, sys, atexit, os, itertools
sys.stdout = io.BytesIO()
atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
sys.stdin = io.BytesIO(sys.stdin.read())
raw_input = lambda: sys.stdin.readline().rstrip()
 
o = raw_input()
e = raw_input()
l = list()
j = k = 0
for i in range(len(o)+len(e)):
	if i%2:
		l.append(e[k])
		k += 1
	else:
		l.append(o[j])
		j += 1

print(''.join(l))

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

int main(){
    int cnt = 0;
    int n; cin >> n;
    vector<int> a(n); rep(i,n) cin >> a[i];

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

    put(cnt/2);
}

Measured memory_bytes: 640
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

numToCost = [nil,2,5,5,4,5,6,3,7,6]

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

nn = inputs[0][0]
lst = inputs[1]

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
  p nn
  p lst
end

dp = [""]
for i in 1..nn
  cand = [""]
  lst.each do |l_i|
    pd "l_i=#{l_i}, #{numToCost[l_i]}"
    if i - numToCost[l_i] >= 0 
      tmp = dp[i - numToCost[l_i]]
      if dp[i - numToCost[l_i]] != ""
        if tmp[0..0].to_i > l_i
          cand << tmp + l_i.to_s
        else
          cand << l_i.to_s + tmp 
        end
      end
    end
    if i - numToCost[l_i] == 0
      cand << l_i.to_s
    end
  end

  
  tmp_max = cand[0]
  cand.each do |c_i|
    if c_i.length > tmp_max.length 
      tmp_max = c_i
    elsif c_i.length == tmp_max.length  and c_i > tmp_max
      tmp_max = c_i
    end
  end

  dp[i] = tmp_max

  pd i
  pd cand
  pd dp[i]
  
end

pd dp

puts dp[nn]


Measured memory_bytes: 47996
#include <bits/stdc++.h>
#define int long long
using namespace std;
int ans = 1;
int mod  =1e9 + 7;
int a[400005];
main()
{

    int n;
    cin>>n;
    for(int i = 0; i<n; i++){
        cin>>a[i];
    }
    for(int i =0; i<61; i++){
            int on = 0,off = 0;
        for(int j =0; j<n; j++){
            if(a[j] & (1LL<<i))on++;
            else off++;
        }
        int cur = on * off;
        cur%=mod;
        cur = ((cur % mod) * ((1LL<<i) % mod)) %mod;
        ans = ((ans % mod) + (cur % mod))%mod;
    }
    cout<<ans-1<<endl;


    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>

using namespace std;

const int kSize = 101;

vector<int> adj[kSize];
bool isMarked[kSize];
int d[kSize];
int f[kSize];
int t = 1;

void dfs(int v) {
    isMarked[v] = true;
    d[v] = t;
    t++;

    for (int i = 0; i < adj[v].size(); ++i) {
        int u = adj[v][i];
        if (!isMarked[u]) {
            dfs(u);
        }
    }
    f[v] = t;
    t++;
}

int main() {
    int n;
    fill(isMarked, isMarked + kSize, false);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int id, k;
        cin >> id >> k;
        for (int j = 0; j < k; ++j) {
            int v;
            cin >> v;
            adj[id].push_back(v);
        }
    }

    //dfs(1);
    for (int i = 1; i <= n; ++i) {
        if (!isMarked[i]) {
            dfs(i);
        }
    }
    for (int i = 1; i <= n; ++i) {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3148
#include <vector>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <numeric>

typedef long long ll;

using namespace std;
int main(){
	int n;
	cin >> n;
	string msg = "No";
	
	for (int i=0; i*4<=100; ++i){
		for (int j=0; j*7<100; ++j){
			int x = i*4 + j*7;
			if (x==n){
				msg = "Yes";
				cout << msg << endl;
				return 0;
				}
			}
		}
	cout << msg << endl;
	return 0;
}

Measured memory_bytes: 256