akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  int n,k,s;
  cin >> n >> k >> s;
  if (s == 1e9) {
    rep(i,k) cout << s << ' ';
    rep(i,n-k) cout << 1 << ' ';
    cout << endl;
  } 
  else {
    rep(i,k) cout << s << ' ';
    rep(i,n-k) cout << s+1 << ' ';
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3604
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Fri Dec 21 00:20:49 2018
//
package main

import "fmt"

func main() {
	var S, T string
	fmt.Scan(&S, &T)

	m := map[uint8]uint8{}
	for i := range S {
		if c, ok := m[S[i]]; ok {
			if c != T[i] {
				fmt.Println("No")
				return
			}
		}
		m[S[i]] = T[i]
	}

	m = map[uint8]uint8{}
	for i := range T {
		if c, ok := m[T[i]]; ok {
			if c != S[i] {
				fmt.Println("No")
				return
			}
		}
		m[T[i]] = S[i]
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 2176
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    String a;
    String b;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        a = sc.next();
        b = sc.next();
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        a = a + b;
        int n = Integer.parseInt(a);
        int m = (int)Math.sqrt(n);
        if (n == m * m) {
            System.out.println("Yes");            
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21972
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
    }
    println!("{}", 6 - a - b);
}


Measured memory_bytes: 4352
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
char v[60][60];
int n;
int w[50][30];
int main() {
    
    
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    //初期化
    for(int i=0;i<50;i++){
        for(int j=0;j<30;j++){
            w[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<=50;j++){
            w[i][v[i][j]-'a']++;
        }
    }
    //cout<<w[2][0]<<endl;
    int min=60;
    int a[26];
    for(int i=0;i<26;i++){
        a[i]=0;
    }

    for(int i=0;i<26;i++){
        int min=60;
        for(int j=0;j<n;j++){
            if(min>w[j][i]){
                min=w[j][i];
            }
        }
        a[i]=min;
        while(a[i]>0){
            cout<<(char)(i+'a');
            a[i]--;
        }

    }
    printf("\n");


    return 0;
}

Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
        s:Chars,
    }
    println!("{}", s.iter().filter(|&x| *x == '2').count());
}


Measured memory_bytes: 2112
n, k = map(int, input().split())
a = input()

one = 0
zero = 0
z = 0
flg = False
num_list = []

if a[0] == '0':
    flg = True
for i in a:
    if one >= 0 and zero == 0 and i == '1':
        one += 1
    elif one == 0 and zero >= 0 and i == '0':
        zero += 1
        z += 1
    elif zero > 0 and i == '1':
        num_list.append(zero)
        one += 1
        zero = 0
    elif one > 0 and i == '0':
        num_list.append(one)
        zero += 1
        one = 0
        z += 1
num_list.append(max(one, zero))

if a[0] == '0':
    num_list.insert(0,0)
num_list.insert(0,0)
num_list.append(0)

if z <= k:
    print(n)
    exit()

n_list = []

sum = 0
for i in range(len(num_list)):
    sum += num_list[i]
    n_list.append(sum)

width = 2*k
if width >= len(num_list):
    print(n)
    exit()

max_num = 0

for i in range(1, len(n_list)-width, 2):
    num = n_list[i+width] - n_list[i-1]
    if num > max_num:
        max_num = num

print(max_num)


Measured memory_bytes: 7932
def prime_factor(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            while n % i == 0:
                n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors


def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors


def mebius(n):
    res = {}
    primes = prime_factor(n)
    m = len(primes)
    for i in range(1 << m):
        mu = 1
        d = 1
        for j in range(m):
            if i >> j & 1:
                mu *= -1
                d *= primes[j]
        res[d] = mu
    return res


mod = 10**9+7
N, K = map(int, input().split())
div = divisors(N)

ans = 0

for x in div:
    div2 = divisors(x)
    mu = mebius(x)
    cnt = 0
    for y in mu.keys():
        cnt += pow(K, ((x//y)+1)//2, mod)*mu[y]
    if x % 2 == 0:
        cnt *= pow(2, mod-2, mod)
    ans += x*cnt
    ans %= mod

print(ans)


Measured memory_bytes: 46316
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

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

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	string s;
	cin >> s;
	
	int s1 = 10 * (s[0] - '0') + s[1] - '0';
	int s2 = 10 * (s[2] - '0') + s[3] - '0';
	
	bool ok1 = false, ok2 = false;
	
	if(s1 >= 1 && s1 <= 12)
		ok1 = true;
	
	if(s2 >= 1 && s2 <= 12)
		ok2 = true;
		
	if(ok1 && ok2)
		cout << "AMBIGUOUS" << endl;
	else if(!ok1 && !ok2)
		cout << "NA" << endl;
	else if(!ok1 && ok2)
		cout << "YYMM" << endl;
	else
		cout << "MMYY" << endl;

	return 0;
}


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;


int main() {
    int n, m;
    cin >> n >> m;
    int k, s;
    int x;
    vector<vector<bool>> t(m, vector<bool>(n, false));
    for (int i = 0; i < m; i++) {
        cin >> k;
        for (int j = 0; j < k; j++) {
            cin >> x;
            t[i][x - 1] = true;
        }
    }

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

    int cnt = 0;
    for (int i = 0; i < 1 << n; i++) {
        vector<int> cond(m, 0);
        for (int j = 0; j < n; j++) {
            if ((1 & i >> j) == 1) {
                for (int k = 0; k < m; k++) {
                    if (t[k][j]) {
                        cond[k]++;
                    }
                }
            }
        }
        bool ok = true;
        for (int j = 0; j < m; j++) {
            if (cond[j] % 2 != p[j]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(){cout << -1 << '\n';}
const int INF = 1e18;

signed main(){
    int a, b; cin >> a >> b;
    if(a == 1) a = 14;
    if(b == 1) b = 14;
    if(a==b){
        cout << "Draw" << endl;
        return 0;
    }
    cout << (a > b ? "Alice" : "Bob") << '\n';
}

Measured memory_bytes: 3588
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <map>
#include <random>
#include <string>

using namespace std;
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		cout << "x";
	}

	return 0;
}


Measured memory_bytes: 888
import itertools
n = int(input())
s = [input() for _ in range(n)]
a = [0,0,0,0,0]
for i in range(len(s)):
    if (s[i][0]=="M"):
        a[0] += 1
    elif (s[i][0]=="A"):
        a[1] += 1
    elif (s[i][0]=="R"):
        a[2] += 1
    elif (s[i][0]=="C"):
        a[3] += 1
    elif (s[i][0]=="H"):
        a[4] += 1

l = [0,1,2,3,4]
p = list(itertools.combinations(l, 3))
ans = 0
for i in range(len(p)):
    x,y,z = p[i][0],p[i][1],p[i][2]
    ans += a[x]*a[y]*a[z]
print(ans)

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

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

    int rep_time = (n+1)/2;
    bool ex = false;
    int ans = 0;

    rep(i,(rep_time+1)) {
        ex = false;
        rep(j,p.size()) {
            if(x-i == p[j]){
                ex = true;
            }
        }
        if(ex == false){ 
            ans = x-i;
            break;
        }
        ex = false;
        rep(j,p.size()) {
            if(x+i == p[j]){
                ex = true;
            }
        }
        if(ex == false){
            ans = x+i;
            break;
        }
    }

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

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

int main() {
  int N, W;
  cin >> N >> W;
  long long w[N], v[N];
  for (int i=0; i<N; i++) cin >> w[i] >> v[i];

  long long dp[W+1] = {};
  for (int i=0; i<N; i++) {
    for (int j=W-w[i]; j>0; j--) {
      if (dp[j] > 0 and dp[j + w[i]] < (dp[j] + v[i])) dp[j + w[i]] = dp[j] + v[i];
    }
    if (dp[w[i]] < v[i]) dp[w[i]] = v[i];
  }
  long long ans = 0;
  for (int i=0; i<=W; i++) {
    if (dp[i] > ans) ans = dp[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;

int myabs(int a) {
    if (a < 0) return -a;
    return a;
}

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout.precision(12);
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if (myabs(a - c) <= d) {
        cout << "Yes" << endl;
        return 0;
    }

    if (myabs(a - b) <= d && myabs(b - c) <= d) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M_PI 3.14159265358979323846
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> ipair;
typedef pair<ll, ll> llpair;

int h, w, m, x, y;

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin>>h>>w>>m;
    int row[h], col[w];
    fill_n(row, h, 0);
    fill_n(col, w, 0);
    set<ipair> targets;
    for(int i=0; i<m; i++){
        cin>>x>>y;
        x--, y--;
        targets.insert({x, y});
        row[x]++;
        col[y]++;
    }
    int row_max = *max_element(row, row+h);
    int col_max = *max_element(col, col+w);
    vector<int> row_cand, col_cand;
    for(int i=0; i<h; i++){
        if(row[i]==row_max) row_cand.push_back(i);
    }
    for(int i=0; i<w; i++){
        if(col[i]==col_max) col_cand.push_back(i);
    }
    int ans = row_max+col_max-1;
    for(int i=0; i<row_cand.size() && ans<row_max+col_max; i++){
        for(int j=0; j<col_cand.size(); j++){
            if(targets.find({row_cand[i], col_cand[j]})==targets.end()){
                ans++;
                break;
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 23808
// khodaya khodet komak kon
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;

const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 50 + 10;
const ll INF = 1e18;
const ll LOG = 20;
ll n, a[N], A, dp[N][N][N * N + 100];
int main(){
	IOS;
	cin >> n >> A;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	dp[0][0][100] = 1;
	for (ll i = 1; i <= n; i++){
		dp[i][0][100] = 1;
		for (int j = 1; j <= min(n, i); j++){
			for (int sum = 0; sum < N * N ; sum++){
				dp[i][j][sum + 100] = dp[i - 1][j][sum + 100] + dp[i - 1][j - 1][sum - a[i] + 100];
				//debug(dp[i][j][sum + 100]);
			}
		}
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++){
		ans += dp[n][i][A * i + 100];
	}
	cout << ans;
	
	
	
	
	
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)

using lli = long long int;

int main(){
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<lli> a(x);
  vector<lli> b(y);
  vector<lli> c(z);
  
  REP(i, x) cin >> a.at(i);
  REP(j, y) cin >> b.at(j);
  REP(k, z) cin >> c.at(k);
  
  vector<lli> ab(x*y);
  int idx = 0;
  REP(i, x) {
    REP(j, y) {
      ab.at(idx) = a.at(i) + b.at(j);
      idx++;
    }
  }
  
  sort(ab.rbegin(), ab.rend());
  
  vector<lli> abc(k*z);
  idx = 0;
  REP(i, min(x*y, k)) {
    REP(j, z) {
      abc.at(idx) = ab.at(i) + c.at(j);
      idx++;
    }
  }
  
  sort(abc.rbegin(), abc.rend());
  REP(i, k) {
    cout << abc.at(i) << endl;
  }
}


Measured memory_bytes: 31616
#! env/bin/local python3
# -*- coding:utf-8 -*-

# -- submit ----

import numpy as np

a, b, h, m = map(float, input().split())

theta = np.abs(h * 30. + 0.5 * m - m * 6.) / 180 * np.pi

print(np.sqrt(a ** 2. + b ** 2. - 2 * a * b * np.cos(theta)))


Measured memory_bytes: 27192
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
        long n = cin.nextLong();
        long k = cin.nextLong();
        if(k == 1){
        	System.out.println(0);
        	return;
        }
        HashMap<Long,Integer> mp = new HashMap<Long,Integer>();
        long x = n%k;
        long minn = x;
        while(true){
        	x = Math.abs(x-k);
        	if(!mp.containsKey(x)){
        		 mp.put(x, 1);
        		 minn = Math.min(x, minn);
        	}
        	else break;
        }
        System.out.println(minn);
    }
}

Measured memory_bytes: 21844
int main(){
  int N,i;
  int a[1001]={0};
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  int min,max;
  min=a[0];
  min=a[0];
  for(i=0;i<N;i++){
    if(min>a[i]){
      min=a[i];
    }
  }
  for(i=0;i<N;i++){
    if(max<a[i]){
      max=a[i];
    }
  }
  
  printf("%d",max-min);
}


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

int main(){
  int n; cin>>n;
  vector<int> num(n),base(n);
  for(int i=0;i<n;i++){
    cin>>base[i];
    num[i]=base[i];
  }
  sort(num.begin(),num.end());
  int left=num[n/2-1],right=num[n/2];
  for(int i=0;i<n;i++){
    if(base[i]<=left){
      cout<<right<<endl;
    }else{
      cout<<left<<endl;
    }
  }
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ll> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define FOR(i, a, b) for (ll i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (ll i = (b), _a = (a); i >= _a; i--)
#define REP(i, n) for (ll i = 0, _n = (n); i < _n; i++)
#define FORE(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fi   first
#define se   second
#define all(a) a.begin(), a.end()
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define endl '\n'

const ll N = 3005, MOD = 1e9 + 7, H = 2e5 + 5;
ll dp[N], h, w, fac[H], n;
ii a[N];

void add(ll &a, ll b) {
	a = (a + b) % MOD;
	return;
}

void sub(ll &a, ll b) {
	a = (a - b + MOD) % MOD;
	return;
}

void mult(ll &a, ll b) {
	a = 1LL * a * b % MOD;
	return;
}

ll mul(ll a, ll b) {
	return 1LL * a * b % MOD;
}

ll modPow(ll a, ll x) {
	ll res = 1;
	while (x) {
		if (x & 1) mult(res, a);
		mult(a, a);
		x >>= 1;
	}
	return res;
}

ll inv(ll a) {
	return modPow(a, MOD - 2);
}

ll C(ll k, ll n) {
	if (k > n) return 0;
	ll ret = fac[n];
	mult(ret, inv(mul(fac[n - k], fac[k])));
	return ret;
}

int main(int argc, char const *argv[])
{
    //freopen("Y.inp","r",stdin);
	ios_base::sync_with_stdio(0); cin.tie(0);
	clock_t tStart = clock();

	cin >> h >> w >> n;
	FOR(i, 1, n) cin >> a[i].first >> a[i].second;
	fac[0] = 1;
	FOR(i, 1, H - 3) {
		fac[i] = fac[i - 1];
		mult(fac[i], i);
	}

	sort(a + 1, a + 1 + n);
	FOR(i, 1, n) {
		dp[i] = C(a[i].first - 1, a[i].second + a[i].first - 2);
		FOR(j, 1, i - 1) if (a[j].second <= a[i].second)
			sub(dp[i], mul(dp[j], C(a[i].first - a[j].first, a[i].first + a[i].second - a[j].first - a[j].second)));
	}

	ll res = C(h - 1, h + w - 2);
	FOR(i, 1, n) sub(res, mul(dp[i], C(h - a[i].first, h + w - a[i].first - a[i].second)));
	cout << res << endl;

	fprintf(stderr, "Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
	return 0;
}


Measured memory_bytes: 1920
import numpy as np

inf = float('inf')

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

dp = np.zeros((N + 1, 2))
dp[0][1] = -inf
# dp[i][0]:=1-indexedで、a_iとa_i+1を反転させない場合の最大値
# dp[i][1]:=1-indexedで、a_iとa_i+1を反転させる場合の最大値

for i, aa in enumerate(a, 0):
    dp[i + 1][0] = max(dp[i][0] + aa, dp[i][1] - aa)
    dp[i + 1][1] = max(dp[i][0] - aa, dp[i][1] + aa)
print(int(dp[N][0]))


Measured memory_bytes: 20888
def myAnswer(N:int)->int:
   length = len(str(N))
   if(length == 1): return N
   l = list(str(N))
   tmp = 0
   for n in l[1:]:
      tmp += int(n)
   total = length * 9
   if(tmp == total - 9):
      return tmp + int(l[0])
   else:
      total += -9 + int(l[0]) - 1
      return total
def modelAnswer():
   tmp=1
def main():
   N = int(input())
   print(myAnswer(N))

if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
import scala.annotation.tailrec
import scala.collection.mutable
import scala.io.StdIn._
object Main extends App {
  val Array(x, a) = readLine.trim.split(' ').map(_.toInt)
  println(if (x < a) 0 else 10)
  implicit class Scope[T](val receiver: T) extends AnyVal {
    def let[A](@inline func: T ⇒ A): A = func(receiver)
    def tap(@inline func: T ⇒ Unit): T = {
      func(receiver)
      receiver
    }
  }
}


Measured memory_bytes: 25528
#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); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
 
typedef long long ll;
#define INF 1e9
 
int main(){
  int N, Ma, Mb;
  cin >> N >> Ma >> Mb;
  vector<int> a(N), b(N), c(N);
  REP(i, N){
    cin >> a[i] >> b[i] >> c[i];
  }

  vector<vector<vector<int>>> dp(N+1, vector<vector<int>>(411,vector<int>(411, 1e9)));
  dp[0][0][0] = 0;
  REP(i, N){
    FOR(j, 0, 401){
      FOR(k, 0, 401){
        dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
        dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i]);
      }
    }
  }
  int ans = 1e9;
  FOR(i, 1, 401){
    FOR(j, 1, 401){
      if(i % Ma == 0 && j % Mb == 0 && i/Ma == j/Mb){
        ans = min(dp[N][i][j], ans);
      }
    }
  }

  if(ans == 1e9){
    cout << -1 << endl;
  }
  else{
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 28672
use proconio::{input, fastout};
// use std::cmp::max;

#[fastout]
fn main() {
    input! {
        n: usize,
        mut hp: [[i32; 3]; n],
    }

    hp.insert(0, vec![0; 3]);
    let mut dp = vec![vec![0;3]; n+1];

    for day in 1..dp.len() {
        dp[day][0] = dp[day-1][1].max(dp[day-1][2]) + hp[day][0];
        dp[day][1] = dp[day-1][0].max(dp[day-1][2]) + hp[day][1];
        dp[day][2] = dp[day-1][0].max(dp[day-1][1]) + hp[day][2];
        // for act in 0..3 {
        //     let oa = (0..3).filter(|&n| n != act).collect::<Vec<usize>>();
        //     dp[day][act] = max(dp[day-1][oa[0]], dp[day-1][oa[1]]) + hp[day][act];
        // }
    }

    println!("{:?}", dp[n].iter().max().unwrap());
}


Measured memory_bytes: 14592
#include <iostream>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

const int MOD = 1e9+7;

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept { return val ? MOD - val : 0; }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept { return this->val == r.val; }
    constexpr bool operator != (const Fp& r) const noexcept { return this->val != r.val; }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept { return os << x.val; }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<MOD>;

int main() {
  int N; cin >> N;

  int x[N];
  rep(i, N) cin >> x[i];

  mint j = 1, ans = 0;
  rep(i, N-1) {
    ans += ((mint)x[i+1]-x[i]) * j;
    j += mint(1) / (i+2);
  }
  rep(i, N-1) {
    ans *= i+1;
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
  string s;
  cin >> s;
  bool ok = true;
  if (s[0] == s[1]) ok = false;
  if (s[1] == s[2]) ok = false;
  if (s[2] == s[3]) ok = false;
  
  if (ok) cout << "Good" << endl;
  else cout << "Bad" << endl;
}

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

int main() {
  int N;
  int S = 0;
  int l, r;
  
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> l >> r;
    S += r - l + 1;
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
#define PI 3.14159265358979323846264338327950L
const int mod=1000000007,MAX=200005,INF=1<<30;

	int n;
  	ll a[100010][3];
  
  	ll dp[100010][3];

int main() {
	int n; cin>>n;
  	for(int i=0;i<n;i++){
      for(int j=0;j<3;j++){
      	cin>>a[i][j];
      }
}

	for(int i=0;i<n;i++){
    	for(int j=0;j<3;j++){
        	for(int k=0;k<3;k++){
            	if(j==k)continue;
              	chmax(dp[i+1][k],dp[i][j]+a[i][k]);
            }
        }
    }
  
  ll res=0;
  for(int j=0;j<3;j++)chmax(res,dp[n][j]);
  cout<<res<<endl;


}

Measured memory_bytes: 8252
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n;
  cin >> n;
  long long int a[n];
  long long int c=1;
  long long int b = 1e18;
  for(int i=0;i<n;i++)
  {
    cin >> a[i];
  }
  for(int i=0;i<n;i++)
  {
    if(a[i] == 0)
    {
      cout << 0  << endl;
      return 0;
    }
  }
  for(int i=0;i<n;i++)
  {

    if(a[i] > b/c)
    {
      cout << -1 << endl;
      return 0;
    }
    else
    {
      c = c * a[i];
    }
  }
  if(c > b)
  {
    cout << -1 << endl;
  }
  else
  {
    cout << c << endl;
  }

  return 0;
}


Measured memory_bytes: 4380
#include<stdio.h>

int main(){
	long long x;
	scanf("%lld",&x);
	
	long long i = 1;
	long long sum = 0;
	for(i = 1;i <= x;i++){
		int a = i/3;
		int b = i/5;
		if(a*3 != i && b*5 != i)
			sum +=i;
	}
	
	printf("%lld",sum);
} 

Measured memory_bytes: 1704
s = input().strip()

gc, pc = 0, 0
wc, lc = 0, 0
for _s in s:
  if _s == 'g':
    if pc + 1 <= gc:
      pc += 1
      wc += 1
    else:
      gc += 1
  else:
    if pc + 1 <= gc:
      pc += 1
    else:
      gc += 1
      lc += 1
print(wc - lc)


Measured memory_bytes: 3316
<?php
  list($n, $k) = explode(" ", trim(fgets(STDIN)));

  $snuke = array_fill(1, $n, 0);

  for($i=0; $i<$k; $i++){
    list($d) = explode(" ", trim(fgets(STDIN)));
    $a = explode(" ", trim(fgets(STDIN)));    
    for($j=0; $j<$d; $j++){
      $snuke[$a[$j]]++;
    }
  }

  $ans = 0;
  for($i=1; $i<=$n; $i++){
    if($snuke[$i] == 0){
      $ans++;
    }
  }

  echo $ans;

Measured memory_bytes: 16180
#include<stdio.h>
#include<stdlib.h>

typedef struct node{
  struct node *parent;
  int key;
  struct node *left;
  struct node *right;
}Node;

Node *head;
void insert(Node *,int);
Node *make_node(Node *,int,Node *,Node *);
void inorder_print(Node *);
void preorder_print(Node *);
void free_node(Node *);

int main(){
  int n,key;
  char command[7];
  head = make_node(NULL,key,NULL,NULL);
  scanf("%d",&n);
  while(n--){
    scanf("%s",command);
    if(command[0] == 'i'){
     
      scanf("%d",&key);
      insert(head->left,key);
    }
    else{
      inorder_print(head->left);
      printf("\n");
      preorder_print(head->left);
      printf("\n");
    }
  }
  free_node(head->left);
  free(head);
}

void insert(Node *node,int in_key){
  if(node == NULL)head->left = make_node(node,in_key,NULL,NULL);
  else{
    if(node->key > in_key){
      if(node->left == NULL) node->left = make_node(node,in_key,NULL,NULL);
      else insert(node->left,in_key);
    }
    else{
      if(node->right == NULL) node->right = make_node(node,in_key,NULL,NULL);
      else insert(node->right,in_key);
    }
  }
}

Node *make_node(Node *p,int k,Node *l,Node *r){
  Node *new;

  new = malloc(sizeof(Node));
  if(new == NULL){
    free(new);
    printf("node Generation failed\n");
    exit(1);
  }
  new->parent = p;
  new->key = k;
  new->left = l; 
  new->right= r;
  return new;
}
void inorder_print(Node *next){
  if(next != NULL){
    inorder_print(next->left);
    printf(" %d",next->key);
    inorder_print(next->right);
  }
}
void preorder_print(Node *next){
  if(next != NULL){
    printf(" %d",next->key);
    preorder_print(next->left);
    preorder_print(next->right);
  }
}
void free_node(Node *n){
  if(n->left != NULL){
    free_node(n->left);
    free(n->left);
  }
  if(n->right != NULL){
    free_node(n->right);
    free(n->right);
  }
}



Measured memory_bytes: 25176
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#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 acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
	int n;
	cin >> n;
	vector<ll> v(n);
	rep(i, n) cin >> v[i];
	ll ans = 0;
	rep(i, 60)
	{
		ll x = 0;
		rep(j, n)
			x += (v[j] >> i & 1) ? 1 : 0;
		ll y = n - x;
		ll tans = x * y%MOD;
		rep(j, i)
		{
			tans *= 2;
			tans %= MOD;
		}
		ans += tans;
		ans %= MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
    IOS; string s;
    cin >> s;
    if(s[1]=='B')
        cout << "ARC";
    else
        cout << "ABC";
    return 0;
}


Measured memory_bytes: 3608
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll n;
  cin >> n;
  map<string,ll> m;

  rep(i,n)
  {
    string s;
    cin >> s;
    m[s] = 1;
  }

  ll ty = sz(m);

  cout << ty << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 19228
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<limits>
#include<queue>
#include<stack>
#include<math.h>
#include<array>
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;
int main(){
    string S;
    cin >> S;
    int ans = 753;
    for(int i = 0; i < S.size() - 2; i++){
        int X = 100 * (S[i] - '0') + 10 * (S[i + 1] - '0') + S[i + 2] - '0';
        ans = min(ans, abs(753 - X));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n; cin >> n;
    vector<vector<pair<int, int>>> a(n);
    for (int i = 0; i < n; i++) {
        int k; cin >> k;
        a[i].resize(k);
        for (auto &p : a[i]) {
            cin >> p.first >> p.second;
            p.first--;
        }
    }
    int res = 0;
    for (int mask = 1; mask < (1 << n); mask++) {
        bool ok = true;
        bitset<20> b(mask);
        for (int i = 0; i < n; i++) {
            if (b[i]) {
                for (auto &p : a[i]) {
                    if (b[p.first] != p.second) {
                        ok = false;
                    }
                }
            }
        }
        if (ok) {
            res = max(res, (int) b.count());
        }
    }
    cout << res << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  while(1){
    int h,w;
    int counth,countw;
    scanf("%d%d",&h,&w);
    if(h==0&&w==0) break;
    else if(h>=3&&w<=300){
    for(countw=0;countw<w;countw++) printf("#");
    printf("\n");
    for(counth=0;counth<h-2;counth++){
      printf("#");
      for(countw=0;countw<w-2;countw++){
        printf(".");
      }
      printf("#");
      printf("\n");
    }
    for(countw=0;countw<w;countw++) printf("#");
    printf("\n\n");
  }else continue;
}
  return 0;
}

Measured memory_bytes: 588
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
  int N;
  cin >> N;

  if (N % 2 == 0) {
    cout << N * (N - 2) / 2 << endl;
  } else {
    cout << (N - 1) + (N - 1) * (N - 3) / 2 << endl;
  }

  if (N % 2 == 1) {
    N--;
    for (int i = 1; i <= N; i++) {
      cout << i << " " << N + 1 << endl;
    }
  }

  for (int i = 1; i <= N; i++) {
    for (int j = i + 1; j <= N; j++) {
      if ((i + j) != (N + 1)) {
        cout << i << " " << j << endl;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	ll A, B, K;  cin >> A >> B >> K;
  	ll a = max((ll)0, A - K), b = B;
  	if(a == 0)  b = max((ll)0, B - (K - A));
	
	cout << a << " " << b;
 
	return 0;
}


Measured memory_bytes: 256
dp[1<<17],h[1<<17],i,j,n;
main(k)
{
	for(scanf("%*d%d",&k);~scanf("%d",++n+h);)dp[n]=~-n*1e4;
	for(;++i<n;)for(j=0;j++<k;)dp[i+j]=fmin(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
	printf("%d",dp[n-1]);
}

Measured memory_bytes: 896
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    int D; std::cin >> D;
    std::vector<int> c(26), t(D+1);
    std::vector<std::set<int>> days(26);
    for(int i(0); i < 26; ++i){
        days[i].emplace(0);
        days[i].emplace(D+1);
    }
    std::vector<std::vector<int>> s(D+1, std::vector<int>(26));
    for(int i(0); i < 26; ++i) std::cin >> c[i];
    for(int i(1); i <= D; ++i){
        int mx(0), id(-1);
        for(int j(0); j < 26; ++j){
            std::cin >> s[i][j];
            if(chmax(mx, s[i][j])) id = j;
        }
        t[i] = id;
        days[t[i]].emplace(i);
    }

    long long v(0);
    for(int i(1); i <= D; ++i){
        long long dcr(0);
        for(int j(0); j < 26; ++j){
            auto itr(std::upper_bound(std::begin(days[j]), std::end(days[j]), i));
            dcr += c[j] * (i - *(--itr));
        }
        v += s[i][t[i]] - dcr;
    }
    int M(100000);
    srand((unsigned int)time(NULL));
    {
        int d, q;
        for(int qq(0); qq < M; ++qq){
            d = rand() % D + 1;
            q = rand() % 26;

            long long oldv(v);

            auto itr(days[t[d]].find(d));
            long long d1(*(--itr));
            itr = std::upper_bound(std::begin(days[t[d]]), std::end(days[t[d]]), d);
            long long d2((*itr)-1);
            v -= c[t[d]] * ((d1-d)*(d-d2) + d - d1);

            itr = std::lower_bound(std::begin(days[q]), std::end(days[q]), d);
            d1 = *(--itr);
            itr = std::upper_bound(std::begin(days[q]), std::end(days[q]), d);
            d2 = (*itr)-1;
            v += c[q] * ((d1-d)*(d-d2) + d - d1);

            v += s[d][q] - s[d][t[d]];
            if(oldv <= v){
                days[t[d]].erase(d);
                days[q].emplace(d);
                t[d] = q;
            }else{
                v = oldv;
            }
        }
    }
    for(int i(1); i <= D; ++i){
        std::cout << t[i] + 1 << "\n";
    }
    return 0;
}


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

using namespace std;

using ll = long long;
using ii = pair<int,int>;

#define ff first
#define ss second

const int maxn = 2e5+10;

vector<int> g[maxn],ts;
bitset<maxn> vs;

int cicle=0;

void dfs(int x){
	if(vs[x]){
		cicle=x;
		return;
	}
	vs[x]=true;
	for(auto &u:g[x])
		dfs(u);
	ts.push_back(x);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	ll k;
	cin >> n >> k;
	vector<int> A(n);
	for(int i=1;i<=n;++i){
		cin >> A[i-1];
		g[i].push_back(A[i-1]);
	}
	dfs(1);
	reverse(ts.begin(),ts.end());
	vector<int> towns;
	//cout << "cicle start at value = " << cicle << '\n';
	for(int i=0;i<ts.size();++i){
		//cout << ts[i] << " \n"[i==ts.size()-1];
		if(ts[i]==cicle){
			for(int j=i;j<ts.size();++j)
				towns.push_back(ts[j]);
			break;
		}
	}
	if(k<ts.size()){
		cout << ts[k] << '\n';
	}
	else{
		k-=ts.size();
		//cout << "k = " << k << " towns.size() = "<< towns.size() << " k%t.sz() = "<< k%towns.size() << '\n';
		cout << towns[k%towns.size()] << '\n';
	}
	return 0;
}

Measured memory_bytes: 25920
#include<bits/stdc++.h>  
using namespace std;  
   
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }  
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " "<<a.second; }  
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }  
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }  
   
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)  
#define ALL(v) (v).begin(), (v).end()  
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}  
#define fr first  
#define sc second  
   
typedef pair< int , int > Pi;  
typedef pair< int , Pi > Pii;  
   
typedef long long int64;  
const int64 INF = 1LL << 60;  
  
  
//vectorよくなさそう(適当  
  
struct edge{  
  int to, cost;  
};  
  
typedef vector< vector< edge > > Graph;  
  
void add_edge(Graph& info, int u, int v, int cost, bool flag = true){  
  info[u].push_back( (edge){ v, cost});  
  if(flag) info[v].push_back( (edge){ u, cost});  
}  
  
int64 bfs(int idx, Graph& graph){  
  
  typedef pair< int , int > Pi;  
  int64 ans = INF;  
  queue< Pi > que;  
  que.push( Pi( 0, idx));  
  vector< int64 > Flag(graph.size() + 100, 0);  
  int sum = 0;  
  
  while(!que.empty()){  
    Pi p = que.front(); que.pop();  
    Flag[p.second] = p.first; /* 最後は戻らなくて良い */  
    for(int i = 0; i < graph[p.second].size(); i++){  
      edge& e = graph[p.second][i];  
      if(e.to == idx || Flag[e.to] != 0) continue;  
      if(graph[e.to].size() == 1){ /* 消して良い橋やで */  
        sum += e.cost;  
      } else {  
        sum += e.cost * 3; /* 行くコスト + 消すコスト + 戻るコスト(他の橋があるから戻ってくる必要がある)*/  
        que.push( Pi( p.first + e.cost, e.to));  
      }  
    }  
  }  
  for(int i = 0; i < graph.size(); i++){  
    if(i == idx) continue;  
    ans = min( ans, sum - Flag[i]);  
  }  
  return ans;  
}  
  
int main(){  
  int n;  
  while(cin >> n, n){  
  
    Graph info(n + 100);  
    int64 ret = INF;  
  
    vector< int64 > p(n - 1), d(n - 1);  
    cin >> p;  
    cin >> d;  
  
    for(int i = 0; i < n - 1; i++){  
      add_edge( info, i + 1, p[i] - 1, d[i]);   
    }  
  
    for(int i = 0; i < n; i++){  
      ret = min( ret, bfs(i, info));  
    }  
      
    cout << ret << endl;  
  }  
}  

Measured memory_bytes: 1296
from heapq import heappush, heappop
n,m=map(int,input().split())
data=[]
pn=[0 for _ in range(n)]
for i in range(m):
  p,y=map(int,input().split())
  heappush(data,(y,p,i))
data2=[]
while data:
  y,p,i=heappop(data)
  pn[p-1]+=1
  cid=str(p).zfill(6)+str(pn[p-1]).zfill(6)
  data2.append((i,cid))
for i,cid in sorted(data2):
  print(cid)

Measured memory_bytes: 109900
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep(i,n) for(ll i=0; i<n; i++)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int n;  cin >> n;
  ll y;  cin >> y;
  rep(i,n+1){
    rep(j,n-i+1){
      if(y == 10000*i+5000*j+1000*(n-i-j) ){
        cout << i << " " << j << " " << n-i-j;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n, h = 0, a;
    long long ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a);
        if (h < a) {
            h = a;
        }
        else {
            ans += h - a;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3740
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    vector<ll>a(90);
    a[0]=2;
    a[1]=1;
    FOR(i,2,90){
        a[i]=a[i-1]+a[i-2];
    }
    cout << a[n] << endl;
    return 0;
}

Measured memory_bytes: 3624