akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pll = pair<ll, ll>;

ll mpow(ll base, ll n) {
    ll res = 1;
    rep(i, n)res *= base;
    return res;
}

vector<ll> make_route(const vector<vector<ll>>& edges, const pll& uv) {
    const int N = edges.size();
    ll u, v;
    tie(u, v) = uv;
    vector<ll> ds(N, 1ll << 60);
    priority_queue<pll, vector<pll>, greater<pll>> pq;
    ds[u] = 0;
    pq.push({ 0,u });
    while (!pq.empty()) {
        ll d, pos;
        tie(d, pos) = pq.top(); pq.pop();
        for (auto next : edges[pos]) {
            if (ds[next] <= d + 1)continue;
            ds[next] = d + 1;
            pq.push({ d + 1,next });
        }
    }
    vector<ll> res(1, v);
    while (res.back() != u) {
        ll now = res.back();
        for (auto next : edges[now])if (ds[now] - 1 == ds[next]) {
            res.push_back(next);
            break;
        }
    }
    return res;
}

ll find_edge(const vector<pair<ll, ll>>& edges, pair<ll, ll> edge) {
    auto itr = find(edges.begin(), edges.end(), edge);
    return itr - edges.begin();
}

vector<ll> make_users(
    const vector<vector<ll>>& graph,
    const vector<pair<ll, ll>>& edges,
    const vector<pll>& uvs
) {
    const int N = graph.size();
    vector<ll> res(N - 1, 0);
    rep(i, uvs.size()) {
        const auto& uv = uvs[i];
        auto route = make_route(graph, uv);
        rep(j, (int)route.size() - 1) {
            ll from = route[j], to = route[j + 1];
            ll idx = min(find_edge(edges, { from,to }), find_edge(edges, { to,from }));
            res[idx] |= 1 << i;
        }
    }
    return res;
}

int main()
{
    ll N, M;
    cin >> N;
    vector<pair<ll, ll>> edges;
    vector<vector<ll>> graph(N);
    rep(i, N - 1) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        edges.push_back({ a,b });
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    cin >> M;
    vector<pair<ll, ll>> uvs(M);
    rep(i, M) {
        ll u, v;
        cin >> u >> v;
        u--; v--;
        uvs[i] = { u,v };
    }
    auto users = make_users(graph, edges, uvs);
    ll res = 0;
    //vector<ll> res(1, 0);
    REP(way, 1, mpow(2, M)) {
        ll sign = 0;
        rep(i, M)sign += (way >> i) & 1;
        ll cnt = 0;
        rep(i, N - 1) {
            ll flag = users[i] & way;
            if (flag != 0)cnt++;
        }
        cnt = mpow(2, N - 1 - cnt);
        res += cnt * (sign % 2 == 0 ? -1 : 1);
    }

    cout << mpow(2, N - 1) - res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define INF 10000000000000009
#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

signed main(){
    int N,K;
    int h[114514];
    int dp[114514]={};
    
    cin >> N >> K;
    REP(i,N){cin >> h[i];dp[i]=INF;}
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<N;i++){
        for(int j=1;j<=K;j++){
            if(i-j<0){break;}
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout << dp[N-1] << endl;
    return 0;
}   


Measured memory_bytes: 1920
#include<stdio.h>
int main(){
int a,b,c,x;
scanf("%d%d%d",&a,&b,&c);
   if(a > b){x = a;a = b;b = x;}
   if(b > c){x = b;b = c;c = x;}
   if(a > b){x = a;a = b;b = x;}
printf("%d %d %d\n",  a, b, c);
return 0; 
}



Measured memory_bytes: 2060
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 1000000000
#define MOD 1000000007
#define ll long long int

using namespace std;



int main(){
	int H,W; cin>>H>>W;
	int time[1009][1009];
	for(int i=0;i<1009;i++){
		for(int j=0;j<1009;j++){
			time[i][j] = INF;
		}
	}

	queue <int> qx;
	queue <int> qy;

	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			char c; cin>>c;
			if(c == '#') {time[i][j] = 0;qx.push(i);qy.push(j);}
		}
	}

	while( ! qx.empty() ) {
		int nowx = qx.front(); qx.pop();
		int nowy = qy.front();qy.pop();
		vector <int> dx = {1,0,-1,0};
		vector <int> dy = {0,1,0,-1};
		for(int i=0;i<4;i++){
			int x = nowx + dx[i];
			int y = nowy + dy[i];
			if(x > H or x == 0 or y == W+1 or y ==0) continue;
			if(time[x][y] <= time[nowx][nowy] + 1) continue;
			time[x][y] = time[nowx][nowy] + 1;

			//time[x][y] = min(time[x][y],time[nowx][nowy] + 1);
			//if(time[x][y] == time[nowx][nowy] + 1) {
				qx.push(x);qy.push(y);
			//}
		}
	}

	int ans = -1;

	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){

			ans = max(ans,time[i][j]);

		}
	}



cout<<ans<<endl;



	return 0;
}

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


int main() {
  string N;
  cin >> N;
  
  reverse(N.begin(),N.end());
  if(N.at(0) == '2' || N.at(0) == '4' || N.at(0) == '7' || N.at(0) == '5' ||  N.at(0) == '9'){
    cout << "hon" << endl;
  }else if(N.at(0) == '0' || N.at(0) == '1' || N.at(0) == '6' || N.at(0) == '8'){
    cout << "pon" << endl;
  }else if(N.at(0) == '3'){
    cout << "bon" << endl;
  }
  


}

Measured memory_bytes: 3608
import Control.Monad(replicateM)

main = do
  n  <- readLn
  if n == 0 then return ()
  else do 
    s <- replicateM n getLine
    print $ sum $ map head $ scanl roll [1,2,3] s
    main  
    
-- [Up,Front,Right]
--Express the function by manipulating the above three numbers
roll [u,f,r] s
  | s == "North" = [f,7-u,r]
  | s == "East"  = [7-r,f,u]
  | s == "West"  = [r,f,7-u]
  | s == "South" = [7-f,u,r]
  | s == "Right" = [u,r,7-f]
  | otherwise    = [u,7-r,f]

Measured memory_bytes: 6596
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
//library begin
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int log(int a){
    int b=a;
    int cnt=0;
    while(b%2==0){
        b/=2;
        cnt++;
    }
    return cnt;
}
//library end
int n;
int a[200000];
signed main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    int half=(a[n-1]+1)/2;
    int r=-INF;
    rep(i,n-1){
        if(abs(half-a[i])<abs(half-r)){
            r=a[i];
        }
    }
    cout<<a[n-1]<<" "<<r<<endl;
    return 0;
}



Measured memory_bytes: 1024
n = gets.to_i

max_1 = [-1,0]
max_2 = 0
n.times do |i|
    x = gets.to_i
    if x >= max_1[1] then
        max_2 = max_1[1]
        max_1 = [i,x]
    elsif x >= max_2
        max_2 = x
    end
end

ans = Array.new(n,max_1[1])
ans[max_1[0]] = max_2

puts ans

Measured memory_bytes: 4988
#include<bits/stdc++.h>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define eb emplace_back
#define pb push_back
#define ll long long
#define mp make_pair
#define x first
#define y second
//# define INF 99999999999999999
#define mod 1000000007
#define mod1 1000000006
#define sc(a) scanf("%d",&a);
#define pc(x) putchar_unlocked(x)
#define PI  3.141592653589793
#define pp pair < ll , ll >
using namespace std;

int min(int a ,  int b)
{
  if(a<b) return a;
  else return b;
}
int max(int a ,  int b)
{
  if(a>b) return a;
  else return b;
}
int a[100005];

int cn[1000005];
int main()
{
	ll n ;
	cin >> n;
	n = (n * (n-1)) / 2;
	cout << n;
	
	return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
#include <functional>

//#include "All.h"

using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

int gcd(int a, int b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    REP(i, b) tmp *= a;
    return tmp;
}



int main() {
    ll N, K;
    ll ans = 0;
    ll mod = ll(1e9) + 7;
    cin >> N >> K;
    //for (ll k = K - 1; k <= N; k++) {
    //    ans += -k * k + (N - 1) * k + N + 1;
    //    ans %= ll(1e9) + 7;
    //}
    //ll n = (N - (K - 1));
    ans += -(N - (K - 1)) * ((N - (K - 1)) + 1) * (2 * (N - (K - 1)) + 1) / 6
        + (N - 2 * K + 1) * (N - (K - 1)) * ((N - (K - 1)) + 1) / 2
        + ((N - (K - 1)) + 1) * (-(K - 1) * (K - 1) + (N - 1) * (K - 1) + N + 1);
    
    //ans %= mod;
    //ans += 
    //ans %= mod;
    //ans += 
    ans %= mod;
    cout << ans << endl;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    string s;
    cin >> s;

    int ans = 0, ansnow = 0;
    for(int in=0;in<n;in++) {
        if(s.at(in)=='I') ansnow++;
        else ansnow--;
        ans = max(ans, ansnow);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,k=map(int,input().split())
a=list(map(int,input().split()))

l,h=0,max(a)
while h-l>1:
    mid=(h+l)//2
    # print(l,h,mid)
    cnt=0
    for i in range(n):
        cnt+=math.ceil(a[i]/mid)-1
    #     print(a[i]/mid)
    # print(cnt)
    if cnt<=k:
        h=mid
    else:
        l=mid

# print(l)
print(h)

Measured memory_bytes: 103716
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

int main(){
    int N, M, X;
    read(N, M, X);
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    for(int i = 0; i < N; i++){
        read(C[i]);
        for(int j = 0; j < M; j++){
            read(A[i][j]);
        }
    }
    int ans = INT_MAX;
    for(int b = 0; b < (1 << N); b++){
        vector<int> undst(M, 0);
        for(int i = 0; i < N; i++){
            for(int j = 0; j < M; j++){
                if((b >> i) & 1) undst[j] += A[i][j];
            }
        }
        bool f = true;
        for(int i = 0; i < M; i++){
            if(undst[i] < X) f = false;
        }
        if(f) {
            int sum = 0;
            for(int i = 0; i < N; i++){
                if((b >> i) & 1) sum += C[i];
            }
            ans = min(ans, sum);
        }
    }
    if(ans == INT_MAX) write(-1);
    else write(ans);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vvint sum(n+1, vint(n+1, 0));
    rep(i, m) {
        int l, r;
        cin >> l >> r;
        sum[l][r]++;
    }

    srep(i, n+1, 1) srep(j, n+1, 1) {
        sum[i][j] += sum[i-1][j];
        sum[i][j] += sum[i][j-1];
        sum[i][j] -= sum[i-1][j-1];
    }

    rep(i, q) {
        int p, q;
        cin >> p >> q;
        cout << sum[q][q] - sum[p-1][q] - sum[q][p-1] + sum[p-1][p-1] << endl;
    }


    return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define double long double
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,int> Pi;
typedef pair<P,P> PP;
double eps=1e-8;
int mod=1e9+7;
int inf=1LL<<55;

priority_queue<P,vector<P>,greater<P> > pq;

template <typename T>
int Count(const vector<T> &v, T l,T r){
  //counting [l,r]
  auto L = lower_bound(v.begin(), v.end(), l );
  auto R = upper_bound(v.begin(), v.end(), r );
  // [l,r) change upper -> lower
  return R-L;
}

signed main(){
  int n,ans=0;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.begin(),v.end());
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++){
      int x = lower_bound(v.begin(), v.end(), v[i]+v[j] )-v.begin()-1-j;
      ans+=x;
    }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int aaa(int n,int limit){
  int i=1,count=0;
  while(n*i<=limit){
    i*=n;count++;
  }
  if(count>=2){
    return(i);}
  else{
  return(1);}
}
int main(void){
  int c,n,i=1,max=0;
  scanf("%d",&n);
  if(n>=1)
    max=1;
  for(i=2;i*i<=n;i++){
    c=aaa(i,n);
    if(c>max)
      max=c;
  }
  printf("%d\n",max);
  return(0);
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var travelNum = Convert.ToInt32(Console.ReadLine());


            for (int i = 0; i < travelNum; i++)
            {
                var travelList = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToList<int>();

                if(travelList[0] < travelList[1] + travelList[2])
                {
                    if(i < travelNum)
                    {
                        i++;
                        while (i < travelNum)
                        {
                            Console.ReadLine();
                            i++;
                        }
                    }

                    Console.WriteLine("No");
                    return;
                }

                if (travelList[0] % 2 == 0 && (travelList[1] + travelList[2]) % 2 == 0)
                    continue;

                if (travelList[0] % 2 == 1 && (travelList[1] + travelList[2]) % 2 == 1)
                    continue;

                if (i < travelNum)
                {
                    i++;
                    while (i < travelNum)
                    {
                        Console.ReadLine();
                        i++;
                    }
                }

                Console.WriteLine("No");
                return;
            }

            Console.WriteLine("Yes");
        }
    }


}


Measured memory_bytes: 17452
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	p = 1000000007
)

var (
	fac []int
)

func mpow(x int, n int) int {
	result := 1
	for n != 0 {
		if n&1 == 1 {
			result *= x
			result %= p
		}
		x *= x
		x %= p
		n >>= 1
	}
	return result
}

func mcomb(n int, k int) int {
	if n == 0 && k == 0 {
		return 1
	}
	if n < k || k < 0 {
		return 0
	}
	return (fac[n] * mpow(fac[n-k], p-2) % p) * mpow(fac[k], p-2) % p
}

func main() {
	N := readInt()
	K := readInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = readInt()
	}

	fac = make([]int, N+1)
	fac[0] = 1
	for i := 0; i < N; i++ {
		fac[i+1] = fac[i] * (i + 1) % p
	}

	sort.Sort(sort.Reverse(sort.IntSlice(A)))
	result := 0
	for i := 0; i < N-K+1; i++ {
		result += A[i] * mcomb(N-(i+1), K-1)
		result %= p
	}

	sort.Ints(A)
	t := 0
	for i := 0; i < N-K+1; i++ {
		t += A[i] * mcomb(N-(i+1), K-1)
		t %= p
	}

	result -= t
	result %= p
	result += p
	result %= p
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 4992
#include <stdio.h>

char opera(int i, int j, char array[100][100]);

int main(void)
{
	char array[100][100];
	int i, j;
	char ans;
	int flog;
	
	while (scanf("%s", array[0]) != EOF){
		flog = 0;
		
		for (i = 1; i < 8; i++){
			scanf("%s", array[i]);
		}
		for (i = 0; i < 8; i++){
			for (j = 0; j < 8; j++){
				if (array[i][j] == '1'){
					ans = opera(i, j, array);
					flog++;
					break;
				}
			}
			if (flog != 0){
				break;
			}
		}
		printf("%c\n", ans);
	}
	
	return (0);
}
char opera (int i, int j, char array[100][100])
{
	int line = 0;
	int row  = 0;
	int obli = 0;
	
	if (array[i][j + 1] 	== '1'){
		line++;
		if (array[i][j + 2]	== '1'){
			return ('C');
		}
	}
	if (array[i + 1][j] 	== '1'){
		row++;
		if (array[i + 2][j] == '1'){
			return ('B');
		}
	}
	if (array[i + 1][j + 1] == '1'){
		obli++;
	}
	
	if (line >= 1){
		if (row >= 1){
			if (obli >= 1){
				return ('A');
			}
			return ('G');
		}
		return ('E');
	}
	
	if (row >= 1){
		if (obli >= 1){
			return ('F');
		}
		return ('D');
	}
	
}

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

int main(void) {
  int N;
  string S;
  cin >> N >> S;
  bool flag=true;
  
  if(N%2==0){
    for(int i=0; i<N/2; i++){
      if(S[i] != S[N/2+i]){
        flag=false;
        break;
      }
    }
  }
  else
    flag=false;
  
  if(flag==true) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  string ans;
  if (S.size() + 1 == T.size()) {
    rep(i,S.size()) {
      if (S.at(i) == T.at(i)) ans = "Yes";
      else {
        ans = "No";
        break;
      }
    }
  }
  else ans = "No";
  cout << ans << endl;
}

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

int main(){
    int x, y;
    cin >> x >> y;
    for(int i=0;i<=x;++i){
        int j = x - i;
        if(i*2 + j*4 == y){ cout << "Yes" << endl; return 0; }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3652
#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 dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INF = 999999999;
const int MOD = (int)1e9 + 7;
const int EPS = 1e-9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a;
  int mn = INF;
  cin >> n;
  REP(i,n){
      cin >> a;
      int cnt = 0;
      while(a%2==0){
          cnt++;
          a /= 2;
      }
      mn = min(mn,cnt);
  }
  cout << mn << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}

#define xmin first.first
#define xmax first.second
#define ymin second.first
#define ymax second.second

int main(){
	int n;
	cin>>n;
	rep(datasets,n){
		map<char,int> mp;
		map<int,pair<pii,pii>> pt;

		int h,w;
		cin>>h>>w;
		mp['.']=0;
		pt[0]={{w,0},{h,0}};
		vvi f(h,vi(w));
		rep(i,h)rep(j,w){
			char c;
			cin>>c;
			if(mp.find(c)==mp.end()){
				mp[c]=mp.size()-1;
				pt[mp[c]]={{w,0},{h,0}};
			}
			f[i][j]=mp[c];
			pt[mp[c]].xmin=min(pt[mp[c]].xmin,j);
			pt[mp[c]].xmax=max(pt[mp[c]].xmax,j);
			pt[mp[c]].ymin=min(pt[mp[c]].ymin,i);
			pt[mp[c]].ymax=max(pt[mp[c]].ymax,i);
		}
		
		vi perm(mp.size()-1);
		iota(all(perm),1);
		bool ok=false;
		do{
			auto p=f;
			for(auto key:perm){
				for(int i=pt[key].ymin;i<=pt[key].ymax;i++){
					for(int j=pt[key].xmin;j<=pt[key].xmax;j++){
						if(p[i][j]!=key and p[i][j]!=-1){
							goto next;
						}else{
							p[i][j]=-1;
						}
					}
				}
			}
			ok=true;
			break;
			next:;
		}while(next_permutation(all(perm)));
		if(ok){
			cout<<"SAFE"<<endl;
		}else{
			cout<<"SUSPICIOUS"<<endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3156
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    std::string s; std::cin >> s;
    long long k; std::cin >> k;
    int n = s.size();
    if (n*k <= 100000) {
        std::string t;
        for (int i = 0; i < k; i++) t += s;
        int ans = 0;
        for (int i = 0; i < k*n - 1; i++) {
            if (t[i] == t[i + 1]) {
                char alph = 'a';
                while (alph == t[i] || (i < 3 * n - 2 && alph == t[i + 2])) alph++;
                t[i + 1] = alph;
                ans++;
            }
        }
        std::cout << ans << std::endl;
        return 0;
    }
    std::string t = s + s + s;
    long long a = 0, b = 0, c = 0;
    bool f = false, g = false;
    for (int i = 0; i < 3 * n - 1; i++) {
        if (t[i] == t[i + 1]) {
            char alph = 'a';
            while (alph == t[i] || (i < 3 * n - 2 && alph == t[i + 2])) alph++;
            t[i + 1] = alph;
            if (i + 1 < n) a++;
            else if (i + 1 < 2 * n) b++;
            else c++;
            f |= i + 1 == n;
            g |= i + 1 == 2 * n;
        }
    }
    if (!f || !g) std::cout << k / 2 * a + (k - 1) / 2 * b + c << std::endl;
    else std::cout << a + (k - 2)*b + c << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n+1];
  for(int i=1; i<=n; i++) arr[i]=0;
  for(int i=1; i<n; i++) {
    int a;
    cin >> a;
    arr[a]++;
  }
  for(int i=1; i<=n; i++) cout << arr[i] << '\n';
}

Measured memory_bytes: 4380
#include <iostream>
#include <string>
using namespace std;
int main() {
	int a, b, i;
	string s;
	cin >> a >> b >> s;
	for (i = 0;i < a;i++) {
		if (s[i] >= '0'&&s[i] <= '9') {
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	if(s[a]=='-'){}
	else {
		cout << "No" << endl;
		return 0;
	}
	for (i = a + 1;i < a + b + 1;i++) {
		if (s[i] >= '0'&&s[i] <= '9') {
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{for(T&x:v)i>>x;return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;for(T&x:v)s<<' '<<x;return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}

const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n, d;
  string s;
  cin >> n >> s >> d;
  string t = s;
  rep(i,n) {
    if (d && s[i] == '0') {
      t[i] = '1';
      --d;
    }
  }
  drep(i,n) {
    if (d && s[i] == '1') {
      t[i] = '0';
      --d;
    }
  }
  cout<<t<<endl;
  return 0;
}

Measured memory_bytes: 3200
n=int(input())
dp=[0]*(n+1)
i=1
while i <= n:
    dp[i]=float('inf')
    p=1
    while p<=i:
        dp[i]=min(dp[i],1+dp[i-p])
        p*=6
    p=1
    while p<=i:
        dp[i]=min(dp[i],1+dp[i-p])
        p*=9
    i+=1
print(dp[n])


Measured memory_bytes: 3828
#include <iostream>
#include <cstdio>
#include <map>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <cmath>
#include <queue>
#include <ctime>
#include <utility> // std::pair
#include <functional> // std::greater <int> ()
#define int long long
#define inf 1000000000000000001
#define BASE 29 // hashings mod, can be rand'd
#define mod 998244353 // can be 1000000007
#define pi 3.1415926535897
#define pii pair <int, int>
#define fii first
#define see second

typedef long long ll;
typedef long double ld;
using namespace std;

int n, ans=0;

// functions
void input(){
	cin >> n;
	return;
}

void solve(){
	for(int i=1; i<n; i++){
		ans+=i;
	}
	cout << ans;
	return;
}

void output(){
	return;
}

signed main(){
/*
//  REMEMBER TO TURN OFF IFDEF IN PROBLEMS WITH FILE I/O
*/
//#ifdef sheeep
//	freopen("forces.inp", "r", stdin);
//	freopen("forces.out", "w", stdout);
//#endif
	ios_base::sync_with_stdio(false);
//	int t;
//	cin >> t;
//	for(int i=1; i<=t; i++){
		input();
		solve();
		output();
//	}
	return 0;
}
// Author: NamSPro

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

int main()
{
    int n,a,b;
    cin >> n >> a >> b;
    if((a-b)%2 == 0)
    {
        cout << "Alice" << endl;
    }
    else
    {
        cout << "Borys" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long long
using namespace std;

signed main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	sort(vec.begin(),vec.end());
	if(N % 2 == 1) {
		bool A = true;
		int B = 0;
		for(int i = 0;i < N;i++) {
			if(vec.at(i) != B) {
				A = false;
				break;
			}
			if(i % 2 == 0) {
				B += 2;
			}
		}
		if(A == true) {
			int answer = 1;
			for(int i = 0;i < (N - 1) / 2;i++) {
				answer = answer * 2 % 1000000007;
			}
			cout << answer << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
	else {
		bool A = true;
		int B = 1;
		for(int i = 0;i < N;i++) {
			if(vec.at(i) != B) {
				A = false;
				break;
			}
			if(i % 2 == 1) {
				B += 2;
			}
		}
		if(A == true) {
			int answer = 1;
			for(int i = 0;i < N / 2;i++) {
				answer = answer * 2 % 1000000007;
			}
			cout << answer << endl;
		}
      	else {
          	cout << 0 << endl;
        }
	}
}

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

int main() {
  int D;
  cin >> D;
  
  if (D == 22) {
    cout << "Christmas Eve Eve Eve" <<endl;
  }
  else if (D == 23) {
    cout << "Christmas Eve Eve" <<endl;
  }
  else if (D == 24) {
    cout << "Christmas Eve" <<endl;
  }
  else {
    cout << "Christmas" <<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    
    string s;
    cin >> s;
    if(s == "Sunny"){
        cout << "Cloudy" << endl;
    }else if(s == "Cloudy"){
        cout << "Rainy" << endl;
    }else{
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
use std::fmt::Debug;
use std::io;
use std::io::{Read, Stdin};
use std::str;
use std::str::FromStr;
use std::usize;
use std::cmp;
use std::collections::vec_deque::VecDeque;
use std::i64::MAX;

fn main() {
    let mut sc = Scanner::new();
    let n = sc.parse::<usize>();
    let l = sc.parse::<i64>();
    let t = sc.parse::<i64>();

    let mut x: Vec<i64> = vec![0; n];
    let mut w: Vec<usize> = vec![0; n];

    for i in 0..n {
        x[i] = sc.parse::<i64>();
        w[i] = sc.parse::<usize>();
    }

    let cross_count = (0..n)
        .map(|i| {
            let w0 = w[0];
            let wi = w[i];
            if w0 == wi {
                return 0;
            }

            let interval;
            if w0 == 1 {
                interval = x[i] - x[0];
            } else {
                interval = x[0] + l - x[i];
            }

            if interval > t * 2 {
                return 0;
            }

            let time = t * 2 - interval;
            let count;
            if time % l == 0 && w[0] == 1 {
                count = time / l;
            } else {
                count = time / l + 1;
            }
            return count;
        })
        .collect::<Vec<i64>>();

    let count_sum: i64 = cross_count.iter().sum::<i64>() % (n as i64);
    let position;
    let num;
    if w[0] == 1 {
        position = (x[0] + t) % l;
        num = count_sum;

    } else {
        position = (x[0] - (t % l) + l) % l;
        num = (n as i64) - count_sum;
    }

    let mut positions: Vec<i64> = (0..n)
        .map(|i| {
            let p;
            if w[i] == 1 {
                p = (x[i] + t) % l;
            } else {
                p = (x[i] - (t % l) + l) % l;
            }
            return p;
        })
        .collect::<Vec<i64>>();
    positions.sort();

    let mut a = 0;
    for i in 0..n {
        if positions[i] == position {
            a = i;
            break;
        }
    }

    let ans = (0..n)
        .map(|idx| {
                 let i = (idx + n - ((num as usize) % n)) % n;
                 let p = (a + i as usize) % n;
                 return positions[p];
             })
        .collect::<Vec<i64>>();

    for a in &ans {
        println!("{}", a);
    }

}

struct Scanner {
    stdin: Stdin,
    buf: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            buf: Vec::with_capacity(256),
        }
    }

    fn parse<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let mut it = self.stdin.lock().bytes();
        let mut c = it.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = it.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = it.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse::<T>().unwrap()
    }
}

Measured memory_bytes: 9340
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// --------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<int> dp(N+1,0);
  for(int i=0; i<N; i++){
    dp[i+1] = dp[i] + (S[i] == '#');
  }
  int ans = inf;
  for(int i=0; i<=N; i++){
    chmin(ans,dp[i] + (N-i) - (dp[N] - dp[i]));
  }
  cout << ans << "\n";
  return 0;
}

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

int main()
{
    int n;
    while (1) {
        int ans = 1000000;
        cin >> n;
        if (n == 0) break;
        for (int a = 0; a <= 50; a++) {
            for (int b = 0; b <= 50; b++) {
                for (int c = 0; c <= 50; c++) {
                    int sum = (380 * (5 * (a / 5))) * 0.8 + (a % 5) * 380;
                    sum += (550 * (4 * (b / 4))) * 0.85 + (b % 4) * 550;
                    sum += (850 * (3 * (c / 3))) * 0.88 + (c % 3) * 850;
                    if (a * 200 + b * 300 + c * 500 == n) {
                        ans = min(ans, sum);
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

namespace A {
static class Extensions {
   public static int ToInt(this string str) =>
      int.Parse(str);

   public static int[] readIntArr() =>
      ReadLine().Split(' ').Select(int.Parse).ToArray();

   public static long[] readLongArr() =>
      ReadLine().Split(' ').Select(long.Parse).ToArray();
   
   public static void Fill<T>(this List<T> a, T b) {
      for (var i = 0; i < a.Capacity; i++) {
         a.Add(b);
      }
   } 

   public static void Fill<T>(this T[] a, T b) {
      for (var i = 0; i < a.Length; i++) {
         a[i] = b;
      }
   }
}

class Program {
   public static void Main(string[] args) {
      var tmp = Extensions.readIntArr();

      var N = tmp[0];
      var W = tmp[1];
      var w = new long[N + 1];
      var v = new long[N + 1];
      
      for (var i = 1; i < N + 1; i++) {
         var tmp2 = Extensions.readIntArr();
         w[i] = tmp2[0];
         v[i] = tmp2[1];
      }

      var V = v.Sum();

      var dp = new long[N + 1][];
      for (var i = 0; i < N + 1; i++) {
         dp[i] = new long[V + 1];
         dp[i].Fill(long.MaxValue);
      }
      for (var i = 0; i < N + 1; i++) {
         dp[i][0] = 0;
      }

      /*
         (4, 3) (2, 3) (1, 2)

               j (value)
         0   1   2   3   4   5
      0  0  inf inf inf inf inf
      1  0   4   4   4  inf inf
    i 2  0   2   2   2   6
      3  0   1   1   2   2

      */
      for (var i = 1; i <= N; i++) {
         for (var j = 1; j <= V; j++) {
            if (j - v[i] > 0 && dp[i - 1][j - v[i]] != long.MaxValue) {
               dp[i][j] = Min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
            }
            else if (j <= v[i]){
               dp[i][j] = Min(dp[i - 1][j], w[i]);
            } 
            // WriteLine($"{i}, {j}: {dp[i][j]}");
         }
      }

      var ams = 0;
      for (var j = 1; j <= V; j++) {
         if (dp[N][j] <= W) ams = j;
      }

      WriteLine(ams);
   }
}

}


Measured memory_bytes: 93248
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int  n,a;
	scanf("%d",&n);
	a=1;
	while(1){
		if(n<a*2){
			break;
		}
		a*=2;
	}
	printf("%d\n",a);
	return 0;
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;
typedef long double ldb;
typedef pair<int,int> pii;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int T;
    LL A, B, C, D;
    cin>>T;
    while(T--)
    {
        cin>>A>>B>>C>>D;
        if(A < B || D < B)
        {
            cout<<"No\n";
            continue;
        }
        A %= B;
        LL G = __gcd(B, D);
        if(A+(B-1-A)/G*G>C)
            cout<<"No\n";
        else
            cout<<"Yes\n";
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int X = N;
  int sum = 0;
  while (N > 0) {
    sum += N % 10;
    N = N / 10;
  }
  if (X % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF (2e9)
#define EPS (1e-7)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    int n, t, a;
    cin >> n;
    int h[n];
    cin >> t >> a;
    REP(i, n) cin >> h[i];

    double cand[n];
    int ans = 0;
    REP(i, n) {
        cand[i] = t - h[i]*0.006;
        ans = abs(a-cand[i]) - abs(a-cand[ans]) >= 0 ? ans : i;
    }
    cout << ans+1 << endl;
}

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

int main(){
    int a,b,c,s;
    cin>>a>>b>>c;
    if(a==b&&a==c) s=1;
    else if(a==b||b==c||c==a) s=2;
    else s=3;
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
//#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
#define index Index
#define Line pll
typedef long long LL;
int main(){
    int n;
    scanf("%d",&n);
    pair<int,pii> p[1005];
    for(int i=0;i<n;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        p[i]=mp(a+b,mp(a,c));
    }
    sort(p,p+n);
    LL dp[20005];
    MEM(dp);
    LL ans=0;
    for(int i=0;i<n;i++){
        for(int j=p[i].x-p[i].y.x;j>=0;j--){
            dp[j+p[i].y.x]=max(dp[j+p[i].y.x],dp[j]+p[i].y.y);
            ans=max(ans,dp[j+p[i].y.x]);
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ipr pair<ll,ll>
#define ps push_back
#define fs first
#define sc second
#define endl "\n"
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n>>k;

	ll fl[10]={0};
	for(i=0;i<k;i++){
		cin>>l;
		fl[l]=1;
	}

	ll t=1,a=n;
	while(t==1){
		l=n;
		int g=1;
		while(l>0){
			if(fl[(l%10)]==1){
				g=0;
				break;
			}
			l=l/10;
		}
		if(g==1){
			cout<<n;
			return 0;
		}
		n=n+1;
	}
	return 0;
}


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

#define f first 
#define s second 
#define pb push_back               
#define mp make_pair 

using namespace std;                    

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = 2123, mod = (int)1e9 + 7, inf = (int)1e9;

vector< int > g[N];
int n, k, dp[N][N], tmp[N], ans, sz[N];

void dfs(int v,int p){
	
	sz[v] = 1;

	for(int i = 1; i < N; i++)
		dp[v][i] = inf;
	for(auto to : g[v]){
		if(to == p)
			continue;
		dfs(to, v);
		
		for(int i = 0; i < N; i++)
			tmp[i] = inf;
		
		for(int i = 0; i <= sz[to]; i++)
			for(int j = 0; j <= sz[v]; j++)
				if( i + j + 1 <= k )
					tmp[max(i + 1, j)] = min(tmp[max(i + 1, j)], dp[v][j] + dp[to][i]);
		
		sz[v] += sz[to];
		for(int i = 0; i <= sz[v]; i++)
			dp[v][i] = min(dp[v][i] + sz[to], tmp[i]);
	}
	for(int i = 0; i < N; i++)
		ans = min(ans, dp[v][i] + n - sz[v]);
}
int main(){    
	cin >> n >> k;
	for(int i = 1; i < n; i++){
		int v, u;
		cin >> v >> u;
		g[v].pb(u);
		g[u].pb(v);
	}
	ans = inf;
	dfs(1, 1);
	cout << ans;
	return 0;
}


Measured memory_bytes: 17152
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pint;
typedef vector<int>vint;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int N;
int a[40000],b[40000];
int cnt[40000];
int main(){
    while(scanf("%d",&N),N){
        rep(i,N)scanf("%d",&a[i]);
        rep(i,N)scanf("%d",&b[i]);
        sort(a,a+N);reverse(a,a+N);
        sort(b,b+N);reverse(b,b+N);

        memset(cnt,0,sizeof(cnt));
        int cur=0,sum=0;
        rep(i,N-1){
            while(cur<N&&a[cur]>b[i])cur++;
            
            if(cur!=N)cnt[cur++]=1;
            sum+=cnt[i];
            if(i+1-sum>sum){
                cout<<i+1<<endl;
                goto END;
            }
        }
        cout<<"NA"<<endl;

        END:;
    }
    return 0;
}

Measured memory_bytes: 1700
N = gets.to_i
S = gets.chomp.chars.map &:to_i
count = 0

10.times do |i|
  10.times do |j|
    10.times do |k|
      ix = S.index(i)
      next unless ix

      s = S[ix+1,S.size-ix+1]
      iy = s.index(j)
      next unless iy

      s = s[iy+1,s.size-iy+1]
      iz = s.index(k)
      next unless iz

      count += 1
    end
  end
end

p count

Measured memory_bytes: 3452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,W;
  cin >> n >> W;
  vec dp(W+1);
  vec w(n),v(n);
  for(ll i=0;i<n;i++) cin >> w[i] >> v[i];
  for(ll i=0;i<n;i++) {
    for(ll j=W;j>=1;j--) {
      dp[j]=max(dp[j],dp[j-1]);
      if(j-w[i]>=0) {
        dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
      }
    }
  }
  cout << dp[W] << endl;
}

Measured memory_bytes: 1024
x, k, d = map(int, input().split())
if x < 0:
    x *= -1
if x >= k*d:
    ans = x - k*d
else:
    i = x//d
    x %= d
    k -= i
    if k%2 == 0:
        ans = x
    else:
        ans = abs(x-d)

print(ans)

Measured memory_bytes: 9208
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int W,H,N;

    cin >> W >> H >> N;

    vector<int> w{0, W};
    vector<int> h{0, H};

    for(int i = 0; i < N; i++){
        int x,y,a;
        cin >> x >> y >> a;

        if(a == 1 && w[0] < x){
            w[0] = x;
        }else if(a == 2 && w[1] > x){
            w[1] = x;
        }else if(a == 3 && h[0] < y){
            h[0] = y;
        }else if(a == 4 && h[1] > y){
            h[1] = y;
        }
    }
    
    if((w[1]-w[0]) > 0 && (h[1]-h[0]) > 0){
        cout << (w[1]-w[0])*(h[1]-h[0]) << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, h2, w2;
  cin >> h >> w >> h2 >> w2;
  cout << h*w-h2*w-w2*h+h2*w2 << endl;
  return 0;
}

Measured memory_bytes: 256
function main(input){
  const N = parseInt(input);
  let count = 0;
  
  const permutation = (sevenFiveThree, num, N) => {
    let Num = 10*num + sevenFiveThree;
    //console.log("Num",Num);
    let NumString = Num.toString();

    if(N>=Num) {
      //console.log("NumString",NumString);
      if(NumString.indexOf('7')!= -1 && NumString.indexOf('5')!= -1 && NumString.indexOf('3')!= -1) count++;
      permutation(7, Num, N);
      permutation(5, Num, N);
      permutation(3, Num, N);
    }
  };
  permutation(0, 0, N);
  console.log(count);    
}

main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 35296