akhauriyash/Code-Regression huggingface dataset:
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

bool isReachable(string s, int fm, int to) {
    assert(s[fm] == '.' && s[to] == '.');
    int p = fm;
    while (p < to) {
        if (p + 2 <= to && s[p + 2] == '.') p += 2;
        else if (s[p + 1] == '.') p++;
        else return false;
    }
    return true;
}

bool findJumpPoint(string s, int lo, int hi) {
    int n = cast(int)s.length;
    for (int i = lo; i <= hi; i++) {
        if (i + 2 >= n) break;
        if (s[i..i+3] == "...") return true;
    }
    return false;
}

bool calc(string s, int a, int b, int c, int d) {
    int n = cast(int)s.length;
    bool reachOk = isReachable(s, a, c) && isReachable(s, b, d);
    // a, b の移動は独立している
    if (c < d) return reachOk;
    // a は b を追い越す必要がある
    return reachOk && findJumpPoint(s, b-1, d-1);
}

void main() {
    int n, a, b, c, d; scan(n, a, b, c, d);
    string s = read!string;
    writeln(calc(s, a-1, b-1, c-1, d-1) ? "Yes" : "No");
}


Measured memory_bytes: 2556
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int h = scan.nextInt();
    int w = scan.nextInt();
    int n = scan.nextInt();
    int[] c = new int[n];
    for (int i=0;i<n;i++){
      c[i] = scan.nextInt();
    }

    ArrayList<ArrayList<Integer>> a = new ArrayList<ArrayList<Integer>>();
    for (int i=0;i<h;i++){
      ArrayList<Integer> b = new ArrayList<Integer>();
      a.add(b);
    }

    int f = 1;
    int current = 0;

    for (int i=0;i<n;i++){
      int count = c[i];
      while (count > 0){
        ArrayList<Integer> g = a.get(current);
        g.add(i+1);

        current += f;
        if (current == h){
          current = h-1;
          f = -1;
        }

        if (current == -1){
          current = 0;
          f = 1;
        }

        count -= 1;
      }
    }

    for (int j=0;j<h;j++){
      ArrayList<Integer> m = a.get(j);
      for (int k=0;k<w-1;k++){
        System.out.print(m.get(k) +" ");
      }
      System.out.println(m.get(w-1));
    }




  }

}


Measured memory_bytes: 48628
#include<iostream>
main(){
  std::string s;
  std::cin>>s;
  int n=s.size();
  for(int i=0;i<n-1;++i){
    if(s[i]=='A'&&s[i+1]=='C'){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
}


Measured memory_bytes: 256
// Problem : C - XYZ Triplets
// Contest : AtCoder - AIsing Programming Contest 2020
// URL : https://atcoder.jp/contests/aising2020/tasks/aising2020_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

int ans[maxN];

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	// 1/2((x + y)^2 + (x + z)^2 + (y+z)^2)
	cin.tie(0); cout.tie(0);
	FOR(x, 1, 100) {
		FOR(y, 1, 100) {
			FOR(z, 1, 100) {
				ans[x * x + y * y + z * z + x * y + x * z + z * y]++;
			}
		}
	}
	int n;
	cin >> n;
	RI(i, n) cout << ans[i] << "\n";
	return 0;
}
 


Measured memory_bytes: 3844
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>

using namespace std;

void solve()
{
	string s;
	cin >> s;
	stack<char> st;
	for (int i = 0; i < s.size(); ++i)
	{
		if (s[i] == '0')
		{
			st.push('0');
		}
		else if (s[i] == '1')
		{
			st.push('1');
		}
		else if (s[i] == 'B')
		{
			if (!st.empty())
			{
				st.pop();
			}
		}
	}
	string ans = "";
	while (!st.empty())
	{
		ans += st.top();
		st.pop();
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;
	string ans = "No";
	if (n % 2 == 1) {
		cout << ans << endl;
		return 0;
	}
	ans = "Yes";
	rep(i, n/2) {
		if (s[i] != s[i + (n / 2)]) {
			ans = "No";
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
x = int(input())
l = int(x/105)
u = int(x/100)+1
flag = False
for n in range(l, u):
    for a in range(0, u):
        for b in range(0, u-a):
            for c in range(0, u-a-b):
                for d in range(0, u-a-b-c):
                    for e in range(0, u-a-b-c-d):
                        for f in range(0, u-a-b-c-d-e):
                            if 100*a + 101*b + 102*c + 103*d + 104*e + 105*f == x:
                                #print(a,b,c,d,e,f)
                                flag = True
                                break
                            if flag == True: break
                        if flag == True: break
                    if flag == True: break
                if flag == True: break
            if flag == True: break
        if flag == True: break
    if flag == True: break

if flag:
    print('1')
else:
    print('0')

Measured memory_bytes: 3064
#include <stdio.h>

#define ll long long

int main()
{
	ll n, sum,i;
	scanf("%lld",&n);
	
	ll n3,n5,n15;
	n3 = n/3; 
	n5 = n/5;
	n15 = n/15;
	
	sum = (n*(n+1)-n3*(3*n3+3)-n5*(5*n5+5)+n15*(15*n15+15))/2;
	printf("%lld\n",sum);
	
	return 0;
}


Measured memory_bytes: 1728
#include <stdio.h>
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <list>
#include <map>

#define FORi(N) for(ll i=0;i<N;++i)
#define FORj(N) for(ll i=0;i<N;++i)
#define FABi(a,b) for(ll i=a;i<=b;++i)

using namespace std;
using ll = long long;
using ld = long double;
int main(){
  ll N,K;
  cin>>N>>K;
  vector<vector<ll>> sushi;
  FORi(N){
    vector<ll> tmp(3);
    cin>>tmp[0]>>tmp[1];//ネタ・おいしさ
    sushi.push_back(tmp);
  }
  sort(sushi.begin(),sushi.end(),[](vector<ll> a,vector<ll> b){
    return a[1]>b[1];
  });
  map<ll,ll> select;//種類・その個数
  list<ll> sellist;//選んだsushiの添字
  ll oisisum=0;//おいしさ合計
  ll syurui=0;
  ll manzokumax=0;
  FORi(K){
    ll neta=sushi[i][0];
    oisisum+=sushi[i][1];
    if(select.find(neta)==select.end()){
      sellist.insert(sellist.begin(),i);
      select[neta]=1;
      syurui++;
    }else{
      sellist.push_back(i);
      select[neta]++;
    }
  }
  manzokumax=syurui*syurui+oisisum;
  for(ll i = K;i<N;++i){
    ll neta=sushi[i][0];
    if(select.find(neta)!=select.end())continue;
    ll rmsushi=sellist.back();
    ll rmneta=sushi[rmsushi][0];
    if(select.find(rmneta)->second==1ll)break;
    select[rmneta]--;
    oisisum-=sushi[rmsushi][1];
    sellist.pop_back();
    select[neta]=1;
    sellist.insert(sellist.begin(),i);
    oisisum+=sushi[i][1];
    syurui++;
    
  	manzokumax=max(manzokumax,syurui*syurui+oisisum);
    
  }
  cout<<manzokumax<<endl;
  return 0;
}

Measured memory_bytes: 12592
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = (x << 1) + (x << 3) + (ch & 15);
		ch = getchar();
	}
	return f == 1 ? x : (-x);
}
int main() {
	long long a, b;
	cin >> a >> b;
	cout << ceil((double)(b - 1) / (a - 1)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,b[52],i,j;
	char a[52];
	scanf("%d", &n);
	for(i=0; i<n; i++)
	scanf("%s %d", &a[i], &b[i]);
	for(i=1; i<14; i++)
	{
		for(j=0; j<n; j++)
		{
			if(a[j]=='S'&&i==b[j])
			break;
			if(j==n-1)
			printf("S %d\n", i);
		}
	}
	for(i=1; i<14; i++)
	{
		for(j=0; j<n; j++)
		{
			if(a[j]=='H'&&i==b[j])
			break;
			if(j==n-1)
			printf("H %d\n", i);
		}
	}
	for(i=1; i<14; i++)
	{
		for(j=0; j<n; j++)
		{
			if(a[j]=='C'&&i==b[j])
			break;
			if(j==n-1)
			printf("C %d\n", i);
		}
	}
	for(i=1; i<14; i++)
	{
		for(j=0; j<n; j++)
		{
			if(a[j]=='D'&&i==b[j])
			break;
			if(j==n-1)
			printf("D %d\n", i);
		}
	}
	
	return 0;
}


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

int main(){
    int X, Y;
    cin >> X >> Y;
    int ans = 0;
    if(X <= 3) ans += (4-X)*100000;
    if(Y <= 3) ans += (4-Y)*100000;
    if(X == 1 && Y == 1) ans += 400000;
    cout << ans << endl;
    return 0;
}


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

int main() {
    int n; cin >> n;
    vector<int> v(n, 0);

    int s = 0;

    for(int i = 0; i < n; ++i) {
        cin >> v[i];
        s ^= v[i];
    }
    
    vector<int> used(n, 0);
    int ans = 0;
    for(int bit = 29; bit >= 0; --bit) {
        if((1 << bit) & s) {
            ans++;
            bool has = false;
            for(int i = 0; i < n; ++i) {
                if(not used[i] && (v[i] & (-v[i])) == (1 << bit)) {
                    has = true;
                    used[i] = 1;
                    s ^= ((1 << bit) - 1);
                    s ^= (1 << bit);
                    break;
                }
            }
            if(not has) {
                cout << "-1";
                return 0;
            }
        }
    }

    cout << ans << "\n";
}

Measured memory_bytes: 1024
N, M = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(M)]
 
# 10^(N-1)から10^Nの数を順に調べる
# N=1の場合のみ、0から10であることに注意
if N == 1:
  a, b = 0, 10
elif N >= 2:
  a, b = 10**(N-1), 10**N

ans = -1
for i in range(a, b):
  tmp = str(i)
  flag = True
  for j in range(M):
    if tmp[arr[j][0]-1] != str(arr[j][1]):
      flag = False
  if flag:
    ans = i
    break

print(ans)
 
# Memo: 0からNの中でM個の条件全てを満たす整数を求めるときは、以下のようにする
'''
a = -1
for i in range(N):
  flag = True
  for j in range(M):
  　　if 条件を満たさない: flag = False
  if flag:
    a = i
    break
print(i)
'''

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

int main(){
  int K,A[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin>>K;
  cout<<A[K-1]<<endl;
}

Measured memory_bytes: 256
let input () =
let (n,m) = Scanf.sscanf (read_line ()) "%d %d" (fun a b -> (a,b)) in
let rec loop count list =
  match count with
    0 -> list
  | x -> let (a,b) = Scanf.sscanf (read_line ()) "%d %d" (fun a b -> (a,b)) in
          loop (count - 1) ((a,b)::list)
in (m,loop n []);;

let solve () =
  let (m, list) = input() in
  let sort_list = List.sort (fun (a,_) (b,_) -> if a > b then 1 else -1) list in
  let rec loop ans m l =
    let (a,b) = List.hd l in
    if m > b then
      loop (ans + (a*b)) (m-b) (List.tl l)
    else print_int (ans + m*a)
  in loop 0 m sort_list;;

solve();;

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl
#define rep(n, i) for (int i = 0; i < n; i++)

using namespace std;
using i64 = long long;

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

    i64 ans;

    if (a * c >= 0LL || b * d >= 0LL)
    {
        ans = max(a * c, b * d);
    }
    else
    {
        ans = max(a * d, b * c);
    }

    cout << ans << endl;

    return 0;
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    string s, t; cin >> s >> t;
    REP(i, 0, s.size()){
        if(s[i] != t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3628
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;


int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n);
	for (int i = 0; i < n; i++) cin >> a.at(i);
	for (int i = 0; i < n; i++) cin >> b.at(i);
	for (int i = 0; i < n; i++) cin >> c.at(i);
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		long long ka = lower_bound(a.begin(), a.end(), b.at(i)) - a.begin();
		long long kc = n - (upper_bound(c.begin(), c.end(), b.at(i))-c.begin());
		ans += ka * kc;
	}
	cout << ans << endl;
}

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

int main()
{
	int A, B, C, D, answer = 0;
	bool AliceOn[110] = {false}, BobOn[110] = { false };

	cin >> A >> B >> C >> D;
		
	for (int i = 0; i <= 100; i++) {
	
		if (A <= i && i <= B) AliceOn[i] = true;
		if (C <= i && i <= D) BobOn[i] = true;
	}


	for (int i = 0; i <= 100; i++) {
	
		if (AliceOn[i] && BobOn[i]) answer++;
	
	}
	
	cout << max(0, answer - 1)  << endl;

	return 0;
}

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


int main() {
	int A, B,X, k;

	cin >> A >> B >> X;
	if (A > X) {
		cout << "NO" << endl;
	}

	else if (X - A <= B) {
		cout << "YES" << endl;
	}
	else if(X-A>B){
		cout << "NO"<< endl;
	}

	system("pause");
}


Measured memory_bytes: 504
#include <iostream>
using namespace std;
using ll = long long;
template <class T> inline ll pow(T x, T n) {
  if(n == 0) {
    return 1;
  }
  if(n == 1) {
    return x;
  }
  if(n % 2 == 0) {
    auto xx = pow(x, n / 2);
    return xx * xx;
  } else {
    auto xx = pow(x, n - 1);
    return xx * x;
  }
}
int main() {
  ll N, K;
  cin >> N >> K;
  cout << K * pow(K - 1, N - 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, int> PL;
constexpr ll INF = (1LL << 60);
int main() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  s--; t--;
  vector<vector<P>> g1(n), g2(n);
  rep(i,m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--; v--;
    g1[u].emplace_back(make_pair(v, a));
    g1[v].emplace_back(make_pair(u, a));
    g2[u].emplace_back(make_pair(v, b));
    g2[v].emplace_back(make_pair(u, b));
  }

  auto dijkstra = [&](int f, vector<vector<P>> &g) {
    vector<ll> dp(n, INF);
    priority_queue<PL, vector<PL>, greater<PL>> que;
    dp[f] = 0;
    que.push(make_pair(0LL, f));
    while (!que.empty()) {
      auto p = que.top(); que.pop();
      int u = p.second;
      if (dp[u] < p.first) continue;
      for (auto e : g[u]) {
        int v = e.first;
        if (dp[v] > dp[u] + e.second) {
          dp[v] = dp[u] + e.second;
          que.push(make_pair(dp[v], v));
        }
      }
    }
    return dp;
  };

  ll mx = 1e15;
  auto ds = dijkstra(s, g1);
  auto dt = dijkstra(t, g2);
  ll cur = INF;
  vector<ll> res;
  for (int i = n - 1; i >= 0; i--) {
    cur = min(cur, ds[i] + dt[i]);
    res.emplace_back(mx - cur);
  }
  for (int i = n - 1; i >= 0; i--) cout << res[i] << endl;
  return 0;
}


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

namespace ABC111 {
	class ABC111_A {
		static void Main(string[] args) {
			var input = Console.ReadLine();
			var sb = new StringBuilder();
			foreach (var c in input) {
				if(c == '1') {
					sb.Append("9");
					continue;
				}
				if(c == '9') {
					sb.Append("1");
					continue;
				}
			}
			Console.WriteLine(sb.ToString());
		}
	}
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;cin>>n>>m;
	vint f(10, 0);
	vint h = {-10000, 2, 5, 5, 4, 5, 6, 3, 7, 6};
	vint dp(10002, -100000);
	rep(i, m){
		int a;cin>>a;
		f[a] = 1;
		//chmax(dp[h[a]], a);
	}
	dp[0] = 0;
	reps(i, n+1){
		reps(j, 10){
			if(f[j] == 1){
				if(i-h[j] >= 0&& dp[i-h[j]] >= 0){
					chmax(dp[i], dp[i-h[j]]+1);
				}
			}
		}
	}
	int k = dp[n];
	//cout << k << endl;
	rep(i, k){
		for(int j = 9;j > 0;j--){
			if(f[j] == 1&&n-h[j] >= 0&&dp[n-h[j]]==k-1-i){
				//cout << j << ' ' << n << endl;;
				n -= h[j];
				cout << j;
				break;
			}
		}
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string S ;
    char a , b , c , s ;
     cin >> S ;
    a = S[0] ;
    b = S[1] ;
    c = S[2] ;
    s = S[3] ;

    if (a == b || b == c || c == s )
    {
            cout << "Bad"  << endl;

    }
    else
    {
            cout << "Good" << endl;

    }
    return 0;
}


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


int main()
{
    ll n;
    cin >> n;
    string s, t;
    cin >> s;
    if(n % 2 != 0){
        cout << "No" << endl;
        return 0;
    }
    t = s.substr(n / 2);
    if(s != t + t){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;



}

Measured memory_bytes: 256
#include <iostream>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


int N, K, X, Y;

int main(void) {
  cin >> N >> K >> X >> Y;
  cout << (N > K ? K * X + (N - K) * Y : N * X) << endl;

  return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    string s,t;
    cin>>s>>t;
    vector<set<int>> set(26);
    rep(i,0,s.size()){
        int idx=s[i]-'a';
        set[idx].insert(i);
    }
    ll a=0,b=0;
    rep(i,0,t.size()){
        int idx=t[i]-'a';
        if(set[idx].empty()){
            cout<<-1<<endl;
            return 0;
        }
        auto p=set[idx].lower_bound(b);
        if(p==set[idx].end())b=0,a++,p=set[idx].lower_bound(b);
        b=*p;
        b++;
    }
    cout<<a*s.size()+b<<endl;
    return 0;
}




Measured memory_bytes: 5120
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif



int count_div(int n, int m) {
    int cnt = 0;
    while(n % m == 0){
        n /= m;
        cnt++;
    }
    return cnt;
}

int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll D, N; cin >> D >> N;

    ll M = 1;
    REP(i, D) M *= 100;

    ll ans = 0;
    int j = 0;
    FOR(i,1,(N+2)*M) {
        if (count_div(i,100) == D) j++;
        
        if (j == N) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

    int n = s.nextInt();
    int k = s.nextInt();
//    System.out.println(n - k);
//    System.out.println((n - k) / (k - 1));
//    System.out.println((n - k) % (k - 1) > 0 ? 1 : 0);
    System.out.println(
      1 + 
      ((n - k) / (k - 1)) + 
      (((n - k) % (k - 1)) > 0 ? 1 : 0)
    );
/*
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = s.nextInt();
    }

    int minIndex = -1;
    for (int i = 0; i < n; i++) {
      if (a[i] == 1) {
        minIndex = i;
        break;
      }
    }
*/
    
  }
}


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

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadIntArray();
	int h = tmp[0], w = tmp[1];

	string[] ss = new string[h];

	for (int i = 0; i < h; i++)
	{
	    ss[i] = ReadLine();
	}

	// check columns
	bool[] cols = new bool[w];
	for (int i = 0; i < w; i++)
	{
	    cols[i] = false;
	    for (int j = 0; j < h; j++)
	    {
		char c = ss[j][i];
		if (c == '#')
		{
		    cols[i] = true;
		    break;
		}
	    }
	}

	// print
	for (int i = 0; i < h; i++)
	{
	    string s = ss[i];

	    bool rowcheck = false;
	    for (int j = 0; j < w; j++)
	    {
		if (s[j] == '#')
		{
		    rowcheck = true;
		    break;
		}
	    }
	    if (!rowcheck){ continue; }

	    for(int j = 0; j < w; j++)
	    {
		if (cols[j])
		{
		    Write(s[j]);
		}
	    }
	    Write("\n");
	}
    }
}


Measured memory_bytes: 13396
n,l  =map(int,input().split())
apples = [l+i-1 for i in range(1,n+1) ]
ideal= sum(apples)
res = 10**9
for x in apples:
    v = ideal - x
    if res > abs(v-ideal):
        res = abs(v-ideal)
        ans = v

    
    

print(ans)


    

Measured memory_bytes: 38256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BPolygon solver = new BPolygon();
        solver.solve(1, in, out);
        out.close();
    }

    static class BPolygon {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int max = 0, sum = 0;
            for (int i = 0; i < n; i++) {
                int s = in.nextInt();
                max = Math.max(max, s);
                sum += s;
            }

            boolean answer = (sum - max) > max;

            out.println(answer ? "Yes" : "No");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23252
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>
#include <vector>
#include <string>
#include <queue>

using namespace std;

int x[1111], y[1111];

double mxx = 1000;
double mxy = 1000;
double mnx = 0;
double mny = 0;
int n;
int pre = 1000;

double calc(double xx, double yy) {
    double r = 0;
    for (int i = 0; i < n; i++) {
        double dx = x[i] - xx;
        double dy = y[i] - yy;
        r = max(r, dx * dx + dy * dy);
    }
    return r;
}

double calc_f(double x) {
    int y_iter = pre;
    double mny_c = mny;
    double mxy_c = mxy;
    while (y_iter--) {
        double dy = (mxy_c - mny_c) / 3.0;
        double y1 = mny_c + dy;
        double y2 = mxy_c - dy;
        double r1 = calc(x, y1);
        double r2 = calc(x, y2);
        if (r1 > r2) {
            mny_c = y1;
        } else {
            mxy_c = y2;
        }
    }
    return calc(x, mny_c);
}

void solution() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }
    
    int x_iter = pre;
    while (x_iter--) {
        double dx = (mxx - mnx) / 3.0;
        double x1 = mnx + dx;
        double x2 = mxx - dx;
        double r1 = calc_f(x1);
        double r2 = calc_f(x2);
        if (r1 > r2) {
            mnx = x1;
        } else {
            mxx = x2;
        }
    }

    printf("%.15f\n", sqrt(calc_f(mnx)));
}

/*-------------------*/

int main()
{
#ifdef Files
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    /*Test*/
    //freopen("input.txt", "w", stdout);

    double OcZ2X = clock();
#else
    //freopen("joke.in", "r", stdin);
    //freopen("joke.out", "w", stdout);
#endif

    solution();

#ifdef Time
    double P2HxQ = clock();
    printf("\n*** Total time = %.3f sec ***\n", (P2HxQ - OcZ2X) / CLOCKS_PER_SEC);
#endif
}

Measured memory_bytes: 256
/*input
100000
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb emplace_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        int x=i;
        string z=to_string(x);
        if(z.length()%2==1) ++ans;
    }
    cout<<ans;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        PriorityQueue<Double> que = new PriorityQueue<>();
        for(int i=0; i<n; i++){
            que.add((double)sc.nextInt());
        } 

        for(int i=0; i<n-2; i++){
            double v1 = que.poll();
            double v2 = que.poll();
            que.add((v1+v2)/2.0);
        }
        double v1 = que.poll();
        double v2 = que.poll();
        
        System.out.println((v1+v2)/2.0);


    }

    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}


Measured memory_bytes: 21204
//3重ループだと2500^3=1.5625*10^10で間に合わない
//２つの文字の値が決まれば残りの文字の値が１つに決まる
//2500^2=6.25*10^6で間に合う

#include <bits/stdc++.h>
using namespace std;

int main(){
  int k , s;
  cin >> k >> s;
  int count =0;
  
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      if((s-i-j)>=0&&(s-i-j)<=k) count++;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define int              long long
#define ll               long long
#define pii              pair<int,int>
#define pb               push_back
#define all(a)           a.begin(),a.end()
#define print(a)         for(auto b:a)cout<<b<<" ";cout<<endl;
#define endl             '\n'
#define F                first
#define S                second
#define vi               vector<int>
#define sz(s)            (int)s.size()
#define rep(i,a,b)       for(int i=a;i<b;i++)
#define bs               binary_search
#define PI               3.14159265358979323844
#define input(a,n)       for(int i=0;i<n;i++)cin>>a[i];
#define lb               lower_bound
#define ub               upper_bound
#define mapi             map<int,int>
#define point            complex<int>
#define fat              998244353
#define hell             1000000007
#define N                100005
#define ios              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
using namespace __gnu_pbds;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) { 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) { 
    if (x < y) 
        x = y; 
}

int solution()
{
    string s;
    cin>>s;
    if(s[4]==s[5]&&s[2]==s[3])
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
}
 
signed main()
{
ios
int tests=1;
//cin>>tests;
while(tests--)
{
    solution();
}
return 0;
}

Measured memory_bytes: 256
use std::io::{self, Write};

fn main() {
    let mut stdout = io::stdout();
    let stdin = io::stdin();

    let mut input = String::new();
    stdin.read_line(&mut input).expect("failed to read line");
    let n: i32 = input.trim().parse().expect("failed to parse");

    let mut lottery: Vec<String> = Vec::new();
    for _ in 0..n {
        let mut draw = String::new();
        stdin.read_line(&mut draw).expect("failed to read line");
        lottery.push(draw);
    }
    lottery.sort();
    lottery.dedup();
    println!("{}", lottery.len());
    stdout.flush().unwrap();
}


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

int main(){
    int N,M;cin>>N>>M;
    vector<vector<int>> a(N+1);
    vector<pair<int,int>> info(M);
    rep(i,M){
        cin>>info.at(i).first>>info.at(i).second;
        a.at(info.at(i).first).push_back(info.at(i).second);
    }
    rep(i,N+1)sort(a.at(i).begin(),a.at(i).end());
    rep(i,M){
        rep(j,5-log10(info.at(i).first))cout<<0;
        cout<<info.at(i).first;
        int p=lower_bound(a.at(info.at(i).first).begin(),a.at(info.at(i).first).end(),info.at(i).second)
            -a.at(info.at(i).first).begin();
        p++;
        rep(j,5-log10(p))cout<<0;
        cout<<p<<endl;
    }
    return 0;
}

Measured memory_bytes: 7808
# 164
# 高橋君モンスター体力A/攻撃力B
# 青木君ﾓﾝｽﾀｰ体力C/攻撃力D
# 高橋→青木→高橋→青木の順番
# 相手のﾓﾝｽﾀｰの体力を自分のﾓﾝｽﾀｰの攻撃分減らせる。C＝C-B/A=A-D
# どちらかの体力が０以下になるまで戦い続ける。 A<0 B<0
# 先に自分のﾓﾝｽﾀｰの体力が０になった方が負け。
# 高橋君が勝つなら”Yes”負けるなら”No”を出力

A,B,C,D = map(int,input().split())

while A>0 and C>0:
    C = C-B
    A = A-D

if C <= 0:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 9148
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include <iomanip>
#include<algorithm>
#include<vector>
#include <map>
#define rep(i,N) for(int (i)=0;(i) < (N); ++(i))

using namespace std;

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

  int n;
  cin >> n;
  int a[n];

  int max_f = 0;
  int max_s = 0;

  rep(i, n){
    int input;
    cin >> input;
    a[i] = input;
    if(input > max_f){
      int temp = max_f;
      max_f = input;
      max_s = temp;
    }else if(input > max_s){
      max_s = input;
    }
  }

  rep(i, n){
      if(a[i] != max_f){
        cout << max_f << "\n";
      }else{
        cout << max_s << "\n";
      }
  }

  return 0;
}


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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cerr << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cerr << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
template<typename T = int>
T in() {T a; cin >> a; return a;}
/***** MAIN *****/
signed main() {
  int n; cin >> n;
  vector<bitset<32>> v(n);
  int tmp;
  REP(i,n) {
    cin >> tmp;
    v[i] = bitset<32>(tmp);
  }
  vector<bitset<32>> ans(n);
  REP(i,32) {
    int counter = 0;
    REP(j,n) {
      if(v[j][i]) ++counter;
    }
    REP(j,n) {
      if(v[j][i]) {
        if(counter%2) ans[j].reset(i);
        else ans[j].set(i);
      } else {
        if(counter%2) ans[j].set(i);
        else ans[j].reset(i);
      }
    }
  }
  REP(i,n) {
    cout << ans[i].to_ulong();
    if(i < n-1) {
      cout << " ";
    }
  }
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

#define ll long long
#define ii pair<int, int>
#define dd pair<double, double>
#define pb(i) push_back(i)
const double PI = 3.14159265359;
const int inf = 1e9+77;
const ll mod = 1e9+7;
const double eps = 1e-7;
//int dir1[8] = {0, 0, 1, -1, 1, -1, 1, -1};
//int dir2[8] = {1, -1, 0, 0, 1, 1, -1, -1};
int dir1[4] = {0, 0, 1, -1};
int dir2[4] = {1, -1, 0, 0};

int main()
{
	int i, j, k;

	ll ans = 0;
	int n; cin >> n;
	for(i = 1; i <= n; i++)
		for(j = 1; j <= n; j++)
			for(k = 1; k <= n; k++)
				ans += __gcd(i, __gcd(j, k));
	cout << ans << '\n';

}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define lli long long int
#define floop(a,b,c) for(lli a=b;a<c;a++)
#define bloop(a,b,c) for(lli a=b;a>=c;a--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vt vector
#define MAX 1000000007
using namespace std;
lli t,n,w;
lli i,j;
int main(){
        cin>>n>>w;
        lli weight[n+1],value[n+1];
        weight[0]=0; value[0]=0;
        floop(i,1,n+1){
            cin>>weight[i]>>value[i];
        }
        lli mat[n+1][w+1];
        floop(i,0,n+1) mat[i][0]=0;
        floop(i,0,w+1) mat[0][i]=0;
        floop(i,1,n+1){
              floop(j,1,w+1){
                  if(weight[i]>j){
                      mat[i][j]=mat[i-1][j];
                  }
                  else{
                      mat[i][j]=max(value[i]+mat[i-1][j-weight[i]],mat[i-1][j]);
                  }
              }
        }
        cout<<mat[n][w];
        return 0;
}


Measured memory_bytes: 79104
#include<iostream>
using namespace std;
int main()
{
    // 文字列の入力
    string s;
    cin >> s;
    if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
    {
    	cout << "Yes" << endl;
    }
    else if(s[0] == s[2] && s[1] == s[3] && s[0] != s[1])
    {
    	cout << "Yes" << endl;
    }
    else if(s[0] == s[3] && s[1] == s[2] && s[0] != s[1])
    {
    	cout << "Yes" << endl;
    }
    else
    {
    	cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let vec: Vec<i32> = (0..n).map(|_| read()).collect();
    let diffs: Vec<_> = vec.windows(2).map(|a| a[1] - a[0]).collect();
    let mut before = None;
    let mut ans = 0;
    // dbg!(&diffs);
    for v in diffs {
        if v < 0 {
            match before {
                None => before = Some(v),
                Some(a) if a <= 0 => before = Some(v),
                Some(a) if a > 0 => {
                    before = None;
                    ans += 1;
                }
                Some(_) => unreachable!(),
            }
        } else if v > 0 {
            match before {
                None => before = Some(v),
                Some(a) if a >= 0 => before = Some(v),
                Some(a) if a < 0 => {
                    before = None;
                    ans += 1;
                }
                Some(_) => unreachable!(),
            }
        } else if v == 0 {
            match before {
                None => before = Some(v),
                Some(_) => {}
            }
        }
    }
    println!("{}", ans + 1)
}


Measured memory_bytes: 4352
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int p = sc.nextInt();

        int piece = a*3 + p;
        int applepie = piece/2;

        System.out.println(applepie);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define lli long long int
#define llu long long unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,s,e) for(i=s; i<e; i++)
#define mod 998244353
#define F first
#define S second
#define plli pair<lli,lli>
#define pqlli priority_queue<lli>
#define test(t) cin>>t; while(t--)
using namespace std;
 
lli power(lli a, lli b, lli M = mod)
{
	lli result = 1;
    for (;;)
    {
        if (b & 1)
            result = (result*a)%M;
        b >>= 1;
        if (!b)
            break;
        a = (a*a)%M;
    }
    return result;
}
 
int main()
{
    IOS;
    lli n;
    cin>>n;
    int flag = 0;
    while(n>0)
    {if(n%10 == 7)
    flag = 1;n = n/10;}
    if(flag)
    cout<<"Yes\n";
    else
    cout<<"No\n";
 /*   string s;
    cin>>s;
    lli dp[3][n+1];
    memset(dp, 0, sizeof(dp));
    for(lli i = 1; i<n+1; i++)
    dp[0][i] = dp[0][i-1] + (s[i-1] == 'R'), dp[1][i] = dp[1][i-1] + (s[i-1] == 'G'), dp[2][i] = dp[2][i-1] + (s[i-1] == 'B');
	lli ans = 0;
    for(lli i = 0; i<n; i++)
    {
		for(lli k = i+3; k<n; k++)
		{
			if(s[i] != s[k])
			{
				if(s[i]!='R' and s[k]!='R')
				{
					ans += dp[0][k] - dp[0][i+1];
					if((k-i-1)%2 and (s[(k+i)/2] == 'R'))
					ans--;
				}
				else if(s[i]!='G' and s[k]!='G')
				{
					ans += dp[1][k] - dp[1][i+1];
					if((k-i-1)%2 and (s[(k+i)/2] == 'G'))
					ans--;
				}
				else
				{
					ans += dp[2][k] - dp[2][i+1];
					if((k-i-1)%2 and (s[(k+i)/2] == 'B'))
					ans--;
				}
			}
		}
	}
	cout<<ans<<endl;*/
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
using P = pair<long long, int>;

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

    vector<P> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first >> b[i].first;
        a[i].second = i;
        b[i].second = i;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    int d = n;
    for (int i = 0; i < n; ++i) {
        if (a[i].first > b[i].first) {
            d = i;
            break;
        }
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += min(a[i].first, b[i].first);
    }
    if (d == n || d == 0) {
        cout << ans << "\n";
        return 0;
    }
    vector<int> cnt(n);
    for (int i = 0; i < d; ++i) {
        ++cnt[a[i].second];
        ++cnt[b[i].second];
    }
    for (int i = 0; i < n; ++i) {
        if (cnt[i] == 1) {
            cout << ans << "\n";
            return 0;
        }
    }
    ans = 0;
    if ((d == 1 || a[d - 1].second != b[d - 1].second) && (d == n - 1 || a[d].second != b[d].second)) {
        for (int i = 0; i < d - 1; ++i) {
            ans += a[i].first;
        }
        ans += min(a[d - 1].first, b[d].first);
        ans += min(a[d].first, b[d - 1].first);
        for (int i = d + 1; i < n; ++i) {
            ans += b[i].first;
        }
    }
    else {
        long long ans1 = 0, ans2 = 0, ans3 = 1e18;
        for (int i = 0; i < d - 2; ++i) {
            ans1 += a[i].first;
        }
        ans1 += min(a[d - 2].first, b[d].first);
        ans1 += a[d - 1].first;
        ans1 += min(a[d + 1].first, b[d - 1].first);
        for (int i = d + 1; i < n; ++i) {
            ans1 += b[i].first;
        }

        for (int i = 0; i < d - 1; ++i) {
            ans2 += a[i].first;
        }
        ans2 += min(a[d - 1].first, b[d + 1].first);
        ans2 += b[d].first;
        ans2 += min(a[d].first, b[d - 2].first);
        for (int i = d + 2; i < n; ++i) {
            ans2 += b[i].first;
        }
        int ad = d - 2, bd = d + 1;
        while (ad >= 0) {
            if (a[ad].second != b[ad].second) break;
            --ad;
        }
        while (bd < n) {
            if (a[bd].second != b[bd].second) break;
            ++bd;
        }
        if (ad >= 0 && bd < n) {
            ans3 = 0;
            for (int i = 0; i < d; ++i) {
                if (i == ad) continue;
                ans3 += a[i].first;
            }
            ans3 += min(a[ad].first, b[bd].first);
            ans3 += min(a[bd].first, b[ad].first);
            for (int i = d; i < n; ++i) {
                if (i == bd) continue;
                ans3 += b[i].first;
            }
        }
        if (ad >= 0) {

        }

        ans = min({ans1, ans2, ans3});
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3712