akhauriyash/Code-Regression huggingface dataset:
import sys
n = int(input())
c = list(map(int, input().split()))
c = [x-1 for x in c]
# print(c)
adj = [[] for i in range(n)]
for i in range(n-1):
    a, b = tuple(map(int, input().split()))
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)


size = [1 for i in range(n)]
stack = [[] for color in range(n)]
in_time = [-1 for i in range(n)]
out_time = [-1 for i in range(n)]
timer = 0
total = n*(n+1)//2
ans = [total for color in range(n)]
# print(ans)


def dfs(parent, root):
    global timer
    in_time[root] = timer
    timer += 1

    for child in adj[root]:
        if parent == child:
            continue
        dfs(root, child)
        size[root] += size[child]

        cnt = size[child]
        while stack[c[root]]:
            x = stack[c[root]][-1]
            if in_time[x] > in_time[root] and out_time[x] != -1:
                cnt -= size[x]
                stack[c[root]].pop()
            else:
                break
        ans[c[root]] -= cnt*(cnt+1)//2

    out_time[root] = timer
    timer += 1

    stack[c[root]].append(root)


sys.setrecursionlimit(10**6)

dfs(0, 0)
# print(size)
for color in range(n):
    cnt = n
    while len(stack[color]) > 0:
        x = stack[color][-1]
        cnt -= size[x]
        stack[color].pop()
    # print("node:", -1, "color:", color, "cnt:", cnt)
    ans[color] -= cnt*(cnt+1)//2
    print(ans[color])


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

using namespace std;
int main(){
    int X;
    cin>>X;
      for(int j=X;j<(2*X);j++){
             int count =0;
          for(int i=2;i<=sqrt(j);i++){
              if(j%i==0)count++;}
          if(count==0){cout<<j;break;}}
          return 0;}
        
    

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using static System.Math;
using System.Text.RegularExpressions;

namespace CsharpSpiral {
    partial class Program {
        static void Main(string[] args) {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }
        public void Solve(ConsoleInput cin) {
            var L = (double)cin.ReadInt;
            Console.WriteLine(Pow(L / 3, 3));
        }
    }

    static class ExtendClass {
        public static string Join<T>(this T[] X, string separator = " ") => string.Join(separator, X);
        public static S[] Clone<S>(this S[] src) where S : struct {
            var res = new S[src.Length];
            Array.Copy(src, res, src.Length);
            return res;
        }
    }

    class ConsoleInput {
        private readonly TextReader _stream;
        private readonly char _separator = ' ';
        private readonly Queue<string> inputStream;
        public ConsoleInput(TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read {
            get {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) {
            var ret = new string[N];
            for(long i = 0; i < N; ++i)
                ret[i] = Read;
            return ret;
        }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }
}


Measured memory_bytes: 13268
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (300006)
ll n,r,dam;
pi A[MAXN]; // (coords, health)
struct node {
	int s,e,m;
	ll v,add;
	node *l,*r;
	node(int S,int E){
		s=S,e=E,m=(s+e)>>1;
		v=0;add=0;
		if(s^e){
			l=new node(s,m);
			r=new node(m+1,e);
			v=max(l->v,r->v);
		} v=A[s].s;
	}
	void update(int x,int y,ll nval) {
		if(s==x&&e==y) {
			add+=nval;
			return;
		}
		if(x>m) r->update(x,y,nval);
		else if(y<=m) l->update(x,y,nval);
		else l->update(x,m,nval),r->update(m+1,y,nval);
		v=max(l->value(),r->value());
	}
	ll value() {
		v+=add;
		if(s^e){
			l->add+=add;
			r->add+=add;
		}
		add=0;
		return v;
	}
	ll rmq(int x) {
		value();
		if(s==e){
			return v;
		}
		if(x>m) return r->rmq(x); else return l->rmq(x);
	}
} *seg;
int main()
{
	FAST
	cin>>n>>r>>dam;
	FOR(i,0,n-1) cin>>A[i].f>>A[i].s;
	sort(A,A+n);
	seg=new node(0, n-1);
	ll co = 0, ans=0;
	while(co < n) {
		if(seg->rmq(co) > 0) {
			ll num=ceill(seg->rmq(co)/ld(dam));
			ll until = A[co].f + r*2;
			until = upper_bound(A+co, A+n, pi(until,LLINF)) - A - 1;
			assert(co<=until), seg->update(co, until, -dam*num), ans+=num;
		} else ++ co;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 29312
import sys, re
from math import ceil, floor, sqrt, pi#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_rpw_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    a, b = i_map()

    print(max(a+b, a-b, a*b))
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
def solve():
    N = int(input())
    A = list(map(int,input().split()))

    ans = 0
    for i in range(N):
        if (i+1) % 2 != 0 and A[i] % 2 != 0:
            ans += 1
    
    print(ans)
if __name__ == '__main__':
    solve()

Measured memory_bytes: 61676
// created by anaksoleh
// 21 Feb 2020

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

#define MAXN 100005

int n;
vector<int> v(MAXN);
vector<int> dp(MAXN,0);
bool computed[MAXN];

int solve(int idx){
    if(idx == 0)return 0;
    if(idx == 1)return abs(v[1] - v[0]);
    if(computed[idx])return dp[idx];
    dp[idx] = min(solve(idx-1) + abs(v[idx] - v[idx-1]),solve(idx-2) + abs(v[idx] - v[idx-2]));
    computed[idx] = true;
    return dp[idx];
}

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

    cin >> n;
    for(int i = 0 ; i < n ; i++)
        cin >> v[i];
    cout << solve(n-1) << '\n'; 
    return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<algorithm>
using namespace std;
using namespace std;
const int maxn = 100005;
struct node{
	int h,num;
};
int minnn=10000000;
int a[10005];
int main(){
	int n,m,t;
	cin>>n;
	cin>>t>>m;
	for(int i=0;i<n;i++)
		{
			cin>>a[i];
		}
	int temp;
	int aim=(t-m)*1000/6;
	for(int i=0;i<n;i++)
		if(abs(a[i]-aim)<minnn){
			temp=i;
			minnn=abs(a[i]-aim);
		}
	cout<<temp+1<<endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC target ("avx,avx2,tune=native")
//#pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"

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

using namespace __gnu_pbds; 
using namespace __gnu_cxx;
using namespace std;
using ll = long long;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define precision(n) fixed<<setprecision(n)

#ifdef LOCAL
    #include "debug.h"
#else
    #define debug(...) 42
#endif

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("output.txt","w",stderr);
    #endif
}
template<typename T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;
template<typename T> using MinPriorityQueue = priority_queue <T, vector <T>, greater <T> >;
template<typename T> void done(T ans) {cout << ans << "\n"; exit(0);}

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937_64 mt(seed);

clock_t time_p=clock();
void printTime(){
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}


const int N = 2e5 + 5;

int main() {
    io();
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        for(int j = i + 1; j <= n; j++) {
            for(int k = 0; k < 12; k++) {
                if(((1 << k) & i) != ((1 << k) & j)) {
                    cout << (k + 1) << " ";
                    break;
                }
            }
        }
        cout << "\n";
    }
}




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

int main()
{ ll k,n,a,ans;
 cin>>n>>k;
  for(int i=0; ;i++)
  {   a=n%k; 
      n=a-k; 
      if(a==0){cout<<0; break;}
      if(n<0){if(((-1)*n)>a){cout<<a;}else{cout<<(-1)*n;} break;}
  }  return 0;
}  

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

int main(){
    int x,y;cin>>x>>y;
    bool ok=false;
    for(int i=0;i<=x;++i){
        if(2*i+4*(x-i)==y)ok=true;
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
using namespace std;
int counter=0;
void selectionsort(int a[],int n)
{
	for(int i=0;i<n-1;i++)
	{
	int minnj=i;
	for(int j=i+1;j<n;j++)
	if(a[j]<a[minnj])
	{
		minnj=j;
	}
	if(minnj!=i)
	{
	swap(a[i],a[minnj]);counter++;
    }
    }
	return ;
}
int main()
{
	int n;cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	selectionsort(a,n);
	for(int i=0;i<n;i++)
	if(i!=n-1)
	cout<<a[i]<<" ";
	else
	cout<<a[i]<<endl;
	cout<<counter<<endl;
	return 0;
}


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

int main() {
  int x, count;
  cin >> x;
  if (x < 2) {
    cout << 1;
  }else if (x < 4) {
    cout << 2;
  }else if (x < 8) {
    cout << 4;
  }else if (x < 16) {
    cout << 8;
  }else if (x < 32) {
    cout << 16;
  }else if (x < 64) {
      cout << 32;
    }else {
      cout << 64;
    }
}

Measured memory_bytes: 3596
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll X, Y;
    cin >> X >> Y;

    ll count = 0;
    while(X <= Y){
        X *= 2;
        count++;
    }

    p(count);
    
    return 0;
}

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

using i64 = int64_t;

constexpr i64 MOD = 1e9 + 7;

i64 dp[202][100005]={0};

int main(){
    int n;
    i64 x;
    cin >> n >> x;
    vector<i64> v;
    for(int i=0;i<n;++i){
        i64 s;
        cin >> s;
        v.push_back(s);
    }
    sort(v.rbegin(), v.rend());

    for(i64 i=0;i<=x;++i){
        dp[n][i] = i % v[n-1];
    }
    for(int i=n-1;i>0;--i){
        for(i64 j=0;j<=x;++j){
            dp[i][j] = ((n-i)*dp[i+1][j]) % MOD;
            dp[i][j] = (dp[i][j] + dp[i+1][j%v[i-1]]) % MOD;
        }
    }

    cout << dp[1][x] << endl;

    return 0;
}


Measured memory_bytes: 157184
#include<stdio.h>
#define MAX 500001
int heap[MAX];
int main() {
	int i, H;
	scanf("%d", &H);
	for (i = 1; i <= H; i++) {
		scanf("%d", &heap[i]);
	}
	buildMaxHeap(heap, H);
	for (i = 1; i <= H; i++) {
		printf(" %d", heap[i]);
	}
	printf("\n");
	return 0;
}

maxHeapify(int*A, int i,int H) {
	int l, r,largest,dum;
	l = 2 * i;
	r = 2 * i + 1;

	if (l <= H&&A[l]>A[i])largest = l;
	else largest = i;
	if (r <= H&&A[r] > A[largest])largest = r;

	if (largest != i) {
		dum = A[i];
		A[i] = A[largest];
		A[largest] = dum;
		maxHeapify(A, largest, H);
	}
}

buildMaxHeap(int *A, int H) {
	int i;
	for (i = H / 2; i > 0; i--) {
		maxHeapify(A, i, H);
	}
}


Measured memory_bytes: 3808
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 8;
const ll MOD = 1e9 + 7;
const ll LLINF = 1e18;
#define Pint pair<int, int>
#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rnr(i, a, b) for(int i = int(a); i >= int(b); i--)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

ll roundUp(ll a, ll b) {
    return (a + (b - a % b) % b) / b;
}

int main() {
    ll x, k, d; cin >> x >> k >> d;
    if(x < 0) x *= -1;
    if(roundUp(x, d) <= k) {
        k -= x / d;
        x -= ll(x / d) * d;
        if(k % 2 == 0) {
            cout << abs(x) <<  endl;
        } else {
            cout << abs(x - d) << endl;
        }
        //いったりきたり
    } else {
        cout << x - k * d << endl;
    }
}


Measured memory_bytes: 3612
#include<stdio.h>
int main(){
	long long n;
	long long result = 1;
	
	scanf("%lld", &n);
	long long input[n];
	for(int i = 0 ; i < n ; i++){
		scanf("%lld", &input[i]);
	}
	for(int i = 0 ; i < n ; i++){
		if(input[i] == 0){
			printf("0\n");
			return 0;
		}
	}
	for(int i = 0 ; i < n ; i++){
		if(input[i] <= 1000000000000000000/result){
			result *= input[i];
		}else{
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n", result);
	return 0;
}

Measured memory_bytes: 2504
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque,BinaryHeap};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        B: [usize; N-1],
    }
    let mut A = vec![0; N];
    A[0] = B[0];
    for i in 0..N-1{
        A[i+1] = B[i];
        if A[i] > B[i]{
            A[i] = B[i];
        }
    }
    println!("{}", A.into_iter().sum::<usize>());
}


Measured memory_bytes: 4352
while True:
    inp,oup=map(int,input().split())
    if not inp: 
        break
    dic={}
    for i in range(inp):
        era,num,wes=input().split()
        dic[era] =[int(wes)-int(num)+1, int(wes)]
    for j in range(oup):
        p=int(input())
        for i in dic:
            if dic[i][0]<=p<=dic[i][1]:
                print(i+' '+str(p-dic[i][0]+1))
                break
        else:
             print('Unknown')


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

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

  int a, b, c; cin >> a >> b >> c;
  if(a == b) cout << c << endl;
  else if(b == c) cout << a << endl;
  else cout << b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);

typedef long long int ll;

int main() {
	optimizar_io
	double d, t, s;

	cin >> d >> t >> s;
	double time = d / s;
	if (time <= t)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

Measured memory_bytes: 3716
#include<stdio.h>
#include<malloc.h>
int main(void)
{
	int f=0, t=0, ct=0, n, *a;
	scanf("%d", &n);
	a = (int*)malloc(n * sizeof(int));
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		if (a[i] % 4==0) f++;
		else if (a[i] % 2 == 0) t++;
		else ct++;
	}
	if (ct - f == 1 && t == 0)
	{
		printf("Yes\n");
		return 0;
	}
	if (ct > f) printf("No\n");
	else
		printf("Yes\n");
	return 0;
}

Measured memory_bytes: 640
S = int(input())
i = 0
ans = 0
mod = 10 ** 9 + 7
    
def comb(n, k):
  de = 1
  nu = 1
  for i in range(k):
    de *= (n - i) % mod
    nu *= (i + 1) % mod
  nu = pow(nu, -1, mod)
  return de * nu
  
while 1:
  S -= 3
  if S <= 0:
    if S == 0:
      ans += 1
    print(ans)
    exit()
  ans += comb(S+i, i)
  ans = ans % mod
  i += 1

Measured memory_bytes: 9200
//Feet don't fail me now
//Take me to the finish line
//Oh, my heart, it breaks every step that I take
//But I'm hoping at the gates, they'll tell me
//that IOI gold is mine
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer {cout << "NO"; exit(0);}
#define vectors vector<vector<llong> >
#define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k)

const long long MXN = 2e5 + 10;
const long long MNN = 1e4 + 520;
const long long MOD = 10007;
const long long INF = 1e18;
const long long OO = 1e9;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int h, w, n, dp[MXN][4];
int curx, cury;
string s, t;

bool check(int pos){
    if(dp[pos][0] <= 0){
        return true;
    }
    if(dp[pos][1] > w){
        return true;
    }
    if(dp[pos][2] <= 0){
        return true;
    }
    if(dp[pos][3] > h){
        return true;
    }
    return false;
}

int main(){
    ios;
    cin >> h >> w >> n;
    cin >> curx >> cury;
    cin >> s >> t;
    s = '#' + s;
    t = '#' + t;
    dp[0][0] = dp[0][1] = cury;
    dp[0][2] = dp[0][3] = curx;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < 4; j++) dp[i][j] = dp[i - 1][j];
        
        if(s[i] == 'L') dp[i][0] = dp[i - 1][0] - 1;
        if(s[i] == 'R') dp[i][1] = dp[i - 1][1] + 1;
        if(s[i] == 'U') dp[i][2] = dp[i - 1][2] - 1;
        if(s[i] == 'D') dp[i][3] = dp[i - 1][3] + 1;
        
        if(check(i)) return cout << "NO", 0;
        
        if(t[i] == 'L') dp[i][1] = max(dp[i][1] - 1, 1);
        if(t[i] == 'R') dp[i][0] = min(dp[i][0] + 1, w);
        if(t[i] == 'U') dp[i][3] = max(dp[i][3] - 1, 1);
        if(t[i] == 'D') dp[i][2] = min(dp[i][2] + 1, h);
    }
    cout << "YES";
}


Measured memory_bytes: 3728
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 8;
int main()
{
  int n,m,a,b,i,res=0;
  int d[N_MAX][N_MAX],rr[N_MAX];
  bool f;
  cin >> n >> m;
  for(i=0;i<n;i++)
    fill(d[i],d[i]+n,0);
  for(i=0;i<m;i++){
    cin >> a >> b;
    d[a-1][b-1]=1;
    d[b-1][a-1]=1;
  }
  for(i=0;i<n;i++)
    rr[i]=i;
  do {
    f=0;
    for(i=1;i<n;i++)
      if(d[rr[i-1]][rr[i]]==0){
        f=1;
        break;
      }
    if(f==0)
      res++;
  } while(next_permutation(rr+1,rr+n));
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3636
n, q = map(int, input().split())
edge = [[] for i in range(n)]
for i in range(n-1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    edge[u].append(v)
cost = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    cost[p] += x
for idx, e in enumerate(cost):
    if e == 0:
        continue
    for f in edge[idx]:
        cost[f] += e
print(*cost)

Measured memory_bytes: 47820
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x&&x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS*max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x*x + y*y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;

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

	if (a + b == 15)
	{
		cout << "+" << endl;
	}
	else if (a * b == 15)
	{
		cout << "*" << endl;
	}
	else 
	{
		cout << "x" << endl;
	}

	return 0;
}


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

int main()
{
    int N; cin >> N;
    vector<int> A(N+1);
    for (int i = 1; i <= N; i++) cin >> A[i];
    int lit = 1;
    int count = 0;
    while (count++ < N) {
        lit = A[lit];
        if (lit == 2) {
            cout << count << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n];
    set<ll> s;
    multiset<pair<ll,int> > ms;
    for(int i=0;i<n;i++){
        cin>>a[i];
        ms.insert(make_pair(a[i],i));
        s.insert(a[i]);
    }
    auto itr1=ms.begin();
    auto itr2=ms.end();
    itr2--;
    vector<pair<int,int> > ans;
    if((*itr1).first<0&&(*itr2).first>0){
        s.clear();
        if(abs((*itr1).first)>abs((*itr2).first)){
            for(int i=0;i<n;i++){
                a[i]+=(*itr1).first;
                ans.pb(make_pair((*itr1).second+1,i+1));
                s.insert(a[i]);
            }
        }
        else{
            for(int i=0;i<n;i++){
                a[i]+=(*itr2).first;
                ans.pb(make_pair((*itr2).second+1,i+1));
                s.insert(a[i]);
            }
        }
    }
    if(*(s.begin())>=0){
        for(int i=1;i<n;i++){
            ans.pb(make_pair(i,i+1));
        }
    }else{
        for(int i=n;i>1;i--){
            ans.pb(make_pair(i,i-1));
        }
    }
    int maki=ans.size();
    cout << maki<<endl;
    for(int i=0;i<maki;i++){
        cout << ans[i].first<<" "<<ans[i].second<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using ll=long long; 
using ld=long double; 
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int mod1=1e9+7; 
void __print(int x) {cerr << x;} 
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;} 
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x){cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;} 
void __print(double x) {cerr << x;}
void __print(ld x){cerr << x;} 
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x){cerr<<'\"'<<x<<'\"';}
void __print(const string &x) {cerr<<'\"'<<x<<'\"';}
void __print(bool x){cerr<<(x?"true":"false");}
template<typename T, typename V>
void __print(const pair<T, V> &x){cerr<<'{'; __print(x.first);cerr<<','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) 
{ return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) 
{ return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } 
void debug_out() { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) 
{
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifndef ONLINE_JUDGE 
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#ifndef ONLINE_JUDGE 
#define debugt(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debugt(...) 42
#endif
constexpr ll inf=2223372036854775807;
constexpr int mod2=(998244353);
constexpr int MAX=(1e5+3);
template<typename L>int factorise(L a){ int c=0; int limit=sqrt(a); rep(i,1,limit) { if(a%i==0) { c++; if(i!=a/i) c++; } } return c;   }
int main()
{
    #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  int n; cin>>n; int ans=0; 
  rep(c,1,n-1)
  {
   ans+=(n-1)/c; 
  }
  cout<<ans<<"\n"; 
} 

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define uns unsigned
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define pq priority_queue
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
struct edge
{
    int u, v, c;
    edge(int u, int v, int c) : u(u), v(v), c(c) {}
};
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m, p;
    cin >> n >> m >> p;
    vector<edge> e;
    for (int i = 0; i < m; i++)
    {
        int u, v, c;
        cin >> u >> v >> c;
        u--, v--;
        e.push_back(edge(u, v, p - c));
    }
    vi d(n, LLONG_MAX);
    d[0] = 0;
    for (int it = 0; it < n - 1; it++)
        for (edge cur : e)
            if (d[cur.u] < LLONG_MAX)
                d[cur.v] = min(d[cur.v], d[cur.u] + cur.c);
    mask bad(n, false);
    for (int it = 0; it < n; it++)
        for (edge cur : e)
            if (d[cur.u] < LLONG_MAX)
                if (bad[cur.u] || d[cur.v] > d[cur.u] + cur.c)
                    bad[cur.v] = true;
    int res = d[n - 1];
    if (bad[n - 1])
        res = -1;
    else
        res = max(-res, 0LL);
    cout << res << endl;
    GAME_OVER;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << ", ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll n,k,ans=0;
	cin >> n >> k;
	vll x(n);
	rep(i,n) cin >> x[i];
	rep(i,n){
		ans+=min(2*x[i],2*(k-x[i]));
	}
	cout << ans << endl;
    return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, t;
	cin >> n >> t;
	
	vector<pll> items;
	FOR(i,0,n) {
		ll a, b;
		cin >> a >> b;
		items.eb(a,b);
	}
	sort(all(items));


	vl dp(t,-oo);
	dp[0] = 0;
	ll res = 0;
	FOR(i,0,n) {
		ll a, b;
		tie(a,b) = items[i];
		res = max(res, *max_element(all(dp)) + b);
		FORD(x,a,t) dp[x] = max(dp[x], dp[x-a] + b);
	}
	cout << res << endl;
}



Measured memory_bytes: 384
fun main() {
    var n=readLine()!!.toInt()
    var s=readLine()!!
    var ans=0
    for (i in 0 until 1000){
        var tmp=i.toString().padStart(3, '0')
        var ind=0
        for (j in s){
            if (tmp[ind]==j){
                ind++
                if (ind==3){
                    break
                }
            }
        }
        if (ind==3){
            ans++
        }
    }
    println(ans)

}

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

int main(void){
  int s,w; cin >> s >> w;
  if(s <= w) cout << "unsafe" << endl;
  else cout << "safe" << endl;
  return 0;
}


Measured memory_bytes: 3592
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]

now_t=0
now_x=0
now_y=0

for nt,nx,ny in l:
  d_dist=abs(nx-now_x)+abs(ny-now_y)
  d_t=nt-now_t
  if d_dist>d_t or (d_t-d_dist)%2==1:
    print('No')
    exit()
  now_t=nt
  now_x=nx
  now_y=ny

print('Yes')

Measured memory_bytes: 27380
#include <algorithm>
#include <bits/stdc++.h>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); //cinの高速化
  
  string S;
  IN(S);
  string ans = "Yes";
  
  for(int i=0; i<S.length();i=i+2){
    if(S[i] != 'R' && S[i] != 'U' && S[i] != 'D'){
      ans="No";
   	  goto fin;
    }
    if(S.length()%2 !=0 && i == S.length()-1) goto fin;
    if(S[i+1] != 'L' && S[i+1] != 'U' && S[i+1] != 'D'){
      ans="No";
      goto fin;
    }
  }
  fin:
  OUT(ans);
}

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


int main(){
	int n;
	cin>>n;
	
	double k=n;
	
	double x;
	if (n%2==0) x=n/2;
	else x=n/2+1;
	
	printf("%.10f\n", x/k);
	
	
}



Measured memory_bytes: 256
import numpy as np

div = 10**9 + 7

def Mod_Pow(a,n,mod):
    res = 1
    while (n > 0):
        if (n & 1):
            res = (res * a )% mod
        a = (a * a)% mod
        n >>= 1
    
    return res

def CountFrequency(my_list): 
  
    # Creating an empty dictionary  
    freq = {} 
    count_0 = 0
    for item in my_list: 
        if (item in freq): 
            freq[item] += 1
        else:             
            if item ==0:
                count_0+=1
            else:
                freq[item] = 1
    if N%2==0:
        return freq
    else:
        return freq, count_0

N = int(input())

A = list([int(i) for i in input().split()])

if N%2 == 0:
    if all([ i ==2 for i in CountFrequency(A).values()]):
        ans = Mod_Pow(2,int(N/2),div)
    else:
        ans =0
    
            
else:
    count_0 = CountFrequency(A)[1]
    
    count_1 = list(CountFrequency(A)[0].values())
    if all([ i ==2 for i in count_1]) & (count_0 ==1):
        ans = Mod_Pow(2,int(N/2),div)
    else:
        ans =0
    
    
            
print(ans)      

Measured memory_bytes: 23436
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


int w, h;
const int INF = 1 << 30;

bool range(int xx, int yy)
{
	return (0 <= xx && xx < w+2 && 0 <= yy && yy < h+2);
}

int main()
{
	cin >> w >> h;
	
	vector<vint> field(h+2, vint(w+2));
	
	rep(y, h) rep(x, w)     
	{
		int in;
		cin >> in;
		field[y+1][x+1] = in;
	}
	
	int res = 0;
	
	queue<pint> que;
	for(que.push(mp(0, 0)); !que.empty(); que.pop())
	{
		pint p = que.front();
		
		int b = p.first % 2 ? 1 : -1;
		
		int dx[] = {1, -1, 0, 0, b, b};
		int dy[] = {0, 0, 1, -1, 1, -1};
		
		rep(i, 6)
		{
			int nx = p.second + dx[i], ny = p.first + dy[i];
			
			if(!range(nx, ny))              continue;
			if(field[ny][nx] == 1)  res++;
			else if(field[ny][nx] != INF)
			{
				field[ny][nx] = INF;
				que.push(mp(ny, nx));
			}
		}
	}
	
	cout << res << endl;
}

Measured memory_bytes: 0
#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 FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;


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

    ll h, w, a, b;
    cin >> h >> w >> a >> b;

    REP(i, h) {
        REP(j, w) {
            if ((i < b && j < a) || (i >= b && j >= a)) cout << 0;
            else cout << 1;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
N = int(input())
A = [int(i) for i in input().split()]

def BubbleSort(N, A):
    flag = 1
    cnt = 0
    while flag > 0:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                cnt += 1
    return A, cnt

res = BubbleSort(N, A)
print(" ".join(map(str, res[0])))
print(res[1])

Measured memory_bytes: 7744
import java.util.*;
import java.math.BigInteger;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
      	BigInteger a[] = new BigInteger[N];
        for (int i=0; i<N; i++) {
            a[i] = BigInteger.valueOf(sc.nextInt());
        }
      
      	Arrays.sort(a, Collections.reverseOrder());
      	BigInteger ans = BigInteger.ZERO;
      
      	for (int i=1; i<N-1; i++) {
          	if(i<=N/2){
           	 ans = ans.add(a[i-1]);
             //System.out.println(a[i-1]);
            }
          	else{
              ans = ans.add(a[N-i-1]);
              //System.out.println(a[N-i-1]);
            }
        }
      	if(N % 2 == 0){
          ans = ans.add(a[N/2-1]);
          //System.out.println(a[N/2-1]);
        }
      	else{
      		ans = ans.add(a[N/2]);
          	//System.out.println(a[N/2]);
        }
      	
      
       	System.out.println(ans);
    }
}

Measured memory_bytes: 74288
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n: String = read();
    let k: usize = read();
    let mut dp = vec![vec![vec![0i64; 4]; 2]; n.len() + 1];
    dp[0][0][0] = 1; // pos, less, no_nontimes

    for (i, c) in n.chars().enumerate() {
        for j in 0..2 {
            for m in 0..4 {
                let lim = if j == 1 { 9 } else { c.to_digit(10).unwrap() };
                for l in 0..lim + 1 {
                    let idx1 = if j == 1 || l < lim { 1 } else { 0 };
                    let idx2;

                    if l != 0 {
                        idx2 = m + 1;
                    } else {
                        idx2 = m;
                    }
                    if idx2 > 3 {
                        continue;
                    }

                    dp[i + 1][idx1][idx2] += dp[i][j][m];
                }
            }
        }
    }
    // debug!(dp[0]);
    //  debug!(dp[n.len()]);

    let mut ans = 0;
    for j in 0..2 {
        ans += dp[n.len()][j][k];
    }
    println!("{:?}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int md = 1e9+7;
 
 
 
 
 
long long cn, dp[2005];
 
ll  rec(ll s)
{
   
        if(dp[s]!=-1) return dp[s];
 
         if(s==0)      return 1;
        //if(s<0)       return 0 ;
  
  
 
  
 
  ll ans=0;
 
  for(int i=3;i<=s;i++)
  
    ans = (ans%md +rec(s-i)%md)%md;
  
 
  dp[s] =ans;
 
  return dp[s];
 
 
}
 
 
 
int main()
{
 
  long long s;
  cin>>s;
 
  memset(dp,-1,sizeof(dp));  //dp array initialize all with minus -1
  
  //dp gives pair with sum =s and all element greater than or equal to 3
 
  cout<<rec(s)<<endl;
 
 
    
}

Measured memory_bytes: 3620
#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <iomanip>
#include <cstdlib>
#include <climits>
using namespace std;

//関数getinputdata宣言
vector<vector<string>> getinputdata();
vector<vector<int>> getinputdata2();
vector<vector<double>> getinputdata3();

void abc115_c(vector<vector<int>> v) {

    int n = v[0][0];
    int k = v[0][1];

    vector<int>vec;
    for (int i = 1; i < 1 + n; i++) {
        vec.push_back(v[i][0]);
    }

    sort(vec.begin(), vec.end());


    int mindata=INT_MAX;
    for (int i = 0; i <= vec.size() - k ; i++) {

//        cout << vec[i] << "" << vec[i + k - 1] << endl;
        mindata=min(mindata,vec[i + k - 1]-vec[i]);
    }
    
    cout << mindata <<endl;


}

int main() {

    //    vector<vector < string>> vec_arr_result;
    vector<vector<int>> vec_arr_result;
    vec_arr_result = getinputdata2();

    abc115_c(vec_arr_result);

    return 0;
}

//関数getinputdata実装

vector<vector<double>> getinputdata3() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<double>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<double> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atof(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;
}

//関数getinputdata実装

vector<vector<int>> getinputdata2() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<int>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<int> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atoi(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;


}

//関数getinputdata実装

vector<vector < string >> getinputdata() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector < string>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<string> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(ret);
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;

}


Measured memory_bytes: 13680
a, b, t = gets.chomp.split.map(&:to_i)

ans = 0

count = a  # 今回、a の段階でカウントは 1 が置かれる
# count = 0 だとカウントに 5 が置かれるまでwhileされてしまう
while count < (t + 0.5) do
  ans += b
  count += a
end

puts ans

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

int main() {
  int N,a=0,i,q,w;
  cin >> w;
  N=w;
  for(i=100000000;i>0;i=i/10){
    q=w/i;
    w=w%i;
    a=a+q;
    q=w; 
  }
  if(N%a == 0){
    cout << "Yes"  << endl;
  }else{
    cout << "No" << endl;
  }
}     

Measured memory_bytes: 256