akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());

        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 1; i <= N; i++) {
            map.put(Integer.parseInt(sc.next()), i);
        }

        StringBuilder builder = new StringBuilder();
        for (int i = 1; i <= N; i++) {
            builder.append(map.get(i))
                    .append(" ");
        }
        System.out.println(builder.toString());
    }
}

Measured memory_bytes: 54384
// #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")

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

typedef long long int64;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef double dl;
typedef pair<int,int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || (WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define uint(n) ((unsigned int)(n))
#define int64(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define dl(n) ((double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed<<setprecision(n)

const int INF=1061109567;
const int NINF=-1044266559;
const int64 LINF=4557430888798830399;
const dl eps=1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)

#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(),(a).end()
#define pall(a) (a).rbegin(),(a).rend()
#define Log(x,y) log(x)/log(y)
#define SZ(a) ((int)(a).size())
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define rep1(i,n) for(int i=1;i<=((int)(n));i++)
#define repd(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define repd1(i,n) for(int i=((int)(n));i>=1;i--)
#define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)
#define repV(i,v) for(auto i:v)
#define repE(i,v) for(auto &i:v)
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x) MS(x,0)
#define MINF(x) MS(x,63)
#define MCP(x,y) memcpy(x,y,sizeof(y))
#define UN(v) sort(All(v)),v.erase(unique(All(v)),v.end())
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
#define fileio(x)\
	freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)
#define filein2(filename,name) ifstream name(filename,ios::in)
#define fileout2(filename,name) ofstream name(filename,ios::out)
#define fileio2(filename,name) fstream name(filename,ios::in|ios::out)
#define sqr(x) ((x)*(x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf

const int maxn=2010;

int n,dp[maxn];

int main()
{
	cin>>n;

	for(int i=3;i<=n;i++)
	{
		dp[i]=1;
		for(int j=1;j+3<=i;j++) dp[i]=(dp[i]+dp[j])%MOD;
	}

	cout<<dp[n];

	return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 1000000
int main(){
    while(1){
		int a[101],b[101],n,m,i,j,dif,suma=0,sumb=0,flg=0,ansa,ansb,min=INF;
		cin>>n>>m;
		if(n==0&&m==0)break;
		for(i=0;i<n;i++){
			cin>>a[i];suma+=a[i];
		}
		for(i=0;i<m;i++){
			cin>>b[i];sumb+=b[i];
		}
		dif=(suma-sumb);
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				if((a[i]-b[j])*2==dif&&min>a[i]+b[j]){
					flg=1;
					ansa=a[i];
					ansb=b[j];
					min=a[i]+b[j];
				}
			}
		}
		if(flg==0){
			cout<<-1<<endl;
		}else{
			cout<<ansa<<' '<<ansb<<endl;
		}
		
	
	}
    return 0;
}

Measured memory_bytes: 1160
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    res = l[0]
    for i in range(1, n):
        res = (res+l[i]) / 2
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <stdio.h>
#include <stdlib.h>

void upheap(int *buff, int n)
{
    while (1) {
        int p = (n - 1) / 2;
        if (p < 0 || buff[p] >= buff[n]) break;
        int temp = buff[n];
        buff[n] = buff[p];
        buff[p] = temp;
        n = p;
    }
}

void downheap(int *buff, int n, int size)
{
    while (1) {
        int c = 2 * n + 1;
        if (c >= size) break;
        if (c + 1 < size && buff[c] < buff[c + 1]) c++;
        if (buff[n] >= buff[c]) break;
        int temp = buff[n];
        buff[n] = buff[c];
        buff[c] = temp;
        n = c;
    }
}

int main(void)
{
    char line[20];
    fgets(line, 20, stdin);
    int n = atoi(line);

    int **Q;
    int *Q_i;
    Q = malloc(sizeof(int *) * n);
    Q_i = malloc(sizeof(int) * n * 200000);
    int i;
    for (i = 0; i < n; i++) {
        Q[i] = Q_i + i * 200000;
    }
    int *size;
    size = calloc(n, sizeof(int));

    char *a;
    a = line;
    while (*a >= '0') a++;
    int q;
    q = atoi(a + 1);

    int op, t, x, s;

    while (q--) {
        fgets(line, 20, stdin);
        op = atoi(line);
        a = line + 2;
        t = atoi(a);
        s = size[t];
        if (op == 0) {
            while (*a >= '0') a++;
            x = atoi(a + 1);
            Q[t][s] = x;
            upheap(Q[t], s);
            size[t] += 1;
            }
        else if (s != 0) {
            if (op == 1) printf("%d\n", Q[t][0]);
            else {
                Q[t][0] = Q[t][s-1];
                downheap(Q[t], 0, s);
                size[t] -= 1;
            }
        }
    }

    free(Q);
    free(Q_i);
    free(size);

    return 0;
}


Measured memory_bytes: 6052
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
long ans=0;
		String con;
		String s[] = new String[n];
		for (int i = 0; i < n; i++) {
			con = sc.next();
			char[] c = con.toCharArray();
			Arrays.sort(c);
			s[i] = String.valueOf(c);
		}

		Arrays.sort(s);
		int how = 1;
		for (int i = 0; i < s.length - 1; i++) {
			if (!s[i].equals(s[i + 1])) {
				how++;
			}
		}
		int x[] = new int[how];
		Renzoku(s, x);

		for (int i = 0; i < how; i++) {
			ans+=con(x[i],2);
		}
		System.out.println(ans);
	}

	public static int Renzoku(String c[], int x[]) {

		int mode = 0;
		int val = 0;

		for (int i = 0; i <= c.length - 2; i++) {
			if ((c[i].equals(c[i + 1])) && i != c.length - 2) {
				val++;
			} else {
				if ((c[i].equals(c[i + 1])) && i == c.length - 2) {
					val++;
				}
				val++;
				x[mode] = val;
				mode++;

				if (!(c[i].equals(c[i + 1])) && i == c.length - 2) {
					x[mode] = 1;
					mode++;
				}

				val = 0;
			}

		}
		return mode;

	}

	static public long con(int n, long r) {
		long num = 1;
		for (long i = 1; i <= r; i++) {
			num = num * (n - i + 1) / i;
		}
		return num;
	}

}

Measured memory_bytes: 51648
import java.math.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++)
      A[i] = sc.nextInt();
    sc.close();

    int[] d = new int[N];
    d[0] = A[0] + K - A[N - 1];
    for (int i = 1; i < N; i++)
      d[i] = A[i] - A[i - 1];
    Arrays.sort(d);

    long ans = 0;
    for (int i = 0; i < N - 1; i++)
      ans += d[i];
    System.out.println(ans);
  }
}


Measured memory_bytes: 84692
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

LL cnt[200005], sum[200005];
int a[100005];
int n, m;

void mark(int a, int b) {
	if (a > b) b += m;
	{
		cnt[a + 1]++;
		cnt[b + 1]--;
		sum[a + 1] += a;
		sum[b + 1] -= a;
	}
}
int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		a[i]--;
	}

	LL total = 0;
	for (int i = 1; i < n; i++) {
		if (a[i + 1] > a[i]) total += a[i + 1] - a[i];
		else total += (m) - a[i] + a[i + 1];

		mark(a[i], a[i + 1]);
	}

	LL runCnt = 0, runSum = 0;
	for (int i = 0; i < 2 * m; i++) {
		runCnt = (cnt[i] += runCnt);
		runSum = (sum[i] += runSum);
	}

	LL ans = total;
	for (int i = 0; i < m; i++) {
		LL cur = total;
		cur = cur + cnt[i] - i * cnt[i] + sum[i];
		cur = cur + cnt[i + m] - (i + m) * cnt[i + m] + sum[i + m];
		ans = MIN(ans, cur);
		//fprintf(stdout, "%d %lld\n", i, cur);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;

ll q,h,s,d,n;

int main(){
	scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n);
	q*=8,h*=4,s*=2; 
	if(d<q&&d<h&&d<s){
		if(n&1){
			printf("%lld\n",(n>>1)*d+qmin(q,qmin(s,h))/2);
		}else{
			printf("%lld\n",d*n/2);
		}
	}else{
		printf("%lld\n",qmin(q,qmin(h,s))/2*n);
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int n,k,q;
    cin>>n>>k>>q;

    vector<int> a(n);

    rep(i,0,a.size())
    {
        a[i] = k;
    }
    int s = q;
    while(q--)
    {
        int x;
        cin>>x;

        a[x-1]++;
    }

    rep(i,0,a.size())
    {
        if ( (a[i]-s) > 0 )
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 1408
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
 
struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;
 
int n, m;
vector<int> Graph[1010], rGraph[1010];
int d[1010];
int main(){
    cin >> n >> m;
    REP(i, m){
        int a, b;
        cin >> a >> b;
        a--, b--;
        Graph[a].emplace_back(b);
        rGraph[b].emplace_back(a);
    }
    vector<int> ans(1010, -1);
    REP(root, n){
        REP(i, 1010)d[i] = HINF<int>();
        d[root] = 0;
        queue<int> q;
        q.push(root);
        int flg = -1;
        while(!q.empty()){
            int p = q.front();
            q.pop();
            for(auto to : Graph[p]){
                if(to == root){
                    flg = p;
                    break;
                }
                if(d[to] != HINF<int>())continue;
                d[to] = d[p] + 1;
                q.push(to);
            }
            if(flg != -1)break;
        }
        if(flg != -1){
            vector<int> vec;
            int cur = flg;
            while(cur != root){
                vec.emplace_back(cur);
                for(auto to : rGraph[cur]){
                    if(d[to] == d[cur] - 1){
                        cur = to;
                        break;
                    }
                }
            }
            vec.emplace_back(root);
            if((int)vec.size() < (int)ans.size()){
                ans = vec;
            }
        }
    }
    if(ans[0] == -1){
        cout << -1 << endl;
        return 0;
    }
    cout << (int)ans.size() << endl;
    REP(i, (int)ans.size()){
        cout << ans[i] + 1 << endl;
    }
}

Measured memory_bytes: 384
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N;
	std::vector<int> A;
	std::cin >> N;
	A.resize(N);
	for (auto& a : A)
		std::cin >> a;
	
	bool approved = true;
	for (auto a : A) {
		if (a % 2 == 0) {
			if (a % 3 == 0 || a % 5 == 0)
				;
			else
				approved = false;
		}
	}
	
	if (approved)
		std::cout << "APPROVED\n";
	else
		std::cout << "DENIED\n";
}


Measured memory_bytes: 256
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        //private static long mod = 1000000007;
        private static long mod = 998244353;
        static void Main(string[] args)
        {
            //var n = int.Parse(ReadLine());
            var line = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();

            var n = line[0];
            var x = line[1];
            var m = line[2];

            var hashSet = new HashSet<long>();
            var list = new List<long>();
            hashSet.Add(x);
            list.Add(x);
            var index = -1;

            for(var i = 1; i < n; i++)
            {
                var a = list[i - 1] * list[i - 1];
                a %= m;
                
                if(hashSet.Contains(a))
                {
                    for(var j = 0; j < list.Count; j++)
                    {
                        if(list[j] == a)
                        {
                            index = j;
                            break;
                        }
                    }
                    break;
                }

                hashSet.Add(a);
                list.Add(a);
            }

            if(index == -1)
            {
                WriteLine(list.Sum());
                return;
            }

            long sum = 0;
            for(var i = 0; i < index; i++)
            {
                sum += list[i];
            }

            n -= index;
            var count = list.Count - index;
            if(list.Last() == 0)
            {
                WriteLine(sum);
                return;
            }
            sum += (list.Sum() - sum) * (n / count);
            for(var i = index; i < index + (n % count); i++)
            {
                sum += list[i];
            }

            WriteLine(sum);
        }
    }
}


Measured memory_bytes: 31724
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<29;
const ll LINF = 1LL<<58;

void solve() {
    ll x;
    cin >> x;
    for(ll a = -150; a < 150; a++) {
        for(ll b = -150; b < 150; b++) {
            if (pow(a, 5) - pow(b, 5) == x) {
                cout << a << " " << b << endl;
                return;
            }
        }
    }
}

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


Measured memory_bytes: 4060
import sys

def main():
  input = sys.stdin.readline
  H, W = map(int, input().split())
  A = [[0 for _ in range(W+2)] for _ in range(H+2)]
  for i in range(H):
    a = [0] + [c == '#' for c in input().strip()] + [0]
    A[i+1] = a
  
  ans = 'Yes'
  for i in range(H):
    for j in range(W):
      if A[i+1][j+1] == 1:
        u, d, r, l = A[i][j+1], A[i+2][j+1], A[i+1][j+2], A[i+1][j]
        if any([u, d, r, l]):
          continue
        else:
          ans = 'No'
          break
  print(ans)


if __name__ == '__main__':
  main()


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>

typedef   signed long long int slli;
typedef unsigned long long int ulli;
const slli MAX_SLLI = 0x7FFFFFFFFFFFFFFF;
const slli MIN_SLLI = 0x8000000000000000;
const ulli MAX_ULLI = 0xFFFFFFFFFFFFFFFF;
const ulli MIN_ULLI = 0x0000000000000000;

#define N_TIMES(i, n)     for (ulli i = 0;     i <  n; ++i)
#define N_TIMES_REV(i, n) for (slli i = n - 1; i >= 0; --i)

#ifdef __DEBUG__
template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  const std::string delim = ", ";
  typename std::list<T>::const_iterator itr = list.begin();
  while (itr != list.end()) {
    os << *itr;
    ++itr;
    if(itr != list.end()) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v)
{
  const std::string delim = ", ";
  for (unsigned n = 0; n < v.size(); ++n) {
    os << v[n];
    if((n + 1) < v.size()) os << delim;
  }
  return os;
}
#endif /* __DEBUG__ */

ulli solve(ulli A, ulli B)
{
  if (A == B) {
    return 2 * (A - 1);
  } else if (A + 1 == B) {
    return 2 * (A - 1);
  } else if (B + 1 == A) {
    return 2 * (B - 1);
  } else {
    ulli C = static_cast<ulli>(::floor(::sqrt(static_cast<double>(A * B))));
    if (A * B == C * C) --C;
    
    if (C * (C + 1) >= A * B) {
      return 2 * (C - 1);
    } else {
      return 2 * C - 1;
    }
  }
  
  return 0;
}

int main(int argc, char **argv)
{
  unsigned Q;
  std::cin >> Q;
  
  N_TIMES(q, Q) {
    ulli A, B;
    std::cin >> A >> B;
    
    std::cout << solve(A, B) << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(){

int   a, b;
int   d   ;
int   r   ;
double f   ;

scanf("%d %d", &a, &b) ;

d = a / b;
r = a % b;
f = 1.0 * a / b;

printf("%d %d %f\n", d, r, f);

return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
int main()
{
   char s1[5],s2[5];
   scanf("%s%s",s1,s2);
   int i,j;
   for(i=0;i<strlen(s1);i++)
   {
      if(s1[i]!=s2[strlen(s1)-1-i])
      {
         printf("NO\n");return 0;
      }
   }
   printf("YES\n");
}


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

int main() {
	int n;
	cin>>n;
	float p;
	if(n%2==0)
	{ p = 1/2.0;
		cout<<p;
	}
	else 
	{
		p = ceil(n/2.0)/(n*1.0);
		cout<<p;
	}
	 
	return 0;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;
const ll 	N 		= 	2*1e6;

/*vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
*/
// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,m;
string s,t;
//vll a;

// <------------- Implement Functions Here ----------> //

// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n;
	vll a(n);
	ll cou = 0;
	for(ll i=0;i<n;i++) cin>>a[i];

	for(ll i=1;i<n;i++) {
		if(a[i] < a[i-1]) {
			cou += (a[i-1] - a[i]);
			a[i] = a[i-1];
		}
	}

	cout<<cou;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}



Measured memory_bytes: 4808
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
//const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
   int n;
   cin>>n;
   string s;
   cin>>s;
   int w=0,r=0;
   for(int i=0;i<n;i++){
       if(s[i]=='W')w++;
       else r++;
   }
   if(w==0||r==0){
       cout<<0<<"\n";
       return 0;
   }
   ll ans=min(w,r);
   ll res=0;
   ll cnt=0;
   for(int i=0;i<n;i++){
       if(s[i]=='W'&&r>0){
           r--;
           res++;
       }else r--;
   }
   chmin(ans,res);
   cout<<ans<<"\n";

}

Measured memory_bytes: 3768
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int A[5];
  for(int i=0; i<5; i++)  cin>>A[i];
  int resA[5];
  for(int i=0; i<5; i++) resA[i] = A[i]%10;
  //for(int i=0; i<5; i++) resA[i] = abs(10-resA[i]);
  //for(int i=0; i<5; i++) resA[i] = abs(10-A[i]%10)%10;
  
  bool allzeroflag=true;
  int minresindex=0;
  int minresA=10000000;
  for(int i=0; i<5; i++){
    if(resA[i]<minresA && resA[i]!=0){
      minresA=resA[i];
      minresindex=i;
      allzeroflag=false;
    }
  }
  if(allzeroflag)minresA=10;

  int totaltime=0;
  for(int i=0; i<5; i++){
    if(resA[i]==0)totaltime+=(A[i]/10)*10;
    else totaltime+=(A[i]/10+1)*10;
  }  
  totaltime = totaltime - (10-minresA);
  cout<<totaltime;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <sstream>
#include <vector>
#include <stdio.h>
#define ll              long long
#define fr(i,j,p)       for(int i=j; i<p ;i++)
#define frr(i,j,p)      for(int i=j; i>=p ;i--)
#define PI              3.14159265358979323846
#define print(m)        std::cout << std::fixed << std::setprecision(11) << m <<endl;
#define mkp             make_pair
#define pb              push_back
#define M               32
#define lbindex(a,x)    (int)(lower_bound(a.begin(), a.end(),x)-a.begin());
#define upindex(a,x)    (int)(upper_bound(a.begin(), a.end(),x)-a.begin());
#define all(a)          (a).begin(),(a).end()
#define mem(b,a,n)      memset(b,a,sizeof(b[0])*n);
#define meme(b,a,n,m)   memset(b,a,sizeof(b[0][0])*n*m);
#define ff              first
#define ss              second
#define endl            '\n'

//ll md=1000000007;
//ll mdd=998244353;

using namespace std;

typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(NULL);  cout.tie(NULL);
    int n,c1=0,c2=0,c3=0,c4=0;  cin>>n;
    fr(i,0,n)
    {
        string s;   cin>>s;
        if(s[0]=='A')   c1++;
        if(s[0]=='W')   c2++;
        if(s[0]=='T')   c3++;
        if(s[0]=='R')   c4++;
    }
    cout<<"AC"<<' '<<"x"<<' '<<c1<<endl;
    cout<<"WA"<<' '<<"x"<<' '<<c2<<endl;
    cout<<"TLE"<<' '<<"x"<<' '<<c3<<endl;
    cout<<"RE"<<' '<<"x"<<' '<<c4<<endl;
    return 0;

}


Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
  int A[3],N[3],n;
  cin>>n;
    for(int i=0;i<n;i++){
      for(int i=0;i<3;i++) cin>>A[i];
      for(int i=0;i<3;i++){
        for(int j=i;j<3;j++){
          if(A[i]<A[j]) swap(A[i],A[j]);
        }
      }
      for(int i=0;i<3;i++) N[i]=A[i]*A[i];
      if(N[0]==N[1]+N[2]) cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
    }
  return 0;
}

Measured memory_bytes: 3012
O = list(input())
E = list(input())

ans = [0]*(len(O)+len(E))
for i in range(len(ans)):
    if i % 2 == 0:
        ans[i] = O[0]
        del O[0]
    else:
        ans[i] = E[0]
        del E[0]
        
print("".join(ans))

Measured memory_bytes: 8996
local N = io.read("n", "l")
local inner = 0
local endsA = 0 -- but not starts w/ B
local startsB = 0 -- but not ends w/ A
local both = 0
for i=1, N do
    local s = io.read("l")
    local head = string.sub(s, 1, 1)
    local tail = string.sub(s, #s, #s)
    if head == 'B' and tail == 'A' then
        both = both + 1
    elseif head == 'B' then
        startsB = startsB + 1
    elseif tail == 'A' then
        endsA = endsA + 1
    end
    for _ in string.gmatch(s, "AB") do
        inner = inner + 1
    end
end
local ans = inner
if both > 0 then
    ans = ans + both - 1
    if endsA > 0 then
        ans = ans + 1
        endsA = endsA - 1
    end
    if startsB > 0 then
        ans = ans + 1
        startsB = startsB - 1
    end
end
ans = ans + math.min(endsA, startsB)
print(ans)

Measured memory_bytes: 880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vec<int> C(N);
    set<int> s;
    for(int i=0;i<N;i++){
        cin >> C[i];
        C[i]--;
        s.insert(C[i]);
    }
    vvec<int> g(N);
    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vec<map<int,ll>> mp(N);
    vec<ll> ans(N,N*(N+1)/2);
    vec<ll> si(N);
    for(int i=0;i<N;i++) if(!s.count(i)) ans[i] = 0;

    auto unite = [&](map<int,ll>& large,map<int,ll>& small){
        for(auto& x:small){
            large[x.first] += x.second;
        }
        small.clear();
    };

    auto dfs = [&](auto&& self,int cur,int par)->void{
        int col = C[cur];
        si[cur] = 1;
        int l = -1,ma = -1;
        for(auto& to:g[cur]) if(to!=par){
            self(self,to,cur);
            ll d = si[to]-(mp[to].count(col)? mp[to][col]:0);
                ans[col] -= d*(d+1)/2;
            si[cur] += si[to];
            if(l==-1 || ma<mp[to].size()){
                l = to;
                ma = mp[to].size();
            }
        }
        if(l!=-1){
            swap(mp[cur],mp[l]);
            for(auto& to:g[cur]) if(to!=par && to!=l){
                unite(mp[cur],mp[to]);
            }
        }
        mp[cur][col] = si[cur];
    };
    dfs(dfs,0,-1);
    for(auto& x:mp[0]){
        ll d = si[0]-x.second;
        ans[x.first] -= d*(d+1)/2;
    }
    for(auto& x:ans) cout << x << "\n";
}

Measured memory_bytes: 78652
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 998244353


#############
# Main Code #
#############

N = getN()
A = getArray(N)

ans = deque([A[0]])
for i in range(1, N):
    index = bisect_left(ans, A[i])
    if index == 0:
        ans.appendleft(A[i])
    else:
        ans[index - 1] = A[i]

print(len(ans))

Measured memory_bytes: 82444
#!/usr/bin/python
# -*- coding: utf-8 -*-

def main():
    while(True):
        # 入力
        N = int(raw_input())
        if N == 0:
            break

        inp = []
        for x in range(N):
            input_list = map(int, raw_input().split())
            inp.append(input_list)

        printAns(inp)

def printAns(num_list):
    add_list = []
    for x in num_list:
        x.append(sum(x))
        add_list.append(x)

    total_list = [sum(x) for x in zip(*add_list)]
    add_list.append(total_list)
    print5digit(add_list)

def print5digit(num_list):
    for x in num_list:
        print "".join(map(lambda x_: str(x_).rjust(5), x))

if __name__=='__main__':
    main()

Measured memory_bytes: 4236
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define llu unsigned long long 
#define ll long long 
ll read() { ll  x; if (scanf("%lld", &x) == -1)exit(0); return x; }
#define vi vector<int>
#define vb vector<bool>
const long long INF = 5e18;

#define LOCAL_JUDGE
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

map<ll, ll> memo;
ll A, B, C, D, N;

ll f(ll goal) {
   
    if (memo.count(goal)) return memo[goal];
    if (goal == 0) return 0;
    if (goal == 1) return D;

    ll best = INF;
    if (D < INF / goal) {
        best = min(best, D * goal);
    }

    for (int i = 0; i < 3; i++) {
        auto mul = vector<ll>{ 2, 3, 5 }[i];
        auto cost = vector<ll> { A, B, C }[i];
        if (goal % mul == 0) {
            best = min(best, cost + f(goal / mul));
        }
        else {
            ll down = goal / mul * mul;
            ll v1 = cost + f(goal / mul) + (goal - down) * D;
            ll up = down + mul;
            ll v2 = cost + f(goal / mul + 1) + (up - goal) * D;
            best = min(best, v1);
            best = min(best, v2);
        }
    }
    return memo[goal] = best;
}


int main() {
    //c_p_c();
    auto T = read();
    while (T--) {
        memo.clear();
        N = read();
        A = read();
        B = read();
        C = read();
        D = read();
        cout << f(N) << endl;
    }
    return 0;
}



Measured memory_bytes: 4356
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

void solve(){

    ll n;
    cin >> n;
    if(n==1){
        cout << "Yes" << endl;
        cout << 2 << endl;
        cout << "1  1" << endl;
        cout << "1  1" << endl;
        return;
    }
    ll tmp=3;
    ll count=3;
    vector<vector<ll>> v;
    vector<ll> x;
    x.emplace_back(1);
    x.emplace_back(2);
    v.emplace_back(x);
    x.clear();
    x.emplace_back(1);
    x.emplace_back(3);
    v.emplace_back(x);
    x.clear();
    x.emplace_back(2);
    x.emplace_back(3);
    v.emplace_back(x);
    x.clear();
    while(n>tmp){
        rep(i,count){
            v[i].emplace_back(tmp+1+i);
        }
        vector<ll> y;
        rep(i,count){
            y.emplace_back(tmp+1+i);
        }
        v.emplace_back(y);
        tmp = tmp + count;
        count++;

    }
    if(n!=tmp) cout << "No" << endl;
    else{
        cout << "Yes" << endl;
        cout << v.size() << endl;
        rep(i, v.size()){
            auto t = v[i];
            cout << t.size() << " ";
            rep(j,t.size()){
                cout << t[j] << " ";
            }
            cout << endl;
        }
    }


}

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


Measured memory_bytes: 3840
#include<iostream>

int main(){
    
    int d;

    std::cin >> d;

    if(d == 25){
        std::cout << "Christmas" << std::endl;
    }else if(d == 24){
        std::cout << "Christmas Eve" << std::endl;
    }else if(d == 23){
        std::cout << "Christmas Eve Eve" << std::endl;
    }else{
        std::cout << "Christmas Eve Eve Eve" << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
using namespace std;

typedef long long ll;

int main()
{
    int a, b, k;
    vector<int> v;
    cin >> a >> b >> k;
    mFOR(i, __gcd(a, b), 0)
    {
        if (a % i == 0 && b % i == 0)
        {
            k--;
            if (k == 0)
            {
                cout << i << "\n";
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
class Dice :
    def __init__(self, pane):
        self.pane = pane
    
    def roll_W(self):
        temp = self.pane[0]
        self.pane[0] = self.pane[2]
        self.pane[2] = self.pane[5]
        self.pane[5] = self.pane[3]
        self.pane[3] = temp

    def roll_S(self):
        temp = self.pane[0]
        self.pane[0] = self.pane[4]
        self.pane[4] = self.pane[5]
        self.pane[5] = self.pane[1]
        self.pane[1] = temp
    
dice = Dice(input().split())
n = int(input())
result = []

for i in range(0, n):
    str_in = input().split()
    t = str_in[0]
    f = str_in[1]
    while True:
        if (dice.pane[0] == f or dice.pane[4] == f):
            dice.roll_S()
        if (dice.pane[0] == t and dice.pane[1] == f):
            break
        dice.roll_W()

    result.append(dice.pane[2])

for i in result:
    print(i)



Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define repr1(i, n) for (int i = n; i >= 1; i--)
#define all(v) v.begin(), v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  string s;
  cin >> s;
  if (s.size() >= 4 && s.substr(0, 4) == "YAKI") {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    LL n, k;
    cin >> n >> k;
    n = n % k;
    cout << min({n, llabs(n - k), llabs(k - n)}) << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int x;
    cin >> x;
    while(x--){
        float x1,x2,x3,x4,y1,y2,y3,y4;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        float a = (y1-y2)*(x3-x4);
        float b = (y3-y4)*(x1-x2);
        if(a==b)    cout << "YES\n";
        else    cout << "NO\n";
    }
    return 0;
}


Measured memory_bytes: 3060
def calc(n):
    return n * (n+1) / 2

S = list(input())

prev = S[0]
series = 1
l = []

for i in range(1, len(S)):
    if prev == S[i]:
        series += 1
    else:
        l.append((prev, series))
        prev = S[i]
        series = 1

l.append((prev, series))

prev_max = l[0][1]
prev = calc(prev_max)
res = prev

for s, n in l[1::]:
    if s == '<':
        prev = calc(n)
        prev_max = n
        res += prev
    else:
        if n >= prev_max:
            res -= prev_max
            prev = calc(n)
            res += prev
        else:
            prev = calc(n-1)
            res += prev

print(int(res))


Measured memory_bytes: 27440
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;
int main(){
    int n,x,t;
    cin >> n >> x >> t;
    if(n%x==0) cout << (n/x)*t << endl;
    else cout << ((n/x)+1)*t << endl;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n,d[20][20];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		for(int j = 0; j < a; j++){
			int b,c;
			cin >> b >> c;
			d[i][b-1] = c+1;
		}
	}
	
	int ans = 0;
	for(int i = 0; i < (1<<n); i++){
		bool c[20] = {0};
		int cnt = 0;
		for(int j = 0; j < n; j++){
			if(i>>j&1){
				c[j] = 1;
				cnt++;
			}
		}
		bool ok = 1;
		for(int j = 0; j < n; j++){
			if(!c[j]) continue;
			for(int k = 0; k < n; k++){
				if(j == k) continue;
				if(d[j][k] && c[k] ^ (d[j][k]-1)){
					ok = 0;
					break;
				}
			}
			if(!ok) break;
		}
		if(ok) chmax(ans,cnt);
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
 
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define mod 1000000007
    #define qmod 998244353
    #define M 1000001
    #define endl "\n"
    #define all(a) (a).begin(),(a).end()
    #define rep(i,a,b) for(int i=a;i<b;++i)
    #define repr(i,a,b) for(int i=a;i>=b;--i)
    #define F first
    #define S second
    #define pb push_back
    #define mp make_pair
 
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef vector<int> vi;
    typedef vector<string> vs;
    typedef vector<pii> vii;
    typedef vector<vi> vvi;

    int main(){
        
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin); 
    freopen("output.txt","w",stdout);   
    #endif  */

        fast;
        ll n,k;
        cin>>n>>k;
        ll d1=n/k;
        ll d2=d1+1;
        ll ans1=abs(n-(d1*k));
        ll ans2=abs(n-(d2*k));
        cout<<min(ans1,ans2);
        return 0;  
    }       
 
 
    //keep it simple stupid


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<set>
#include<map>
using namespace std;

int main(void){
    int n;
	cin>>n;
	if(n==1){
		cout<<"Hello World";
	} else{
		int a,b;
		cin>>a>>b;
		cout<<a+b;
	}
    return 0; 
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstring>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>
#include<cstdio>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF ((LLONG_MAX) / (2))
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;


int main(){


    string s;
    cin >> s;
    int count = 0;
    int s_count = 0,t_count = 0;

    for(int i = 0;i < s.length();i++){
        if(s[i] == 'S'){

            if(s_count >= t_count){
                s_count++;
            }

        }else{

            if(t_count < s_count){
                t_count++;
            }
        }

        if(s_count > 0 && t_count > 0){
            count++;
            s_count--;
            t_count--;
        }
        //cout << s[i] << " " << s_count << " " << t_count << endl;
    }
   
    cout << s.length()-2*count << endl;


    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()

int main(){
  ll x;
  cin >> x;
  ll happy1000 = x / 500 * 1000;
  ll happy5 = x % 500 / 5 * 5;
  ll answer = happy1000 + happy5;
  cout << answer << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <tuple>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
//ll mod = 1000000007;
//ll mod = 998244353;

int main() {
	int n;
	cin >> n;
	set<int> st;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		st.insert(a);
	}
	cout << st.size() << endl;
}


Measured memory_bytes: 7672