akhauriyash/Code-Regression huggingface dataset:
N=gets.to_i
g = Array.new(N){[]}
(N-1).times do
  a,b = gets.split.map(&:to_i)
  g[a-1] << b-1
  g[b-1] << a-1
end
c = gets.split.map(&:to_i)

set_pos = (0...N).to_a
set_pos.sort_by!{|i| g[i].size}
c.sort_by!{|x| -x}
ans = 0

d = Array.new(N) # 書き込むべき整数

used = Array.new(N)
start = set_pos[0]
q = []
q << start

d[start] = c.shift

while !q.empty?
  par = q.shift
  used[par] = true
  g[par].each do |child|
    if !used[child]
      cost = c.shift
      q << child
      ans += cost
      d[child] = cost
    end
  end
end

puts ans
puts d * ' '

Measured memory_bytes: 3488
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

ll gcd(ll a, ll b) {
    while (b) {
        ll c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int main() {
    ios::sync_with_stdio(false);
    int k, x;
    cin >> k >> x;
    if (k * 500 >= x) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 3560
from sys import stdin
N, W = [int(x) for x in stdin.readline().rstrip().split()]

baggage = [0]*N

for l in range(N):
    w, v = [int(x) for x in stdin.readline().rstrip().split()]
    baggage[l] = (w, v)

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for w in range(W+1):
        if w >= baggage[i][0]:
            dp[i+1][w] = max(baggage[i][1]+dp[i][w-baggage[i][0]],dp[i][w])

        else:
            dp[i+1][w] = dp[i][w]
print(dp[N][W])

Measured memory_bytes: 120044
import java.util.*;

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

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();

		int arr[] = new int[N];

		for(int n=0;n<N;n++){
			arr[n] = sc.nextInt();
		}
		Arrays.sort(arr);
		int min = -1;
		for(int n=0;n<N-K+1;n++){
			if(n==0) min = arr[K-1] - arr[0];
			else{
				if(min > arr[K-1+n] - arr[n]){
					min = arr[K-1+n] - arr[n];
				}
			}
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 50208
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,d;
    cin >> n >> d;
    int a = 2*d+1;
    if(n%a==0){
        cout << n/a;
    }
    else{
        cout << n/a+1;
    }
    


    return 0;
}

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

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

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

// Functions

// Main
fn main(){
    input!{
        N: usize,
        K: i64,
        _A: [i64; N],
    } 
    println!("{}",(N as i64 -2)/(K-1)+1);
}

Measured memory_bytes: 4352
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
    long long n;
    int k,i,l;
    scanf("%lld%d",&n,&k);
    l=k;
    for(i=0;;i++)
    {
        if(n<k) break;
        else k*=l;
    }
    cout<<(i+1)<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, m, x;
  cin >> n >> m >> x;
  vl c(n + 1, 0);
  rep(i, m) {
    ll a;
    cin >> a;
    c[a] = 1;
  }
  ll ans1 = 0, ans2 = 0;
  rep(i, x) ans1 += c[i];
  rep2(i, x, n) ans2 += c[i];
  cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll I,O,T,J,L,S,Z;
    cin>>I>>O>>T>>J>>L>>S>>Z;
    ll ans=O;

    if(I%2){
        if(L>0 and J>0 and I>0 and (L%2==1 or J%2==1)){
            ans+=3;
            L--;J--;
            I--;
        }
        ans+=2*(L/2);
        ans+=2*(J/2);
        ans+=2*(I/2);
        cout<<ans<<endl;
    }else{
        if(L>0 and J>0 and I>0 and L%2==1 and J%2==1){
            ans+=3;
            L--;J--;
            I--;
        }
        ans+=2*(I/2);
        ans+=2*(L/2);
        ans+=2*(J/2);
        cout<<ans<<endl;
    }
    return 0;
}



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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N;
int A[200010];

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

	cin >> N;
	rep(i, 0, N)
	{
		cin >> A[i];
		if (i > 0)A[i] += A[i - 1];
	}

	int ans = INF;
	rep(i, 0, N - 1)
	{
		chmin(ans, abs(A[i]-(A[N - 1] - A[i])));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
//
//  main.cpp
//  D - Line++
//
//  Created by 李远铄 on 2020/7/15.
//  Copyright © 2020 李远铄. All rights reserved.
//

#include <iostream>
#include <vector>
#define DEBUG
#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << "  "<<'\n';
#else
#define debug(x) ;
#endif

using namespace std;
int N;
int X,Y;
vector<int>ans;
int main(int argc, const char * argv[]) {
    scanf("%d %d %d",&N,&X,&Y);
    ans.resize(N);
    for (int i=0; i<N; i++) {
        ans[i]=0;
    }
    for (int i=1; i<=N; i++) {
        for (int j=i+1; j<=N; j++) {
            int len=abs(X-i)+1+abs(j-Y);
            ans[len<j-i?len:j-i]++;
        }
    }
    for (int i=1; i<N; i++) {
        printf("%d\n",ans[i]);
    }
    return 0;
}


Measured memory_bytes: 3256
#include <cstdio>
#include <iostream>
#include <sstream>

#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

//////////////////////////////////////////////////
struct modi64{
    i64 value, mod;
    modi64(i64 value_, i64 mod_):value(value_), mod(mod_){value = value % mod;};
    modi64(i64 mod_):value(0LL), mod(mod_){};
    
    modi64& operator= (i64 val){ value = val % mod; return *this;}
    modi64 operator+ (i64 val){ return modi64(value + val, mod);}
    modi64 operator- (i64 val){ return modi64(mod + value - val, mod);}
    modi64 operator* (i64 val){ return modi64(value * val, mod);}
    modi64& operator+= (i64 val){ value = (value + val) % mod; return *this;}
    modi64& operator-= (i64 val){ value = (mod + value - val) % mod; return *this;}
    modi64& operator*= (i64 val){ value = (value * val) % mod; return *this;}
    modi64 operator/ (i64 val){ return modi64(value * modi64(val, mod).pow(mod-2LL).value , mod);}
    modi64 operator/= (i64 val){ 
        value = (value * modi64(val, mod).pow(mod-2LL).value) % mod; 
        return *this;
    }
    modi64 pow(i64 r){
        modi64 ret(1LL, mod);
        modi64 a(value, mod);
        while(r){
            if(r&1LL)ret *= a;
            a *= a;
            r >>= 1;
        }
        return ret;
    }
    operator i64(){return value;}
    friend ostream& operator << (ostream& os, const modi64 &x){ os << x.value; return os;}
};


int main() { 
  const i64 MOD = 1e9+7LL;
  string s;
  cin >> s;
  vl dp(13);
  reverse(s.begin(), s.end());
  if(s[0] == '?'){
    for(int i=0;i<10;i++)dp[i] = 1;
  }
  else dp[s[0] - '0'] = 1;
  for(i64 i=1, f=10;i<s.length();i++){
    vl newdp(13);
    if(s[i] == '?'){
      for(int j=0;j<10;j++){
        for(int i=0;i<13;i++){
          newdp[(i + j * f % 13) % 13] += dp[i];
          newdp[(i + j * f % 13) % 13] %= MOD;
        }
      }
    }
    else{
      i64 k = s[i] - '0';
      for(int i=0;i<13;i++){
        newdp[(i + k * f % 13) % 13] += dp[i];
        newdp[(i + k * f % 13) % 13] %= MOD;
      }
    }
    dp = newdp;
    f = f * 10 % 13;
    // for(auto&& x:dp)cerr << x << " ";
    // cerr << endl;
  }
  cout << dp[5] << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>

int main()
{
    using namespace std;
    
    long int a, b, x;
    cin >> a >> b >> x;

    auto solver = [](long a, long b, long x) -> long {
        return b/x - (a-1)/((a==0)? 1 : x);
    };

    cout << solver(a,b,x) << endl;
    return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <cstdio>
using namespace std;
long long n, x;
inline long long solve (long long a, long long b) {
	if (a == b) return a;
	if (a < b) {
		if (b % a == 0) return (2 * (b / a) - 1) * a;
		long long t = b / a;
		return 2 * a * t + solve (a, b % a);
	} else {
		if (a % b == 0) return (2 * (a / b) - 1) * b;
		long long t = a / b;
		return 2 * b * t + solve (a % b, b);
	}
}
int main () {
	scanf ("%lld%lld", &n, &x);
	printf ("%lld\n", n + solve (x, n - x));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define fip ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define reptUsual(b) for(i=0; i<b; ++i)
#define reptArIn(i,a,b,ar) for( i=a; i<b; ++i) cin>>ar[i];
#define rept(i,a,b) for(i=a; i<b; ++i)
#define maX(a,b)    ( (a) > (b) ? (a) : (b))
#define miN(a,b)    ( (a) < (b) ? (a) : (b))
#define pb(a) push_back(a)
#define bigPrime 1000000007
#define $ %1000000007
using namespace std;


int main()
{
    fip;
    multimap <ll ,ll> mp;
    ll n,i,sum=0,a,b;
    cin>>n;
    reptUsual(n)
    {
        cin>>a>>b;
        mp.insert(pair<ll,ll>(b,a));
    }

    multimap <ll ,ll>  :: iterator it;
    /*
    for(it=mp.begin() ; it!=mp.end();it++)
    {
        b=it->first;
        a=it->second;
        sum+=b;
        cout<<b<<" "<<a<<" "<<sum<<"\n";
    }
    sum=0;
    */
    for(it=mp.begin() ; it!=mp.end();it++)
    {
        b=it->first;
        a=it->second;
        sum+=a;
        //cout<<b<<" "<<a<<" "<<sum<<"\n";
        if(sum>b)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";

    return 0;
}

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

int main(){
	int h,w;
	cin >> h >> w;
	vector<vector<int>> mp(h,vector<int>(w));
	int a;
	rep(i,h){
		rep(j,w){
			cin >> a;
			mp[i][j] = a%2;
		}
	}
	vector<vector<int>> ans;
	rep(i,h){
		rep(j,w-1){
			if(mp[i][j] == 1){
				mp[i][j] = 0;
				mp[i][j+1] =  (mp[i][j+1]+1)%2;
				vector<int> v = {i,j,i,j+1};
				ans.push_back(v);
			}
		}
	}
	rep(i,h-1){
		if(mp[i][w-1] == 1){
			mp[i][w-1] = 0;
			mp[i+1][w-1] =  (mp[i+1][w-1]+1)%2;
			vector<int> v = {i,w-1,i+1,w-1};
			ans.push_back(v);
		}
	}
	cout << ans.size() << endl;
	rep(i,ans.size()){
		rep(j,4){
			if(j > 0) cout << ' ';
			cout << ans[i][j]+1;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 10032
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007 //1000000000000000003
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

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

  cout<< a+b+c-max({a,b,c})<<"\n";
}


//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cassert>
using namespace std;

template <int64_t M>
class mint {
public:
        mint() :v(-1) {}
        mint(int n) : v(n % M) {}

        int64_t get() const { return v; }

        mint &operator+=(const mint &r) {
                v = (v + r.v) % M;
                return *this;
        }
        mint &operator-=(const mint &r) {
                v = (v - r.v + M) % M;
                return *this;
        }
        mint &operator*=(const mint &r) {
                v = (v * r.v) % M;
                return *this;
        }
        mint &operator/=(const mint &r) {
                return (*this) *= r.inv();
        }

        mint pow(int r) const {
                mint k = *this, ret = 1;
                while (r > 0) {
                        if (r % 2 != 0) ret *= k;
                        r /= 2;
                        k *= k;
                }
                return ret;
        }

        mint inv() const {
                return pow(M - 2);
        }

private:
        int64_t v;
};

template <int64_t M>
inline mint<M> operator+(mint<M> l, const mint<M> &r) {
        return l += r;
}

template <int64_t M>
inline mint<M> operator-(mint<M> l, const mint<M> &r) {
        return l -= r;
}

template <int64_t M>
inline mint<M> operator*(mint<M> l, const mint<M> &r) {
        return l *= r;
}

template <int64_t M>
inline mint<M> operator/(mint<M> l, const mint<M> &r) {
        return l /= r;
}

template <int64_t M>
inline ostream &operator<<(ostream &os, const mint<M> &r) {
        return os << r.get();
}

typedef mint<1000000007> MINT;

MINT fact(int n)
{
    MINT ret = 1;
    for (int i = 1; i <= n; i++) ret *= i;
    return ret;
}

MINT comb(int a, int b)
{
    // cout << "COMB " << a << ", " << b << " = " << (fact(a) / (fact(b) * fact(a - b))) << endl;
    return fact(a) / (fact(b) * fact(a - b));
}

int main()
{
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    h--, w--;

    if (!(h-a <= w-b)) {
        swap(h, w);
        swap(a, b);
    }

    assert(h-a <= w-b);

    MINT ans(0);
    MINT c1(1), c2(1);

    // cout << "** " << w-b+a << ", " << h << endl;

    c2 = comb(w-b+a, h);

    for (int i = 0; i <= h-a; i++) {
        // cout << i << ": " << c1 << ", " << c2 << endl;

        // comb(h-a+b, i) * comb(w-b+a, h - i);
        ans += c1 * c2;

        if (i > 0) c1 /= MINT(i+1);
        c1 *= MINT(h-a+b - i);

        c2 *= MINT(h-i);
        c2 /= MINT(w-b+a - (h-i-1));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
al = sorted(map(int, input().split()))

r = 0
for i in range(n-2):
  for j in range(i+1, n):
    for k in range(j+1, n):
      if al[k] < al[j] + al[i]:
        if al[k] != al[j] and al[k] != al[i] and al[i] != al[j]:
          r += 1
print(r)

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

int main(){
  int t,r=0,b=0;
  cin>>t;
  char s[t];
  for(int i=0;i<t;i++){
     cin>>s[i];
     if(s[i]=='R'){
        r++;}
     else{
        b++;}
  }
  if(r>b)
    cout<<"Yes"<<endl;

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


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int Num, n;
  int flag=0;
  
  scanf("%d", &Num);
  
  int seisuu[Num]; 
  
  for(n=0;n<Num;n++)
  {
    scanf("%d",&seisuu[n]);
    if (seisuu[n]%2==0)
      if (seisuu[n]%3!=0&&seisuu[n]%5!=0)
        flag=1;
  }
  if (flag==0)
    printf("APPROVED");
  else
    printf("DENIED");
  
  return 0;
}


Measured memory_bytes: 128
import math
import bisect
from queue import Queue
from collections import deque

n, k= [int(i) for i in input().split()]

count = []
for i in range(n+1):
    count.append(0)

for i in range(k):
    d = int(input())
    a = [int(i) for i in input().split()]
    for j in a:
        count[j] = 1

print(n-sum(count))


Measured memory_bytes: 9704
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;
int n,m,q,a[11],ans=0;
struct node{
    int a,b,c,d;
}e[55];
void dfs(int pos,int cnt){
    a[cnt]=pos;
    if(cnt==n){
        int sum=0;
        for(int i=1;i<=q;i++){
            if(a[e[i].b]-a[e[i].a]==e[i].c){
                sum+=e[i].d;
            }
        }
        //printf("%d %d\n",sum,ans);
        ans=max(ans,sum);
        return ;
    }
    for(int i=pos;i<=m;i++){
        dfs(i,cnt+1);
    }
}
int main(){
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=q;i++){
        scanf("%d%d%d%d",&e[i].a,&e[i].b,&e[i].c,&e[i].d);
    }
    for(int i=1;i<=m;i++){
        dfs(i,1);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1732
N, M = map(int, input().split())
A = set(map(int, input().split()))

INF= 10 ** 9
d_t = {
    1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6
}


# 使う候補の数字を選ぶ
# A1, ..., AMのうち、本数が同じものは大きな方だけを採用する
d = dict()
for a in A:
    d[a] = d_t[a]

if 2 in A and (3 in A or 5 in A):
    d.pop(2)

if 3 in A and 5 in A:
    d.pop(3)

if 6 in A and 9 in A:
    d.pop(6)


# N本で何桁作れるか求める
# dp[n]: n本で作れる最大の桁数
# dp[n]は dp[n-k] + 1 で作ることができる(dp[n-k]>0のときのみ、どのkが最適かは分からない)
dp = [-INF] * (N + 1)
dp[0] = 0
for i in range(1, N+1):
    for m in d.values():
        if i-m >=0 and dp[i-m] >= 0:
            dp[i] = max(dp[i], dp[i-m] + 1) 


# 最大の数値を求める
# 大きい桁から考える
# dp[n] = dp[n-k] + 1 なら、本数kの数値を残りの桁の最大桁として使える
desc_d = sorted(d.items(), key = lambda x: x[0], reverse=True)
s = ''
r = N
for i in range(dp[N]):
    for k, v in desc_d:
        # 残りの本数が足りるか
        if r < v:
            continue

        # この数値を使うことができるか
        if dp[r] == dp[r-v] + 1:
            s += str(k)
            r -= v
            break

print(s)


Measured memory_bytes: 3364
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
 //freopen("input.txt", "r", stdin); 
 //freopen("output.txt", "w", stdout); 
int n,m,k,A[200000],B[200000];
long long a[200001],b[200001];
cin>>n>>m>>k;
for(int i=0;i<n;i++)
{
    cin>>A[i];
}
for(int i=0;i<m;i++){
    cin>>B[i];

}
a[0]=b[0]=0;
for(int i=1;i<=n;i++)
{
    a[i] = a[i-1] + A[i-1];
}

for(int i=1;i<=m;i++)
{
    b[i] = b[i-1] + B[i-1];
}
int jbest = m,max = -1;
for(int i=0;(i<=n && a[i]<=k);i++)
{
    
    for(int j=jbest;j>-1;j--)
    {
        if((a[i]+b[j]) <= k)
         {
             jbest = j;
             if((i+j) > max)
              max = i+j;
             break;
         }
    }
}

cout<<max<<endl;
return 0;
}

Measured memory_bytes: 8324
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int A, B, X;
    cin >> A >> B >> X;
    if (X < A || A + B < X) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,k;
  cin >> n >> k;
  cout << (n-1+k-1-1)/(k-1) << endl;
}

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<int,int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define error(x) cerr << #x << " = " << x << endl
#define sz(x) (int)(x).size()
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int INF = 1e9 + 7;

int n, m;
vector<pii> stu, che;

int dist(pii p, pii q) {
    return abs(p.f - q.f) + abs(p.s - q.s);
}

int main(void) {
    ios_base::sync_with_stdio(0), cin.tie(nullptr);
    cin >> n >> m;
    int x, y;
    for (int i = 0; i < n; ++i) {
        cin >> x >> y;
        stu.eb(x,y);
    }
    for (int i = 0; i < m; ++i) {
        cin >> x >> y;
        che.eb(x,y);
    }
    for (auto p : stu) {
        int res = 0;
        for (int i = 0; i < m; ++i) {
            if (dist(p, che[i]) < dist(p, che[res]))
                res = i;
        }
        cout << res+1 << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

typedef long long ll;

int n = 0;

int main(){
    cin >> n;
    vector<int> x;
    int res = 0, number = 0;
    for(int i = 0; i < n; ++i){
        cin >> number;
        x.push_back(number);
        res+=number;
    }
    ll ans = 0, k = 0;
    ll ans1 = 0, ans2 = 0, finalans = 1000000;
    res = res / n;
    ll res1 = res;
    ++res1;
    ll t = 0;
    for(int i = 0; i < n; ++i){
        k = x[i] - res;
        t = pow(k, 2);
        ans+=t;
    }
    for(int i = 0; i < n; ++i){
        k = x[i] - res1;
        t = pow(k, 2);
        ans1+=t;
    }
    finalans = min(ans,finalans);
    finalans = min(ans1,finalans);
    cout << finalans << endl;
    
    
    return 0;
}

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

int main(){
	int a[11];
	int n,x,ans=0;
	memset(a,0,sizeof(a));
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		if(x>=1&&x<=399) a[1]++;
		else if(x>=400&&x<=799) a[2]++;
		else if(x>=800&&x<=1199) a[3]++;
		else if(x>=1200&&x<=1599) a[4]++;
		else if(x>=1600&&x<=1999) a[5]++;
		else if(x>=2000&&x<=2399) a[6]++;
		else if(x>=2400&&x<=2799) a[7]++;
		else if(x>=2800&&x<=3199) a[8]++;
		else if(x>=3200) a[9]++;
	}
	int res=0;
	
	for(int i=1;i<=8;i++){
		if(a[i]>0) ans++;
	}
	
	int temp=a[9];
	res=ans+temp;
	
	
	if(ans==0&&temp!=0) ans=1;
	
	cout<<ans<<" "<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
//package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args)throws Exception{
        FastReader scan=new FastReader(System.in);
        int t=1;
//        t=scan.nextInt();
        while(t-->0){
            int h=scan.nextInt();
            int w=scan.nextInt();
            int k=scan.nextInt();
            String[] mat=new String[h];
            for(int i=0;i<h;i++){
                mat[i]=scan.next();
            }
            out.println(recur(0,new HashSet<>(),mat,h,w,k));
        }
        out.flush();
        out.close();
    }
    static int recur(int in,Set<Integer> s,String[] mat,int h,int w,int k){
        if(in==h+w){
            int bc=0;
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    if(mat[i].charAt(j)=='#'){
                        if(!s.contains(i)&&!s.contains(h+j)){
                            bc++;
                        }
                    }
                }
            }
            if(bc==k){
                return 1;
            }
            return 0;
        }
        int ans=0;
        s.add(in);
        ans+=recur(in+1,s,mat,h,w,k);
        s.remove(in);
        ans+=recur(in+1,s,mat,h,w,k);
        return ans;
    }
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }
}


Measured memory_bytes: 36600
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
constexpr int INF = (numeric_limits<int>::max() == INT_MAX ? (int)1e9 : (long long)1e18);
constexpr long double eps = 1e-6;
const string el = "\n";
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;using pii = pair<int,int>;using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
void fast_io(){ios::sync_with_stdio(false); cin.tie(nullptr);}
int out(int a){cout << a << el; return 0;}
int out(string s = "NO"){cout << s << el; return 0;}
template <class T>
inline int out(vector<T>&v,string c = " "){
    for(int i = 0; i < v.size(); ++i){
        if(i) cout << c; cout << v[i];
    } cout << el;return 0;
}

int counter = 0;
int gcd(int a, int b) {
    if (b == 0) return a;
    counter++;
    return gcd(b, a%b);
}
signed main(){
    fast_io();
    string s; cin >> s;
    int g = 0, p = 0;
    for(auto& c : s)
        (c == 'g' ? g : p)++;
    cout << max(0LL,(g - p)/2) << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

string S;

map<int, int> SS;

int ctoi(char c) {
  int cnt = c - 'a';
  return (1 << cnt);
}

int main () {
  cin >> S;
  int N = S.size();
  int cnt[26];
  fill(cnt, cnt+26, 0);
  for (auto x : S) {
    cnt[x - 'a']++;
  }
  bool ok = true;
  for (auto i = 0; i < 26; ++i) {
    if (cnt[i] % 2  != 0) ok = false;
  }
  if (ok) {
    cout << 1 << endl;
    return 0;
  }
  int dp[200010];
  dp[0] = 0;
  int now = 0;
  SS[now] = 0;
  for (auto i = 1; i <= N; ++i) {
    now = now ^ ctoi(S[i-1]);
    dp[i] = dp[i-1] + 1;
    if (SS.find(now) != SS.end()) {
      dp[i] = min(dp[i], SS[now] + 1);
    }
    for (auto j = 0; j < 26; ++j) {
      int twd = now ^ (1 << j);
      if (SS.find(twd) != SS.end()) {
        dp[i] = min(dp[i], SS[twd] + 1);
      }
    }
    if (SS.find(now) != SS.end()) {
      SS[now] = min(SS[now], dp[i]);
    } else {
      SS[now] = dp[i];
    }
  }
  /*
  for (auto i = 0; i <= N; ++i) {
    cerr << "dp[" << i << "] = " << dp[i] << endl;
  }
  */
  cout << dp[N] << endl;
}


Measured memory_bytes: 10628
#include <bits/stdc++.h>
using namespace std;
int power_2(int x) {
  int ans = 1;
  for(int i = 0; i < x; i++) {
    ans *= 2;
  }
  return ans;
}
int main() {
  int N;
  cin >> N;
  vector<long double> vec(N);
  for(int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  long double ans = 0;
  cout << setprecision(10);
  for(int i = 0; i < N; i++) {
    ans += vec.at(i);
    if(i != 0) {
      ans /= 2;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3808
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main(){
  string s;
  cin>>s;
  ll n=sz(s);
  ll cu=0;
  rep(i,n-1){
    if(s[i]!=s[i+1]){
      cu++;
    }
  }
  COUT(cu);
}

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

    #define ll long long
    #define ff first
    #define ss second
    #define pb push_back
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define MOD 1000000007
    #define pll pair<ll,ll>
constexpr ll INF = 1999999999999999997; 
    #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
    int main() {
        fastio;

        ll n,m,k;
        cin>>n>>m>>k;
        ll a[n+1],b[m+1];
        a[0]=0;
        b[0]=0;
        for(int i=1;i<=n;i++)
           {  
             cin>>a[i];
             if(i!=0)
                a[i]+=a[i-1];
            }

         for(int i=1;i<=m;i++)
            {
                cin>>b[i];
                if(i!=0)
                    b[i]+=b[i-1];
            }

         int ans=0;
         for(int i=0;i<=n;i++)
         {
            if(a[i]>k)
                break;
            ll ch=k-a[i];
            int j=prev(upper_bound(b,b+m+1,ch))-b;
            ans=max(ans,(i+j));

         }
        
        cout<<ans<<endl;

    }

Measured memory_bytes: 6644
#include <iostream>
#include <map>

using namespace std;

int main() {
  for (;;) {
    int A;
    cin >> A;
    if (!A) return 0;
    map<int, int> cs;
    for (int i = 0; i < A; i++) {
      int c;
      cin >> c;
      cs[c]++;
    }
    bool f = false;
    for (map<int, int>::iterator it = cs.begin(); it != cs.end(); ++it)
      if (2*it->second > A) {
        cout << it->first << endl;
        f = true;
        break;
      }
    if (!f)
      cout << "NO COLOR" << endl;
  }
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n,k; cin>>n>>k;
    cout << min(n%k,abs(n%k-k)) << endl;
    return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

    ll num;

    cin >> num;

    ll sum = 0;

    if(num >= 500)
    {
        ll rem = num / 500;

        num = num % 500;

        rem = rem * 1000;

        sum += rem;

        num = num / 5;

        ll rem1 = num * 5;

        sum += rem1;

        cout << sum;


    }

    else
    {
        ll rem = num / 5;

        rem = rem * 5;

        sum += rem;

        cout << sum;
    }



}


Measured memory_bytes: 3600
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
 
using namespace std;
 

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 
ll binomialCoeff(ll n, ll k) 
{ 
    ll C[n + 1][k + 1]; 
    ll i, j; 


    for (i = 0; i <= n; i++) 
    { 
        for (j = 0; j <= min(i, k); j++) 
        { 
            
            if (j == 0 || j == i) 
                C[i][j] = 1; 

            else
                C[i][j] = (C[i - 1][j - 1] + 
                                        C[i - 1][j])%MOD; 
        } 
    } 

    return C[n][k]; 
}
bool compare(const pair<int,int> &a , const pair<int,int>&b){
    //set<pair<int,int> , decltype(&compare)>s(&compare) ;
    if(a.fi!=b.fi)return a.se<b.se ;
    return a.fi<b.fi;
}

// struct compare{
//     // for priority_queue
//     bool operator()(const int &a , const int&b){
//         return a<b ;
//     }
// };

void solve()
{
    int n , m ;
    cin>>n>>m;
    vector<int>L(m) , R(m) ;
    rep(i , m){
        cin>>L[i]>>R[i] ;
    }
    int mal = INT_MIN ;
    int mir = INT_MAX ;
    rep(i , m){
        mal = max(L[i] , mal) ;
        mir = min(mir , R[i]) ;
    }
    int ans= 0 ;
    repu(i , 1 , n){
        if(mal<=i && mir>=i){
            ans++;
        }
    }
    cout<<ans<<endl;
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  
  for (int i = 0; i < h; i++) {
    cin >> a.at(i);
  }

  for (int i = 0; i < h + 2; i++) {
    if (i == 0) {
      for (int j = 0; j < w + 2; j++) cout << '#';
    }
    else if (i > 0  && i < h + 1) {
      cout << '#' << a.at(i-1) << '#';
    }
    else if (i == h + 1) {
      for (int j = 0; j < w + 2; j++) cout << '#';
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
Int LSB(Int x) { return x & -x; }
struct Tree {
    Tree(Int h) {
        height = h;
        grundy = 0;
        p[0] = p[1] = nullptr;
    }
    void insert(const string &str, int idx) {
        if (idx >= str.size()) return;
        int t = str[idx] - '0';
        if (p[t] == nullptr) {
            p[t] = new Tree(height - 1);
        }
        p[t]->insert(str, idx + 1);
        grundy = 0;
        for (int i = 0; i < 2; i++) {
            grundy ^= (p[i] ? p[i]->grundy : LSB(height));
        }
    }
    Int height, grundy;
    Tree *p[2];
};
int main() {
    Int N, L; cin >> N >> L;
    Tree root(L);
    for (int i = 0; i < N; i++) {
        string s; cin >> s;
        root.insert(s, 0);
    }
    cout << (root.grundy ? "Alice" : "Bob") << '\n';
    return 0;
}


Measured memory_bytes: 6608
#include <iostream>
#include <string>

using namespace std;

int main(void){
	string A,B;
	cin >> A;
	cin >> B;
	int flag = 0;
	if(A.size() != B.size()) flag = 1;
	int s = A.size();
	int n,i;
	int flg[s] = {0};
	if(flag == 0){
		for(n=0;n<s;n++){
			for(i=0;i<s;i++){
				if(A[i] != B[(i+n)%s]) flg[n] = 1; 
			}
		}
	}
	int count = 0;
	for(i=0;i<s;i++){
		if(flg[i] == 1) count++;
	}
	if(count != s && flag == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] s = in.readLine().split("/");
    System.out.println("2018/" + s[1] + "/" + s[2]);
  }
}

Measured memory_bytes: 36788
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
ans=0
for i in range(n):
    ans+=min(a[i],b[i])
    b[i]-=min(a[i],b[i])
    ans+=min(a[i+1],b[i])
    a[i+1]-=min(a[i+1],b[i])
print(ans)

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

int main(){
long long n;
  cin>>n;
  long long ans,a;
  ans=1;
  bool ng=false;
  bool end=false;
  for(int i=0;i<n;i++){
cin>> a;
    if(a==0){
cout<<"0"<<endl;
      end=true;
      break;
    }
    if(1000000000000000000/a<ans){
      ng=true;
    }
   else if(ng==false){
ans*=a;
   }
  }
  if(end==false&&ng){
cout<<"-1"<<endl;
  }
  else if(ng==false){
cout<<ans<<endl;
  }
}
  
      


Measured memory_bytes: 3596
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    a,b,c = MI()
    d = a%b
    res = d
    for i in range(b**2):
        if c == res:
            print("YES")
            exit()
        res+=d
        res%=b
    print("NO")
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3572
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int X = 100010;
	int N, M; cin >> N >> M;
	vector<int> a(M), b(M); rep(i, 0, M) { cin >> a[i] >> b[i]; }
	vector<int>cnt(X, 0);
	rep(i, 0, M) {
		cnt[a[i]]++;
		cnt[b[i]]++;
	}
	bool f(true);
	rep(i, 0, X)if (cnt[i] & 1)f = false;
	cout << (f ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 1408
n=int(input())
a=[]
for i in range(n):
  s=list(input())
  a.append("".join(sorted(s)))
a.sort()

ans=0
d=1
for i in range(n-1):
  if a[i]==a[i+1]:
    d+=1
  else:
    ans+=(d*(d-1))//2
    d=1
ans+=(d*(d-1))//2
print(ans)

Measured memory_bytes: 59004
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>

using namespace std;
int main() {

    int a[3] = {0};
    int b[3] = {0};
    int c[3][3];
    int i,j,k,l,counter;
    

    for(i = 0; i < 3; i++){
        cin >> c[i][0] >> c[i][1] >> c[i][2];
    }

    

    for(i = 0; i <= 100; i++){
        a[0] = i;
        if(a[0] > c[0][0]){
            break;
        }
        for(j = 0; j <= 100; j++){
            counter = 0;
            b[0] = j;
            if(a[0] + b[0] > c[0][0]){
                break;
            }

            b[1] = c[0][1] - a[0];
            b[2] = c[0][2] - a[0];
            a[1] = c[1][0] - b[0];
            a[2] = c[2][0] - b[0];
			//cout << a[0] << a[1] << a[2]<< b[0] << b[1] << b[2] << endl;
            for(k = 0; k < 3;k++){
                for(l = 0; l < 3;l++){
                    if(a[k] + b[l] == c[k][l]){
                        counter++;
                    }
                }
            }

            if(counter == 9){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
  


    cout << "No" <<endl;



    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define int long long

string S;
int X, Y;
bool dp[2][200001];

signed main() {
	vector<int> v;
	cin >> S >> X >> Y;
	S += 'T';
	reverse(S.begin(), S.end());
	v.push_back(0);
	while (!S.empty()) {
		if (S.back() == 'F') v.back()++;
		else v.push_back(0);
		S.pop_back();
	}
	X -= v.front();
	v.erase(v.begin());
	vector<int> v1, v2;
	for (int i = 0; i < v.size(); i += 2) v1.push_back(v[i]);
	for (int i = 1; i < v.size(); i += 2) v2.push_back(v[i]);
	auto f = [&](int x, const vector<int> &w) {
		const int O = 100000;
		for (int i = -90000; i <= 90000; i++) dp[0][O + i] = dp[1][O + i] = false;
		dp[0][O + 0] = true;
		for (int i = 0; i < w.size(); i++) {
			for (int j = -90000; j <= 90000; j++) {
				if (!dp[i&1][O + j]) continue;
				dp[(i + 1)&1][O + j + w[i]] = true;
				dp[(i + 1)&1][O + j - w[i]] = true;
			}
			for (int j = -90000; j <= 90000; j++) {
				dp[i&1][O + j] = false;
			}
		}
		return dp[w.size()&1][O + x];
	};
	if (f(Y, v1) && f(X, v2)) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 768
def merge(a,b)
  r=[]
  i=0
  a.each do |x|
    i += 1 until i==b.size || x<=b[i]
    return r if i==b.size
    next unless x==b[i]
    r << x
    i += 1
  end
  r
end

S=gets.to_i.times.map{gets.chop.chars.sort}
s=S[0]
S.each{|x|s=merge(s,x)}
puts s ? s*"" : ""


Measured memory_bytes: 1788
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int v[n], c[n];
    int result = 0;
    for (int i=0; i<n; i++) {
        cin >> v[i];
    }
    for (int i=0; i<n; i++) {
        cin >> c[i];
        result += max(v[i]-c[i], 0);
    }
    cout << result << endl;
}

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

#define MAX_N 100
#define MAX_W 10000

int N, W;
int v[MAX_N];
int w[MAX_N];
int m[MAX_N];

int dp[MAX_W + 1];

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

	for( int i = 0; i < N; i++ ) {
		int cnt = 0;
		int mul = 1;
		int end = 0;
		while( 1 ) {
			int ww = mul * w[i];
			int vv = mul * v[i];
			for( int j = W; j >= ww; j-- ) {
				dp[j] = max( dp[j], dp[j - ww] + vv );
			}
			if( end ) {
				break;
			}
			cnt += mul;
			if( cnt == m[i] ) {
				break;
			}
			mul *= 2;
			if( mul + cnt >= m[i] ) {
				mul = m[i] - cnt;
				end = 1;
			}
		}
	}
	int ans = dp[W];

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3172