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

#define double long double
#define int long long
#define ALL(x) x.begin(),x.end()
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb(x) push_back(x)
#define eb emplace_back
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend()) 
#define mp(x, y) make_pair(x, y)
#define INF 1000000000
#define MOD 998244353 
#define F(i, a, n) for(i=a;i<n;i++)
#define SI(x) cin>>x
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z
#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<< "\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

const int N = 82;
int a[N];
int n;


int32_t main(void)
{
    FASTER;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int i, j;
    SI(n);
    F(i, 0, n)
    	SI(a[i]);
    int money = 1000;
    int stocks = 0;
    F(i, 0, n - 1)
    {
    	while(i + 1 < n && a[i] > a[i + 1])
    		i++;
    	stocks += (money / a[i]);
    	money = (money % a[i]);
    	while(i + 1 < n && a[i] < a[i + 1])
    		i++;
    	money += stocks * a[i];
    	stocks = 0;
    }
	money += stocks * a[n - 1]; 
    SO(money);

    
    #ifdef LOCAL
    	cout<<endl<<endl<<"Time: "<<(float)clock()/CLOCKS_PER_SEC<<" seconds"<<endl;
    #endif
    return 0;
}

Measured memory_bytes: 3688
n, m = map(int, input().split())
vertex = [[0] * n for _ in range(n)]
edge = []
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge.append([a, b])
    vertex[a][b] = 1
    vertex[b][a] = 1

check = [0] * n
check[0] = 1


def dfs(x):
    ans = 0
    if min(check) == 1:  # 全ての探索が完了した時
        return 1  # 1を返す。
    for i in range(n):  # n個の頂点から一つずつ取り出して
        if vertex[x][i] == 1 and check[i] == 0:  # 頂点xから頂点iに移動でき、かつ未探索の時
            check[i] = 1  # 探索済みにする
            ans += dfs(i)  # pathの本数を加える
            check[i] = 0  # 未探索に戻す
    return ans  # pathの本数を出力する


print(dfs(0))


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

ll ans = 0;

int main(){
  string S; cin >> S;
  int N = sz(S);
  int K; cin >> K;
  /*
  dp[i][j][k]
  i: 頭からi桁 j: 未満フラグ k: 0以外の個数
  dp[i][0][0]:頭からi桁 n未満確定 全部0
  dp[i][0][1]:頭からi桁 n未満確定 0以外が1個
  dp[i][1][0]:頭からi桁 nは一致 全部0
  dp[i][1][1]:頭からi桁 nは一致 0以外が1個
  */
  vector<vector<vector<ll>>> dp(N+1,vector<vector<ll>>(2,vector<ll>(K+2,0)));
  dp[0][0][0] = 1;
  rep(i,N){
    rep(smaller,2){
      rep(k,K+1){
        for(int x=0; x<=(smaller?9:(int)(S[i]-'0')); x++){
          dp[i + 1][smaller || x < (int)(S[i]-'0')][k+(x!=0)] += dp[i][smaller][k];
        }
      }
    }
  }
  cout << dp[N][0][K] + dp[N][1][K] << endl;
  return 0;
}


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


int main(){
    int n,a;
    cin >> n >>a;

    if((n-n/500*500)<=a) cout <<"Yes" <<endl;
    else cout << "No" << endl;
   }

Measured memory_bytes: 256
void main()
{
    long k, a, b;
    rdVals(k, a, b);

    long diff = k - a + 1;
    long c = a + (b - a) * (diff / 2) + diff % 2;

    max(k+1, c).writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

struct SegT {
private:
	int sz; vector<int> node;
	const int init_c = mod;
public:
	SegT(int n) {
		sz = 1;
		while (sz < n)sz *= 2;
		node.resize(2 * sz - 1, init_c);
	}
	int f(int a, int b) {
		return min(a, b);
	}
	void update(int k, int a) {
		k += sz - 1;
		node[k] = f(node[k],a);
		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}
	int query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = sz;
		if (r <= a || b <= l)return init_c;
		else if (a <= l && r <= b)return node[k];
		else {
			int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return f(vl, vr);
		}
	}
};

void solve() {
	int n; cin >> n;
	vector<int> b(n);
	vector<int> rb(n+1,0);
	rep(i, n) {
		cin >> b[i];
		rb[i + 1] = rb[i];
		if (b[i] == 0)rb[i + 1]++;
	}
	int q; cin >> q;
	vector<vector<int>> loc(n);
	rep(i, q) {
		int l, r; cin >> l >> r; l--; r--;
		loc[l].push_back(r);
	}
	SegT st(n + 1);
	st.update(0, 0);
	int cur = 0;
	rep(i, n) {
		//cur = min(cur, st.query(i, i+1)+rb[i]);
		rep(j, loc[i].size()) {
			int r = loc[i][j];
			int z = st.query(i, r+1);
			int sum = z + rb[r + 1];
			sum = min(sum, cur + rb[r + 1] - rb[i]);
			st.update(r+1, sum-rb[r+1]);
		}
		if (b[i] == 1)cur++;
		cur = min(cur, st.query(i + 1, i + 2) + rb[i + 1]);
	}
	cout << cur << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	solve();
	//stop
	return 0;
}

Measured memory_bytes: 12544
#include<iostream>
using namespace std;
int main(){
    int N,H,W;
    cin>>N>>H>>W;
    int ans=0;
    int a[1000],b[1000];
    for(int i=0;i<N;i++){
        cin>>a[i]>>b[i];
        if(a[i]>=H && b[i]>=W)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys

S = input()

A = int(''.join(S[0:2]))
B = int(''.join(S[2:4]))

if S[0:2] == '00' or S[2:4] == '00':
    if 0 < A <= 12:
        print('MMYY')

    elif 0 < B <= 12:
        print('YYMM')
    else:
        print('NA')

else:
    if 12 < A and 12 < B:
        print('NA')

    if  0 <= B and B <= 12:
        if  0 <= A and A <= 12:
            print('AMBIGUOUS')
        else:
            print('YYMM')

    elif 0 <= A and A <= 12:
        print('MMYY')

Measured memory_bytes: 3064
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (R, G, B, N) = read!(usize, usize, usize, usize);

    let mut k = 0;
    for r in 0.. {
        if r * R > N {
            break;
        }
        for g in 0.. {
            if r * R + g * G > N {
                break;
            }

            let x = N - (r * R + g * G);
            if x % B == 0 {
                k += 1;
            }
        }
    }

    println!("{}", k)
}


Measured memory_bytes: 4352
use std::collections::VecDeque;
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)*}
    };
}

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
    h: usize,
    w: usize,
    s: [chars; h]
    }
    let mut m = vec![vec!['#'; w + 2]; h + 2];
    let mut d = vec![vec![-1; w + 2]; h + 2];
    let dx = [-1, 1, 0, 0];
    let dy = [0, 0, -1, 1];
    let mut ans = 0;
    for i in 0..h {
        for j in 0..w {
            m[i + 1][j + 1] = s[i][j];
            if s[i][j] == '.' {
                ans += 1;
            }
        }
    }
    let mut q = VecDeque::new();
    q.push_back((1, 1));
    d[1][1] = 1;
    while !q.is_empty() {
        let v = q.pop_front().unwrap();
        for k in 0..4 {
            let nv = ((v.0 as i64 + dy[k]) as usize, (v.1 as i64 + dx[k]) as usize);
            if d[nv.0][nv.1] >= 0 || m[nv.0][nv.1] == '#' {continue}
            if d[nv.0][nv.1] == -1 {
                d[nv.0][nv.1] = d[v.0][v.1] + 1;
                q.push_back(nv);
            }
        }
    }
    if d[h][w] == -1 {println!("-1"); return}
    println!("{}", ans - d[h][w]);
}


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

int main() {
    vector<tuple<int, int, int>> t(5);

    for (int i = 0; i < 5; i++) {
        int x;
        cin >> x;
        t.at(i) = make_tuple(x, (((x + 9) / 10) * 10), ((10 - (x % 10)) % 10));
    }

    sort(t.begin(), t.end(), [](auto &a, auto &b){
        return get<2>(a) < get<2>(b);
    });

    //for (auto &x : t)
    //    cout << get<0>(x) << ',' << get<1>(x) << ',' << get<2>(x) << endl;

    int s = 0;
    for (int i = 0; i < 4; i++) {
        s += get<1>(t.at(i));
    }

    s += get<0>(t.at(4));

    cout << s << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main() {
    int n, k;
    int count = 0;
    cin >> n >> k;
    vector<int> d(k);
    vector<bool> peo(n, false);
    for (int i = 0; i < k; i++) {
        cin >> d.at(i);
        for (int j = 0; j < d.at(i); j++) {
            int a;
            cin >> a;
            peo.at(a - 1) = true;
        }
    }
    for (int i = 0; i < n; i++) {
        if (!peo.at(i)) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll t(n);
    rep(i, n){
        cin >> t[i];
        t[i] <<= 1;
    }
    t.insert(t.begin(), 0);
    repr(i, 1, n+1){
        t[i] += t[i-1];
    }
    vll v(n);
    rep(i, n){
        cin >> v[i];
        v[i] <<= 1;
    }
    v.insert(v.begin(), 0);
    v.insert(v.end(), 0);
    // 0.5s each
    ll T = t[n];
    vll speed(T, INF);
    rep(i, T){
        chmin(speed[i], i);
        chmin(speed[i], T-i);
        rep(j, n){
            if(t[j] <= i && i <= t[j+1]){
                chmin(speed[i], v[j+1]);
                break;
            }
        }
        rep(j, n+1){
            chmin(speed[i], abs(t[j]-i)+min(v[j], v[j+1]));
            //dump(i, speed[i], abs(t[j]-i), min(v[j], v[j+1]));
        }
    }
    speed.emplace_back(0);
    //dump(speed);
    //rep(i, T+1) dump(i, speed[i]);
    //dump(t);
    //dump(v);
    
    ld ans = 0;
    rep(i, T){
        ans += ld(speed[i]+speed[i+1])/2;
        //dump(ans);
    }
    cout << ans/4 << endl;
    
    return 0;
}

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

int main() {
    int A, B, C, X, Y;
    int sum = 0;

    cin >> A >> B >> C >> X >> Y;
    if (X < Y) {
        swap(X, Y);
        swap(A, B);
    }

    sum += min(A + B, 2 * C) * Y;
    sum += min(A, 2 * C) * (X - Y);

    cout << sum << endl;
}

Measured memory_bytes: 256
import math
 
A, B, H, M = map(int, input().split())
 
th_h = 360 // 12 * H + 360 / 12 / 60 * M
th_m = 360 // 60 * M
 
ans = A ** 2 + B ** 2 - 2*A*B*math.cos(math.radians(abs(th_h - th_m)))
print(math.sqrt(ans))

Measured memory_bytes: 9480
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//Atcoderくんとボール色塗り
		Scanner sc =new Scanner(System.in);
		int n=sc.nextInt();//ボールの数
		int k=sc.nextInt();//色の数
		System.out.println((int)(k * Math.pow((k-1),(n-1))));//K-1のｎ-1乗パターンがある。
	}
	//例）入力　10 8→　出力　9の7乗=322828856
}

Measured memory_bytes: 9804
//temprates
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

using ll = long long;
using namespace std;

#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define LFOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define FORR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define LFORR(i,a,b) for(ll i = (int)(a); i >= (ll)(b); i--)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define LREP(i,n) LFOR(i,0,(ll)(n)-1)
#define REPR(i,n) FORR(i,(int)(n)-1,0)
#define LREPR(i,n) LFORR(i,(ll)(n)-1,0)

#define SIZ(v) int(v.size())
const int INF = 1e8;
const ll LINF = 1e15;
const int MOD = 1e9+7;



ll gcd(ll a, ll b){
  if(b==0) return a; else return gcd(b,a%b);
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,lcd;
  ll qc=0,qd=0,qcd=0;
  cin >> a >> b >> c >> d;
  lcd = (c*d)/gcd(c,d);
  qc = b/c - a/c; if(!(a%c))qc++;
  qd = b/d - a/d; if(!(a%d))qd++;
  qcd = b/lcd - a/lcd; if(!(a%lcd))qcd++;
  cout << b-a+1 -qc-qd+qcd << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, l;
    cin >> n >> l;
    int s = 0;
    for(int i = 1; i <= n; i++) {
        s += l + i - 1;
    }
    int mi = INF, ans;
    for(int i = 1; i <= n; i++) {
        int s2 = 0;
        for(int j = 1; j <= n; j++) {
            if(i == j) {
                continue;
            }
            s2 += l + j - 1;
        }
        if(mi > abs(s2 - s)) {
            mi = abs(s2 - s);
            ans = s2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int dp[3001][3001];

string getLCS(string &s, string &t, int l ){
    string ans="";
    int i=0,j=0;
    while(l>0){
        if(s[i]==t[j]){ans.push_back(s[i]);
            i++; j++; l--; 
        }
        else{
            if(dp[i+1][j]>dp[i][j+1]) i++;
            else j++;
        }
    }
    return ans;
}

int lenLCS(string &s, string &t, int n, int m, int i, int j){
    if(i>=n || j>=m) return 0;
    if(dp[i][j]!=-1) return dp[i][j];
    if(s[i]==t[j]) return dp[i][j]=lenLCS(s,t,n,m,i+1,j+1)+1; 
    else
    return dp[i][j]=max(lenLCS(s,t,n,m,i+1,j), lenLCS(s,t,n,m,i,j+1));
}

int main(){
    string s,t,p="";
    cin>>s>>t;
    memset(dp,-1,sizeof(dp));
    int n=s.length();
    int m=t.length();
    int l=lenLCS(s,t,n,m,0,0);
    cout<<getLCS(s,t,l);
    
}


Measured memory_bytes: 39352
import fractions

a, b = map(int, input().split())

x = fractions.gcd(a,b)
ans = []

i = 2
y = int(x**0.5)
for j in range(10000000):
    if x%i == 0:
        x //= i
        ans.append(i)
        i = 2
        y = int(x**0.5)
    elif i == y:
        ans.append(x)
        break
    else:
        i += 1

print(len(set(ans))+1)

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

const int MOD =1e9+7;

int main(){

string s ; cin>>s; int count=0;  int a; int z;
for(int i=0;i<s.length();i++)
{
	if(s[i]=='A')
	{
		 a=i; break; 
	}	
}
for(int i=s.length()-1;i>=0;i--)
{
	if(s[i]=='Z')
	{
		 z=i; break; 
	}	
}
		
	cout<<z-a+1<<endl;

	return 0; 
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

inline int dist(const pi &p, const pi &q){
    return abs(p.fi-q.fi) + abs(p.se-q.se);
}

const int N = 7;
const ll INF = LLONG_MAX/3;

ll min_time[1<<N][N];
ll ti[1<<N];

const int W = 10001;
ll max_val[W]={};
ll val[1<<N];

const int T = 10001;
ll dp[T];

int main(){
    int n,m,w,t;
    cin >>n >>m >>w >>t;

    map<string,int> name2id;
    vector<int> v(m),p(m);
    rep(i,m){
        string s;
        cin >>s >>v[i] >>p[i];
        name2id[s] = i;
    }

    vector<int> L(n);
    vector<pi> pos(n);
    vector<vector<pi>> city(n);
    rep(i,n){
        cin >>L[i] >>pos[i].fi >>pos[i].se;
        city[i] = vector<pi>(L[i]);
        rep(j,L[i]){
            string s;
            int q;
            cin >>s >>q;

            int ID = name2id[s];
            // weight, value
            city[i][j] = {v[ID], p[ID]-q};
        }
    }

    // calc minimum time
    rep(i,1<<N){
        rep(j,N) min_time[i][j] = INF;
        ti[i] = INF;
    }

    rep(i,n) min_time[1<<i][i] = dist(pos[i],{0,0});
    for(int mask=1; mask<(1<<n); ++mask){
        rep(from,n)if(mask>>from&1){
            rep(to,n)if(!(mask>>to&1)){
                int nmask = mask|(1<<to);
                min_time[nmask][to] = min(min_time[nmask][to], min_time[mask][from]+dist(pos[from],pos[to]));
            }
        }

        rep(i,n){
            ti[mask] = min(ti[mask], min_time[mask][i]+dist(pos[i],{0,0}));
        }
    }
    ti[0] = 0;

    // calc maximum value
    rep(mask,1<<n){
        memset(max_val, 0, sizeof(max_val));

        vector<pi> item;
        rep(i,n)if(mask>>i&1){
            rep(j,L[i]) item.pb(city[i][j]);
        }
        int SZ = item.size();

        rep(i,w){
            rep(j,SZ)if(i+item[j].fi<=w){
                max_val[i+item[j].fi] = max(max_val[i+item[j].fi], max_val[i]+item[j].se);
            }
        }

        rep(i,w+1) val[mask] = max(val[mask], max_val[i]);
    }

    // calc dp
    rep(i,t){
        rep(mask,1<<n){
            int ni = i+ti[mask];
            if(ni<=t){
                dp[ni] = max(dp[ni], dp[i]+val[mask]);
            }
        }
    }

    ll ans = 0;
    rep(i,t+1) ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3320
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <numeric>
#include <sstream>

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1;i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define PI 3.14159265358979

using namespace std;

//================================================
vector<int>prime(1000000);
vector<bool>is_prime(1000001);

//Sieve of Eratosthenes
int func(int N) {
	int p = 0;

	REP(i, N + 1) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;

	REP2(i, 2, N + 1) {
		if (is_prime[i]) {
			prime[p++];
			for (int j = 2 * i; j <= N; j += i) is_prime[j] = false;
		}
	}
	return p;
}

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

	int N;
	while (cin >> N) {
		cout << func(N) << "\n";
	}
	return 0;
}

Measured memory_bytes: 6596
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def MI(): return map(int, input().split())


def LI_(): return [int(x) - 1 for x in input().split()]


def main():
    import sys
    sys.setrecursionlimit(5*(10**5))
    N, M = MI()
    edge = [[] for _ in range(N)]
    for _ in range(M):
        x, y = LI_()
        edge[x].append(y)

    def go_to_leaf(n):
        if dp[n] >= 0:
            return dp[n]
        ret = 0
        for y in edge[n]:
            ret = max(go_to_leaf(y) + 1, ret)
        dp[n] = ret
        return ret

    dp = [-1] * N
    ans = 0
    for i in range(N):
        ans = max(ans, go_to_leaf(i))
    print(ans)

    """start = 0
    while rev_edge[start]:
        start = rev_edge[start][0]
    stack = set([start])
    ans = 0
    for _ in range(N + 1):
        tmp = []
        print(stack)
        while stack:
            now = stack.pop()
            tmp.extend(edge[now])
        if not tmp:
            print(tmp)
            break
        stack = set(tmp)
        ans += 1
    print(ans)"""


if __name__ == '__main__':
    main()


Measured memory_bytes: 145612
S = gets.chomp
T = gets.chomp

if S.length < T.length
  puts 'UNRESTORABLE'
  exit
end

words = []
(S.length - T.length + 1).times do |i|
  f, s_word, e = S[0...i], S[i, T.length], S[i+T.length..S.length]
  T.length.times do |t|
    if s_word[t] == T[t]
    elsif s_word[t] == '?'
      s_word[t] = T[t]
    else
      break
    end
    if t == T.length - 1
      w = f + s_word + e
      w.gsub!(/\?/, 'a')
      words.push(w)
    end
  end
end
if words.empty?
  puts 'UNRESTORABLE'
else
  puts words.sort.first
end


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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define N 1024
#define M 2048

vi st;
int q[N];
vi adj[N], radj[N];
int cl[N];
int last[N];
int p[N][N];
int d[N][N];

void bfs(int s, int n)
{
    fill_n(d[s]+1, n, n+1);
    d[s][s] = 0;
    cl[s] = n+1;
    int k = 0;
    q[k++] = s;
    for (int i = 0; i < k; ++i) {
        int u = q[i];
        int dv = d[s][u]+1;
        for (int v : adj[u]) {
            if (d[s][v] > dv) {
                d[s][v] = dv;
                p[s][v] = u;
                q[k++] = v;
            }
            if (v == s && cl[s] > dv) {
                cl[s] = dv;
                last[s] = u;
            }
        }
    }
}

int main()
{
    canhazfast();

    int n, m;
    int s = 0, lmin;
    vi ans;

    cin >> n >> m;
    lmin = n+1;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        adj[a].pb(b);
        radj[b].pb(a);
    }
    for (int i = 1; i <= n; ++i) {
        bfs(i, n);
        if (lmin > cl[i]) {
            lmin = cl[i];
            s = i;
        }
    }
    retif(lmin > n) cout << "-1\n", 0;
    for (int i = last[s]; i; i = p[s][i]) ans.pb(i);
    reverse(all(ans));
    cout << ans.size() << '\n';
    for (int v : ans) cout << v << '\n';

    return 0;
}


Measured memory_bytes: 8576
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    ll k;
    cin>>n>>k;
    vector<ll> v(n);
    rep(i,k){
        cin>>d;
        rep(j,d){
            cin>>b;
            v[b-1]++;
        }
    }
    rep(i,n){
        if(v[i]==0) sum++;
    }
            cout<<sum<<endl;

    return 0;
}


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

int main() { 
  
  int s = 0, s1 = 0, s2 = 0, s3 = 0;  
  cin >> s;
  
  s1 = s / 100;
  s2 = (s - s1 * 100) / 10;
  s3 = s - s1 * 100 - s2 * 10;
  
  cout << s1 + s2 + s3 << endl;    
}

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

int main(void)
{
    string n;
    cin >> n;

    if(n>="A" && n<="Z"){
        cout << "A" << endl;
    }else{
        cout << "a" << endl;
    }

    return 0;
}

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

using namespace std;

int main() {

    string s;
    int a=-1, z=-1;
    
    getline(cin, s);
    
    for(int i=0; i<s.size(); i++) {
        if (a == -1 && s[i] == 'A')
            a = i;
        if (s[i] == 'Z')
            z = i;
    }
    
    cout << z-a+1 << "\n";
    
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

pair<int,int> p1,p2;
pair<int,int> p3,p4;

int main(){
    cin>>p1.first>>p1.second>>p2.first>>p2.second;

    p3.first=p2.first+(p1.second-p2.second);
    p3.second=p2.second+(p2.first-p1.first);
    p4.first=p3.first+(p2.second-p3.second);
    p4.second=p3.second+(p3.first-p2.first);

    cout<<p3.first<<' '<<p3.second<<' '<<p4.first<<' '<<p4.second;
}

Measured memory_bytes: 256
/**Bismillahir Rahmanir Raheem
    Author:Refat(BSMRSTU)**/
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pil pair<int,ll>
const int N = 1e5 + 5;
const int M = 1e9 + 7;
const double pi=2*acos(0.0);
const double esp=1e-9;
int Set(int N,int pos) {
    return N=N | (1<<pos);
}
int reset(int N,int pos) {
    return N= N & ~(1<<pos);
}
bool check(int N,int pos) {
    return (bool)(N & (1<<pos));
}
int main() {
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);
    int test=1,n,ans,a;
    ///scanf("%d",&test);
    for(int cs=1; cs<=test; cs++) {
       scanf("%d %d",&n,&a);
       if(n%a){
        printf("%d\n",(n/a)+1);
       }
       else{
        printf("%d\n",n/a);
       }
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

struct Kmp {
    string pat;
    vector<int> tab;

    template<class T>
    Kmp(const T& pat) : pat(pat) {
        build();
    }

    void build() {
        int n = pat.size();
        tab.resize(n);
        for (int i = 1, j = 0; i < n; ++i) {
            if (pat[i] == pat[j]) {
                ++j;
                tab[i] = j;
            } else if (j > 0) {
                j = tab[j - 1];
                --i;
            } else {
                j = 0;
            }
        }
    }

    template<class T>
    vector<int> match_all(const T& s) const {
        int n = s.size(), m = pat.size();
        vector<int> res;
        for (int i = 0, j = 0; i < n; ++i) {
            if (s[i] == pat[j]) {
                ++j;
                if (j == m) {
                    res.push_back(i - m + 1);
                    j = tab[m - 1];
                }
            } else if (j > 0) {
                j = tab[j - 1];
                --i;
            }
        }
        return res;
    }
};

int main() {
    string s, p;
    cin >> s >> p;
    Kmp kmp(p);
    auto a = kmp.match_all(s);
    for (int x : a) {
        cout << x << '\n';
    }
    return 0;
}


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

int main(){
    int n, W;
    cin >> n >> W;
    ll w[n], v[n];
    rep(i,n) cin >> w[i] >> v[i];
    vector<vector<ll>> dp(n+1,vector<ll>(W+1,0));
    rep(i,n){
        rep(j,W+1){
            if(j < w[i]) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i]);
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}


Measured memory_bytes: 80256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskF {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            String t = in.next();
            int n = s.length();
            int m = t.length();
            int[][] lcs = new int[n + 1][m + 1];
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i <= n; i++) {
                for (int j = 0; j <= m; j++) {
                    if (i == 0 || j == 0) {
                        lcs[i][j] = 0;
                    } else if (s.charAt(i - 1) == t.charAt(j - 1)) {
                        lcs[i][j] = 1 + lcs[i - 1][j - 1];
                    } else {
                        lcs[i][j] = Math.max(lcs[i - 1][j], lcs[i][j - 1]);
                    }
                }
            }
            int i = n, j = m;
            while (i > 0 && j > 0) {
                if (lcs[i][j] == lcs[i - 1][j]) {
                    i -= 1;
                } else if (lcs[i][j] == lcs[i][j - 1]) {
                    j -= 1;
                } else if (lcs[i][j] == 1 + lcs[i - 1][j - 1]) {
                    i -= 1;
                    j -= 1;
                    sb.append(s.charAt(i));
                }
            }
            out.println(sb.reverse().toString());
        }

    }
}



Measured memory_bytes: 81256
import re
while True:
    N, M = map(int, raw_input().split())
    if (N, M) == (0, 0):
        break
    rules = []
    for _ in xrange(N):
        f, p1, p2 = raw_input().replace("?", "\d").split()        
        rules += [(f, re.compile(p1+p2))]
    rules = rules[::-1]
    def check(s):
        a1, a2, _ = s.split()
        a = a1 + a2
        for f, r in rules:
            if f == "permit" and r.match(a):
                return True
            if f == "deny" and r.match(a):
                return False
    ans = filter(check, [raw_input() for _ in xrange(M)])
    print len(ans)
    if len(ans) != 0:
        print "\n".join(ans)

Measured memory_bytes: 5268
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
long long a[105];
long long gys(long long m,long long n)
{
    long long t;
    long long  b;
    if(m<n)
    {
        t=m;
        m=n;
        n=t;
    }
    do{
    b=m%n;
    m=n;
    n=b;
    }while(n!=0);
    return m;
}
long long gbs(long long m,long long n)
{
    long long b;
    long long sum;
    b=gys(m,n);
    sum=m/b*n;
    return sum;
}
int main()
{
    long long b;
    int n,i;
  
    while(scanf("%d",&n)!=EOF)
    {       memset(a,0,sizeof(a));
        for(i=0;i<n;i++)
        scanf("%lld",&a[i]);
        if(n==1)
      printf("%lld\n",a[0]);
        else 
        {
		
        b=gbs(a[0],a[1]);
        for(i=2;i<n;i++)
        b=gbs(b,a[i]);
      printf("%lld\n",b);
      }
    }
    return 0;
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

#define INF (1<<(4*4-1))
#define MOD 1000000007

struct Edge{
   int to;
   int cost;
};

vector<vector<Edge> >e;
vector<bool>used;
vector<int>node;
bool res = true;

void func(int now){
   used[now] = true;
   if(!used[now])return;
   for(auto it:e[now]){
      if(used[it.to]){
         if(node[now]+it.cost!=node[it.to]){
            //cout<<now+1<<" "<<it.to+1<<endl;
            res = false;
            break;
         }
      }
      else{
         node[it.to] += it.cost + node[now];
         func(it.to);
      }
   }
   return;
}

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

   int N,M;
   cin>>N>>M;
   used.resize(N,false);
   node.resize(N,0);
   e.resize(N);
   for(int i=0;i<M;i++){
      int l,r,d;
      cin>>l>>r>>d;
      l--;
      r--;
      //cout<<l+1<<" "<<r+1<<" "<<d<<endl;
      Edge e1,e2;
      e1.to = r;
      e1.cost = d;
      e[l].push_back(e1);
      e2.to = l;
      e2.cost = -d;
      e[r].push_back(e2);
   }

   for(int i=0;i<N;i++){
      if(!used[i]){
         func(i);
         //cout<<i<<endl;
      }
   }

   //for(int i=0;i<N;i++)cout<<i+1<<" "<<node[i]<<endl;

   if(res)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;

   return 0;
}


Measured memory_bytes: 12032
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):
    return map(type,input().split())

#%%code
def resolve():
    H,W=pin()
    N,=pin()
    A=list(pin())
    aindex=0
    atemp=0
    for h in range(H):
        temp=[0]*W
        wren=range(W)
        if h%2!=0:wren=reversed(range(W))
        for w in wren:
            temp[w]=aindex+1
            atemp+=1
            if atemp==A[aindex]:
                aindex+=1;atemp=0
        print(*temp)
        
#%%submit!
resolve()

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
int vis[10];
vector<int> g[20];
int n;
int dfs(int now){
	bool all = true;
	rep(i,n){
		if(!vis[i]){
			all = false;
			break;
		}
	}
	if(all)return 1;
	int ret = 0;
	for(auto next:g[now]){
		if(vis[next])continue;
		vis[next] = 1;
		ret += dfs(next);
		vis[next] = 0;
	}
	return ret;
}
signed main(){
	int m;cin >> n >> m;
	rep(i,m){
		int a,b;cin >> a >> b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vis[0] = 1;
	cout << dfs(0) << endl;
	return 0;
}

Measured memory_bytes: 3628
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


x, a = MI()
print(0 if x < a else 10)


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

int main(){
    int n,k;
    cin >> n >> k;
    int number = 1;
    for(int i=0;i<n;i++){
        if(number*2>number+k){
            number += k;
        } else {
            number *= 2;
        }
    }
    cout << number << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] arr = new int[N];
        for(int i=0;i<N;i++){
            arr[i] = sc.nextInt();
        }
        int[] dp = new int[N];
        dp[0] = 0;
        for(int i=1 ;i< N;i++ ){
            int min = Integer.MAX_VALUE;
            for(int j=1; j<= K; j++){
                if(i-j>=0){
                    int cost = dp[i-j] + Math.abs(arr[i]-arr[i-j]);
                    if(cost<min){
                        min = cost;
                    }
                }
            }
            dp[i]=min;
        }
        System.out.println(dp[N-1]);
    }
}


Measured memory_bytes: 50160
import sys
input = sys.stdin.readline
s = list(input())
t = list(input())

snum = [(0,0)] #snum[j]-snum[i-1]:i-j文字目に含まれる(A,B)の数
for i in range(len(s)):
    if s[i] == 'A':
        snum.append((snum[-1][0]+1,snum[-1][1]))
    else:
        snum.append((snum[-1][0],snum[-1][1]+1))

tnum = [(0,0)]
for i in range(len(t)):
    if t[i] == 'A':
        tnum.append((tnum[-1][0]+1,tnum[-1][1]))
    else:
        tnum.append((tnum[-1][0],tnum[-1][1]+1))

q = int(input())
for i in range(q):
    a,b,c,d = map(int,input().split())
    sa = snum[b][0]-snum[a-1][0]
    sb = snum[b][1]-snum[a-1][1]
    ta = tnum[d][0]-tnum[c-1][0]
    tb = tnum[d][1]-tnum[c-1][1]
    
    #全てbにする
    b1 = sb+sa*2
    b1 += max(tb-b1,0)//3*3+3
    a1 = (b1-tb)*2
    if abs(a1-ta)%3==0:
        print('YES')
        continue
    
    #全てaにする
    a2 = sa+sb*2
    a2 += max(ta-a2,0)//3*3+3
    b2 = (a2-ta)*2
    if abs(b2-tb)%3==0:
        print('YES')
        continue
    
    print('NO')


Measured memory_bytes: 26052