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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int ctoi(char c) {
  return c - '0';
}

template <class C>
void printContainer(C &container, const char *delim=",") {
  for(const auto &e : container) {
    std::cout << e << delim;
  }
  std::cout << "\n";
}

// Greatest common divisor
template<class T>
T gcd(T x, T y) {
  if(x < y) {
    std::swap(x, y);
  }
  T r = x % y;
  while(r != 0) {
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

// Least common multiple
template<class T>
T lcm(T x, T y) {
  return (x*y)/gcd(x,y);
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  string ans;
  if(a <= c && c <= b){
    ans = "Yes";
  }
  else {
    ans = "No";
  }

  cout << ans << endl;

  return 0;
}


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

def main():
    A, B, C = map(int,readline().split())
    ans = 'NO'
    for i in range(1,B+1):
        if A*i%B==C:
            ans = 'YES'
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10 ** 9)

input = sys.stdin.readline

n, q = map(int, input().split())
edges = [[] for _ in range(n)]
cnt = [0 for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
for i in range(q):
    p, x = map(int, input().split())
    cnt[p - 1] += x

ans = [0 for _ in range(n)]

visit = [False for _ in range(n)]
visit[0] = True

stack = []
stack.append((0, 0))

while stack:
    pos, val = stack.pop(-1)
    val += cnt[pos]
    ans[pos] = val
    for to in edges[pos]:
        if not visit[to]:
            visit[to] = True
            stack.append((to, val))

for x in ans[:-1]:
    print(x, end=' ')
print(ans[-1])


Measured memory_bytes: 87116
import kotlin.math.max

fun main() {
    val (n, m, k) = readLine()!!.split(' ').map { it.toInt() }
    val a = readLine()!!.split(' ').map { it.toInt() }
    val b = readLine()!!.split(' ').map { it.toInt() }

    val sa = LongArray(n + 1)
    val sb = LongArray(m + 1)

    for (i in 0 until n) {
        sa[i + 1] = sa[i] + a[i]
    }

    for (i in 0 until m) {
        sb[i + 1] = sb[i] + b[i]
    }

    var ans = 0

    for (i in 0..n) {
        if (sa[i] > k) continue
        val j = sb.binarySearch(k - sa[i])
        if (j < 0) {
            ans = max(i - (j + 1) - 1, ans)
        } else {
            ans = max(i + j, ans)
        }
    }

    println(ans)
}

Measured memory_bytes: 81608
from collections import deque


h, w = map(int, input().split())
meiro = []
for i in range(h):
    line = input()
    meiro.append(line)


def bfs(y, x):
    dist = [[-1]*w for _ in range(h)]
    if meiro[y][x] == '#':
        return 0
    dist[y][x] = 0

    pattern = [[-1, 0], [1, 0], [0, -1], [0, 1]]
    todo = deque([])
    for dy, dx in pattern:
        ny, nx = y + dy, x + dx
        if 0 <= ny <= h-1 and 0 <= nx <= w-1:
            todo.append([ny, nx, 1])

    while todo:
        y, x, d = todo.popleft()
        if meiro[y][x] == '#':
            continue
        if dist[y][x] != -1:
            continue

        dist[y][x] = d
        for dy, dx in pattern:
            ny, nx = y + dy, x + dx
            if 0 <= ny <= h - 1 and 0 <= nx <= w - 1:
                todo.append([ny, nx, d+1])

    res = 0
    for line in dist:
        res = max(max(line), res)

    return res


ans = []
for y in range(h):
    for x in range(w):
        ans.append(bfs(y, x))

print(max(ans))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N,D;
  cin >> N >>D;
  int ans = 0;
  while(ans * (2 * D + 1) <N) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

   vector<int> s(n+1);
   s[0]=0;
   rep(i, n) s[i+1]=(s[i]+a[i])%k;

   rep(i, n+1) s[i]=(s[i]-i%k+k)%k;

   map<int, int> ma;
   ll cnt=0;
   rep(i, n+1){
      if(i-k>=0) ma[s[i-k]]--;
      cnt+= ma[s[i]];
      ma[s[i]]++;
   }

   cout<<cnt<<endl;
   return 0;
}


Measured memory_bytes: 14260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main(){
    int h, w, k; cin>> h >> w >> k;
    vector<string> c(h);
    forin(c);

    int cnt = 0, ans = 0;
    for(int bit = 0; bit<(1<<h); bit++){
        for(int bit2 = 0; bit2<(1<<w); bit2++){
            for(int i = 0; i<h; i++)for(int j=0; j<w; j++){
                if(c[i][j] == '#' && !(bit & (1<<i)) && !(bit2 & (1<<j))) cnt++;
            }
            if(cnt == k) ans++;
            cnt = 0;
        }
    }
    cout<< ans << endl;
}


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

int main() {
	int a, b, c, k;
	//a=1の枚数 b=0の枚数 c=-1の枚数 k=ひく枚数
	int sum = 0;
	//最大値

	cin >> a >> b >> c >> k;

	if (k - a > 0) {
		sum += 1 * a;
		k = k - a;
	}

	else {
		sum += 1 * k;
		k = k - a;
	}

	k = k - b;

	if (k> 0) {
		sum += -1 * k;
	}

	cout << sum;
	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int n;
  cin >> n;

  n *= 3;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<int>());

  int64_t sum = 0;
  for (int i = 0; i < 2 * n / 3; ++i) {
    if (i % 2 != 0) {
      sum += a[i];
    }
  }

  cout << sum << '\n';

  return 0;
}


Measured memory_bytes: 1408
N=int(input())
a=[[int(i) for i in input().split()] for _ in range(N)]
MOD=10**9+7

dp=[0 for _ in range(1<<N)]
dp[0]=1
# 1<<N=2**N
for S in range(1,1<<N):
    i=bin(S).count('1')
    for x in range(N):
        if (S>>x & 1) and a[i-1][x]==1:
            dp[S]=(dp[S]+dp[S^(1<<x)])%MOD

print(dp[-1])


Measured memory_bytes: 202024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int a, p; cin >> a >> p;
    p += 3*a;
    cout << p/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  string s;
  ll z;
  cin>>s>>z;
  ll n=s.size();

  vector<ll> p(n);
  rep(i,n){
    p[i]=s[i]-'0';
  }

  ll ans[n+5][z+5][2];
  memset(ans,0ll,sizeof(ans));
  ans[0][0][1]=1;
  repo(i,n+1){
    rep(j,z+1){
      ans[i][j][0]+=ans[i-1][j][0];
      ans[i][j+1][0]+=9*ans[i-1][j][0];
      if(p[i-1]) {
        ans[i][j][0]+=ans[i-1][j][1];
        ans[i][j+1][0]+=(p[i-1]-1)*ans[i-1][j][1];
        ans[i][j+1][1]+=ans[i-1][j][1];
      }
      else {
        ans[i][j][1]+=ans[i-1][j][1];
      }
    }
  }

/*  rep(i,n+1){
    rep(j,z+1){
      rep(k,2){
        cout << i << j << k << " " << ans[i][j][k] << endl;
      }
    }
  }
*/

  cout << ans[n][z][0]+ans[n][z][1] << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   string s,t;
   cin>>s>>t;

   vector<long int> countS(26), countT(26);
   long int ans = 0;

   for(long int i = 0; i < s.size(); i++){
   		ans += (s[i] != t[i]);
   		countS[s[i] - 'a']++;
   		countT[t[i] - 'a']++;
   }

   // for(long int i = 0; i < 26; i++){
   // 	if(countS[i] > countT[i])
   // 		ans += countS[i] - countT[i];
   // }

   cout<<ans;
   return 0;
}

Measured memory_bytes: 3796
m, d = map(int, input().split())

ans = 0
for i in range(1, m + 1):
    for j in range(1, d + 1):
        if len(str(j)) == 2:
            str_j = str(j)
            j1, j2 = str_j[0], str_j[1]
            if int(j1) * int(j2) == i and int(j1) >= 2 and int(j2) >= 2:

                ans += 1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
 
int n, ma, mb, dp[45][405][405];
 
int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n >> ma >> mb;
	FOR(i, 45) {
		FOR(j, 405) {
			FOR(k, 405) dp[i][j][k] = 1e9;
		}
	}
	dp[0][0][0] = 0;
	for (int i= 1; i <= n; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		FOR(j, 405) {
			FOR(k, 405) {
				if (j >= a && k >= b) {
					dp[i][j][k] = min(dp[i][j][k], min(dp[i-1][j][k], dp[i-1][j-a][k-b]+c));
				}
				else dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k]);
			}
		}
	}
	int mi = 1e9;
	for (int j = 1; j <= 400; j++) {
		for (int k = 1; k <= 400; k++) {
			if (k*ma == j*mb) mi = min(mi, dp[n][j][k]);
		}
	}
	cout << (mi == 1e9 ? -1 : mi) << endl;
	return 0;
}

Measured memory_bytes: 29184
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

const int MX=200005;
int a[MX];

int main()
{
    int n,x=0;
    scanf("%d",&n);
    for(int i=0,j=0;i<n;i++){
        scanf("%d",&a[i]);
        if(i&1) x^=(a[i]^a[i-1]);
    }
    for(int i=0;i<n;i++){
        if(i) printf(" ");
        printf("%d",x^a[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 4492
#include <iostream>
#include <string>
#include <vector>

using namespace std;

constexpr int M = 2000;
bool match(char a, char b) { return a == b || a == '?' || b == '?'; }

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  vector<bool> ab(100000, false);
  vector<bool> ac(100000, false);
  vector<bool> bc(100000, false);
  // それぞれがいくつずれたときに成立するか
  int A = a.length();
  int B = b.length();
  int C = c.length();
  for (int i = 0; i < A; i++)
    for (int j = 0; j < B; j++)
      if (!match(a[i], b[j]))
        ab[i - j + 50000] = true;
  for (int i = 0; i < A; i++)
    for (int j = 0; j < C; j++)
      if (!match(a[i], c[j]))
        ac[i - j + 50000] = true;
  for (int i = 0; i < B; i++)
    for (int j = 0; j < C; j++)
      if (!match(b[i], c[j]))
        bc[i - j + 50000] = true;
  int ans = 3 * M;
  for (int i = -2 * M; i <= 2 * M; i++)
    for (int j = -2 * M; j <= 2 * M; j++)
      if (!ab[i + 50000] && !ac[j + 50000] && !bc[j - i + 50000]) {
        int L = min(0, min(i, j));
        int R = max(A, max(B + i, C + j));
        ans = min(ans, R - L);
      }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int a[256],n;
  int ln;
  char s[33];
  a['q']=a['a']=a['z']=a['w']=a['s']=a['x']=a['e']=a['d']=a['c']=a['r']=a['f']=a['v']=a['t']=a['g']=a['b']=0;
  a['y']=a['h']=a['n']=a['u']=a['j']=a['m']=a['i']=a['k']=a['o']=a['l']=a['p']=1;
  while(cin>>s&&s[0]!='#'){
    ln=strlen(s);
    n=0;
    for(i=1;i<ln;i++){
      if(a[(int)s[i-1]]!=a[(int)s[i]])
	n++;
    }
    cout<<n<<endl;
  }
  return 0;
}

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

int main()
{
	int n;
	cin >> n;
	char s[n];
	cin >> s;

	int countAllChanges = 0;
	for(int i = 1; i < n; i++){
		if(s[i] == 'E')
			countAllChanges++;
	}

	int ans = countAllChanges;

	for(int i = 1; i < n; i++){
		if(s[i-1] == 'W')
			countAllChanges++;
		if(s[i] == 'E')
			countAllChanges--;
		ans = min(ans,countAllChanges);
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 512
/*ex4_2
ryo_1129*/
#include<stdio.h>
#include<math.h>
//プロトタイプ宣言
double distance(int length_hour,int length_minute,double rad);

int main(void){
    //変数宣言
    int A,B,hour,minute;
    double radhour,radminute,rad,length;
    //入力
    scanf("%d %d %d %d",&A,&B,&hour,&minute);
    //演習率πを決める。
    const double pi = 3.14159265358979;
    //時針、分針を求める。
    radminute = 2*pi*minute/60;
    radhour = 2*pi*(hour*60+minute)/720;
    //角度の差を求める。cos(θ)=cos(-θ)に注意
    rad = radhour - radminute;
    //長さを求める。関数の呼び出し
    length = distance(A,B,rad);
    //出力
    printf("%.9f\n",length);
    return 0;
}
//時針と分針の長さと角度から端点間の長さを求める。引数、時針の長さ、分針の長さ、それらのなす角度
double distance(int length_hour,int length_minute,double rad){
    double length;//変数宣言
    //余弦定理を用いて端点間の長さを求める
    length = sqrt(pow(length_hour,2)+pow(length_minute,2)-2*length_hour*length_minute*cos(rad));
    // 端点間の長さを返す
    return length;
}

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

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

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

	int A,B,C,D; cin >> A >> B >> C >> D;

	cout << min(A,B)+min(C,D) << endl;

	return 0;

}


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

using namespace std;

int main()
{
    string C;
    cin >> C;

    string alphabet = "abcdefghijklmnopqrstuvwxyz";

    for (int i = 0; i < 25; i++)
    {
        if (string{ alphabet[i] } == C)
        {
            cout << alphabet[i + 1] << endl;
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 256
<?php

$abcde = [];

for ($i = 0; $i < 5; $i++) {
    fscanf(STDIN, "%d", $abcde[$i]);
}
fscanf(STDIN, "%d", $k);

if (($abcde[4] - $abcde[0]) > $k) {
    echo ":(";
} else {
    echo "Yay!";
}

Measured memory_bytes: 4856
package main

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

func main() {
	var n int
	fmt.Scanf("%d", &n)
	lines, _ := scanLongIntSlices(1, 10000000)
	nums := lines[0]

	for _, n := range nums {
		if n == 0 {
			fmt.Println("0")
			os.Exit(0)
		}
	}

	prod := 1
	for _, n := range nums {
		if n > 1000000000000000000/prod {
			fmt.Println("-1")
			os.Exit(0)
		}
		prod *= n
	}

	fmt.Printf("%d\n", prod)
}

func scanLongIntSlices(lines int, maxBufSize int) ([][]int, error) {

	res := [][]int{}

	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, bufio.MaxScanTokenSize)
	sc.Buffer(buf, maxBufSize)

	for sc.Scan() {
		line := sc.Text()
		strs := strings.Split(line, " ")
		ints := make([]int, len(strs))
		for i, c := range strs {
			n, err := strconv.Atoi(c)
			if err != nil {
				return nil, err
			}
			ints[i] = n
		}
		res = append(res, ints)
	}

	if err := sc.Err(); err != nil {
		return nil, err
	}

	return res, nil
}


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

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

int main() {
  int n,m;
  cin >> n >> m;
  int inf = 1000000000;
  vector<vector<int>> dp(m+1, vector<int>((1<<n)+1, inf));
  dp[0][0] = 0;
  rep(i,0,m) {
    int a,b;
    cin >> a >> b;
    int mask = 0;
    rep(j,0,b) {
      int c;
      cin >> c;
      mask |= 1<<(c-1);
    }
    rep(j,0,1<<n) {
      if (dp[i][j] == inf) continue;
      chmin(dp[i+1][j], dp[i][j]);
      chmin(dp[i+1][j|mask], dp[i][j]+a);
    }
  }
  if (dp[m-1][(1<<n)-1] == inf) cout << -1 << endl;
  else cout << dp[m-1][(1<<n)-1] << endl;
  return 0;
}


Measured memory_bytes: 19272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<(k) ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=(k) ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef jayinnn
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 100005;

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

/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();
    int n, x, t;
    cin >> n >> x >> t;
    if(n % x == 0){
        cout << (n / x) * t << endl;
    } else {
        cout << ((n / x) + 1) * t << endl;
    }

    return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int dp[2019] = {0};

int main() {
  string s;
  cin >> s;

  ll ans = 0;
  for (int i = 0; i < s.length(); i++) {
    int next[2019] = {0};
    next[s[i]-'0'] += 1;

    if (i > 0) {
      for (int j = 0; j < 2019; j++) {
        next[(j * 10 + (s[i] - '0')) % 2019] += dp[j];
      }
    }
    ans += next[0];
    for(int i = 0; i < 2019; i++) {
      dp[i] = next[i];
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3696
N = int(input())
A = list(map(int,input().split()))
ans,k = [0]*8,0
for a in A:
    if a>=3200: k+=1
    elif a>=2800: ans[7] = 1
    elif a>=2400: ans[6] = 1
    elif a>=2000: ans[5] = 1
    elif a>=1600: ans[4] = 1
    elif a>=1200: ans[3] = 1
    elif a>=800 : ans[2] = 1
    elif a>=400 : ans[1] = 1
    else: ans[0] = 1
print(max(sum(ans),1),sum(ans)+k)

Measured memory_bytes: 3064
fun count(x: Int): Int {
    var cnt = 0
    var tmp = x
    while(tmp%2==0) {
        cnt++
        tmp /= 2
    }
    return cnt
//    val res = cnt
//    return res
}

fun main(args: Array<String>) {
    val N = readLine()!!
    val As = readLine()!!.split(" ").map(String::toInt)
    val counts = As.map { count(it) }

    println(counts.min())
}

Measured memory_bytes: 36076
// Vacation

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

int main(){
    int n;
    cin >> n;
    int a[n][3], dp[n][3];
    for(int i = 0 ; i < n ; i++){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    for(int i = 0; i <= 2 ; i++){
        dp[0][i] = a[0][i];
    }
    for(int i = 1 ; i < n ;i++){
        for(int j = 0; j <= 2 ; j++){
            dp[i][j] = 0;
            for(int c = 0 ; c <= 2 ; c++){
                if(c!=j)
                    dp[i][j] = max(dp[i][j], a[i][j] + dp[i-1][c]);
            }
        }
    }
    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
    return 0;
}

Measured memory_bytes: 2560
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

// utils
func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

// func max(a, b int) int {
// 	return int(math.Max(float64(a), float64(b)))
// }

// func min(a, b int) int {
// 	return int(math.Min(float64(a), float64(b)))
// }

// func abs(a, b int) int {
// 	return int(math.Abs(float64(a) - float64(b)))
// }

// //data types

// type pair struct {
// 	first  int
// 	second int
// }

func main() {
	sc.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()
	p := make([]int, n)

	for i := range p {
		p[i] = nextInt()
	}

	ans := sum(p[0:k])
	diff := 0

	for i := 1; i <= n-k; i++ {
		diff += p[i+k-1] - p[i-1]
		if diff > 0 {
			ans = sum(p[i : i+k])
			diff = 0
		}
	}
	fmt.Printf("%6f", ans)
}

func sum(a []int) float64 {
	sum := 0.0
	for _, v := range a {
		sum += expect(v)
	}
	return sum
}

func expect(v int) float64 {
	if v%2 == 0 {
		return float64(v/2) + 0.5
	}
	return float64(v/2 + 1)
}


Measured memory_bytes: 3072
<?php
fscanf(STDIN, "%d %d %d", $a, $b, $k);

for($i=$a; $i>0; $i--){
    if($a % $i == 0){
        $arr[] = $i;
    }
}

for($i=0; $i<count($arr); $i++){
    if($b % $arr[$i] == 0){
        $array[] = $arr[$i];
    }
}

echo $array[$k-1];
?>

Measured memory_bytes: 4728
xkd=input().split()
x=int(xkd[0])
k=int(xkd[1])
d=int(xkd[2])

ans = abs(x + k*d)
ans = min(ans, abs(x - k*d))

pos = x%d

if (abs(x-pos) // d) % 2 == k % 2 and k >= abs(x-pos)//d: ans=min(ans, pos)

negpos = pos - d

if(abs(x-negpos) // d) % 2 == k % 2 and k >= abs(x-negpos)//d: ans=min(ans,abs(negpos))

print(ans)

Measured memory_bytes: 9208
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
int main() {
    abdelrahman010
    int n , a[N];
    cin >> n;
    for(int i = 0;i < n;i++)
        cin >> a[i];
    sort(a , a + n , greater<>());
    ll ans = a[0];
    for(int i = 1 , j = 2;j < n;i++ , j += 2) {
        ans += a[i];
        if(j != n - 1)
            ans += a[i];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4444
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;

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;
}



int main()
{
	ll  i, j, k, l, m,n, sum, flag, N,  M, K, H, W, B,T,A,C,D;
	sum = 0;
	flag = 0;
	cin >> N >> A>>B>>C>>D;
	REP(i, 0, N) {
		m = i * D - (N -1- i)*C;
		n = i * C - (N - 1-i)*D;
		if (A + n <= B && A + m >= B) {
			output("YES");
		
			return 0;
		}
	}
	output("NO");
	return 0;
	

	
}













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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    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;
    }
}
ll 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;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    ll A,B,C,D;
    cin>>A>>B>>C>>D;
    if(A>B)swap(A,B);
    REP(i,N){
        if(C*(N-1-i)-D*i<=B-A&&B-A<=-C*i+D*(N-1-i)){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	int n;

	cin >> n;

	if (n >= 195) {
		cout << 5 << endl;
	}
	else if (n >= 189) {
		cout << 4 << endl;
	}
	else if (n >= 165) {
		cout << 3 << endl;
	}
	else if (n >= 135) {
		cout << 2 << endl;
	}
	else if (n >= 105) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}


}

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

int main() {
  int a, b;
  while(cin >> a >> b) {
    int t;
    if(a > b) t = b;
    else      t = a;

    for(; t >0; t--) {
      if(a % t == 0 && b % t == 0) break;
    }
    cout << t << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int h,w;
  cin>>h>>w;
  vector<vector<char>> l(h, vector<char>(w));;
  rep(i,h){
    rep(j,w){
      cin>>l.at(i).at(j);
    }
  }
  rep(a,w+2){
    cout<<'#';
  }
  cout<<endl;
  rep(b,h){
    cout<<'#';
    rep(c,w){
      cout<<l.at(b).at(c);
    }
    cout<<'#'<<endl;
  }
  rep(d,w+2){
    cout<<'#';
  }
   cout<<endl;
}

Measured memory_bytes: 256
/*
*/

#define _CRT_SECURE_NO_WARNINGS

#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds

#define eps 1e-6
#define M_PI 3.141592653589793
#define bs 1000000007
#define bsize 337

using namespace std;

const int INF = 1e9;
const int N = 101231;

int n, m;
pair<int, int> ans;

int main(){
	//freopen("fabro.in","r",stdin);
	//freopen("fabro.out","w",stdout);
	//freopen("F:/input.txt", "r", stdin);
	//freopen("F:/output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);
	
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			string st;
			cin >> st;
			if (st == "snuke")
				ans = make_pair(j,i);
		}
	}

	cout << char(ans.first + 'A' - 1) << ans.second << endl;

	cin.get(); cin.get();
	return 0;
}

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

#define say(a) cout<<a<<endl
#define say1(a,b) cout<<a<<" "<<b<<endl
#define loop(a,b) for(int i=a;i<b;i++)

int main()
{
    int i,j,n;
    cin>>n;
    int a[n],d[n];
    long long tum=0;
    loop(0,n) {cin>>d[i];
    d[i]=d[i]*2;
    }
    loop(0,n)
    {
       if(i%2==0)
       {
           tum+=d[i];
       }else
       {
           tum-=d[i];
       }
    }tum/=2;
    a[0]=abs(tum);
    loop(0,n-1)
    {
        a[i+1]=abs(d[i]-a[i]);cout<<a[i]<<" ";
    }cout<<abs(d[n-1]-tum);

}




Measured memory_bytes: 2048
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == '__main__':
    a = [int(i) for i in input().split()]

    for i in range(1,100000002):
        if a[0] % a[1]==0:
            print(-1)
            break

        if i ==10**9+1:
            print(-1)
            break
        if a[0]*i %a[1] >0:
            print(a[0]*i)
            break
        if a[0]*i >10**18 +1:
            print(-1)
            break



Measured memory_bytes: 3828
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define int long long
#define endl "\n"
#define print_array(name,n) for(int o=0;o<n;o++) cout<<name[o]<<" "

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n,k;
    cin>>n>>k;
    vector<int> vec;
    int a;
    for(int i=0;i<n;i++){
    	cin>>a;
    	vec.pb(a);
    } 
    sort(vec.begin(),vec.end());
    for(int i=0;i<min(k,n);i++){
    	vec[n-i-1] = 0;
    }
    int sum = 0;
    for(int i=0;i<n;i++){
    	sum+=vec[i];
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 2420
s = input()
ans1 = 0
for i in range(len(s)):
    if i % 2 == 0:
        ans1 += (s[i] == '0')
    else:
        ans1 += (s[i] == '1')

ans2 = 0
for i in range(len(s)):
    if i % 2 == 1:
        ans2 += (s[i] == '0')
    else:
        ans2 += (s[i] == '1')

print(min(ans1,ans2))

Measured memory_bytes: 3188
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())


aa=a%10
bb=b%10
cc=c%10
dd=d%10
ee=e%10

temp=min(aa,bb,cc,dd,ee)

if aa!=0:
	aaa=(a//10)*10+10
else:
	aaa=a

if bb!=0:
	bbb=(b//10)*10+10
else:
	bbb=b
	
if cc!=0:
	ccc=(c//10)*10+10
else:
	ccc=c
	
if dd!=0:
	ddd=(d//10)*10+10
else:
	ddd=d
	
if ee!=0:
	eee=(e//10)*10+10
else:
	eee=e
	
a1=a+bbb+ccc+ddd+eee
a2=aaa+b+ccc+ddd+eee
a3=aaa+bbb+c+ddd+eee
a4=aaa+bbb+ccc+d+eee
a5=aaa+bbb+ccc+ddd+e

ans=min(a1,a2,a3,a4,a5)

print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
 
using namespace std;
 
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define mp make_pair
#define f first
#define s second
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vpl = vector<pll>;
 
void fio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const long double pi = 3.14159265358979323846;



void solve() {
  ll n;
  cin >> n;
  cout << n + n * n + n * n * n << '\n';
}
 
int main() {
  fio();
  
  int T = 1;
  // cin >> T;
  while (T--) solve();
} 

Measured memory_bytes: 3616
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1

def main():
    n, k = map(int, input().split())
    ans = 0
    for b in range(k + 1, n + 1):
        ans += (b - k) * ((n + 1) // b) + max(0, (n + 1) % b - k)
    if k == 0:
        ans -= n
    print(ans)

main()


Measured memory_bytes: 3060
#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()

using namespace std;
typedef long long ll;

template<typename T>
T gcd(T a, T b) {
    if (a % b == 0) {
        return(b);
    }
    else {
        return(gcd(b, a % b));
    }
}

string binary(int bina) {
    string ans="000000";
    for (int i = 0; bina > 0; i++){
        ans[i] = char(bina % 2 + '0');
        bina = bina / 2;
    }
    return ans;
}

template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

int main(void) {
    int h, w, k;
    cin >> h >> w >> k;
    int ans = 0;
    vector<vector<char>>c(h, vector<char>(w));
    rep(i, h) {
        rep(j,w){
            cin >> c[i][j];
        }
    }
    rep(i, pow(2, h)) {
        rep(j, pow(2, w)) {
            string ws = binary(j);
            string hs = binary(i);

            int black = 0;
            rep(a, h) {
                rep(b, w) {
                    if (c[a][b] == '#' && !(ws[b] != '1' || hs[a] != '1')) {
                        ++black;
                    }
                }
            }
            if (black == k) {
                ++ans;
                //cout << ws << ' ' << hs << endl;
            }

        }
    }
    cout << ans;
}

/*

*/


Measured memory_bytes: 4072
#include<cstdio>
#include<cstring>
#define  N  1100
using  namespace  std;
int  a[N][N],n,m,a1,a2,b1,b2,hang[N],lie[N];
void  solve(int  x,int  y)
{
	for(int  i=1;i<=x;i++)hang[i]=a1;
	for(int  i=x+1;i<=n;i++)hang[i]=a2;
	for(int  i=1;i<=y;i++)lie[i]=b1;
	for(int  i=y+1;i<=m;i++)lie[i]=b2;
	for(int  i=1;i<=n;i++)
	{
		for(int  j=1;j<=m  &&  hang[i];j++)
		{
			if(lie[j])a[i][j]=1,hang[i]--,lie[j]--;
		}
	}
	for(int  i=1;i<=n;i++)
	{
		for(int  j=1;j<=m;j++)printf("%d",a[i][j]);
		printf("\n");
	}
}
int  main()
{
	scanf("%d%d%d%d",&n,&m,&a1,&b1);
	if(a1>m/2  ||  b1>n/2)
	{
		printf("-1\n");
		return  0;
	}
	a2=m-a1;b2=n-b1;
	for(int  i=0;i<=n;i++)
	{
		for(int  j=0;j<=m;j++)
		{
			if(i*a1+(n-i)*a2==j*b1+(m-j)*b2)
			{
				solve(i,j);
				return  0;
			}
		}
	}
	printf("-1\n");
	return  0;
}

Measured memory_bytes: 5504
def main():
    width, height, target = map(int, input().split())
    answer = False
    if target == 0:
        answer = True
    else:
        for i in range(height):
            if answer:
                break
            for j in range(width):
                if (width - j) * (height - i) + i * j == target:
                    answer = True
                    break
    print("Yes" if answer else "No")


if __name__ == '__main__':
    main()



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

int n,m;
int a[101];
int ans;

int main()
{
	scanf("%d",&n);
	for(register int i(1);i<=n;++i)
	{
		scanf("%d",&a[i]);
		ans+=a[i];
	}
	scanf("%d",&m);
	for(register int i(1);i<=m;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		printf("%d\n",ans-a[x]+y);
	}
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define dd double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define pb push_back
#define pc builtin_popcount
#define pcll builtin_popcountll
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
using namespace std;
ll n, c, h[500005], dp[500005];
vector<pll> lines;
ld cross(pll a, pll b) { return (b.S - a.S + 0.0) / (a.F - b.F + 0.0); }
void add(pll new_line) {
  while (lines.size() > 1) {
    int last = lines.size() - 1;
    if (cross(lines[last], lines[last - 1]) < cross(new_line, lines[last - 1]))
      break;
    lines.pop_back();
  }
  lines.pb(new_line);
}
ll get(ll x) {
  int l = 0;
  for (int pos = lines.size(); pos >= 1; pos >>= 1) {
    while (l + pos < lines.size() &&
           cross(lines[l + pos], lines[l + pos - 1]) < x + 0.0)
      l += pos;
  }
  return lines[l].F * x + lines[l].S;
}
int main() {
  speed;
  oprecision;
  // code
  cin >> n >> c;
  forn(n) cin >> h[i];
  add({-2 * h[1], h[1] * h[1]});
  for (int i = 2; i <= n; i++) {
    dp[i] = get(h[i]) + h[i] * h[i] + c;
    add({-2 * h[i], dp[i] + h[i] * h[i]});
  }
  cout << dp[n];
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 11760
#include<stdio.h>
#include<math.h>
int i,j;
long x,t[201]={};
int main(){
    scanf("%ld",&x);
    for(i=1;i<=200;i++)t[i]=powl(i,5);
    for(i=0;i<=200;i++){
        for(j=i;j<=200;j++){
            if(t[i]+t[j]==x){
                printf("%d %d",i,-j);
                return 0;
            }
        }
    }
    for(i=200;i>=0;i--){
        for(j=i;j>=0;j--){
            if(t[i]-t[j]==x){
                printf("%d %d",i,j);
                return 0;
            }
        }
    }
    return 0;
}

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

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

using namespace std;

int main(){
  ll k;cin>>k;
  ll n=50;
  ll a[n];
  rep(i,n)a[i]=n-1+k/n;

  rep(i,k%n){
    a[i]+=n;
    rep(j,n)a[j]--;
    a[i]++;
  }

  cout<<n<<endl;
  rep(i,50){
    cout<<a[i]<<' ';
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>

//#define int long long

using namespace std;

void Main()
{
	int N, D;
	cin >> N >> D;
	vector<vector<int> >X(N, vector<int>(D, 0));
	for (int i = 0; i < N; i++) {
		for (int k = 0; k < D; k++) {
			cin >> X[i][k];
		}
	}

	int ans = 0;
	for (int i = 0; i < N - 1; i++) {
		for (int k = i + 1; k < N; k++) {
			int dist = 0;
			for (int d = 0; d < D; d++) {
				dist += (X[i][d] - X[k][d]) * (X[i][d] - X[k][d]);
			}
			for (int m = 1; m * m <= dist; m++) {
				if (m * m == dist) {
					ans++;
				}
			}
		}
	}

	cout << ans << endl;
}

int32_t main()
{
	Main();
	return 0;
}

/*
void sample()
{
	vector<int> v;
	sort(v.begin(), v.end());
	sort(v.begin(), v.end(), greater<int>());

}
*/



Measured memory_bytes: 256
def make_comb_dp(n):
    dp = [[0] * (n + 1) for i in xrange(n + 1)]
    for i in xrange(n + 1):
        dp[i][0] = 1
        dp[i][i] = 1
    for i in xrange(2, n + 1):
        for j in xrange(1, i):
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]
    return dp



[N,P]=map(int,raw_input().split())
A= [int(x)%2 for x in raw_input().split()]
odd=A.count(1)
even=A.count(0)
dp=make_comb_dp(N)
#P=0
ans=1
for n in range(1,N+1):
    for i in range(0,odd/2+1):
            ans+=dp[odd][i*2]*dp[even][n-i*2]
if P:
    ans=sum(dp[N]) -ans
print ans

Measured memory_bytes: 2696
#include<bits/stdc++.h>
#define f(i,n) for(long int i = 0; i<(long int)n; i++)
#define testcase ll tt; cin >> tt; while(tt--)
#define F first
#define S second
#define ll long long
#define pb push_back
#define vll vector<ll>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

int main(){
    ll n,x,t; cin>>n>>x>>t;
    ll loops = n/(x);
    ll extra = ((n%x) != 0);
    cout<<loops*t+extra*t;
    return 0;
}

Measured memory_bytes: 3616
N, M = map(int,input().split(' '))
A = list(map(int,input().split(' ')))
changeList=[]
for i in range(N):
    changeList.append([A[i],1])

for i in range(M):
    B,C = map(int,input().split(' '))
    changeList.append([C,B])

changeList.sort()
changeList.reverse()
#print(changeList)
tmp=0
card=0
for i in range(len(changeList)):
    drawCardNum=min(changeList[i][1],N-card)
    drawCardValue=changeList[i][0]
    tmp+=drawCardValue*drawCardNum
    card+=drawCardNum
    if card>=N:
        print(tmp)
        exit()

Measured memory_bytes: 34640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,b;
    ll mini=LLONG_MAX; 
    cin>>n;
    for(int i=0;i<5;i++){
        cin>>b;
        mini=min(b,mini);
    }    
   cout<< ((n+mini-1)/mini)+4;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int moto=100,syuu;
	cin>>syuu;
	for(int abc=0;abc<syuu;abc++){
		if(moto%20!=0){
			moto=moto*1.05+1;
		}else{
			moto*=1.05;
		}
	}
	cout<<moto*1000<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
using ll = long long;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repp(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)


int main() {
  string s;  cin >> s;
  if (s[s.size() - 1] != 's') s.push_back('s');
  else {
    s.push_back('e');
    s.push_back('s');
  }

  cout << s << endl;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int main(){
  string s;
  cin >> s;
  ll N = s.size();

  ll cnt[26];
  fill(cnt, cnt + 26, 0);
  for(int i = 0; i < N; i++){
    cnt[(int)(s[i] - 'a')]++;
  }

  ll ans = N * (N - 1) / 2;
  for(int i = 0; i < 26; i++){
    ans -= cnt[i] * (cnt[i] - 1) / 2;
  }

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


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

int main(){
	int n;
	std::cin >> n;

	std::vector<int> figure;
	figure.resize(n);

	int buf;
	for(int i = 0; i < n; ++i){
		std::cin >> buf;
		figure[i] = buf;
	}

	std::vector<unsigned long long int> ans;
	ans.resize(21);

	ans[figure[0]] = 1;

	for(int i = 1; i < (n - 1); ++i){
		std::vector<unsigned long long int> buf_ans;
		buf_ans.resize(21);

		for(int j = 0; j < 21; ++j){
			if(ans[j] != 0){
				// minus
				if((j - figure[i]) >= 0){
					buf_ans[j - figure[i]] += ans[j];
				}
				// plus
				if((j + figure[i]) <= 20){
					buf_ans[j + figure[i]] += ans[j];
				}
			}
		}
		// copy
		ans.assign(buf_ans.begin(), buf_ans.end());
	}
	
	std::cout << ans[figure[n - 1]] << std::endl;

	return 0;
}

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

using namespace std;

int main(){

	ios_base::sync_with_stdio(false);  cin.tie(NULL);

				

int a,b,c,d;

				

cin>>a>>b>>c>>d;

while(1){

 c-=b;

if(c<=0){

puts("Yes");

	return 0;

}

	a-=d;

if(a<=0){

 puts("No");

 return 0;

}

}

return 0;

}

Measured memory_bytes: 3516