akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = list(input())
r = [0]*n
g = [0]*n
b = [0]*n
for i in range(n):
    if s[i]=='R':
        r[i] = 1
    elif s[i] == 'G':
        g[i] = 1
    elif s[i] == 'B':
        b[i] = 1

r_cum = [0]*n
g_cum = [0]*n
b_cum = [0]*n

x = y = z = 0
i = n-1
while i>=0:
    if r[i]==1:
        x+=1
    if g[i]==1:
        y+=1
    if b[i]==1:
        z+=1
    r_cum[i] = x
    g_cum[i] = y
    b_cum[i] = z
    i-=1
s = 0
for i in range(n):
    for j in range(i+1,n):
        #RGB
        if r[i]==1 and g[j]==1:
            if j+1<n and 2*j-i<n and b[2*j-i] == 1:
                s = s + (b_cum[j+1]-1)
            elif j+1<n:
                s = s + b_cum[j+1]
        #RBG
        if r[i]==1 and b[j]==1:
            if j+1<n and 2*j-i<n and g[2*j-i] == 1:
                s = s + (g_cum[j+1]-1)
                #print(i,j,b_cum[j+1]-1)
            elif j+1<n:
                s = s + g_cum[j+1]
                #print(i,j,b_cum[j+1])
        #GBR
        if g[i]==1 and b[j]==1:
            if j+1<n and 2*j-i<n and r[2*j-i] == 1:
                s = s + (r_cum[j+1]-1)
                #print(i,j,b_cum[j+1]-1)
            elif j+1<n:
                s = s + r_cum[j+1]
                #print(i,j,b_cum[j+1])
        #GRB
        if g[i]==1 and r[j]==1:
            if j+1<n and 2*j-i<n and b[2*j-i] == 1:
                s = s + (b_cum[j+1]-1)
                #print(i,j,b_cum[j+1]-1)
            elif j+1<n:
                s = s + b_cum[j+1]
                #print(i,j,b_cum[j+1])
        if b[i]==1 and r[j]==1:
            if j+1<n and 2*j-i<n and g[2*j-i] == 1:
                s = s + (g_cum[j+1]-1)
                #print(i,j,b_cum[j+1]-1)
            elif j+1<n:
                s = s + g_cum[j+1]
                #print(i,j,b_cum[j+1])
        if b[i]==1 and g[j]==1:
            if j+1<n and 2*j-i<n and r[2*j-i] == 1:
                s = s + (r_cum[j+1]-1)
                #print(i,j,b_cum[j+1]-1)
            elif j+1<n:
                s = s + r_cum[j+1]
                #print(i,j,r_cum[j+1])
print(s)

Measured memory_bytes: 75648
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int n,A,B,C;
vi a;

int main(){
	cin>>n>>A>>B>>C;
	a=vi(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]*=-1;
	}
	sort(a.begin(),a.end());
	int sum=0,ans=0;
	for(int i=0;i<n;i++){
		sum-=a[i];
		int tmp=(sum+C)/(A+B*(i+1));
		ans=max(ans,tmp);
	}
	cout<<ans<<endl;
}

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

const ll mod = 998244353;


ll modPow(ll a, int n)
{
	ll mul = a;
	ll ans = 1;

	while ( n > 0 ) {
		if ( n & 1 ) (ans *= mul) %= mod;
		(mul *= mul) %= mod;
		n >>= 1;
	}
	return ( ans );
}

int main()
{
	int N;
	int A[100005];
	int count[100005] = {};
	int mul = 1;
	int maxv = 0;
	cin >> N;

	for ( int i = 0; i < N; i++ ) {
		cin >> A[i];
		maxv = max(maxv, A[i]);
		count[A[i]]++;
	}

	if ( A[0] == 0 && count[0] == 1 ) {
		for ( int i = 1; i <= maxv; i++ ) {
			mul = ((ll)mul * modPow(count[i - 1], count[i])) % mod;
		}

		cout << mul << endl;
	} else {
		cout << 0 << endl;
	}
	
	return ( 0 );
}


Measured memory_bytes: 1024
import sys
n = int(input())
A = [int(e)for e in sys.stdin]
cnt = 0
G = [int((2.0555**i-1)/1.0555)for i in range(19,1,-1)]+[1]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
for g in G:
    insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print(*A,sep='\n')


Measured memory_bytes: 53328
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
//#define scanf scanf_s
#define fir first
#define sec second
#define mp make_pair
#define mt make_tuple
#define pub push_back
using namespace std;
typedef long long int llint;
const llint one = 1;
const llint big = (one<<30);
const llint mod=1000000007;

/*printf("? %c %c\n",x,y);
		fflush(stdout);
		char ret;scanf(" %c", &ret);
		*/
int main(void){
	int i,j,k,N=200,chousei=5,a,b;
	vector<pair<int,int>> kotae;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		for(j=i+1;j<N;j+=chousei){
			printf("? ");
			for(k=0;k<N;k++){
				if(k==i||(j<=k&&k<j+chousei)){a=1;} else{a=0;}
				printf("%d",a);
			}
			printf("\n");
			fflush(stdout);
			scanf("%d",&a);
			if(a!=0){
				for(k=j;k<min(j+chousei,N);k++){
					printf("? ");
					for(int l=0;l<N;l++){
						if(l==i||k==l){b=1;} else{b=0;}
						printf("%d",b);
					}
				printf("\n");
				fflush(stdout);
				scanf("%d",&b);
				if(b!=0){kotae.pub(mp(i,k));}
				}
			}
		}
	}
	printf("!");
	for(i=0;i<kotae.size();i++){
		printf(" (%d,%d)",kotae[i].first,kotae[i].second);
		
	}
	printf("\n");
	fflush(stdout);
	return 0;
}


Measured memory_bytes: 848
#include <stdio.h>
#include <ctype.h>

int main(void)
{
	char c;
	int i;
	int cnt[26]={0};
	
	while((c=getchar()) != EOF)
	{
		if(isupper(c))
			c = tolower(c);
		if(c >= 'a' && c <= 'z')
			cnt[(c-'a')]++;
		
	}
	for(i=0;i<26;i++)
		printf("%c : %d\n",'a'+i,cnt[i]);
	
	
	return 0;
}

Measured memory_bytes: 524
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int a[100], b[100];
PII p[100];
signed main(void)
{
  int n, K;
  cin >> n >> K;
  REP(i, n) {
    cin >> a[i] >> b[i];
    p[i] = {a[i], b[i]};
  }
  sort(p, p+n);
  int ret = -1;
  REP(i, n) FOR(j, i, n) {
    // cout << i << "," << j << endl;
    VI v;
    REP(k, n) {
      if(p[i].first <= p[k].first && p[k].first <= p[j].first) {
        v.PB(p[k].second);
      }
    }
    sort(ALL(v));
    // for(int i: v) cout << i << " "; cout << endl;
    REP(k, v.size()-K+1) {
      if(ret == -1) {
        ret = (p[j].first-p[i].first)*(v[k+K-1]-v[k]);
      } else {
        chmin(ret, (p[j].first-p[i].first)*(v[k+K-1]-v[k]));
      }
    }
    // cout << "ret:" << ret << endl;
  }
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256
n =gets.to_i
array = gets.split.map{|a| a.to_i}
def gcb(a,b)
  gcb(b,a) if b > a
  return b if (r= a%b).zero?
  gcb(b,r)
end

d = array.inject{|memo,item|
gcb(memo,item)}
puts d


Measured memory_bytes: 8452
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int ball, people, max, diff;
  cin >> ball >> people;

  if (people == 1) { cout << 0 << endl; return 0; }
  /* At least one ball for each person. */
  max = ball - (people-1);
  
  int min = 1;
  diff = max - min;
  cout << diff << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100100
using namespace std;
int beg[N],to[N<<1],nex[N<<1];
int n,done[N],fa[N],dis[N],bs;
int tot,len;
inline void Add(int a,int b){
	nex[++len]=beg[a],beg[a]=len,to[len]=b;
	nex[++len]=beg[b],beg[b]=len,to[len]=a;
}
void dfs(int p){
	tot++;
	for(int i=beg[p];i;i=nex[i]){
		if(done[to[i]]) continue;
		if(to[i]==fa[p]) continue;
		fa[to[i]]=p;dis[to[i]]=dis[p]+1;
		dfs(to[i]);
	}
}
int main(){
	cin>>n;
	for(int i=1,a,b;i<n;i++){
		cin>>a>>b;
		Add(a,b);
	}
	dfs(1);
	tot=0;
	bs=(dis[n]+1)/2;
	int zd=n;
	while(bs){
		bs--;
		done[zd]=1;
		zd=fa[zd];
	}
	dfs(1);
	if(n-tot>=tot) puts("Snuke");
	else puts("Fennec");
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define R freopen("555input.txt","r",stdin);
#define N 105
int i,j,t,n,sa[N],sb[N],ma;
int main ()
{
    
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>t;
        sa[i]=sa[i-1]+t;
    }
    for(i=1;i<=n;i++)
    {
        cin>>t;
        sb[i]=sb[i-1]+t;
    }
    for(i=1;i<=n;i++)
    {
        ma=max(ma,sa[i]+sb[n]-sb[i-1]);
    }
    cout<<ma;

    return 0;
}


Measured memory_bytes: 256
import sys

matrix = []
for i in range(3):
  matrix.append([int(j) for j in input().split()])
#print(matrix)

def find(b):
  for i in range(3):
    for j in range(3):
      if matrix[i][j] == b:
        return (i, j)
  return None

matched = [[False for _ in range(3)]
           for _ in range(3)]
n = int(input())
for i in range(n):
  b = int(input())
  result = find(b)
  if result is not None:
    matched[result[0]][result[1]] = True
    
for i in range(3):
  ans = True
  for j in range(3):
    if not matched[i][j]:
      ans = False
      break
  if ans:
    print('Yes')
    sys.exit()
  
for i in range(3):
  ans = True
  for j in range(3):
    if not matched[j][i]:
      ans = False
      break
  if ans:
    print('Yes')
    sys.exit()
  
if matched[0][0] and matched[1][1] and matched[1][1]:
  print('Yes')
  sys.exit()

if matched[0][2] and matched[1][1] and matched[2][0]:
  print('Yes')
  sys.exit()
  
print('No')

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

int main() {
  string n;
  cin >> n;
  int sum = 0;
  
  for (int i = 0; i < n.size(); i++){
    sum += n.at(i) - '0';
  }
  
  if (sum % 9 == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3704
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const long double EPS = 1E-10;

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


int dfs(int N, int M, int id, std::vector<int>& A, int prv,
        std::vector<int>& a, std::vector<int>& b,
        std::vector<int>& c, std::vector<int>& d){
    if(id == N){
        int ans(0);
        for(int i(0), i_len(a.size()); i < i_len; ++i){
            if(A[b[i]-1] - A[a[i]-1] == c[i]) ans += d[i];
        }
        return ans;
    }
    int ans(0);
    for(int i(prv); i <= M; ++i){
        A[id] = i;
        chmax(ans, dfs(N, M, id+1, A, i, a, b, c, d));
    }
    return ans;
}


int main(){
    int N, M, Q; std::cin >> N >> M >> Q;
    std::vector<int> a(Q), b(Q), c(Q), d(Q);
    for(int i(0); i < Q; ++i){
        std::cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    std::vector<int> A(N, 0);
    std::cout << dfs(N, M, 0, A, 1, a, b, c, d) << std::endl;
    return 0;
}


Measured memory_bytes: 3560
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pll=pair<ll,ll>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vstr=vector<string>;

void solve() {
    ll N;
    cin >> N;
    vll d(N);
    rep(i,N){
        cin >> d[i];
    }
    sort(ALL(d));
    ll abc=d[N/2-1], arc=d[N/2];
    if(abc==arc) print(0);
    else{
        print(arc-abc);
    } 
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 3976
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"

using namespace std;
typedef long long ll;

int main()
{
  int x, a, b;
  cin >> x >> a >> b;
  if (a >= b)
  {
    cout << "delicious" << "\n";
  }
  else
  if (x + a >= b)
  {
    cout << "safe" << "\n";
  }
  else
  {
    cout << "dangerous" << "\n";
  }
}

Measured memory_bytes: 256
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

A.sort()

arr = []
arr.append(A[0])
arr.append(A[-1])
Atop = 1
Abtm = len(A) - 2
ans = arr[-1]-arr[0]
for i in range(len(A)-2):
    (Ai, ai) = (Atop, 0)
    if abs(A[Atop]-arr[-1]) > abs(A[Ai]-arr[ai]):
        (Ai, ai) = (Atop, -1)
    if abs(A[Abtm]-arr[0]) > abs(A[Ai]-arr[ai]):
        (Ai, ai) = (Abtm, 0)
    if abs(A[Abtm]-arr[-1]) > abs(A[Ai]-arr[ai]):
        (Ai, ai) = (Abtm, -1)

    #print('A[Ai]: ', A[Ai])
    #print(arr)
    ans += abs(A[Ai]-arr[ai])
    if ai == -1:
        arr[-1] = A[Ai]
    else:
        arr[0] = A[Ai]

    if Ai == Atop:
        Atop += 1
    else:
        Abtm -= 1


print(ans)


Measured memory_bytes: 58072
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner cin = new Scanner(System.in);
		
		int m = 100000;
		int n = cin.nextInt();
		for(int i=0; i<n; i++)
		{
			m *= 1.05;
			m  = (m+999)/1000*1000;
		}
		
		System.out.println(m);
	}
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

int n, k, s;
int dfs(int m, int sum, int d) {
  //cout << m << " " << sum << " " << d << endl;
  if(!m) {
    if(!sum) return 1;
    else return 0;
  }

  int res = 0;
  FOR(i, d, n+1) {
    res += dfs(m-1, sum-i, i+1);
  }

  return res;
}

signed main(void)
{
  while(true) {
    cin >> n >> k >> s;
    if(!n && !s && ! k) break;
    cout << dfs(k, s, 1) << endl;
  }
  return 0;
}

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

int main(){

    int N;
    cin >> N;
    vector<int> A(N);
    rep (i, N) cin >> A[i];

    long long now_yen = 1000;
    long long now_stocks = 0;
    rep (i, N){
        if (i == N-1){
            now_yen += A[i]*now_stocks;
            now_stocks = 0;
            break;
        }
        if (A[i] <= A[i+1]){
            now_stocks += now_yen / A[i];
            now_yen %= A[i];
        } else {
            now_yen += A[i]*now_stocks;
            now_stocks = 0;
        }
    }

    cout << now_yen << endl;

    return 0;
}

Measured memory_bytes: 3560
/*Author SHUBH AGRAWAL  */

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
//a power n mod p

#define vl  vector<long long int >
#define vpl vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 

long long int modp(lld a,lld p,lld n)
{
    int d[100];
    int i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

long long int nCrModPFermat(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
    
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    lld fac[n+1]; 
    fac[0] = 1; 
    for (lld i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}


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


lld l,r,mid,ans;
lld n,m,i,j,k,x;


char c;
void solve()
{
    string s;
    cin>>s;
    if(s[5]!=s[4])
    {
        cout<<"No";
        return;
    }
    else if(s[2]!=s[3])
    {
        cout<<"No";
        return;
    }
    cout<<"Yes";
    cout<<"\n";
}

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

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

using namespace std;

const ll INF = 5e17;

ll k;
int n, a[200010];
int nxt[200010], f[200010], last[200010];
ll up[60][200010];
bool vis[200010];

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> k;
    memset(f, -1, sizeof f);
    memset(nxt, -1, sizeof nxt);
    memset(last, -1, sizeof last);
    for (int i = 0; i < n; i++)
    {
    	cin >> a[i];
        if (f[a[i]] == -1)
            f[a[i]] = i;
    }
    for (int i = n - 1; i >= 0; i--)
    {
        if (last[a[i]] == -1)
		{
            nxt[i] = f[a[i]] + n - i + 1;
            last[a[i]] = i;
        }
        else
        {
            nxt[i] = last[a[i]] - i + 1;
            last[a[i]] = i;
        }
    }
    ll t = k * n;
    for (int i = 0; i < n; i++)
        up[0][i] = nxt[i];
    for (int j = 1; j <= 58; j++)
        for (int i = 0; i < n; i++)
		{
            int cur = (up[j - 1][i] + i) % n;
            up[j][i] = up[j - 1][i] + up[j - 1][cur];
            up[j][i] = min(up[j][i], INF);
        }
    ll sum = 0;
    int cur = 0;
    for (int j = 58; j >= 0; j--)
        if (sum + up[j][cur] < t)
		{
            sum += up[j][cur];
            cur = (cur + up[j][cur] % n) % n;
        }
    sum %= n;
    vector<int> st;
    for (int i = sum; i < n; i++)
	{
        if (!vis[a[i]])
		{
            st.push_back(a[i]);
            vis[a[i]] = true;
            continue;
        }
        while (!st.empty() && st.back() != a[i])
		{
            vis[st.back()] = false;
            st.pop_back();
        }
        vis[a[i]] = false;
        st.pop_back();
    }
    for (int v : st)
    	cout << v << ' ';
    cout << endl;
    return 0;
}


Measured memory_bytes: 99572
/*
  GOOD is not Enough
  You've got to be GREAT.
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


void solve()
{ 
 int n,k;
 cin >> n >> k;
 int x=n/k;
 if(n>=k)
  cout << min(abs(n-(x*k)),abs(n-((x+1)*k))) << '\n';
 else
  cout << min(n,k-n) << '\n';
 return;
}

signed main()
{
  int T=1;
  // cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
lake_m, house_num = map(int, input().split())
house_m_li = list(map(int, input().split()))

house_between_distance = list()

for i in range(house_num):
    if i == 0:
        house_between_distance.append(house_m_li[i] + (lake_m - house_m_li[-1]))
    else:
        house_between_distance.append(house_m_li[i] - house_m_li[i-1])

print(lake_m - max(house_between_distance))


Measured memory_bytes: 26444
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    string s;
    cin >> s;
    int ans = static_cast<int>(s.length());
    int n = ans;
    for (int i = 0; i < n-1; ++i) {
        if(s[i] != s[i+1]) ans = min(ans, max(n-i-1, i+1));
    }
    cout << ans << "\n";
    return 0;
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

void solve(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int turn = -1;
	while(a > 0 && c > 0) {
		if(turn == -1) {
			c -= b;
		}
		if(turn == 1) {
			a -= d;
		}
		turn *= -1;
	}
	string s = "No";
	if(a > c) s = "Yes";
	cout << s;
}

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

	solve();
    
    return 0;
}


Measured memory_bytes: 3628
H, W, K = map(int, input().split())

fib = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
mod = 10 ** 9 + 7
'''
端にいてそのまま下にいくときfib[W+1]
端にいて右か左にいくときfib[W]
中にいて下に行くとき
'''
if W == 1:
    print(1)
    exit()

dp = [[0] * W for _ in range(H + 1)]
dp[0][0] = 1
for h in range(1, H + 1):
    for w in range(W):
        if w == 0:
            # 上からくるか右からくるかのどちらか
            dp[h][w] = dp[h - 1][w] * fib[W - 1] + dp[h - 1][w + 1] * fib[W - 2]
        elif w == W - 1:
            dp[h][w] = dp[h - 1][w] * fib[W - 1] + dp[h - 1][w - 1] * fib[W - 2]
        else:
            dp[h][w] = dp[h - 1][w] * fib[w] * fib[W - 1 - w] + dp[h - 1][w + 1] * fib[W - w - 2] * fib[w] + dp[h - 1][
                w - 1] * fib[
                           w - 1] * fib[W - 1 - w]
        dp[h][w] %= mod

print(dp[H][K - 1])


Measured memory_bytes: 3192
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N,t;
    cin>>N>>t;
    if(N>=t)cout<<N-t<<endl;
    else cout<<0<<endl;
    return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N){
  long long cpyN = N;
  long long acc = 0;

  while(cpyN > 0){
    acc += cpyN % 10;
    cpyN /= 10;
  }

  cout << ((N%acc == 0) ? YES : NO) << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3740
//AtCoder ABC065 C - Reconciled?
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
constexpr ll MOD=1e9+7;

ll kaijyou(ll a){
    ll ret=1;
    while(a>=1){
        ret=ret*a%MOD;
        --a;
    }
    return ret;
}

int main() {
    ll N,M;
    cin>>N>>M;
    ll ans=0;
    if(N==M||abs(N-M)==1){
        ans = kaijyou(N) * kaijyou(M) % MOD;
        ans = ans * (N==M?2:1) % MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    A=LI()
    for i in range(N):
        A[i]-=1
    used=[0]*N
    used[0]=1
    
    now=0
    nxt=0
    cnt=1
    flag=1
    while True:
        nxt=A[now]
        if used[nxt]==0:
            used[nxt]=cnt+1
        else:
            if flag:
                lpath=cnt+1-used[nxt]
                roop=(K-cnt)//lpath
                #print(lpath,roop,cnt)
                cnt+=roop*lpath
                flag=0
        now=nxt
        #print(now,cnt)
        if cnt==K:
            break
        cnt+=1
        
            
    print(now+1)

main()


Measured memory_bytes: 91120
import collections
h,w = (int(i) for i in input().split())
c = [[int(i) for i in input().split()] for i in range(10)]
a = [[int(i) for i in input().split()] for i in range(h)]
for k in range(10):
		for i in range(10):
			for j in range(10):
				c[i][j] = min(c[i][k]+c[k][j],c[i][j])
x,answer = [],0
for i in a: x+=i
y = collections.Counter(x)
for i in range(10):
	answer += y[i]*c[i][1]
print(answer)

Measured memory_bytes: 4148
#参考
#https://atcoder.jp/contests/aising2019/submissions/3995168

import bisect

N,Q=map(int,input().split())

A=list(map(int,input().split()))
Asum=[0]*N
Asum2=[0]*N
total=0

for i in range(N):
  total+=A[i]
  Asum[i]=total
  if i>1:
    Asum2[i]=A[i]+Asum2[i-2]
  else:
    Asum2[i]=A[i]

X=[] 
for i in range(Q):
  X.append((int(input()),i))
X.sort(key=lambda x :x[0])
  

#yで高橋くんと青木くんの取りたいカードが初めて衝突すると考える。
#このようなyは半分より小さい所にはないので初期値を半分のところとする。
#yがNまで来た時は最初から交互に取る
#Xを小さい順から計算することで、yの値が単調増加になる
y=N//2-1
ans=[0]*Q
for x,i in X:
  while y<=N-1 and x>A[y]:
    y+=1
  while y<=N-1:
    takahashi=N-y
    aoki=y+1-bisect.bisect_left(A,x-(A[y]-x))
    if takahashi>aoki:
      y+=1
    else:
      break
  #右端からA[y]までは全て高橋くんが取る
  ans[i]+=Asum[N-1]-Asum[y-1]
  #青木くんはyからN-y個取っているので、その下のところから交互に取る
  if y-(N-y)-1<0:
    continue
  ans[i]+=Asum2[y-(N-y)-1]

for i in range(Q):
  print(ans[i])

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

vector <int> vec[6];
int n;

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

	cin >> n;
	if (n == 3) {
		printf("2 5 63\n"); return 0;
	}

	for (int i = 1; i <= 30000; ++i) {
		if (i % 2 == 0 || i % 3 == 0) {
			vec[i % 6].push_back(i);
		}
	}

	vector <int> res;
	res.push_back(vec[3].back()); vec[3].pop_back();
	res.push_back(vec[3].back()); vec[3].pop_back();
	res.push_back(vec[2].back()); vec[2].pop_back();
	res.push_back(vec[4].back()); vec[4].pop_back();

	n -= 4;
	while(n) {
		if (n == 1) {
			assert(vec[0].size() > 0);
			res.push_back(vec[0].back()); vec[0].pop_back(); --n;
		} else {
			if (vec[2].size() && vec[4].size()) {
				res.push_back(vec[2].back()); vec[2].pop_back();
				res.push_back(vec[4].back()); vec[4].pop_back();
				n -= 2;
			}
			else if (vec[3].size() >= 2) {
				res.push_back(vec[3].back()); vec[3].pop_back();
				res.push_back(vec[3].back()); vec[3].pop_back();
				n -= 2;
			}
			else {
				assert(vec[0].size() > 0);
				res.push_back(vec[0].back()); vec[0].pop_back(); --n;
			}
		}
	}

	for (auto &i : res) printf("%d ", i); printf("\n");
}

Measured memory_bytes: 768
N = int(input())
blue = ['a']*N
#Nのサイズにしたがって青のカードのリストを作成
for i in range(0,N):
        blue[i] = input()
M = int(input())
red = ['a']*M
#Mのサイズにしたがって赤のカードのリストを作成
for i in range(0,M):
        red[i] = input()
#カードの単語の種類を調べる
set_blue = set(blue)#カードの単語の種類を調べる
set_red = set(red)
#インデックスで参照するためにタプルにする
tuple_blue = tuple(set_blue)
tuple_red = tuple(set_red)

max_score = 0
for i in range(0,len(tuple_blue)):
    score = blue.count(tuple_blue[i])-red.count((tuple_blue[i]))
    if max_score < score:
        max_score = score
print(max_score)


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

int main()
{
	int n,a,b;
	cin >> n>>a>>b;
	int x = 0;
	if (a+b>n)
	{
		x = a + b - n;
	}
	cout << min(a, b) << " " << x << endl;



}

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

#define rep(i, a) for (int i = 0; i < (a); i++ )

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int X;
    cin >> X;
    if (X<600) cout << 8 << endl;
    else if (X<800) cout << 7 << endl;
    else if (X<1000) cout << 6 << endl;
    else if (X<1200) cout << 5 << endl;
    else if (X<1400) cout << 4 << endl;
    else if (X<1600) cout << 3 << endl;
    else if (X<1800) cout << 2 << endl;
    else cout << 1 << endl;

}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll p = 1e9 + 7;
const ll o = 1e6 + 5;
ll n, k, h, d, re = 0, a[o];

void rf()
{
    ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0);
    cin >> n >> k;
}

void xuli()
{
    for (ll i = 0; i <= 2e5 + 5; i++) a[i] = i;
    for (ll i = k - 1; i <= n; i++)
    {
        d = i;
        h = a[n] - i;
        d = (0 + d) * (i + 1) / 2;
        h = (h + a[n]) * (i + 1) / 2;
        re += h - d + 1;
        re %= p;
    }
    cout << re;
}

int main()
{
    rf(); xuli();
}


Measured memory_bytes: 5200
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

N,K=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
#print(N,K)
#print("A:",A)
#print(F)

A.sort()
F.sort(reverse=True)
#print("A:",A)
#print("F:",F)

left=-1
right=2*10**17
#right=10**3

while left+1<right:
  mid=(left+right)//2
  tmp=0
  for i in range(N):
    tmp+=max(A[i]-mid//F[i],0)
    
  if tmp<=K:
    right=mid
  else:
    left=mid
  #print("mid:",mid,",tmp:",tmp)
#print("left:",left,",mid:",mid,",right:",right)
print(right)

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

int main(){
    int N; cin >> N;
    int k;
    bool flg = false;
    for(int i=1; i<=1000; ++i) {
        if(N == i*(i-1)/2) {
            flg = true;
            k = i;
            break;
        }
    }
    if(!flg) cout << "No" << endl;
    else {
        cout << "Yes" << endl;
        cout << k << endl;
        vector<vector<int>> res(k);
        int cnt = 0;
        for(int i=0; i<k; ++i) for(int j=0; j<k; ++j) {
            if(j <= i) continue;
            cnt ++;
            res[i].push_back(cnt);
            res[j].push_back(cnt);
        }
        for(auto &vec:res) {
            cout << vec.size() << " ";
            for(int i=0; i<vec.size(); ++i) {
                cout << vec[i];
                if(i+1 != vec.size()) cout << " ";
            }
            cout << endl;
        }
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> x(n);

    double sum = 0;
    for(int i = 0; i < n; i++) {
        cin >> x[i];
        sum += x[i];
    }

    int ans = 0;
    double avr = sum / n;
    long long rounded = std::llround(avr);

    for(int j = 0; j < n; j++) {
        ans += (x[j] - rounded) * (x[j] - rounded);
    }

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


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

int main()
{
  int n;
  cin>>n;
  vector<string>s;
  string s1;
  int c1=0,c2=0,c3=0,c4=0;
  for(int i=0; i<n; i++)
  {
    cin>>s1;
    s.push_back(s1);
    if(s[i]=="AC")
      	c1++;
   	else if(s[i]=="WA")
      	c2++;
    else if(s[i]=="TLE")
        c3++;
   else if(s[i]=="RE")
     	  c4++;
  }
  cout<<"AC x "<<c1<<endl;
  cout<<"WA x "<<c2<<endl;
  cout<<"TLE x "<<c3<<endl;
  cout<<"RE x "<<c4;
  return(0);
}


Measured memory_bytes: 7460
#include<bits/stdc++.h>
using namespace std;
int main(){
  string n;
  cin >> n;
  int a,b,c,d;
  a = n[0]-'0';
  b = n[1]-'0';
  c = n[2]-'0';
  d = n[3]-'0';
  int i;
  int tmp;
  string s;
  for(i=0;i<=7;i++){
    tmp = a;
    s = "";
    if(i>=4) {
      tmp+=b;
      s += "+";
    }else{
      tmp -= b;
      s += "-";
    } 
    if(i%4>=2) {
      tmp+=c;
      s+= "+";
    }else{
      tmp -= c;
      s+= "-";
    } 
    if(i%2>=1) {
      tmp+=d;
      s+= "+";
    }else{
      tmp -= d;
      s+= "-";
    } 
    if(tmp==7)break;
  }
cout << a << s[0] << b << s[1] << c << s[2] << d << "=7";

  
}

Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int n;
map<pair<int, int>, int> mm;

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	int k = 0;
	while (k * (k - 1) / 2 < n)
		++k;
	if (k * (k - 1) / 2 != n) {
		cout << "No\n";
		return 0;
	}
	int cc = 1;
	for (int i = 0; i < k - 1; ++i)
		for (int j = 0; i + j < k - 1; ++j)
			mm[{i, j}] = cc++;
	cout << "Yes\n";
	cout << k << "\n";
	for (int i = 0; i < k - 1; ++i) {
		int x = i;
		int y = k - 2 - x;
		vector<int> vv;
		for (int j = 0; j <= x; ++j)
			vv.push_back(mm[{j, y}]);
		for (int j = 0; j < y; ++j)
			vv.push_back(mm[{x, j}]);
		cout << vv.size() << " ";
		for (int i: vv)
			cout << i << " ";
		cout << "\n";
	}
	vector<int> vv;
	for (int i = 0; i < k - 1; ++i) {
		vv.push_back(mm[{i, k - 2 - i}]);
	}
	cout << vv.size() << " ";
	for (int i: vv)
		cout << i << " ";
	cout << "\n";
	return 0;
}




Measured memory_bytes: 7680
use proconio::input;

fn main() {
  input! {
    a: usize,
    b: usize,
    q: usize,
    mut aps: [isize;a],
    mut bps: [isize;b],
    mut qs: [isize;q]
  }
  aps.sort();
  bps.sort();
  
  for qv in qs {
    let mut ais = vec![];
    let mut bis = vec![];
    let av = aps.binary_search(&qv).unwrap_err();
    let bv = bps.binary_search(&qv).unwrap_err();
    
    if av < aps.len() {
      if 0 < av {
        ais.push(av-1);
      }
      if av < aps.len() - 1 {
        ais.push(av+1);
      }
      ais.push(av);
    } else {
      ais.push(av-1);
    }
    
    if bv < bps.len() {
      if 0 < bv {
        bis.push(bv-1);
      }
      if bv < bps.len() - 1 {
        bis.push(bv+1);
      }
      bis.push(bv);
    } else {
      bis.push(bv-1);
    }

    let mut min = isize::max_value();
    for ai in ais {
      let av = aps[ai];
      for bi in bis.iter() {
        let bv = bps[*bi];
        let v = if (av - qv).abs() < (bv - qv).abs() {
          (av - qv).abs() + (bv - av).abs()
        } else {
          (bv - qv).abs() + (bv - av).abs()
        };
        min = std::cmp::min(min, v);
      }
    }
    println!("{}", min);
  }
}

Measured memory_bytes: 8028
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
ll INF = 1LL<<40;

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

    int N, Y;
    cin >> N >> Y;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N - i; j++){
            if(i*10000+j*5000+(N-i-j)*1000 == Y){
                cout << i << " " << j << " " << N-i-j << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		sc.close();

		int[] cnt = new int[26];
		for (int i = 0; i < s.length; i++) {
			cnt[s[i] - 'A']++;
		}

		if ((cnt['N' - 'A'] > 0) != (cnt['S' - 'A'] > 0)) {
			System.out.println("No");
			return;
		}
		if ((cnt['W' - 'A'] > 0) != (cnt['E' - 'A'] > 0)) {
			System.out.println("No");
			return;
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int main(){
    int N;
    cin>>N;
    int L[N];
    for(int i=0;i<N;i++)L[i]=i+1;
    int p[N];
    for(int i=0;i<N;i++) cin>>p[i];
    int check=0;
    for(int i=0;i<N;i++){
        if(L[i]!=p[i]){
            check++;
        }
    }
    if(check>2) cout<<"NO";
    else cout<<"YES";
    return 0;
}

Measured memory_bytes: 256
double x[100],y[100],t,u,a,b,s;
n,i,j,k,c;
main(m){
	for(;scanf("%d",&n),i=j=n;printf("%d\n",m)){
		for(m=1;i--;scanf("%lf,%lf",x+i,y+i));
		for(i=n;--i;)
			for(j=i;j--;)
				if(s=(u=acos(hypot(x[j]-x[i],y[j]-y[i])/2))<9)
					for(t=atan2(y[j]-y[i],x[j]-x[i]);c=0,s+3;s-=2)
						for(a=x[i]+cos(t+s*u),b=y[i]+sin(t+s*u),k=n;k--;)
							hypot(a-x[k],b-y[k])<1.1&&++c>m?m=c:0;
	}
}

Measured memory_bytes: 0
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long N, K;
    scan(N, K);
    auto H = aryread();
    long ans;
    foreach (h; H)
        if (K <= h)
            ans++;
    writeln(ans);
}


Measured memory_bytes: 4360
n,m = map(int,input().split())
A=[]
B=[]
for i in range(n):
    A.append(input())
for i in range(m):
    B.append(input())
cnt=0
flag = False
for i in range(n-m+1):
    for j in range(n-m+1):
        ans = 'Yes'
        for k in range(m):
            for l in range(m):
                if A[i+k][j+l]!=B[k][l]:
                    ans = 'No'
        else:
            if ans == 'Yes':
                print(ans)
                exit()
print(ans)

Measured memory_bytes: 9064
// Problem: B - Product Max
// Contest: AtCoder - AtCoder Beginner Contest 178
// URL: https://atcoder.jp/contests/abc178/tasks/abc178_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
 
using namespace std;
#define int long long
#define ll long long
const int N = 2e5+5;
const int mod = 1e9;
#define ld long double
#define PI 3.14159265358979323846
#pragma GCC optimize("-O2")
const int INF = 10000000;

int getIInput() {
	cout.flush();
	#ifdef LOCAL
	return generateLocalInputOrAnythingYouWant();
	#else
	int x;
	cin>>x;
	return x;
	#endif
}

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(9);
}
 
//3. Structure or classes
//3. Ends here
 
//1. Data structures declaration here
//1. Ends here
 
//2. Extra Functions here
//2. Ends here
 
 
void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
        //cout<<"\n";
    }
    return 0;
}
 
 
 
void solve()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	
	cout<<max(a*c,max(a*d,max(b*c,b*d)));
    return;
}
// how r u bro

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

unsigned long long int gcd(unsigned long long int a,unsigned long long int b){
	if(a==0){
		return b;
	}
	return gcd(b % a, a);
}
unsigned long long int lcm(unsigned long long int a,unsigned long long int b){
	return (a*b)/gcd(a,b);
}


int main(){
	unsigned long long int a,b,c,d,cnta=0,cntb=0, cntl=0,l;
	cin>>a>>b>>c>>d;
	unsigned long long int sa,sb,ea,eb,sl,el;
	l=lcm(c,d);
	if(a%c==0){
		sa = a/c;
	}else{
		sa = (a/c)+1;
	}
	if(a%d==0){
		sb=a/d;
	}else{
		sb=(a/d)+1;
	}
	if(a%l==0){
		sl=(a/l);
	}else{
		sl=(a/l)+1;
	}
	ea=b/c;
	eb=b/d;
	el=b/l;
	cnta=ea-sa+1;
	cntb=eb-sb+1;
	cntl=el-sl+1;
	cout<<(b-a+1)-(cnta+cntb-cntl)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define sec second 
#define MOD 1000000007
#define pb push_back
#define endl "\n"
#define test cout<<"debuged\n";
#define INF 10000000000
#define si 1000000
#define pi pair<ll,ll>

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n,0);
    for(auto &x:v)
      cin>>x;
    vector<ll> ans(k+1,0);
    //win 1,lose 0
    ans[0]=0;
    for(ll i=1;i<=k;i++)
    {
      bool chk=false;
      for(auto x:v)
      {
        if(x<=i)
        {
          if(ans[i-x]==0)
          {
            ans[i]=1;
            break;
          }
        }
      }
    }
    if(ans[k]==1)
    {
      cout<<"First";
    }
    else
    {
     cout<<"Second"; 
    }

}


Measured memory_bytes: 1024
#include <tuple>
#include <vector>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
using ll	= long long;
using ull	= unsigned long long;
using ld	= long double;
using pii	= pair<int,int>;
using pll	= pair<ll,ll>;
using vi	= vector<int>;
using vb	= vector<bool>;
using vc	= vector<char>;
using vvi	= vector<vi>;
using vvb	= vector<vb>;
using vpii	= vector<pii>;
using vpll	= vector<pll>;
using vll	= vector<ll>;
using vull	= vector<ull>;
#define ever (;;)
#define f first
#define s second
#define pb emplace_back
#define sz size()
#define graph vector<vertex>
#define deg(X) (int)G[X].e.size()
#define INF 1234567890
#define INFll 2000000000000000000
#define maxe(X, Y) if((Y) > (X)) (X) = (Y)
#define mine(X, Y) if((Y) < (X)) (X) = (Y)
#define rep(i, begin, end) for(__typeof(end) i = (begin); i < (end); ++i)
#define repr(i, begin, end) for(__typeof(end) i = (begin)-1; i >= (end); --i)
#define bend(X) X.begin(), X.end()
pii operator+(const pii& A, const pii& B) { return {A.f+B.f, A.s+B.s}; }
pii operator-(const pii& A, const pii& B) { return {A.f-B.f, A.s-B.s}; }
pii operator-(const pii& A) { return {-A.f, -A.s}; }

//
// END OF DEFINES
//

int n;
vi T, DP;

bool in() {
	scanf("%d", &n);
	T.resize(n);
	DP.resize(n, INF);
	DP[0] = 0;
	rep(i, 0, n)
		scanf("%d", &T[i]);
	
	return true;
}

ll solve() {
	rep(i, 1, n) {
		mine(DP[i], DP[i-1]+abs(T[i]-T[i-1]));
		if(i > 1)
			mine(DP[i], DP[i-2]+abs(T[i]-T[i-2]));
	}
	return DP[n-1];
	
	return -INF;
}

int main() {
	int noOfTests = 1;
	//scanf("%d", &noOfTests);
	
	while(noOfTests --> 0) {
		if(!in()) {
			printf("popsute wejscie\n");
			continue;
		}
		ll result = solve();
		if(result == ll(-'t'))
			printf("TAK\n");
		else if(result == ll(-'n'))
			printf("NIE\n");
		else if(result != -INF)
			printf("%lld\n", result);
	}
	
	return 0;
}


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

int main(){
    int x,n,p,mini = 1000,ans;
    cin >> x >> n;
    vector<bool> num(103,true);
    for(int i = 0; i < n;i++){
        cin >> p;
        num[p + 1] = false;
    }

    for(int i = 0; i < 103;i++){
       if(num[i] == true){
           if(mini > abs(x-(i - 1))){
               mini = abs(x - (i - 1));
               ans = i - 1;
           }
       }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3588
n = int(input())
n1 = n
i = 2
x = []
while i*i <= n:
  while n % i == 0:
    n //= i
    x.append(str(i))
  i += 1
if n > 1:
  x.append(str(n))
print(str(n1) + ": " + " ".join(x))


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;


int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans=n;
    rep(i,n){
        if (i==0) continue;
        if (s[i]==s[i-1]) ans--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
int main() {
	string s, t; cin >> s >> t;
	vector<vector<int>>dir(s.size() + 1, vector<int>(t.size() + 1));
	vector<vector<int>>len(s.size() + 1, vector<int>(t.size() + 1));
	for (int i = 1; i <= s.size(); i++)dir[i][0] = 1;
	for (int i = 1; i <= s.size(); i++) {
		for (int j = 1; j <= t.size(); j++) {
			if (s[i - 1] == t[j - 1]) {
				len[i][j] = len[i - 1][j - 1] + 1; dir[i][j] = 2;
			}
			else {
				if (len[i - 1][j] > len[i][j - 1]) {
					len[i][j] = len[i - 1][j]; dir[i][j] = 1;
				}
				else {
					len[i][j] = len[i][j - 1]; dir[i][j] = 0;
				}
			}
		}
	}
	string ret; int a = s.size(); int b = t.size();
	while (a != 0 || b != 0) {
		switch (dir[a][b]) {
		case 2: {ret = s[a - 1] + ret; a--; b--; break; }
		case 1: {a--; break; }
		default: {b--; break; }
		}
	}
	cout << ret << endl;
	return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define Min(...) min({__VA_ARGS__})
#define Max(...) max({__VA_ARGS__})
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
static inline ll sgn(ll x) { return (x>0)-(x<0); }
static inline bool vowel(char c) { c = (char)tolower(c); return c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u' or c == 'y'; }
static inline vi rvi(int N) { vi res(N); rep(i,0,N) cin >> res[i]; return res; }
static inline int ri() { int N; cin >> N; return N; }
static inline void pvi(const vi& r) { trav(it,r) cout << it << " "; cout << endl; }
template<class S, class T> static inline void smax(S& s, const T& t) { if (t > s) s = t; }
template<class S, class T> static inline void smin(S& s, const T& t) { if (t < s) s = t; }
template<class S> static inline void in(S& s) { cin >> s; }
template<class S> static inline void ut(const S& s) { cout << s << " "; }
static inline void nl() { cout << endl; }

signed main() {
	cin.sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int N;
	cin >> N;
	
	ll ans;
	cin >> ans;
	rep(i,1,N) {
		ll T;
		cin >> T;
		ans = T / __gcd(T, ans) * ans;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import statistics
n = int(input())

a=[0]*n
b=[0]*n

for i in range(n):
    a[i],b[i] = map(int,input().split())

cen_a=statistics.median(a)
cen_b=statistics.median(b)

if n%2==1:
    print(cen_b-cen_a+1)
else:
    print(int((cen_b-cen_a)*2+1))


Measured memory_bytes: 28756
#include <stdio.h>
int main()
{
  int H,W,i, j;
  while(1)
    {
      scanf("%d %d",&H,&W);
      if(H==0 && W==0)break;
      
      for ( i = 0; i < H; i++ ){
	for ( j = 0; j < W; j++ ){
	  if((i>0 && i<H-1) && (j>0 && j<W-1) ){
            printf(".");
	  } else {
            printf("#");
	  }
	}
	printf("\n");
      }
      printf("\n");
    }
  
  return 0;
}

Measured memory_bytes: 572