akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

using i64 = long long int;

class UnionFindTree {
  private:
    vector<int> par;   // 親
    vector<int> depth; // 木の深さ

  public:
    // n要素で初期化
    UnionFindTree(int n) {
        for (int i = 0; i < n; i++) {
            par.push_back(i);
            depth.push_back(0);
        }
    }

    // 木の根を求める
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;

        if (depth[x] < depth[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (depth[x] == depth[y])
                depth[x]++;
        }
    }

    // xとyが同じ集合に属するか否か
    bool same(int x, int y) { return find(x) == find(y); }
};

int main(){
    int n, q;
    cin >> n >> q;
    UnionFindTree uft = UnionFindTree(n);
    for(int i=0;i<q;++i){
        int c, x, y;
        cin >> c >> x >> y;
        if(c == 0){
            uft.unite(x, y);
        }else{
            cout << (uft.same(x, y) ? 1 : 0) << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3276
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		char[] s = nc();

		String ans = "";

		for (char c : s) {
			if (c == '0') {
				ans += "0";
			}
			if (c == '1') {
				ans += "1";
			}
			if (c == 'B') {
				if (ans.length() >= 1) {
					ans = ans.substring(0, ans.length() - 1);
				}
			}
		}

		out(ans);
	}

	/*
	 * 以下メソッド集
	 */
	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static double nd() {
		return sc.nextDouble();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void out(Object obj) {
		System.out.println(obj.toString());
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static double max(double d, double e) {
		return Math.max(d, e);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static double min(double d, double e) {
		return Math.min(d, e);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}
}

class XY {
	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
#include<cassert>
using namespace std;
#include<atcoder/all>
using namespace atcoder;


#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

using mint = modint998244353;

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

/////////////////////////////////////


int main() {
	string S;
	cin >> S;
	ll N = S.size();

	vector<int> suf = suffix_array(S);
	vector<int> lcp = lcp_array(S, suf);

	ll ans = 0;
	rep(i, N) {
		ll c = N - suf[i];
		if (i > 0)c -= lcp[i - 1];
		ans += c;
	}
	cout << ans << endl;
}


Measured memory_bytes: 15660
#include<stdio.h>
int cnt;
void insertionSort(int*,int,int);

int main(){
  int n,A[1000000],i,m=1,hn=1;
  int G[100];

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  
  //shellSort
  cnt=0;
  for(i=0; i<100; i++){
    hn=hn*3+1;
    if(n<=hn){
      break;
    }
    m++;
  }

  G[m-1]=1;
  for(i=m-2; i>=0; i--){
    G[i]=G[i+1]*3+1;
  }
  /*for(i=0; i<=m; i++){
    printf("G[%d]:%d\n",i,G[i]);
  }*/
  for(i=0; i<=m; i++){
    insertionSort(A, n, G[i]);
  }

  printf("%d\n",m);
  for(i=0; i<m; i++){
    if(i){
      printf(" ");
    }
    printf("%d",G[i]);
  }
  printf("\n%d\n",cnt);
  for(i=0; i<n; i++){
    printf("%d\n",A[i]);
  }

  return 0;
}

void insertionSort(int* A,int n,int g){
  int i,v,j;
  for(i=g; i<n; i++){
    v=A[i];
    j=i-g;
    while(j>=0 && A[j]>v){
      A[j+g]=A[j];
      j=j-g;
      cnt++;
    }
    A[j+g]=v;
  }
}



Measured memory_bytes: 5640
from itertools import accumulate 

n,m,k=map(int,input().split())
alst=list(accumulate(list(map(int,input().split()))))
blst=list(accumulate(list(map(int,input().split()))))
#print(alst)
#print(blst)

mx=0
for i in range(len(blst)-1,-1,-1):
    if blst[i]<=k : mx=i+1;break

for i in range(len(alst)):
#    print(i,mx)
    work=k-alst[i]
    if work<0 : break
    if i+1>=mx :
        for j in range(len(blst)):
            if blst[j]>work : mx=i+1+j;break
        else : mx=i+1+len(blst)
    else:
        if work<=blst[mx-i-2]: continue
        for j in range(mx-i-1,len(blst)):
            if blst[j]>work : mx=i+1+j;break
        else : mx=i+1+len(blst)

print(mx)       


Measured memory_bytes: 45296
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	int mid;
	string s,ss;
	cin>>n;
	cout<<"0"<<endl;
	cout.flush();
	cin>>s;
	if(s=="Vacant"){
		return 0;
	}
	else {
		int l=1,r=n-1;
		while(l<r){
			mid=(l+r)/2;
			cout<<mid<<endl;
			cout.flush();
			cin>>ss;
			if(ss=="Vacant"){
				return 0;
			}
			string ans;
			if(mid%2==0){
				ans=s;
			}
			else {
				if(s=="Female"){
					ans="Male";
				}
				else {
					ans="Female";
				}
			}
			if(ss==ans){
				l=mid+1;
			}
			else {
				r=mid;
			}
		}
		cout<<l<<endl;
		cout.flush();
	}
}

Measured memory_bytes: 852
using System;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Text.RegularExpressions;
using System.Threading;

namespace Atcoder
{
	class Program
	{
		//string s = Console.ReadLine();
		//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
		//int H = intArray[0];
		//int W = intArray[1];
		//int N = int.Parse(Console.ReadLine());
		//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());
		//Boolean ok = false;

		//Console.WriteLine(ans);
		//Console.WriteLine("Yes");
		//Console.WriteLine("No");
		//Console.ReadKey();
		//Console.WriteLine(cnt);

		//string[] strArray = Console.ReadLine().Split(' ').ToArray();
		//string S = strArray[0];
		//string T = strArray[1];
		static void Main(string[] args)
		{
			int N = int.Parse(Console.ReadLine());
			string S = Console.ReadLine();

			int cnt = 0;

			int ind = -1;
            while (true)
            {
				ind = S.IndexOf("ABC",ind + 1);
				if (ind == -1)
					break;
				cnt++;
            }
			Console.WriteLine(cnt);
		}

		/// <summary>
		/// 回文
		/// </summary>
		/// <param name="Target"></param>
		/// <param name="len"></param>
		/// <returns></returns>
		static bool Palindrome(string Target , int len)
        {
			bool yes = true;

			for(int i = 0;i < len; i++)
            {
				if(Target[i] != Target[len - 1 - i])
                {
					yes = false;
					break;
                }
            }
			return yes;
        }

		/// <summary>
		/// アナグラム
		/// </summary>
		/// <param name="word1"></param>
		/// <param name="word2"></param>
		/// <returns></returns>
		static bool IsAnagramOf(string word1, string word2)
		{
			return word1.OrderBy(x => x).SequenceEqual(word2.OrderBy(x => x));
		}
		/// <summary>
		/// 最小公倍数
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <returns></returns>
		public static BigInteger Lcm(BigInteger a, BigInteger b)
		{
			return a * b / Gcd(a, b);
		}

		/// <summary>
		/// 最大公約数
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <returns></returns>
		public static BigInteger Gcd(BigInteger a, BigInteger b)
		{
			if (a < b)
				// 引数を入替えて自分を呼び出す
				return Gcd(b, a);
			while (b != 0)
			{
				var remainder = a % b;
				a = b;
				b = remainder;
			}
			return a;
		}
	}
}

Measured memory_bytes: 27740
import java.io.*;
import java.util.Scanner;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		String s = sc.next();
		int n = s.length();

		int max = 0;
		for (int i = 0; i < n; i++) {
			out:
			for (int j = i + 1; j <= n; j++) {
				String tmp = s.substring(i, j);
				for (int k = 0, size = tmp.length(); k < size; k++) {
					char c = tmp.charAt(k);
					if (c != 'A' && c != 'C' && c != 'G' && c != 'T') {
						continue out;
					}
				}
				max = Math.max(max, tmp.length());
			}
		}

		pr.println(max);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007 
#define ll long long 
#define N 200005
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define piii pair<int, pii>
#define print(x) cout << #x << "=" << x << "\t";
#define endl "\n"
#define newline cout << endl;

int n;
int h[N];
int b[N];
ll tree[4 * N];

void update(int idx, int lup, int rup, ll val, int l, int r) {
    if (lup <= l && r <= rup) {
        tree[idx] = val;
        return;
    }
    if (lup > r || l > rup)
        return;
    int mid = (l + r) / 2;
    update(2 * idx, lup, rup, val, l, mid);
    update(2 * idx + 1, lup, rup, val, mid + 1, r);
    tree[idx] = max(tree[2 * idx], tree[2 * idx + 1]);
}

ll query(int idx, int lup, int rup, int l, int r) {
    if (lup <= l && r <= rup)
        return tree[idx];
    if (lup > r || l > rup)
        return 0;
    int mid = (l + r) / 2;
    return max(query(2 * idx, lup, rup, l, mid), query(2 * idx + 1, lup, rup, mid + 1, r));
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL); 
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> h[i];
    for(int i=1;i<=n;i++)
        cin >> b[i];

    for(int i=1;i<=n;i++) {
        if (h[i] == 1)
            update(1, 1, 1, b[i], 1, n);
        else {
            ll beauty = query(1, 1, h[i] - 1, 1, n);
            update(1, h[i], h[i], beauty + b[i], 1, n);
        }
    }

    cout << tree[1];
    return 0;
}


Measured memory_bytes: 7936
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int sx, sy, tx, ty;
    cin>>sx>>sy>>tx>>ty;
    int w = tx-sx;
    int h = ty-sy;
    rep(i, h) cout<<"U";
    rep(i, w) cout<<"R";
    rep(i, h) cout<<"D";
    rep(i, w+1) cout<<"L";
    rep(i, h+1) cout<<"U";
    rep(i, w+1) cout<<"R";
    cout<<"D";
    cout<<"R";
    rep(i, h+1) cout<<"D";
    rep(i, w+1) cout<<"L";
    cout<<"U"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iterator>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<vector<int>> A(2, vector<int>(N));
  for (auto& v : A) {
    copy_n(istream_iterator<int>(cin), N, v.begin());
  }
  vector<vector<int>> S(2, vector<int>(N));
  partial_sum(A[0].begin(), A[0].end(), S[0].begin());
  partial_sum(A[1].begin(), A[1].end(), S[1].begin());
  int result = S[0][0] + S[1][N - 1];
  for (int i = 1; i < N; ++i) {
    int tmp = S[0][i] + (S[1][N - 1] - S[1][i - 1]);
    if (result < tmp) {
      result = tmp;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int m,D[1401][1401]={m=0},h,w,f,i;
main(){
	cin>>h>>w;
	for(i=0;i<h*w;i++){
		cin>>f;
		m=max(m,D[i/w+1][i%w+1]=(min(D[i/w][i%w],min(D[i/w+1][i%w],D[i/w][i%w+1]))+1)*(!f));
	}
	cout<<m*m<<endl;
}


Measured memory_bytes: 10744
N = int(input())
P = [int(i) for i in input().split()]

ans = 0
for i,p in enumerate(P):
    if p == i+1:
        if i + 1 < N:
#             print('i+1,p',i+1,p)
            tmp0 = P[i+1]
            P[i] = tmp0
            P[i+1] = p
            ans += 1
#             print('P',P)
        else:
            ans += 1
print(ans)

Measured memory_bytes: 13880
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

//vector//
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

typedef pair<int,int> P;  //q(p.first,p.second)

const ll int MOD = 1000000000 + 7;

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

    ll int l,m,p;
    l=1;
    m=1;
    p=1;

    for(int i=1; i<=n; i++){
        l = l*10 % MOD;
        m = m*9 % MOD;
        p = p*8 % MOD;
    }

    ll int ans = l - 2*m + p;

    if(ans < 0){
        cout << ans % MOD + MOD;
    } else{
        cout << ans % MOD;
    }
    
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<long double> v;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        v.push_back(x);
    }
    sort(v.rbegin(), v.rend());
    while (v.size() > 1)
    {
        sort(v.rbegin(), v.rend());
        long double t = (v[v.size() - 1] + v[v.size() - 2]) / 2.0;
        v.erase(--v.end());
        v.erase(--v.end());
        v.push_back(t);
    }
    cout << v[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	int a,b;
	cin>>n;
	cin>>a>>b;
	for(int i=a;i<=b;i++){
		if(i%n==0){
			cout<<"OK"<<endl;
			return 0;
		}
	} 
	cout<<"NG"<<endl;
	return 0;
}


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

const int INF = 1 << 28;
int res;

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

int solve (int count, vector<vector<int> > v, int x, int y) {
    if (count > res || count >= 10) return INF;
    if (v[x][y] == 3) return count;

    int ret = INF;
    for (int i = 0; i < 4; i++) {
        vector<vector<int> > tmp(v.begin(), v.end());
        int nx = x + dx[i];
        int ny = y + dy[i];
        bool flag = false;
        while (0 <= nx && nx < tmp.size() && 0 <= ny && ny < tmp[0].size() && (tmp[nx][ny] == 0 || tmp[nx][ny] == 3)) {
            flag = true;
            if (tmp[nx][ny] == 3) {
                return count+1;
            }
            nx += dx[i];
            ny += dy[i];
        }
        if (0 <= nx && nx < tmp.size() && 0 <= ny && ny < tmp[0].size() && flag) {
            tmp[nx][ny] = 0;
            ret = min(solve(count + 1, tmp, nx - dx[i], ny - dy[i]), ret);
        }
    }

    return ret;
}

int main () {
    int n, m;
    while (cin >> m >> n, n || m) {
        res = INF;
        vector<vector<int> > v(n, vector<int>(m));
        int sx, sy;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                int num; cin >> num;
                if (num == 2) sx = i, sy = j, num = 0;
                v[i][j] = num;
            }
        }
        int res = solve (0, v, sx, sy);

        cout << (res == INF ? -1 : res) << endl;
    }

    return 0;
}

Measured memory_bytes: 1340
# coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(10000000)

#const
dxdy=((1,0),(0,1))
# my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())

def resolve():
    N,M=pin()
    A=sorted(list(pin()))
    A.reverse()
    p=(sum(A))/(4*M)
    #print(sum(A),A)
    print(["No","Yes"][A[M-1]>=p])
"""         
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じ,るの忘れてるだろ
"""
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4 1
5 4 2 1"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 2
380 19 1"""
        output = """No"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """12 3
4 56 78 901 2 345 67 890 123 45 6 789"""
        output = """Yes"""
        self.assertIO(input, output)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define read cin >>
#define echo cout <<
#define fin << '\n'
#define _ << ' ' <<
#define in :
#define var auto&&
#define let const auto

signed main ( ) {

    int h, n;
    read h >> n;
    while ( n-->0 ) {
        int a;
        read a;
        h-= a;
    }
    puts(h<=0?"Yes":"No");


    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String slist[] = s.split("");
        int w =sc.nextInt();
        for(int i = 0; i < s.length(); i+=w){
            System.out.print(slist[i]);
        }
    }
}


Measured memory_bytes: 35956
# include <cstdio>
# include <iostream>
# include <cstring>
# include <string>
# include <algorithm>
# include <cmath>
# define R register int
# define ll long long

using namespace std;

int n,t,a;
int h[1005];
double ans;

double ab (double a)
{
	if(a<0) return -a;
	return a;
}

int main()
{
	scanf("%d%d%d",&n,&t,&a);
	for (R i=1;i<=n;++i) scanf("%d",&h[i]);
	ans=ab(t-h[1]*0.006);
	for (R i=1;i<=n;++i) ans=min(ans,ab(a-(t-h[i]*0.006)));
	for (R i=1;i<=n;++i) 
		if(ab(ans-ab(a-(t-h[i]*0.006)))<=0.0001) 
		{
			printf("%d",i);
    		return 0;
		}
	return 0;
}

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

#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define ALL(obj) (obj).begin(),(obj).end()
#define space <<" "<<
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
#define FIX <<fixed<<setprecision(10)<<
using namespace std;

using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;

const ll MOD = 1e9+7;

int main(){
double a;
double b;
double C;
double PI=acos(-1);
cin>>a>>b>>C;
C=C*PI/180;
cout FIX 0.5*a*b*sin(C)<<endl<< a+b+sqrt(a*a+b*b-2*a*b*cos(C))<<endl<< b*sin(C);
}


Measured memory_bytes: 3488
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define con continue
#define ub upper_bound
#define lb lower_bound
#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

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

const int dx8[] = {-1, 0, 1, 0,1,1,-1,-1};
const int dy8[] = {0, -1, 0, 1,1,-1,1,-1};




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

    ll n ;
    cin >> n ;
    ll c=0 ;

    ll ans =-1 ;
    while(n--)
    {
        ll x,y ;
        cin >> x >> y ;
        if(x==y) c++ ;
         else c=0 ;

         ans=max(ans,c);

    }
    if(ans>=3) cout <<"Yes" << endl ;
    else cout << "No" << endl;

}


Measured memory_bytes: 3608
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];

int main(){
    string s,rev;
    cin>>s;
    rev=s;
    reverse(rev.begin(),rev.end());
    if(rev==s){
        cout<<0<<endl;
        return 0;
    }
    int count=0;
    for(int i=0;i<s.size()/2;i++){
        if(s.at(i)!=rev.at(i))count++;
    }
    cout<<count<<endl;
    return 0;
}




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

int main() {
  int a[101][101] = {}; //???????????????u??¨u?????£??\?????????????????????v  u??????v???????????£???????????°1
  int n;
  cin >> n;

  int u,k,v;
  for(int i = 0; i < n; i++){
    cin >> u >> k;
    for(int j = 0; j < k; j++) {
      cin >> v;
      a[u][v] = 1;
    }
  }

  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= n; j++) {
      cout << a[i][j];

      if(j != n) cout << " ";
    }
    cout <<  endl;
  }
  return 0;
}
  
  

Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define ll long long 
#define mod 200003
using namespace std;
const int N=200010;
const double pi=acos(-1);
int n,g=5,len,L,rev[N<<2],r[N],p[N];
ll ans;
struct C{
	double x,y;
	C(double _x=0,double _y=0):x(_x),y(_y){};
	C operator +(const C&A)const{return C(x+A.x,y+A.y);}
	C operator -(const C&A)const{return C(x-A.x,y-A.y);}
	C operator *(const C&A)const{return C(x*A.x-y*A.y,x*A.y+y*A.x);}
	C operator /(const int&t)const{return C(x/t,y/t);}
}a[N<<2],b[N<<2];
int pw(int x,int y){
	int tmp=1;
	for(;y;y>>=1,x=(ll)x*x%mod)
		if(y&1)tmp=(ll)tmp*x%mod;
	return tmp;
}
void ntt(C*A,int f){
	for(int i=0;i<len;++i)if(i<rev[i])swap(A[i],A[rev[i]]);
	for(int i=1;i<len;i<<=1){
		C wn=C(cos(pi/i),f*sin(pi/i));
		for(int j=0;j<len;j+=i<<1){
			C w=C(1,0);
			for(int k=0;k<i;++k,w=w*wn){
				C x=A[j+k],y=w*A[j+k+i];
				A[j+k]=x+y,A[j+k+i]=x-y;
			}
		}
	}
	if(!~f)for(int i=0;i<len;++i)A[i]=A[i]/len;
}
int main(){
//	freopen("C.in","r",stdin);
//	freopen("C.out","w",stdout);
	scanf("%d",&n);
	for(int i=0,t=1;i<mod-1;++i,t=(ll)t*g%mod)p[r[t]=i]=t;
	for(int i=1,x;i<=n;++i){
		scanf("%d",&x);
		if(!x)continue; 
		a[r[x]].x+=1;
		ans-=(ll)x*x%mod; 
	}
	for(L=0,len=1;len<(mod-1<<1);len<<=1,L++);
	for(int i=1;i<len;++i)rev[i]=(rev[i>>1]>>1)|((i&1)<<(L-1));
	ntt(a,1);
//	ntt(a,-1);
	for(int i=0;i<len;++i)b[i]=a[i]*a[i];
	ntt(b,-1);
	for(int i=0;i<mod-1;++i)ans+=(ll)(b[i].x+b[i+mod-1].x+0.5)*p[i];
	ans/=2;
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 32652
solve a b
  | a == "H" && b == "H" = "H"
  | a == "H" && b == "D" = "D"
  | a == "D" && b == "H" = "D"
  | a == "D" && b == "D" = "H"

main = do
  s <- getLine
  let [a, b] = words s in
    putStrLn $ solve a b


Measured memory_bytes: 380
def suit(n):
    if n%2==0 or n%3==0 or n%5==0:
        return True
    else:
        return False
N=int(input())
if N==3:
    print(2,3,25)
else:
    M=N//2
    a=[]
    k=0
    for i in range(1,15000):
        if suit(i):
            a.append(i)
            a.append(30000-i)
            k+=1
            if k==M:
                break
    if N%2==1:
        a.append(30000)

    st=""
    for p in a:
        st+=str(p)+" "
    print(st)


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    string s,t;
    cin >> s >> t;
    reverse(t.begin(), t.end());
    if(s == t) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}

Measured memory_bytes: 3628
string=['a','b','c','d','e','f','g','h','i','j']
N=int(input())
res=[]
def dfs(ss):
  if len(ss)==N:
    ss=''.join(ss)
    res.append(ss)
  else:
    for i in range(string.index(max(ss))+2):
      a=ss+[string[i]]
      dfs(a)
  return res
ans=dfs(['a'])
for i in range(len(ans)):
  print(ans[i])

Measured memory_bytes: 12656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    vector<int> t;
    int now = 1;
    int cnt = 0;
    rep(i, 0, n) {
        if (s[i] == (char)(now + '0')) cnt++;
        else {
            t.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    t.push_back(cnt);
    if ((int)t.size() % 2 == 0) t.push_back(0);

    int ans = 0;
    int len = t.size();
    int sum[len + 1] = {};
    rep(i, 0, len) {
        sum[i + 1] = sum[i] + t[i];
    }

    for (int i = 0; i < len + 1; i += 2) {
        int left = i;
        int right = min(i + 2 * k + 1, len);
        int tmp = sum[right] - sum[left];
        ans = max(ans, tmp);
    }

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


Measured memory_bytes: 1272
#include<stdio.h>


int main(){

  int z,i,d[5], g, c, p;

  while(1){
    g=0;
    c=0;
    p=0;
    z = 0;
    for(i=0;i<5;i++){
      d[i]=0;
    }
    for(i=0;i<5;i++){
      scanf("%d",&d[i]);
      if(d[0] == 0)
	return 0;
      if(d[i]==1) g++;
      if(d[i]==2) c++;
      if(d[i]==3) p++;
    }
    
    if(g == 5 || c ==5 || p == 5)
      z = 3;
    else{ if(g > 0 && c > 0 && p > 0)
	z = 3;
      if(g == 0){
	for( i = 0; i < 5; i++){
	  if(d[i] == 2)
	    d[i] = 1;
	else 
	  d[i] = 2;
	}
      }
      if(c == 0){
	for( i = 0; i < 5; i++){
	  if(d[i] == 3)
	    d[i] = 1;
	else 
	  d[i] = 2;
	}  
      }
      if(p == 0){
	for( i = 0; i < 5; i++){
	  if(d[i] == 1)
	    d[i] = 1;
	  else 
	    d[i] = 2;
	}
      }
    }
    
    for(i = 0; i < 5; i++){
      if(z == 3){
	printf("3\n");
	continue;
      }
      printf("%d\n",d[i]);
    }
  }
  return 0;
}

Measured memory_bytes: 0
MOD = 10**9+7
n = int(input())
dp = [[[ [0]*4 for _ in range(4)] for _ in range(4)] for _ in range(n+1)]
A, C, G, T = 0, 1, 2, 3
dp[0][3][3][3] = 1
for i in range(1, n+1):
    for s in range(4):
        for t in range(4):
            for u in range(4):
                for v in range(4):
                    if any( x==(t, u, v) for x in ((A,G,C), (A,C,G), (G,A,C)) ) or any( (A,G,C)==x for x in ((s,u,v), (s,t,v)) ):
                        continue
                    dp[i][t][u][v] = ( dp[i][t][u][v]+dp[i-1][s][t][u] )%MOD
print( sum( dp[n][i][j][k] for i in range(4) for j in range(4) for k in range(4) )%MOD )

Measured memory_bytes: 57052
#include <bits/stdc++.h>
using namespace std;
const int MAX=1000000001;

int main() {
  int n,m,p;
  cin >> n >> m >> p;
  vector<int> a(m+1);
  for(int i=0; i<m; i++) cin >> a[i];
  a[m]=p;
  sort(a.begin(),a.end());
  int ans=MAX;
  for(int i=0; i<m+1; i++) {
    int x=a[i],y=a[(i+1)%(m+1)];
    int d=abs(n-p+x)%n;
    int d2=abs(n+p-y)%n;
    ans=min(ans,min(d*2+d2,d+d2*2));
  }
  cout << ans*100 << endl;
  return 0;
}


Measured memory_bytes: 1252
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

string change(string s)
{
	char end = s.at(s.size() - 1);
	s.erase(s.begin() + s.size() - 1);

	string s_change = "";
	s_change += end;
	s_change += s;

	return s_change;
}

int main() 
{
	string S, T;
	cin >> S >> T;

	for (int i = 0; i < S.size(); i++)
	{
		if (S == T)
		{
			cout << "Yes" << endl;
			return 0;
		}
		S = change(S);
		
		//cout << S << endl;
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int i,n,j,max,min;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		int x,u[100];
		scanf("%d",&x);
		for(j=0;j<x;j++){
			scanf("%d",&u[j]);
		}
		max=0;
		min=0;
		for(j=1;j<x;j++){
			if(max<u[j]-u[j-1]){
				max=u[j]-u[j-1];
			}
			if(min>u[j]-u[j-1]){
				min=u[j]-u[j-1];
			}
		}
		printf("%d %d\n",max,-min);
	}
	return 0;
}

Measured memory_bytes: 1028
numbers = [int(i) for i in input().split()]
if (4*numbers[0]-numbers[1])%2 == 0 and (4*numbers[0]-numbers[1]) >= 0 and (numbers[1]-2*numbers[0])%2 == 0 and (numbers[1]-2*numbers[0]) >= 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9192
n,w = map(int,input().split())
pack_list = [list(map(int,input().split())) for _  in range(n)]

# dp = [[float('inf') for _ in range(10**7+1)] for _ in range(n+1)]
# dp[0] = [0 for _ in range(10**7+1)]

dp_dict = {0: {0:0}} # w,v

'''
for i,pack in enumerate(pack_list):
    for value,weight in enumerate(dp[i]):
        dp[i+1][value] = min(dp[i][value],dp[i+1][value])
        dp[i+1][value+pack[1]] = min(dp[i+1][value+pack[1]],dp[i][value]+pack[0])

for i,num in enumerate(dp[-1][::-1]):
    if num <= w:
        print(10**7-i)'''

for i,pack in enumerate(pack_list):
    i += 1
    if i not in dp_dict:
        dp_dict[i] = {}
    for weight,v in dp_dict[i-1].items():
        if weight not in dp_dict[i]:
            dp_dict[i][weight] = v
        else:
            dp_dict[i][weight] = max(dp_dict[i][weight],v)
        if weight+pack[0] <= w:
            if weight+pack[0] not in dp_dict[i]:
                dp_dict[i][weight+pack[0]] = v+pack[1]
            else:
                dp_dict[i][weight+pack[0]] = max(dp_dict[i][weight+pack[0]],v+pack[1])

target = dp_dict[n]
max_num = 0

for k,v in target.items():
    if k <= w:
        max_num = max(max_num,v)

print(max_num)



Measured memory_bytes: 11964
using System;

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

            Point a = new Point(0,0);
            Point b = new Point(100, 0);

            Console.WriteLine(string.Format("{0:f8} {1:f8}", a.x, a.y));
            koch(d, a, b);
            Console.WriteLine(string.Format("{0:f8} {1:f8}", b.x, b.y));
        }

        public static void koch(int d, Point a, Point b)
        {
            if (d == 0)
                return;
            Point s = new Point();
            Point t = new Point();
            Point u = new Point();

            s.x = (2 * a.x + 1 * b.x) / 3.0;
            s.y = (2 * a.y + 1 * b.y) / 3.0;
            t.x = (1 * a.x + 2 * b.x) / 3.0;
            t.y = (1 * a.y + 2 * b.y) / 3.0;

            u.x = (t.x - s.x) * Math.Cos(60 * (Math.PI / 180)) - (t.y - s.y) * Math.Sin(60 * (Math.PI / 180)) + s.x;
            u.y = (t.x - s.x) * Math.Sin(60 * (Math.PI / 180)) + (t.y - s.y) * Math.Cos(60 * (Math.PI / 180)) + s.y;

            koch(d - 1, a, s);
            Console.WriteLine(string.Format("{0:f8} {1:f8}",s.x,s.y));
            koch(d - 1, s, u);
            Console.WriteLine(string.Format("{0:f8} {1:f8}", u.x, u.y));
            koch(d - 1, u, t);
            Console.WriteLine(string.Format("{0:f8} {1:f8}", t.x, t.y));
            koch(d - 1, t, b);
        }
    }

    public class Point
    {
        public double x { get; set; }
        public double y { get; set; }

        public Point()
        {

        }
        
        public Point(double x,double y)
        {
            this.x = x;
            this.y = y;
        }
    }

}



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

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mpq priority_queue<int,vector<int>,greater<int>>
#define debug(a) cerr << #a << ": " << a << endl
#define umii unordered_map<int64_t,int64_t>
#define ftt int t;cin>>t;for(int tt=1;tt<=t;++tt)
#define forr(i,n) for((i)=1;(i)<=(n);(i)++)
#define Rev(v) reverse(v.begin(),v.end());
#define Sort(v) sort(v.begin(),v.end());
#define mem(a,b) memset(a,b,sizeof(a))
#define deb(x) cout<<"\nhi"<<x<<"\n"
#define pq priority_queue<int>
#define dbg cout<<"\nhi\n"
#define sayy cout<<"YES\n"
#define sayn cout<<"NO\n"
#define int long long
#define double long double
#define pii pair<int,int>
#define mii map<int,int>
#define vb vector<bool>
#define vi vector<int>
#define eb emplace_back
#define nl cout<<"\n"
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define sp <<" "<<
#define se second
#define fi first

const int MOD = 1000000007;
const double PI = 3.1415926535898;
const int LIM = 100005;

using namespace std;

int fpow( int x,int y) {
    int temp;
    if(y == 0)
        return 1;
    temp = fpow(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;}

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

void sieve(int n) {
     bool prime[5*LIM];
     memset(prime, true, sizeof(prime));
     for (int p=2; p*p<=n; p++)
          if (prime[p] == true)
               for (int i=p*p; i<=n; i += p)
                    prime[i] = false;
     prime[1]=0;}

inline int read(){
    int p=1,ans=0;
    char ch=getchar();
    while(ch<48||ch>57)
    {
        if(ch=='-')p=-1;
        ch=getchar();
    }
    while(ch>=48&&ch<=57)
    {
        ans=(ans<<3)+(ans<<1)+ch-48;
        ch=getchar();
    }
    return ans*p;
}

map<int,int> primeFactors(int n)
{
    map<int, int> mp;
    while (n % 2 == 0)
    {
        if(mp.count(2) == 1)
            mp[2]++;
        else
            mp.insert({2,1});
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            if(mp.count(i) == 1)
                mp[i]++;
            else
                mp.insert({i,1});
            n = n/i;
        }
    }
    if (n > 2)
    {
        if(mp.count(n) == 1)
            mp[n]++;
        else
            mp.insert({n,1});
    }
    return mp;
}

//*************************************************************************************************************************


int32_t main()
{    fio;

     int n, sum = 0;
     cin>>n;
     vi v(100000);
     for(int i=0;i<n;i++)
     {
        int x;
        cin>>x;
        sum += x;
        v[x-1]++;
    }
    int q;
    cin>>q;
    while(q--)
    {
        int b, c, cnt = 0;
        cin>>b>>c;
        cnt = v[b-1];
        v[b-1] = 0;
        v[c-1] += cnt;
        sum = sum + cnt*c - cnt*b;
        cout<<sum<<endl;
    }
}





Measured memory_bytes: 4028
// sinapusu2002's code

#include <stdio.h>
#include <algorithm>

void search(long long int);

int main()
{
  long long int n;
  scanf("%lld",&n);
  while(n!=0){
    search(n);
    scanf("%lld",&n);
  }
}

void search(long long int n)
{
  if(n==1){
scanf("%lld", &n);
    printf("0\n");
    return ;
  }
  long long int *d=new long long int[n];
  long long int sum=0;
  for(int i=0;i<n;i++){
    scanf("%lld",&d[i]);
  }
  std::sort(d, d + n);
  for(long long int i=0;i<n-1;i++){
    sum+=d[i]*(n-i-1);
  }
  printf("%lld\n",sum);
  delete[] d;
}

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


#define mod 1000000007
#define ull unsigned long long int
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
/* TYPE DEFINITIONS */
typedef     long long int        ll;
typedef     vector<ll>     vi;
typedef     pair<ll,ll>   pi;
 
 
 
/* MATH */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 
ll pow(ll a,ll b,ll m)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}

ll ncr(int n, int k)  
{  
	if(k>n)return 0;
    ll res = 1;  
    if ( k > n - k )  
        k = n - k;  
    for (int i = 0; i < k; ++i)  
    {  
        res *= (n - i);  
        res /= (i + 1);  
    }  
  
    return res;  
} 
  
//
/* MACROS */
 
#define  all(A)         (A).begin() , (A).end()
#define  arrall(A,n)    (A),((A)+(n))
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) 
#define  deb(x)       cout << '>' << #x << ':' << x << endl;

void  solve()
{
	string s;
	cin>>s;
	forn(i,ln(s))cout<<"x";
}


int main()
{
 
    FastIO;
   // init();
    int t=1;
  	//cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 256
k=int(input())

a=[i for i in range(1,10)]

for x in a:
    if k<=len(a):
        break
    
    if x%10!=0:
        a.append(10*x+(x%10)-1)
    a.append(10*x+(x%10))
    if x%10!=9:
        a.append(10*x+(x%10)+1)
        
print(a[k-1])

Measured memory_bytes: 7156
private fun readStrings() = readLine()!!.split(" ")
private fun readInts() = readStrings().map { it.toInt() }

fun main(args: Array<String>) {
    val N = readInts()[0]
    val X = readInts()
    val sortedX = X.sorted()
    val smallerMed = sortedX[N / 2 - 1]
    val largerMed = sortedX[N / 2]
    X.forEach {
        println(if (it < largerMed) largerMed else smallerMed)
    }
}

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

using namespace std;
long long dp[1000005],num[1000005];
int main()
{
    //freopen("tttt.out", "w", stdout) ;
    //freopen("tttt.in", "r", stdin) ;
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    long long a,b;
    cin>>a>>b;
    for(int i=0;i<a;i++)
    {
        cin>>num[i];
        long long mi;
        for(int j=1;j<=b;j++)
        {
            if(i-j<0)
                break;
            if(j==1)
                mi=dp[i-j]+abs(num[i]-num[i-j]);
            if(dp[i-j]+abs(num[i]-num[i-j])<mi)
            {
                mi=dp[i-j]+abs(num[i]-num[i-j]);
            }
            dp[i]=mi;
        }
    }
    cout<<dp[a-1];
    return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[10010];
int vis[10010];
int cnt=0,flag;
stack<int>st;
void dfs(int s)
{
    int i,j,u;
    vis[s]=1;
    for(i=0;i<adj[s].size();i++)
    {
        u=adj[s][i];
        if(vis[u]==0)
        {
            dfs(u);
        }
    }
    vis[s]=2;
    st.push(s);
}
void cl()
{
    for(int i=0;i<=10000;i++)
    {
        vis[i]=0;
    }
}
int main()
{
    int n,m,a,b,i,u;
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        cin>>a>>b;
        adj[a].push_back(b);
    }
    cl();
    for(i=n-1;i>=0;i--)
    {
        if(vis[i]==0)
        {
            dfs(i);
        }
    }

        while(!st.empty())
        {
            u=st.top();
            printf("%d\n",u);
            st.pop();
        }

}



Measured memory_bytes: 3896
//Ash180-AtCoder:4 B - Mix Juice [Beginner Contest 171]
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define clock cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
#define forie(a,n) for(int i=(a);i<=(n);i++)
#define forje(b,m) for(int j=(b);j<=(m);j++)
#define forke(c,g) for(int k=(c);k<=(g);k++)
#define ffe(a,n,b,m) forie(a,n) forje(b,m)
#define fori(n) for(int i=0;i<n;++i)
#define forj(n) for (int j=0;j<n;++j)
#define fork(n) for (int k=0;k<n;++k)
#define rev(s)  reverse(s.begin(), s.end()) 
#define initblock(v,d) memset(v,d,sizeof(v))
#define ll long long
#define ull unsigned long long
#define re return 
using namespace std;
void Ash() 
{ 	
#ifndef ONLINE_JUDGE 
freopen("input.txt", "r", stdin); freopen("error.txt", "w", stderr); freopen("output.txt", "w", stdout); 
#endif 
}
void solve() 
{
	int N, K, sum = 0; cin >> N >> K;
	int kind[N];
	fori(N) cin >> kind[i];
	sort(kind, kind+N);
	fori(K) sum += kind[i];
	cout << sum; 
}
int main()   { fast; Ash(); solve(); clock; return 0; } 


Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b){
        cout<<c;
    }else if(a==c){
        cout<<b;
    }else{
        cout<<a;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pl;
const int N = 1e5;
int dp[N];
int h, n;
pl spell[N];

int main() {
	for(int i=0;i<N-10;i++)dp[i] = 1000000000;
	cin>>h>>n;
    for(int i=0;i<n;i++) {
    	scanf("%d%d", &spell[i].first, &spell[i].second);
    }
    dp[0] = 0;
  	for(int i=1;i<=20005;i++) {
        for(int j=0;j<n;j++) {
        	if(i - spell[j].first < 0)continue;
            dp[i] = min(dp[i], dp[i-spell[j].first] + spell[j].second);
        }
    }
    int ans = dp[h];
    for(int i=h+1;i<=20005;i++)
        ans = min(ans, dp[i]);
  
    cout<<ans<<endl;
}

Measured memory_bytes: 640
from statistics import mean


n = int(input())
X = list(map(int, input().split()))
m = int(mean(X))
M = m + 1

def dist(X, mean):
    out = 0
    for x in X:
        out += (x - mean) ** 2
    return out


print(min(dist(X, M), dist(X, m)))

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

int main()
{
    string s;
    string substr;
    int num, h, i;
    while(cin >> s) {
        if (s[0] == '-')
            break;
        cin >> num;
        for (i = 0; i < num; i++) {
            cin >> h;
            substr = s.substr(0, h);

            s.erase(0, h);
            s.append(substr);
        }
        cout << s<< endl;
    }
    return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

int main() {
    string s;
    uint64_t p1 = 0, p2 = 0;
    cin >> s;
    for (int i = 0; i < 64; i++) {
        p1 = (p1 << 1) + (i % 2);
        p2 = (p2 << 1) + ((i+1) % 2);
    }

    uint64_t start = 0;
    uint64_t sum1 = 0, sum2 = 0;

    while (start < s.length()) {
        string sub = s.substr(start, 64);
        reverse(sub.begin(), sub.end());
        uint64_t s_bit = stoul(sub, nullptr, 2);

        uint64_t c1 = p1 ^ s_bit;
        uint64_t c2 = p2 ^ s_bit;
        for (int i = 0; i < sub.length(); i++) {
            if ((c1 >> i) & 1) sum1++;
            if ((c2 >> i) & 1) sum2++;
        }

        start += 64;
    }

    if (sum1 < sum2) {
        cout << sum1 << endl;
    } else {
        cout << sum2 << endl;
    }
}


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

int main() {
  int cup[3] = {1};
  char a, c, b;
  while (cin >> a >> c >> b) {
    swap(cup[a - 'A'], cup[b - 'A']);
  }
  if (cup[0] == 1) {
    cout << 'A' << endl;
  }
  if (cup[1] == 1) {
    cout << 'B' << endl;
  }
  if (cup[2] == 1) {
    cout << 'C' << endl;
  }
}



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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

int n;
int a, v;
int ra, rv = -1;

int main()
{
  scanf(" %d", &n);

  rep(i, n){
    scanf(" %d %d", &a, &v);
    if(v == rv && a < ra) ra = a;
    if(v > rv) rv = v,  ra = a;
  }

  printf("%d %d\n", ra, rv);

  return 0;
}

Measured memory_bytes: 1188
# -*- coding: utf-8 -*-


def run():
    n = int(input())
    a = list(map(int, input().split()))[:n]
    x = [0] * (n + 1)
    for _a in a:
        x[_a] += 1
    for y in x[1:]:
        print(y)


if __name__ == '__main__':
    run()


Measured memory_bytes: 32176
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
/******************************************
* AUTHOR : PANDRAVISAM SHIVA SANTHOSH *
* Handle : santhosh_80 *
* INSTITUTION : IIT Palakkad *
******************************************/
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
#define ll long long int 
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define S(x) scanf("%d",&(x))
#define P(x) printf("%d\n",(x))
#define Sl(x) scanf("%lld",&(x))
#define Pl(x) printf("%lld\n",(x))
#define pb push_back
#define f first
#define s second

const ll N = 2*(1e3) + 7 ;

ll ans[N] ;
vector<int> graph[N] ;

void bfs(int i,int n) {
	ll dist[N] ;
	for(int i = 1; i <= n ; i++)dist[i] =  INT_MAX ;
	dist[i] = 0 ;
	//cout << "YEAh12\n" ;
	queue<int> q ;
	q.push(i) ;
	while(!q.empty()){
		int x = q.front() ;
		q.pop() ;

		for(auto x1 : graph[x]){

			if(dist[x1] == INT_MAX){
				
				dist[x1] = dist[x] + 1 ;
				q.push(x1) ;

			}

		}
	}
	//cout << "YEAh123\n" ;
	for(int j = i+1; j<= n ; j++){
		//cout << dist[j] << "\n" ; 
		if(dist[j] != INT_MAX) ans[dist[j]]++;
	}
}

int main() {
	int n,x,y ;
	cin >> n >> x >> y ;
	for(int i = 1; i <= (n-1) ; i++){
		graph[i].pb(i+1) ;
		graph[i+1].pb(i) ;
	}
	graph[x].pb(y) ;
	graph[y].pb(x) ;
	//cout << "YEAh\n" ;
	for(int i = 1 ; i <= (n-1) ; i++)bfs(i,n) ;
	for(int i = 1; i <= (n-1) ; i++)cout << ans[i] << "\n" ;
	return 0 ;
}

Measured memory_bytes: 384