akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define NIL -1

typedef struct{
  int parent,left,right;
}Node;

Node tree[100001];
int count=0; //再帰関数、子供表示用

int retdepth(int id){ //再帰で根っこまでの長さを計る
  if (tree[id].parent==NIL){
    return count;
  } else {
    count++;
    return retdepth(tree[id].parent);
  }
}


void dispdegree(int id){
  if (id!=NIL){
    if (count!=0){
      printf(", ");
    }
    printf("%d",id);
    count++;
    dispdegree(tree[id].right);
  }
}

int main(){
  int i,j,n,nownode,deg,gaki,left,right;

  scanf("%d",&n);
  for (i=0;i<n;i++){
    tree[i].parent=tree[i].left=tree[i].right=NIL;
    //NILで初期化を行う
  }

  for (i=0; i<n; i++){
    scanf("%d%d",&nownode,&deg);
    for (j=0; j<deg; j++){
      scanf("%d",&gaki);
      tree[gaki].parent=nownode;
      if (j!=0){ //左端ならnownodeのleftを子供に
	tree[left].right = gaki;
      } else {
	tree[nownode].left = gaki;
      }
      left = gaki;
    }
      /*                           |
		       親          |
		     | | |       ->|  親1->2->3 のイメージ 横並ばせで
		    1  2  3        |
		    
        親のleftは1,1のrightは2,2のrightは3,3のrightはNIL。
      */
  }
  //---------------------
  //表示部分

  for(i=0; i<n; i++){
    count=0;
    printf("node %d: parent = %d, depth = %d, ",i,tree[i].parent,retdepth(i));
    if(tree[i].parent == NIL){
      printf("root, [");
    } else if(tree[i].left == NIL){
      printf("leaf, [");
    } else {
      printf("internal node, [");
    }
    count=0;
    dispdegree(tree[i].left);
    printf("]\n");
  }

  return 0;
}

Measured memory_bytes: 1784
/* C */

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	int n;
	cin >> n;
	std::vector<int> v(n);
	std::vector<int> lis(100010, 0);

	for (int i = 0; i < n; ++i)
	{
		cin >> v[i];
	}

	for (int i = 0; i < n; ++i)
	{
		lis[v[i]]++;
	}

	int sum = 0;
	int cnt = 0;

	for(int i = 0; sum <= n/2; i++){
		sum += lis[i];
		if(sum == n / 2) cnt++;
	}

	cout << cnt << endl;

}

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

int main()
{
    int a, b, c;
    bool ans = false;
    std::cin >> a >> b >> c;
    for (int i = 1; i <= b; ++i) {
        if ((a * i) % b == c) {
            ans = true;
        }
    }
    if (ans) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		sc.close();

		if(S.length() % 2 == 1){
			S = S.substring(0, S.length() - 1);
		}
		else{
			S = S.substring(0, S.length() - 2);
		}

		for(; S.length() > 0; S = S.substring(0, S.length() - 2)){
			if(isEvenString(S)){
				break;
			}
		}
		System.out.println(S.length());
	}

	//長さが偶数の文字列sが遇文字列かどうかを返す
	static boolean isEvenString(String s){
		String a = s.substring(0, s.length()/2);
		String b = s.substring(s.length()/2);
		if(a.equals(b)){
			return true;
		}
		else{
			return false;
		}
	}

}


Measured memory_bytes: 21716
#include <iostream>

using namespace std;

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

  int r=0, b=0;
  for (int i=0; i<N; i++) {
    if (s[i] == 'R') r++;
    else b++;
  }

  cout << (r > b ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);

		int n = Integer.valueOf(stdin.nextLine());
		List<List<Integer>> action = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			
			action.add(Arrays.stream(stdin.nextLine().split(" ", 3)).map(Integer::valueOf)
					.collect(Collectors.toList()));
		}

		int[][] dp = new int[n][3];
		for (int i = 0; i < 3; i++) {
			dp[0][i] = action.get(0).get(i);
		}

		for (int i = 1; i < n; i++) {
			for (int j = 0; j < 3; j++) {
				dp[i][j] = Math.max(dp[i - 1][(j + 1) % 3] + action.get(i).get(j),
						dp[i - 1][(j + 2) % 3] + action.get(i).get(j));
			}
		}

		int max = Integer.MIN_VALUE;
		for (int i = 0; i < 3; i++) {
			max = Math.max(max, dp[n - 1][i]);
		}

		System.out.println(max);

		stdin.close();
	}

}


Measured memory_bytes: 173100
#include <bits/stdc++.h>
using namespace std;
typedef long long in;
typedef pair<in,in> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (in)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(in i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

const in maxn= 2e5+99;
const in inf = 1e14;

int main()
{
    IOS;
    in n, ans=0;
    string s;
    cin >> n >> s;
    rep(i,0,n-2)
    {
        if(s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C') ans++;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m, f, b;
    cin >> m >> f >> b;
    if (m + f >= b)
    {
        cout << max(b - m, 0) << endl;
    }
    else
    {
        cout << "NA" << endl;
    }
}


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

int main(){
    int n,m;

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

    cin >> m;
    for(int i = 0; i < m; i++){
        int p,x;
        cin >> p >> x;
        cout << accumulate(t.begin(), t.end(), 0) - t[p - 1] + x << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int n,i,c=0;
  cin>>n;
  vector<string> a(n);
  for(i=0;i<n;i++)
    cin>>a[i];
  sort(a.begin(),a.end());
  for(i=0;i<n-1;i++)
  {
    if(a[i]!=a[i+1])
      c++;
  }
  c++;
  cout<<c;
  return 0;
}

Measured memory_bytes: 9596
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	// x := []int{97, 98, 99, 100, 96, 1}
	// n = len(x)
	x := make([]int, n)
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &x[i])
		sum += x[i]
	}

	center := (sum + n - 1) / n // round up

	minCost := 0.0
	for i := 0; i < n; i++ {
		// fmt.Println(i, "center", center, "cost", math.Pow(float64(x[i]-center), 2))
		minCost += math.Pow(float64(x[i]-center), 2)
	}

	fmt.Println(tryAll(x))
}

func tryAll(x []int) int {
	minCost := math.MaxInt64
	for i := 1; i <= 100; i++ {
		cost := 0.0
		for _, eachX := range x {
			cost += math.Pow(float64(eachX-i), 2)
		}
		if minCost > int(cost) {
			minCost = int(cost)
		}
	}
	return minCost
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N=1e6+10;
int a[N];

int main(){
	int i,j,k,n;
	cin>>n>>k;
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	int sum=0;
	for(i=1;i<=n;i++){
		sum+=min(abs(0-a[i]),abs(k-a[i]))*2;
	}
	cout<<sum;
	return 0;
}


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

int main() {
  int H,W;
  cin>>H>>W;
  for(int i=0;i<W+2;i++)cout<<"#";
  cout<<endl;
  for(int j=0;j<H;j++){
    string s;
    cin>>s;
    cout<<"#"<<s<<"#"<<endl;
  }
  for(int i=0;i<W+2;i++)cout<<"#";
  cout<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, M = map(int, input().strip().split())
ans = 1
if N == 1:
    print(M)
    exit()

for n in range(2, int(M ** 0.5) +1):
    if M % n == 0:
        if n < N and M // n < N:
            continue
        elif n >= N and M // n < N:
            ans = max(ans, M // n)
        elif n < N and M // n >= N:
            ans = max(ans, n)
        else:
            ans = max(ans, n, M // n)

print(ans)

Measured memory_bytes: 3188
from collections import deque
S=list(input())
Q=int(input())
query=[]
reverseflg=False
S=deque(S)

for i in range(Q):
  query.append(list(input().split()))

for q in range(Q):
  if query[q][0]=="1":
    reverseflg= not reverseflg
  
  if query[q][0]=="2":
    if query[q][1]=="1":
      if reverseflg== False:
        S.appendleft(query[q][2])
      else:
        S.append(query[q][2])
    
    else:
      if reverseflg== False:
        S.append(query[q][2])
      else:
        S.appendleft(query[q][2])

if reverseflg==True:
  S.reverse()
  
print(''.join(S))

Measured memory_bytes: 35172
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

int res;

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

    int L, R, d;
    cin >> L >> R >> d;
    res = 0;
    for (int i = L; i < R + 1; i++)
    {
        if (i % d == 0)
        {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;
using ll=long long ;

template <typename T=int>
struct Fenwick {
    int n;
    vector<T> v;
    
    Fenwick(int size = 100005) : n(size), v(n+1, 0) {}
    inline void add(int p, T val) {
        for (; p <= n; p += (p&-p)) { v[p] += val; }
    }
    inline T query(int p) {
        T tmp = 0;
        for (; p > 0; p -= (p&-p)) { tmp += v[p]; }
        return tmp;
    }
    inline T query(int l, int r) {
        return query(r) - query(l-1);
    }
};

// when range [l, r), has property P~notP, want last P.
// when return l-1, means not found.
template <typename T>
T bs_last(T l, T r, function<bool (T)> f) {
    assert(l < r);
    T mid;
    while (l != r) {
        mid = l + (r-l)/2;
        if (f(mid)) {
            l = mid + 1;
        }else {
            r = mid;
        }
    }
    return r-1;
}

void solve() {
    int n; cin >> n;
    ll TOT = (ll)n*(n+1)/2;
    vector<int> a(n);
    for (auto& x: a) {
        cin >> x;
    }
    auto ge = [&](int med){
        auto b = a;
        int sum = n+5;
        for (auto& x: b) {
            x = sum += (x>=med ? 1:-1);
        }
        Fenwick<int> f(2*n+10);
        f.add(n+5, 1);
        ll res = 0;
        for (int x: b) {
            res += f.query(x);
            f.add(x, 1);
        }
        return res;
    };
    auto candi = a;
    sort(candi.begin(), candi.end());
    candi.erase(unique(candi.begin(), candi.end()), candi.end());
    int m = candi.size();
    int res = bs_last<int>(0, m, [&](int i){
            return ge(candi[i]) >= (TOT+1)/2;
            });
    cout << candi[res];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

int main() {
    string S;
    cin>>S;
    int N = S.size();
    bool ans = true;
    for(int i=0;i<N;++i){
        if(S[i]!=S[N-1-i])ans = false;
    }
    for(int i=0;i<(N-1)/2;++i){
        if(S[i]!=S[(N-1)/2-1-i])ans = false;
    }
    for(int i=(N+3)/2-1;i<N;++i){
        if(S[i]!=S[N-1-i])ans = false;
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>
 
using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
 
 
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
 
//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n;
	cin>>n;

	string s,t;
	cin>>s>>t;

	REP(i,n){
		cout<<s[i]<<t[i];
	}
	return 0;
}




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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int x, y;
	cin >> x >> y;
	int ans = x * (x - 1) / 2 + y * (y - 1) / 2;
	print(ans);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	string S;
	bool aflg, bflg, cflg;

	aflg = bflg = cflg = false;

	cin >> S;

	for (int i = 0; i < 3; i++) {
		if (S[i] == 'a') aflg = true;
		if (S[i] == 'b') bflg = true;
		if (S[i] == 'c') cflg = true;
	}

	if (aflg and bflg and cflg) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
/*GOD     IS    GREAT,
  SO    AM    I*/
#include<bits/stdc++.h>
#include<numeric>
using namespace std;
#define ll long long int
#define ford(i,a,n) for(long long int i=a;i<n;++i)
#define fore(i,a,n) for(long long int i=a;i<=n;i++)
#define foru(i,a,n) for(long long int i=a;i>=n;i--)
#define test ll t;cin>>t;while(t--)
#define op(z) cout<<z<<endl
#define ops(z) cout<<z<<" "
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(vec) (vec).begin(),(vec).end() 
#define debug(x) cout<<#x<<" "<<x<<endl
#define pp pair<ll,ll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define maxe 1000000
#define MOD 1000000007
ll prime[maxe] = {0},ans=0;
// TO COUNT THE DIGIT IN A NUMBER => floor(log(n)/log10+1)
ll pwe(ll a, ll b) {
    if (b == 0)
        return 1;
    ll res = pwe(a, b / 2);
    res *= res; res %= MOD;
    if (b % 2)
        return (res * a) % MOD;
    else
        return (res );
}

void file()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
ll sumofdigits(ll n) {
    ll sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
void sieve()
{
    prime[0] = 0;
    prime[1] = 0;
    prime[2] = 1;
    ll i, j, k;
    for (i = 3; i <= maxe; i += 2)
    {
        prime[i] = 1;
    }
    for (i = 3; i <= maxe; i++)
    {
        if (prime[i])
        {
            for (j = i * i; j <= maxe; j += 2 * i)prime[j] = 0;
        }
    }
}
bool cmp(pp &a, pp &b)
{
    if (a.first != b.first)
    {
        return b.first > a.first;
    }
    else
    {
        return b.second > a.second;
    }
}
void solve()
{
  ll n,x,t;
  cin>>n>>x>>t;
  if(n%x)
  {
    op(((n/x)+1)*t);
  }
  else
  {
    op((n/x)*t);
  }
}
int main()
{
    fastIO
    //sieve();
    //file();
    //test
    {
        solve();
    }
    return 0;
}

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<vector<T>> m) {
    repall (v, m)
        init(v);
}

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int H, W, h, w;
    cin >> H >> W >> h >> w;

    print(H * W - W * h - H * w + h * w);

    return 0;
}

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

using namespace std;

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

  int N; cin>>N;
  vector<int> D(N); for (auto& d : D) cin>>d;

  int ans = 0;
  for (int i = 0; i < N; i++) for (int j = i+1; j < N; j++) {
    ans += D[i]*D[j];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <memory.h>
#include <stdio.h>
using namespace std;
const bool SUBMIT = 1;
struct Edge{
    int v, d, c;
    bool operator<(const Edge & b) const {
        //return d < b.d || d == b.d && c < b.c ;
        return(d==b.d)?((c==b.c)? v < b.v: c < b.c): d < b.d;
    }
};
vector<Edge> g[10000];
set<Edge> mq;  //&#36825;里tm的不能使用 SET，如果&#35828;只比&#36739;Edge d c，且d,c相等，就insert 不&#36827;去（小心&#21834;小心）！！！ 用priority que 保&#38505;吶！！！
int dist[10000];
//int cost[10000];
int father[10000];
bool visited[10000];
 

int dijkstra(int s, int n){
	memset(father, -1, sizeof(int) * n);
    memset(visited, 0, sizeof(bool) * n);
	int i;
	for(i = 0; i < n; ++i){
	    dist[i] = 100000000;
        //cost[i] = 100000000;
	}
    Edge edge;
    edge.v = s;
    edge.d = 0;
    edge.c = 0;
	mq.insert(edge);
	father[s] = -1;
	dist[s] = 0;
    //cost[s] = 0;
    int res = 0;
	while(mq.size()){
        edge = *mq.begin();
        int u = edge.v;
        //printf("cur top: %d %d %d\n", u, edge.d, edge.c);
		mq.erase(mq.begin());
        if(visited[u]) continue;
        visited[u] = 1;
        res += edge.c;
        for(i = 0; i < g[u].size(); ++i){
            Edge e = edge;
            e.v = g[u][i].v;
            e.d = g[u][i].d + edge.d;
            e.c = g[u][i].c;
            //printf("   insert e: %d %d %di\n", e.v, e.d, e.c);
            mq.insert(e);
		}
	}
    return res;
}
int main(){
	int n, m;
	int u, s;
    if(!SUBMIT)
        freopen("2249-input.txt", "r", stdin);
	scanf("%d%d", &n, &m);

	int i,j;
	while(n !=0 || m != 0){
	for(i = 0; i < n; ++i){
		g[i].clear();
        mq.clear();
	}
    Edge edge;
	for(i = 0; i < m; ++i)
	{
		scanf("%d%d%d%d", &u, &edge.v, &edge.d, &edge.c);
		u--; edge.v--;
		if(i == 0) s = u;
        g[u].push_back(edge);
        int temp = u;
        u = edge.v;
        edge.v = temp;
        g[u].push_back(edge);
	}
    s = 0;
	int cost = dijkstra(s, n);
	/*int cost = 0;
	for(i = 0; i < n; ++i){
		if(father[i] >= 0){
            for(j = 0; j < g[father[i]].size(); ++j){
                int c = g[father[i]][j].c;
                int v = g[father[i]][j].v;
                if(v == i){
                    cost += c;
                    break;
                }
            }
		}
	}*/
	printf("%d\n", cost);
	scanf("%d%d", &n, &m);
	}
    return 0;
}

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

int main()
{
    string S;
    cin >> S;
    
    int count=0;
    int N = S.length();
    for(int i=0; i<N/2; i++){
        if(S[i] != S[N-i-1]) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int d[101],f[101],g[101][101],n;
int t = 1 ;

void visit(int i){

  int l,m;
  
  d[i] = t++;
  
  for(l = 1 ; l <= n ; l++ ){
    if(g[i][l] == 1 && d[l] == 0){
      visit(l);
    } 
  }
  
  f[i] = t++;
}

int main(void){
  
  int i,j,u,k,x;


  scanf("%d",&n);

  // 初期化
  for(i = 1 ; i <= n ; i++){
    d[i] = 0;
    f[i] = 0; 
    for(j = 1 ; j <= n ; j++ ){
      g[i][j] = 0;
    }
  }

  // 入力
  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&u,&k);
    for(j = 0 ; j < k ; j++ ){
      scanf("%d",&x);
      g[u][x] = 1;
    }
  }
  /*  
  // 仮出力
  printf("隣接行列\n");

  for(i = 1 ; i <= n ; i++){
    for(j = 1 ; j <= n ; j++ ){
      if(j != 1) printf(" ");
      printf("%d",g[i][j]);
    }
    printf("\n");
  }
  */
  // 深さ優先探索

  
  for(i = 1 ; i <= n ; i++ ){
      
    if(d[i] == 0 ){
      visit(i);

    }
  }
    
    
  // 出力

  for(i = 1 ; i <= n ; i++ ){
    printf("%d %d %d\n",i,d[i],f[i]);
    
  }
    
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
template<typename T1, typename T2>
inline bool cmn (T1& a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<typename T1, typename T2>
inline bool cmx (T1& a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  vector<vector<bool>> s(h + 2, vector<bool>(w + 2, true));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      char c;
      cin >> c;
      s[i][j] = c == '#';
    }
  }
  vector<vector<int>> lft(h + 1, vector<int>(w + 1, 0));
  vector<vector<int>> rgt(h + 1, vector<int>(w + 1, 0));
  vector<vector<int>> lwr(h + 1, vector<int>(w + 1, 0));
  vector<vector<int>> upr(h + 1, vector<int>(w + 1, 0));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      lft[i][j] = s[i][j - 1] 
        ? 0
        : lft[i][j - 1] + 1;
      upr[i][j] = s[i - 1][j]
        ? 0
        : upr[i - 1][j] + 1;
    }
  }
  for (int i = h; i >= 1; i--) {
    for (int j = w; j >= 1; j--) {
      rgt[i][j] = s[i][j + 1]
        ? 0
        : rgt[i][j + 1] + 1;
      lwr[i][j] = s[i + 1][j]
        ? 0
        : lwr[i + 1][j] + 1;
    }
  }
  vector<vector<int>> score(h + 1, vector<int>(w + 1, 0));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      score[i][j] = lft[i][j] + upr[i][j] + rgt[i][j] + lwr[i][j] + 1;
    }
  }
  int ret = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (!s[i][j]) cmx(ret, score[i][j]);
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 79488
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}

int main() {
  LL N; cin >> N;
  vector<LL> C(N); cin >> C;
  sort(C.rbegin(), C.rend());

  vector<LL> k(N + 1); k[0] = 1;
  for (int i = 1; i <= N; ++i) {
    k[i] = 2LL * k[i-1] % kMod;
  }

  LL f = k[N-1] * C[0] % kMod;
  for (int i = 1; i < N; ++i) {
    LL l = k[N-i-1];
    LL r = (k[i] + k[i-1] * i) % kMod;
    LL a = l * r % kMod;
    f = (f + a * C[i]) % kMod;
  }

  cout << (k[N] * f) % kMod << endl;
}


Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

size_t non_zero_min(vector<int> &V){
  int min = 1e9;
  int pos = -1;
  for(int i=0; i<V.size(); i++){
    if(V[i]!=0 && min >= V[i]){
      min = V[i];
      pos = i;
    }
  }
  return pos;
}



int main(){
  int N,tem;
  cin >> N;
  vector<int> As;
  for(int i=0; i<N; i++){
    cin>>tem;
    As.push_back(tem);
  }
  size_t min_pos;
  while(true){
    min_pos = non_zero_min(As);
    for(int i=0; i<N; i++){
      if(i==min_pos) continue;
      As[i] %= As[min_pos];
    }
    int zero_cnt=0;
    for(int i=0; i<N; i++){
      if(As[i]==0) zero_cnt++;
    }
    if(zero_cnt==N-1) break;
  }
  cout << As[min_pos] << endl;
}


Measured memory_bytes: 892
#!/usr/bin/env python3
import sys


def solve(S: str, T: str):
    print(T+S)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61872
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
struct edge{ int to, time, cost; };
const double esp = 1e-9;
const int infi = (int)1e+9;
const ll infll = (ll)1e+17;

const int max = (int)1e+6 + 1;

typedef std::pair<ll, int> MP;

int n, r, l;
MP seg[max * 2];
ll point[max];
int d[max], t[max], x[max];

void init(){
	int x = 1;
	while (x < n)x *= 2;
	n = x;
	rep(i, max * 2)seg[i].first = -infll, seg[i].second = 0;
	REP(i, n - 1, n * 2 - 1)seg[i].second = i - (n - 1);
}

void update(int k, int e){
	k += n - 1;
	seg[k].first += e;
	while (k > 0){
		k = (k - 1) / 2;
		int BigI = (seg[k * 2 + 1].first >= seg[k * 2 + 2].first ? k * 2 + 1 : k * 2 + 2);
		seg[k].first = seg[BigI].first;
		seg[k].second = seg[BigI].second;
	}
}

int main(){
	std::cin >> n >> r >> l;
	int before = 0;
	init();
	rep(i, r)std::cin >> d[i] >> t[i] >> x[i];

	rep(i, r){
		if (i == r - 1 || t[i] != t[i + 1]){
			point[seg[0].second] += (t[i] - before);
			before = t[i];
		}
		update(d[i] - 1, x[i]);
	}

	point[seg[0].second] += (l - before);
	int maxI = 0;
	REP(i, 1, n){
		if (point[i] > point[maxI])maxI = i;
	}
	std::cout << maxI + 1 << std::endl;
	return 0;
}

Measured memory_bytes: 47844
import heapq
n, m = map(int, input().split())
a_b = [[] for _ in range(m)]
for i in range(n):
    a, b = map(int, input().split())
    if a < m+1:
        a_b[a-1].append(-b)
h = []
heapq.heapify(h)
ans = 0
for i in range(m):
    for j in a_b[i]:
        heapq.heappush(h, j)
    if len(h) == 0:
        continue
    ans += heapq.heappop(h)*(-1)
print(ans)

Measured memory_bytes: 17708
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = Console.ReadLine().Split(' ').Select(x=>long.Parse(x)).ToArray();
			long N = input[0];
			long M = input[1];
			long count = 0;
			count = 2*N > M? M / 2 : N + (M - 2 * N) / 4;
			Console.WriteLine(count);
		}
	}
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   string s;
   cin >> s;
   string t = s[0] + string(s.size()-1, '9');
   ll a = stoll(s), b = stoll(t);
   ll sum = s[0] - '0' + (s.size() - 1)*9;
   if (a < b) {
      cout << sum - 1 << endl;
   } else {
      cout << sum << endl;
   }

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(x,i,e) for(int x=i;x<e;x++)
/*
URL:https:https://atcoder.jp/contests/agc038/tasks/agc038_a
*/
int main()
{
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	FOR(i,0,h)
	{
		FOR(j,0,w)
		{
			if(i<b)
			{
				if(j<a)
				{
					cout<<"0";
				}
				else
				{
					cout<<"1";
				}
			}
			else
			{
				if(j<a)
				{
					cout<<"1";
				}
				else
				{
					cout<<"0";
				}
			}
		}
		cout<<endl;
	}
	return 0;	
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <vector>
 
using namespace std;
typedef long long LL;
#define pb push_back

const int maxn = 200005;
int n,a[maxn];

bool check(int o) {
	int p=0,q=0;
	for (int i=n;i>=2;i--) if ((a[i]>=o)==(a[i-1]>=o)) {p=i;break;}
	for (int i=n;i<2*n-1;i++) if ((a[i]>=o)==(a[i+1]>=o)) {q=i;break;}
	if (!p&&!q) return a[1]>=o;
	if (!p) return a[q]>=o;
	if (!q) return a[p]>=o;
	if (a[p]>=o&&a[q]>=o) return true;
	if (a[p]<o&&a[q]<o) return false;
	return n-p<q-n?a[p]>=o:a[q]>=o;
}
int main()
{
	#ifdef Amberframe
		freopen("agc006d.in","r",stdin);
		freopen("agc006d.out","w",stdout);
	#endif
	scanf("%d",&n);
	for (int i=1;i<=2*n-1;i++) scanf("%d",&a[i]);
	int lb=0,rb=2*n;
	while (rb-lb>1) {
		int mid=lb+rb>>1;
		check(mid)?lb=mid:rb=mid;
	}
	printf("%d",lb);
	return 0;
}

Measured memory_bytes: 1024
/*  
    |\_/|
    |* *|
    \_+_/
*/
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  int n,m;

  cin>>n>>m;

  cout<<(n-1)*(m-1)<<endl;
  
  return 0;

}




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

using namespace std;

int main()
{
	int a[30], n,year;
	cin >> n;
	
	a[1] = 1;
	a[2] = 2;
	a[3] = 4;

	while (1)
	{
		if (n==0)
		{
			break;
		}
			for (int  i = 4; i < n+1; i++)
		{
				a[i] = a[i - 1] + a[i - 2] + a[i - 3];

		}
			if (a[n]%3650==0)
			{
				year = a[n] / 3650;
			}
			else
			{
				year = a[n] / 3650 + 1;
			}
			
		cout <<year<<endl;
		cin >> n;
	}
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = -1;
  for (int i = 1; i <= 20000; ++i) {
    if ((int)(0.08 * i) == a && (int)(0.1 * i) == b) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()
    val d = (0 until k).map {
        val di = sc.next().toInt()
        val list = (0 until di).map {
            sc.next().toInt()
        }
        di to list
    }
    println(problem166b(n, k, d))
}

fun problem166b(
    n: Int,
    k: Int,
    d: List<Pair<Int, List<Int>>>
): Int {
    val sunukes = Array(n) { mutableSetOf<Int>() }
    for (i in 0 until k) {
        for (j in 0 until d[i].first) {
            sunukes[d[i].second[j] - 1].add(i + 1)
        }
    }
    return sunukes.count { it.isEmpty() }
}

Measured memory_bytes: 44568
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  using namespace chrono_literals;
  chrono::high_resolution_clock clock;
  auto be = clock.now();
  int D;
  cin >> D;
  array<int, 26> c;
  for (auto& e : c) cin >> e;
  vector<array<int, 26>> d(D);
  for (auto& r : d)
    for (auto& e : r) cin >> e;
  auto eval = [&](vector<int> t) {
    int S = 0;
    array<int, 26> last = {};
    for (int i = 0; i < D; ++i) {
      S += d[i][t[i]];
      last[t[i]] = i + 1;
      for (int j = 0; j < 26; ++j) S -= c[j] * (i + 1 - last[j]);
    }
    return S;
  };
  vector<int> t(D);
  for (int i = 0; i < D; ++i)
    t[i] = distance(cbegin(d[i]), max_element(cbegin(d[i]), cend(d[i]))) + 1;
  for (const auto& e : t) cout << e << '\n';
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e5;
const int size=1e5;
const int inf=1e9;
int main(){
	int K;int X;cin>>K>>X;
	if(500*K>=X) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
/* author   : mpily :-()
title : Competing.cpp
time :Mon May 11 18:41:30 2020

*/
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int64_t>arr;
int64_t dp[65];
int64_t ans[128];
const int64_t mod = 1e9+7;
//int64_t fans = 0;
int64_t bforce(vector<int64_t>arr){
	int64_t bans = 0;
	int n = arr.size();
	for(int i = 0; i < n; ++i){
		for(int j = i; j < n; ++j){
			bans+=arr[i]^arr[j];
			bans%=mod;
		}
	}
	return bans;
}
int main(){
	int64_t fans = 0, bans = 0;
	//while(bans == fans){
		fans = 0;
		bans = 0;
		for(int i =0; i< 65; ++i)
			dp[i] = 0;
		for(int j = 0; j < 128; ++j)
			ans[j] = 0;
		//srand(time(0));
		//n = rand()%10;
		cin >> n;
		arr.resize(n);
		for(int i = 0; i < n; ++i){
			cin >> arr[i];
			//arr[i] = rand()%10000;
		}
		for(int i = 0; i < n; ++i){
			long long tmp = arr[i];
			int pos = 0;
			while(tmp){
				if(tmp&1LL){
					dp[pos]++;
				}
				pos++;
				tmp>>=1;	
			}
		}
		for(int i = 0; i < 65; ++i){
			//cout << "before adding from dp the "<<i <<"th bit had "<< ans[i] <<"\n"; 
			ans[i]+=(dp[i]*(n-dp[i]));
			ans[i]%=mod;
			/*int64_t tmp = ans[i];
			ans[i] = 0;
			//cout << "after adding  "<< tmp <<"\n";
			for(int j = 0; j < 64; ++j){
				if(tmp & 1LL<<j){
					ans[i+j]+=1;
				}
			}*/
		}
		int64_t po2 = 1;
		assert(fans == 0);
		for(int i = 0;i < 65; ++i){
			if(ans[i]){
				//cout << "bit " << i << " is on \n";
				int64_t toad = po2*ans[i];
				toad%=mod;
				fans+=toad;
				fans%=mod;
			}
			po2*=2LL;
			po2%=mod;
		}
		cout << fans <<"\n";
		/*bans = bforce(arr);
		if(bans != fans){
			cout <<"found bug \n";
			for(auto a : arr){
				cout << a <<" ";
			}
			cout << "\n";
			cout <<"bforce gives "<<bans <<"\n";
			cout <<" my working gives "<< fans <<"\n";
		}*/
		//cout << fans <<"\n";
	//}
	return 0;
}

Measured memory_bytes: 2560
using System;
using System.Linq;
class Program{
static void Main(string[] args){
  var N = int.Parse(Console.ReadLine());
  //配列でやる場合
  var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
  Array.Sort(a);
  Array.Reverse(a);
  int alice=0;
  int bob=0;
  //素直にaliceとbobを計算
  for(int i=0;i<N;i++){
    if(i%2==0) alice+=a[i];
    else bob+=a[i];
  }
  Console.WriteLine(alice-bob);
}
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) (i64)(a / (f64)__gcd(a, b) * b) /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    string S;
    cin >> S;
    cout << S << YN("es", "s", S[S.size() - 1] == 's') << endl;
}


Measured memory_bytes: 3652
#include <cstdio>
#include<cstring>
#include<queue>
using namespace std;

int main(void){
  int n=0,k=0;
  scanf("%d%d",&n,&k);
  int i=0;
  priority_queue<int> ques[10];
  int dkm[10][2010]={0};
  int dkz[11][2010];
  memset(dkz,-1,sizeof(dkz));
  int ama=0,bmb=0;
  for(i=0;i<n;i++){
    scanf("%d%d",&ama,&bmb);
    ques[bmb-1].push(ama);
  }
  int j=0;
  for(i=0;i<10;i++){
    j=0;
    //dkm[i][0]=-2;
    while(!ques[i].empty()){
      ama=ques[i].top();
      ques[i].pop();
      dkm[i][j+1]=dkm[i][j]+ama+2*j;
      //printf("%d\x0020\n",dkm[i][j+1]);
      j++;
    }
    dkm[i][0]=j;
  }

  int h=0;
  dkz[0][0]=0;
  for(i=0;i<10;i++){
    dkz[i+1][0]=dkz[i][0];


      for(h=k;h>0;h--){
     dkz[i+1][h]=dkz[i][h];
 
    for(j=1;j<=dkm[i][0];j++){


	if(h-j>=0 && dkz[i][h-j]!=-1){

	  dkz[i+1][h]=(dkz[i][h-j]+dkm[i][j]>dkz[i+1][h]) ? dkz[i][h-j]+dkm[i][j] : dkz[i+1][h];

	}
	//printf("%d\x0020%d\x0020%d\n",dkz[i+1][h],i+1,h);
      }
    }
  }

  int ans=0;
  for(i=0;i<10;i++){
    if(ans<dkz[i+1][k])ans=dkz[i+1][k];
  }

  printf("%d\n",ans);
  return 0;
}
	//dkz[i][j]は、i種目まで使ってj冊分埋めた値。
	//dkz[i][x]=max(dkz[i-1][x-j]+dkm[i][j],dkz[i][x])
	//i種目からj冊採ってh冊にする

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int tak = (c + b - 1)/b;
  int aok = (a + d - 1)/d;
  
  if(tak <= aok) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define Pi 3.1415926535
#define MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}

int solve(){
    string s; cin >> s;
    bool ans = true;
    int n = s.size();
    rep(i,n/2){
        if(s[i] != s[n-i-1]) ans = false;
    }
    rep(i,(n-1)/4){
        if(s[i] != s[(n-1)/2-i-1]) ans = false;
    }
    for(int i = (n+3)/2-1; i < n; ++i){
        if(s[i] != s[n-i-1]) ans = false;
    }

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

    return 0;
}

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


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <climits>
using namespace std;

int d[8]={1,2,1,2,1,4,1,4};
void revolution(int *p,int k){
	for(int i=0;i<8;i++){
		p[i]=d[(i+k)%8];
	}
}
int main(int argc,char *argv[]){
	int p[8],res,t,td[8];
	unsigned long long int m, tt;
	while(scanf("%d%d%d%d%d%d%d%d",&p[0],&p[1],&p[2],&p[3],&p[4],&p[5],&p[6],&p[7])!=EOF){
		res=INT_MAX;m=59999*100000;
		for(int i=0;i<8;i++){
			revolution(td,i);
			t=0;tt=0;
			for(int j=0;j<8;j++) {t+=max(p[j]-td[j],0);tt=tt*10+td[j];}
			if(res>t) {res=t;m=tt;}
			if(res==t&&tt<m) {res=t;m=tt;}
		}
		for(int i=0;i<8;i++){
			p[7-i]=m%10;m/=10;
		}
		printf("%d %d %d %d %d %d %d %d\n",p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]);
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n; cin >> n;
    rep(i, 12) {
        if (i*1000 >= n) {
            cout << i*1000 - n << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3636
def modpow(x, n, m)
    res=1
    while n>0
        res=res*x%m if n.odd?
        x=x*x%m
        n>>=1
    end
    res
end

z=0
h={}
n=gets.to_i
n.times do
    a, b=gets.split.map(&:to_i)
    if a==0 and b==0
        z+=1
    else
        h[ab=b==0 ? (10**20).to_r : Rational(a, b)]||=0
        h[ab]+=1
    end
end

MOD=10**9+7
res=1
h.each do |k, v|
    x=k.zero? ? (10**20).to_r : -1/k
    x=0.to_r if k==(10**20).to_r

    w=h[x]||0
    res*=modpow(2, v, MOD)+modpow(2, w, MOD)-1
    res%=MOD

    h[k]=0
    h[x]&&=0
end
puts (res+z+MOD-1)%MOD


Measured memory_bytes: 33912
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    String str = br.readLine();
	    StringTokenizer st = new StringTokenizer(str, " ");

		int a  = Integer.parseInt(st.nextToken());
		int b  = Integer.parseInt(st.nextToken());
		int c  = Integer.parseInt(st.nextToken());

		if(a <= b && b <= c ) {
			System.out.println(a + " " + b + " " + c);

		}else if(a <= b && c <= b && a <= c){
			System.out.println(a + " " + c + " " + b);

		}else if(b <= c && c <= a){
			System.out.println(b + " " + c + " " + a);

		}else if(b <= c && a <= c){
			System.out.println(b + " " + a + " " + c);

		}else if(c <= a && a <= b){
			System.out.println(c + " " + a + " " + b);

		}else if(c <= a && b <= a){
			System.out.println(c + " " + b + " " + a);
		}

	}

}

Measured memory_bytes: 24136
#include<cstdio>
#include<iostream>

#define REP(i,s,n) for(register int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define MAX 500010

using namespace std;

long long depth[MAX],L[MAX],R[MAX],N,noSaveDp[MAX],saveDp[MAX],leaf[MAX];

int main(){
  scanf("%d",&N);
  depth[0] = leaf[N-1] = 1;
  rep(i,N-1){
    scanf("%d %d",&L[i],&R[i]);
    depth[--L[i]] = depth[--R[i]] = depth[i] + 1;
  }

  for(int i = N-2;i>=0;i--){
    leaf[i] = leaf[L[i]] + leaf[R[i]];
    saveDp[i] = noSaveDp[i] = noSaveDp[L[i]] + noSaveDp[R[i]] + leaf[L[i]] + leaf[R[i]];
    saveDp[i] = min(saveDp[i],
		    min(noSaveDp[L[i]]+leaf[L[i]]+1+saveDp[R[i]],
			noSaveDp[R[i]]+leaf[R[i]]+1+saveDp[L[i]]));
    saveDp[i] = min(saveDp[i],
		    saveDp[L[i]]+1+depth[i]-1+1+saveDp[R[i]]);
  }
  printf("%d\n",saveDp[0]);
  return 0;
}

Measured memory_bytes: 24620
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

bool dfs(int c_node, int cnt, vector<vector<int>> &G, const int &goal){
    if(cnt==2){
        if(c_node==goal) return true;
        else return false;

    }
    for(auto n_node : G[c_node]){
        if(dfs(n_node, cnt+1, G, goal)){
            return true;
        }
    }
    return false;
}

int main(){
    int n,m;
    cin >> n>>m;
    vector<vector<int>> G(n, vector<int>(0));
    REP(i,m){
        int a,b;
        cin >> a>>b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    cout << (dfs(0,0,G,n-1)?"POSSIBLE":"IMPOSSIBLE") << endl;  
    return 0;
}

Measured memory_bytes: 12016
#include <iostream>

int main(void){
	char hen[128];
	int n;

	while(true){

		for(int i=0; i<128; i++) hen[i] = i;

		std::cin >> n;
		if(!n) break;
		for(int i=0; i<n; i++){
			char from, to;
			std::cin >> from >> to;
			hen[from] = to;
		}
		std::cin >> n;
		for(int i=0; i<n; i++){
			char c;
			std::cin >> c;
			std::cout << hen[c];
		}
		std::cout << '\n';

	}

	return 0;
}

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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for(int i = (int)a; i <= (int)b; ++i)
#define sz(s) (int)s.size()
#define all(v) v.begin(),v.end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef long double ld;
const ll inf = (ll)1e18;
const ll N = (ll)2e5+77;
const ll mod = (ll)1e9+7;

int main() {
    fast;
    int n, k, x, a[N]={0};
    cin >> n >> k;
    forn(i, n) cin >> x, a[x]++;
    vector<int> v;
    forn(i, N) if (a[i]) v.push_back(a[i]);
    sort(all(v));
    x = 0;
    forn(i, sz(v) - k) {
        x += v[i];
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 2168
n = int(input())

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

    #divisors.sort(reverse=True)
    return divisors

d = make_divisors(n)
ans = 10**18
for a in d:
    b = n//a
    a = str(a)
    b = str(b)
    ans = min(ans, max(len(a), len(b)))
print(ans)


Measured memory_bytes: 68124