akhauriyash/Code-Regression huggingface dataset:
// JAI SHREE RAM
#pragma GCC optimize("O3")
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define sec second
#define fir first
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(ll (i)=(m);(i)<(n);(i)++)
// #define all(a) (a).begin(),(a).end()
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define MOD 998244353

void solve()
{

	ll n, k;
	cin >> n >> k;
	if (k == 1) {
		cout << 0 << endl;
		return;
	}
	ll x = n / k + 1 ;
	ll ans1=n-(x-1)*k;
	ll ans2=abs(ans1-k);
	cout<<min(ans1,ans2)<<endl;

}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast
	int T;
	// cin >> T;
	T = 1;
	while (T--)
	{
		solve();
	}
	return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

void Dfs(const int cur, vector<bool> &visited,
         const vector<vector<int>> &adj) {
    visited[cur] = true;
    for (int v : adj[cur]) {
        if (!visited[v]) Dfs(v, visited, adj);
    }
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    // cout << setprecision(8) << setiosflags(ios::fixed);

    int n, m;
    cin >> n >> m;

    vector<vector<int>> adj(n);
    for (int i = 0, x, y, z; i < m; ++i) {
        cin >> x >> y >> z;
        adj[x - 1].push_back(y - 1);
        adj[y - 1].push_back(x - 1);
    }

    vector<bool> visited(n, false);
    int num_comp = 0;
    for (int v = 0; v < n; ++v) {
        if (visited[v]) continue;

        ++num_comp;
        Dfs(v, visited, adj);
    }

    cout << num_comp << endl;

    return 0;
}


Measured memory_bytes: 10496
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

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

if N > K:
    t = N % K
else:
    t = N
print(min(K-t, t))


Measured memory_bytes: 9008
#include <iostream>

using namespace std;

int main(){
    int S;
    cin >> S;
    int h = S / 3600;
    int m = (S - h * 3600) / 60;
    int s = (S - h * 3600) % 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3092
N=int(input())
A=list(map(int,input().strip().split(' ')))
MAx=max(A)
dp=[[-3*max(A)]*N for i in range(N)]
for i in range(N):
    dp[i][i]=A[i]

for length in range(2,len(A)+1):
    for start in range(0,len(A)-length+1):
        left=start
        right=start+length-1
        temp1=0
        temp2=0
        dp[left][right]=max(A[left]-dp[left+1][right],A[right]-dp[left][right-1])
print(dp[0][-1])

Measured memory_bytes: 114140
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int max = 0;
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == 'R'){
                int count = 0;
                for (; i < s.length() && s.charAt(i) == 'R'; i++,count++) ;
                if(max < count){
                    max = count;
                }
            }
        }
        System.out.println(max);
        sc.close();
    }
}

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

int main(){
    int n, m;
    string u;
    set<string> key;

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> u;
        key.emplace(u);
    }

    cin >> m;
    bool locked = true;

    for(int i = 0; i < m; i++){
        cin >> u;
        if(key.count(u)){
            if(locked)  cout << "Opened by " << u << endl;
            else        cout << "Closed by " << u << endl;
            locked = !locked; 
        }else{
            cout << "Unknown " << u << endl;
        }
    }
    return 0;
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  std::string s;
  std::cin >> s;

  int64_t ans = 0;
  int64_t a = 0;
  for (int64_t i = 0; i < static_cast<int64_t>(s.size()) - 1; i++) {
    if (s[i] == 'A') {
      a++;
      continue;
    } else {
      if (a != 0 && s[i] == 'B' && s[i + 1] == 'C') {
        ans += a;
        i++;
      } else {
        a = 0;
      }
    }
  }

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

Measured memory_bytes: 640
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		int Q=sc.nextInt();

		int[][] sta=new int[M][2];

		int[][] hct=new int[N+1][N+1];

		for(int i=0; i<=N; i++) {
			for(int j=0; j<=N; j++) {
				hct[i][j]=0;
			}
		}

		for(int i=0; i<M; i++) {
			sta[i][0]=sc.nextInt();
			sta[i][1]=sc.nextInt();
			hct[sta[i][0]][sta[i][1]]++;
		}

		for(int i=0; i<=N; i++) {
			for(int j=1; j<=N; j++) {
				hct[i][j]=hct[i][j-1]+hct[i][j];
			}
		}

		for(int i=1; i<=N; i++) {
			for(int j=0; j<=N; j++) {
				hct[i][j]=hct[i-1][j]+hct[i][j];
			}
		}

		int s=0; int g=0;
		long ans=0;
		for(int i=0; i<Q; i++) {
			ans=0;
			s=sc.nextInt();
			g=sc.nextInt();

			ans=hct[g][g]-hct[g][s-1]-hct[s-1][g]+hct[s-1][s-1];
			System.out.println(ans);
		}
	}
}

/*

*/

Measured memory_bytes: 163792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
int a[5000][1005];
const int INF=1e9;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<5000;i++)
    {
        for(int j=0;j<=1000;j++)
        {
            if(i==0) a[i][j]=0;
            else a[i][j]=INF;
        }
    }
    for(int i=1;i<=m;i++)
    {
        int c,d;
        cin>>c>>d;
        int t=0;
        for(int j=0;j<d;j++)
        {
            int h;
            cin>>h;
            t+=(1<<(h-1));
        }
        for(int j=0;j<(1<<n);j++)
        {
            a[(j|t)][i]=min(a[j][i-1]+c,a[(j|t)][i]);
            a[j][i]=min(a[j][i],a[j][i-1]);
        }
        //for(int j=0;j<(1<<n);j++)
            //cout<<a[j][i]<<' ';
        //cout<<'\n';
    }
    int ans=INF;
    for(int i=1;i<=m;i++)
    {
        ans=min(ans,a[(1<<n)-1][i]);
        //cout<<a[(1<<n)-1][i]<<'\n';
    }
    if(ans>999999999)
    {
        cout<<"-1"<<'\n';
        return 0;
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 19968
#include <bits/stdc++.h>
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#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 per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef long long int64;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
template<class T,class U>bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>void vcin(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cii(k);
    int64 ans=0;
    function<int64(int64, int64)> gcd = [&gcd](int64 x, int64 y){
        return !y ? x : gcd(y, x % y);
    };
    rep1(i, k){
        rep1(j, k){
            rep1(y, k){
                ans += gcd(gcd(i, j), y);
            }
        }
    }
    co(ans);

    return 0;
}

Measured memory_bytes: 3652
a,b,c,k = map(int, input().split())
ans = 0

if k - a  > 0:
    k = k - a
    ans = ans + (a * 1)
    if k - b > 0:
        k = k - b
        ans = ans + (b * 0)
        if k - c > 0:
            k = k - c
            ans = ans + (c * (-1))
        elif c - k >= 0:
            ans = ans + (k * (-1))
        else:
            ans
    elif b - k >= 0:
        ans = ans + (k * (0))
    else:
        ans
elif a - k >= 0:
    ans = ans + (k * (1))       
else:
    ans

print(ans)  

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<long long int> a(n);
    for(int i = 0 ; i < n ; i++)
        cin >> a[i];
    
    bool flag = false;
    sort(a.begin(),a.end());

    for(int i = 0 ; i < n - 1 ; i++){
        if(a[i] == a[i + 1]){
            flag = true;
            break;
        }
    }
    if(flag == true)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;

    return 0;
}

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);


    int m,n;
    cin>>m>>n;

    int s=0,x;
    loop(i,0,n)
    {
        cin>>x;
        s+=x;
    }

    if(s>=m) cout<< "Yes";
    else cout<< "No";



    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int n, s,sum=0;
	cin >> n;
	vector<int>point(n);
	rep(i, n)cin >> point[i];
	sum = accumulate(all(point), 0);
	sort(all(point));
	if (sum % 10 != 0)cout << sum << endl;
	else {
		rep(i, n) {
			for (int j = i; j < n; j++) {
				if ((sum - point[j]) % 10 != 0) {
					cout << sum - point[j] << endl;
					return 0;
				}
			}
				sum -= point[i];
		}
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  char p = 'P';
  rep(i,n){
    int ii = n-1-i;
    if(s[ii]=='?'){
      s[ii] = p^'P'^'D';
      if(s[ii]=='P' && ii>0 && s[ii-1]=='P') s[ii]='D';
    }
    p = s[ii];
  }
  cout << s << endl;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
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; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0) val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator - () const noexcept {
return val ? MOD - val : 0;
}
constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
constexpr Fp& operator += (const Fp& r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr Fp& operator -= (const Fp& r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr Fp& operator *= (const Fp& r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp& operator /= (const Fp& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
val = val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator == (const Fp& r) const noexcept {
return this->val == r.val;
}
constexpr bool operator != (const Fp& r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0) return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1) t = t * a;
return t;
}
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

mint dp[2020][2020];

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

int N,M;
cin >> N >> M;
vl s(N),t(M);
rep(i,N) cin >> s[i];
rep(i,M) cin >> t[i];


rep(i,2010) {
    dp[i][0] = 1;
    dp[0][i] = 1;
}

rrep(i,N) {
    rrep(j,M) {
        if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j] + dp[i][j-1];
        else dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];
    }
}
cout << dp[N][M] << endl;
return 0;
}

Measured memory_bytes: 31872
#include<bits/stdc++.h>
using namespace std;
 
int main(){
 double A,B;
 cin >> A >> B;
 if(A>B) cout << "GREATER"<<endl;
 else if(A<B) cout << "LESS" << endl;
 else if(A = B) cout << "EQUAL" << endl;
    
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()

    if n < 4:
        return max(a)

    dp = [[-inf] * 3 for _ in range(n)]
    for i in range(3):
        dp[i][i] = a[i]

    for i in range(n):
        c = a[i]
        di = dp[i]
        if i > 1:
            d2 = dp[i-2]
            for j in range(3):
                if di[j] < d2[j] + c:
                    di[j] = d2[j] + c
        if i > 2:
            d3 = dp[i-3]
            for j in range(2):
                if di[j+1] < d3[j] + c:
                    di[j+1] = d3[j] + c
        if i > 3:
            d4 = dp[i-4]
            for j in range(1):
                if di[j+2] < d4[j] + c:
                    di[j+2] = d4[j] + c

    if n % 2 == 0:
        return max(dp[-1][1], dp[-2][0])

    r = -inf
    for i in range(3):
        r = max(r, dp[-1-i][2-i])

    return r

print(main())





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

int main() {
  char ch;
  while(true) {
    scanf("%c", &ch);
    if('a' <= ch && ch <= 'z') {
      ch = ch - 32;
    } else if('A' <= ch && ch <= 'Z') {
     ch = ch + 32;
    }
    printf("%c", ch);
    if(ch == '\n') break;
  }
  return 0;
}


Measured memory_bytes: 2696
#include <math.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <ostream>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

typedef int _lcint;
#define REP(i, n) for (_lcint i = 0; i < n; i++)
#define FOR(i, a, b) for (_lcint i = (_lcint)(a); i < (_lcint)(b); i++)
#define FORREV(i, a, b) for (_lcint i = (_lcint)(b)-1; i >= (_lcint)(a); i--)
#define DEBUG(x) cout << #x << ": " << x << endl;
#define DEBUG_VEC(v)  \
  cout << #v << ": "; \
  REP(i, v.size()) cout << " " << v[i] << endl;

#define ALL(a) (a).begin(), (a).end()
#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = max((a), (b))

// permutation
ll mPn(ll m, ll n) {
  ll a = 1;
  REP(i, n) { a *= m - i; }
  return a;
}

// excrametion
ll exc(ll m) {
  ll a = 1;
  FOR(i, 1, m) { a *= i + 1; }
  return a;
}

// combination
ll mCn(ll m, ll n) {
  ll a = 1, b = 1;
  REP(i, n) {
    a *= m - i;
    b *= n - i;
  }
  return a / b;
}

int main() {
  char S[100001];
  scanf("%s", S);
  int len = strlen(S);
  int countA = 0;
  int countB = 0;

  for (int i = 0; i < len; i++) {
    if (S[i] - '0' != i % 2) {
      countA++;
    }

    if (S[i] - '0' != (i + 1) % 2) {
      countB++;
    }
  }

  cout << min(countA, countB) << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define For(i, l, r) for(register int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define Fordown(i, r, l) for(register int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
   int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}

int h, w;

const int N = 110;
char str[N];
int G[N][N];
int dis[N][N];

int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

int cnt;
int main () {
	cin >> h >> w;
	For (i, 1, h) {
		scanf ("%s", str + 1);
		For (j, 1, w)
			if (str[j] == '.') G[i][j] = 1, ++ cnt;
	}
	queue<pair<int, int> > Q;
	Q.push(make_pair(1, 1));
	while (!Q.empty() ) {
		pair<int, int> u = Q.front(); Q.pop();
		For (i, 0, 3) {
			int xi = u.first + dir[i][0],
				yi = u.second + dir[i][1];
			if (G[xi][yi]) {
				G[xi][yi] = 0;
				dis[xi][yi] = dis[u.first][u.second] + 1;
				Q.push(make_pair(xi, yi));
			}
		}
	}
	if (!dis[h][w]) puts("-1");
	else
	cout << (cnt - dis[h][w] - 1) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < k; i++) {
			int d = Integer.parseInt(sc.next());
			for (int j = 0; j < d; j++) {
				int snack = Integer.parseInt(sc.next());
				a[snack - 1]++;
			}
		}

		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] == 0)
				ans++;
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 32948
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

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

    int n;
    cin >> n;
    vector<int> t = vector<int>(n+1, 0);
    vector<int> x = vector<int>(n+1, 0);
    vector<int> y = vector<int>(n+1, 0);
    for (int i = 1; i <= n; ++i)
    {
        cin >> t[i] >> x[i] >> y[i];
    }

    for (int i = 0; i < n; ++i)
    {
        int dt = t[i+1] - t[i];
        int dxy = abs(x[i+1] - x[i]) + abs(y[i+1] -y[i]);
        if (dxy > dt) 
        {
            cout << "No" << endl;
            return 0;
        }
        else 
        {
            if (dxy % 2 != dt % 2) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>

int main()
{
	long long n;
	char c[25]; int count = 0;
	scanf("%lld", &n);
	while(n != 0)
	{
		n--;
		c[count++] = n % 26 + 'a';
		n /= 26;
	}
	for(int i = count - 1; i >= 0; i--) printf("%c", c[i]);
	return 0;
}

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

int y[3001];

int main()
{
  for (int i = 4; i <= 3000; i += 4){
    y[i] = 1;
  }
  for (int i = 100; i <= 3000; i += 100){
    y[i] = 0;
  }
  for (int i = 400; i <= 3000; i += 400){
    y[i] = 1;
  }
  
  int a, b;
  cin >> a >> b;
  if (a == 0){
    return 0;
  }
  int c = 0;
  for (int i = a; i <= b; i++){
    if (y[i] == 1){
      cout << i << endl;
      c = 1;
    }
  }

  while (1){
    cin >> a >> b;
    if (a == 0){
      break;
    }
    c = 0;
    cout << endl;
    for (int i = a; i <= b; i++){
      if (y[i] == 1){
        cout << i << endl;
        c = 1;
      }
    }
    if (c == 0){
      cout << "NA" << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PipedInputStream;
import java.util.*;

public class Main {
    private static final int MOD = (int) Math.pow(10, 9);
    private static final int[][] DIRS = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        String s = sc.next();
        String t = sc.next();
        int a = sc.nextInt();
        int b = sc.nextInt();
        String u = sc.next();

        if (u.equals(s)) {
            a--;
        } else {
            b--;
        }
        System.out.println(a + " " + b);
        System.exit(0);
    }
    static private class Point {
        public int x;
        public int y;
        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    static private int log2(int x) {
        return (int)(Math.log(x) / Math.log(2));
    }

    static private long gcd(long m, long n) {
        if (m < n) { return gcd(n, m); }
        if (m % n == 0) { return n; }
        return gcd(n, m%n);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try{
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
int N;
cin>>N;
N=N%10;
if(N==2||N==4||N==5||N==7||N==9){
  cout<<"hon"<<endl;
}
if(N==0||N==1||N==6||N==8){
  cout<<"pon"<<endl;
}
if(N==3){
  cout<<"bon"<<endl;
}
}

Measured memory_bytes: 3636
#include <cstdio>

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

	int ac = 0;
	int wa = 0;
	int tle = 0;
	int re = 0;

	char s[5];
	int i;
	for (i = 0; i < n; i++) {
		scanf("%s", s);
		if (s[0] == 'A')
			ac++;
		else if (s[0] == 'W')
			wa++;
		else if (s[0] == 'T')
			tle++;
		else if (s[0] == 'R')
			re++;
	}

	printf("AC x %d\n",  ac );
    printf("WA x %d\n",  wa );
    printf("TLE x %d\n", tle);
    printf("RE x %d\n",  re );

	return 0;
}

Measured memory_bytes: 1728
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#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 PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int A, B;

	cin >> A >> B;

	cout << max(A+B,max(A-B,A*B)) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    
    int N, M;
    cin >> N >> M;
    vector<P> e(M);
    rep(i,M) cin >> e[i].second >> e[i].first;

    sort(e.begin(), e.end());
    int now_x = e[0].first - 1;
    int ans = 1;
    for (int i = 1; i < M; i++) {
        if (e[i].second > now_x) {
            ans++;
            now_x = e[i].first - 1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
n = int(input())
w = [input() for _ in range(n)]

res = 'Yes'
temp = []
tail = w[0][0]
for word in w:
    if word in temp:
        res = 'No'
        break

    temp.append(word)

    if tail != word[0]:
        res = 'No'
        break

    tail = word[-1]

print(res)

Measured memory_bytes: 3316
N, M = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(N)]
cd = [list(map(int, input().split())) for i in range(M)]

for a, b in ab:
    tmp = []
    for c, d in cd:
        tmp.append(abs(a-c) + abs(b-d))
    n = min(tmp)
    print(tmp.index(n)+1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define itn int
//#define fi first
//#define se second
#define be begin()
#define en end()
#define reverse
const int mod=1000000007;
const int INFi=2147483647;
const long long INFl=9223372036854775807LL;
template<typename T> T abs(T a,T b){
  return max(a,b)-min(a,b);
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,k,sum=0;
  cin>>a>>b>>c>>k;
  if(a>=k){
    sum=k;
    k=0;
  }
  else{
    sum=a;
    if(k-a-b>0) sum-=(k-a-b);
  }
  cout<<sum<<"\n";
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll a, b;
  cin >> a >> b;

  cout << a * b << ln;

  return 0;
}

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

int main() {

    string s;
    cin >> s;

    bool ok = true;
    for(int i=0; i < s.length(); i+=2){
        if(s[i] != 'h' || s[i+1] != 'i'){
            ok = false;
        }
    }

    if(ok){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
# coding=utf-8

abc = [int(i) for i in input().split()]

counter = 0

while not abc[0] == abc[1] == abc[2]:
    abc = sorted(abc)
    
    if abc[1] == abc[2]:
        abc[0] += 2
        counter += 1
    else:
        abc[0] += 1
        abc[1] += 1
        counter += 1

print(counter)


Measured memory_bytes: 3060
S = input()
c = 0
c2 = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == '0':
            c += 1
        else:
            c2 += 1
    elif i % 2 == 1:
        if S[i] == '1':
            c += 1
        else:
            c2 += 1
print(min(c, c2))

Measured memory_bytes: 39664
const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {

    const lines = input.split('\n')
    const S = lines[0]

    if (S[2] === S[3] && S[4] === S[5]) {
        console.log('Yes')
    } else {
        console.log('No')
    }

})(input)


Measured memory_bytes: 30536
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <utility>
using namespace std;

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

    int s = accumulate(a.begin(), a.end(), 0);
    int bestd = 100 * n;
    int result = 0;
    for (int i = 0; i < n; ++i) {
        int d = abs(a[i] * n - s);
        if (d < bestd) {
            result = i;
            bestd = d;
        }
    }

    cout << result << endl;
}


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

int main() {
	int N;
    cin >> N;
    int a = N/1000;
    int b = (N-a*1000)/100;
    int c = (N-a*1000-b*100)/10;
    int d = N%10;
    int count = 0;
    if(a==2){
      count++;
    }
    if(b==2){
      count++;
    }
    if(c==2){
      count++;
    }
    if(d==2){
      count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
# 直感的に分かる貪欲（下から組を作る）だと思うんだけど、これでdiff1185は数字が高すぎじゃない? 
# 貪欲で取っていくのを考えると、非ゼロの区間が連続する場合、その連続に対して下からペアを作って、最後に0か1だけ残ることがわかり、
# 単純に書ける。こんなふうに。

n = int(input())
nums = [int(input()) for _ in range(n)]

ans = 0
temp = 0
for m in nums:
    if m == 0:
        ans += temp // 2
        temp = 0
    else:
        temp += m
ans += temp // 2
print(ans)


Measured memory_bytes: 7072
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int X, Y, Z;
  cin>>X>>Y>>Z;
  swap(X, Y);
  swap(X, Z);
  cout<<X<<" "<<Y<<" "<<Z<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a[10000], min, max, n, i;
    
    long long sum = 0;
    scanf("%d", &n);//1以上が入力されるものとします
    for(i = 0; i < n; i++){
        scanf("%d", &a[i]);
        sum += a[i];
    }
    max = min = a[0];//とりあえず最初の要素をセットしておく
    for(i = 1; i < n; i++){//2番目以降の要素と比較
        if(a[i] > max)max = a[i];
        if(a[i] < min)min = a[i];
    }
    
    printf("%d %d %lld\n", min, max, sum);
   
    return 0;
}



Measured memory_bytes: 3248
# -*- coding: utf-8 -*-
import itertools
N, K = map(int, input().split())
a = [0] * (N+1)
for i in range(N+1):
  a[i] = i

max_total = 0
min_total = 0
ans = 0
for k in range(K, N+2):
  # 和の最大(10**100 は無視): 大きい順にk個選んだ場合
  max_total = k * ((N-k+1) + N) // 2

  # 和の最小(10**100 は無視): 小さい順にk個選んだ場合
  min_total = k * (0 + (k-1)) // 2

  # 最小と最大の間は全パターン取り得るので差が個数になる
  ans += (max_total - min_total + 1)

print(ans % (10**9 + 7))

Measured memory_bytes: 65496
def factorize(n):
    a = 2
    fct = []
    while a * a <= n:
        while n % a == 0:
            n //= a
            fct.append(a)
        a += 1
    if n > 1:
        fct.append(n)
    return fct


a, b = map(int, input().split())
print(len(set(factorize(a)) & set(factorize(b))) + 1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int x,y,z,mx,a,b;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>a>>b;
    x = a+b;
    y = a-b;
    z = a*b;
    mx = x;
    mx = max(mx,y);
    mx = max(mx,z);
    cout<<mx<<newl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
const int D = 60;
ll to[D][200005];

signed main(){
	//cout << fixed << setprecision(10);
	rep(i,0,100100){
		int n; cin>>n;
		int m; cin>>m;
		if(n==0 && m==0)return 0;
		if(n>m)swap(n,m);
		cout<<n<<" "<<m<<endl;
	}

	return 0;
}


Measured memory_bytes: 3020
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, a[10] = {}, c[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}, d[10004] = {};
    cin >> n >> m;
    for (int i = 0; i < m; i++) cin >> a[i];
    sort(a, a + m); reverse(a, a + m);
    for (int i = 1; i <= n; i++) {
        d[i] = -10004;
        for (int j = 0; j < m; j++) if (i >= c[a[j]]) d[i] = max(d[i], d[i - c[a[j]]] + 1);
    }
    while (n) {
        for (int i = 0; i < m; i++) if (n >= c[a[i]] && d[n - c[a[i]]] + 1 == d[n]) {
            cout << a[i];
            n -= c[a[i]];
            break;
        }
    }
}


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

int main() {
   string t;
   cin >> t;
   rep(i, t.size()){
      if(t[i] == '?'){
         t[i] = 'D';
      }
   }
   int ans = 0;
   /**rep(i, t.size()){
      if(i < t.size()-1){
         if(t[i] == 'P' && t[i+1] == 'D'){
            ans++;
         }
         if(t[i] == 'D'){
            ans++;
         }
      }
   }**/
   cout << t << endl;
   return 0;
}

Measured memory_bytes: 3748
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
long long solve(vector<string> S) {
	int H = S.size(), W = S[0].size();
	vector<vector<int> > sum(H + W - 1, vector<int>(H + 1));
	for (int i = 0; i <= H + W - 2; ++i) {
		for (int j = 0; j < H; ++j) {
			sum[i][j + 1] = sum[i][j] + (0 <= i - j && i - j < W && S[j][i - j] == '#' ? 1 : 0);
		}
	}
	long long ans = 0;
	for (int i = 0; i <= H + W - 2; ++i) {
		for (int j = i + 2; j <= H + W - 2; j += 2) {
			int B = (j - i) / 2;
			for (int k = 0; k < H - B; ++k) {
				if (i - k >= W || i - k - B < 0 || S[k][i - k] == '.' || S[k + B][i - k - B] == '.') continue;
				int llim = max(k + B, j - W + 1);
				int rlim = min({ k + 2 * B, H - 1, j }) + 1;
				ans += (sum[j][rlim] - sum[j][llim]) * 2;
				ans -= (0 <= j - (k + B) && j - (k + B) < W && S[k + B][j - (k + B)] == '#' ? 1 : 0);
				ans -= (k + 2 * B < H && 0 <= j - (k + 2 * B) && j - (k + 2 * B) < W && S[k + 2 * B][j - (k + 2 * B)] == '#' ? 1 : 0);
			}
		}
	}
	return ans;
}
vector<string> rotate(vector<string> S) {
	int H = S.size(), W = S[0].size();
	vector<string> ans(W, string(H, '?'));
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			ans[j][H - i - 1] = S[i][j];
		}
	}
	return ans;
}
int main() {
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	for (int i = 0; i < H; ++i) {
		cin >> S[i];
	}
	long long ans = 0;
	for (int i = 0; i < 4; ++i) {
		ans += solve(S);
		S = rotate(S);
	}
	cout << ans / 2 << endl;
	return 0;
}

Measured memory_bytes: 1228
#include <stdio.h>

#define INFTY 2000000000
#define A 500000

void m1(int[],int,int,int,int);
void m2(int[],int,int,int);

int L[A/2+2],R[A/2+2];
int q;

int main(){
  int n,S[500000],i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  m2(S,n,0,n);

  for(i=0;i<n;i++){
    if(i>0)printf(" ");
    printf("%d",S[i]);
  }
  printf("\n");
  printf("%d\n",q);

  return 0;
}

void m1(int S[],int n,int l,int m,int r){
  int n1,n2,i,j,k;
  
  n1 = m-l;
  n2 = r-m;

  for(i=0;i<n1;i++){
    L[i]=S[l+i];
  }

  for(i=0;i<n2;i++){
    R[i]=S[m+i];
  }

  L[n1]=INFTY;
  R[n2]=INFTY;

  i=0;
  j=0;

  for(k=l;k<r;k++){
    q++;
    if(L[i] <= R[j]){
      S[k]=L[i];
      i=i+1;
    }else{
      S[k]=R[j];
      j=j+1;
    }
  }
}

void m2(int S[],int n,int l,int r){
  int m;
  
  if(l+1 < r){
    m = (l+r)/2;
    m2(S,n,l,m);
    m2(S,n,m,r);
    m1(S,n,l,m,r);
  }
}
    
    
  



Measured memory_bytes: 5604
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
using namespace std;
#define ll long long int
int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if ( k % 2 == 1 ) cout << - a + b << endl;
  else cout << a - b << endl;  
  return 0;
}


Measured memory_bytes: 384
// Problem : A - ABC Swap
// Contest : AtCoder Beginner Contest 161
// URL : https://atcoder.jp/contests/abc161/tasks/abc161_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

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


Measured memory_bytes: 764
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n;
    cin >> n;
    vi a(n+1);
    rep(i, n) {
        cin >> a[i+1];
    }
    int cou = 0;
    for(int i=n; i>0; --i) {
        int i_ = i;
        i_ += i;
        int sum = 0;
        while(i_ <= n) {
            sum += a[i_];
            i_ += i;
        }
        if((sum & 1) != a[i]) {
            a[i] = 1;
            cou++;
        } else {
            a[i] = 0;
        }
    }

    cout << cou << endl;

    rep(i, n+1) {
        if(a[i]) {
            cout << i << ' ';
        }
    }
    cout << endl;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, K;
    ll mini = LONG_LONG_MAX;
    vector<ll> h;
    cin >> N >> K;
    h.resize(N);
    rep(i, N) cin >> h[i];
    sort(h.begin(), h.end());
    rep2(i, K - 1, N) mini = min(mini, h[i] - h[i - K + 1]);
    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 1024
/* Author : tushar3105 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef pair<long long int,long long int> ii;					// Pair of integers
typedef vector<long long int> vi;                   				// Vector of integers
typedef vector<vector<long long int>> vvi;                 			// Vector of vi
typedef vector<pair<long long int, long long int>> vii;				// Vector of ii

#define pb push_back								// Push back to vectors
#define mp make_pair								// For pairs
#define ff first								// For pairs
#define ss second								// For pairs
#define all(c) (c).begin(),(c).end()						// Use in sorting
#define sz(a) ((long long int)(a).size())
#define lli long long int
#define ull unsigned long long int
#define ld long double
#define ref(i,x,y) for(long long int i=(x);i<=(y);++i)				// Loop to go forward
#define reb(i,x,y) for(long long int i=(x);i>=(y);--i)				// Loop to go backward
#define trf(c,it) for(auto it = (c).begin(); it != (c).end(); it++)		// Remember it is an iterator
#define trb(c,it) for(auto it = (c).end()-1; it != (c).begin()-1; it--)		// Remember it is an iterator
#define tc(t) long long int (t); cin>>(t);while((t)--)				// Test cases
//fill (dist,dist+110000,pinf);							// For setting default

const long long int mod = 1e9+7;
const long long int pinf = 9223372036854775807;
const long long int ninf = -9223372036854775807;

/*-----------------------------Code begins----------------------------------*/

int main (void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	lli n1,n2,m,x,c[15], a[15][15], minc=pinf;
	
	cin>>n1>>m>>x;
	
	for (int i=0;i<n1;i++)
	{
		cin>>c[i];
		
		for (int j=0;j<m;j++)
			cin>>a[i][j];
	}
	
	for (lli n2=0;n2<pow(2,n1);n2++)
	{	
		lli n=n2;
		lli res[15]={0};
		lli binaryNum[15]={0}; 
		lli i = 0; 
		lli cst=0;
		//cout<<n<<endl;

		while (n>0)
		{ 
			binaryNum[i]=n%2; 
			n=n/2;
			i++;
			//cout<<n<<endl;
		} 
  
		for (int j = i - 1; j >= 0; j--) 
		{
			if (binaryNum[j]==1)
			{
				cst=cst+c[j];
				
				for (int l=0;l<m;l++)
					res[l]=res[l]+a[j][l];				
			}
		}
		
		int flag=0;
		
		for (int l=0;l<m;l++)
			if (res[l]<x)
				flag++;
				
		if (flag==0)
			minc=min(minc,cst);
	}
	
	if (minc==pinf)
		minc=-1;
	
	cout<<minc<<endl;

	return 0;
}


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

void Main()
{
	int n, d;
	cin >> n >> d;
	vector<ll> x(n);
	vector<ll> y(n);
	vector<long double> p(n);
	rep(i, n) {
		cin >> x[i] >> y[i];
	}
	int ans = 0;
	rep(i, n) {
		p[i] = sqrt(x[i]*x[i] + y[i]*y[i]);
		if (p[i] <= d) {
			ans++;
		}
	}
	cout << ans << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 9532
#include<iostream>
using namespace std;
int a[100007];
int main(){
	int n;
	int m[2]={100007,0};
	bool s=false;
	int i,j,k;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
		if(a[i]<m[0])m[0]=a[i];
		if(m[1]<a[i])m[1]=a[i];
	}
	if(m[0]==m[1]){
		if(n>=a[0]*2 || n==a[0]+1)s=true;
	}
	if(m[1]-m[0]==1){
		for(i=0,k=0;i<n;i++){
			if(a[i]==m[0])k++;
		}
		if(n-k>1){
			j=k+(n-k)/2;
			if(k+1<=m[1] && m[1]<=j)s=true;
		}
	}
	if(s)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}
	


Measured memory_bytes: 640
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int x=sc.nextInt();
        int y=sc.nextInt();
        int[] ans=new int[n-1];
        int tmp;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                tmp=Math.min(j-i, Math.abs(i+1-x)+Math.abs(j+1-y)+1);
                ans[tmp-1]++;
            }
        }
        for(int i=0;i<n-1;i++){
            System.out.println(ans[i]);
        }
    }
    
}


Measured memory_bytes: 23636