akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 1 << 21;
using pii = std::pair<int, int>;
#define SORT(v) std::sort(v.begin(), v.end())
int F[100][15];
int main(void) {
	std::string s;
	std::cin >> s;
	std::map<char, int> mp;
	for (size_t i = 0; i < s.size(); i++) {
		mp[s[i]]++;
	}
	std::map<char, int>::iterator it;
	for (it = mp.begin(); it != mp.end();it++) {
		if (it->second % 2 != 0) {
			std::cout << "No" << std::endl;
			return 0;
		}
	}
	std::cout << "Yes" << std::endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    a,b=input().split()
    n=int(a+b)
    k=n**.5
    print("Yes" if(k==int(k)) else "No")
resolve()

Measured memory_bytes: 38512
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[100005];
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer> ();
		int cnt = 0;
		for(int i = 0; i < n; i++) {
			int a = scan.nextInt();
			if(map.containsKey(a) == false) {
				map.put(a, cnt);
				cnt++;
			}
			arr[map.get(a)] += 1;
		}
		int ans = 0;
		for(int i = 0; i < cnt; i++) {
			if(arr[i] % 2 == 1) ans++;
		}
		System.out.printf("%d\n", ans);
		scan.close();
	}
}

Measured memory_bytes: 65572
from copy import copy, deepcopy
from collections import Counter
from math import sqrt

MOD = 10**9 + 7
K = int(input())
A, B = list(map(int, input().split()))
flag = 0
for i in range(B-A+1):
    if (A+i) % K == 0:
        flag = 1
        break

if flag == 0:
    print("NG")
else:
    print("OK")


Measured memory_bytes: 9628
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

int main(){
	int n; cin >> n;
	vector<ll> a(n),b(n);
	ll mi=1e9;
	ll sum=0;
	for(int i=0;i<n;i++){
		cin >> a[i] >> b[i];
		if(a[i]>b[i])mi=min(mi,b[i]);
		sum+=a[i];
	}
	if(a==b){
		cout << 0 << endl;
	}
	else{
		cout << sum-mi << endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N, D;
long long X[51][51];

long long solve() {
    long long res = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            long long sum = 0;
            for (int k = 0; k < D; ++k) {
                sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            bool exist = false;
            for (long long d = 0; d <= 10000; ++d) {
                if (sum == d*d) exist = true;
            }
            if (exist) ++res;
        }
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> N >> D) {
        for (int i = 0; i < N; ++i) for (int j = 0; j < D; ++j) cin >> X[i][j];
        cout << solve() << endl;
    }
}


















Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[110][110];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}


int main() {
	int x;
	cin >> x;
	if (x == 1) {
		cout << 0 << " " << -1 << endl;
		return 0;
	}
	for (int a = -300; a <= 300; a++) {
		for (int b = -300; b <= 300; b++) {
			if (a * a * a * a * a - b * b * b * b * b == x) {
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3588
import heapq


def submit():
    x, y, z, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))

    a.sort(reverse=True)
    b.sort(reverse=True)
    c.sort(reverse=True)

    def get(i, j, k):
        return a[i] + b[j] + c[k], (i, j, k)

    check = set()
    check.add((0, 0, 0))
    ans = [get(0, 0, 0)]
    q = []
    for _ in range(k - 1):
        prev, (i, j, k) = ans[-1]
        
        if i < x - 1:
            new_triple = (i + 1, j, k)
            if new_triple not in check:
                check.add(new_triple)
                s, _ = get(*new_triple)
                heapq.heappush(q, (-s, new_triple))
        
        if j < y - 1:
            new_triple = (i, j + 1, k)
            if new_triple not in check:
                check.add(new_triple)
                s, _ = get(*new_triple)
                heapq.heappush(q, (-s, new_triple))

        if k < z - 1:
            new_triple = (i, j, k + 1)
            if new_triple not in check:
                check.add(new_triple)
                s, _ = get(*new_triple)
                heapq.heappush(q, (-s, new_triple))

        next_s, next_triple = heapq.heappop(q)
        ans.append((-next_s, next_triple))
        # print(ans)

    for s, _ in ans:
        print(s)
        

submit()

Measured memory_bytes: 5104
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
ll n,m,f[2005][2005];
ll fact[4000005],inv[4000005];
ll quick_pow(ll x,ll a)
{
	ll ans=1;
	while(a)
	{
		if(a&1)ans=ans*x%MOD;
		x=x*x%MOD;
		a>>=1;
	}
	return ans;
}
ll C(ll n,ll m)
{
	return fact[n]*inv[n-m]%MOD*inv[m]%MOD;
}
int main()
{
	scanf("%lld%lld",&n,&m);
	fact[0]=1;
	for(int i=1;i<=4000000;i++)fact[i]=fact[i-1]*i%MOD;
	inv[4000000]=quick_pow(fact[4000000],MOD-2);
	for(int i=3999999;i>=0;i--)inv[i]=inv[i+1]*(i+1)%MOD;
	if(m==1)
	{
		printf("1\n");
		return 0;
	}
	f[n][n]=1;
	for(int i=n;i>=0;i--)
	for(int j=n;j>=i;j--)
	{
		f[i][j]%=MOD;
		if(i)f[i-1][j]+=f[i][j];
		if(i!=j)f[i][j-1]+=f[i][j]*C(i+j*(m-1)-1,m-2)%MOD;
	}
//	for(int i=0;i<=n;i++)
//	{
//		for(int j=0;j<=n;j++)
//		  printf("%lld ",f[i][j]);
//		printf("\n");
//	}
	printf("%lld\n",f[0][0]*fact[n]%MOD);
	return 0;
}

Measured memory_bytes: 92800
#include <iostream>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <queue>
#include <vector>
#define lld long long
#define PB push_back
#define F first
#define S second
#define jizz cin.tie(0);ios_base::sync_with_stdio(0);
#define endl '\n'
using namespace std;
typedef pair<int,int> Pair;
int c[502],s[502],f[502];
int main(){jizz
	int n;cin >> n;
	for(int i = 1; i < n ; i++){
		cin >> c[i] >> s[i] >> f[i];
	}
	for(int i = 1; i < n ; i++){
		int tmp = 0;
		for(int j = i; j < n ; j++){
			tmp = max(s[j],tmp);
			int p = (tmp - s[j])%f[j];
			if(p == 0){
				tmp += c[j];
			}else{
				tmp += f[j]-p;
				tmp += c[j];
			}
		}
		cout << tmp <<endl;
	}
	cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(void){
	char *p, s[21];
	int i=0;
	
	std::cin >> s;
	p=s;
	while(*(p++));
	for(p-=2; p>=s; p--)
		std::cout << *p << std::flush;
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        int M = ni();
        graph = new HashMap<>();
        int[] A = new int[M];
        int[] B = new int[M];
        for (int i = 0; i < M; i++) {
            int a = ni();
            int b = ni();
            A[i] = a;
            B[i] = b;
            graph.putIfAbsent(a, new HashSet<>());
            graph.get(a).add(b);
            graph.putIfAbsent(b, new HashSet<>());
            graph.get(b).add(a);
        }
        int ans = 0;
        for (int i = 0; i < M; i++) {
            graph.get(A[i]).remove(B[i]);
            graph.get(B[i]).remove(A[i]);
            visited = new HashSet<>();
            dfs(1);
            // System.out.println(visited.toString());
            if(visited.size()<N) ans ++;
            graph.get(A[i]).add(B[i]);
            graph.get(B[i]).add(A[i]);
        }
        out.println(ans);
    }
    HashSet<Integer> visited;
    HashMap<Integer, HashSet<Integer>> graph;
    void dfs(int cur){
        visited.add(cur);
        if(!graph.containsKey(cur))return;
        for (Integer next : graph.get(cur)) {
            if(visited.contains(next))continue;
            else dfs(next);
        }
    }

    final int mod = 1000000007;
    int mul(int x, int y){
        return (int)((x * 1L * y) % mod);
    }
    int add(int x, int y) {
        x += y;
        return x >= mod ? (x - mod) : x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        return x >= mod ? (x - mod) : x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

int main()
{
	int a, b;
	cin >> a >> b;
	int d = a / b;
	int r = a % b;
	double f = a * 1.0 / b;
	cout << d << " " << r << " " 
		 << fixed
		 << setprecision(5)
		 << f
		 << endl;
	return 0;
}

Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    if(n%10==3)printf("bon\n");
    else if(n%10==0 || n%10==1 || n%10==6 || n%10==8)printf("pon\n");
    else printf("hon\n");
    return 0;
}


Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;

int h,w,n;
char ss[1000001];
char field[1001][1001];
int sx,sy;
int gx,gy;

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

int d[4][1001][1001];
int toAng[4][4][1000001];
const int INF=1000000000;

typedef pair<int,int> pii;

int dfs(int cang,int oang,int pos){
	if(cang==oang)return pos;
	else if(pos==n)return INF;
	else if(toAng[cang][oang][pos]!=-1)return toAng[cang][oang][pos];
	int nang;
	if(ss[pos]=='L')nang=(cang-1+4)%4;
	else nang=(cang+1)%4;
	return toAng[cang][oang][pos]=dfs(nang,oang,pos+1);
}

bool bfs(){
	memset(toAng,-1,sizeof(toAng));

	// »ÝÌü«©çÚIÌü«ÖÚ®·éÌÉÇ±ÜÅ^[ðg¤Kvª é©vZ
	// ìêÈ¢ÈçÎINF
	// cang==oagn
//	for(int i=0;i<4;i++)for(int j=0;j<n;j++)toAng[i][i][j]=i;
//	// cang!=oang&&pos==n
//	for(int i=0;i<4;i++)for(int j=0;j<4;j++)if(i!=j)toAng[i][j][n]=INF;
//	for(int k=n-1;k>=0;k--){
//		for(int i=0;i<4;i++){
//			for(int j=0;j<4;j++){
//				if(j==i)continue;
//				int nang;
//				int cang=i;
//				int oang=j;
//				int pos=k;
//				if(ss[pos]=='L')nang=(cang-1+4)%4;
//				else nang=(cang+1)%4;
//				toAng[cang][oang][pos]=toAng[nang][oang][pos+1];
//			}
//		}
//	}
	//  éêÖB·éÌÉKvÈÅ¬^[
	priority_queue<pair<pii,pii>,vector<pair<pii,pii> >,greater<pair<pii,pii> > > pq;
	for(int i=0;i<4;i++)for(int j=0;j<1001;j++)for(int k=0;k<1001;k++)d[i][j][k]=INF;
	pq.push(make_pair(pii(0,0),pii(sy,sx)));
	d[0][sy][sx]=0;
	while(pq.size()){
		pair<pii,pii> p=pq.top();
		pq.pop();
		int cx=p.second.second;
		int cy=p.second.first;
		int cang=p.first.second;
		int cpos=p.first.first;
		// àµ»ÝÌRXgæè¬³¢àÌª·ÅÉ¶ÝµÄ¢½ÌÈçÎ
		if(d[cang][cy][cx]<cpos)continue;
		// 4ûüÖÚ®
		for(int i=0;i<4;i++){
			int ny=cy+dy[i];
			int nx=cx+dx[i];
			int nang=i;
			// ÌûüðìêéÜÅposðißé
			//int npos=toAng[cang][nang][cpos];
			int npos=dfs(cang,nang,cpos);
			if(npos!=INF&&ny>=0&&nx>=0&&ny<h&&nx<w&&field[ny][nx]=='.'&&d[nang][ny][nx]>npos){
				d[nang][ny][nx]=npos;
				pq.push(make_pair(pii(npos,nang),pii(ny,nx)));
			}
		}
	}
	for(int i=0;i<4;i++)if(d[i][gy][gx]!=INF)return true;
	return false;
}

int main(){
	while(cin>>h>>w>>n&&(h|w|n)){
		for(int i=0;i<n;i++)cin>>ss[i];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++){
			cin>>field[i][j];
			if(field[i][j]=='S'){
				sx=j;
				sy=i;
				field[i][j]='.';
			}
			else if(field[i][j]=='G'){
				gx=j;
				gy=i;
				field[i][j]='.';
			}
		}
		if(bfs())cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
def dfs(i, a, b, c)
  
  return if a < 0 || b < 0 || c < 0
  
  if i == N
    puts "Yes"
    puts $ans
    exit
  end
  
  if S[i] == "AB"
    $ans[i] = 'A'
    dfs(i+1, a+1, b-1, c  )
    $ans[i] = 'B'
    dfs(i+1, a-1, b+1, c  )
  elsif S[i] == "AC"
    $ans[i] = 'A'
    dfs(i+1, a+1, b  , c-1)
    $ans[i] = 'C'
    dfs(i+1, a-1, b  , c+1)
  else
    $ans[i] = 'B'
    dfs(i+1, a  , b+1, c-1)
    $ans[i] = 'C'
    dfs(i+1, a  , b-1, c+1)
  end
  
  puts "No" if i == 0
end

N, a, b, c = gets.to_s.split.map{|e|e.to_i}
S = Array.new(N){ gets.to_s.chomp }

$ans = Array.new(N)
dfs(0, a, b, c)

Measured memory_bytes: 43196
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	x := io.NextInt()
	if x >= 30 {
		io.Println("Yes")
	} else {
		io.Println("No")
	}
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {

    ll N,W; cin >> N >> W;
    vector<ll> w(N),v(N);
    for(ll i=0; i<N; i++) cin >> v[i] >> w[i];

    vector<vector<ll>> dp(N+1,vector<ll>(N*100+1,INT_MAX));
    dp[0][0] = 0;
    for(ll i=0; i<N; i++) {
	for(ll j=0; j<N*100; j++) {
	    dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
	    if( dp[i][j] + w[i] <= W)
		dp[i+1][j+v[i]] = min(dp[i+1][j+v[i]], dp[i][j] + w[i]);
	}
    }
    for(ll i=N*100; i>=0; i--) {
	if(dp[N][i] != INT_MAX) {
	    cout << i << endl;
	    return 0;
	}
    }
	    
}

Measured memory_bytes: 10796
import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict


def input():
    return sys.stdin.readline().strip()


def main():
    h, w, m = [int(i) for i in input().split()]
    d_h = defaultdict(int)
    d_w = defaultdict(int)
    bom = set()
    for _ in range(m):
        h, w = [int(i) for i in input().split()]
        bom.add((h, w))
        d_h[h] += 1
        d_w[w] += 1
    H = sorted(d_h.items(), key=lambda x: -x[1])
    W = sorted(d_w.items(), key=lambda x: -x[1])
    ans = 0
    for k_h, v_h in H:
        for k_w, v_w in W:
            tmp = v_h + v_w
            if (k_h, k_w) in bom:
                tmp -= 1
                ans = max(tmp, ans)
            else:
                ans = max(tmp, ans)
                break
        else:
            continue
        break

    for k_w, v_w in W:
        for k_h, v_h in H:
            tmp = v_h + v_w
            if (k_h, k_w) in bom:
                tmp -= 1
                ans = max(tmp, ans)
            else:
                ans = max(tmp, ans)
                break
        else:
            continue
        break
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 231896
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int tx[] = {0,1,1,1,0,-1,-1,-1};
const static int ty[] = {-1,-1,0,1,1,1,0,-1};
 
static const double EPS = 1e-8;

class Data {
public:
  Data () : satisfaction_vol(0),mask(0) {}
  ll satisfaction_vol;
  int mask;
};

ll dp[101][1<<16];

int main(){
  int guy_num;
  while(~scanf("%d",&guy_num)){
    if(guy_num == 0) break;
    Data guy[100];

    memset(dp,0,sizeof(dp));

    for(int i=0;i<guy_num;i++){

      int date_num;
      ll satisfaction_vol;
      scanf("%d %lld",&date_num,&satisfaction_vol);
      int mask = 0;
      for(int j=0;j<date_num;j++){
    	int begin,end;
    	scanf("%d %d",&begin,&end);
	for(int k=begin-6;k<end-6;k++) mask |= (1<<k);
      }
      guy[i].mask = mask;
      guy[i].satisfaction_vol = satisfaction_vol;
    }

    for(int i=0;i<guy_num;i++){
      for(int S=0;S<=(1<<16)-1;S++){
	dp[i+1][S] = max(dp[i+1][S],dp[i][S]);
    	if((S & guy[i].mask) == 0){
    	  int next = S | guy[i].mask;
    	  dp[i+1][next] = max(dp[i+1][next],dp[i][S]+guy[i].satisfaction_vol);
    	}
      }
    }

    ll max_v = 0;
    for(int S=0;S<=(1<<16)-1;S++) max_v = max(dp[guy_num][S],max_v);
    printf("%lld\n",max_v);
  }
}

Measured memory_bytes: 52908
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll ,ll> pll;


ll n, k;
ll cnt[200005];
ll gt(ll x)
{
        if(x==k) x=0;
        return cnt[x];
}
int main()
{
        cin >> n >> k;
        for(ll i=1;i<=n;i++) {
                cnt[(i%k)]++;
        }
        ll ans = 0;
        for(ll M=0;M<k;M++) {
                ll yo = gt(M);
                if(((M+M)%k) == 0){
                        //cout << M << endl;
                        ans += yo*gt(k-M)*gt(k-M);
                }
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 1024
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
 
int main() {
    int n;
    cin >> n;
    uint64_t b[n-1];
    for (int i = 0; i < n-1; ++i) {
        cin >> b[i];
    }
    uint64_t sum = 0;
    sum += b[n-2];
    for (int i = 0; i < n - 2; i++) {
	if (b[i] < b[i+1]) {
	    sum += b[i];
	} else {
	    sum += b[i+1];
	}
    }
    sum += b[0];
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    ll n,m;
    cin >> n >> m;
    if(n>m){
        swap(n,m);
    }
    //n<=m
    if(n==1){
        if(m==1){
            cout << 1 << endl;
        }else{
            cout << m-2 << endl;
        }       
    }else if(n==2){
        cout << 0 << endl;
    }else{
        cout << (n-2)*(m-2) << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;



long long int K,N,H[200005],res=0;
int main() {
	cout << fixed << setprecision(18);
	
	cin>>N>>K;
	for(int i=0;i<N;i++){
		cin>>H[i];
	}
	sort(H,H+N);
	for(int i=0;i<N-K;i++){
		res+=H[i];
	}
	cout<<res;
} 

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

int main() {
    int N, M, ans;
    cin >> N >> M;
    vector<int> s(M), c(M);
    rep(i,M) {
        cin >> s.at(i) >> c.at(i);
    }
    int x = 0;
    int xx = 0;
    int xxx = 0;
    if (N == 1) {
        rep(i,M) {
            if (s.at(i) == 1) {
                ans = c.at(i);
            }
        }
        rep(i,M) {
            if (s.at(i) > 1) {
                ans = -1;
            }
        }
    }
    if (N == 2) {
        rep(i,M) {
            if (s.at(i) == 1) {
                xx = c.at(i);
            }
            if (s.at(i) == 2) {
                x = c.at(i);
            }
        }
        ans = xx * 10 + x;
        if (xx == 0) {
            ans = 10 + x;
        }
        rep(i,M) {
            if (s.at(i) > 2) {
                ans = -1;
            }
        }
    }
    if (N == 3) {
        rep(i,M) {
            if (s.at(i) == 1) {
                xxx = c.at(i);
            }
            if (s.at(i) == 2) {
                xx = c.at(i);
            }
            if (s.at(i) == 3) {
                x = c.at(i);
            }
        }
        ans = xxx * 100 + xx * 10 + x;
        if (xxx == 0) {
            ans = 100 + xx * 10 + x;
        }
        rep(i,M) {
            if (s.at(i) > 3) {
                ans = -1;
            }
        }
    }
    rep(i,M) {
        rep(j,M){
            if ((i != j) && (s.at(i) == s.at(j)) && (c.at(i) != c.at(j))) {
                ans = -1;
            }
        }
    }
    rep(i,M) {
        if ((N != 1) && (s.at(i) == 1) && (c.at(i) == 0)) {
            ans = -1;
        }
    }
    cout << ans << endl;
    return 0;
}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

unordered_map<i32, u64> a;

int main() {
    i32 n,q,bi,ci;
    u64 sum=0;
    cin >> n;

    rep(i, n) {
      i32 ai;
      cin >> ai;
      a[ai] += 1;
      sum += ai;
    }

    cin >> q;

    rep(i, q) {
      cin >> bi >> ci;

      sum += ci * a[bi];
      sum -= bi * a[bi];

      a[ci] += a[bi];
      a[bi] = 0;

      cout << sum << endl;
    }

  return 0;
}


Measured memory_bytes: 7132
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n; cin >> n;
	vector<string>s(n);
	for (int i = 0; i < n; i++) cin >> s[i];

	string abc = "abcdefghijklmnopqrstuvwxyz";
	string ans;
	for (int i = 0; i < 26; i++) {
		int cnt = (int)1e9;
		for (int j = 0; j < s.size(); j++) {
			int tmp = count(s[j].begin(), s[j].end(), abc[i]);
			cnt = min(cnt, tmp);
		}
		for (int j = 0; j < cnt; j++) {
			ans += abc[i];
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    ll n ; 
    cin >> n ;
    ll L = 1 , R = 1e9 ; 
    ll ans = -1 ; 
    while(L<=R){
    	ll mid = L + (R-L) / 2 ;
    	if ( (mid*(mid+1))/2 >= n ){
    		ans = mid ; 
    		R = mid - 1 ;
    	}
    	else L = mid + 1 ;
    }
    cout << ans << endl;
    return 0 ;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)

int main(){
  int N;
  cin >> N;
  vector<int> D1(N), D2(N);
  rep(i,N){
    cin >> D1.at(i) >> D2.at(i);
  }
  bool zoro = false;
  rep(i,N-2){
    if(D1.at(i)==D2.at(i)){
      if(D1.at(i+1)==D2.at(i+1)){
        if(D1.at(i+2)==D2.at(i+2)){
          zoro = true;
        }
      }
    }
  }
  if(zoro){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


vector<ll> prime_decompose(ll P) {
	vector<ll> res;
	for (ll prime = 1; prime*prime <= P; ++prime) {
		if (P%prime == 0) {
			res.push_back(prime);
			if (prime != P / prime)res.push_back(P / prime);
		}
	}
	return res;
}

ll sum;

int main() {
	ll N, K; cin >> N >> K;
	vector<ll> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum += A[i];
	}
	sort(A.rbegin(), A.rend());

	vector<ll> prm = prime_decompose(sum);
	sort(prm.rbegin(), prm.rend());

	for (int i = 0; i < prm.size(); i++) {
		vector<ll> debt(N);
		ll ss = 0;
		ll hh = 0;
		for (int j = 0; j < N; j++) {

			debt[j] = A[j] % prm[i];
			ss += debt[j];
			hh += prm[i] - debt[j];
		}
		sort(debt.begin(), debt.end());
		ll cost = 0;
		for (int j = 0; j < N - ss / prm[i]; j++)cost += debt[j];
		if (cost <= K) {
			cout << prm[i] << endl;
			return 0;
		}



	}



	return 0;
}


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

int main() { 
  int a,b,c;
  cin >> a >> b >> c;
  cout << max(0, c - (a - b)) << endl;
  return 0;
}

Measured memory_bytes: 256
#coding: utf-8

S = input()
N = len(S)

A = ["dream", "erase", "eraser", "dreamer"]
dp = [1] + [0]*N
for i in range(5,N+1):
    if i >= 5 and S[i-5:i] == A[0]: dp[i] = dp[i-5]
    if i >= 5 and S[i-5:i] == A[1]: dp[i] = dp[i-5]
    if i >= 6 and S[i-6:i] == A[2]: dp[i] = dp[i-6]
    if i >= 7 and S[i-7:i] == A[3]: dp[i] = dp[i-7]

if dp[N]: print("YES")
else: print("NO")

Measured memory_bytes: 4724
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N, Q = MAP()
    S = input()
    t = [0] * (N + 1)
    for i in range(N - 1):
        if S[i:i+2] == 'AC':
            t[i + 1] = t[i] + 1
        else:
            t[i + 1] = t[i]
    ans = []
    for i in range(Q):
        l, r = MAP()
        ans.append(t[r - 1] - t[l - 1])
    for i in range(Q):
        print(ans[i])

if __name__ == '__main__':
    main()


Measured memory_bytes: 53852
#include <iostream>
#include <cstdlib>
#include <vector>
#include <math.h>
using namespace std;
int main()
{
    double x1, x2, y1, y2, d;
    cin >> x1 >> y1 >> x2 >> y2;
    d = sqrt(pow(x2-x1, 2) + pow(y2-y1, 2));
    printf("%.8f", d);
    cout << endl;
    return 0;
}



Measured memory_bytes: 3196
<?php
	fscanf(STDIN,'%d',$n);
	$l=explode(' ',fgets(STDIN));
	$s=$m=0;
	for($i=0;$i<$n;$i++){
		$s+=$l[$i]+=0;
		if($m<$l[$i])$m=$l[$i];
	}
	echo $s>$m*2?Yes:No;

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

using namespace std;

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i =0;i<t;i++)
#define bs(a,x) binary_search(a.begin(),a.end(),x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int,int> 
#define umpl unordered_map<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mod 1000000007 
#define N 10000000
#define all(a) a.begin(),a.end()
#define point pair<ll,ll>

const int inf = 100000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM =100005;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll min(ll a, ll b){return a<b?a:b;}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
    C[0] = 1;
  
    for (ll i = 1; i <= n; i++) 
    {
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    fio;
    ll n,m;cin>>n>>m;
    ll ans=binomialCoeff(n,2)+binomialCoeff(m,2);
    cout<<ans<<"\n";
}



Measured memory_bytes: 256
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]


a,b,c = map(int, input().split())

ans = "NO"
for i in range(1, b+1):
    if (a*i % b == c):
        ans = "YES"
        break
print(ans)



Measured memory_bytes: 8960
import java.util.Scanner;

public class Main implements Runnable {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        long n = sc.nextLong(), k = sc.nextLong();
        boolean div = k % 2 == 0;
        long divk = 1;
        if (k / 2 + n / k * k > n) {
            divk = 0;
        }

        if (div && k > n && k <= n * 2) {
            System.out.println(1);
        } else {
            System.out.println(((long) Math.pow(n / k, 3) + (div ? (long) Math.pow(n / k + divk, 3) : 0L)));
        }
    }
}

Measured memory_bytes: 25812
#include<bits/stdc++.h>
using namespace std;
int main(void) {
  int a,b,i;
  cin >> a >> b;
  vector <string> vac(a);
    for( i=0; i<a; i++) {
        cin >> vac.at(i);
    }

  //the most top raw
  for(i=0; i<b+2; i++) {
      cout << "#";
  }
  cout << endl;
//word output
  for(i=0; i<a; i++) {
      cout << "#" <<  vac.at(i) << "#" << endl;
  }

//bottom raw
for (i=0; i<b+2; i++) {
    cout << "#";
}
cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int h, w;
    
    while (true) {
        cin >> h >> w;
        if (h == 0 && w == 0) break;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (i == 0 || i == h - 1 || j == w - 1 || j == 0) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3068
num = []
for i in range(3): num.append([int(i) for i in input().split()])

q = int(input())
val=[]
for i in range(q): val.append(int(input()))

for p in val:
    for i in range(3):
        for j in range(3):
            if p == num[i][j]: num[i][j]=-1

ans='No'

for j in range(3): #colunas
    if(num[0][j] == -1 and num[1][j] == -1 and num[2][j] ==-1): ans='Yes'
    if(num[j][0] == -1 and num[j][1] == -1 and num[j][2] ==-1): ans='Yes'

if(num[0][0] == -1 and num[1][1] == -1 and num[2][2] ==-1): ans='Yes'
if(num[0][2] == -1 and num[1][1] == -1 and num[2][0] ==-1): ans='Yes'


print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n, a;
    cin >> n >> a;
    if ( n % 500 > a ) cout << "No" << endl;
    else               cout << "Yes" << endl;
    return 0;
}


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

int main(){
    int A,B,C,X;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> X;

    int ans = 0;

    for (int i=0; i<(A+1); i++){
        for (int j=0; j<(B+1); j++){
            for (int k=0; k<(C+1); k++){
                if (500 * i + 100 * j + 50 * k == X) ans = ans + 1;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
fn getline() -> String {
	let mut  __ret = String::new();
	std::io::stdin().read_line(&mut __ret).ok();
	return __ret;
}

fn check(x:i32) -> i32 {
	if x == 2 {
		0
	}else if x == 4 || x == 6 || x == 9 || x == 11{
		1
	}else{
		2
	}
}

fn main() {
	// let line = io::stdin().read_line().unwrap();
	let s = getline();
	let a:Vec<_> = s.trim().split(' ').collect();
	let x:i32 = a[0].parse().unwrap();
	let y:i32 = a[1].parse().unwrap();
	if (check (x)) == (check (y)) {
		println!("Yes");
	} else {
		println!("No");
	}
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstring>
#include <set>
#include <vector>

using namespace std;

using ll = long long;

int main() {
    int n, m;
    cin >> n >> m;
    char arr[100][100];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> arr[i][j];
        }
    }
    int extra = m + 2;
    cout << string(extra, '#') << '\n';
    for (int i = 0; i < n; i++) {
        cout << '#';
        for (int j = 0; j < m; j++) {
            cout << arr[i][j];
        }
        cout << "#\n";
    }
    cout << string(extra, '#') << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
int vis[200005],a[200005];
void solve(){
	ll n,k;
	cin>>n>>k;
	rep(i,n)cin>>a[i+1];
	ll offset=0;
	vector<int>path;
	int st=1;
	path.pb(st);
	vis[1]=1;
	while(!vis[a[st]]){
		path.pb(a[st]);
		vis[a[st]]=1;
		st=a[st];
	}
	int i=0;
	for(i=0;path[i]!=a[st];i++);
	offset=i;
	ll cyclelen=path.size()-offset;
	if(k<=offset)cout<<path[k];
	else{
		k-=offset;
		k%=cyclelen;
		cout<<path[offset+k];
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 5844
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
#define rep(i,n) for(int i=0;i<(n);i++)
 
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n) cin>>a[i];
    vector<int>rate(9,0);
    rep(i,n){
     if(a[i]<=3199)rate[a[i]/400]++;
     else rate[8]++;
    }
    int minc=0;
    rep(i,8){
        if(rate[i]!=0)
          minc+=1;
    }
    int maxc=minc+rate[8];
    minc=max(1,minc);
    cout<<minc<<" "<<maxc<<endl;
}

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

typedef long long ll;
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);

    for (int i = 0; i < n; ++i) cin >> h[i];
    int minv = INT_MAX;

    sort(h.begin(), h.end());

    for (int i = 0; i < n - (k - 1); ++i) {
        minv = min(h[i + k - 1] - h[i], minv);
    }
    cout << minv;
    return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    int c = Integer.parseInt(str[2]);
    int sum = a+b+c;
    int max = Math.max(Math.max(a,b),c);
    int min = Math.min(Math.min(a,b),c);
    int middle = sum-max-min;
    int count = 0;
    count = max - middle;
    min += count;
    count += (max-min)/2;
    if((max-min)%2==1)
      count+=2;
    System.out.println(count);
  }
}

Measured memory_bytes: 32648
import java.util.Scanner;

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

                int N = scan.nextInt();
                int X = scan.nextInt();
                int T = scan.nextInt();

                if (N%X == 0) {
                	System.out.println(N/X * T);
                } else {
                	System.out.println(N/X * T + T);
                }

                scan.close();

        }
}

Measured memory_bytes: 35600
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }

    vector<int> dp(n,INT_MAX);
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        for(int j=i-1,jump=0; j>=0&&jump<k;j--,jump++){
                dp[i]=min(dp[i],dp[j]+abs(h[j]-h[i]));
        }
    }
    cout<<dp[n-1]<<endl;
    
    return 0;
}

Measured memory_bytes: 4052
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    String str = s.next();
    int count = 0;
    for (int i = 1; i < str.length(); i++) {
      if (str.charAt(i-1) != str.charAt(i)) {
        count++;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 13844
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 200005
#define __TRUE "Yes"
#define __FALSE "No"
using namespace std;

int main() {
  int x;
  cin >> x;
  //1は絶対
  int max=1;
  for(int num=2;num<=x;num++) {
    int sqN=num*num;
    while(sqN<=x) {
      if(max<sqN) {
        max=sqN;
      }
      sqN *= num;
    }
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
using namespace std;

int main() {
  long long N, K;
  scanf("%lld%lld", &N, &K);
  long long odd = 0;
  long long even = 0;
  if (K % 2 == 1) {
    for (int m = K ; m <= N ; m = m + K) {
      odd++;
    }
  } else {
    for (int m = K/2 ; m <= N ; m = m + K) {
      odd++;
    }
    for (int m = K ; m <= N ; m = m + K) {
      even++;
    }
  }
  printf("%lld\n", odd*odd*odd + even*even*even);
}

Measured memory_bytes: 128
#include<stdio.h>

int main(void){
  int h,w,n;
  int m,p;
  
  scanf("%d\n%d\n%d",&h,&w,&n);
  if(h>w){
    m=h;
  }else{
    m=w;
  }
  
  p=n/m;
  if(n%m!=0){
    p++;
  }
  
  printf("%d",p);
  
  return 0;
}

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

#define ll long long
#define ull unsigned long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    int br = 0;
    vector<int> a(n), b(8);
    rep(i,n){
        cin >> a[i];
        if(a[i]/400 > 7) br ++;
        else b[a[i]/400] ++; 
    }
    int mi = 0;
    rep(i, 8){
        if(b[i]) mi ++;
    }
    if(mi == 0){
        cout << 1 << " " << br;
    }
    else{
        cout << mi << " " << mi+br;
    }
    return 0;
}

Measured memory_bytes: 3632
n, m = map(int, input().split())
aaa = [input() for _ in range(n)]
bbb = [input() for _ in range(m)]
ans = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        flag = True
        for k in range(m):
            for l in range(m):
                if aaa[i + k][j + l] != bbb[k][l]:
                    flag = False
        if flag:
            ans = True
if ans:
    print('Yes')
else:
    print('No')


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

using namespace std;

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef complex<double> point;
struct circle { point p; double r; };
struct line { point p, q; };

const double eps = 1e-9;

double sign(double x) { return x < -eps ? -1 : x > eps; }

circle read(){
	double x, y, r; cin >> x >> y >> r;
	return {point(x, y), r};
}

namespace std
{
	bool operator<(point a, point b)
	{
		if (a.real() != b.real())
			return a.real() < b.real();
		return a.imag() < b.imag();
	}
}

// circle-circle intersection
vector<point> intersect(circle C, circle D)
{
	double d = abs(C.p - D.p);
	if (sign(d - C.r - D.r) > 0) return {};       // too far
	if (sign(d - abs(C.r - D.r)) < 0) return {}; // too close
	double a = (C.r*C.r - D.r*D.r + d*d) / (2*d);
	double h = sqrt(C.r*C.r - a*a);
	point v = (D.p - C.p) / d;
	if (sign(h) == 0) return {C.p + v*a};         // touch
	return {C.p + v*a + point(0,1)*v*h,           // intersect
			C.p + v*a - point(0,1)*v*h};
}

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

	circle c1 = read(), c2 = read();
	auto ans = intersect(c1, c2);
	if (ans.size() == 1) ans.push_back(ans[0]);
	sort(ans.begin(), ans.end());
	cout.precision(10);
	for (auto pp : ans)
		cout << fixed << pp.real() << " " << pp.imag() << " ";
	cout << endl;

	return 0;
}

Measured memory_bytes: 1320