akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

const double PI  = 3.141592653589793238463;
const int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec){
        is >> x;
    }
    return is;
}

string solve(int n, const string& s){
    string t;
    transform(begin(s), end(s), back_inserter(t),
              [=](char c){return (c + n - 'A') % ('Z' - 'A' + 1) + 'A';});
    return t;
}

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

    int n;
    string s;
    cin >> n >> s;
    cout << solve(n, s) << "\n";

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          int num1 = sc.nextInt();
          int num2 = sc.nextInt();
          if(num1 <=5 ){
            System.out.println(0);
          } else if(num1 >= 13){
            System.out.println(num2);
          } else {
            System.out.println(num2 / 2);
          }
          }
    }

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

int par[10001];
int high[10001];
//n要素で初期化
void init(int n){
  for(int i=0; i<n; i++){
    par[i]=i;
    high[i]=0;
  }
}
//木の根を求める
int find(int x){
  if(par[x]==x){
    return x;
  }
  else{
    return par[x]=find(par[x]);
  }
}

//xとyの属する集合を併合
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(high[x]<high[y]){
    par[x]=y;
  }else{
    par[y]=x;
    if(high[x]==high[y])high[x]++;
  }
}
//xとyが同じ集合に属するか否か
bool same(int x,int y){
  return find(x)==find(y);
}   
int main(){
	int a[7]={1,3,5,7,8,10,12};
  	int b[4]={4,6,9,11};
  	init(13);
  	for(int i=1; i<7; i++){
      unite(a[0],a[i]);
    }
  	for(int i=1; i<4; i++){
      unite(b[0],b[i]);
    }
  	int x,y;
  	cin>>x>>y;
	if(same(x,y))cout<<"Yes"<<endl;
  	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/m-solutions2019/tasks/m_solutions2019_d
//D - Maximum Sum of Minimum
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}

template< typename T >
struct edge {
	int src, to;
	T cost;
	edge(int _to, T _cost) : src(-1), to(_to), cost(_cost) {}
	edge(int _src, int _to, T _cost) : src(_src), to(_to), cost(_cost) {}
	edge &operator=(const int &x) {
		to = x;
		return *this;
	}
	operator int() const { return to; }
};

template< typename T>
struct node {
	vector<edge<T>> edges;
    ll score=0;
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< node< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N; cin>>N;
    WeightedGraph<ll> graph(N+1);
    FOR(i,0,N-1){
        ll a,b; cin>>a>>b;
        graph.at(a).edges.emplace_back(a,b,0);
        graph.at(b).edges.emplace_back(b,a,0);
    }
    vector<ll> cn(N); //昇順
    FOR(i,0,N){
        cin>>cn.at(i);
    }
    sort(cn.begin(), cn.end());

    ll max_edges_node, max_edges_num=0;
    FOR(i,1,N+1){
        if (chmax<ll>(max_edges_num,graph.at(i).edges.size())){
            max_edges_node=i;
        }
    }

    //nodeに点を入れる
// function 幅優先探索(v)
//     Q ← 空のキュー
//     v に訪問済みの印を付ける
//     v を Q に追加
//     while Q が空ではない do
//         v ← Q から取り出す
//         v を処理する
//         for each v に接続している頂点 i do
//             if i が未訪問 then
//                 i に訪問済みの印を付ける
//                 i を Q に追加
    auto tree_bfs = [&](auto& g, int s){
	    using Pi = pair<ll, int>; //dist,node id
	    priority_queue<Pi, vector<Pi>, less<Pi>> que;
	    vector<bool> visit(g.size(), false);
        visit[s]=true;
        que.emplace(g[s].edges.size(), s);
        while(!que.empty()){
		    ll tmp;
		    int idx; //node id
		    tie(tmp, idx) = que.top();
		    que.pop();
            //vを処理する
            dump(idx);
            g.at(idx).score = cn.back();
            cn.pop_back();

			for(auto &e : g[idx].edges) {
                if(visit[e.to]) continue;
				visit[e.to] = true;
				que.emplace(g[e.to].edges.size(), e.to);
			}
		}
    };

    tree_bfs(graph,max_edges_node);
    ll ans=0;
    FOR(i,1,N+1){
        for(auto& e:graph[i].edges){
            ans += min(graph[e.to].score, graph[e.src].score);
        }
    }
    assert(ans%2==0);
    cout<<ans/2<<endl;
    FOR(i,1,N+1){
        cout<<graph[i].score<<endl;
    }
    return 0;
}

Measured memory_bytes: 1532
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t H, W;
    cin >> H >> W;
    int64_t ans = min(H, W);
    if (H % 3 == 0|| W % 3 == 0) {
        cout << 0 << endl;
        return 0;
    }
    for(int64_t i = 1; i < W + 1; i++){
        ans = min(ans, max((H + 1) / 2 * i, (W - i) * H) - min(H / 2 * i, (W - i) * H));
    }
    for(int64_t i = 1; i < H + 1; i++){
        ans = min(ans, max((W + 1) / 2 * i, (H - i) * W) - min(W / 2 * i, (H - i) * W));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template<typename T> void swap(T *t1, T *t2){ T* tmp=t1; t1=t2; t2=tmp;}
Int tmpi = 0;
double tmpd = 0.0;


struct Restaurant {
    string name;
    Int p;
    Int id;

    Restaurant(string name_, Int p_, Int id_){
        id = id_;
        name = name_;
        p = p_;
    }

    bool operator<(const Restaurant &another) const {
        if(name == another.name){
            return p > another.p;
        }
        return name < another.name;
    }
};

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

    Int n, p;
    string s;
    vector<Restaurant> v;
    cin >> n;
    for(Int i=0; i<n; i++){
        cin >> s >> p;
        v.push_back(Restaurant(s, p, i+1));
    }
    sort(v.begin(), v.end());
    for(Int i=0; i<n; i++){
        cout << v[i].id << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(a) a, a+sizeof(a)/sizeof(a[0])
using namespace std;

ll gcd(ll n, ll m) {
	if (m == 0) return n;
	return gcd(m, n % m);
}

ll lcm(ll n, ll m) {
	return m / gcd(n, m) * n;
}

int main(void) {
	int a, b;
	cin >> a >> b;
	cout << (a + b) / 2 << endl;
	return 0;
}


Measured memory_bytes: 3112
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        
        if(s.contains("A") && s.contains("B")){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21716
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n,u,k,p;
bool adm[105][105];
int main()
{
    memset(adm,false,sizeof(adm));
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&u,&k);
        while(k--)
        {
            scanf("%d",&p);
            adm[u][p]=true;
        }
    }
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)printf("%d%c",adm[i][j]?1:0,j==n?'\n':' ');
    return 0;
}


Measured memory_bytes: 3240
k, n = gets.chomp.split(' ').map{|i| i.to_i }

a1 = 0
old = -1
sum = 0
max = 0

alast = gets.chomp.split(' ').map{|i|
  ii = i.to_i
  if old == -1
    a1 = ii
    old = ii
    next
  end
  diff = ii - old
  sum += diff
  max = diff if max < diff
  old = ii
  ii
}.last

uediff = k - (alast - a1)
sum += uediff
max = uediff if max < uediff

puts sum - max


Measured memory_bytes: 16644
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,A,B = MI()
v = LI()
v.sort(reverse=True)

print(sum(v[0:A])/A)

kaijou = [1]
for i in range(1,N+1):
    kaijou.append(kaijou[-1]*i)

def nCr(n,r):
    if n < r:
        return 0
    else:
        return (kaijou[n]//kaijou[r])//kaijou[n-r]

if v[0] != v[A-1]:
    a,b = 0,0  # v[A-1] より大きい元の個数、v[A-1] と等しい元の個数
    for i in range(N):
        if v[i] > v[A-1]:
            a += 1
        elif v[i] == v[A-1]:
            b += 1
    print(nCr(b,A-a))
else:
    a = v.count(v[A-1])
    print(sum(nCr(a,i) for i in range(A,B+1)))


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

#define pb push_back
#define ll long long
using namespace std;

const int mod = 1e9 + 7;

int pow(int n, int x) {
    ll res = 1;
    while (n) {
        if (n & 1) res = (res * x) % mod;
        x = ((ll)x * x) % mod;
        n >>= 1;
    }
    return res;
}

int inv(int x) { return pow(mod - 2, x); }

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int T = 0; T < t; T++) {
        ll n;
        cin >> n;
        ll a[n], sum = 0, sqsum = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            sum += a[i];
            sqsum += ((a[i] * a[i]) % mod);
            sum %= mod;
            sqsum %= mod;
        }
        ll ans = (((sum * sum) % mod - sqsum % mod + mod)) % mod;
        cout << ans * (ll)inv(2) % mod << endl;
    }
    return 0;
}


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

#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define mp make_pair
#define pb push_back

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b,c,k,ans=0;
	cin >> a >> b >> c >> k;
	if (a <= k) {ans += a; k-=a;}
	else {ans += k; k=0;}
	if (b <= k) {k-=b;}
	else {k=0;}
	// cout << "k = " << k << "\n";
	if (c <= k) {ans -= c;}
	else {ans -= k; k=0;}
	cout << ans << "\n";
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,ll>pa;

const int N=2e5+100;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

char s[N];
int main()
{
    int bf=0,tot=0;
    int n;cin>>n;
    cin>>s+1;
    for(int i=1;i<=n;i++){
        if(s[i]=='R') tot++;
    }
    for(int i=1;i<=tot;i++){
        if(s[i]=='R') bf++;
    }
    cout<<tot-bf<<endl;
}



Measured memory_bytes: 3792
// Problem : C - Reconciled?
// Contest : AtCoder - AtCoder Beginner Contest 065
// URL : https://atcoder.jp/contests/abc065/tasks/arc076_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a) for (int i=0; i<(a); i++)
#define rep1(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define imax INT_MAX
#define imin INT_MIN
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
ll perm(ll n)
{
	ll ans=1;
	l00p(i,2,n+1)
	{
		ans*=i;
		ans%=MOD;
	}
	return ans;
}
int main() {
	 
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int t=1;
	while(t--)
	{
		ll n,m;
		cin>>n>>m;
		if(abs(n-m)>1)
		cout<<0<<nl;
		else if(n==m)
			cout<<2*perm(n)*perm(n)%MOD;
		else
			cout<<perm(n)*perm(m)%MOD<<nl;
	}
	
    
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3684
import numpy as np
from numba import njit
i4 = np.int32
i8 = np.int64
u4 = np.uint32


@njit
def get_factorization(n):
    """
    nまでの割り切れる最小の素数を返す。
    """
    sieve_size = (n - 1) // 2
    sieve = np.zeros(sieve_size, u4)
    for i in range(sieve_size):
        if sieve[i] == 0:
            value_at_i = i*2 + 3
            for j in range(i, sieve_size, value_at_i):
                if sieve[j] == 0:
                    sieve[j] = value_at_i
    return sieve


@njit
def solve(A):
    a = np.sort(A)
    p_max = a[-1]
    p = get_factorization(p_max)
    primes_num = 1
    for i in range(p.shape[0]):
        if i*2 + 3 == p[i]:
            primes_num += 1
    a_start = 0
    while a[a_start] == 1:
        a_start += 1
        if a_start == a.shape[0]:
            return 0
    a = a[a_start:]
    if len(a) > primes_num:
        return 1
    check = np.zeros(p_max + 1, u4)
    for d in a:
        if d & 1 == 0:
            check[2] += 1
            d //= 2
            while d & 1 == 0:
                d //= 2
        prev = 2
        while d > 1:
            i = (d - 3) // 2
            f = p[i]
            if f > prev:
                check[f] += 1
                prev = f
            d //= f

    if check.max() > 1:
        return 1
    else:
        return 0


def main(in_file):
    stdin = open(in_file)
    stdin.readline()
    A = np.fromstring(stdin.readline(), u4, sep=' ')
    ans = solve(A)
    if ans:
        g = np.gcd.reduce(A)
        if g > 1:
            ans = 2
        else:
            ans = 1
    p = ['pairwise coprime', 'setwise coprime', 'not coprime']
    print(p[ans])


if __name__ == '__main__':
    main('/dev/stdin')


Measured memory_bytes: 140504
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int N = scan.nextInt();

        int M = scan.nextInt();

        int C = scan.nextInt();

        int B[] = new int[M];

        int A[] = new int[M*N];

        for(int i = 0; i < M; i++){

            B[i] = scan.nextInt();

        }

        for(int cnt = 0; cnt < M*N; cnt++){

                A[cnt] = scan.nextInt();

            }


        scan.close();

        int ans = 0;

        int cnt = 0;

        for(int howCodes = 0; howCodes < N; howCodes++){

            int calcAns = 0;

            for(int i = 0; i < M; i++){

                calcAns = calcAns + A[cnt] * B[i];
                cnt++;

            }
            calcAns = calcAns + C;

            if(calcAns > 0){
                ans++;
            }
        }


        System.out.print(ans);

    }
}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,r,g,b,n;
	cin>>r>>g>>b>>n;

	ll c=0;
	for(i=0;i*r<=n;i++){
		for(j=0;i*r+j*b<=n;j++){
			k=(n-(i*r+j*b));
			//cout<<i<<" "<<j<<" "<<k<<endl;
			if(k==0||(k>=g&&k%g==0)){
				
				c++;
			}
		}
	}
	cout<<c;
	return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) (a).begin(),(a).end()
typedef pair<int, int> P;
const long long mod = 1000000007;

struct UF {
	int N; vector<int>par, siz;
	void init(int n_) {
		par.resize(n_); siz.resize(n_); N = n_;
		rep(i, N) {
			par[i] = i; siz[i] = 1;
		}
	}
	int find(int x) {
		if (x == par[x])return x;
		return par[x] = find(par[x]);
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return false;
		if (siz[x] > siz[y])swap(x, y);
		par[x] = par[y];
		siz[y] += siz[x];
		return true;
	}
};

struct edge {
	int u, v, cost;
	bool operator <(const edge &A) const {
		return cost < A.cost;
	}

	bool operator >(const edge &A) const {
		return cost > A.cost;
	}
};

int modpow(int a, int x) {
	int res = 1;
	while (x) {
		if (x & 1)res = res * a%mod;
		a = a * a%mod;
		x >>= 1;
	}
	return res;
}
int n, m, x;
int u[2005], v[2005], w[2005];
int used[2005];
vector<edge>MST[1005];
int dist[1006][1006];

void dfs(int start, int now, int par) {
	for (auto e : MST[now]) {
		if (e.v == par)continue;
		dist[start][e.v] = max(dist[start][now] , e.cost);
		dfs(start, e.v, now);
	}
}

void constructdist() {
	rep(i, n) {
		dfs(i, i, -1);
	}
}
signed main() {
	cin >> n >> m >> x;
	priority_queue<edge, vector<edge>, greater<edge>>Q;
	vector<edge>G;
	rep(i, m) {
		cin >> u[i] >> v[i] >> w[i];
		u[i]--; v[i]--;
		G.push_back({ u[i], v[i], w[i] });
		Q.push(G[i]);
	}
	sort(all(G));
	int ans = 0;

	UF uf; uf.init(n);
	int cost = 0;
	rep(i, m) {
		if (uf.unite(G[i].u, G[i].v)) {
			cost += G[i].cost;
			used[i]++;
			MST[G[i].u].push_back({ G[i].u,G[i].v,G[i].cost });
			MST[G[i].v].push_back({ G[i].v,G[i].u,G[i].cost });
		}
	}
	if (cost == x) {
		ans += (modpow(2, n - 1) - 2 + mod)*modpow(2, m - n + 1) % mod;
	}

	constructdist();
	int e0 = 0, em = 0, ep = 0;
	rep(i, m) {
		if (used[i])continue;
		int D = cost + G[i].cost - dist[G[i].u][G[i].v] - x;
		if (D == 0) e0++;
		else if (D < 0)em++;
		else ep++;
	}
	ans += (modpow(2, e0) - 1)*modpow(2, ep + 1) % mod;
	ans %= mod;
	cout << ans << endl;
}


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

int main(){
  ll x,y;
  cin>>x>>y;
  ll ans;
  ans=(x>y?x-y+2:y-x);
  ans=min(ans,abs(y+x)+1);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
typedef long long ll;
const int MOD = 1000000007;
const int INF = 2002002002;
#define PI 3.141592653589
// 4方向探索用ベクトル
const int di[] = { -1, 0, 1, 0 };
const int dj[] = { 0, -1, 0, 1 };
using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	for (int i = 0; i < h; i++)
		cin >> s[i];
	int black = 0;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			if (s[i][j] == '#')
				black++;
	// s[0][0]からs[i][j]までの最短距離
	vector<vector<int>> dist(h, vector<int>(w, INF));
	queue<pair<int, int>> q;
	// 更新されていないマスを距離xで更新し、queueに入れる関数
	auto update = [&](int i, int j, int x) {
		// autoを使う利点は、main内で定義した配列を参照できる点
		if (dist[i][j] != INF)
			return;
		dist[i][j] = x;
		q.push(make_pair(i, j));
	};
	// 始点を0で更新
	update(0, 0, 0);
	while (!q.empty()) {
		// queueの先頭を保存し、取り出す
		int nowi = q.front().first;
		int nowj = q.front().second;
		q.pop();
		// 4方向探索
		for (int dir = 0; dir < 4; dir++) {
			// nowの隣接
			int nexti = nowi + di[dir];
			int nextj = nowj + dj[dir];
			// 隣接が定義範囲内か判定
			if (nexti < 0 || nexti >= h || nextj < 0 || nextj >= w)
				continue;
			// 隣接が障害物マスならqueueには入れない
			if (s[nexti][nextj] == '#')
				continue;
			// updateは、既に更新されているかどうかの判定を含む
			update(nexti, nextj, dist[nowi][nowj] + 1);
		}
	}

	if (dist[h - 1][w - 1] == INF)
		cout << -1 << endl;
	else
		cout << h * w - black - dist[h - 1][w - 1] - 1 << endl;

	return 0;
}


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

using namespace std;
#define lli long long int
#define mod 1000000007

char M[1005][1005];
int dp[1005][1005];

int main()
{
    int h,w,i,j;
    cin>>h>>w;
    for(i=1;i<=h;i++)
    {
        for(j=1;j<=w;j++)
        {
            cin>>M[i][j];
        }
    }
    dp[1][1]=1;
    for(i=1;i<=h;i++)
    {
        for(j=1;j<=w;j++)
        {
            if(M[i][j]=='#')
                dp[i][j]=0;
            else
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
            if(i==1 && j==1)
                dp[i][j]=1;
        }
    }
    cout<<dp[h][w]<<"\n";
    return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x, y) CPP_CAT_I(x, y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x, y) x##y

#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
// }}}

constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define M5 100007
#define M9 1000000000

// util {{{
#define FOR(i, start, end) for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); i < CPP_CAT(i, xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f, c, ...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); })(c))
#define ll long long int
#define VI vector<int>
template <typename C>
i64 SIZE(const C &c)
{
    return static_cast<i64>(c.size());
}

template <typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {})
{
    if (comp(xmax, x))
    {
        xmax = x;
        return true;
    }
    return false;
}

template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {})
{
    if (comp(x, xmin))
    {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit
{
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit()
    {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

bool isOK(int mid, double key)
{
}

int binary_search(double key)
{
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = 2000000000;
    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1)
    {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key))
            right = mid;
        else
            left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}

bool isKaibun(string st)
{
    bool ans = true;
    int n = st.length();
    REP(i, n / 2)
    {
        if (st[i] != st[n - i - 1])
        {
            return false;
        }
    }
    return true;
}

int toInt(char a)
{
    return a - '0';
}

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

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

void solve()
{
    int N, M;
    int x[5];
    REP(i, 5)
    {
        cin >> x[i];
        if (x[i] == 0)
        {
            cout << i + 1;
            return;
        }
    }
}

signed main()
{

    solve();

    return 0;
}


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

int main(void){
    int n,m,i,j,cnt,left,right;
    cin >> n >> m;
    vector<int>  L(m),R(m);

    for(i=0; i<m; i++){
        cin >> L.at(i) >> R.at(i);
    }

    //gate 0
    left = L.at(0);
    right = R.at(0);

    //gate 1 to m
    for(i=1; i<m; i++){
        if(L.at(i) > left){
            left = L.at(i);
        }

        if(R.at(i) < right){
            right = R.at(i);
        }
    }
    if(right >= left){
        cout <<  right - left + 1  << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
def solve():
  D = int(input())
  C = list(map(int, input().split()))
  S = [list(map(int, input().split())) for _ in range(D)]

  ans = [1]*D
  for d in range(D):
    maxi = 0
    contest = 0
    for i in range(26):
        if S[d][i]>maxi:
            contest = i
            maxi = S[d][i]
    ans[d] = contest+1
  
  return ans
print(*solve(),sep='\n')

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

#define pb push_back
#define all(a) a.begin(), a.end()
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repl(i, a, n) for (long long i = a; i < n; i++)
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vl vector<long long>
#define vvi vector<vector<int>>

#define tcases \
  int t;       \
  cin >> t;    \
  while (t--)

typedef long long ll;

// for debugging output uncomment below line
// #define DBG
//NOTE : COMMNET ABOVE LINE BEFORE SUBMITTING

#ifdef DBG
#define dout \
  if (true)  \
  cout
#define dfor \
  if (true)  \
  rep
#else
#define dout \
  if (false) \
  cout
#define dfor \
  if (false) \
  rep
#endif

using namespace std;

#define MOD 1000000007

void optimizeIO()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//==================================================================================///////////////////
///                  CLASHER
//////////////==========================================================//////////////////////////////

int main()
{
  // ifstream cin("input.txt");
  //for optimizing input output
  optimizeIO();
  int n, m;
  cin >> n >> m;
  vector<int> ar(n + 1, 0);
  vector<bool> b(n + 1, false);
  for (int i = 0; i < m; i++)
  {
    int a;
    string s;
    cin >> a >> s;
    if (!b[a])
    {
      if (s == "WA")
      {
        ar[a]++;
      }
      else
      {
        b[a] = true;
      }
    }
  }

  int c = 0, w = 0;
  // for (int i = 0; i < n+1; i++){
  //   cout << " : " << ar[i];
  // }
  for (int i = 1; i <= n; i++)
  {
    if (b[i])
    {
      c++;
      w += ar[i];
    }
  }
  cout << c << " " << w;

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<numeric>
using namespace std;
using ll = long long int;
int n;
vector<ll> a;
ll suml = 0, sumr = 0;
ll ret = 1000000000000000;
int main(void) {
	cin >> n;
	for (size_t i = 0; i < n; i++){
		ll ai;
		cin >> ai;
		a.push_back(ai);
		sumr += ai;
	}
	for (int i = 0; i < n - 1; i++) {
		suml += a[i];
		sumr -= a[i];
		ll tmp = abs(suml - sumr);
		if (tmp < ret) {
			ret = tmp;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
typedef long long ll;

using namespace std;
int gcm(int n, int m) {
    if (m > n) {
        swap(m, n);
    }
    int d = n%m;
    if (d == 0) {
        return m;
    }
    return gcm(m, d);
}

int main() {
    int N, M; cin >> N >> M;
    string s, t;
    cin >> s;
    cin >> t;
    
    int g = gcm(N, M);
    int i = N/g;
    int j = M/g;
    for (int mul = 0; mul < g; mul++) {
        int x = mul *i; int y = mul *j;
        if (s[x] != t[y]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << (ll)N/g*M<< endl;
    return 0;
}


Measured memory_bytes: 512
import itertools
N = int(input())
A = [0] + [int(a) for a in input().split()] + [0]
B = [0] + [int(a) for a in input().split()] + [0]

AA = list(itertools.accumulate(A))
BB = list(itertools.accumulate(B))

ma = 0
for i in range(1, N + 2):
    ma = max(AA[i] - BB[i-1], ma)

print(ma + BB[-1] if N > 1 else A[1] + B[1])


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


int main(){
    cin.sync_with_stdio(false);
    int n, a, b, c, x, y;
    while(cin >> n >> a >> b >> c >> x, n) {
        int ans = 0;
        rep(i, n) {
            cin >> y;
            while(x != y && ans < 10001) {
                x = (a * x + b) % c;
                ans++;
            }
            if (n - 1 > i) {
                x = (a * x + b) % c;
                ans++;
            }
        }
        cout << ((ans < 10001) ? ans : -1) << endl;
    }

    return 0;
}

Measured memory_bytes: 3112
num=1000000
prime=[1]*1000000
prime[0]=0
prime[1]=0
i=2
ans=0
while i<1000000:
 if prime[i]==1:
  ans+=1
 if i<1000:
  j=i*i
  while j<1000000:
   prime[j]=0
   j+=i
 prime[i]=ans
 i+=1
while True:
 try:
  n=input()
  print prime[n]
 except:
  break

Measured memory_bytes: 13756
import java.util.Scanner;
 
public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] btn = new int[N];
		for(int i = 0; i<N; i++) {
			btn[i] = sc.nextInt();
		}
		String s = "-1";
		int count = 0;
		int light = btn[0];
		while(true) {
			count++;	
			if(light == 2) {
			s = count+"";
				break;
			}
			light = btn[light-1];
			if(count > N) {
				break;
			}
			
			
		}
		System.out.println(s);
	}
	
}

Measured memory_bytes: 52616
S = input()
wb = ["0" if i % 2 == 0 else "1" for i in range(len(S))]
bw = ["1" if i % 2 == 0 else "0" for i in range(len(S))]

cnt_wb = 0
cnt_bw = 0
for i in range((len(S))):
  if wb[i] != S[i]:
    cnt_wb += 1
  if bw[i] != S[i]:
    cnt_bw += 1
    
print (min(cnt_wb, cnt_bw))

Measured memory_bytes: 4724
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }

// ll gcd(ll m, ll n){
//   if(m<n) swap(m,n);
//   if(n==0) return m;
//   return gcd(n, m%n);
// }

// ll get_pow(ll x, ll y){
//   ll ret=0;
//   ll temp = y;
//   while(true){
//     if(x<=temp) break;
//     ret++;
//     temp *= 2;
//   }
//   return ret;
// }



int main() {
  cout<<fixed<<setprecision(10);

  ll a,b;
  cin>>a>>b;
  ll ans;
  if(a>=13)ans=b;
  else if(a<=5)ans=0;
  else ans=b/2;

  cout << ans << endl;

}

















//


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

int main(){
    int N, M;
    cin >> N >> M;
    vector<ll> A(N);
    priority_queue<int, vector<int>, less<int>> pq;
    for(int i=0; i<N; i++){
        cin >> A[i];
        pq.push(A[i]);
    }
    ll res=0;
    for(int i=0; i<M; i++){
        int tmp=pq.top();
        pq.pop();
        pq.push(tmp/2);
    }
    while(!pq.empty()){
        res+=pq.top();
        pq.pop();
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4648
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	int i1=0;
	int i2=(int)s.size()-1;
	int v=0;
	while (i1<i2){
// 		cout<<i1<<" "<<i2<<endl;
		if (s[i1]==s[i2]){
			i1++;
			i2--;
		}
		else{
			if (s[i1]=='x'){
				v++;
				i1++;
			}
			else if(s[i2]=='x'){
				v++;
				i2--;
			}
			else{
				cout<<-1<<endl;
				return 0;
			}
		}
	}
	cout<<v<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)


int main(void){
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d",a*b);
	return 0;
}


Measured memory_bytes: 3812
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
    ll n, a, b;
    ll ans = 0;
    ll A[100005];
    cin>>n>>a>>b;
    for(ll i = 0; i < n; i++){
        cin>>A[i];
    }
    for(ll i = 1; i < n; i++){
        if((A[i]-A[i-1])*a > b)ans += b;
        else ans += (A[i]-A[i-1])*a;
    }
    cout<<ans;


    return 0;
}


Measured memory_bytes: 1024
/**
 * Author: Deb Natkh Maxim (debnatkh@gmail.com)
 * Date: 02.03.2019
 */

#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;

const int MAXN = 1e5;
vector <int> arr;

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

    int n;
    cin >> n;
    vector <pair <int, int> > E;
    int for_sum = ((n % 2 == 0) ? n + 1 : n);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i + j != for_sum && i < j) {
                E.push_back({i, j});
            }
        }
    }
    vector <int> sm(n + 1);
    cout << E.size() << endl;
    for (auto e : E) {
        sm[e.x]+=e.y;
        sm[e.y]+=e.x;
        cout << e.x << " " << e.y << "\n";
    }
    // cout << count(sm.begin(), sm.end(), sm[1]) << endl;

    return 0;
}

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

int dp[2][2], dc[2][2];
int A[100055], B[100055];

int N, Ans;

int main() {
	ios::sync_with_stdio(false);

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

	for(int i = 1; i <= N; i += 2) B[A[i]]++;
	for(int i = 1, k, c; i <= 100000; i++) {
		k = i; c = B[i];
		if(dc[0][0] < c) {
			swap(c, dc[0][0]);
			swap(k, dp[0][0]);
		}
		if(dc[0][1] < c) {
			swap(c, dc[0][1]);
			swap(k, dp[0][1]);
		}
		B[i] = 0;
	}

	for(int i = 2; i <= N; i += 2) B[A[i]]++;
	for(int i = 1, k, c; i <= 100000; i++) {
		k = i; c = B[i];
		if(dc[1][0] < c) {
			swap(c, dc[1][0]);
			swap(k, dp[1][0]);
		}
		if(dc[1][1] < c) {
			swap(c, dc[1][1]);
			swap(k, dp[1][1]);
		}
	}

	for(int i = 0; i < 2; i++) for(int j = 0; j < 2; j++) {
		if(dp[0][i] == dp[1][j]) continue;
		int c = N - dc[0][i] - dc[1][j];
		if(c < Ans) Ans = c;
	}

	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#D_GridColoring
import numpy as np
def GridColoring(H, W, N, a):
    a = np.array(map(int, a))
    #print(np.argsort(a)[::-1])
    c = np.zeros((H,W))
    direct = True
    x = 0
    y = 0
    for color in np.argsort(a)[::-1]:
        for i in range(a[color]):
            c[y,x] = color+1
            if ((x == 0) and not(direct)) or ((x == (W-1)) and direct):
                y += 1
                direct = not(direct)
            else:
                if direct:
                    x += 1
                else:
                    x -= 1
    return c

def output(X):
    import sys
    for i in range(X.shape[0]):
        for j in range(X.shape[1]):
            sys.stdout.write("%d " %X[i,j])
        sys.stdout.write("\n")



if __name__ == "__main__":
    l = raw_input().split()
    H = int(l[0])
    W = int(l[1])
    N = int(raw_input())
    a = raw_input().split()
    c = GridColoring(H,W,N,a)
    output(c)

Measured memory_bytes: 10792
#include <bits/stdc++.h>
#define pb push_back
#define sc second
#define fr first
#define mk make_pair
#define ll long long
#define ii pair<int,int>
#define mp make_pair
using namespace std;
int n,m;
int memo[3005][3005];
string s,t;
int solve(int i,int j)
{
    if(i == n || j == m)
    {
        return 0;
    }
    int &ret = memo[i][j];
    if(ret != -1)
        return ret;
   if(s[i] == t[j])
    ret = 1+solve(i+1,j+1);
   else
   {
       ret = max(solve(i+1,j),solve(i,j+1));
   }
    return ret;
}
void solve2(int i,int j)
{
    if(i == n || j == m)
    {
        return ;
    }
    int ret = memo[i][j];
    if(s[i] == t[j])
      {
          cout<<s[i];
          solve2(i+1,j+1);
      }
   else
   {
       if(solve(i+1,j) == ret)
       {
           solve2(i+1,j);
       }
       else
       {
          solve2(i,j+1);
       }
   }
    return ;
}
int main()
{
    memset(memo,-1,sizeof(memo));
   cin>>s>>t;
   n = s.length();
   m = t.length();
   solve(0,0);
   solve2(0,0);
}


Measured memory_bytes: 35968
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main()
{
  string s;
  cin>>s;
  map<char,int>m;
  FOR(i,4)
  {m[s[i]]++;}
  	if(m.size()==2)
      cout<<"Yes"<<"\n";
  else 
    cout<<"No"<<"\n";
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	_, S := ReadInt(), ReadString()
	add := 0
	l := 0
	for _, c := range S {
		if c == ')' {
			if l > 0 {
				l--
			} else {
				add++
			}
			continue
		}
		l++
	}
	fmt.Println(strings.Repeat("(", add) + S + strings.Repeat(")", l))
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1848
#include<stdio.h>

int add(int m, int i, int n, int A[])
{
	if(m==0)
	{
		return 1;
	}
	if(i >= n)
	{
		return 0;
	}

	int ans = add( m,i+1, n, A) || add( m-A[i],i+1, n, A);
	
	return ans;
}

int main(void)
{
	int n, q;
	
	scanf("%d", &n);
	
	int A[n];
	
	for(int i=0; i<n; i++)
	{
		scanf("%d", &A[i]);
	}
	
	scanf("%d", &q);
	
	int m[q];
	
	for(int i=0; i<q; i++)
	{
		scanf("%d", &m[i]);
		

		
		if(add(m[i], 0, n, A))
		{
			printf("yes\n");
		}
		else
		{
			printf("no\n");
		}
	}
	
	return 0;
	
}


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


int main(){
 int n;cin >> n;
 int t;cin >> t;
 ll sum = 0;
 int prev;cin >> prev;
 int after;
 for(int i = 1;i<n;i++){
     cin >> after;
     sum += min(t,after-prev);
     prev = after;
 }
 sum += t;
 cout << sum << endl;
} 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;

static class Extensions
{
    public static int ToInt(this string s) => int.Parse(s);
    public static long ToLong(this string s) => long.Parse(s);
    public static char ToChar(this string s) => char.Parse(s);
    public static double ToDouble(this string s) => double.Parse(s);
    public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
    public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
    public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
    public static Queue<T> ToQueue<T>(this IEnumerable<T> seq) => new Queue<T>(seq);
    public static Stack<T> ToStack<T>(this IEnumerable<T> seq) => new Stack<T>(seq);
    public static HashSet<T> ToHashSet<T>(this IEnumerable<T> seq) => new HashSet<T>(seq);
}

static class MyMath
{
    static public long GCD(long a, long b) => (a < b) ? GCD(b, a) : ((b == 0) ? a : GCD(b, a % b));
    static public long LCM(long a, long b) => (a > b) ? (a / GCD(a, b) * b) : (b / GCD(a, b) * a);
    static private readonly long _m = 1000000000 + 7;
    static public long Mod(long val) => (val % _m + _m) % _m;
    static private long ExtGCD(long a, long b, ref long x, ref long y) => (b == 0) ? (a + (x = 1) * 0 + (y = 0) * 0) : (ExtGCD(b, a % b, ref y, ref x) + (y -= a / b * x) * 0);
    static private long ModInverseInner(long a, long dummy1 = 0, long dummy2 = 0) => ExtGCD(a, _m, ref dummy1, ref dummy2) * 0 + Mod(dummy1);
    static public long ModInverse(long a) => ModInverseInner(a, 0, 0);
}

class Program
{
    static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();

    static void Main()
    {
        string input = Console.ReadLine();
        if (input == "Sunny")
        {
            Console.WriteLine("Cloudy");
        }
        else if (input == "Cloudy")
        {
            Console.WriteLine("Rainy");
        }
        else
        {
            Console.WriteLine("Sunny");
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

  vector<long long>a(N),b(N),c(M),d(M);

  for(int i=0;i<N;i++) cin>>a[i]>>b[i];
  for(int i=0;i<M;i++) cin>>c[i]>>d[i];

  for(int i=0;i<N;i++){
    int ans=0; long long mnum=1e9,temp=0;
    for(int j=0;j<M;j++){
      if((temp=(abs(a[i]-c[j])+abs(b[i]-d[j])))<mnum){
        mnum=temp;
        ans=j+1;
      }
    }
    cout<<ans<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    a = tuple(map(int, input().split()))
    c1 = a.count(1) #i
    c2 = a.count(2) #j
    c3 = a.count(3) #k

    dp = [[[0.0]*(N+1) for _ in range(N+1)] for __ in range(N+1)]
    for i in range(c3+1):
        for j in range(c2+c3-i+1):
            for k in range(N-i-j+1):
                if i == j == k == 0:
                    continue
                tmp = N
                if k != 0:
                    tmp += k*dp[k-1][j][i]
                if j != 0:
                    tmp += j*dp[k+1][j-1][i]
                if i != 0:
                    tmp += i*dp[k][j+1][i-1]
                dp[k][j][i] = tmp/(i+j+k)

    print(dp[c1][c2][c3])

if __name__ == '__main__':
    main()

Measured memory_bytes: 254088
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	// ABC138D X
	public class ABC
	{
		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			long A = vs[0];
			long B = vs[1];

			var gcd = GCD(A, B);
			var ans = PrimeFactorization(GCD(A, B)).Distinct().Count() + 1;
			Console.WriteLine(ans);


			Console.Out.Flush();
		}

		#region 最大公約数
		static long GCD(long a, long b)
		{
			long tmp;
			if (a < b) {
				tmp = a;
				a = b;
				b = tmp;
			}
			if (b == 0) {
				return a;
			}
			do {
				tmp = a % b;
				a = b;
				b = tmp;
			} while (b != 0);
			return a;
		}
		#endregion

		#region 素因数分解
		static long[] PrimeFactorization(long x)
		{
			if (x < 2) { return new long[] { }; }

			List<long> ans = new List<long>();
			while (x % 2 == 0) {
				ans.Add(2);
				x /= 2;
			}
			for (int i = 3; i <= Math.Sqrt(x); i += 2) {
				while (x % i == 0) {
					ans.Add(i);
					x /= i;
				}
			}
			if (x > 1) {
				ans.Add(x);
			}
			return ans.ToArray();
		}
		#endregion

	}
}


Measured memory_bytes: 13280
#include<bits/stdc++.h>
#define lp3(i,a,b) for(int i=a;i<b;i++)
#define lp2(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	cout<<a+1-b<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF = 100000000;
ll i,j,k;
int main(){//任意の偶数nについて n⊕(n+1)=1 であることを用いた。 
    ll a,b;cin>>a>>b;
    ll ans;

    if(a==b){cout<<a<<endl;return 0;}

    if(a%2==1){
        ans=a;
        if(b%2==1){
            if(((b-a)/2)%2==1){ans^=1;}
        }else{
            ans^=b;
            if(((b-a)/2)%2==1){ans^=1;}
        }
    }else{
        ans=0;
        if(b%2==1){
            if(((b-a+1)/2)%2==1){ans^=1;}
        }else{
            ans^=b;
            if(((b-a+1)/2)%2==1){ans^=1;}
        }
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll a, b;
    cin >> a >> b;
    if (a == b)
        cout << "Draw" << endl;
    else if (a == 1 || (b != 1 && a > b))
    {
        cout << "Alice" << endl;
    }
    else {
        cout << "Bob" << endl;
    }
}

Measured memory_bytes: 256
N, M = map(int, input().split())

C = [0]*(M+1)

for _ in range(N):
    li = list(map(int, input().split()))
    K = li[0]
    for i in range(K):
        C[li[i+1]] += 1
        # print(C)

print(C.count(N))

Measured memory_bytes: 3060
import numpy as np

N = int(input())
A = np.array(input().split(), dtype=np.int32)
B = np.array(input().split(), dtype=np.int32)

sum_a = A.sum()
sum_b = B.sum()
time = (B-A).sum()
if time < 0:
    print('No')
    exit()
time2 = (((B-A)[B>A]+1) // 2).sum()
if time < time2:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 20748