akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

const long long int MOD=1e9+7;

int main() {
    string str1, str2;
    int N;
    cin >> N;
    cin >> str1 >> str2;
    
    long long int ans=1;
    char pre=str1[0];
    int cnt=1;
    int pr=0;
    for(int i=1; i<str1.size(); i++) {
        if(pre==str1[i]) {
            cnt++;
        } else {
            if(pr==0) {
                if(cnt==1) {
                    ans *= 3;
                    pr = 1;
                } else {
                    ans *= 6;
                    pr = 2;
                }
            } else if(pr==1) {
                ans *= 2;
            } else {
                if(cnt==2) {
                    ans *= 3;
                }
            }
            ans %= MOD;
            pr = cnt;
            cnt=1;
        }
        pre=str1[i];
    }
    if(pr==0) {
        if(cnt==1) {
            ans *= 3;
            pr = 1;
        } else {
            ans *= 6;
            pr = 2;
        }
    } else if(pr==1) {
        ans *= 2;
    } else {
        if(cnt==2) {
            ans *= 3;
        }
    }
    ans %= MOD;
    cout << ans << endl;


    return 0;
    
}

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

int main()
{
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx = x2 - x1, dy = y2 - y1;
    int x3 = x2 - dy, y3 = y2 + dx;
    int x4 = x3 - dx, y4 = y3 - dy;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}


Measured memory_bytes: 3584
// #include <iostream>
// #include <vector>
// #include <unordered_map>
// #include <unordered_set>
// #include <algorithm>
// #include <numeric>
// #include <math.h>
// #include <utility>
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
// typedef vector<int> vi;
// typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = a; i <= b; i++)

void solution() {
    string s;
    cin >> s;
    int n = s.size();
    int c = 0;
    for (int i = 0; i < n/2; i++) {
        if (s[i] != s[n - 1 - i]) c++;
    }

    cout << c << endl;
}

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    solution();
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int p[] = new int[N];
		for(int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
		}
		int x[] = new int[M];
		int y[] = new int[M];
		for(int  i = 0; i < M; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		
		UnionFind.init(N);
		for(int i = 0; i < M; i++) {
			UnionFind.unite(x[i] - 1, y[i] - 1);
		}
		
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			if(UnionFind.same(p[i] - 1, i)) {
				cnt++;
			}
		}
		
		System.out.println(cnt);
	}
}

class UnionFind {
	static int N;
	static int par[];
	static int rank[];
	public static void init(int n) {
		N = n;
		par = new int[N];
		rank = new int[N];
		for(int i = 0; i < N; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}

	public static int find(int x) {
		if(par[x] == x) {
			return x;
		} else {
			return par[x] = find(par[x]);
		}
	}
	
	public static void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if(x == y) return;
		
		if(rank[x] < rank[y]) {
			par[x] = y;
		} else {
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}
	
	public static boolean same(int x, int y) {
		return find(x) == find(y);
	}
}


Measured memory_bytes: 90236
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500 * i + 100 * j + 50 * k == x:
                cnt += 1
print(cnt)

Measured memory_bytes: 3060
#ifndef __cplusplus
    cat << EOF
#endif
#include <bits/stdc++.h>
using namespace std;

typedef long long lint;
constexpr int inf = (1 << 30) - 1;
constexpr lint linf = (1ll << 60) - 1;

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }

constexpr long double PI = 3.1415926535897932384626;
constexpr int MX = 99999999;

struct point {
    int x, y;
    point(int x = 0, int y = 0) : x(x), y(y) { }
    bool operator < (const point& rhs) {
        if(x == rhs.x) return y < rhs.y;
        return x < rhs.x;
    }
    friend istream& operator >> (istream& st, point& p) {
        return st >> p.x >> p.y;
    }
    void x_swap() {
        x = MX - x;
    }
    void y_swap() {
        y = MX - y;
    }
};

int main() {

    point start, goal;
    cin >> start >> goal;

    bool swap_x = start.x > goal.x;
    bool swap_y = start.y > goal.y;
    if(swap_x) {
        start.x_swap();
        goal.x_swap();
    }   
    if(swap_y) {
        start.y_swap();
        goal.y_swap();
    }

    int N;
    cin >> N;
    vector<point> fountains;
    rep(i, N) {
        point tmp;
        cin >> tmp;
        if(swap_x) tmp.x_swap();
        if(swap_y) tmp.y_swap();
        if(tmp.x >= start.x && tmp.y >= start.y && tmp.x <= goal.x && tmp.y <= goal.y) {
            fountains.push_back(tmp);
        }
    }

    long double answer = 100.0 * ((goal.x - start.x) + (goal.y - start.y));
    sort(all(fountains));
    vector<int> dp(fountains.size() + 1, inf);
    dp[0] = -inf;
    for(const point& p : fountains) {
        *lower_bound(all(dp), p.y) = p.y;
    }
    int cnt = lower_bound(all(dp), inf) - dp.begin() - 1;
    answer -= 20.0 * cnt;
    answer += 5.0 * PI * cnt;
    if(cnt == min(goal.x - start.x, goal.y - start.y) + 1) {
        answer += 5.0 * PI;
    }

    cout << fixed << setprecision(30) << answer << '\n';
    return 0;

}


Measured memory_bytes: 2544
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int[] h = new int[N];
        for(int i = 0; i < N; i++){
            h[i] = sc.nextInt();
        }
        sc.close();
        int count = 0;
        for(int i = 0; i < N-1; i++){
            if(h[i] > h[i+1]){
                count += h[i] - h[i+1];
            }
        }
        count += h[N-1];
        System.out.println(count);
    }
}


Measured memory_bytes: 22996
#coding:utf-8
import math
import string
import time
import fractions


#制約
#1≦N≦105
#0≦Ai≦N−1

#N
#A1 A2 … AN

n = int(raw_input())
a = map(int, raw_input().split())

a.sort()
ret = -1
if n % 2 == 0:
	for i in range(n):
		tmp = i
		if i % 2 == 0:
			tmp += 1
		if tmp != a[i]:
			ret = 0
			break
	if ret == -1:
		ret = (2 ** (n / 2)) % (10 ** 9 + 7)
else:
	for i in range(n):
		tmp = i
		if i % 2 == 1:
			tmp += 1
		if tmp != a[i]:
			ret = 0
			break
	if ret == -1:
		ret = (2 ** (n / 2)) % (10 ** 9 + 7)

print ret

Measured memory_bytes: 12696
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static void AssertEquals<T>(
				       T expected,
				       T actual,
				       [CallerLineNumber] int lno = 0
				       )
	where T : IComparable
    {
	if (expected.CompareTo(actual) != 0)
	{
	    WriteLine($"Assertion Error at line {lno}:");
	    WriteLine($"\texpected: {expected}");
	    WriteLine($"\t  actual: {actual}");
	    Environment.Exit(1);
	}
    }
}

class Program
{
    static bool isEven(int x){ return (x&1) == 0; }
    static bool isOdd(int x){ return !isEven(x); }
    
    public static void Main()
    {
	int n = int.Parse(ReadLine());
	int[] a = new int[n];
	for (int i = 0; i < n; i++)
	    a[i] = int.Parse(ReadLine());

	Array.Sort(a);
	Array.Reverse(a);
	
	int[] nP2 = new int[2];
	int[] nP1 = new int[2];
	int[] nM1 = new int[2];
	int[] nM2 = new int[2];

	// case P1 < P2 > P3 < P4 > P5
	nP2[0] = isOdd(n) ? n/2 : n/2 - 1;
	nP1[0] = isEven(n) ? 1 : 0;
	nM1[0] = isOdd(n) ? 2 : 1;
	nM2[0] = n/2 - 1;
	AssertEquals(nP2[0]+nP1[0]+nM1[0]+nM2[0], n);

    	// case P1 > P2 < P3 > P4 < P5
	nP2[1] = n/2 - 1;
	nP1[1] = isOdd(n) ? 2 : 1;
	nM1[1] = isEven(n) ? 1 : 0;
	nM2[1] = isOdd(n) ? n/2 : n/2 - 1;
	AssertEquals(nP2[1]+nP1[1]+nM1[1]+nM2[1], n);

	long[] ans = new long[2];
	for (int i = 0; i < 2; i++)
	{
	    int ct = 0;
	    for (int j = 0; j < nP2[i]; j++)
		ans[i] += 2L * a[ct++];
	    for (int j = 0; j < nP1[i]; j++)
		ans[i] += a[ct++];
	    for (int j = 0; j < nM1[i]; j++)
		ans[i] -= a[ct++];
	    for (int j = 0; j < nM2[i]; j++)
		ans[i] -= 2L * a[ct++];
	}
	WriteLine(Math.Max(ans[0], ans[1]));
    }	
}


Measured memory_bytes: 17344
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.Exerwizerds2019
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nq = ReadInts();
            int n = nq[0];
            int q = nq[1];
            string s = "a" + Read() + "b";
            char[][] tds = new char[q+2][];
            for(int i =0; i < q; i++)
            {
                string[] ss = Read().Split();
                tds[i] = new char[2] { ss[0][0], ss[1][0] };
            }
            int bottom = 0;
            int top = n + 2;
            while (bottom + 1 < top)
            {
                int mid= (bottom + top) / 2;
                int now = mid;
                for (int i = 0; i < q; i++)
                {
                    if (s[now] == tds[i][0])
                    {
                        if (tds[i][1] == 'L') now--;
                        else now++;

                        if (now == 0)
                        {
                            break;
                        }
                    }
                }
                if (now == 0)
                {
                    bottom = mid;
                }
                else
                {
                    top = mid;
                }
            }
            int res = bottom;

            bottom = -1;
            top = n + 1;
            while (bottom + 1 < top)
            {
                int mid = (bottom + top) / 2;
                int now = mid;
                for (int i = 0; i < q; i++)
                {
                    if (s[now] == tds[i][0])
                    {
                        if (tds[i][1] == 'L') now--;
                        else now++;

                        if (now == n + 1)
                        {
                            break;
                        }
                    }
                }
                if (now == n+1)
                {
                    top = mid;
                }
                else
                {
                    bottom = mid;
                }
            }
            res += n+1 - top;
            res = n - res;
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main() {
  int a;
  int b;
  cin >> a >> b;
  
  if (a*b%2 == 0) {
    cout << "Even" << endl;
  }
  
  else {
    cout << "Odd" << endl;
  }


}


Measured memory_bytes: 3520
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;
int main()
{
    abdelrahman010
    string s;
    deque<char>d;
    bool a = true;
    int q;
    cin >> s >> q;
    for(auto &i : s)
        d.push_back(i);
    while(q--)
    {
        int t;
        cin >> t;
        if(t == 1)
            a = !a;
        else
        {
            int f;
            char c;
            cin >> f >> c;
            if((f == 1 && a) || (f == 2 && !a))
                d.push_front(c);
            else
                d.push_back(c);
        }
    }
    if(!a)
        reverse(d.begin() , d.end());
    for(auto &i : d)
        cout << i;
    return 0;
}

Measured memory_bytes: 976
package main

import (
	"fmt"
	"sort"
)

type digs []int

func (d digs) Len() int {
	return len(d)
}

func (d digs) Swap(i, j int) {
	d[i], d[j] = d[j], d[i]
}

func (d digs) Less(i, j int) bool {
	return d[i] < d[j]
}

func main() {
	arr := make([]int, 3)
	for i := 0; i < 3; i++ {
		fmt.Scanf("%d", &arr[i])
	}
	sort.Sort(digs(arr))

	ret := arr[2]*10 + arr[1] + arr[0]
	fmt.Println(ret)
}


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

int main(){
    unsigned long h,n;
    cin >> h >> n;
    unsigned long sum = 0;
    for(unsigned long i = 0; i<n; i++){
        int a;
        cin >> a;
        sum += a;
    }
    if(sum >= h){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let s = read_vec::<i64>();
    let ans = if s[0] <= s[2] && s[2] <= s[1]{
        "Yes"
    }else{
        "No"
    };
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <bitset>
#include <sstream>
#include <queue>

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long int64;
typedef long double ldb;

const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1e10) + 100;
const long double pi = acos(-1);

template <class T> T sqr (T x) {return x * x;}
template <class T> T abs (T x) {return x < 0 ? -x : x;}

const int MAXP = 3000;
const int MAXN = 120 * 1000;

bool notPrime[MAXP];
vector <long long> p, p3;
long long a[MAXN];
vector <pair <long long, int> > num;

long long getRad (long long x) {
	for (int i = 0; i < sz(p3); ++i) {
		while (x % p3[i] == 0) {
			x /= p3[i];
	   	}
	}
	return x;
}

long long getInv (long long x) {
	x = getRad(x);
	long long y = 1;
	for (int i = 0; i < sz(p); ++i) {
		int num = 0;
		while (x % p[i] == 0) {
			x /= p[i];
			num++;
		}
		if (num == 1) {
			y = min(inf64, y * sqr(p[i]));
	   	} else if (num == 2) {
	   		y = min(inf64, y * p[i]);
	   	}
	}

	if (x > 1) {
		long long sqrt_x = round(sqrt(x));
		if (sqrt_x * sqrt_x == x) {
			y = min(inf64, y * sqrt_x);
		} else if (x < sqrt(inf64)) {
			y = min(inf64, y * sqr(x));
		} else {
			y = inf64;
		}
	}

	return y;
}

int main () {
    ios_base::sync_with_stdio(0);
//	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);

	for (int i = 2; i < MAXP; ++i) {
		if (!notPrime[i]) {
			p.pb(i);
			for (long long j = i * (long long) i; j < MAXP; j += i) {
				notPrime[j] = true;
			}
		}
	}

	for (int i = 0; i < sz(p); ++i) {
		p3.pb(p[i] * p[i] * p[i]);
	}

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

	sort(a, a + n);
	a[n] = inf64;
	int curNum = 1;
	for (int i = 1; i <= n; ++i) {
		if (a[i] == a[i - 1]) {
			curNum++;
		} else {
			num.pb(mp(a[i - 1], curNum));
			curNum = 1;
		}
	}

	int res = 0;
	for (int i = 0; i < sz(num); ++i) {
		if (num[i].fs == 1) {
			res += 2 * min(num[i].sc, 1);
		} else {
			long long tmp = getInv(num[i].fs);
			int id = lower_bound(num.begin(), num.end(), mp(tmp, 0)) - num.begin();
			if (num[id].fs == tmp) {
				res += max(num[i].sc, num[id].sc);
			} else {
				res += 2 * num[i].sc;
			}
		}
	}
	res /= 2;

   	cout << res << endl;

	return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int n,x,t;
  cin >> n >> x >> t;
  cout << ((n+x-1)/x)*t << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <string.h>

int main(){
    int k;
    char s[101];

    scanf("%d", &k);
    scanf("%s", s);

    int n;
    n = strlen(s);
    if(n <= k){
        printf("%s", s);
    }else{
        /*for(int i = 0; i < k; i++){
            printf("%s", s[i]);
        }*/
        s[k] = '\0';
        printf("%s...", s);
    }
    }

Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector< vector<int> > edge(N+1);
	int s,t;
	for (int i = 0; i < N-1; ++i) {
		cin >> s >> t;
		edge[s].push_back(t);
		edge[t].push_back(s);
	}
	vector<int> color(N+1,0);
	color[1] = 1;
	color[N] = -1;

	int bc,wc;
	bc = wc = 0;
	queue<int> b,w,db,dw;
	b.push(1);
	w.push(N);
	db.push(0);
	dw.push(0);
	int pn,dn = 0;
	while (!b.empty() || !w.empty()) {
		while (!db.empty() && dn == db.front()) {
			pn = b.front();
			b.pop();
			db.pop();
			for (size_t i = 0; i < edge[pn].size(); ++i) {
				if (color[edge[pn][i]] == 0) {
					b.push(edge[pn][i]);
					db.push(dn+1);
					color[edge[pn][i]] = 1;
					++bc;
				}
			}
		}

		while (!dw.empty() && dn == dw.front()) {
			pn = w.front();
			w.pop();
			dw.pop();
			for (size_t i = 0; i < edge[pn].size(); ++i) {
				if (color[edge[pn][i]] == 0) {
					w.push(edge[pn][i]);
					dw.push(dn+1);
					color[edge[pn][i]] = -1;
					++wc;
				}
			}
		}
		++dn;
	}
	if (bc > wc) {
		cout << "Fennec" << endl;
	}
	else {
		cout << "Snuke" << endl;
	}
	return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)

int main(){
    string s; cin >> s;
    int f,e;
    rep(i,s.size()) {
        if(s[i] == 'A') {
        f = i;
        break;
        }
    }
    for(int i = s.size()-1; i>=0; i--){
        if(s[i] == 'Z') {
        e = i;
        break;
        }
    }
    cout << e - f + 1 << endl;
    return 0;
}

Measured memory_bytes: 644
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;

int main() {
	string s;
	cin >> s;
	int n;
	n = s.length();
	
	rep(i, n) {
		cout << "x";
	}
}



Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int n;
    int m;
    vector<int> a;
    
    cin >> n >> m;
    
    for(int i=m/n; i>=1; i--){
        
        if(m%i==0){
            
            cout << i << endl;
            return 0;
            
        }
        
    }
    
    return 0;
    
}

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

using namespace std; 


int main() {
	string s;
	cin >> s;
	int n = s.size();
	if (n%2 == 0){
		cout << "No";
		return 0;
	}
	bool ok = true;
	for (int i = 0; i < n/2; i++) {
		if (s[i] != s[n-1-i]) {
			ok = false;
			break;
		}
	}
	if(!ok){
		cout << "No";
		return 0;
	}
	string s1 = s.substr(0, n/2);
	string s2 = s.substr((n+1)/2, n/2);
	n = n/2;
	// cout << s1 << " " << s2 << endl;
	for (int i = 0; i < n/2; i++) {
		if (s1[i] != s1[n-1-i]) {
			ok = false;
			break;
		}
	}
	for (int i = 0; i < n/2; i++) {
		if (s2[i] != s2[n-1-i]) {
			ok = false;
			break;
		}
	}
	if(!ok){
		cout << "No";
		return 0;
	}
	cout << "Yes";

}

Measured memory_bytes: 256
//51
#include<iostream>
#include<string>
#include<algorithm>
#include<cctype>

using namespace std;

char g[70][71];
string mem[70][70];
int w,h;

bool cmp(string a,string b){
  if(a.size()!=b.size()){
    return a.size()<b.size();
  }else{
    return a<b;
  }
}

string dfs(int y,int x){
  if(y<0||h<=y||x<0||w<=x||isalpha(g[y][x])){
    return "";
  }else if(mem[y][x]!=""){
    return mem[y][x];
  }else{
    mem[y][x]=g[y][x]+max(dfs(y+1,x),dfs(y,x+1),cmp);
    return mem[y][x];
  }
}

int main(){
  while(cin>>w>>h,w|h){
    for(int i=0;i<h;i++){
      cin>>g[i];
    }
    string ans;
    fill(mem[0],mem[70],"");
    for(int y=0;y<h;y++){
      for(int x=0;x<w;x++){
	if(g[y][x]!='0'){
	  ans=max(ans,dfs(y,x),cmp);
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1396
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 101
#define MAXV 100001
ll w[MAXN];
ll v[MAXN];
ll dp[MAXN][MAXV]; // 最小の重さを記録
#define INF 100000000000
int main() {
    int N;
    ll W;
    cin >> N >> W;
    for (int i = 0; i < MAXN; i++) {
        for (int j = 0; j < MAXV; j++) {
            dp[i][j] = INF;
        }
    }
    for (int i = 1; i <= N; i++) {
        cin >> w[i] >> v[i];
    }
    for (int i = 0; i <= v[1]; i++) {
        dp[1][i] = w[1];
    }
    dp[1][0] = 0;
    for (int i = 2; i <= N; i++) {
        for (int j = 0; j <= MAXV; j++){
            if (j >= v[i]) {
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
            }
            else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    ll max = 0;
    for (int i = 0; i <= 100000; i++) {
        //cout << dp[N][i] << endl;
        if (dp[N][i] <= W) {
            max = i;
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 82512
#include <iostream>
#include <set>
#include <string>

using namespace std;

// data
set<string> dict;

int main(){
    // input 
    int n;
    cin >> n;

    string cmd, str;
    while(n--){
        cin >> cmd >> str;

        if(cmd == "insert"){
            dict.insert(str);
        }
        else if(cmd == "find"){
            cout << ((dict.find(str) != dict.end())?"yes":"no") 
                << endl;
        }
    }
}


Measured memory_bytes: 32608
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Prime_Numbers
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());

          
            int nop = 0;

            for (int i = 0; i < num; i++)
            {
                int temp = int.Parse(Console.ReadLine());
                if (temp == 2)
                {
                    
                }
                else
                {
                    for (int j = 2; j*j<=temp; j++)
                    {
                        if (temp % j == 0)
                        {
                            ++nop;
                            break;
                        }
                    }
                }
            }

            Console.WriteLine(num - nop);
        }
    }
}



Measured memory_bytes: 15920
#include<stdio.h>

void QSort(int x[ ], int left, int right);
void Swap(int x[ ], int i, int j);
int main(void);

void QSort(int x[ ], int left, int right)
{
    int i, j;
    int pivot;

    i = left;                      /* ソートする配列の一番小さい要素の添字 */
    j = right;                     /* ソートする配列の一番大きい要素の添字 */

    pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */

    while (1) {                    /* 無限ループ */

        while (x[i] < pivot)       /* pivot より大きい値が */
            i++;                   /* 出るまで i を増加させる */

        while (pivot < x[j])       /* pivot より小さい値が */
            j--;                   /*  出るまで j を減少させる */
        if (i >= j)                /* i >= j なら */
            break;                 /* 無限ループから抜ける */

        Swap(x, i, j);             /* x[i] と x[j]を交換 */
        i++;                       /* 次のデータ */
        j--;
    }
 
    if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
        QSort(x, left, i - 1);     /* 左の配列を Q ソートする */
    if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
        QSort(x, j + 1, right);    /* 右の配列を Q ソートする */
}

  /* 配列の要素を交換する */
void Swap(int x[ ], int i, int j)
{
    int temp;

    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
}



int main(){
  int n,a[200000],k,i,cnt=0,flag=1,box[200000]={},j,box2[200000],temp,sum=0;
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(box[a[i]-1]==0){
      box2[cnt]=a[i];
      cnt++;
    }
    box[a[i]-1]++;
  }

  if(cnt>k){
    QSort(box, 0, n - 1);
    
    for(i=0;i<n-k;i++){
      sum+=box[i];
    }
  }
  printf("%d\n",sum);
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
using namespace std;
#define ll long long
#define INF (int)(1e9+5)
#define MOD (int)(1e9 + 7) 
#define pi 3.14159265

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> ans(n+1, 0);
    for(int i = 1; i <= n; ++i) {
        for(int j = i + 1; j <= n; ++j) {
            int res = INF;
            res = min(res, j - i);
            res = min(res, abs(x - i) + abs(y - j) + 1);
            ans[res]++;
        }
    }
    for(int i = 1; i < n; ++i) cout << ans[i] << '\n';
    return 0;
}



Measured memory_bytes: 3652
N = int(input())
a = list(map(int, input().split()))
x = a[0]
y = sum(a)-a[0]
ans = abs(x-y)
for i in range(1,N-1):
    x += a[i]
    y -= a[i]
    ans = min(ans, abs(x-y))
print(ans)


Measured memory_bytes: 100240
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define fe(x) for(int i=be[x];i;i=e[i].ne)
using namespace std;
int n;long long k;
struct nod{
	int a,b;
	bool operator <(const nod&t)const{
		return a<t.a;
	}
};
nod e[110000];
int main(){
	scanf("%d%lld",&n,&k);
	fo(i,1,n) scanf("%d%d",&e[i].a,&e[i].b);
	sort(e+1,e+n+1);
	fo(i,1,n){
		if (k<=e[i].b){
			printf("%d\n",e[i].a);
			return 0;
		}
		k-=e[i].b;
	}
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,M;
  cin >> N >> M;
  vector<vector<int>> R(M,vector<int>(2));
  vector<int> ans(N);
  for(int i=0;i<M;i++) cin >> R[i][0] >> R[i][1];
  for(int i=0;i<M;i++){
    ans[R[i][0]-1]++;
    ans[R[i][1]-1]++;
  }
  for(int i=0;i<N;i++) cout << ans[i] << endl; 
}

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf
#define sf(n) scanf("%d",&n)
#define sff(n1,n2) scanf("%d %d",&n1,&n2)
#define sfff(n1,n2,n3) scanf("%d %d %d",&n1,&n2,&n3)
#define sl(n) scanf("%lld",&n)
#define sll(n1,n2) scanf("%lld %lld",&n1,&n2)
#define slll(n1,n2,n3) scanf("%lld %lld %lld",&n1,&n2,&n3)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define nl puts("");
#define pb push_back
#define MOD 1000000007
#define fi first
#define se second
#define N 100005
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define sz(x) x.size()
#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >
#define line puts("-------");
#define db(x) cout<<#x<<" :: "<<x<<"\n";
#define dbb(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
typedef long long int ll;
using namespace std;
int main()
{
    int n,m;
    sff(n,m);
    int i,k,now=0;
    ll ans=0;
    unordered_map<int,int>mp;
    mp[0]=1;
    rep0(i,n)
    {
        sf(k);
        now+=k;
        now%=m;
        ans+=mp[now];
        mp[now]++;
    }
    pf("%lld",ans);
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll n;
    cin>>n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    vector<ll> p(n),m(n);
    for (int i = 0; i < n; i++)
    {
        if(i+a[i]<n)
        {
            p[i+a[i]]++;
        }
        if(0<=i-a[i])
        {
            m[i-a[i]]++;
        }
    }
    ll ans=0;
    for (int i = 0; i < n; i++)
    {
        ans+=p[i]*m[i];
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 7980
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007, mod998 = 998244353;

string S;

int main() {
	cin >> S;
	cout << S.front() << S.size() - 2 << S.back() << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextLong()
    val q = sc.nextInt()
    val a = (0 until q).map { sc.next().toInt() }
    println(problem141c(n, q, k, a))
}

fun problem141c(n: Int, q: Int, k: Long, a: List<Int>): String {
    val dp =  LongArray(n)
    for (i in 0 until q) {
        val winner = a[i]
        dp[winner - 1] = dp[winner - 1] + 1
    }
    val sb = StringBuilder()
    for (element in dp) {
        sb.append((if (q - k >= element) "No" else "Yes") + "\n")
    }
    return sb.toString()
}

Measured memory_bytes: 49936
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/
#define fast            ios_base::sync_with_stdio(false)
#define mems(x, y)      memset(x, y, sizeof x)
#define pii             pair < int, int >
#define prec(x)         << fixed << setprecision(x)
#define itf             it->first
#define its             it->second
#define it(x)           it = x.begin(); it != x.end(); it++
#define pq_max(x)       priority_queue < x >
#define pq_min(x)       priority_queue < x, vector < x >, greater < x > >
#define ll              long long
#define nl              << "\n"
#define spc             << " "
#define pb              push_back
#define inf             0x3f3f3f3f
#define PI              3.14159265358979323846
#define E               2.71828182845904523536
#define gamma           0.5772156649
#define EPS             1e-9
#define toint(st, x)    stringstream ss(st); ss >> x
// =======Debug========//
#define watch(x)        cout << (#x) spc << x nl
//int fx[] = {1, -1, 0, 0};
//int fy[] = {0, 0, 1, -1};
const int mod=1e9+7;
const ll mxn=2e5+9;
int cases = 1;
//ll BigMod(ll n,ll power) {ll ans=1;assert(power>=0);n%=mod;while(power>0){if(power&1) ans=(ans*n)%mod;n=(n*n)%mod;power>>=1;}return ans%mod;}
//ll ModInverse(int n)  { return BigMod(n, mod - 2); }
int n;
double probability[3003];
double dp[3003][3003];
double func(int i, int heads)
{
	
	if(i >= n)	{
		int tails = n - heads;
		if(heads > tails)		return 1.0;
		else return 0.0;
	}
	if(dp[i][heads] != -1.0)		return dp[i][heads];
	
	double temp1 = probability[i] * func(i + 1, heads + 1);
	double temp2 = (1.0 - probability[i]) * func(i + 1, heads);
	return dp[i][heads] = temp1 + temp2;
}
int main()
{
	//    freopen("input.txt", "r", stdin);
    //    freopen("out.txt", "w", stdout);
    cin >> n;
    for(int i = 0; i < n; i++)		cin >> probability[i];
    
    for(int i = 0; i < n; i++)	for(int j = 0; j <= n; j++)		dp[i][j] = -1.0;
    double ans = func(0, 0);
	
    cout prec(10) << ans nl;
    
    return 0;
	
}

Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  ll n,a;
  cin>>n>>a;
  ll x[n];
  rep(i,n) cin>>x[i];
  sort(x, x + n);
  ll mx = max(a, x[n-1]);
  ll dp[n+1][n+1][mx * n + 1];
  rep(i,n + 1) {
    rep(j, n + 1) {
      rep(k, mx * n + 1) {
        if(i == 0 && j == 0 && k == 0) {
          dp[i][j][k] = 1;
        } else if(i >= 1 && k < x[i-1]) {
          dp[i][j][k] = dp[i-1][j][k];
        } else if(i >= 1 && j >= 1 && k >= x[i-1]) {
          dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k - x[i-1]];
        } else {
          dp[i][j][k] = 0;
        }
      }
    }
  }
  ll ans = 0;
  for(ll l = 1; l <= n; l++) {
    ans += dp[n][l][a * l];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 51072
def main():
    n_ansl = [0]*(2*(10**5))
    for i in range(1,2*(10**5)):
    # for i in range(1,20):
        cnt = 0
        one_cnt = bin(i).count("1")
        rem = i
        while rem != 0:
            one_cnt = bin(rem).count("1")
            rem = rem%one_cnt   
            cnt += 1
        n_ansl[i] = cnt
 
    n = int(input())
    x = list(input())
    one_cnt = x.count('1')

    if one_cnt == 0:
        for i in range(n):
            print(1)
        exit()
    
    curr_2b_p = 1
    curr_2b_m = 1
    curr_sum_p1 = 0
    curr_sum_m1 = 0
    for i in range(n-1, -1, -1):
        if x[i] == '1':
            curr_sum_p1 += curr_2b_p
            curr_sum_m1 += curr_2b_m
            curr_sum_p1%=(one_cnt+1)
            if one_cnt > 1:
                curr_sum_m1%=(one_cnt-1)
        curr_2b_p*=2
        curr_2b_m*=2
        curr_2b_p%=(one_cnt+1)
        if one_cnt > 1:
            curr_2b_m%=(one_cnt-1)
 
        
 
    curr_2b_p = 1
    curr_2b_m = 1
    ansl = [0]*(n)
    for i in range(n-1, -1, -1):
        if x[i] == '1':
            diff = (-1)*curr_2b_m
            if one_cnt > 1:
                ans = (curr_sum_m1 + diff)%(one_cnt-1)
                ansl[i] = n_ansl[ans]+1
            else:
                ansl[i] = 0
        else:
            diff = curr_2b_p
            ans = (curr_sum_p1 + diff)%(one_cnt+1)
            ansl[i] = (n_ansl[ans]+1)
        curr_2b_p*=2
        curr_2b_m*=2
        curr_2b_p%=(one_cnt+1)
        if one_cnt > 1:
            curr_2b_m%=(one_cnt-1)
 
 
    # print(ansl)
    for a in ansl:
        print(a)
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 93376
#include <iostream>
#define ll long long

using namespace std;

ll thick[55];
ll patty[55];

ll dfs(int n, ll x) {
    if (n == 0) {
        return (x <= 0) ? 0 : 1;
    }
    else if (x <= thick[n - 1] + 1) {
        return dfs(n - 1, x - 1);
    }
    else if (x <= thick[n]) {
        return 1 + patty[n - 1] + dfs(n - 1, x - 2 - thick[n - 1]);
    }
    else {
        return patty[n];
    }
}

int main() {
    int n;
    ll x;
    cin >> n >> x;
    thick[0] = 1;
    patty[0] = 1;

    for (int i = 1; i < n + 1; i++) {
        thick[i] = 2 * thick[i - 1] + 3;
        patty[i] = 2 * patty[i - 1] + 1;
    }

    cout << dfs(n, x) << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,d,x;
  int a;
  cin >> n >> d >>x;
  REP(i,n){
      cin >> a;
      int cnt = 0;
      while(cnt*a+1<=d)cnt++;
      x += cnt;
  }
  cout << x << endl;
}


Measured memory_bytes: 256
n=int(input())  
A=list(map(int, input().split())) 
B=list(map(int, input().split())) 
C=list(map(int, input().split())) 
full_mind = sum(B)
plus_mind = 0
for i in range(len(A)-1):
    if A[i+1] - A[i] == 1:
        #print(A[i], A[i+1])
        #print(C[A[i]-1])
        plus_mind += C[A[i]-1]
full_mind += plus_mind
print(full_mind)

Measured memory_bytes: 3064
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
import Data.Bits

main :: IO ()
main = do
  (a:b:_) <- fmap (map read . words) getLine :: IO [Integer]
  print $ solve' a b

solve a b = foldl' xor 0 [a..b]

xors x = foldl' xor 0 [0..x]

solve' a b = xors' b `xor` xors' (a - 1)

xors' x 
  | x `mod` 4 == 0 = x
  | x `mod` 4 == 1 = 1
  | x `mod` 4 == 2 = x + 1
  | x `mod` 4 == 3 = 0


Measured memory_bytes: 508
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN=100005;
 
int N;
vector<int> adj[MAXN];
int col[MAXN];
 
bool dfs(int u,int f)
{
    if(adj[u].size()==1U)
    {
        col[u]=0;
        return false;
    }
    int cnt[2]={0};
    for(int i=0;i<(int)adj[u].size();i++)
    {
        int v=adj[u][i];
        if(v==f)
            continue;
        if(dfs(v,u))
            return true;
        cnt[col[v]]++;
    }
    if(cnt[0]>=2)
        return true;
	if(f==0&&(int)adj[u].size()==cnt[1])
		return true;
    if(cnt[0])
        col[u]=1;
    else
        col[u]=0;
    return false;
}
 
int main()
{
    scanf("%d",&N);
    for(int i=1;i<N;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    if(N==2)
        puts("Second");
    else
    {
        bool ans;
        for(int i=1;i<=N;i++)
            if(adj[i].size()>1U)
            {
                ans=dfs(i,0);
                break;
            }
        puts(ans?"First":"Second");
    }
 
    return 0;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long A,B,C,K;
    scanf("%lld%lld%lld%lld",&A,&B,&C,&K);
    if(K<=A){
       printf("%lld\n",K);
    }
    else if(K<=A+B){
        printf("%lld\n",A);
    }
    else{
        printf("%lld\n",A-(K-A-B));
    }
    return 0;
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
#define lli long long int
using namespace std;


int maxn = 2*100001;

lli T[4*2*100001];
lli S[4*2*100001];
lli E[4*2*100001];

void build(lli node,lli l,lli r)
{
    S[node] = l;
    E[node] = r;
    if(l == r)
    {
        T[node] = 0;
        return;
    }
    lli m = l + (r-l)/2;
    build(2*node,l,m);
    build(2*node+1,m+1,r);
    T[node] = max(T[2*node] , T[2*node+1]);
    return;
}

void update(lli node,lli x,lli i)
{
    if(S[node] == E[node])
    {
        T[node] = x;
        return;
    }
    if(i <= E[2*node])
        update(2*node,x,i);
    else
        update(2*node+1,x,i);
    T[node] = max(T[node*2] , T[2*node+1]);
}

lli get(lli node , lli l,lli r)
{
    if(r < S[node] || E[node] < l)
        return LLONG_MIN;
    if(l<=S[node] && E[node] <= r)
    {
        return T[node];
    }
    lli ret = LLONG_MIN;
    ret = max(ret , get(node*2,l,r));
    ret = max(ret , get(2*node+1,l,r));
    return ret;
}

int main()
{
    int n;
    cin>>n;
    lli h[n];
    lli a[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    for(int i=0;i<n;i++)
        cin>>a[i];
    build(1,0,n-1);
    lli dp[n];
    lli ret = LLONG_MIN;
    for(lli i=0;i<n;i++)
    {
        dp[i] = a[i] + get(1,0,h[i]-1);
       // cout<<dp[i]<<endl;
        update(1,dp[i],h[i]-1);
      /*  for(int j=0;j<10;j++)
            cout<<T[j]<<" ";
        cout<<endl;*/
        ret = max(ret,dp[i]);
    }
    cout<<ret;

}


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

using ll = long long;

ll sum(ll N){
  return N*(N+1)/2;
}

int main(){

  int N;
  cin >> N;

  ll g = N*(N+1)/2;

  ll ans=0;
  for(ll i=1;i<=N;i++){
    ans+=i*sum(ll(N/i));
  }

  cout << ans << endl;
}

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

int main()
{
  int D, T, S;

  cin >> D >> T >> S;

  if(1.0*D/S <= T){
    cout << "Yes\n";
  }
  else{
    cout << "No\n";
  }

  return 0;
}

Measured memory_bytes: 3628
N = gets.chomp.to_i

S = gets.chomp.split("")

def include_both(a1, a2)
  a1.sort!.uniq!
  a2.sort!.uniq!

  count = 0

  for i in 0...a1.length do
    for j in 0...a2.length do
      if a1[i] == a2[j] then
        count += 1
        break
      end
    end
  end
  
  count
end

max = 0
for i in 1...N do
  s1 = S[0, i]
  s2 = S[i, N-1]

  max = [max, include_both(s1, s2)].max
end

puts max

Measured memory_bytes: 1916
#include <iostream>
#include <vector>
using namespace std;
const int ub=1e6;

int main(){
	vector<bool> prime(ub, true);
	vector<int> numprime(ub, 0);
	for(int i=2; i<ub; i++){
		if(prime[i]){
			numprime[i] = numprime[i-1]+1;
			for(int j=2; i*j<ub; j++){
				prime[i*j]=false;
			}
		}else{
			numprime[i] = numprime[i-1];
		}
	}
	
	int n;
	while(cin>>n){
		cout << numprime[n] << endl;
	}
	return 0;
}

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

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

    int move = 0;
    if(a + w < b){
        move = b - (a + w);
    }else if(b + w < a){
        move = a - (b + w);
    }else{
        move = 0;
    }

    cout << move << endl;
}

Measured memory_bytes: 256
#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 sol(ll n) {
    if (n == 1) return 1;
    return sol(n / 2) * 2 + 1;
}

int main() {
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    cout << sol(n);
}


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

const int MAX = 999999;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll nCr(int n, int r) {
    ll ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

int main(){
  COMinit();
  ll x, y;
  cin >> x >> y;
  ll yy = x/2;
  ll cnt = 0LL;
  ll ans;
  if(x % 2 == 0){
    if((y - x/2) % 3 !=0 ){
      ans = 0LL;
    }else{
      cnt = (y - x/2) / 3;
      ans = COM(x/2+cnt, 2*cnt);
    //  return 0;
    }
  }else{
    if((y - ((x+1)/2+1))% 3 != 0){
      ans = 0LL;
    }else{
      cnt = (y - (x+1)/2+1) / 3;
      ans = COM((x+1)/2+cnt, 2*cnt+1);
    }
  }
  cout << ans %  MOD<< endl;

}


Measured memory_bytes: 23680
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#include <numeric>

using namespace std;

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

using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long mod = 1e9 + 7;

long power(long a, long b) { return b ? power(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, K;
    cin >> N >> K;
    long dp[100100];
    long res = 0;
    for (int k = K; k >= 1; k--)
    {
        dp[k] = power(K / k, N);
        for (int j = 2 * k; j <= K; j += k)
            dp[k] -= dp[j];
        res += k * dp[k] % mod;
        res = (res + mod) % mod;
    }

    cout << res << "\n";
}

Measured memory_bytes: 4392
n, m, x = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(n)]
INF = 10 ** 9 + 7

ans = INF
for bits in range(2 ** n):
    cost = 0
    score = [0] * m
    for i, book in enumerate(books):
        if bits >> i & 1:
            cost += book[0]
            score = [s + b for s, b in zip(score, book[1:])]
    if all(s >= x for s in score):
        ans = min(ans, cost)

if ans == INF:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9204