akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200200;
int a[maxn], b[maxn];
int main(){
	int n; cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) cin >> b[i];
	priority_queue<pair<int,int> > pq;
	for(int i = 0; i < n; i++) if(b[i] > a[i]) pq.push({b[i], i});
	long long ops = 0;
	while(!pq.empty()){
		int tp = pq.top().second; pq.pop();
		int pv = (tp + n - 1) % n;
		int nx = (tp + 1) % n;
		if(b[tp] > b[pv] + b[nx]){
			int upto = (b[tp] - a[tp]) / (b[pv] + b[nx]);
			if(upto == 0){
				cout << -1 << endl;
				return 0;
			}
			ops += upto;
			b[tp] -= upto * (b[pv] + b[nx]);
			if(b[tp] > a[tp]) pq.push({b[tp], tp});
		} else {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ops << endl;
	return 0;
}


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

int main()
{
    ll a, b, k;
    cin >> a >> b >> k;
    if (a >= k) a -= k;
    else {
        b -= (k-a);
        a = 0;
    }
    if (b < 0) b = 0;
    cout << a << " " << b << endl;
}

Measured memory_bytes: 3596
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let a: Vec<u32> = s.by_ref().take(n).map(|a| a.parse().unwrap()).collect();
	let b: Vec<u32> = s.by_ref().take(n).map(|a| a.parse().unwrap()).collect();

	if n == 1 {
		println!("0 {}", a[0] ^ b[0]);
		return;
	}

	let adif: Vec<_> = (0..n)
		.map(|i| a[i] ^ a.get(i + 1).unwrap_or(&a[0]))
		.collect();
	let bdif: Vec<_> = (0..n)
		.map(|i| b[i] ^ b.get(i + 1).unwrap_or(&b[0]))
		.collect();
	let c = [bdif, adif.clone(), adif].concat();
	let z = z_algorithm(&c);
	use std::io::Write;
	let out = std::io::stdout();
	let mut out = std::io::BufWriter::new(out.lock());
	for i in n..2 * n {
		if z[i] >= n - 1 {
			writeln!(out, "{} {}", i - n, b[0] ^ a[i - n]).unwrap();
		}
	}
}

pub fn z_algorithm<T>(s: &[T]) -> Vec<usize>
where
	T: Ord,
{
	if s.len() == 0 {
		Vec::new()
	} else {
		let mut r = vec![0; s.len()];
		let mut j = 0;
		for i in 1..s.len() {
			r[i] = if j + r[j] <= i {
				0
			} else {
				std::cmp::min(j + r[j] - i, r[i - j])
			};
			while i + r[i] < s.len() && s[r[i]] == s[i + r[i]] {
				r[i] += 1;
			}
			if j + r[j] < i + r[i] {
				j = i;
			}
		}
		r[0] = s.len();
		r
	}
}

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

int main(){
  string a,b,c;
  cin >>a >>b >>c;
  if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]) cout << "YES" << endl;
  else cout << "NO" << 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.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class CMultiplication3 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String str[] = in.readLine().split(" ");
            long a = Long.parseLong(str[0]);
            long b = Long.parseLong(str[1].replaceAll("\\.", ""));
            out.println(String.valueOf(a * b / 100));
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0) {
                s = readLine0();
            }
            return s;
        }

    }
}



Measured memory_bytes: 33668
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
score = [0]*(1<<N)

for S in range(1<<N):
    for i in range(N):
        if (S>>i)&1:
            for j in range(i+1, N):
                if (S>>j)&1:
                    score[S] += a[i][j]
    
dp = [-10**18]*(1<<N)
dp[0] = 0

for S in range(1<<N):
    T = S
    
    while True:
        dp[S] = max(dp[S], dp[T]+score[S-T])
        T = (T-1)&S

        if T==S:
            break

print(dp[-1])

Measured memory_bytes: 44064
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define mp make_pair
#define pb push_back
void solve(){
	int n;
	cin>>n;
	ll a[n];
	for (int i = 0; i < n; i++)
	{
		cin>>a[i];
	}
	map<ll,int>m;
	ll a1[n],a2[n];
	for(int i=0;i<n;i++){
		a1[i]=a[i]+i+1;
		m[a1[i]]++;
		a2[i]=i+1-a[i];
	}
	ll ans=0;
	for(int i=0;i<n;i++){
		if(m.find(a2[i])!=m.end()){
			ans+=m[a2[i]];
		}
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	int T=1;
	//cin>>T;
	while(T--)
		solve();
}



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

ll n,m,k,x[N],r[N];

void mul(ll a[],ll b[]){
	static ll c[N];
	for (int i=1;i<=n;i++) c[i]=a[r[i]];
	memcpy(a,c,sizeof(c));
}

ll read(){
	ll x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();
	for (int i=1;i<=n;i++) x[i]=read();
	for (int i=n;i>=1;i--) x[i]-=x[i-1];
	for (int i=1;i<=n;i++) r[i]=i; 
	m=read();k=read();
	for (int i=1,t;i<=m;i++)
		t=read(),swap(r[t],r[t+1]);
	for (;k;mul(r,r),k/=2)
		if (k%2) mul(x,r);
	for (int i=1;i<=n;i++)
		printf("%lld.0\n",x[i]+=x[i-1]);
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> H(N);
  for(int i=0; i<N; i++){
    cin>>H.at(i);
  }
  for(int i=N-1; i>0; i--){
    if(H[i]<H[i-1]){
      if(H[i]>=H[i-1]-1){
        H[i-1]--;
        continue;
      }
      else{
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
}

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

using namespace std;
typedef long long ll;

int main(int argc, char const *argv[])
{
	int N,K,Q;
	cin >> N >> K >> Q;
	std::vector<int > people(N,0);
	std::vector<int> A(Q);
	for (int i = 0; i < Q; i++)
	{
		cin >> A[i];
		people[A[i]-1] += 1;
	}

	for (int i = 0; i < N; i++)
	{
		if (people[i] > Q - K )
		{
			cout << "Yes"<< endl;
		}
		else cout << "No" << endl;
	}

		

	return 0;
}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

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

  int tmp = 0;
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    mp[a[i] ^ (a[i] - 1)]++;
    tmp ^= a[i];
  }

  int cont = 0;
  for (int i = 30; i >= 0; i--) {
    if (mp[Bit(i) - 1]) {
      if (Bitcheck(tmp, i - 1)) {
        cont++;
        tmp ^= Bit(i) - 1;
      }
    }
  }

  if (tmp == 0) {
    cout << cont << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


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

int n;

int main() {

  cin >> n;

  for(int i = 1; i <= n; i++){
    int x = i;
    if(x%3 == 0){
      cout << " " << i;
    }else{
      while(x){
        if(x%10 == 3){
          cout << " " << i;
          break;
        }
        x /= 10;
      }
    }
  }
  cout << endl;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int N=1e7+7,SZ=1e7+1;
ll fac[N],inv[N],s[N],sv[N];
ll ksm(ll b,int n){
	ll res=1;
	while(n){
		if(n&1) res=res*b%mod;
		b=b*b%mod;
		n=(n>>1);
	}
	return res;
}
ll C(int n,int m){
	if(n<m) return 0;
	return fac[n+1]*inv[n-m+1]%mod*inv[m+1]%mod;
}
int main(){
	fac[1]=1;
	for(int i=2;i<=SZ;++i) fac[i]=fac[i-1]*(i-1)%mod;
	s[0]=1;
	for(int i=1;i<=SZ;++i) s[i]=s[i-1]*fac[i]%mod;
	sv[SZ]=ksm(s[SZ],mod-2);
	for(int i=SZ;i>=1;--i) sv[i-1]=sv[i]*fac[i]%mod;
	for(int i=1;i<=SZ;++i) inv[i]=sv[i]*s[i-1]%mod;
	int n,k; ll ans;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;++i){
		if(n==k && i==1){
			printf("1\n");
			continue;
		}
		ans=((C(n-k-1,i-2)+C(n-k-1,i-1)*2%mod)%mod+C(n-k-1,i))%mod;
		ans=ans*C(k-1,i-1)%mod;
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 312704
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict, deque #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
#S = [list(map(int, list(input()))) for _ in range(N)]
rel = [[] for _ in range(N)]

for i in range(N):
    S = input()
    l = []
    for j in range(N):
        if S[j] == '1':
            l.append(j)
    rel[i] = l

flag = [0]*N
ans = 0

for i in range(N):
    flag = [0]*N
    que = deque([i])
    add = 0
    flag[i] = 1
    while que != deque([]):
        node = que.popleft()
        for nn in rel[node]:
            if not flag[nn]:
                que.append(nn)
                flag[nn] = flag[node] + 1
    ans = max(ans, max(flag))

for i in range(N):
    for t in rel[i]:
        if abs(flag[t] - flag[i]) != 1:
            print(-1)
            exit()

print(ans)

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <random>
#include <time.h>
#include <bitset>
#include <stack>

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;

    int mx = max(max(a, b), c);
    int ans = a + b + c - mx;
    mx <<= k;

    cout << ans + mx << '\n';
    return 0;
}

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

const int MOD=1000000000+7;

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

  vector<int> x(n+1,0),y(n+1,0),z(n+1,0);
  for(int i=0;i<n;++i){
    if(x[i]==a[i]){
      x[i+1]=x[i]+1;
      y[i+1]=y[i];
      z[i+1]=z[i];
      //cout << x[i] << " ";
    }else if(y[i]==a[i]){
      x[i+1]=x[i];
      y[i+1]=y[i]+1;
      z[i+1]=z[i];
      //cout << y[i] << " ";
    }else if(z[i]==a[i]){
      x[i+1]=x[i];
      y[i+1]=y[i];
      z[i+1]=z[i]+1;
      //cout << z[i] << " ";
    }else{
      cout << "0" << endl;
      //cout << i << endl;
      return 0;
    }
  }
  ll ans=1;
  for(int i=0;i<n;++i){
    int cnt=0;
    if(a[i]==x[i])cnt++;
    if(a[i]==y[i])cnt++;
    if(a[i]==z[i])cnt++;
    ans=(ans*cnt)%MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n, m, x;
    cin >> n >> m >> x;

    int a = 0;
    int b = 0;
    for(int i=0; i<m; ++i){
        int y;
        cin >> y;
        if(y < x)
            ++ a;
        else
            ++ b;
    }
    cout << min(a, b) << endl;

    return 0;
}


Measured memory_bytes: 256
import math
import copy

inputa = input().split()
# inputb = input().split()
# inputc = input().split()

a = int(inputa[0])
b = int(inputa[1])
c = int(inputa[2])

inputb = input().split()
inputbint = [int(x) for x in inputb]
# inputList = list(b)

# x = int(inputb[0])
# y = int(inputb[1])

inputList=[]
for i in range(a):
    inputNum = input().split()
    inputNum = [int(x) for x in inputNum]
    inputList.append(inputNum)

# inputList = [int(n) for n in inputList]

# b = [int(n) for n in inputb]
# c = [int(n) for n in inputc]

cnt = 0
sum = 0
for i in range(a):
    sum = c
    for j in range(len(inputbint)):
        sum += inputbint[j]*inputList[i][j]
    if sum > 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 3444
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define REPS(i,n) for(int i=1;i<=(n);i++)
#define RREPS(i,n) for(int i=(n);i>0;i--)
#define mp make_pair
#define pb(a) push_back(a)
typedef long long ll;

int main(){
  int N,C,K;
  cin >> N >> C >> K;
  vector<int> T(N);
  REP(i,N) cin >> T[i];
  sort(T.begin(),T.end());
  int cnt = 1;
  int t = T[0];
  int ans = 1;
  REPS(i,N-1){
    if(cnt < C && T[i] - t <= K) cnt++;
    else{
      ans++;
      t = T[i];
      cnt = 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	string a,b;
	cin >> a >> b;
	int n=b.size();
	int m=a.size();
	if(m==n){
		rep(i,a.size()) {
			cout << a[i] << b[i];
		}
	}
	else {
		rep(i,n) {
			cout << a[i] << b[i];
		}
		cout << a[m-1];
	}
	cout << endl;
} 

Measured memory_bytes: 3652
#include <bits/stdc++.h> 
using namespace std;
int main(){
	long int a,b,k;
	cin>>a>>b>>k;
	if(a+2*k<=b){	
		for(int i=0;i<k;i++){
			cout<<a+i<<endl;
		}
		for(int i=k-1;i>=0;i--){
			cout<<b-i<<endl;
		}
	}
	else{
		for(int i=0;i<b-a+1;i++){
			cout<<a+i<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    long long int n,a,b,k;
    scanf("%lld %lld %lld",&n,&a,&b);
    k = n %(a+b);
    if(k < a)
    {
        printf("%lld\n",(n/(a+b))*a+k);
    }
    else
    {
        printf("%lld\n",(n/(a+b))*a+a);

    }
    
    
    




    
    return 0;

}

Measured memory_bytes: 1712
/*
 * @Author: Kaizyn
 * @Date: 2020-06-20 20:03:14
 * @LastEditTime: 2020-06-20 20:18:42
 */ 
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const double eps = 1e-7;
const double PI = acos(-1);
typedef pair<int, int> pii;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const int N = 3e3+7;

template <int _MOD> struct Mint {
  int v = 0;
  Mint() {}
  Mint(int _v) : v((_v%_MOD+_MOD)%_MOD) {}
  Mint(long long _v) : v(static_cast<int>((_v%_MOD+_MOD)%_MOD)) {}
  Mint operator = (const int &_v) { return *this = Mint(_v); }
  Mint operator = (const long long &_v) { return *this = Mint(_v); }
  bool operator ! () const { return !this->v; }
  bool operator < (const Mint &b) const { return v < b.v; }
  bool operator > (const Mint &b) const { return v > b.v; }
  bool operator == (const Mint &b) const { return v == b.v; }
  bool operator != (const Mint &b) const { return v != b.v; }
  bool operator <= (const Mint &b) const { return v < b.v || v == b.v; }
  bool operator >= (const Mint &b) const { return v > b.v || v == b.v; }
  Mint operator + (const Mint &b) const { return Mint(v+b.v); }
  Mint operator - (const Mint &b) const { return Mint(v-b.v); }
  Mint operator * (const Mint &b) const { return Mint(1ll*v*b.v); }
  Mint operator / (const Mint &b) const { return Mint(b.inv()*v); }
  Mint& operator += (const Mint &b) { return *this = *this+b; }
  Mint& operator -= (const Mint &b) { return *this = *this-b; }
  Mint& operator *= (const Mint &b) { return *this = *this*b; }
  Mint& operator /= (const Mint &b) { return *this = *this/b; }
  Mint operator - () const { return Mint(-v); }
  Mint& operator ++ () { return *this += 1; }
  Mint& operator -- () { return *this -= 1; }
  Mint operator ++ (int) { Mint tmp = *this; *this += 1; return tmp; }
  Mint operator -- (int) { Mint tmp = *this; *this -= 1; return tmp; }
  Mint pow(int p) const {
    Mint res(1), x(*this);
    while (p) {
      if (p&1) res = res*x;
      x *= x;
      p >>= 1;
    }
    return res;
  }
  Mint inv() const { return pow(_MOD-2); }
  friend istream& operator >> (istream &is, Mint &mt) { return is >> mt.v; }
  friend ostream& operator << (ostream &os, const Mint &mt) { return os << mt.v; }
};
using mint = Mint<MOD>;


int a, b, c, d;
mint dp[N][N];

inline void solve() {
  cin >> a >> b >> c >> d;
  dp[a][b] = 1;
  for (int i = a+1; i <= c; ++i) {
    dp[i][b] = dp[i-1][b]*b;
  }
  for (int i = b+1; i <= d; ++i) {
    dp[a][i] = dp[a][i-1]*a;
  }
  for (int i = a+1; i <= c; ++i) {
    for (int j = b+1; j <= d; ++j) {
      dp[i][j] = dp[i-1][j]*j+dp[i][j-1]*i-dp[i-1][j-1]*(i-1)*(j-1);
    }
  }
  cout << dp[c][d] << endl;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int T = 1;
  // cin >> T;
  for (int t = 1; t <= T; ++t) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 38960
#include<stdio.h>

int main(){
    int H,W;
    for(int k=0;;k++){

    scanf("%d %d",&H,&W);
        if(H==0 && W==0)break;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            printf("#");
            
        }printf("\n");
    }
        printf("\n");
    }
    return 0;
}



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

using namespace std;

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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

#define int long long

typedef pair<int, int> P;

int H, W, S;
vector< vector<int> > A;
bool m1[40][40][40][40];
P m2[40][40][40][40];
int m[50][50];

void setM(int x, int y, int val) {
	m[y+1][x+1] = val;
}
int getM(int x1, int y1, int x2, int y2) {
	return m[y2][x2] - m[y2][x1] - m[y1][x2] + m[y1][x1];
}
void initM() {
	REP(x, W+1) REP(y, H+1) {
		m[y+1][x] += m[y][x];
	}
	REP(x, W+1) REP(y, H+1) {
		m[y][x+1] += m[y][x];
	}
}

// [x1, x2) && [y1, y2)
P solve(int x1, int y1, int x2, int y2) {
	if (m1[x1][y1][x2][y2]) return m2[x1][y1][x2][y2];

	P res(1, S-(getM(0, 0, W, H) - getM(x1, y1, x2, y2)));
	if (res.second < 0) {
		res = P(-inf, -inf);
	}
	else {
		// [y1, y) [y, y2)
		FOR(y, y1+1, y2) {
			P a1 = solve(x1, y1, x2, y);
			P a2 = solve(x1, y, x2, y2);
			P a = P(a1.first+a2.first, min(a1.second, a2.second));
			res = max(res, a);
		}
		// [x1, x) [x, x2)
		FOR(x, x1+1, x2) {
			P a1 = solve(x1, y1, x, y2);
			P a2 = solve(x, y1, x2, y2);
			P a = P(a1.first+a2.first, min(a1.second, a2.second));
			res = max(res, a);
		}
	}
//	cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << res.first << " " << res.second << endl;
	return m1[x1][y1][x2][y2] = true, m2[x1][y1][x2][y2] = res;
}

signed main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	while (cin >> H >> W >> S, H || W || S) {
		fill(m[0], m[50], 0);
		fill(m1[0][0][0], m1[39][39][40], false);
		A = vector< vector<int> >(H, vector<int>(W, 0));
		REP(y, H) REP(x, W) {
			cin >> A[y][x];
			setM(x, y, A[y][x]);
		}
		initM();
		int sum = 0;
		REP(y, H) REP(x, W) sum += A[y][x];
		P ans = solve(0, 0, W, H);
		assert(ans.first >= 0 && ans.second >= 0);
		cout << ans.first << " " << ans.second << endl;
	}
}

Measured memory_bytes: 43776
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll long long
ll dp[5000][5001], a[305011];
char s[1001][1001];
ll f(ll i, ll j)
{
    if(i==j) {dp[i][j]= a[i]; return a[i]; }
    if(dp[i][j]!=-1) return dp[i][j];
    dp[i][j] = f(i+1,j)^f(i,j-1);
    return dp[i][j];
}
int main()
{
    IO;
    ll j, n, m, k, m1, m2, a1, a2, l, t, cnt=0, mn, h=0, mod=1e9+7; int tc=0; ll i;
    //cin>>t;
    //while(t--){
        tc++; dp[1][0]=1;
        cin>>n>>m;
        for(i = 1; i<=n; i++)
            for(j = 1; j<=m; j++) cin>>s[i][j];
        for(i = 1; i<=n; i++) {
            for(j = 1; j<=m; j++){
                if(s[i][j]=='.')
                    dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
            }
        }
        cout<<dp[n][m]<<endl;
        //cout<<"Case "<<tc<<": "<<dp[2*n-1][1]<<endl;
    //}
    return 0;
}


Measured memory_bytes: 42240
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> student(n);
  rep(i,n){
    int x; cin >> x;
    student.at(i)=make_pair(x,i+1);
  }

  sort(all(student));
  cout << student.at(0).second;
  for(int i=1;i<n;i++){
    cout << " " << student.at(i).second;
  }
}


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

int main() {
	int n;
	cin >> n;
	int* array = new int[ n ];
	rep( i, 0, n )
	cin >> array[ i ];
	int minimum = 100;
	rep( i, 0, n ){
		int sum_a = 0, sum_b = 0;
		rep( j, 0, i ){
			sum_a += array[ j ];
		}
		rep( j, i, n ){
			sum_b += array[ j ];
		}
		minimum = min( minimum, abs( sum_a - sum_b ));
	}
	printf( "%d\n", minimum );
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>

using namespace std;

typedef long long ll;

constexpr ll MOD = 1e9 + 7;

ll n, m;

ll get_edge_len(ll n, vector<ll> X) {
    ll xall = 0;
    ll k = 0;
    vector<ll> D(n - 1);
    for (ll i = 0; i < n - 1; i++) {
        D[i] = X[i + 1] - X[i];
    }

    ll len = D.size();
    for (ll i = 0; i < len / 2; i++) {
        k += len - 2 * i;
        xall = (xall + ((k * D[i]) % MOD) + MOD) % MOD;
        xall = (xall + ((k * D[len - 1 - i]) % MOD) + MOD) % MOD;
    }

    if (len % 2) {
        ll i = len / 2;
        k += len - 2 * i;
        xall = (xall + ((k * D[i]) % MOD) + MOD) % MOD;
    }

    return xall;
}

int main(void) {
    cin >> n >> m;
    vector<ll> X(n), Y(m);
    for (auto&& x : X) {
        cin >> x;
    }
    for (auto&& y : Y) {
        cin >> y;
    }

    ll xall = 0, yall = 0;

    /*
    for (ll i = 0; i < n; i++) {
        for (ll j = i + 1; j < n; j++) {
            xall = (xall + X[i] - X[j]) % MOD;
        }
    }

    for (ll i = 0; i < m; i++) {
        for (ll j = i + 1; j < m; j++) {
            yall = (yall + Y[i] - Y[j]) % MOD;
        }
    }

    cout << xall << "," << yall << endl;

    cout << "reset" << endl;
    xall = yall = 0;
    */

    // xall = get_edge_len(n, X);
    // yall = get_edge_len(m, Y);

    // cout << xall << "," << yall << endl;

    // from editorial
    for (ll i = 0; i < n; i++) {
        xall = (xall + (i * X[i] - (n - 1 - i) * X[i])) % MOD;
    }

    for (ll i = 0; i < m; i++) {
        yall = (yall + (i * Y[i] - (m - 1 - i) * Y[i])) % MOD;
    }

    cout << (xall * yall) % MOD << endl;

    return 0;
}



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

int main() {
  int N;
  int R;
  cin >> N >> R;
  if (N >= 10) {
    cout << R << endl;
  }
  else {
    // x - 100 * (10 - N) = R
    // x = R - 100 * N + 1000
    int x = R - 100 * N + 1000;
    cin >> x;
    cout << x << endl;
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

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

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

// constexpr inline ll mod = 1'000'000'007;
// constexpr int max_n = 200'000 + 5;

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    ll x; cin >> x;
    for (int a = -200; a <= 200; a++) {
        for (int b = -200; b <= 200; b++) {
            if (((ll)a)*a*a*a*a - ((ll)b)*b*b*b*b == x) {
                cout << a << ' ' << b << '\n';
                return 0;
            }
        }
    }

    return 0;
}


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

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

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

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

ostream& operator<<(ostream& os, const pair<char, int>& unit) {
  return os << unit.first << "^" << unit.second;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int N = 500010, P = 998244353;

int n, m;
int inv[N], ifac[N], fac[N], pw[N], qw[N];

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n >> m;
  if (n < m) swap(n, m);
  inv[1] = 1;
  for (int i = 2; i <= n; ++i)
    inv[i] = -(P / i) * (ll)inv[P % i] % P + P;
  ifac[0] = 1;
  for (int i = 1; i <= n; ++i)
    ifac[i] = ifac[i - 1] * (ll)inv[i] % P;
  fac[0] = 1;
  for (int i = 1; i <= n; ++i)
    fac[i] = fac[i - 1] * (ll)i % P;
  pw[0] = 1;
  for (int i = 1; i <= m; ++i)
    pw[i] = pw[i - 1] * (n + 1LL) % P;
  qw[0] = 1;
  for (int i = 1; i <= n; ++i)
    qw[i] = qw[i - 1] * (m + 1LL) % P;
  int ans = 0;
  for (int i = 0; i <= m; ++i) {
    int res = ((i & 1) ? (P - 1) : 1) * (ll)pw[m - i] % P * ifac[i] % P * ifac[m - i] % P * qw[n - i] % P * ifac[n - i] % P;
    ans = (ans + res) % P;
  }
  ans = ans * (ll)fac[n] % P * fac[m] % P;
  cout << ans;

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
      -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}



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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h,w;
    cin >> h >> w;
    vector<ll> s(3);
    ll ans = 1e10;
    for(int i = 1;i < w;i ++){
        s[0] = h*i;
        s[1] = (w-i)*(h/2);
        s[2] = (w-i)*((h+1)/2);
        sort(s.begin(),s.end());
        if(s[2]-s[0]<ans) ans = s[2] - s[0];
    }
    for(int i = 1;i < h;i ++){
        s[0] = w*i;
        s[1] = (h-i)*(w/2);
        s[2] = (h-i)*((w+1)/2);
        sort(s.begin(),s.end());
        if(s[2]-s[0]<ans) ans = s[2] - s[0];
    }
    if(h*(w/3+min(w%3,1LL))-h*(w/3)<ans) ans = h*(w/3+min(w%3,1LL))-h*(w/3);
    if(w*(h/3+min(h%3,1LL))-w*(h/3)<ans) ans = w*(h/3+min(h%3,1LL))-w*(h/3);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import math
a,b,h,m=map(int,input().split())
h*=30
h+=m/2
m*=6
t=min(abs(m-h),360-abs(m-h))
p=math.pi*(t/180)

print(math.sqrt(a*a+b*b-2*a*b*math.cos(p)))

Measured memory_bytes: 9408
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;

int main(){
    int N;
    cin>>N;
    vector<int> L;
    int ans=0;
    for(int i=0;i<2*N;i++){int l;cin>>l;L.push_back(l);}
    sort(L.begin(),L.end());
    for(int i=0;i<N;i++) ans+=min(L[i*2],L[i*2+1]);
    cout<<ans<<endl;
    
    return 0;
};


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,j,n,p[100],w,cnt;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&p[i]);
	}
	for(i=n;i>=1;i--){
		cnt=0;
		for(j=1;j<=n;j++){
			if(p[j]>=i){
				cnt++;
			}
		}
		if(i<=cnt){
			break;
		}
	}
	printf("%d\n",i);
	return 0;
}


Measured memory_bytes: 2732
def main():
    N = int(input())
    AB = []
    for _ in range(N):
        a, b = map(int, input().split())
        AB.append((a, b))
    AB = sorted(AB, key=lambda x: x[1])
    c = 0
    for a, b in AB:
        c += a
        if c > b:
            print('No')
            return
    print('Yes')


main()


Measured memory_bytes: 33396
N, A, B, C = gets.split.map(&:to_i)
L          = N.times.map{ gets.to_i }

def dfs(cur, a, b, c)
  if cur == N
    if [a, b, c].min > 0
      return (a-A).abs + (b-B).abs + (c-C).abs - 30
    else
      return 10**9
    end
  end

  r0 = dfs(cur+1, a,        b,        c       )
  r1 = dfs(cur+1, a+L[cur], b,        c       ) + 10
  r2 = dfs(cur+1, a,        b+L[cur], c       ) + 10
  r3 = dfs(cur+1, a,        b,        c+L[cur]) + 10

  return [r0, r1, r2, r3].min
end

puts dfs(0, 0, 0, 0)

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

int main(){
  long long n;
  cin >> n;
  int f;
  for (int i=1; i<sqrt(n)+1; i++){
    if(n%i==0){
      long long b = n/i;
      f = 1;
      while (b/10 > 0){
        f++;
        b=b/10;
      }
    }
  }
  cout << f << endl;
}

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

int main(int argc, char const *argv[]) {
    while(true){
        int N;
        cin >> N;
        if(N==0) break;
        vector<int> a;
        for(int i=0;i<N;i++){
            int b;
            cin >> b;
            a.push_back(b);
        }
        sort(a.begin(),a.end());
        int total=0;
        for(int i=1;i<N-1;i++){
            total+=a[i];
        }
        cout << total/(a.size()-2) << endl;
    }
    return 0;
}

Measured memory_bytes: 3092
// È¥°É£¡Æ¤¿¨Çð! °ÑAC´ø»ØÀ´£¡
//      ¤Ø¡¡¡¡¡¡¡¡¡¡£¯|
// ¡¡¡¡/£Ü7¡¡¡¡¡¡ ¡Ï£ß/
// ¡¡ /¡¡©¦¡¡¡¡ £¯¡¡£¯								AC		AC		AC		AC
//    ©¦¡¡Z £ß,£¼¡¡£¯¡¡¡¡ /`©c						AC		AC		AC		AC
//    ©¦¡¡¡¡¡¡¡¡¡¡©c¡¡¡¡ /¡¡¡¡¡µ					AC		AC		AC		AC
// ¡¡Y¡¡¡¡¡¡¡¡¡¡`¡¡ /¡¡¡¡/  /						AC		AC		AC		AC
// ¡¡Øé¡ñ¡¡.¡¡¡ñ¡¡¡¡¡´¡¡/¡¡/						AC		AC		AC		AC
// ¡¡()¡¡ ¤Ø¡¡¡¡¡¡¡¡|¡¡£Ü¡´							AC		AC		AC		AC
// ¡¡¡¡>- ._¡¡ ¥£¡¡ ©¦ £¯£¯							AC		AC		AC		AC
// ¡¡ / ¤Ø¡¡¡¡ /¡¡/£¼| £Ü£Ü							AC		AC		AC		AC
// ¡¡ ©c_/¡¡¡¡(_£¯¡¡ ©¦£¯£¯							AC		AC		AC		AC
// ¡¡¡¡ 7¡¡¡¡¡¡¡¡¡¡¡¡¡¡|£¯							AC		AC		AC		AC
// ¡¡¡¡ £¾¨Dr£þ£þ`-¨D£ß/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

using namespace std;

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

const int Days[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};

inline int read()
{
	#define gc getchar
	int ans=0;
	bool f=1;
	char ch=gc();
	
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	
	return f?ans:-ans;
	
	#undef gc
}

typedef long long ll;

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	
	int d,t,s;cin>>d>>t>>s;
	
	cout<<(d<=t*s ? "Yes" : "No");
	
	//printf("Time used = %.12f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

/*  GOD BLESS  */


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

int main(){
  int n, x=0, a=0, b=0, c=0, ans;
  string s[20000];
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> s[i];
    for(int j=0;j<s[i].length()-1;j++){
      if(s[i][j]=='A'&&s[i][j+1]=='B')x++;
    }
    int m=s[i].length();
    if(s[i][0]=='B'&&s[i][m-1]=='A')a++;
    else if(s[i][0]=='B')b++;
    else if(s[i][m-1]=='A')c++;
  }
  if(a==0)ans=min(b,c);
  else{
    if(b+c>0)ans=a+min(b,c);
    else ans=a-1;
  }
  cout << ans+x << endl;
  return 0;
}


Measured memory_bytes: 896
#include <stdio.h>
using namespace std;
int main(void){
    char q;
 
   
   while(1){
       scanf("%c",&q);
      if ( q == 10 ) break;
       if(65<=q&&96>=q){
           printf("%c",q+32);
       }else if(97<=q&&122>=q){
           printf("%c",q-32);
       }else{printf("%c",q);
           
       }
       
   }
printf("\n");
}




Measured memory_bytes: 2576
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<MOD2>;

ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD2;
        mul = mul * mul % MOD2;
        n /= 2;
    }
    return res;
}

ll modinv(ll x, ll n){
    return modpow(x, n - 2);
}


ll a[3100];
mint dp[3100][3100];

int main(){
    int n, s;
    cin >> n >> s;
    rep(i, n) cin >> a[i];

    dp[0][0] = 1;

    rep(i, n){
        rep(j, s + 1){
            if (j + a[i] < 3100) dp[i+1][j+a[i]] += dp[i][j];
            dp[i+1][j] += dp[i][j] * 2;
        }
    }

    cout << dp[n][s] << endl;

    return 0;
}


Measured memory_bytes: 76272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    cin>>s;
    bool flg1 = (bool)(s[0]=='A');
    bool flg2 = (bool)(count(s.begin()+2,s.end()-1,'C')==1);
    int cnt = 0;
    for(int i=0;i<s.size();++i)
        if(isupper(s[i]))
            cnt++;
    bool flg3 = (bool)(cnt==2);
 
    (flg1 && flg2 && flg3 )?cout<<"AC":cout<<"WA";
    return 0;
}   

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

struct UnionFind{
  int n;
  vector<int> p;
  UnionFind(int nn):n(nn+1){
      p.resize(n);
      rep(i,n) p[i] = i;
  }
  int root(int x){
    if(p[x] == x) return x;
    else return p[x] = root(p[x]);
  }
  void unite(int x,int y){
      x = root(x);
      y = root(y);
      if(x != y) p[y] = x;
  }
  bool query(int x,int y){
    return root(x) == root(y);
  }
};


class Solver {
  public:
    bool solve() {
        int N, M; cin >> N >> M;
        UnionFind uf(M + N + 1); // 0 ~ (M - 1) and ...
        rep(i, N) {
            int k; cin >> k;
            rep(j, k) {
                int l; cin >> l;
                l--;
                uf.unite(M + i, l);
            }
        }
        int root = uf.root(M);
        bool flg = true;        
        rep(i, N) {
            flg &= uf.root(M + i) == root;
        }
        cout << (flg ? "YES" : "NO") << endl;
        return 0;
    }
};

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


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

int main()
{
    ios_base::sync_with_stdio(0);

    int n;
    string s;
    cin >> s;
    n=s.length();
    long long sum=0;
    vector<int>v(n+1,-1);
    bool flg=1;
    for(int i=0;i<n;i++){
        if(s[i]=='<'){
            if(flg){
                flg=0;
                v[i]=0;
            }
            else
                v[i]=v[i-1]+1;
        }
        else{
            if(!flg)
                v[i]=v[i-1]+1;
            flg=1;
        }
    }
    if(s[n-1]=='<')
        v[n]=v[n-1]+1;
    flg=1;
    for(int i=n-1;i>=0;i--){
        if(s[i]=='>'){
            if(flg){
                flg=0;
                v[i+1]=0;
            }
            else
                v[i+1]=max(v[i+1],v[i+2]+1);
        }
        else{
            if(!flg)
                v[i+1]=max(v[i+1],v[i+2]+1);
            flg=1;
        }
    }
    if(s[0]=='>')
        v[0]=max(v[0],v[1]+1);
    
    for(int i=0;i<n+1;i++)
        sum+=v[i];


    cout << sum << endl;

    return 0;
}

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

int main(){
  int N;
  cin>>N;
  map<string,int> m;
  vector<pair<int,string> > p;
  int n=0;
  for(int i=0;i<N;i++){
    string S;
    cin>>S;
    if(m.count(S)==0){
      m[S]=n;
      n++;
      p.push_back(make_pair(1,S));
    }else{
      p.at(m[S]).first++;
    }
  }

  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());

  int k=p.at(0).first;
  int i=0;
  while(p.at(i).first==k){
    i++;
    if(i==n){
      break;
    }
  }
  for(int j=i-1;j>=0;j--){
    cout<<p.at(j).second<<endl;
  }
}


Measured memory_bytes: 28396
open Scanf
open Printf

let () = scanf "%d %d %d" (fun a b c ->
  if a = 7 && b = 5 && c = 5 then "YES"
  else if a = 5 && b = 7 && c = 5 then "YES"
  else if a = 5 && b = 5 && c = 7 then "YES"
  else "NO"
  ) |> printf "%s\n"

Measured memory_bytes: 3716
#include<iostream>
using namespace std;
#define maxn 10000+5
#define inf 999999999
#define mod 10007
char c;
inline void yu()
{
}
inline void in()
{
	while(cin>>c)
	{
		if(c==',')c=' ';
		cout<<c;
	}
}
inline void Do()
{
}
inline void out()
{
}
int main()
{
	yu();
    in();
    Do();
    out();
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(true) {
            int h = scanner.nextInt();
            int w = scanner.nextInt();
            if (h == 0 && w == 0) break;
            for (int b = 1; b <= h; b++) {
                StringBuilder out = new StringBuilder();
                //偶数の行
                if (b % 2 == 0) {
                    for (int a = 1; a <= w; a++){
                        //偶数の列には#を追加
                        if (a % 2 == 0) {
                            out.append("#");
                        } else {
                            out.append(".");
                        }
                    }
                } else {
                    for (int c = 1; c <= w; c++){
                        if (c % 2 == 0) {
                            out.append(".");
                        } else {
                            out.append("#");
                        }
                    }
                }
                System.out.println(out);
            }
            System.out.println("");
        }
    }
}



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

int main(){
  int a;
  cin >> a;
  float cnt=0;
  for(int i=1;i<=a;i++){
    if(i%2==1){
      cnt++;
    }
  }
  cout << fixed << setprecision(10);
  cout << cnt/a << endl;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  if (a == b && a != c && b != c) {
    cout << "Yes" << endl;
  }
  else if (b == c && a != b && a != c) {
    cout << "Yes" << endl;
  }
  else if (a == c && b != a && b != c) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
   int i, n; 
   int a[100]; 
   scanf("%d", &n); 
   for(i=0;i<n;i++){ 
       scanf(" %d", &a[i]); 
    } 
    for(i=0;i<n;i++){ 
        if(i)printf(" "); 
        printf("%d", a[n-i-1]); 
    } 
    printf("\n"); 
    return 0; 
} 



Measured memory_bytes: 2044
n=int(input())
s=list(map(int,list(input())))
ans=0
for i in range(10):
    try:
        ss=s[s.index(i)+1:]
        for j in range(10):
            try:
                sss=ss[ss.index(j)+1:]
                for k in range(10):
                    if k in sss:ans+=1
            except:pass
    except:pass

print(ans)

Measured memory_bytes: 4428
#include <iostream>

using namespace std;

int main(){

    int L, R, l, r;
    cin >> L >> R;

    l = L % 2019;
    r = R % 2019;

    if( R - L >= 2018){
        cout << 0 << endl;
        return 0;
    }

    if(l >= r){
        cout << 0 << endl;
        return 0;
    }

    int ans = 2019;
    for(int i = l; i <= r; i++){
        for(int j = i + 1; j <=r; j++){
            if( ( i * j )  % 2019 < ans) ans = ( i * j ) % 2019;
        }
    }

    cout << ans << endl;
    return 0;

}


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

int main(){
  string s;
  cin >> s;
  rep(i,s.size()){
    string t = s.substr(0,s.size()-2*(i+1));
    if(t.substr(0,t.size()/2)==t.substr(t.size()/2,t.size()/2)){
      cout << t.size() << endl;
      return 0;
    }
  }
  
  
	return 0;
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)

ks = []
ss = Array.new(m) { [] }

m.times do |i|
  _, *s = gets.split.map(&:to_i)
  ss[i] = s
end
ps = gets.split.map(&:to_i)

ans = 0

(1 << n).times do |bit|
  valid = true

  m.times do |i|
    count = ss[i].count { |s| bit[s - 1] == 1 }

    if count % 2 != ps[i]
      valid = false
      break
    end
  end

  ans += 1 if valid
end

puts ans


Measured memory_bytes: 3836