akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

signed main()
{
	int N;
	cin >> N;
	N--;
	cout << ((N + 1) * N) / 2 << endl;

}




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

using namespace std;

typedef long long ll;

const int mod = 998244353, N = 3005;

int n, s;
int a[N];
int f[N];

int main() {
    scanf("%d %d", &n, &s);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = s; j > a[i]; j--) f[j] = (f[j] + f[j - a[i]]) % mod;
        f[a[i]] = (f[a[i]] + i) % mod;
        ans = (ans + (ll)f[s] * (n - i + 1) % mod) % mod;
        f[s] = 0;
    }
    printf("%d\n", ans);
    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};
 
int main(){
  int n;
  cin>>n;
  int h[n];
  int max=0;
  int ans=0;
  REP(i,n){
    cin>>h[i];
    if(max<=h[i]){
      ans++;
      max = h[i];
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

LL n,A,B;
LL a[N];
bool judge(LL x){
    LL temp=x*B;
    LL sub=A-B;
    LL sum=0;
    for(LL i=n;i>=1;i--){
        if(a[i]>temp){
            sum+=ceil(1.0*(a[i]-temp)/sub);
        }
    }
    if(sum<=x)
        return true;
    return false;
}
int main() {
    scanf("%lld%lld%lld",&n,&A,&B);

    LL right=0;
    for(LL i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        right+=a[i]/B+1;
    }
    sort(a+1,a+1+n);

    LL left=1;
    while(left<right){
        LL mid=(left+right)>>1;
        if(judge(mid))
            right=mid;
        else
            left=mid+1;
    }
    printf("%lld\n",left);

    return 0;
}


Measured memory_bytes: 1024
import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    if N==1:
        print('a')
        exit()
    d = deque(['a'])
    ans = []
    while d:
        s = d.popleft()
        last = ord(max(s))
        for i in range(97,last+2):
            S = s + chr(i)
            if len(S)==N:
                ans.append(S)
            else:
                d.append(S)
    ans.sort()
    for s in ans:
        print(s)
if __name__ == '__main__':
    main()

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

int main()
{
    long long n;
    cin>>n;
    
    int ar[n];
    for(int i=0;i<n;i++){
        cin>>ar[i];
    }
    
    sort(&ar[0],&ar[n]);
    
     for(int i=0;i<n-1;i++){
        if(ar[i]==ar[i+1]){
            cout<<"NO"<<"\n";
            return 0;
        }
    }
    cout<<"YES"<<"\n";
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define lol long long
using namespace std;
int main(){
    int a,b,c,ans,co=0;
    string s,t;
    cin>>s;
    if(s[0]==s[1] && s[1]==s[2] || s[1]==s[2] && s[2]==s[3]) cout<<"Yes\n";
    else cout<<"No\n";
    return(0);
}

Measured memory_bytes: 3600
#include <stdio.h>
#include<vector>
#include<deque>

using namespace std;
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
inline void reader(int& x) { int k, m = 0; x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; x = x * 10 + k - '0'; }if (m) x = -x; }
inline void writer(int x, char c) { int s = 0, m = 0; char f[7]; if (x<0)m = 1, x = -x; while (x)f[s++] = x % 10, x /= 10; if (!s)f[s++] = 0; if (m)mypc('-'); while (s--)mypc(f[s] + '0'); mypc(c); }
inline void writerLn(int x) { writer(x, '\n'); }
#define rep(i,n)for(int i=0;i<n;i++)
vector<int>E[100000];
int u[200000], v[200000], r[200000], ans[200000], d[100000], cnt = 1;
char b[200000], ok[100000];
deque<int>que;

void bfs(int u, int t) {
	que.emplace_back(u);
	while (!que.empty()) {
		int p = que.front(); que.pop_front();
		for (int v : E[p]) {
			if (t) {
				if (d[v] > d[p] && !ok[v]) {
					ok[v] = 1; cnt++; que.emplace_back(v);
				}
			}
			else if (!d[v]) {
				d[v] = d[p] + 1; que.emplace_back(v);
			}
		}
	}
}
int main() {
	ok[0] = d[0] = 1;
	int n, m, q; reader(n); reader(m); reader(q);
	rep(i, m) {
		reader(u[i]); reader(v[i]);
		u[i]--; v[i]--;
		E[u[i]].emplace_back(v[i]); E[v[i]].emplace_back(u[i]);
	}
	bfs(0, 0);
	rep(i, m) {
		if (d[u[i]] > d[v[i]])swap(u[i], v[i]);
	}
	rep(i, n)E[i].clear();
	rep(i, q) {
		reader(r[i]); r[i]--;
		b[r[i]] = 1;
	}
	rep(i, m) {
		if (!b[i]) {
			if (d[v[i]] > d[u[i]]) {
				E[u[i]].emplace_back(v[i]);
			}
		}
	}
	bfs(0, 1);
	for (int i = q - 1; i >= 0; i--) {
		ans[i] = n - cnt;
		if (d[v[r[i]]] > d[u[r[i]]] && !ok[v[r[i]]]) {
			E[u[r[i]]].emplace_back(v[r[i]]);
			if (ok[u[r[i]]]) {
				cnt++; ok[v[r[i]]] = 1;
				bfs(v[r[i]], 1);
			}
		}
	}
	rep(i, q)writerLn(ans[i]);
}

Measured memory_bytes: 12968
#include<iostream>
#include<string>
using namespace std;
typedef long long int ll;
static const int MAX_N = 5000;
static const int MOD = 1000000007;
ll mod_pow(ll x, ll n){
	if(n == 0) return 1;
	ll res = mod_pow(x * x % MOD, n / 2);
	if(n % 2 == 1) res = res * x % MOD;
	return res;
}
int main(){
	int N;
	string S;
	ll dp[5010][5010];
	cin >> N;
	cin >> S;
	for(int i = 0; i <= N; i++){
		for(int j = 0; j <= N; j++){
			if(i == 0 && j == 0) dp[i][j] = 1;
			else if(j == 0) dp[i][j] = dp[i - 1][j] + dp[i - 1][j + 1];
			else if(i >= 1 && j >= 1) dp[i][j] = 2 * dp[i - 1][j - 1] + dp[i - 1][j + 1];
			dp[i][j] %= MOD;
		}
	}
	ll num = mod_pow(2, S.length());
	cout << dp[N][S.length()] * mod_pow(num, MOD - 2) % MOD << endl;
	return 0;
}

Measured memory_bytes: 195968
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, a, b, s;
  b=10000;
  cin >> n;
  for(i=0;i<n;i++) {
    cin >> s;
    a=0;
    while(s%2==0) {
      s /= 2;
      a++;
      }
    if(b>a) {
      b = a;
    }
  }
  cout << b << endl;
  return 0;
}
    

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i;
  scanf("%d",&n);
  int a[n+1],b[n+1];
  for(i=1;i<=n;i++)
    scanf("%d",&a[i]);
  for(i=1;i<=n;i++){
    if(i%2==0)
      b[(n+1)/2+i/2]=a[i];
    else
      b[(n+1)/2-i/2]=a[i];
  }
  if(n%2==1){
    for(i=1;i<=n;i++)
      printf("%d ",b[i]);
  }
  else{
    for(i=n;i>=1;i--)
      printf("%d ",b[i]);
  }
  puts("");
  return 0;
}


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

int main(){
  int n,ans;
  cin>>n;
  
  rep(i,0,n){
    int l,r;
    cin>>l>>r;
    ans+=r-l+1;
  }

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


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:usize,
        xn:[usize;n],
    }
    let mut sub = xn.clone();
    sub.sort();
    let mid = n /2;
    let median = sub[mid];
    let median_before = sub[mid-1];
    for &x in &xn {
        if x >= median {
            println!("{}",median_before);
        } else {
            println!("{}",median);
        }
    }
}

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

namespace AOJ_ICPC1 {

	class Program {
		static void Main(string[] args) {
			List<string> U = new List<string>();
			int N = int.Parse(Console.ReadLine());
			for(int n=0; n<N; n++) U.Add(Console.ReadLine());
			int M = int.Parse(Console.ReadLine());

			bool isClosed = true;
			for (int m = 0; m < M; m++) {
				string T = Console.ReadLine();
				if (U.Contains(T)) {
					Console.WriteLine("{0} by {1}", isClosed ? "Opened" : "Closed", T);
					isClosed = !isClosed;
				}
				else {
					Console.WriteLine("Unknown {0}", T);
				}
			}
		}
	}
}

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

int main()
{
        long long A, B, C, K;
        cin >> A >> B >> C >> K;
        long long sum = 0;
        if ((A+B) >= K && A < K) {
                sum = A;
        }
        else if (A >= K) {
                sum = K;
        }
        else {
                sum = A - (K-A-B);
        }
        cout << sum << endl;
}


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

int main() {
    // 入力
    int A, B, C, X;
    cin >> A >> B >> C >> X;

    // 求める
    int num = 0;
    for (int a = 0; a <= A; ++a) {
        for (int b = 0; b <= B; ++b) {
            for (int c = 0; c <= C; ++c) {
                // 条件を満たしていたらカウント
                if (500*a + 100*b + 50*c == X) {
                    ++num;
                }
            }
        }
    }

    // 答えを出力
    cout << num << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1000000000; //10^9

int main(void){
    int K, N; cin >> K >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }

    int mmax = 0;
    for (int i = 1; i < N; i++){
        mmax = max(mmax, A.at(i) - A.at(i - 1));
    }
    mmax = max(mmax, K + A.at(0) - A.at(N - 1));

    cout << K - mmax << endl;
    
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    int n;
    cin >> n;
    map<int,int> data;
    rep(i,0,n){
        int a;
        cin >> a;
        data[a]++;
    }
    int m;
    cin >> m;
    map<int,int> ans;
    rep(i,0,m){
        int a;
        cin >> a;
        ans[a]++;
    }
 
    for(auto x:ans){
        if(ans[x.first]>data[x.first]){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    


    return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<char> s1(n), s2(n);
  for(int i=0; i<n; i++)cin>>s1.at(i);
  for(int i=0; i<n; i++)cin>>s2.at(i);

  int i=0;
  long long ans=1;
  if(s1.at(0)==s2.at(0)){
    ans*=3;
    i++;
  }else{
    ans*=6;
    i+=2;
  }

  while(i<n){
    if(s1.at(i)==s2.at(i)){
      if(s1.at(i-1)==s2.at(i-1))ans*=2;
      i++;
    }else{
      if(s1.at(i-1)==s2.at(i-1))ans*=2;
      else ans*=3;
      i+=2;
    }
  }

  cout<<ans%1000000007<<endl;
}

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
A = [list(map(lambda x:int(x)-1,input().split()))[::-1] for _ in range(N)]
d = defaultdict(lambda:0)
q = []
for i in range(N):
    j = A[i].pop()
    i,j = min(i,j),max(i,j)
    d[(i,j)] += 1
    if d[(i,j)] == 2:
        q.append((i,j))

ans = 0
while q:
    ans += 1
    q_ = []
    for i,j in q:
        if A[i]:
            i_ = A[i].pop()
            i,i_ = min(i,i_),max(i,i_)
            d[(i,i_)] += 1
            if d[(i,i_)] == 2:
                q_.append((i,i_))
        if A[j]:
            j_ = A[j].pop()
            j,j_ = min(j,j_),max(j,j_)
            d[(j,j_)] += 1
            if d[(j,j_)] == 2:
                q_.append((j,j_))
    q = q_

f = True
for i in range(N):
    if A[i]:
        f = False

if f:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 121600
#include<cstdio>
#include<algorithm>
 
using namespace std;
 
const int MAX_N = 100;
 
int N;
int P[MAX_N];
 
int A, B;
 
int main(){
	scanf("%d", &N);
	scanf("%d%d", &A, &B);
	for(int i = 0; i < N; ++i) scanf("%d", P + i);
	int e = 0, m = 0, h = 0;
	for(int i = 0; i < N; ++i){
		if(P[i] <= A) e++;
		else if(P[i] <= B) m++;
		else h++;
	}
	int ans = min(min(e, m), h);
	printf("%d\n", ans);
	return 0;
}

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

int main(void){

    int N; cin>>N;
    map<string, int> blue, red;
    vector<string> moji(N);
    for (int i = 0; i < N; ++i) {
        string tmp; cin>>tmp;
        blue[tmp]++;
        moji[i]=tmp;
    }
    int M; cin>>M;
    for (int i = 0; i < M; ++i) {
        string tmp; cin>>tmp;
        red[tmp]++;
    }
    int mx=0;
    for (int i = 0; i < N; ++i) {
        int tmp;
        tmp = blue[moji[i]]-red[moji[i]];
        mx = max(tmp, mx);
    }
    cout<<mx<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
int a,b,h,m;
double szj,fzj,j;
int main()
{
	scanf("%d%d%d%d",&a,&b,&h,&m);
	szj=(h*60+m)*0.5;
	fzj=6*m;
	j=fabs(szj-fzj);
	if(j>180)j=360-j;
	printf("%.20f",sqrt(a*a+b*b-2*cos(j*M_PI/180)*a*b));
	return 0;
}

Measured memory_bytes: 2596
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, q = list(map(int, input().rstrip('\n').split()))
    s = str(input().rstrip('\n'))
    ls = [0] * n
    for i in range(1, n):
        if s[i] == "C" and s[i-1] == "A":
            ls[i] += 1
        ls[i] += ls[i-1]
    for i in range(q):
        l, r = list(map(int, input().rstrip('\n').split()))
        print(ls[r-1] - ls[l-1])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 53976
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <unordered_map>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug "<< i << std::endl

//const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,k,q;
  std::cin>>n>>k>>q;

  std::vector<ll> a(q);
  rep(i,0,q)std::cin>>a[i];

  std::sort(all(a));

  ll now=0;

  rep(i,0,n){
    ll cnt=0;
    while(now<q&&a[now]==i+1){
      cnt++;
      now++;
    }

    if(q-cnt<k)std::cout<<"Yes\n";
    else std::cout<<"No\n";
  }

  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

const int maxn = 5e5+5;

int n, D;

int d[maxn];
int cur[maxn];
int run[maxn];

int main()
{
	scanf("%d %d", &n, &D);
	for(int i = 1; i<= n; i++) scanf("%d", &d[i]);
	cur[n+1] = 1;
	for(int i = n; i>= 1; i--)
	{
		cur[i] = (2*cur[i+1]> d[i])?cur[i+1]+d[i]:cur[i+1];
	}
	run[1] = D;
	for(int i = 1; i<= n; i++)
	{
		run[i+1] = min(run[i], abs(run[i]-d[i]));
	}
	int q; scanf("%d", &q);
	while(q--)
	{
		int x; scanf("%d", &x);
		if(run[n+1] || cur[x+1]<= run[x]) puts("YES");
		else puts("NO");
	}
}

Measured memory_bytes: 7808
n, c, k = gets.split.map(&:to_i)
times = n.times.map{gets.to_i}.sort


bus = i = 0
while i < n
  pivot = times[i]

  cnt = 0
  while i < n && times[i] <= pivot + k
    cnt += 1
    i += 1
  end

  i -= cnt - c if cnt > c
  bus += 1
end

puts bus


Measured memory_bytes: 4656
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
 
using namespace std;
 
typedef vector<int> vi;
typedef queue<int> qi;
 
int main() {
    ios::sync_with_stdio(false);
 
    int n, m;
    cin >> n >> m;
    vi e[n];
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        e[a].push_back(b);
    }
 
    vi ans;
    for (int i = 0; i < n; i++) {
        int v[n];
        fill(v, v + n, -1);
        qi q;
        for (int y : e[i]) {
            v[y] = i;
            q.push(y);
        }
        while (!q.empty()) {
            int x = q.front();
            q.pop();
 
            if (x == i) {
                vi t;
                x = v[x];
                while (x != i) {
                    t.push_back(x);
                    x = v[x];
                }
                t.push_back(i);
                
                if (ans.size() == 0 || t.size() < ans.size()) {
                    ans = t;
                }
                
                break;
            }
 
            for (int y : e[x]) {
                if (v[y] == -1) {
                    v[y] = x;
                    q.push(y);
                }
            }
        }
    }
 
    if (ans.size()) {
        cout << ans.size() << endl;
        for (int i = ans.size() - 1; i >= 0; i--) {
            cout << ans[i] + 1 << endl;
        }
    } else {
        cout << -1 << endl;
    }
 
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int a,b,c;cin>>a>>b>>c;
    if (a<b&&b<c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main() {
  long N, T, A, sum, t, a, mag;
  cin >> N >> T >> A;
  sum = T + A;
  while (cin >> t >> a)
    mag = max((T + t - 1) / t, (A + a - 1) / a), t *= mag, a *= mag, sum = t + a, T = t, A = a;
  cout << sum << "\n";
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int w[n];
    int all;

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

    int ans = 1e9;
    for (int i = 1; i < n; ++i){
        int left = 0;
        for (int j = 0; j < i; ++j){
            left += w[j];
        }
        int right = all - left;

        ans = min(ans, abs(left-right));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
 *    FileName:
 *      Source:
 *        Date:
 *      Author: Mew
 *	  Function:
 */
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iomanip>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<iterator>
#include<ctime>
using namespace std;
int main()
{
	string s;
	int k;
	cin >> s;
	cin >> k;
	int l = s.length();
	for(int i=0;i<l;i++){
		if(k == 0)break;
		if(s[i] == 'a')continue;
		int now = int('z')- s[i] +1;
		if(k >= now){
			s[i] = 'a';
			k-=now;
		}
	}
	if(k>0){
		s[l-1] =(s[l-1]-'a'+k)%26+'a';
	}
	cout<<s<<endl;
	return 0;
}



Measured memory_bytes: 512
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	static InputStream is = System.in;
	static String INPUT = "";

	public static void main(String[] args) throws Exception
	{
		int n = ni();
		int M = 1000001;
		int W = (M>>>6)+1;
		long[] f1 = new long[W];
		long[] f2 = new long[W];
		long[] ex = new long[W];
		for(int i = 0;i < n;i++){
			int v = ni();
			if(f1[v>>>6]<<~v>=0){
				f1[v>>>6] |= 1L<<v;
			}else{
				f2[v>>>6] |= 1L<<v;
			}
		}
		for(int i = 1;i*2 <= M;i++){
			if((f1[i>>>6]&~ex[i>>>6])<<~i<0){
				for(int j = i*2;j < M;j+=i){
					ex[j>>>6] |= 1L<<j;
				}
			}
		}
		int ans = 0;
		for(int i = 0;i < W;i++){
			ans += Long.bitCount((f1[i]^f2[i])&~ex[i]);
		}
		System.out.println(ans);
	}
	
	private static byte[] inbuf = new byte[1024];
	static int lenbuf = 0, ptrbuf = 0;
	
	private static int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
//	private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); }
	private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private static double nd() { return Double.parseDouble(ns()); }
	private static char nc() { return (char)skip(); }
	
	private static String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private static char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private static char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private static int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private static int ni()
	{
		int num = 0, b;
//		boolean minus = false;
//		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
//		if(b == '-'){
//			minus = true;
//			b = readByte();
//		}
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9')));
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return num;
//				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}


Measured memory_bytes: 33924
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	l := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&l[i])
	}
	sort.Ints(l)
	ans := 0
	for i := 0; i < k; i++ {
		ans += l[n-i-1]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
LL N, K;
VEC<LL> A;
LL answer(LL x) {
  LL sum = 0;
  REP(i, 0, N) {
    sum += (x xor A[i]);
    // DUMP(sum, x, A[i], x xor A[i]);
  }
  return sum;
}

int main() {
  cin >> N >> K;
  A = VEC<LL>(N);
  REP(i, 0, N) cin >> A[i];
  LL ma = pow(2, (LL)log2(K));
  // DUMP(ma);
  LL x = 0;
  for (LL bit = ma; bit > 0; bit >>= 1) {
    // DUMP("bit: ", bit);
    LL cnt = 0;
    REP(i, 0, N) {
      // if on
      if ((bit & A[i]) > 0) {
        ++cnt;
      }
    }
    // DUMP("cnt: ", cnt);
    if (cnt < (double)N / 2 && x+bit <= K) x += bit;
  }
  LL ans = 0;
  ans = answer(x);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main() {

  int h, w;
  int i, j;

  while(1) {
    scanf("%d %d", &h, &w);

    if(h == 0 && w == 0)
      break;
    else {
      for(i = 0; i < h; i++) {
	for(j = 0; j < w; j++) {
	  if((i+j) % 2)
	    printf(".");
	  else
	    printf("#");
	}
	printf("\n");
      }
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>
#include <deque>

using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(){

    ll N, K;
    cin >> N >> K;
    ll maxVal = 0;

    deque<ll> v;
    for(int i = 0; i < N; i++){
        ll val;
        cin >> val;
        v.push_back(val);
    } 

    // act: 行動する回数
    for(ll act = 0; act <= K; act ++){

        // get: actのうち，取得する回数
        // ret: 返却する回数

        for(ll get = 0; get <= min(act, N); get ++){
            ll ret = act - get;
            if(ret > get) continue; //とった回数以上は返せない

            // left : 左側からとる個数
            // right: 右側からとる個数
            for(ll left = 0; left <= get; left++){
                ll right = get - left;
                
                deque<ll> tmp = v;
                //for(int i = 0; i < N; i++) cout << v[i] ;
                //cout << endl;
                vector<ll> ans;
                for(ll l = 0; l < left; l++){
                    ans.push_back( tmp.front() );
                    tmp.pop_front();
                }
                for(ll r = 0; r < right; r++){
                    ans.push_back( tmp.back() );
                    tmp.pop_back();
                }
                sort( rall(ans) );
                ll sum = 0;
                for(int i = 0; i < get - ret; i++){
                    sum += ans[i];
                }
                maxVal = max(sum, maxVal);

            }



        }
    }
    cout << maxVal << endl;
}   

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;


int main() {
    ll n;
    cin >> n;
    vector<string> S(n);
    string ans;
    rep(i,n) cin >> S[i];

    int ans_chr[26];
    rep(i,26) ans_chr[i] = MOD;

    rep(i,n){
        int tmp_chr[26] = {0};
        rep(j,S[i].size()){
            tmp_chr[(S[i][j] - 'a')]++;
        }
        rep(j,26) ans_chr[j] = min(ans_chr[j],tmp_chr[j]);
    }

    rep(i,26){
        rep(j,ans_chr[i]) ans += ('a' + i);
    }

    cout << ans;
    //printf("%.15lf", ans);
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
class WhatDayIsToday
  def initialize
    init_ndays
    init_week
    init_calendar
  end

  def init_ndays
    @ndays = Array.new(12, 31)
    @ndays[1] = 29
    @ndays[3] = @ndays[5] = @ndays[8] = @ndays[10] = 30
  end

  def init_week
    @week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
  end

  def init_calendar
    c = 3
    @calendar = []
    12.times do |i|
      temp = []
      @ndays[i].times do |j|
        temp.push @week[c % 7]
        c += 1
      end
      @calendar.push temp
    end
  end

  def what_day(month, day)
    @calendar[month - 1][day - 1]
  end
end

calendar = WhatDayIsToday.new

while line = gets do
  month, day = line.chomp.split(" ").map(&:to_i)
  break if month == 0
  puts calendar.what_day(month, day)
end

Measured memory_bytes: 8620
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] d = new int[n];

		for (int i = 0; i < n; i++) {
			d[i] = sc.nextInt();
		}

		Arrays.sort(d);

		if (d[n / 2 - 1] == d[n / 2]) {
			System.out.println("0");
		} else {

			System.out.println(d[n / 2] - d[n / 2 - 1]);
		}
	}
}

Measured memory_bytes: 50916
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<fstream>
#include<map>
#include<bitset>
#include<unordered_map>
#include<cstring>
#include<cctype>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define mod 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define allr(v) v.rbegin(),v.rend()
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
ll fix_mod(ll x, ll y)
{
	return (y + x % y) % y;
}
void fast() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);

#ifdef ONLINE_JUDGE
	//freopen("crosses.in", "r", stdin);

	//freopen("crosses.out", "w", stdout);
#endif
#ifndef ONLINE_JUDGE
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
}
map<int, int>mp;
int arr[400][400];
int main()
{
	Mohammed_Atef_Hassan
		int n, m,k;
	cin >> n >> m>>k; char c;
	for (int i = 0; i < m; i++)
		mp[i] = -1;
	int cnt = 1;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> c;
			if (c == '#')
			{
				for (int k = mp[j] + 1; k <= i; k++)
					arr[k][j] = cnt;
				cnt++;
				mp[j] = i;
			}
		}
	}
	for (int j = 0; j < m; j++)
	{
		if (mp[j] == -1)continue;
		for (int i = mp[j] + 1; i < n; i++)
		{
			arr[i][j] = arr[i - 1][j];
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (arr[i][j] != 0)
			{
				for (int k = j - 1; k >= 0; k--)
				{
					if (arr[i][k])break;
					arr[i][k] = arr[i][j];
				}
				for (int k = j + 1; k < m; k++)
				{
					if (arr[i][k])break;
					arr[i][k] = arr[i][j];
				}
			}
		}
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cout << arr[i][j] << " \n"[j == m - 1];
}

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

int main ()
{
    int r, c;
    cin >> r >> c;
    int arr[r+1][c+1];
    
    for (int i = 0;i < r+1;i++)
        for (int j = 0;j < c+1;j++)
            arr[i][j] = 0;
    
    
    for (int i = 0;i < r;i++)
        for (int j = 0;j < c;j++)
            cin >> arr[i][j];
            
    for (int i = 0;i < r+1;i++)
    {
        for (int j = 0;j < c;j++)
        {
            arr[i][c] += arr[i][j];
            if (i != r) arr[r][j] += arr[i][j];
        }
    }
    
    for (int i = 0;i < r+1;i++)
    {
        for (int j = 0;j < c+1;j++)
        {
            cout << arr[i][j];
            if (j != c) cout << " ";
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

ll fac(ll n){
  return n * (n + 1) / 2;
}

int main(){
  ll N; cin >> N;
  ll ans = 0;
  repn(i,N){
    ans += i * fac(N / i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+7;
int q,t,f;
string se,s,con;
char c;
int main()
{
    cin>>s;
    cin>>q;
    
   for(int i=0;i<q;i++){
        cin>>t;
        if(t==1) swap(se,s);
        else{
            cin>>f>>c;
            if(f==1){
               se+=c;
            }
            else{
                s=s+c;
            }
        }
    }
    reverse(se.begin(),se.end());
    
    cout<<se<<s;
    
    return 0;
}

Measured memory_bytes: 1496
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String s = sc.next();

			char before = ' ';
			for(char c : s.toCharArray()) {
				if(c == before) {
					System.out.println("Bad");
					return;
				}
				before = c;
			}
			System.out.println("Good");
		}
	}
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A+B > C+D) {
    cout << "Left" << endl;
  }
  else if (A+B < C+D) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long w = sc.nextLong();

        if(h == 1 || w == 1) {
            System.out.println(1);
            return;
        }
        long t = 0;
        if(h%2==1&&w%2==1) {
            t = ((h*w)/2)+1;
        } else {
            t = (h*w)/2;
        }
        System.out.println(t);
    }
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template <typename T1, typename T2> 
inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin >> n >> m;
  int to, from;
  int ans[n] = {0};
  rep(i, m) { cin >> to >> from;
    to--, from--;
    ans[to]++, ans[from]++;
  }
  rep(i, n) { cout << ans[i] << endl; }
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
//#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  
  vvl dp(c+1, vl(d+1, 0));
  dp[a][b]=1;
  
  rep2(i, 1, c-a+d-b) rep2(j, 0, i) if(a+j<=c and b+i-j<=d) {
    dp[a+j][b+i-j] =dp[a+j-1][b+i-j]*(b+i-j)
                    +dp[a+j][b+i-j-1]*(a+j)
                    -dp[a+j-1][b+i-j-1]*(a+j-1)*(b+i-j-1);
    ((dp[a+j][b+i-j] %= MOD) += MOD) %= MOD;
  }
  
  cout << dp[c][d] << newl;
  return 0;
}

Measured memory_bytes: 73668
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) string((s).rbegin(), (s).rend())
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

int main(){

	char m[200];

	m[')'] = '(';
	m[']'] = '[';

	while(1){
		string s;
		getline(cin, s);
		if(s.size() == 1 && s[0] == '.')break;
		stack<char> st;
		rep(i, s.size()){
			if(s[i] == '(' || s[i] == '[') st.push(s[i]);
			if(s[i] == ')' || s[i] == ']'){
				if(st.size() < 1){
					st.push('a');
					break;
				}
				if(st.top() == m[s[i]]){
					st.pop();
				}else{
					break;
				}
			}
		}
		cout << (st.size()?"no":"yes") << endl;
	}

	return 0;
}

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

ll dp[200001][5];

int main(){
	long long L;
	scanf("%lld",&L);
	vector<long long> A(L-1+1);
	for(int i = 0 ; i <= L-1 ; i++){
		scanf("%lld",&A[i]);
	}

	// memset(dp, 1e9, sizeof(dp));
	// dp[0][0] = 0;

	for(int i = 1 ; i <= L ; i++){
		for(int j = 0 ; j <= 4 ; j++){
			ll dpmin = 1e15;
			for (int k = 0; k <= j; k++) dpmin = min(dpmin, dp[i-1][k]);
			if (j == 0 || j == 4) dp[i][j] = dpmin+A[i-1];
			if (j == 1 || j == 3) {
				ll add;
				if (A[i-1]%2 == 1) add = 1;
				if (A[i-1]%2 == 0) add = 0;
				if (A[i-1] == 0) add = 2;
				dp[i][j] = dpmin+add;
			}
			if (j == 2) {
				ll add;
				if (A[i-1]%2 == 1) add = 0;
				if (A[i-1]%2 == 0) add = 1;
				dp[i][j] = dpmin+add;
			}
			// if (i == 1) cout << dp[i][j] << " ";
		}
	}
	ll res = 1e15;
	for(int i = 0 ; i <= 4 ; i++) res = min(res, dp[L][i]);
	// cout << endl;
	// for(int i = 1 ; i <= L ; i++){
	// 	for(int j = 0 ; j <= 4 ; j++){
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	printf("%lld\n", res);

	return 0;
}


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


int main(){
    int a, b;
    cin >> a >> b;
    if(b == 1){
        cout << 0 << endl;
        return 0;
    }
    b -= a;
    a--;
    int cnt = 1;
    while(b > 0){
        b -= a;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import sys
from heapq import heappop, heappush


def main():
    input = sys.stdin.readline
    INF = 10**9 + 1
    Q = int(input())
    left = []
    right = []
    min_val = 0
    for _ in range(Q):
        q = list(map(int, input().split()))
        if q[0] == 1:
            a, b = q[1], q[2]

            # Update median
            heappush(left, -a)
            heappush(right, a)

            left_max = -heappop(left)
            right_min = heappop(right)

            median_left = min(left_max, right_min)
            median_right = max(left_max, right_min)

            heappush(left, -median_left)
            heappush(right, median_right)

            # Update minimum value of f(x)
            min_val += abs(median_right - median_left)
            min_val += b

        else:
            median = -heappop(left)
            print('{} {}'.format(median, min_val))

            heappush(left, -median)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18988
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<int> count(N, 0);
  for (int i = 0; i < N; i++){
    count[A[i]]++;
  }
  if (N % 2 == 1){
    bool flg = true;
    if (count[0] != 1){
      flg = false;
    }
    for (int i = 1; i < N; i++){
      if (i % 2 == 1){
        if (count[i] != 0){
          flg = false;
        }
      } else {
        if (count[i] != 2){
          flg = false;
        }
      }
    }
    if (!flg){
      cout << 0 << endl;
    } else {
      long long ans = 1;
      for (int i = 0; i < (N - 1) / 2; i++){
        ans *= 2;
        ans %= 1000000007;
      }
      cout << ans << endl;
    }
  } else {
    bool flg = true;
    for (int i = 0; i < N; i++){
      if (i % 2 == 0){
        if (count[i] != 0){
          flg = false;
        }
      } else {
        if (count[i] != 2){
          flg = false;
        }
      }
    }
    if (!flg){
      cout << 0 << endl;
    } else {
      long long ans = 1;
      for (int i = 0; i < N / 2; i++){
        ans *= 2;
        ans %= 1000000007;
      }
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 1024
h,n=map(int,input().split())
ma=[]
for _ in range(n):
  a=list(map(int,input().split()))
  ma.append(a)
  
inf=float('inf')
dp=[inf for _ in range(h+1) ]

dp[h]=0

for i in range(1,h+1):
  j=h+1-i
  for x in ma:
    p=x[0]
    q=x[1]
    if j-p>=1:
      dp[j-p]=min(dp[j-p],dp[j]+q)
    else:
      dp[0]=min(dp[0],dp[j]+q)
      
print(dp[0])
    

Measured memory_bytes: 74452
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int A, B;
    cin >> A >> B;
    int c = B - A;
    output(c * (c - 1) / 2 - A);
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define R(i,c,n) for(int i=c;i<n;i++)
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back
using namespace std;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int func(int a){
    return a%2==0 ? a/2 : 3*a+1;
}

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

  int s;
  cin >> s;
  vector<int> v;
  
  int count = 1;
  int tmp=0;
  while(true){
    if(count == 1){
        v.push_back(s);
        count ++;
        continue;
    }else{
        tmp = func(v.back());
    }
    if(find(v.begin(),v.end(),tmp) != v.end()){
        break;
    }
    count ++;
    v.push_back(tmp);
  }
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256