akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

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

const int N_MAX = 5000;
ll Per[N_MAX] = {}; // n!
ll Per_inv[N_MAX] = {}; //(n!)^-1

ll nCr(ll n, ll r){
    if(n<r) return 0;
 
    if (n == r || r == 0)
        return 1;
    else
        return Per[n] * Per_inv[n-r] % mod * Per_inv[r] % mod;  
}
 
// a^b mod p
ll mod_pow(ll a, ll b){
    if(b==0) return 1;
 
    // 肩が奇数
    if(b%2==1){
        return a * mod_pow(a, b-1) % mod;
    }
    else{
        return mod_pow(a*a % mod, b/2) % mod;
    }
}

void prepare_nCr(){
    Per[0] = 1;
    Per_inv[0] = 1;

    // nCr高速化準備
    Per[1] = 1;
    FOR(i, 2, N_MAX){
        Per[i] = i * Per[i-1] % mod;
    }
    Per_inv[1] = 1;
    FOR(i, 2, N_MAX){
        Per_inv[i] = mod_pow(Per[i], 1000000005);
    }
}

ll f(ll N, ll K){
    return Per[N+K-1] * Per_inv[N] % mod * Per_inv[K-1] % mod;
}

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

    // input
    ll N, K;
    cin >> N >> K;

    prepare_nCr();
    
    if(N-K<0){
        p(0);
        return 0;
    }
    ll ans = f(N-K, K);
    p(ans);
    
    return 0;
}


Measured memory_bytes: 3272
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  string s;
  scan(s);
  if (s[0] == '9' || s[1] == '9') {
    print("Yes");
  } else {
    print("No");
  }
  return 0;
}


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

int main() {
  int N, K;
  int x;
  cin >> N >> K;
  int mid = K/2;
  int sum = 0;
  for(int i = 0; i < N; i++) {
    cin >> x;
    if(x > mid)
      sum += (K - x) * 2;
    else sum += x * 2;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = gets.to_i
puts A[k-1]


Measured memory_bytes: 1788
N =int(input())

def dfs(s):
  # s < N　か確認。満たさなければ、これ以上先の深さを探索しない
  if int(s) > N:
    return 0
  
  # sが753数か確認
  # もしcntを下のfor内部で作ってしまうと、毎回書き換わるので7以外がカウントできないし、元のコールスタックに戻る際にもcntのスコープによっては消える
  if s.count("3") >= 1 and s.count("5") >= 1 and s.count("7") >= 1:
    cnt = 1
  else:
    cnt = 0
    
  for num in ["3", "5", "7"]:
    # ここで連結した値がNを超えても、次のdfsが呼ばれた時に初めにはじかれるから問題ない
    cnt += dfs(s + num)
    
  return cnt

ans = dfs("0")
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int INF = 1e9;
const int EPS = 1e-9; 
const int SEARCH_MAX = 6e3;

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  int sum = 0, cost1 = 0, cost2 = 0;
  int ave, ans;
  for (int i = 0; i < N; ++i) {
    cin >> X.at(i);
    sum += X.at(i);
  }
  ave = sum / N;
  for (int i = 0; i < N; ++i) {
    cost1 += (X.at(i)-ave) * (X.at(i)-ave); 
    cost2 += (X.at(i)-ave-1) * (X.at(i)-ave-1);
  }
  ans = min(cost1, cost2);
  cout << ans << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::io::*;

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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!{
        n: i32,
        d: i32,
    }
    let t = 2 * d + 1;
    println!("{}", (n + t - 1) / t);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define fast_io() ios::sync_with_stdio(false); cin.tie(nullptr)
#define fix(n) fixed << setprecision(n)

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;


int main(void){
    fast_io();
    
    string s;
    cin >> s;
    rep(i,s.size()){
        if(i % 2 == 0 && s[i] == 'L'){
            cout << "No" << endl;
            return 0;
        } else if (i % 2 == 1 && s[i] == 'R'){
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3100
a=list(map(int,input().split()))
matrix=[[] for i in range(a[0])]
ans=[0,]*a[0]
vector=[]
for i in range(a[0]):
    value=list(map(int,input().split()))
    for j in range(a[1]):
        matrix[i].append(value[j])
for i in range(a[1]):
    vector.append(int(input()))

# start calc
for i in range(a[0]):
    for j in range(a[1]):
        ans[i]+=matrix[i][j]*vector[j]
# print
for i in range(a[0]):
    print(str(ans[i]))


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

#define facMax 200010

long long int factorial[facMax];

long long int reciprocal[facMax];

long long int MOD = static_cast<long long int>(1e9) + 7;

long long int my_pow(long long int a, long long int k) {
    if (k == 0) return 1;
    long long int res = my_pow(a, k / 2);
    res = res * res % MOD;
    if (k & 1) res = res * a % MOD;
    return res;
}

long long int comb(long long int n,long long int r){

    if(n < r){
        return 0;
    }

    if(r == 0){
        return 1;
    }

    return (factorial[n] * reciprocal[n-r] % MOD * reciprocal[r]) % MOD;

}


int main() {

    factorial[0] = 1;
    reciprocal[0] = 1;

    for(long long int i=1; i<facMax; i++) {
        factorial[static_cast<int>(i)] = factorial[static_cast<int>(i - 1)] * i;
        factorial[static_cast<int>(i)] %= MOD;
        reciprocal[static_cast<int>(i)] = my_pow(factorial[static_cast<int>(i)], MOD - 2);
        reciprocal[static_cast<int>(i)] %= MOD;
    }

    long long int h,w,a,b;

    cin >> h >> w >> a >> b;

    long long int ans = 0;

    //*
    for(long long int i = b; i<=w-1; i++){
        ans += comb(h-a-1+i,i)*comb(a-1+w-i-1,a-1);
        ans %= MOD;
    }//*/

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>

int main(void){

int a,b,c,d,e;
int k;	//check
int less=0;

  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
  scanf("%d",&e);
  scanf("%d",&k);
//E
  if(e-d>k)
      less=1;
  if(e-c>k)
    less=1;
  if(e-b>k)
    less=1;
  if(e-a>k)		
    less=1;	
  //D
  if(d-c>k)
      less=1;
  if(d-b>k)
    less=1;
  if(d-a>k)
      less=1;	
   //C
    if(c-b>k)
      less=1; 
  if(c-a>k)
      less=1;	
  //B
  	if(b-a>k)
      less=1;	
  
  if(less==1)
      printf(":(\n");  
  else if(less==0)
         printf("Yay!\n");

return 0;

}

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

// one-based numbering
struct union_find {
    vector<int> data;
    // i: (data[i] < 0) -> group size, (data[i] > 0) -> parent;
    union_find(int n) {
      data.resize(n+1, -1);
    }
    int find(int x) {
        if(data[x] < 0) return x;
        else return data[x] = find(data[x]);
    }
    int size(int x) {
      return -data[find(x)];
    }
    void unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
    }
    bool same(int x, int y) {
        x = find(x); y = find(y);
        return x == y;
    }
};

int main(){
  int n, m; cin >> n >> m;
  union_find u = union_find(n);
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int c; cin >> c;
    v.push_back(c);
  }
  for (int i = 0; i < m; i++) {
    int a, b; cin >> a >> b;
    u.unite(a, b);
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    count += u.same(i+1, v[i]);
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1276
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;

int main(){
  int d;
  scanf("%d",&d);
  if(22<=d&&d<=25){
    printf("Christmas");
    for(int i=d;i<=24;i++){
      printf(" Eve");
    }
    printf("\n");
  }
  
  return 0;
}


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


#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ll long long


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int a, b;
    cin >> a >> b;

    if ( a > b ) {
    	cout << 2 * a - 1 << endl;
    	return 0;
    }

    if ( b > a ) {
    	cout << 2 * b - 1 << endl;
    	return 0;
    }

    cout << a + b << endl;


    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<cstdlib>
#include<cstring>

struct Node
{
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key)
{
    Node *cur = nil->next;
    while(cur != nil && cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

void init()
{
    nil = (Node*)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList()
{
    Node *cur = nil->next;
    int isf = 0;
    while(1) {
        if(cur == nil) break;
        if(isf++ > 0) printf(" ");
        printf("%d",cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t)
{
    if(t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst()
{
    deleteNode(nil->next);
}

void deleteLast()
{
    deleteNode(nil->prev);
}

void deleteKey(int key)
{
    deleteNode(listSearch(key));
}

void insert(int key)
{
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main()
{
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d",&n);
    init();
    for(i = 0;i < n;i++) {
        scanf("%s%d",com,&key);
        if(com[0] == 'i') {
            insert(key);
            np++;
            size++;
        }
        else if(com[0] == 'd') {
            if(strlen(com) > 6) {
                if(com[6] == 'F')
                    deleteFirst();
                else if(com[6] == 'L')
                    deleteLast();
            }
            else {
                deleteKey(key);
                nd++;
            }
            size--;
        }
    }
    printList();

    return 0;
}



Measured memory_bytes: 33864
(let* ((n (read))
       (vec (make-array n :initial-element 0 :element-type 'fixnum)))
  (declare (inline sort))
  (loop :for a :from 0 :upto (1- n) :do(setf (aref vec a) (read)))
  (sort vec #'<)
  (princ (- (aref vec (/ n 2)) (aref vec (1- (/ n 2))))))

Measured memory_bytes: 59880
#ABC104

s = input()

if s[0] == "A" and s[2:-1].count("C") == 1:
    k = s[2:-1].index("C") + 2
    
    if str.islower(s[1:k] + s[k+1:]):
        print("AC")
    else:
        print("WA")
else:
    
    print("WA")
 



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<pair<long,long>> data(n);
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    data[i]=make_pair(a,b);
  }
  sort(data.begin(),data.end());
  long ans=0;
  int num=0;
  for(int i=0;i<n;i++){
    if(get<1>(data[i])<m-num){
      num+=get<1>(data[i]);
      ans+=get<0>(data[i])*get<1>(data[i]);
    }
    else{
      ans+=get<0>(data[i])*(m-num);
      break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
A_1 = input().split()
A_2 = input().split()
A_3 = input().split()

N = int(input())

B_list = []
for i in range(N):
    B = input()
    B_list.append(B)

ans = "No"

if A_1[0] in B_list:
    if A_2[0] in B_list and A_3[0] in B_list:
        ans = "Yes"
    elif A_1[1] in B_list and A_1[2] in B_list:
        ans = "Yes"
    elif A_2[1] in B_list and A_3[2] in B_list:
        ans = "Yes"

if A_1[1] in B_list and A_2[1] in B_list and A_3[1] in B_list:
    ans = "Yes"
elif A_1[2] in B_list and A_2[1] in B_list and A_3[0] in B_list:
    ans = "Yes"
elif A_1[2] in B_list and A_2[2] in B_list and A_3[2] in B_list:
    ans = "Yes"    
elif A_2[0] in B_list and A_2[1] in B_list and A_2[2] in B_list:
    ans = "Yes"
elif A_3[0] in B_list and A_3[1] in B_list and A_3[2] in B_list:
    ans = "Yes"

print(ans)


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

#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define pb push_back
#define ar array

typedef long long ll;
typedef long double ld;
//using ll = long long;

typedef vector<int> vi;

const ld EPS = 1e-9, PI = acos(-1.);
const int INF = 0x3f3f3f3f, MOD = 1e9+7;

// global to problem

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	unordered_set<string> count;
	int n;
	cin >> n;
	string s;
	
	while(n--){
		cin >> s;
		count.insert(s);
	}
	cout << count.size() << endl;

}


Measured memory_bytes: 17716
#include<stdio.h>

char ss[1000100];

int main(){
	int n,m,i,j,c,flag,t;
	
	while(~scanf("%d",&n)){
		if(n==0)break;
		scanf("%d",&m);
		
		scanf(" %s ",ss);
		
		c=0;
		t=0;
		flag=0;
		
		for(i=0;i<m;i++){
			if(flag==0 && ss[i]=='I'){
				flag=(i+1)%2+1;
				t=i;
			}
//			printf("%d %d\n",i,t);
			if(flag==1 && i%2==0 && ss[i]=='O'){
				continue;
			}else if(flag==1 && i%2==1 && ss[i]=='I'){
				continue;
			}else if(flag==2 && i%2==0 && ss[i]=='I'){
				continue;
			}else if(flag==2 && i%2==1 && ss[i]=='O'){
				continue;
			}else if(flag!=0){
				if(i-t>2*n){
					if((i-t)%2==1)c+=(i-t-2*n+1)/2;
					else c+=(i-t-2*n)/2;
//					printf("%d\n",c);
				}
				if(ss[i]=='I'){
					flag=(i+1)%2+1;
					t=i;
					continue;
				}
				flag=0;
			}
		}
		
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define show(x) cout << #x << " : " << x << endl

int main ()
{
    int n, i = 1, cnt = 1;
    string s;
    cin >> n >> s;
    for(i = 1; i < s.size(); i++)
    {
        if(s[i] != s[i-1]) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
    int S,h,m,s;
    scanf("%d",&S);
    if(S>=0&&S<=86400){
            h=S/3600;
            S=S%3600;
            m=S/60;
            s=S%60;
            printf("%d:%d:%d\n",h,m,s);
    }
    else{

    }



}



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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll n, k;
	cin >> n >> k;

	if(k % 2 == 1){
		cout << (n / k) * (n / k) * (n / k) << endl;
	}else{
		ll a = n / k;
		ll b = n / (k / 2) - a;
		cout << (b * b * b + a * a * a) << endl;
	}
	
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * 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;
        inclass in = new inclass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ASubscribers solver = new ASubscribers();
        solver.solve(1, in, out);
        out.close();
    }

    static class ASubscribers {
        public void solve(int testNumber, inclass in, PrintWriter out) {
            int n = in.nextInt(), x = in.nextInt(), y = in.nextInt(), min = 0;
            if (x > y) {
                int temp = n;
                temp -= x;
                min = Math.max(0, y - temp);
            } else {
                int temp = n;
                temp -= y;
                min = Math.max(0, x - temp);
            }
            out.println(Math.min(x, y) + " " + min);
        }

    }

    static class inclass {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private inclass.SpaceCharFilter filter;

        public inclass(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21588
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>

using namespace std;

char s[15][15];

char Solution(int i, int j)
{
    if(s[i][j]=='1' && s[i + 1][j] == '1' && s[i][j + 1] == '1' && s[i + 1][j + 1] == '1')
    {
        return 'A';
    }
    
    if(s[i][j] == '1' && s[i + 1][j] == '1' && s[i + 2][j] == '1' && s[i + 3][j] == '1')
    {
        return 'B';
    }
    
    if(s[i][j] == '1' && s[i][j + 1] == '1' && s[i][j + 2] == '1' && s[i][j + 3] == '1')
    {
        return 'C';
    }
    
    if(s[i][j] == '1' && s[i][j + 1] == '1' && s[i + 1][j + 1] == '1' && s[i + 1][j + 2] == '1')
    {
        return 'E';
    }
    
    if(s[i][j] == '1' && s[i + 1][j] == '1' && s[i + 1][j + 1] == '1'&&s[i + 2][j + 1] == '1')
    {
        return 'F';
    }
    
    if(j > 0)  // can not start from j = 0
    {
        if(s[i][j] == '1' && s[i + 1][j] == '1' && s[i + 1][j - 1] == '1' && s[i + 2][j - 1] == '1')
        {
            return 'D';
        }
        
        if(s[i][j] == '1' && s[i + 1][j] == '1' && s[i + 1][j - 1] == '1' && s[i][j + 1] == '1')
        {
            return 'G';
        }
    }
    
    return 0;
}

int main()
{
    while(!cin.eof())  // tests for end-of-file
    {
        
        for(int i = 0; i < 15; i++)
        {
            for(int j = 0; j < 15; j++)
            {
                s[i][j] = '0';
            }
        }
        
        for(int i = 0; i < 8; i++)
        {
            cin>>s[i];
        }
        
        char figure;
        
        bool solved = true;
        
        for(int i=0;i<8;i++)
        {
            for(int j=0;j<8;j++)
            {
                if(s[i][j]!='1')
                {
                    continue;
                }
                
                if(solved)
                {
                    figure = Solution(i, j);
                    
                    cout<<figure<<endl;
                    
                    solved = false;
                }
            }
        }
    }
    return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;

ll dp[15][200050];

int main()
{
    int n,k; cin >> n >> k;
    vector<ll> l(k) , r(k);
    rep(i,n) cin >> l[i] >> r[i];
    ll MOD = 998244353;
    vector<ll > dp(n+1);
    vector<ll> sum(n+1);
    dp[1] = 1;
    sum[1] = 1;
    for(int i = 2; i <= n; i++){
        
        rep(j,k){
            // [l[i],r[i]]
            int li = i - r[j];
            int ri = i - l[j];
            if(ri < 0) continue;
            li = max(li,1);
            dp[i] += sum[ri] - sum[li-1];//dp[li]~dp[ri];
            dp[i] %= MOD;
        }
        sum[i] = sum[i-1]+dp[i];
        sum[i] %= MOD;
    }
    cout << (dp[n] % MOD + MOD) % MOD << endl;
}

Measured memory_bytes: 6344
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include<set>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
llfor;///////////////////////////////////////////////////////////
int main(){
 ll n;
 sc(n);
 ll ans=1000-n%1000;
 if(n%1000==0)ans=0;
 
 pr(ans);
return 0;}

Measured memory_bytes: 3620
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
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;}
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
// clang-format on

void solve(std::string S) {
  ll ans = 0;
  if (S == "SUN") {
    ans = 7;
  } else if (S == "MON") {
    ans = 6;
  } else if (S == "TUE") {
    ans = 5;
  } else if (S == "WED") {
    ans = 4;
  } else if (S == "THU") {
    ans = 3;
  } else if (S == "FRI") {
    ans = 2;
  } else if (S == "SAT") {
    ans = 1;
  }
  cout << ans << endl;
}

int main() {
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n, m;
    cin >> n >> m;

    vector< bool > a(n + 1, true);
    int temp;
    rep (i, m)
    {
        cin >> temp;
        a[temp] = false;
    }

    s64 dp[n + 1];
    dp[0] = 1;
    dp[1] = (a[1] ? 1 : 0);

    for (int i = 2; i <= n; ++i)
    {
        dp[i] = (a[i] ? dp[i - 1] + dp[i - 2] : 0);
        dp[i] %= MOD;
    }

    cout << dp[n] << "\n";
    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0) { return false; }
	}
	return true;
}

int ord(int n, int m) {
	if (m%n != 0) { return 0; }
	return ord(n, m / n) + 1;
}




int main() {

	int N;
	cin >> N;

	int div[100] = {};

	for (int i = 2; i <= N; i++) {
		if (prime(i)) {
			for (int j = 1; j <= N; j++) {
				div[i] += ord(i, j);	
			}
		}
	}

	
	
	int ans = 0;
	
	repn(i, N) {
		if (div[i] >= 74) { ans++; }
	}

	repn(i, N) {
		repn(j, N) {
			if (div[i] >= 24 && div[j] >= 2 && i != j) { ans++; }
			if (div[i] >= 14 && div[j] >= 4 && i != j) { ans++; }
		}
	}

	repn(i, N) {
		repn(j, N) {
			repn(k, N) {
				if (div[i] >= 2 && div[j] >= 4 && div[k] >= 4 && i != j && j < k && k != i) {
					ans++;
				}
			}
		}
	}

	cout << ans;

	
	

	system("PAUSE");
}

Measured memory_bytes: 504
#include<stdio.h>
int main(){
	int n;
	scanf("%d",&n);
    if(n>=64)printf("64");
    if(n>=32&&n<64)printf("32");
    if(n>=16&&n<32)printf("16");
    if(n>=8&&n<16)printf("8");
    if(n>=4&&n<8)printf("4");
    if(n>=2&&n<4)printf("2");
    if(n==1)printf("1");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<queue>
#include<map>

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double db;
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mp make_pair
#define case_for(n) for(int i = 1 ; i <= n ; i ++) { cout<<"Case "<<i<<": "<<endl; solve();}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll power(ll a, ll b, ll p) { ll ans = 1; while (b) { if (b & 1) ans = ans * a % p; a = a * a % p, b /= 2; }return ans; }
//int hw_check(string a, int l, int r) { int ans = r - l + 1; for (l, r; l < r; l++, r--)if (a[l] != a[r]) return 0; return ans; }
string movesubstr(string a, int l, int r) { string s = "";	for (int i = l; i <= r; i++) s.push_back(a[i]);	return s; }

const int N = 2e5 + 15;
int a[N], b[N], c[N];
map<int, int>bs;

ll solve(int i,int j)
{
	ll ans = 1;
	for (int k = 0; k < j; k++)  ans *= i;
	return ans;
}
	
/*
3 3
3 3 3
4 1 3
4 1 3
*/
int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(nullptr),cout.tie(0);

	/*int t; cin >> t;
	while (t--) 
	{
		solve();
	}*/
	int n; cin >> n;
	for (int i = -1000; i <= 1000; i++)
	{
		for (int j = -1000; j <= 1000; j++)
		{
			if (solve(i, 5) - solve(j, 5) == n)
			{
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
	return 0;
}
/*

*/

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

N = int(input())
F=[list(map(int,input().split())) for i in range(N)]
P=[list(map(int,input().split())) for i in range(N)]

#print(F)
#print(P)

ans = -float('inf')
jkopen =  [[0 for j in range(5)] for k in range(2)]
for openday in range(1,1024):
    for j in range(5):
        for k in range(2):
            jkopen[k][j] = (openday & 2**(5*k+j))//2**(5*k+j)
    benefit = 0
#    print(jkopen)
    for shop in range(N):
        counter = 0
        for j in range(5):
            for k in range(2):
                counter += (jkopen[k][j] & F[shop][k+2*j])
        benefit += P[shop][counter]
#    print(counter)
    ans = int(max(ans,benefit))
print(ans)
            
    
    
    
    
    

Measured memory_bytes: 3192
import  numpy as np

def kaku(h,m):
    PI = 3.14159265358979323846
    hum = h * 60 + m
    rad = hum / 360 * PI
    return rad

def yogen(a, b, kaku):
    tmp = pow(a, 2) + pow(b, 2) - 2 * a * b * np.cos(kaku)
    return np.sqrt(tmp)
    

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

hour_rad = kaku(h, m)
min_rad = kaku(0, m) * 12
rad = abs(min_rad - hour_rad)
ans = yogen(a, b, rad)
   

print(ans)

Measured memory_bytes: 27224
#include <bits/stdc++.h>
using namespace std;
constexpr char sheep= 'S';
constexpr char wolf = 'W';

struct Animal{
  char kind;
  Animal(char c): kind(c){}

  Animal flip() const{
    if(this->kind==sheep){
      return Animal(wolf);
    }
    else{
      return Animal(sheep);
    }
  }
};

int main(){
  const vector<pair<Animal, Animal>> search= {make_pair(Animal(sheep), Animal(sheep))
                                             ,make_pair(Animal(sheep), Animal(wolf) )
                                             ,make_pair(Animal(wolf) , Animal(sheep))
                                             ,make_pair(Animal(wolf) , Animal(wolf) ) };
  int N;
  string S;
  cin >> N >> S;

  auto guess= [&](string cand, int pivot){
    int opponent= (pivot==0) ? 1
                             : pivot- 1;
    char ret= (cand.at(pivot)==sheep) ? (S.at(pivot)=='o') ? Animal(cand.at(opponent)).kind
                                                           : Animal(cand.at(opponent)).flip().kind
                                      : (S.at(pivot)=='o') ? Animal(cand.at(opponent)).flip().kind
                                                           : Animal(cand.at(opponent)).kind       ;
    return ret;
  };

  string ans= "-1";
  for(auto [a0,a1]:search){
    string cand= string(N, 'X');
    cand.at(0)= a0.kind;
    cand.at(1)= a1.kind;
    char guess_back= guess(cand, 0);
    for(int pivot=1; pivot+1 < N; pivot++){
      cand.at(pivot+1)= guess(cand, pivot);
    }
    char guess_head= guess(cand, N-1);

    if(guess_back==cand.back() && guess_head==cand.at(0)){
      ans= cand;
      break;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3728
#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++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;



int main(void) {
  string s;
  cin >> s;
  int n = s.size();
  string p = s.substr(0,n/2);
  string q = s.substr(n/2+1,n/2);
  bool ok = true;
  rep(i,n)if(s[i]!=s[n-i-1])ok = false;
  rep(i,n/2)if(p[i]!=p[n/2-i-1])ok = false;
  rep(i,n/2)if(q[i]!=q[n/2-i-1])ok = false;
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}






Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int a,b,c;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    if(a == b + c || b == a + c || c == a + b){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}


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

int main(){
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    string ans;
    ans.push_back(s1[0]+'A'-'a');
    ans.push_back(s2[0]+'A'-'a');
    ans.push_back(s3[0]+'A'-'a');

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
R, C = map(int, input().split())
c = [list(input()) for _ in range(R)]
d = {}
q = [(0, 0, 0)]
d[0, 0] = 0
while q != []:
    (y, x, z) = q.pop(0)
    for v, w in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
        t = x + v
        u = y + w
        if t < 0 or t >= C or u < 0 or u >= R:
            continue
        if c[u][t] == '.' and (u, t) not in d:
            q.append((u, t, z + 1))
            d[u, t] = z + 1
if (R - 1, C - 1) not in d:
    ans = -1
else:
    ans = R * C - d[R - 1, C - 1] - 1
    for i in c:
        for j in i:
            if j == '#':
                ans -= 1
print(ans)

Measured memory_bytes: 40560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const ll inf=100100100100;
const int Inf=1001001001;
const int mod=1000000007;
int main(){
    int n;cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    int ans=1;
    int m=v[0];
    rep(i,n-1){
        if(v[i+1]>=m)ans++;
        chmax(m,v[i+1]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
row = list(map(int, input().split()))
row.sort()
a = row[2] - row[1]
row[0] += a
row[1] += a
count = a
if row[0] % 2 == row[1] % 2:
    count += (row[1]-row[0])/2
else:
    count += int((row[1]-row[0])/2) + 2
print(int(count))


Measured memory_bytes: 3060
import sys
n,m=map(int,input().split())
lrd=[list(map(int,input().split())) for i in range(m)]
x=["a"]*(n+1)
#iより右にいるデータ
R=[[] for i in range(n+1)]
L=[[] for i in range(n+1)]
for u in lrd:
    l,r,d=u
    R[l].append([r,d])
    L[r].append([l,d])
for i in range(1,n+1):
    if x[i]=="a":
        x[i]=0
        que=[i]
        while que:
            h=que.pop()
            for u in R[h]:
                r,d=u
                if x[r]=="a":
                    x[r]=x[h]+d
                    que.append(r)
                else:
                    if x[r]==x[h]+d:
                        continue
                    else:
                        print("No")
                        sys.exit()
            for u in L[h]:
                l,d=u
                if x[l]=="a":
                    x[l]=x[h]-d
                    que.append(l)
                else:
                    if x[l]==x[h]-d:
                        continue
                    else:
                        print("No")
                        sys.exit()
print("Yes")

Measured memory_bytes: 137688
using System;

namespace ITP1_2_C {
    class Program {
        static void Main(string[] args) {
            string[] A = Console.ReadLine().Split(' ');
            int[] B = new int[3];
            for(int i = 0; i < 3; i++) 
                B[i] = int.Parse(A[i]);
            Array.Sort(B);
            Console.WriteLine(B[0] + " " + B[1] + " " + B[2]);
        }
    }
}

Measured memory_bytes: 9268
s = input()
t = input()
lens = len(s)
lent = len(t)

check = 0
ansindex = []
for i in range(lens-lent+1):
  for j in range(lent):
    if not((s[i+j]==t[j]) or (s[i+j]=='?')):
      break
    if j ==lent -1:
      ansindex.append(i)
      check +=1
 
 
if check == 0:
  print('UNRESTORABLE')
  exit()
ans =s.replace('?','a')
ans = ans[:ansindex[-1]]+t+ans[ansindex[-1]+lent:]
print(ans)

Measured memory_bytes: 3064
def submit():
  from collections import deque
  import sys
  input = sys.stdin.readline
  n,q = map(int,input().split())
  y = [[] for _ in range(n)]
  c = [0]*n
  for _ in range(n-1):
    ai,bi = map(int,input().split())
    y[ai-1].append(bi-1)
    y[bi-1].append(ai-1)
  for _ in range(q):
    pi,xi = map(int,input().split())
    c[pi-1] += xi
  z = deque([[0,-1]])
  while z:
    j,b = z.popleft()
    for yj in y[j]:
      if yj != b:
        z.append([yj,j])
        c[yj] += c[j]
  for i in range(n):
    print(c[i],end=" ")
submit()

Measured memory_bytes: 104908
import numpy as np

def main():
	N, W = map(int, input().split())
	dp = np.full(N * 1000 + 1, 10 ** 10, dtype=np.int64)
	dp[0] = 0
	for _ in range(N):
		w, v = map(int, input().split())
		np.minimum(dp[:-v] + w, dp[v:], out=dp[v:])
	print(((dp <= W) * np.arange(N * 1000 + 1)).max())

if __name__ == "__main__":
	main()

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

using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
const int N = 1e5+5;

ll n , m , a[N] , ans;
map<ll,ll> cnt;

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

    cin >> n >> m;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
        a[i] %= m;
        a[i] += a[i-1];
        a[i] %= m;

        ans += cnt[a[i]];
        if (!a[i]) ans++;


        cnt[a[i]]++;
    }

    cout << ans << "\n";
//

    return 0;
}

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

int n;
long long d, x, y;

int main(){
	scanf("%d %lld", &n, &d);
	
	int c = 0;
	for(int i = 0; i < n; i++){
		scanf("%lld %lld", &x, &y);
		
		if(x * x + y * y <= d * d)c++;
	}
	printf("%d\n", c);
	
	return 0;
}


Measured memory_bytes: 3812
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

string s;

signed main() {
	cin >> s;
	for (int i = s.size() - 1; i >= 0; i--) {
		if (s.substr(i - 4, 5) == "dream")i -= 4;
		else if (s.substr(i - 4, 5) == "erase")i -= 4;
		else if (s.substr(i - 5, 6) == "eraser")i -= 5;
		else if (s.substr(i - 6, 7) == "dreamer")i -= 6;
		else {
			cout << "NO" << endl;
			ggr
		}
	}
	cout << "YES" << endl;
	ggr
}

Measured memory_bytes: 512
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
void solve()
{
   ll n,m,k,i;cin>>n>>m>>k;
   ll A[n],B[m];
   fo(i,0,n)cin>>A[i];
   fo(i,0,m)cin>>B[i];
   
   vector<ll>ps1(n+1,0),ps2(m+1,0);
   for(i=0;i<n;i++)ps1[i+1]=ps1[i]+A[i];
   for(i=0;i<m;i++)ps2[i+1]=ps2[i]+B[i];
   
   ll mx=0,sum=0,j;
   vector<ll>::iterator it;
   for(i=0;i<=n;i++)
   {
       
       sum=ps1[i];
       if(sum<=k)
       {
            it=upper_bound(all(ps2),k-sum);it--;
            j=(it-ps2.begin());
            mx=max(mx,i+j);
            //cout<<i<<" "<<j<<"\n";
       }
       else break;
   }
   

   for(i=0;i<=m;i++)
   {
       sum=ps2[i];
       if(sum<=k)
       {
            it=upper_bound(all(ps1),k-sum);it--;
            j=(it-ps1.begin());
             //cout<<i<<" "<<j<<"\n";
            mx=max(mx,i+j);
       }
       else break;
   }
   cout<<mx<<"\n";
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//If wrong on pretest 2 means logically wrong


/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

/* ll n,m,k,i;cin>>n>>m>>k;
   ll A[n],B[m];
   fo(i,0,n)cin>>A[i];
   fo(j,0,m)cin>>B[i];*/

Measured memory_bytes: 9528
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> a;
  int top = -1;
  int top2 = -1;
  int topi = -1;
  int top2i = -1;
  for (int i=0;i<n;i++) {
    int x;
    cin >> x;
    if (top == -1) { top = x; topi = i; }
    else if (top <= x) { top2 = top; top = x; top2i = topi; topi = i; }
    else if (top2 <= x) { top2 = x; top2i = i; }
    else if (top2 == -1) { top2 = x; top2i = i; }
  }
  for (int i=0;i<n;i++) {
    if (i == topi) { cout << top2 << endl; }
    else {cout << top << endl; }
  }
}



Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 (b<a) {a=b; return 1;} return 0;}

int main(){
    string s_prime, t;
    cin >> s_prime >> t;
    int n_s = s_prime.size();
    int n_t = t.size();
    vector<string> s;
    rep(i, n_s + 1 - n_t) {
        bool flag = true;
        rep(j, n_t) {
            if (s_prime[i+j] == '?') continue;
            if (t[j] != s_prime[i+j]) {
                flag = false;
                break;
            }
        }
        if (!flag) continue;
        string now_s = s_prime;
        rep(j, n_t) now_s[i+j] = t[j];
        rep(j, n_s) if (now_s[j] == '?') now_s[j] = 'a';
        s.emplace_back(now_s);
    }
    if (s.size() == 0) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    sort(s.begin(), s.end());
    cout << s[0] << endl;
}

Measured memory_bytes: 256