akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
const ll mod=1000000007;

main(){
  ll x,k,d;cin >> x >> k >> d;
  x=abs(x);
  ll straight = min(k,x/d);
  k-=straight;
  x-=straight*d;
  if(k%2 == 0){
    cout << x << endl;
  } else {
    cout << d-x << endl;
  }
}




Measured memory_bytes: 3576
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	int N;
	cin >> N;
	vint A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	for (int i = 0; i < A.size()-1; i++) {
		if (A[i] == A[i + 1]) {
			A.erase(A.begin() + i);
			i--;
			N--;
		}
	}

	if (N <= 2) {
		cout << 1;
		return 0;
	}

	bool plus = (A[0] < A[1]);
	int ans = 1;
	for (int i = 0; i < N-1; i++) {

		bool local = (A[i] < A[i + 1]);

		if (plus != local) {
			ans++;
			if (i + 2 < A.size()) {
				plus = (A[i + 1] < A[i + 2]);
			}
			else {
				break;
			}
		}

	}

	cout << ans;




}


Measured memory_bytes: 640
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

signed main()
{
    int n,k,gcd=0;  cin>>n>>k;
    int a[n+1]; 
    for (int i=1;i<=n;i++) cin >> a[i] ; 
    sort(a+1,a+n+1);
    if (k<=a[1]) gcd=__gcd(gcd,a[1]-k);
    if (k>=a[n]) gcd=__gcd(gcd,k-a[n]);
    for (int i=1;i<n;i++){
        if (k >= a[i] and k<=a[i+1]) {
            gcd=__gcd(gcd,k-a[i]);
            gcd=__gcd(gcd,a[i+1]-k);
        }
        else gcd=__gcd(gcd,a[i+1]-a[i]);
    }
    cout << gcd << endl;
    return 0;
}


Measured memory_bytes: 4384
#include<stdio.h>
int main(void)
{
  int N,i,j,x,y,MOD,A[200000]={0},check[200000]={},move[200000]={0};
  long long K;
  x=scanf("%d %lld",&N,&K);
  for(i=0;i<N;i++)x=scanf("%d",&A[i]),check[i]=-1;
  for(i=0,j=0;;i=A[i]-1,j++)if(check[i]<0)check[i]=j,move[j]=i;else{x=j-1,y=check[i],MOD=j-check[i];break;}
  if(K>x)K=(K-y)%MOD+y;
  printf("%d\n",move[K]+1);
}

Measured memory_bytes: 4040
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <set>

#define NUM_OF_ALPHA 26

char s[27];
int used_alpha;

void next(){
  used_alpha = 0;
  int len = strlen(s);
  if(len != NUM_OF_ALPHA){
  	for(int i = 0; i < len; i++) {
      used_alpha |= (1 << (s[i]-'a'));
    }
    for(int i = 0; i < NUM_OF_ALPHA; i++) {
      if((used_alpha & (1 << i)) == 0) {
        s[len] = 'a' + i;
        s[len + 1] = 0;
        break;
      }
    }
  } else {
    int i;
    for(i = len - 2; i >= 0; i--) {
      if(s[i] < s[i + 1]){
        for(int k = 0; k < i; k++){
          used_alpha |= (1 << (s[k]-'a'));
        }
        for(int k = 0; k < NUM_OF_ALPHA; k++) {
          if((used_alpha & (1 << k)) == 0 && k > (s[i] - 'a')) {
            s[i] = 'a' + k;
            s[i + 1] = 0;
            break;
          }
        }
        break;
      }
    }
    if(i < 0){
      s[0] = '-';
      s[1] = '1';
      s[2] = 0;
    }
  }
}

int main(){
  scanf("%s", s);
  next();
  printf("%s\n", s);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <sstream>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <climits>
#include <ctype.h>
using namespace std;

#define PI acos(-1.0)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second

#define eps 1e-8
#define mod 998244353

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int>> vvi;

struct Matrix {
    vvi data;
    int r, c;
    Matrix(int row, int col, bool identity = false) : r(row), c(col) {
        data.assign(row, vector<int>(col, 0));
        if (identity) {
            for (int i = 0; i < r; ++i) {
                data[i][i] = 1;
            }
        }
    }
    Matrix operator * (Matrix& other) {
        int m = r, n = c, p = other.c;
        Matrix res(m, p);
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < p; ++j) {
                for (int k = 0; k < n; ++k) {
                    res.data[i][j] += data[i][k] * other.data[k][j];
                }
            }
        }
        return res;
    }
};

// 扩展欧几里得算法 res[1] * a + res[2] * b = res[0] = gcd(a, b)
vector<int> extendGcd(int a, int b) {
    if (b == 0) {
        return {a, 1, 0};
    } else {
        vector<int> tmp = extendGcd(b, a % b);
        return {tmp[0], tmp[2], tmp[1] - (a / b) * tmp[2]};
    }
}

// 矩阵快速幂
Matrix matrix_power(Matrix base, ll exp) {
    int n = base.r;
    Matrix res(n, n, true);
    while (exp) {
        if (exp & 1) {
            res = res * base;
        }
        base = base * base;
        exp >>= 1;
    }
    return res;
}

// 带模快速幂
ll power_mod(ll base, int exp) {
    ll res = 1;
    while (exp) {
        if (exp & 1) res = res * base % mod;
        base = base * base % mod;
        exp >>= 1;
    }
    return res;
}

// 快速幂
ll power(ll base, int exp) {
    ll res = 1;
    while (exp) {
        if (exp & 1) res *= base;
        base *= base;
        exp >>= 1;
    }
    return res;
}

// 求逆元
ll inv(ll a) {
    return power_mod(a, mod - 2);
}

#define MAXFAC 100010

ll fac[MAXFAC];

void initFac() {
    fac[0] = 1;
    for (int i = 1; i < MAXFAC; ++i) {
        fac[i] = i * fac[i - 1] % mod;
    }
}

ll Combine(ll a, ll b) {
    return (fac[a] * inv(fac[b]) % mod) * inv(fac[a - b]) % mod;
}

/******************************** template ********************************/
#define MAXN 100010
int n;
int a[MAXN];

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
    }
    int res = 0;
    for (int i = 1; i < n; ++i) {
        if (a[i] == i) {
            swap(a[i], a[i + 1]);
            ++res;
            ++i;
        }
    }
    if (a[n] == n) ++res;

    cout << res;

    return 0;
}

Measured memory_bytes: 640
#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;
 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
 
vector <ll> v;
 
ll fep(ll x, ll y, ll mod)
{ll res=1;while(y>0){if(y&1)res=(res*x)%mod;
    y=y>>1;x=(x*x)%mod;}return res%mod;}
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
 
	ll n,i,m,j,k,x,y,a,b,c,d,t,r;
	string s;
	
	cin >> r;
	cout << 2*3.1415*r;
 
	return 0;
}

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


int64_t soinbun(int64_t x,int64_t N){
  int64_t n=2;
  int64_t count=0;
  int64_t ans=1;
  while(x>=n*n){
    if(x%n==0){
      x/=n;
      count++;
      if(count==N){
        ans*=n;
        count=0;
      }
    }else{
      n++;
      count=0;
    }
  }
  if(x==n){
    if(count+1==N){
      ans*=n;
    }
  }else{
    if(N==1){
      ans*=x;
    }
  }
  return ans;
}

int main(){
  int64_t N,P;
  cin >> N >> P;
  cout << soinbun(P, N) << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define foru(i,a,b) for (long long i=(a);i<=(b);++i)
#define forn(i, a,b) for (int i = (a); i < (b); i++)
#define rep(i,n) for (int i=0;i<n;++i)
#define forl(i,a,b) for (int i=(a);i>=(b);--i)
#define bug(x) cerr << #x << " = " << x << endl
#define pb push_back
#define mp make_pair
#define bit(s,i) (((s)&(1<<(i)))>0)
#define two(x) (1<<(x))
#define fi first
#define se second
#define sz(x) ((int)x.size())
ll n,a[100002],l[100002],m[100002];

main()
{
    ios_base::sync_with_stdio(0);
    cin >> n;
    foru(i,1,n) cin >> a[i];
    sort(a+1,a+n+1);
    l[1]=a[1];
    foru(i,2,n) l[i]=__gcd(l[i-1],a[i]);
    m[n]=a[n];
    forl(i,n-1,1)
    {
        m[i]=__gcd(m[i+1],a[i]);
    }
    ll re=INT_MIN;
    l[0]=0;
    m[n+1]=0;
    foru(i,1,n)
    {
        re=max(re,__gcd(l[i-1],m[i+1]));
    }
    cout << re;
}


Measured memory_bytes: 2560
object Main {

    def main(args: Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val n = sc.nextInt

        for( i <- 3 to n ) {
            if( i%3 == 0 || i.toString.contains("3") ) print(" " + i )
        }
        print("\n")
    }

}


Measured memory_bytes: 49440
// https://atcoder.jp/contests/dp/tasks/dp_d

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mod 1000000007
#define gcd __gcd
#define inf INT_MAX
#define INF LLONG_MAX
#define minf INT_MIN
#define MINF LLONG_MIN
#define pb push_back
#define all(v) v.begin(),v.end()
#define print(v) for(auto x:v) cout<<x<<" "; cout<<"\n";
#define printn(v) for(auto x:v) cout<<x<<"\n";
#define F first
#define S second
#define mp make_pair

ll dp[101][100001];
vector<int>wt, val;

//Recursive dp
ll knapsack_recursive(int n, int w) {
	if (n == 0 || w == 0) return 0;

	if (dp[n][w] != -1) return dp[n][w];

	if (wt[n] > w) return dp[n][w] = knapsack_recursive(n - 1, w);
	else return  dp[n][w] = max(val[n] + knapsack_recursive(n - 1, w - wt[n]), knapsack_recursive(n - 1, w));
}

ll knapsack_iterative(int n, int w) {
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= w; j++) {
			if (wt[i] > j) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = max(val[i] + dp[i - 1][j - wt[i]], dp[i - 1][j]);
		}
	}
	return dp[n][w];
}

int32_t main() {
	fastio;
	int n, w;
	cin >> n >> w;
	// memset(dp, -1, sizeof dp);
	wt.resize(n + 1, 0);
	val.resize(n + 1, 0);
	for (int i = 1; i <= n; i++) cin >> wt[i] >> val[i];
	cout << knapsack_iterative(n, w) << endl;
}

Measured memory_bytes: 81684
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>

double distance(const std::pair<double, double>& st,
		const std::pair<double, double>& ed){
  double y = ed.second - st.second;
  double x = ed.first - st.first;
  return std::sqrt(x*x + y*y);
}

double calc_total_distance(const std::vector<std::pair<double, double> >& pts,
			   const std::vector<int>& v){
  double total = 0;
  for(int i=1; i<v.size(); i++){
    auto st = pts[v[i-1]];
    auto ed = pts[v[i]];
    total += distance(st, ed);
  }
  return total;
}

int main(void){

  int n;
  std::cin >> n;
  std::vector<std::pair<double, double> > pts(n);
  std::vector<int> v(n);
  for(int i=0; i<n; i++){
    v[i] = i;
  }

  for(int i=0; i<n; i++){
    std::cin >> pts[i].first >> pts[i].second;
  }

  double total = 0;
  int count = 0;
  do{
    total += calc_total_distance(pts, v);
    count++;
  }while(std::next_permutation(v.begin(), v.end()));

  std::printf("%.10lf\n", total / count);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
 
 
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    if(n%k==0)printf("0\n");
    else printf("1\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cout << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(void) {}
  Edge(int src, int dst) : src(src), dst(dst) {}
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void edges_to_graph(Graph &graph, const Edges &edges, const int vertices, const bool directed = true) {
  graph.clear(), graph.resize(vertices);
  for (const auto &e : edges) graph[e.src].emplace_back(e);
  if (!directed) for (const auto &e : edges) graph[e.dst].emplace_back(Edge(e.dst, e.src, e.weight));
}

void dfs(Graph &g, int v, int p, int prev_col, vector<vector<int>> &cv) {
  int col = 0;
  for (const auto &e : g[v]) {
    if (e.dst == p) continue;
    ++col;
    if (col == prev_col) ++col;
    cv[v][e.dst] = col;
    dfs(g, e.dst, v, col, cv);
  }
}

void bfs(Graph &g, map<pair<int, int>, int> &cmap) {
  queue<tuple<int, int, int>> que;
  que.push(make_tuple(0, -1, 0));
  while (!que.empty()) {
    int v = get<0>(que.front()), p = get<1>(que.front()), pc = get<2>(que.front());
    que.pop();
    int col = 1;
    for (const auto &e : g[v]) {
      if (e.dst == p) continue;
      if (col == pc) ++col;
      cmap[{ v, e.dst }] = cmap[{ e.dst, v }] = col;
      que.push(make_tuple(e.dst, v, col));
      ++col;
    }
  }
}

Graph graph;
int main(void) {
  int n;
  cin >> n;
  Edges edges(n - 1);
  rep (i, n - 1) {
    int a, b;
    cin >> a >> b;
    edges[i] = {--a, --b, 0};
  }
  edges_to_graph(graph, edges, n, false);
  int maxi = 0;
  rep (i, n) maxi = max(maxi, (int)graph[i].size());
  // cv.assign(n, vector<int>(n));
  map<pair<int, int>, int> cmap;
  // dfs(graph, 0, -1, 0, cv);
  bfs(graph, cmap);
  cout << maxi << "\n";
  rep (i, n - 1) cout << cmap[{ edges[i].src, edges[i].dst }] << "\n";
  return 0;
}

Measured memory_bytes: 20736
///  http://arc069.contest.atcoder.jp/tasks/arc069_c

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

int maxim[100010];
map <int, int> nr; /// pt a afla cate sunt >= x
map <int, long long> suma; /// suma ca toate cele >= x sa devina x
int v[100010];

int main()
{
    nr[0] = 0;
    int n;
    cin >> n;

    for (int i(1); i <= n; i++) {
        cin >> v[i];
        maxim[i] = max(maxim[i - 1], v[i]);
        nr[v[i]]++;
    }

    int mari(0), last = 1e9;
    for (reverse_iterator <map <int, int> :: iterator> it = nr.rbegin(); it != nr.rend(); it++) {
        suma[it->first] = suma[last] + 1ll * mari * (last - it->first);
        it->second += mari;
        mari = it->second;
        last = it->first;
    }

    for (int i(1); i <= n; i++) {
        if (maxim[i - 1] < v[i])
            cout << suma[maxim[i - 1]] - suma[v[i]] << '\n';
        else
            cout << "0\n";
    }

    return 0;
}


Measured memory_bytes: 12800
n, a, b = map(int, input().split())
h_s = [int(input()) for _ in range(n)]

l = (min(h_s) - 1) // a + 1
r = (max(h_s) - 1) // b + 1

c = a - b
while l != r:
    pos = (l + r) // 2
    cnt = 0
    base = b * pos
    for h in h_s:
        rem = h - base
        cnt += max(0, (rem - 1) // c + 1)
    if cnt <= pos:
        r = pos
    else:
        l = pos + 1
print(r)


Measured memory_bytes: 13032
#include <iostream>
using namespace std;
int main(){

  int ab[1000]={},n,a,b,r=0;
  cin>>a>>b>>n;
  for(int i=a;i<b;i++) ab[i]++;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    for(int i=a;i<b;i++) ab[i]++;
  }
  for(int i=0;i<1000;i++) if(ab[i]>1) r++;
  if(r) cout<<1<<endl;
  else cout<<0<<endl;


}



Measured memory_bytes: 3100
#include <iostream>

using namespace std;

int main(){
    int H, W;
    cin >> H >> W;
    char C[H][W+1];
    for(int i = 0; i < H; i++){
        cin >> C[i];
    }

    for(int i = 0; i < H; i++){
        cout << C[i] << endl;
        cout << C[i] << endl;
    }


    return 0;
}

Measured memory_bytes: 256
n=int(input())
s=[''.join(sorted(input())) for i in range(n)]
an={}
count=0
for i in range(n):
    if s[i] not in an:
        an[s[i]]=1
    else:
        an[s[i]]+=1
        count+=an[s[i]]-1
print(count)

Measured memory_bytes: 19400
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int main(){
    fastio
    int n , m ;
    cin >> n >> m ; 
    char g[n][m] ;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> g[i][j] ; 
        }
    }
    int ans = 0 ;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if ( g[i][j] == '.' ){
                int dist[n][m] ;
                memset(dist, -1, sizeof dist);
                queue<pair<int,int> > q; 
                q.push(make_pair(i, j));
                dist[i][j] = 0 ; 
                while(not q.empty()){
                    auto f = q.front(); q.pop() ;
                    int x = f.first ; 
                    int y = f.second ; 
                    if ( x + 1 < n && g[x + 1][y] != '#' && dist[x + 1][y] == -1 ){
                        q.push(make_pair(x + 1, y)) ; 
                        dist[x + 1][y] = dist[x][y] + 1;
                        ans = max(ans, dist[x + 1][y]);
                    }
                    if ( x - 1 >= 0 && g[x - 1][y] != '#' && dist[x - 1][y] == -1 ){
                        q.push(make_pair(x - 1, y)) ; 
                        dist[x - 1][y] = dist[x][y] + 1;
                        ans = max(ans, dist[x - 1][y]);
                    }
                    if ( y - 1 >= 0 && g[x][y - 1] != '#' && dist[x][y - 1] == -1 ){
                        q.push(make_pair(x, y - 1)) ; 
                        dist[x][y - 1] = dist[x][y] + 1;
                        ans = max(ans, dist[x][y - 1]);
                    }
                    if ( y + 1 < m && g[x][y + 1] != '#' && dist[x][y + 1] == -1 ){
                        q.push(make_pair(x, y + 1)) ; 
                        dist[x][y + 1] = dist[x][y] + 1;
                        ans = max(ans, dist[x][y + 1]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 256
using System;
using System.Linq;
 
class abc124_B
{
    static void Main(string[] args)
    {
        var QN = int.Parse(Console.ReadLine());
        var QHs = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
 
        var lastHeight = 0;
        var cansee = 0;
        for(var i=0; i<QN; i++) {
            if(lastHeight <= QHs[i]) {
                cansee++;
                lastHeight = QHs[i];
            }
        }
        Console.WriteLine(cansee);
 
    }
}

Measured memory_bytes: 13268
K, N = map(int, input().split())
A = list(map(int, input().split()))

max_distance = 0
for i in range(N):
    if i == N - 1:
        distance = A[0] - A[N - 1] + K
    else:
        distance = A[i + 1] - A[i]

    if distance > max_distance:
        max_distance = distance

print(K - max_distance)


Measured memory_bytes: 26444
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d;
int main(){
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	printf("%lld",max(max(max(a*c,a*d),b*c),b*d));
	return 0;
}

Measured memory_bytes: 3828
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B
  * Structured Program II - How many ways?
  */
object Main {
  def main(args: Array[String]): Unit = {
    val dataSets = Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).map(_.split(" ").map(_.toInt))
      .map { case Array(n, x) => (n, x) }
      .takeWhile(_ != (0, 0))
      .toList
    val results = dataSets.map { case (n, x) =>
      // Memory Limit Exceeded
      // (1 to n).combinations(3).count(_.sum == x)
      (for (a <- 1 to n - 2;
            b <- a + 1 to n - 1 if a < b;
            c <- b + 1 to n if a < c && b < c && (a + b + c) == x)
        yield 1).length
    }
    results.foreach(println)
  }

}

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

using namespace std;
 
int main() {

	int n;
	cin>>n;

	int mod = (1e9)+7;

	vector<int> A(n+1);
	for(int i=1; i<=n; i++) cin>>A[i];

	vector<long long int> suffix_sum(n+1);
	
	suffix_sum[n] = A[n];
	for(int i=n-1; i>=1; i--) suffix_sum[i] = (A[i] + suffix_sum[i+1]) % mod;

	long long int ans = 0;

	for(int i=1; i<=n-1; i++) {

		ans = (ans + (A[i] * suffix_sum[i+1]) % mod) % mod;
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 5628
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    const ll MX=500000;
    vector<bool> prime(MX,true);
    for(ll i=6;i*i<MX;i++){
        if((i%7!=1 && i%7!=6) || prime[i]==false){continue;}
        for(ll t=2*i;t<MX;t+=i){
            prime[t]=false;
        }
    }
    ll n;
    while(cin>>n){
        if(n==1){break;}
        cout<<n<<":";
        for(int i=6;i<=n;i++){
            if(n%i==0 && (i%7==1 || i%7==6) && prime[i]){cout<<" "<<i;}
        }
        cout<<endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SIZE(array) (sizeof(array) / sizeof(array[0]))

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

#define MAX_V 100000

#define MOD 1000000007L
#define INF 2147483647

signed main() {
	string p[3] = {};
	int i[3] = {};
	cin >> p[0] >> p[1] >> p[2];

	int t = 0;
	while (i[t] < p[t].size()) {
		// cout << t << endl;
		int k = t;
		t = p[t][i[t]] - 'a';
		i[k]++;
		// cout << t << endl;
	}
	cout << ("ABC"[t]) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include<math.h>
#include <queue>
using namespace std;
#define Minf -1e9
#define scan(n) scanf("%lld",&n)
typedef long long ll;
const int maxn = 1*1e5+10;
const ll INF = 1e9+100;
const int mod = 998244353;

int a[maxn];
int main()
{
	ll x, k, d;
	scanf("%lld%lld%lld", &x, &k, &d);
	x = abs(x);
	if (x >= d){
		if (k >= x / d) {
			k -= x / d;
			x %= d;
		}
		else {
			x -= d * k;
			k = 0;
		}
	}
	if (k % 2 == 1){
		printf("%lld", d-x);
	}
	else printf("%lld", x);
	return 0;
}

Measured memory_bytes: 3816
import java.util.Scanner

object Main {

  def read() = {
    val sc = new Scanner(System.in)
    val s = sc.nextLine()
    s
  }

  def isPalindrome(s: String): Boolean = (s == s.reverse)

  def solve(s: String): Boolean = {
    val n = s.length// 奇数
    val s1 = s.substring(0, (n-1)/2)
    val s2 = s.substring((n+3)/2 -1, n)

    isPalindrome(s) && isPalindrome(s1) && isPalindrome(s2)
  }

  def main(args: Array[String]): Unit = {
    val s = read()
    val result = solve(s)
    println(if(result) "Yes" else "No")
  }
}

Measured memory_bytes: 27324
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    List<Integer>[] groups = new List[M];
    for (int i = 0; i < M; i++) groups[i] = new ArrayList<>();
    for (int i = 0; i < N; i++) {
      int a = scanner.nextInt();
      groups[a % M].add(a);
    }

    int count = groups[0].size() / 2;
    if (M % 2 == 0) count += groups[M / 2].size() / 2;
    for (int i = 1; i < M / 2 + M % 2; i++) {
      count += count(groups[i], groups[M - i]);
    }
    System.out.println(count);
  }

  private static int count(List<Integer> s, List<Integer> t) {
    if (t.size() < s.size()) return count(t, s);
    Collections.sort(t);
    int count = 0;
    for (int i = 0; i < t.size() - 1; i++) {
      if (t.get(i).equals(t.get(i + 1))) {
        count++;
        i++;
      }
    }
    return Math.min(count, (t.size() - s.size()) / 2) + s.size();
  }
}


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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define int ll
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define vi vector<int>
#define pii pair<int,int>
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define MAX 500005
#define initialize(arr,elem) memset(arr,elem,sizeof(arr))

typedef long long ll;
// typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int arr[MAX][3], memo[MAX][3];

int solve(int n,int from){
	if (n<1) return 0;
	if (memo[n][from] != -1) return memo[n][from];

	if (n==1) return memo[n][from] = arr[n][from];

	int ans = max(arr[n][from] + solve(n-1,(from+2)%3),arr[n][from] + solve(n-1,(from+1)%3));
	return memo[n][from] = ans;
}

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

	int n;
	cin>>n;
	initialize(memo,-1);
	For(i,1,n+1) cin>>arr[i][0]>>arr[i][1]>>arr[i][2];

	cout<<max(solve(n,0),max(solve(n,1),solve(n,2)))<<endl;

	return 0;
}


Measured memory_bytes: 20864
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
   int n;
   cin>>n;
   V<string> s(n);
   V<ll> t(n);
   for(int i=0;i<n;i++){
       cin>>s[i]>>t[i];
   }
   string x;
   cin>>x;
   ll ans=0;
   bool used=true;
   for(int i=0;i<n;i++){
       if(used&&s[i]!=x)continue;
       if(used)used=false;
       else{
           ans+=t[i];
       }
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
main()
{
    ll n,m,i,k,j,e,ans=0;
    map<ll,ll>mp;
    cin >> n >> m;
    for(i=0;i<n;i++){
        cin >> k;
        for(j=0;j<k;j++){
            cin >> e;
            mp[e]++;
            if(mp[e]==n)ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
  "fmt"
  "sort"
)

func main() {
  var n,m,ans int
  fmt.Scanf("%d %d", &n, &m)

  a := make([]int, n)
  for i:=0; i<n; i++ {
    fmt.Scan(&a[i])
  }

  sort.Sort(sort.Reverse(sort.IntSlice(a)))

  m4 := float64(sum(a))/float64((4*m))
  for j:=0; j<m; j++ {
    x := a[:1][0]
    a = a[1:]
    if float64(x) >= m4 {
      ans++
    }
  }

  if ans == m {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}

func sum(array []int) int {
  var buf int
  for _, v := range array {
    buf += v
  }
  return buf
}


Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <map>

using namespace std;

int main() {
   int n;
   cin >> n;
   string a[n], cahr, ans = "";
   string alfabets[26] = {"a", "b", "c", "d", "e", "f", "g", "h","i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
   map<string, int> alfamap, gotalfamap;

   for (int i = 0; i < n; i++) {
      cin >> a[i];
      for (int i = 0; i < 26; i++) {
         cahr = alfabets[i];
         gotalfamap[cahr] = 0;
      }
      for (int j = 0; j < a[i].length(); j++) {
         cahr = a[i][j];
         if (i == 0) { // 1週目で初期化
            if (alfamap[cahr] == 0) {
               alfamap[cahr] = 1;
            }else {
              alfamap[cahr] += 1;
            }
         } else { // それ以降
            if (gotalfamap[cahr] == 0) {
               gotalfamap[cahr] = 1;
            } else {
               gotalfamap[cahr] += 1;
            }
         }         
      }
      
      for(auto itr = alfamap.begin(); itr != alfamap.end(); ++itr) {
         if (i != 0) {
            if (alfamap[itr->first] > gotalfamap[itr->first]) {
               alfamap[itr->first] = gotalfamap[itr->first];
            }
         }
         //std::cout << "key = " << itr->first           // キーを表示
            //<< ", val = " << itr->second << "\n";    // 値を表示
      }
      //cout << a[n] << endl;
   }

   for (int i = 0; i < 26; i++) {
      cahr = alfabets[i];
      for (int j = 0; j < alfamap[cahr]; j++) {
         ans += cahr;
      }
   }
   cout << ans << endl;
   



   //std::string o, e, ans = "";
/*
  for (int i = 0; i < e.length(); i++) {
     ans = ans + o[i] + e[i];
  }

  if (o.length() != e.length()) {
     ans = ans + o[(o.length() - 1)];
  }

  cout << ans << endl;
  */

}

Measured memory_bytes: 256
h, w, k = map(int, input().split())
C = []
for _ in range(h): C.append(input())
import itertools
ans = 0
for bit in range(1<<(h+w)):
    c = 0
    for i, j in itertools.product(range(w,h+w), range(w)):
        if bit>>i & 1 and bit>>j & 1: c += C[i-w][j] == '#'
    if c == k: ans += 1
print(ans)


Measured memory_bytes: 8964
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) (a<<b)
#define Rshift(a,b) (a>>b)
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;

ll dp[100][10];

void find(ll w, int deep, int idx) {
    if (deep == 0) {
        cout << idx << endl;
        return;
    }
    for (int x = max(0, idx - 1); x < min(10, idx + 2); x++) {
        if (w > dp[deep-1][x]) {
            w -= dp[deep-1][x];
        } else {
            cout << idx;
            find(w, deep-1, x);
            return;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    memset(dp, 0, sizeof(dp));
    int i, j;
    rep(i, 10) dp[0][i] = 1;
    ll w;
    cin >> w;
    rep(i, 15) {
        if (i > 0 ) dp[i][0] = dp[i-1][0] + dp[i-1][1];
        xrep(j, 1, 10) {
            if (dp[i][j]) {
                w -= dp[i][j];
                if (!w) {
                    cout << j << endl;
                    return 0;
                }
            } else {
                ll sum(0);
                for (int k = max(0, j - 1); k < min(10, j + 2); k++) {
                    sum += dp[i-1][k];
                    if (w > dp[i-1][k]) {
                        w -= dp[i-1][k];
                    } else {
                        cout << j;
                        find(w, i-1, k);
                        return 0;
                    }
                }
                dp[i][j] = sum;
            }
        }
    }
}


Measured memory_bytes: 256
import sys
mod = pow(10, 9) + 7
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NNN = (10**2)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


def erabu(aW):
    r = 0
    for i in range(aW // 2 + 1 + 1):
        sp = aW - (2*i -1)
        r += cmb(sp+i+1-1, sp, mod)
    return r

N, W, K = [int(x) for x in input().strip().split(" ")]
hasi = 0
cc = []
if W == 1:
    if K == 1:
        print(1)
    else:
        print(0)
    sys.exit()
elif W == 2:
    cccl = [1, 1]
    cc = [1, 1]
elif W == 3:
    cccl = [1, 1, 1]
    cc = [2, 1, 2]
elif W >= 4:
    aW = W - 1
    hW = aW - 2
    nhW = aW - 3
    cc = []
    cccl = []
    for w in range(W):
        nn = max(W - 1 - w - 1, 0)
        nnn = max((W - 1) - nn - 2, 0)
        if w == W -1:
            nnn += 1
        cc.append(erabu(nn) * erabu(nnn))
        cccl.append(erabu(nn) * erabu(nnn-1))

cccl[0] = 0
cccr = cccl[::-1]
d = [[1] + [0 for x in range(W-1)]] + [[0] * W for _ in range(N)]
for i in range(N):
    i += 1
    for j in range(W):
        d[i][j] = (d[i-1][j] * cc[j]) % mod
        if j != 0:
            d[i][j] = (d[i][j] + (d[i-1][j-1] * cccl[j]) )% mod
        if j != W-1:
            d[i][j] = (d[i][j] + (d[i-1][j+1] * cccr[j])) % mod

print(d[N][K-1])


Measured memory_bytes: 38384
//05
#include<iostream>
#include<queue>
#include<vector>

using namespace std;

struct S{
  int t,n,r;
  bool operator<(S a)const{
    return t>a.t;
  }
};

struct E{
  int t,c;
};

int main(){
  for(int n,m,l,k,a,h;cin>>n>>m>>l>>k>>a>>h,n|m|l|k|a|h;){
    bool cl[100]={};
    for(int i=0;i<l;i++){
      int t;
      cin>>t;
      cl[t]=true;
    }
    vector<int> to[100];
    vector<int> cs[100];
    for(int i=0;i<k;i++){
      int x,y,t;
      cin>>x>>y>>t;
      to[x].push_back(y);
      cs[x].push_back(t);
      to[y].push_back(x);
      cs[y].push_back(t);
    }
    priority_queue<S> que;
    S is={0,a,m};
    que.push(is);
    bool p[100][101]={{}};
    while(!que.empty()){
      S c=que.top();
      if(c.n==h)break;
      que.pop();
      if(p[c.n][c.r]++)continue;
      for(int i=0;i<to[c.n].size();i++){
	if(c.r>=cs[c.n][i]){
	  S n={c.t+cs[c.n][i],to[c.n][i],c.r-cs[c.n][i]};
	  que.push(n);
	}
      }
      if(cl[c.n]&&c.r<m){
	S n=c;
	n.r++;
	n.t++;
	que.push(n);
      }
    }
    if(que.empty()){
      cout<<"Help!"<<endl;
    }else{
      cout<<que.top().t<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2280
#include <stdio.h>

int main() {

    int i;
    int n, a;
    
    scanf("%d", &n);
    for(i = 0; i < n; i++) {
        scanf("%d", &a);
        if(a % 2 == 0) {
            if(a % 3 == 0) {
                continue;
            }
            else if(a % 5 == 0) {
                continue;
            }
            else {
                printf("DENIED\n");
                return 0;
            }
        }
    }

    printf("APPROVED\n");
    
    return 0;
}

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

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

    int ntup = 0;
    int nkuchi = 0;
    if ( B == 1 ) {
        ntup = 0;
    }
    else {
        while ( nkuchi <  B) {
            if (ntup == 0) {
                nkuchi += A;
                ntup++;
            }
            else {
                nkuchi -= 1;
                nkuchi += A;
                ntup++;
            }
        }
    }

    cout << ntup << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
using namespace std;


int main(){
	ll a, b, c, d, e, k; cin >> a >> b >> c >> d >> e >> k;
	if (e - a <= k) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

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

int main(void) {
    int n;
    double total=0;

    cin>>n;
    vector<double> x(n+1),y(n+1);
    FOR(i,1,n){
        cin>>x[i]>>y[i];
    }
    FOR(i,1,n-1){
        FOR(k,i+1,n){
            total+=sqrt(pow(x[i]-x[k],2)+pow(y[i]-y[k],2));
        }
    }
    total*=2;
    total/=n;

    printf("%.10lf\n",total);

}


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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O2")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);
#ifdef VAMP
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cout << name << " = " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names+1, ',');
    cout.write(names, comma - names) << " = " << arg1 <<" | ";
    __f(comma+1, args...);
}
#else
#define debug(...)
#endif

int main()
{
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    string s;
    cin >> s;
    if(s.back() == 's'){
        s += "es";
    }else{
        s += "s";
    }
    cout << s << "\n";
    #ifdef VAMP
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (long double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
}



Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INT(a) int((a)+1e-9)
#define PI 3.141592653589793
#define p ps[pi]


struct P{
public:
	int m;
	float g;	// =m/M
	float ath,ax,ay;
	float bth,bx,by;
	float oldarea,newarea;
	float re;
};


int main(){
	int R,X,Y,pl;
	cin>>R>>X>>Y>>pl;
	P ps[pl];
	int M=0;
	REP(pi,pl){
		cin>>p.m;
		M+=p.m;
	}
	
	float th=0;
	REP(pi,pl){
		p.ath=th;
		p.g=float(p.m)/M;
		th+=p.g*2*PI;
		p.bth=th;

		p.ax=R*sin(p.ath);
		p.ay=R*cos(p.ath);
		p.bx=R*sin(p.bth);
		p.by=R*cos(p.bth);

		p.oldarea=(p.bth-p.ath)*R*R/2;
		p.newarea = p.oldarea + (p.ax*Y-p.ay*X)/2 + (X*p.by-Y*p.bx)/2;

		p.re = p.newarea/p.oldarea;
		cout<<INT(p.re*100);
		if(pl-pi-1) cout << " "; else cout<<endl;
	}

}

Measured memory_bytes: 1188
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	ps := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&ps[i])
	}

	u := newUnionFind(n + 1)
	var x, y int
	for i := 0; i < m; i++ {
		fmt.Scan(&x, &y)
		u.unite(x, y)
	}

	ans := 0
	for i := 0; i < n; i++ {
		if u.same(i+1, ps[i]) {
			ans++
		}
	}
	fmt.Println(ans)
}

// UnionFind .
type UnionFind struct {
	par   []int
	rank  []int
	sizes []int
}

func newUnionFind(n int) UnionFind {
	u := UnionFind{}
	u.par = make([]int, n)
	u.rank = make([]int, n)
	u.sizes = make([]int, n)
	for i := 0; i < n; i++ {
		u.par[i] = i
		u.rank[i] = 0
		u.sizes[i] = 1
	}
	return u
}

func (u UnionFind) unite(x, y int) {
	x = u.root(x)
	y = u.root(y)
	if x == y {
		return
	}

	if u.rank[x] < u.rank[y] {
		u.par[x] = y
		u.sizes[y] += u.sizes[x]
	} else {
		u.par[y] = x
		u.sizes[x] += u.sizes[y]
		if u.rank[x] == u.rank[y] {
			u.rank[x]++
		}
	}
}

func (u UnionFind) root(x int) int {
	if u.par[x] == x {
		return x
	}
	u.par[x] = u.root(u.par[x])
	return u.par[x]
}

func (u UnionFind) same(x, y int) bool {
	return u.root(x) == u.root(y)
}

func (u UnionFind) size(x int) int {
	return u.sizes[u.root(x)]
}


Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll X;
  cin >> X;

  vector<int> P;
  vector<bool> Pb(111111, false);
  Pb.at(2) = true;
  for (int p = 3; p < 111111; p += 2)
  {
    bool ok = true;
    for (int i = 0; i < P.size(); i++)
    {
      int PP = P.at(i);
      if (PP * PP > p) break;
      if (p % PP == 0)
      {
        ok = false;
        break;
      }
    }
    if (ok)
    {
      P.push_back(p);
      Pb.at(p) = true;
    }
  }
  
  for (ll i = X; i < Pb.size(); i++)
  {
    if (Pb.at(i))
      FINALANS(i);
  }
}

Measured memory_bytes: 384
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tup(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,K=pin()
    H=[int(input()) for i in range(N)]
    H.sort()
    #print(H)
    ans=1000000000
    for i in range(N-K+1):
        ans=min(H[i+K-1]-H[i],ans)
    print(ans)
#%%submit!
resolve()

Measured memory_bytes: 44380
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<endl
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

ll calc(ll k,ll d) {
  return k*(k+1)/2*d;
}

const ll n=26;
ll c[n],q[444];
ll a[444][n];
set<ll> s[n];

ll solve(ll x,ll y,ll t) {
  ll ans=0,e=q[x];
  {
    ans-=a[x][q[x]];
    iter(s[q[x]]) it2=s[q[x]].lower_bound(x);
    iter(s[q[x]]) it1=it2,it3=it2;it1--,it3++;
    ans+=calc(*it2-*it1-1,c[q[x]]);
    ans+=calc(*it3-*it2-1,c[q[x]]);
    ans-=calc(*it3-*it1-1,c[q[x]]);
    s[q[x]].erase(it2);
  }
  {
    q[x]=y;
    s[q[x]].in(x);
    ans+=a[x][q[x]];
    iter(s[q[x]]) it2=s[q[x]].lower_bound(x);
    iter(s[q[x]]) it1=it2,it3=it2;it1--,it3++;
    ans-=calc(*it2-*it1-1,c[q[x]]);
    ans-=calc(*it3-*it2-1,c[q[x]]);
    ans+=calc(*it3-*it1-1,c[q[x]]);
  }
  if(!t) {
    s[q[x]].erase(x);
    q[x]=e;
    s[q[x]].in(x);
  }
  return ans;
}

         
void Main() {
  srand((unsigned)time(NULL));
  int T;
  R T;
  rep(i,n) R c[i];
  rep(i,T)rep(j,n) R a[i][j];
  rep(i,n) s[i].in(-1),s[i].in(T);
  rep(k,T) {
    ll M=0,x=0;
    rep(i,n) {
      if(M<a[k][i]) {
        M=a[k][i];
        x=i;
      }
    }
    q[k]=x;
    s[x].in(k);
  }
  ll ans[T];
  mem(ans);
  clock_t t2=clock();
  for(int tt=0;;tt++) {
    ll x=rand()%T,y=rand()%n;
    if(solve(x,y,0)>0) {
      solve(x,y,1);
      ans[x]=y;
    }
    clock_t t3=clock();
    double t4=(double)(t3-t2)/CLOCKS_PER_SEC;
    if(tt>=2&&(double)t3/CLOCKS_PER_SEC+t4*2>1.500) break;
    t2=t3;
  }
  rep(i,T) pr(ans[i]+1);
}

int main(){Main();return 0;}


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

int main()
{
  int x1, y1, x2, y2, x3, y3, x4, y4;
  cin >> x1 >> y1 >> x2 >> y2;
  int difx = abs(x1-x2);
  int dify = abs(y1-y2);
  if(x1 >= x2 && y1 >= y2)
  {
    x3 = x2+dify;
    x4 = x1+dify;
    y3 = y2-difx;
    y4 = y1-difx;
  }
  else if(x1 < x2 && y1 >= y2)
  {
    x3 = x2+dify;
    x4 = x1+dify;
    y3 = y2+difx;
    y4 = y1+difx;
  }
   else if(x1 >= x2 && y1 < y2)
  {
    x3 = x2-dify;
    x4 = x1-dify;
    y3 = y2-difx;
    y4 = y1-difx;
  }
   else if(x1 < x2 && y1 < y2)
  {
    x3 = x2-dify;
    x4 = x1-dify;
    y3 = y2+difx;
    y4 = y1+difx;
  }
  cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << ' ' << endl;
}

Measured memory_bytes: 256