akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " (" << x.first << " : " << x.second << ")" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "["; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "(" << obj.first << ", " << obj.second << ")"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print_sim_py(void) {cout << endl;}
template <class Head> void print_sim_py(Head&& head) {cout << head;print_sim_py();}
template <class Head, class... Tail> void print_sim_py(Head&& head, Tail&&... tail) {cout << head << " ";print_sim_py(forward<Tail>(tail)...);}

#define print(...) print_sim_py(__VA_ARGS__);
#else
#define print(...);
#endif


void bfs(queue<pair<ll,ll>>& q,vector<list<ll>>& g, vector<ll>& flag){
    while(!q.empty()){
        ll f = q.front().first;
        ll x = q.front().second;
        q.pop();
        print("#",f,">",x)
        for(auto&& y: g[x]){
            print("$",x,">",y)
            if(flag[y] > flag.size()){
                flag[y] = x;
                q.push(pair<ll,ll>(x,y));
            }
        }
    }
    print(flag);
}

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

    ll n,m;

    cin >> n >> m;

    vector<list<ll>> g(n,list<ll>());
    vector<ll> flag(n,n+1);
    flag[0] = 0;
    
    for(int i=0; i<m; i++){
        ll a,b;
        cin >> a >> b;

        a--;b--;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    queue<pair<ll,ll>> q;
    q.push(pair<ll,ll>(0,0));

    bfs(q,g,flag);

    cout << "Yes" << endl;

    for(int i=1; i<n; i++)
        cout << flag[i]+1 << endl;

    return 0;
}

Measured memory_bytes: 20596
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}
 
int n, m, k;
ll a[N], b[N];
vector<ll> A, B;

int main () {
	SpeedForce;
	cin >> n;
	For (i, 1, n) {
		cin >> a[i] >> b[i];
		a[i] *= 2;
		b[i] *= 2;
		A.pb(a[i]), B.pb(b[i]);
	}
	sort(every(A));
	sort(every(B));

	if(n&1) {
		cout << (B[n/2] - A[n/2] + 2) / 2 << '\n';
		return 0;
	}
	//cout << (B[n/2]+B[n/2-1]) / 2 << ' ' << (A[n/2]+A[n/2-1]) / 2 << '\n'; 
	//cout << "res:\n";
	cout << ((B[n/2]+B[n/2-1]) / 2 - (A[n/2]+A[n/2-1]) / 2 + 1) << '\n';

	

	return Accepted;
}

// B...a

Measured memory_bytes: 9868
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))

if sum(a)<x:
  cnt=n-1
else:
  ans=0
  cnt=0
  for i in range(n):
    ans+=a[i]
    cnt+=1
    if ans==x:
      break
    elif ans>x:
      cnt-=1
      break
print(cnt)

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

const int MAX = 200005;
const ll MOD = 1000000007;
vector<int> E[MAX];
pair<ll, ll> dp[MAX];
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long pow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

void dfs(int u, int p=-1) {
  for (int v: E[u]) {
    if (v == p) continue;
    dfs(v, u);
    dp[u].first *= (COM(dp[u].second+dp[v].second, dp[v].second) * dp[v].first) % MOD;
    dp[u].first %= MOD;
    dp[u].second += dp[v].second;
  }
  ++dp[u].second;
}

void bfs(int u, int p=-1) {
  for (int v: E[u]) {
    if (v == p) continue;
    ll c = COM(dp[u].second-1, dp[v].second);
    c = pow(c, MOD-2);
    ll d = pow(dp[v].first, MOD-2);
    ll e = (dp[u].first * c) % MOD * d % MOD;
    dp[v].first *= COM(dp[u].second-1, dp[v].second-1) * e % MOD;
    dp[v].first %= MOD;
    dp[v].second = dp[u].second; 
    bfs(v, u);
  }
}

int main() {
  int n;
  cin >> n;
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  COMinit();
  
  rep(i, n) dp[i] = make_pair(1ll, 0ll);
  dfs(0);
  bfs(0);
  rep(i, n) cout << dp[i].first << endl;
  
  return 0;
}

Measured memory_bytes: 22556
#include<stdio.h>
int q[300010],ta[100010],nt[100010];
int MIN(int a,int b){return a<b?a:b;}
void mklsd(int v,int e,int *a,int *b){
  int i;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i]=ta[a[i]];
    ta[a[i]]=i;
  }
}
int main(){
  int n,m,a[100010],b[100010],s,t,i,j,k,g,r;
  int c[100010][3];
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++){
    for(j=0;j<3;j++)c[i][j]=1e9;
  }
  for(i=0;i<m;i++){
    scanf("%d %d",&a[i],&b[i]);
    a[i]--;
    b[i]--;
  }
  scanf("%d %d",&s,&g);//printf("a\n");
  mklsd(n,m,a,b);
  /*for(i=0;i<n;i++){printf("%d:",i);
    for(j=ta[i];j+1;j=nt[j])printf("%d",b[j]);
    printf("\n");
    }///*/
  c[s-1][0]=0;
  q[t=0]=(s-1)*10+0;
  for(r=1;r-t;t++){
    j=(q[t]%10+1)%3;
    for(i=ta[q[t]/10];i+1;i=nt[i]){//printf("%d %d\n",q[t]/10,b[i]);
      if(c[b[i]][j]<1e8)continue;
      c[b[i]][j]=c[q[t]/10][q[t]%10]+1;
      q[r++]=b[i]*10+j;
    }
  }
  printf("%d\n",c[g-1][0]<1e8?c[g-1][0]/3:-1);
  return 0;
}


Measured memory_bytes: 4096
#coding: UTF-8
import math

def PC(a):
    for k in range(len(a)):
        area = ""
        H = int(a[k].split(" ")[0])
        W = int(a[k].split(" ")[1])
        if H == 0 and W == 0:
            break
        for j in range(H):
            if j%2 == 0:
                for i in range(W):
                    if i%2 == 0:
                        area += "#"
                    else :
                        area += "."
            else :
                for i in range(W):
                    if i%2 == 0:
                        area += "."
                    else:
                        area += "#"                    
            print(area)
            area = ""
        print("")

if __name__=="__main__":
    a = []
    for i in range(300):
        a.append(input())
        if a[i] == "0 0":
            break
    PC(a)    

Measured memory_bytes: 7764
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

typedef pair<long, int>P;

int main(void){
    int num;    cin >> num;
    long sectionHeight[num];
    
    int count = 1;
    cin >> sectionHeight[0];
    int prev;
    for(int i = 1; i < num; i++){
        cin >> prev;
        if(sectionHeight[count - 1] != prev){
            sectionHeight[count] = prev;
            count++;
        }
    }
    num = count;
    P p[num];
    for(int i = 0; i < num; i++){
        p[i].first = sectionHeight[i];
        p[i].second = i;
    }
    sort(p, p + num);
    int cnt = 0;
    int ans = 0;
    if(num > 1){
        for(int i = num-1; i >= 0; i--){
            if(p[i].second == 0){
                if(sectionHeight[p[i].second + 1]<sectionHeight[p[i].second])   cnt++;
            }else if(p[i].second == num - 1){
                if(sectionHeight[p[i].second - 1]<sectionHeight[p[i].second])   cnt++;
            }else{
                if(sectionHeight[p[i].second - 1]>sectionHeight[p[i].second] && sectionHeight[p[i].second + 1]>sectionHeight[p[i].second])  cnt--;
                else if(sectionHeight[p[i].second - 1]<sectionHeight[p[i].second] && sectionHeight[p[i].second + 1]<sectionHeight[p[i].second]) cnt++;
            }
            
            if(i != 0){
                if(p[i - 1].first != p[i].first)    ans = (ans >= cnt) ? ans : cnt;
            }else ans = (ans >= cnt) ? ans : cnt;
        }
    }
    else{
        if(p[0].first > 0)  ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5440
h,w = map(int,input().split())
if h == w == 1:
    print(1)
if max(h,w) >= 2 and min(h,w) ==1:
    print(max(h,w) -2)
if max(h,w) >= 2 and min(h,w) ==2:
    print(0)
if max(h,w) >= 3 and min(h,w) >=3:
    print((h-2)*(w-2))


Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>
int main()
{
    int N,x,y,sum=0;
    int D[50];
    scanf("%d",&N);
    for (x=0;x<N;x++)
    {
    	scanf("%d",&D[x]);
	}
	for (x=0;x<N-1;x++)
	{
		for (y=x+1;y<N;y++)
		{
			sum+=D[x]*D[y];
		}
	}
	printf("%d",sum);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 long long int f(long long int x,long long int A, long long int B)
 {long long int aiu;

  aiu=(B/x)-((A-1)/x);
   return aiu;
 }
 
long long int gcd(long long int n, long long int m)
{if(m==0)return n;
 return gcd(m,n%m);
}
int main() {
	int sum=0;
  	long long int a,b,c,d;
  	cin>>a>>b>>c>>d;
   	
/*    if(!(x%c==0)&&!(x%d==0)){
    	sum=sum+1;}      
      x=x+1;
    }
  cout<<sum<<endl;   */
  cout<<b-a+1-f(c,a,b)-f(d,a,b)+f(c*d/gcd(c,d),a,b)<<endl;
 // cout<<f(d*c,a,b)<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int N;
  int a[200]={0};
  int i;
  int det = 1;
  int count=0;

  scanf("%d",&N);

  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }

  while(det==1){
    for(i=0;i<N;i++){
      if(a[i]%2!=0){
        det =0;
      }
    } 

    if(det==1){
      for(i=0;i<N;i++){
        a[i]=a[i]/2;
      }
      count++;
    }
  }  
  printf("%d",count);
}




Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(void) {
	int i=1, j, max, a[3],kaisu;
	cin >> kaisu;
	while (1) {
		cin >> a[0] >> a[1] >> a[2];
		if (a[0] >= a[1] && a[0] >= a[2]) {
			if (a[0] * a[0] == a[1] * a[1] + a[2] * a[2])
				cout << "YES" << endl;
			else
				cout << "NO" << endl;
		}
		else if (a[1] >= a[0] && a[1] >= a[2]) {
			if (a[1] * a[1] == a[2] * a[2] + a[0] * a[0])
				cout << "YES" << endl;
			else
				cout << "NO" << endl;
		}
		else
		{
			if (a[2] * a[2] == a[1] * a[1] + a[0] * a[0])
				cout << "YES" << endl;
			else
				cout << "NO" << endl;

		}

		if (i == kaisu)break;
		i++;
	}
	return 0;
}

Measured memory_bytes: 1156
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let h: usize = sc.read();
    let w: usize = sc.read();
    let r: usize = sc.read();
    let c: usize = sc.read();
    if h % r == 0 && w % c == 0 {
        sc.write("No\n".to_string());
    } else if h % r == 0 {
        sc.write("Yes\n".to_string());
        let ans = solve(w, c);
        for _ in 0..h {
            for i in 0..w {
                if i > 0 {
                    sc.write(" ".to_string());
                }
                sc.write(format!("{}", ans[i]));
            }
            sc.write("\n".to_string());
        }
    } else {
        sc.write("Yes\n".to_string());
        let ans = solve(h, r);
        for i in 0..h {
            for j in 0..w {
                if j > 0 {
                    sc.write(" ".to_string());
                }
                sc.write(format!("{}", ans[i]));
            }
            sc.write("\n".to_string());
        }
    }
}

fn solve(h: usize, r: usize) -> Vec<i64> {
    let mut s = vec![0; h + 1];
    for i in 0..(h + 1 - r) {
        s[i + r] = s[i] - 1;
    }
    let mut cur = h;
    s[h] = 1;
    loop {
        if cur < r {
            break;
        }
        s[cur - r] = s[cur] + 1;
        cur -= r;
    }
    let mut ans = vec![0; h];
    for i in 0..h {
        ans[i] = s[i + 1] - s[i];
    }
    ans
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write(&mut self, s: String) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int n, m, d;

signed main() {
    cin >> n >> m >> d;
    if (d == 0) {
        cout << setprecision(10) << (double)(m - 1) / n << endl;
        return 0;
    }
    int but, nbut;
    if (d * 2 > n) {
        but = n - (d * 2 - n);
        nbut = 0;
    } else {
        but = d * 2;
        nbut = n - but;
    }
    cout << setprecision(10) << (double)(but + 2 * nbut) / n * (m - 1) / n << endl;
}

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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N;
string name, old;

int check(){
  rep(i, old.size()){
    if(name[0] != old[i]) continue;
    //    printf("i %d\n", i);
    REP(j, i+1, old.size()){
      if(name[1] != old[j]) continue;
      //      printf("j %d\n", j);
      int dis = j - i;
      int k, p;
      for(p = i, k = 0; k < name.size() && p < old.size(); p += dis, k++) if(name[k] != old[p]) break;
      if(k == name.size()) return 1;
    }
  }
  return 0;
}

int main(){
  scanf("%d", &N);
  cin >> name;
  int res = 0;
  rep(i, N){
    cin >> old;
    res += check();
  }
  printf("%d\n", res);
  return 0;
}

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

#define N 111

char s[N];
int k;

int main() {
    scanf("%s %d", s, &k);
    int n = strlen(s);
    vector <int> vec;
    for (int i = 0, j = 0; i < n; i = j) {
        while (j < n && s[j] == s[i]) j ++;
        vec.push_back(j - i);
    }
    if (vec.size() == 1) {
        printf("%lld\n", 1ll * k * n / 2);
    }
    else {
        if (s[n-1] != s[0]) {
            int m = 0;
            for (auto x : vec) m += x >> 1;
            printf("%lld\n", 1ll * k * m);
        }
        else {
            int m = 0;
            for (auto x : vec) m += x >> 1;
            m -= vec[0] >> 1, m -= vec.back() >> 1;
            m += vec[0] + vec.back() >> 1;
            printf("%lld\n", 1ll * k * m - (vec[0] + vec.back() >> 1) + (vec[0] >> 1) + (vec.back() >> 1));
        }
    }

    return 0;
}


Measured memory_bytes: 256
n = int(input())
B = list(map(int, input().split()))
ret = []
enabled = True

def get_latest():
  for i in range(len(B)):
    if len(B) - i == B[len(B) - i - 1]:
      break
  else:
    global enabled
    enabled = False
  ret.append(B.pop(len(B) - i - 1))
  if B:
    get_latest()

get_latest()
if enabled:
  for i in range(n):
    print(ret[n - i - 1])
else:
  print(-1)

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

int main() {
    // input
    int W, a, b;
    cin >> W >> a >> b;

    // solve
    if (a > b) swap(a, b);
    int ans = 0;
    if (a + W < b) ans = abs(a + W - b);

    // output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
using ll = long long;
#define rep(i,n) for (int i=0; i < int(n); i++)
using namespace std;
#define INF (1ll << 50)
#define MAX_V 100005

struct edge {
    ll to;
    ll cost;
};

// <最短距離, 頂点の番号>
using P = pair<ll, ll>;

ll V;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(ll s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if (d[v] < p.first) continue;

        for (ll i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    cin >> V;
    ll E;
    cin >> E;
    for (ll i=0; i<E; ++i) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;b--;
        edge e = {b, c};
        G[a].push_back(e);
    }
    for (ll i = V-1; i > 0; --i) {
        edge e = {i-1,0};
        G[i].push_back(e);
    }
    dijkstra(0);
    if(d[V - 1] == INF){
        cout << -1 << endl;
        return 0;
    }
    cout << d[V - 1] << endl;
}


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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> p(n);
  for (auto& v : p) cin >> v;
  vector<int> as(n, 0), bs(n, 1000000000);
  for (int i = 0; i < n; i++)
    as[p[i] - 1] += i + 1;
  for (int i = 0; i < n; i++) {
    as[i] += 20002 * i;
    bs[i] -= 20002 * i;
  }
  cout << as[0];
  for (int i = 1; i < n; i++) {
    cout << ' ' << as[i];
  }
  cout << endl;
  cout << bs[0];
  for (int i = 1; i < n; i++) {
    cout << ' ' << bs[i];
  }
  cout << endl;
}


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

int f1[3][10], f2[3][10], f3[3][10], f4[3][10];
int n, b, f, r, v;

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> b >> f >> r >> v;
        f--, r--;
        if (b == 1)
            f1[f][r] += v;
        if (b == 2)
            f2[f][r] += v;
        if (b == 3)
            f3[f][r] += v;
        if (b == 4)
            f4[f][r] += v;
    }
    for (int i = 1; i <= 4; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 10; k++)
            {
                if (i == 1)
                    cout << " " << f1[j][k];
                if (i == 2)
                    cout << " " << f2[j][k];
                if (i == 3)
                    cout << " " << f3[j][k];
                if (i == 4)
                    cout << " " << f4[j][k];
            }
            cout << endl;
        }
        if (i != 4)
            puts("####################");
    }
}



Measured memory_bytes: 3080
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;

const int MAX_N = 2e3 +6;

bool mp[MAX_N][MAX_N];
int cnt[MAX_N][MAX_N];
int cnt2[MAX_N][MAX_N];
int pre1[MAX_N][MAX_N];
int pre2[MAX_N][MAX_N];

int main () {
    ios::sync_with_stdio(0);cin.tie(0);
    int n,m,q;
    cin >> n >> m >>q;
    memset(mp,0,sizeof(mp));
    memset(cnt,0,sizeof(cnt));
    memset(cnt2,0,sizeof(cnt2));
    for (int i=1;n>=i;i++) {
        string s;
        cin >>s;
        for (int j=1;m>=j;j++) {
            mp[i][j] = (s[j-1]=='1');
        }
    }
    for (int i=1;n>=i;i++) {
        for (int j=1;m>=j;j++) {
            cnt[i][j] = cnt[i][j-1] + cnt[i-1][j] - cnt[i-1][j-1] + mp[i][j];
            cnt2[i][j] = cnt2[i][j-1] + cnt2[i-1][j] - cnt2[i-1][j-1] + (mp[i][j]&&mp[i][j-1]) + (mp[i][j]&&mp[i-1][j]);
            pre1[i][j] = pre1[i][j-1] + (mp[i][j]&&mp[i][j-1]);
            pre2[j][i] = pre2[j][i-1] + (mp[i][j] && mp[i-1][j]);
            //cout<<cnt2[i][j]<<' ';
        }
        //cout<<endl;
    }
    while (q--) {
        int a,b,c,d;
        cin >>a >>b >>c >>d;
        int ans=cnt[c][d] - cnt[c][b-1] - cnt[a-1][d] + cnt[a-1][b-1];
        ans -= (cnt2[c][d] - cnt2[c][b] - cnt2[a][d] + cnt2[a][b] + 0);
        ans -= (pre1[a][d] - pre1[a][b]);
        ans -= (pre2[b][c] - pre2[b][a]);
        cout<<ans<<'\n';
    }
}



Measured memory_bytes: 68608
import * as fs from "fs";
const input = fs.readFileSync("/dev/stdin", "utf-8");

const main = (input: string): void => {
  const [W, a, b] = input.split(" ").map((str) => Number(str));
  if ((a <= b && b <= a + W) || (b <= a && a <= b + W)) {
    console.log(0);
  } else if (b > a) {
    console.log(b - a - W);
  } else {
    console.log(a - b - W);
  }
};

main(input);


Measured memory_bytes: 29644
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#define LL long long
using namespace std;

LL n,ans=9999999999999999;
LL a[200010];

LL now,fh;char ch;
inline LL get_num()
{
	now=0;fh=1;ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')fh=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){now=(now<<1)+(now<<3)+ch-'0';ch=getchar();}
	return now*fh;
}

int main()
{
	n=get_num();
	for(int i=1;i<=n;i++)a[i]=a[i-1]+get_num();
	for(int i=1;i<n;i++)
	{
		ans=min(abs(a[n]-2*a[i]),ans);
	}
	printf("%lld\n",ans);
	return 0;
}


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

int main()
{
    int n;
    string s;
    cin>>n>>s;
    int x=0;
    int ans = 0;
    for (size_t i = 0; i < s.length(); i++)
    {
        if(s[i]=='I'){
            x++;
            ans = max(ans, x);
        }
        else{
            x--;
        }
    }
    cout << ans << endl;

    return 0;
}

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

public struct State
{
    public int Water;
    public int Sugar;
    public int Weight { get { return Water + Sugar; } }
    public double Density
    {
        get
        {
            if (Weight == 0)
            {
                return -1;
            }
            return Sugar * 100 / (double)Weight;
        }
    }

    public State(int w, int s)
    {
        Water = w;
        Sugar = s;
    }
}

class Solution
{
    static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var a = vals[0] * 100;
        var b = vals[1] * 100;
        var c = vals[2];
        var d = vals[3];
        var e = vals[4];
        var f = vals[5];

        var visited = new HashSet<State>();
        var currents = new HashSet<State>() { new State(0, 0) };
        var best = currents.First();

        while (currents.Count > 0)
        {
            var nexts = new HashSet<State>();
            foreach (var cur in currents)
            {
                if (cur.Density > best.Density)
                {
                    best = cur;
                }

                if (cur.Weight + a <= f)
                {
                    nexts.Add(new State(cur.Water + a, cur.Sugar));
                }
                if (cur.Weight + b <= f)
                {
                    nexts.Add(new State(cur.Water + b, cur.Sugar));
                }
                if (cur.Weight + c <= f && (cur.Sugar + c) * 100 <= e * cur.Water)
                {
                    nexts.Add(new State(cur.Water, cur.Sugar + c));
                }
                if (cur.Weight + d <= f && (cur.Sugar + d) * 100 <= e * cur.Water)
                {
                    nexts.Add(new State(cur.Water, cur.Sugar + d));
                }
            }
            currents = nexts;
        }

        Console.WriteLine($"{best.Weight} {best.Sugar}");
    }
}

Measured memory_bytes: 19636
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
int n,m,dp[50001],c[20];
void solve(){
	for(int i=0;i<=n;i++) dp[i]=9000000;
	dp[0]=0;
	for(int i=0;i<m;i++) for(int j=c[i];j<=n;j++) dp[j]=min(dp[j],dp[j-c[i]]+1);
} 
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++) scanf("%d",&c[i]);
	solve();printf("%d\n",dp[n]);
}


Measured memory_bytes: 3392
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    string s;cin>>s;
    cout<<s.substr(0,3)<<endl;
    return 0;
}


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

#define ll long long int

using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<ll> A(n);
    for (auto & a : A) cin >> a;
    sort(A.begin(), A.end(), greater<ll>());

    priority_queue<ll> q;
    ll res = 0;
    for (ll i = 0; i < n; ++i) {
        if (i == 0) {
            q.push(A[i]);
        } else {
            res += q.top(); q.pop();
            q.push(A[i]); q.push(A[i]);
        }
    }
    cout << res << endl;
}


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

using namespace std;

int n,m,q;
vector<int> a;
vector<int> b;
vector<int> c;
vector<int> d;

void dfs(vector<int> &A,int *result)
{
  int now=0;
  if(A.size()==n)
  {
    for(int i=0;i<q;i++)
    {
      if(A[b[i]-1]-A[a[i]-1]==c[i])
        now+=d[i];
    }
    *result=max(*result,now);
    return;
  }
  
  int move_number=(A.empty())?1:A.back();
  for(int i=move_number;i<=m;i++)
  {
    A.push_back(i);
    dfs(A,result);
    A.pop_back();
  }
}

int main()
{
  cin>>n>>m>>q;
  a=b=c=d=vector<int>(q);
  for(int i=0;i<q;i++)
    cin>>a[i]>>b[i]>>c[i]>>d[i];
  vector<int> A;
  int result=0;
 
  dfs(A,&result);
  cout<<result<<endl;
}
  

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define F first
#define S second
#define pi acos(-1)
using ll = long long;
using namespace std;
using namespace __gnu_pbds;
using vl = vector<ll>;
using pll =  pair<ll,ll>;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


ll power(ll x,ll y){
    ll res = 1;
    while(y){
        if(y&1)
            res = (res*x)%md;
        x = (x*x)%md;
        y = y/2;
    }
    return res;
}

void solve(){
    int n;
    cin>>n;
    vl a(n);
    ll ans=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }


    for(int i=0;i<n;i++){
        ans += a[i]/2;
        a[i] = a[i]%2;
        if(i+1<n && a[i] == 1 && a[i+1] > 0){
            a[i+1]--;
            ans++;
        }
    }
    cout<<ans;
}
 
int main()
{
    

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //int n; cin>>n; for (int i = 0; i < n; ++i)
    solve();
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S,T,U;
  int A,B;
  cin>>S>>T;
  cin>>A>>B;
  cin>>U;
 if(S==U) cout<<A-1<<" "<<B<<endl;
 if(T==U) cout<<A<<" "<<B-1<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    unsigned long long S;
    cin >> S;
    unsigned long long X_1,Y_1,X_2,Y_2,X_3,Y_3;
    X_1 = 0;
    Y_1 = 0;
    if ((unsigned long long)sqrt((long double)S)*(unsigned long long)sqrt((long double)S) == S)
    {
        X_2 = (unsigned long long)sqrt((long double)S);
        Y_2 = 0;
        X_3 = 0;
        Y_3 = (unsigned long long)sqrt((long double)S);
    }else if((unsigned long long)sqrt((long double)S)*((unsigned long long)sqrt((long double)S)+1)>S){
        X_2 = (unsigned long long)sqrt((long double)S);
        Y_3 = (unsigned long long)sqrt((long double)S)+1;
        Y_2 = X_2*Y_3-S;
        X_3 = 1;
    }else
    {
        X_2 = (unsigned long long)sqrt((long double)S)+1;
        Y_3 = (unsigned long long)sqrt((long double)S)+1;
        Y_2 = X_2*Y_3-S;
        X_3 = 1;
    }    
    cout << X_1 << " " << Y_1 << " " << X_2 << " " << Y_2 << " " << X_3 << " " << Y_3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 387947498641LL;
#define endl '\n'


int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll n;
  cin >> n;
  vector<string> A(n);
  for (auto& _a : A) cin >> _a;
  map<int64_t, array<ll,26>> cnt;
  for (auto& s : A) {
    int c = s[0]-'a';
    int ns = s.length();
    ll x = 0;
    for (int i = ns-1; i >= 1; --i) x = (x*27 + (s[i]-'a'+1)) % mod;
    ++cnt[x][c];
  }
  

  vector<int> n_char(26);
  ll ans = 0;
  for (auto& s : A) {
    int ns = s.length();
    fill(n_char.begin(), n_char.end(), 0);
    for (int i = 0; i < ns; ++i) ++n_char[s[i]-'a'];

    ll x = 0;
    for (int i = ns; i >= 1; --i) {
      if (i < ns) {
        --n_char[s[i]-'a'];
        x = (x*27 + (s[i]-'a'+1)) % mod;
      }
      auto it = cnt.find(x);
      if (it != cnt.end()) {
        for (int c = 0; c < 26; ++c) {
          if (it->second[c] && n_char[c]) {
            ++ans;
          }
        }
      }
    }
  }
  ans -= n;
  ans = max(ans, 0LL);
  cout << ans << endl;
}


Measured memory_bytes: 44020
/************************************************
 * Au: Hany01
 * Prob: duliu
 * Email: hany01dxx@gmail.com & hany01@foxmail.com
 * Inst: Yali High School
************************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
#define Rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define X first
#define Y second
#define PB(a) push_back(a)
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((int)(a).size())
#define ALL(a) a.begin(), a.end()
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 wozenmezhemecaia

template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

template <typename T> inline T read() {
	static T _, __; static char c_;
    for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
    for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}
//EOT


const int maxn = 2e5 + 5;

int n, all, ls[maxn], lss, ans, fa[maxn], a[maxn], b[maxn];

struct Item {
	int x, y;
}p[maxn];

int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }

int main()
{
#ifdef hany01
	freopen("duliu.in", "r", stdin);
	freopen("duliu.out", "w", stdout);
#endif

	n = read<int>();
	For(i, 1, n) all ^= (a[i] = ls[++ lss] = p[i].x = read<int>());
	For(i, 1, n) ls[++ lss] = b[i] = p[i].y = read<int>();

	ls[++ lss] = all;
	sort(ls + 1, ls + 1 + lss);
	lss = unique(ls + 1, ls + 1 + lss) - ls - 1;

	static int cnt1[maxn], cnt2[maxn];
	For(i, 1, n) {
		a[i] = lower_bound(ls + 1, ls + 1 + lss, a[i]) - ls;
		b[i] = lower_bound(ls + 1, ls + 1 + lss, b[i]) - ls;
		++ cnt1[a[i]], ++ cnt2[b[i]];
	}
	int sb = 0;
	For(i, 1, lss) if (cnt1[i] != cnt2[i]) { sb = i; break; }
	if (sb) {
		int as[5], ass = 0;
		For(i, 1, lss) if (cnt1[i] != cnt2[i]) {
			if (abs(cnt1[i] - cnt2[i]) > 1) { puts("-1"); return 0; }
			as[++ ass] = i; if (ass > 2) break;
		}
		if (cnt2[as[1]] > cnt1[as[1]]) {
			if (ls[as[1]] != all) { puts("-1"); return 0; }
		}
		if (cnt2[as[2]] > cnt1[as[2]]) {
			if (ls[as[2]] != all) { puts("-1"); return 0; }
		}
		if (ass > 2 || (ls[as[1]] != all && ls[as[2]] != all)) { puts("-1"); return 0; }
	}

	For(i, 1, n) {
		p[i].x = lower_bound(ls + 1, ls + 1 + lss, p[i].x) - ls;
		p[i].y = lower_bound(ls + 1, ls + 1 + lss, p[i].y) - ls;
	}
	all = lower_bound(ls + 1, ls + 1 + lss, all) - ls;
	fa[all] = all;
	For(i, 1, n) if (p[i].x != p[i].y) {
		if (!fa[p[i].x]) fa[p[i].x] = p[i].x;
		if (!fa[p[i].y]) fa[p[i].y] = p[i].y;
		++ ans;
		fa[find(p[i].x)] = find(p[i].y);
	}
	For(i, 1, lss) if (fa[i] == i) ++ ans;
	printf("%d\n", ans - 1);

	return 0;
}

Measured memory_bytes: 7040
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!

MOD = 10**9+7

n=input()
D=int(input())

dp = [[[0 for _ in range(D)] for _ in range(2)] for _ in range(len(n)+1)] # 上からi桁まで、is_less, mod_D

dp[0][0][0] = 1
for i,ni in enumerate(n): #i桁目からi+1桁目に遷移
    ni = int(ni)
    for mod_d in range(D):
        for is_less in range(2):#1 なら真に小さい
            for d in range(10 if is_less else ni+1): # d: i+1桁目の数字
                dp[i+1][is_less or d < ni][(mod_d + d)%D] += dp[i][is_less][mod_d]
                dp[i+1][is_less or d < ni][(mod_d + d)%D] %= MOD
#    print(dp)

print((dp[-1][0][0] + dp[-1][1][0] - 1)%MOD)



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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int main(){
  int a, b;
  cin >> a >> b;
  cout << (a>12 ? b : (a>5 ? b/2 : 0)) << endl;
  return 0;
}

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

int main(){
  int A,B;
  cin >> A >> B;
  int ans;
  if(10*(B+1) < 100*A/8 || 100*(A+1)/8 < 10*B){
    cout << -1 << endl;
  }

  else if(100*A/8 > 10*B){
    ans=10*B;
    if(ans*8/100 == A) cout << ans << endl;
    else{
      while(ans*8/100 != A){
        ans += 1;
      }
      if(ans/10 == B) cout << ans << endl;
      else cout << -1 << endl;
    }
  }

  else if(100*A/8 <= 10*B){
    ans=100*A/8;
    if(ans/10 == B) cout << ans << endl;
    else{
      while(ans/10 != B){
        ans += 1;
      }
      if(ans*8/100 == A) cout << ans << endl;
      else cout << -1 << endl;
    }
  }

  else cout << -1 << endl;
}

Measured memory_bytes: 256
import os
import sys

import numpy as np


def solve(inp):
    n = inp[0]
    ans = n * (n + 1) // 2
    for i in range(2, n + 1):
        k = n // i
        ans += i * k * (k + 1) // 2
    return ans


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print(ans)


Measured memory_bytes: 27356
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i)

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

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

  int a, b;
  scanf("%d%d", &a, &b);
  int x = (b-a);
  printf("%d\n", x * (x-1) / 2 - a);
}


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

using namespace std;

#define MAX_N 10000

int count2Div(int a, int count)
{
    if(a % 2 == 0) return count2Div(a / 2, count + 1);
    else return count;
}

int main()
{
    int N;

    scanf("%d", &N);
    int buf, ans = 0;
    for(int i = 0; i < N; i++)
    {
        scanf("%d", &buf);
        ans += count2Div(buf, 0);
    }

    printf("%d\n", ans);

    return 0;
}


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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    string s;
    cin>>s;
    int a[26];
    REP(i, 26){
        a[i] = 0;
    }
    for(auto v:s){
        int tmp = v - 'a';
        a[tmp]++;
        if(a[tmp]>=2){
            cout<<"no"<<endl;
            return 0;
        }
    }
    cout<<"yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
import itertools

def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    # スコアの累積和
    l = list(itertools.accumulate(A))

    score = sum(A[:M])
    for i in range(1, N-M):
        score = max(score, l[i+M] - l[i])
        
    ans = (M + score) / 2

    return ans

print(solve())


Measured memory_bytes: 25152
#include<iostream>
#include<cmath>
#include<string>
#include<list>
#include<vector>
#include<algorithm>
#include<numeric>
#include<queue>
#include<utility>
#include <map>

using namespace std;

int count(int a){
	int ans=0;
	while(a>0){
		if(a%2==1){
			ans++;
		}
		a>>=1;
	}
	return ans%2;
}

int main(int argc, char const *argv[])
{
	/*
	cin>>x;
	cout<<x<<endl;
	*/
	int a,b,c,i,j,k,l,n,m,ans=0;

	cin>>n>>m;

	int s[m]={};
	bool flg;

	for(i=0;i<m;i++){
		cin>>k;
		for(j=0;j<k;j++){
			cin>>l;
			s[i]+=pow(2,l-1);
		}
	}

	int p[m];

	for(i=0;i<m;i++){
		cin>>p[i];
	}

	for(i=0;i<pow(2,n);i++){
		flg=true;
		for(j=0;j<m;j++){
			a=s[j]&i;
			if(count(a)!=p[j]){
				flg=false;
				break;
			}
		}
		if(flg){
			ans++;
		}
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
using namespace std;
int a,b,c;
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	long long ans=0;
	int num=a/b;
	ans+=num*c;
	if(a-num*b>0)
	{
		ans+=c;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3808
#include <stdio.h>

const int MAX_V = 1000000;
int prime[MAX_V+1];
int main() {
    int i, k, v;
    for(i = 2; i <= MAX_V; i++) {
        prime[i] = 1;
    }
    for(i = 2; i*i <= MAX_V; i++) {
        if(prime[i]){
            for(k = 2 * i; k <= MAX_V; k += i) {
                prime[k] = 0;
            }
        }
    }
    while(scanf("%d", &v) != EOF) {
        int cnt=0;
        for(i=2; i<=v; i++){
            if(prime[i]==1){
                cnt++;
            }
        }
        printf("%d\n",cnt);
    }
}
                

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

int main() {
    int x, y;
    cin >> x >> y;
    if(x == 1 && y == 2){
        cout << "Yes" << endl;
        return 0;
    }
    if(x == 1 && y == 4){
        cout << "Yes" << endl;
        return 0;
    }
    if(x > 50){
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < 100; i++){
        for (int j = 0; j < 100; j++){
            if(i * 2 + j * 4 == y && i + j == x){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int DP[1001][1001];
int pt[1001][1001];
int main() {
	while(true){
	int H,W,N;

	int lastX=1,lastY=1;
	cin >> H >> W >> N;
		if(H==0)
	break;
	for(int i=1;i<=H;i++)
		for(int j=1;j<=W;j++)
			cin >> pt[j][i];
	DP[1][1]=N-1;
	for(int i=1;i<=H;i++)
		for(int j=1;j<=W;j++)
			if(i!=1|| j!=1 ){
			DP[j][i]=DP[j][i-1]/2+DP[j-1][i]/2;
			if(pt[j][i-1]==0 && DP[j][i-1] %2 ==1)
			DP[j][i]++;
			if(pt[j-1][i]==1 && DP[j-1][i] %2 ==1)
			DP[j][i]++;
			}
	while(lastX<=W && lastY<=H){
		if((DP[lastX][lastY]+pt[lastX][lastY])%2==1)
		lastX++;
		else
		lastY++;
	}
	cout << lastY << " " << lastX << endl;
	}
	return 0;
}

Measured memory_bytes: 8988
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <map>
using namespace std;

const double pi = acos(-1);
#define nyan cout << "(=^•ω•^=)" << endl;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop while(true)

int n;
string s;
int val=0;
int res;
int rec;
int ans;

signed main(){
	cin>>n>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='.')val++;
		else val--;
		if(val>=res){
			res=val;
			rec=i;
		}
	}
	for(int i=0;i<=rec;i++)if(s[i]=='#')ans++;
	for(int i=rec+1;i<n;i++)if(s[i]=='.')ans++;
	val=0;
	for(int i=0;i<n;i++)if(s[i]=='.')val++;
	if(val>n/2)val=n-val;
	ans=min(ans,val);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    string t = "JOI";
    vector<vi> dp(n+1,vi(4,0));
    dp[0][0] = 1;
    rep(i,n)rep(j,4){
        dp[i+1][j] += dp[i][j];
        if(j < 3 && s[i] == t[j])dp[i+1][j+1] += dp[i][j];
    }
    int ans = dp[n][3];
    reverse(all(s));
    reverse(all(t));
    vector<vi> dp1(n+1,vi(4,0));
    dp1[0][0] = 1;
    rep(i,n)rep(j,4){
        dp1[i+1][j] += dp1[i][j];
        if(j < 3 && s[i] == t[j])dp1[i+1][j+1] += dp1[i][j];
    }
    int ma = 0;
    ma = dp1[n][2];//先頭にJ
    rep(i,n){//s[i]とs[i+1]のあいだに入れる
        int l = n-i;
        ma = max(ma,dp1[l][2]);//J
        ma = max(ma,dp[i][1]*dp1[l][1]);//O
        ma = max(ma,dp[i+1][2]);//I
    }
    cout << ans + ma << endl;
}



Measured memory_bytes: 17160
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  long long dp[n];
  for(int i = 0; i < n; i++){
    cin >> h[i];
    dp[i] = INF;
  }
  dp[0] = 0;
  for(int i = 1; i < n; i++){
    dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
    for(int j = i - k; j < i; j++){
      if(j >= 0){
        dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
      }
    }
  }
  cout << dp[n - 1] << endl;
}

Measured memory_bytes: 4584
#pragma warning(disable:4996)

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

typedef long long ll;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define pb push_back
#define mp make_pair
#define fill(x,y) memset(x,y,sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	int N; cin >> N;
	vector<int> as(N), pos(N);
	REP(i, N) {
		cin >> as[i];
		pos[as[i] - 1] = i;
	}

	ll ans = 0;
	set<int> saw;
	saw.insert(-1);
	saw.insert(N);
	REP(i, N) {
		auto itr = saw.lower_bound(pos[i]);
		ll r = (*itr) - pos[i];
		itr--;
		ll l = pos[i] - (*itr);
		ans += as[pos[i]] * l * r;
		saw.insert(pos[i]);
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	if(n>=1000){
		cout<<"ABD"<<endl;
	}else{
		cout<<"ABC"<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
long long ans;
int main()
{
    cin>>s;
    int len=s.length();
    for(int i=0;i<len;i++){
        long long l=0;
        long long r=0;
        while(i<len&&s[i]=='<'){
            l++;
            i++;
        }
        while(i<len&&s[i]=='>'){
            r++;
            i++;
        }
        i--;
        if(l>=r){
            ans+=((l+1)*l)/2;
            r--;
            ans+=((r+1)*r)/2;
        }else{
            ans+=((r+1)*r)/2;
            l--;
            ans+=((l+1)*l)/2;
        }
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 4240