akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

// TODO: write
int main() {
  int n,m;cin>>n>>m;
  vector<int> a(n);rep(i,n)cin>>a[i];
  
  auto uf = UnionFind(n);
  
  rep(i,m){
    int x,y;cin>>x>>y;
    uf.unite(x-1,y-1);
  }
  
  int cnt = 0;
  rep(i,n){
    if(uf.same(i,a[i]-1))cnt++;
  }
  print(cnt);
  return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ss string
#define ll long long int
#define Endl endl
#define u_b upper_bound
#define rep(i,n)         for(int i=0;i<n;i++)
#define ld long double
#define tc long long t;cin>>t;while(t--)
#define fr(i,a,b)        for(long long int i=a;i<=b;i++)
#define E endl
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define V deque<ll>v;
#define aaste long long int n;cin>>n;long long int a[n];for(long long int i=0;i<n;i++)cin>>a[i];
const ll   mod=            1000000007;
const ll   MOD1=           (int)1e9 + 9;
const ll   MOD2=           998244353;
const ld    pi=             atan2(0, -1);
const ld    eps=            1e-9;
const int   N=                   2e5+5;
 
const int MAXR = 1000005;
ll         tests=          1;
 
using namespace std;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll binarySearch(ll l, ll r,ll k)
{
  if (r >= l) {
    ll mid = l + (r - l) / 2;
    if (mid*(mid+1)==k)
      return 1;
    if (mid*(mid+1)>k)
      return binarySearch( l, mid - 1,k);
    return binarySearch(mid + 1, r, k);
  }
  return 0;
}
bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 
void swap(ll *p1, ll *p2)
{
   ll temp=*p1;
   *p1=*p2;
   *p2=temp;
}
ll cbratt(ll x)
{
    ll l = 0, r = MAXR;
    while (l != r) {
        ll m = (l + r + 1) / 2;
        if (m * m * m > x)
            r = m - 1;
        else
            l = m;
    }
    return l;
}
int MaxSubArraySumReturn(int a[], int  n) //negative thakle o kaaj korbe in O(n)
{
 
    int sum = 0, best = 0;
   for(ll i=0;i<n;i++)
    {
        sum = max(a[i], a[i] + sum);
        best = max(best, sum);
    }
    return best;
 
}
ll totalDigits(ll n) 
{ 
 
    ll number_of_digits = 0; 
    for (ll i = 1; i <= n; i *= 10) 
        number_of_digits += (n - i + 1); 
  
    return number_of_digits; 
}

int main()
{
  #ifndef ONLINE_JUDGE
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt", "w", stderr);
    }
#endif
ll n;
cin>>n;
ll y=n;
map<ll,ll>mp;
n=sqrt(n);
  ll ctr=0;
  for(ll x=1;x<=n;x++)
  {
    for(ll y=1;y<=n;y++)
    {
      for(ll z=1;z<=n;z++)
      {
        ll twmp=(x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x);
         mp[twmp]++;
      }
    }
  
}
for(ll i=1;i<=y;i++)
cout<<mp[i]<<Endl;

}


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

using namespace std;
mt19937_64 rng(58);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    vector<int> f(n);
    for (int i = 0; i < n; i++) cin >> f[i];
    sort(f.begin(), f.end());
    int ans = 0;
    for (int i=0; i<k; i++) ans += f[i];
    cout << ans << endl;
    
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef priority_queue<int> Pr; typedef vector<int> V; typedef vector<P> Vp; typedef map<int,int> MP;
const int mod = 1000000007; const Int INF = 1145141919810893931;
#define END {cout<<ans<<'\n'; return 0;}
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};


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

  Int n,m; cin>>n>>m; UnionFind t(n); stack<Int> an;
	Int a[m],b[m];
	for (int i = 0; i < m; i++)cin>>a[m-i-1]>>b[m-i-1];
	Int ans=n*(n-1)/2; an.push(ans);
	for (int i = 0; i < m-1; i++){
    if(t.find(--a[i])==t.find(--b[i])){an.push(ans); continue;}
    Int x=t.size(a[i]),y=t.size(b[i]);
		t.unite(a[i],b[i]);
		Int z=t.size(a[i]);
    if(ans)ans=ans-(z*(z-1)/2-x*(x-1)/2-y*(y-1)/2);
    an.push(ans);
	}
  for (int i = 0; i < m; i++){
    Int q=an.top(); an.pop(); cout<<q<<'\n';
  }
}

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    int p = 1;
    rep (i, 21) {
        if (p >= b) {
            cout << i << endl;
            return 0;
        }
        p += a - 1;
    }
    
    return 0;
}



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(){
    ll n,k;
    cin >> n >> k;
    vector <ll> a(n);
    rep(i,n){
        cin >> a[i];
    }

    rep(i,n-k){
        if(a[k+i]>a[i]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    

    return 0;
}

Measured memory_bytes: 4840
//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

A = require('fs').readFileSync(config.input, 'ascii')
  .trim()
  .split(config.newline)
  .map(function (line) { return line.trim().split(' ').map(Number); });
n = Number(A.shift()[0]);

cnt = 1;
cost = 0;
conn = new Array(n);
conn[0] = true;
for (i = 1; i < n; i++) conn[i] = false;

while (cnt < n) {
  min = Number.MAX_VALUE;
  for (i in conn) {
    if (!conn[i]) continue;
    Ai = A[i];
    for (j in conn) {
      if (conn[j]) continue;
      if (Ai[j] !== -1 && Ai[j] < min) {
        min = Ai[j];
        min_j = j;
      }
    }
  }
  conn[min_j] = true;
  cost += min;
  cnt++;
}

console.log(cost);

Measured memory_bytes: 19572
N, W = [int(_) for _ in input().split()]
WV = [[int(_) for _ in input().split()] for _ in range(N)]
dp = {}
dp[0] = 0
for w, v in WV:
    dp_o = dp.copy()
    for k in dp_o:
        if k + w <= W:
            dp[k + w] = max(dp_o.get(k + w, 0), dp_o[k] + v)
print(max([v for k, v in dp.items()]))


Measured memory_bytes: 137820
n=int(input())
a=list(map(int,input().split()))
a.sort()
A=[a[0]]
x=0
sum=sum(a)
sumL=-9999999999
if n==2:
  print(max(a)-min(a))
  print(max(a),min(a))
else:
  for i in range(1,n):
    A.append(A[i-1]+a[i])
  for i in range(1,n):
    if sumL<-A[i-1]+sum-A[i-1]:
      sumL=-A[i-1]+sum-A[i-1]
      x=i
  print(sumL)
  L1=a[0:x]
  L2=a[x:n]

  if x!=1:
    print(L2[0],L1[0])
    z=L2[0]-L1[0]
    for i in range(1,x-1):
      print(z,L1[i])
      z=z-L1[i]
  else:
    z=L2[0]

  if x!=n-1:
    print(L1[x-1],L2[1])
    y=L1[x-1]-L2[1]
    for i in range(2,len(L2)):
      print(y,L2[i])
      y=y-L2[i]
  else:
    y=L1[len(L1)-1]

  print(z,y)

Measured memory_bytes: 14336
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll n;
  double x,ans;
  char u[5]; 
  scanf("%lld",&n);
  for(int i = 0; i < n; i++)
  {
    scanf("%lf%s",&x,u);
    if(!strcmp(u,"BTC")){
      ans+=x*380000.0;
    }else{
      ans+=x;
    }
  }
  printf("%lf\n",ans);
  return 0;  
}


Measured memory_bytes: 128
// ProblemURL : https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_a
// ---------------------------------------------
package main

import "fmt"

func smaller(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func larger(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	mx := smaller(a, b)
	mn := larger(a+b-n, 0)
	fmt.Println(mx, mn)
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  bool ans=false;
  for(int i=0;i<1e7;i++){
    if(a*i%b==c){
      ans=true;
      break;
    }
  }
  cout << (ans?"YES":"NO") << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<sstream>
#include<string>
#include<string.h>
#include<cmath>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#define E (2.71828182)
#define PI (3.1415926535898)
#define	max(a,b)	((a)>(b)?(a):(b))
#define	min(a,b)	((a)>(b)?(b):(a))
#define	mem(a,b)	memset(a,b,sizeof(a))
#define	_max(a,b,c)	(max(a,b)>c?max(a,b):c)
#define mod	1000000007
#include<set>
#define gc getchar
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<float, int> P;
const long long  MAX_V = 5005, INF = 2147483647, MOD = 998244353;
#include <iostream>
using namespace std;
ll n, m, x, temp;
priority_queue<ll> que;
int main()
{
	while (~scanf("%lld%lld", &n, &m))
	{
		temp = 0;
		for (int i = 0; i < n; i++)
		{
			scanf("%lld", &x);
			que.push(x);
		}
		for (int i = 0; i < m; i++)
		{
			que.push(que.top() / 2);
			que.pop();
		}
		while (!que.empty())
		{
			temp += que.top();
			que.pop();
		}
		printf("%lld\n", temp);
	}
}


Measured memory_bytes: 1400
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    cin >> s;
    long long  n=s.size();
    long long m=0,l=0,t=0;
    for(int i=0;i<n;i++){
        if(s[i]=='W') l+=i+1,m++;
    }
    for(int i=1;i<=m;i++) t+=i;
    cout << l-t <<endl; 
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int n;
int a[100010];
int acc[100010];
signed main() {
    cin >> n;
    rep(i,0,n) cin >> a[i];
    sort(a, a+n);

    rep(i,0,n) {
        if(i == 0) acc[i] = a[i];
        else acc[i] = a[i] + acc[i-1];
    }

    int ans = 1;
    bool ok[100010] = {};
    ok[n-1] = true;
    repr(i,n-2,0) {
        if(acc[i] * 2 >= a[i+1] && ok[i+1]) {
            // printf("debug: ok(%lld): %lld\n", i, a[i]);
            ans++;
            ok[i] = true;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

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

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述

ll A, B, K;
cin >> A >> B >> K;

if(A < K){
    K = K-A;
    A = 0;
    if(B < K){
        B = 0;
    }
    else{
        B = B-K;
    }
}
else{
    A = A-K;
}

cout << A << " " << B << "\n"; 

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
#define MOD 1000000007
#define ull unsigned long long int
#define newline cout<<endl
 
 
/* TYPE DEFINITIONS */
typedef     long long int        ll;
typedef     vector<ll>     vi;
typedef     pair<ll,ll>   pi;
 
 
 
/* MATH */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 
ll pow(ll a,ll b)
{
   ll res=1;
    while(b>0)
    {
        if(b&1)res=(res*a);
        a=(a*a);
        b>>=1;
    }
    return res;
}
 
  
//
/* MACROS */
 
#define  all(A)         (A).begin() , (A).end()
#define  arrall(A,n)    (A),((A)+(n))
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)     for (int i = 0; i < int(n); i++)
#define  forr(i, n)     for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)  
#define  deb(x)       cout << '>' << #x << ':' << x << endl;

void solve()
{
    string a,b;
    cin>>a>>b;
    cout<<b<<a<<endl;

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

Measured memory_bytes: 256
C = [[int(x) for x in input().split()] for _ in range(3)]

def f():
    for i in range(3):
        for j in range(3):
            k = (i + 1) % 3
            l = (j + 1) % 3
            if C[i][j] - C[i][(j + 1) % 3] != C[k][j] - C[k][l]:
                return False
    return True
            
print("Yes" if f() else "No")

Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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


class CColon {
public:
    int dy[4]={-1,1,0,0};
    int dx[4]={0,0,1,-1};
    long double PI = 3.14159265358979323846264338327950L;

	void solve(std::istream& in, std::ostream& out) {
        long double A, B, H, M;
        in >> A >> B >> H >> M;
        long double degree = M_PIl * ((M / 30.0l) - (H/ 6.0l + M / 360.0l));
        out << setprecision(64)  << sqrtl(A * A + B * B - 2L * A * B * cosl(degree)) << endl;
	}
};


int main() {
    ios::sync_with_stdio(false);
	CColon solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 4196
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
#define pi pair<int,int>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ; 
		ll n , k  ;
		cin>> n >>k  ;
		if(n >= k ){
			n = n %k ;
		}
		ll ans = min(n , abs(n - k) ) ; 
		cout<<ans <<endl;
	
	
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    int n;
    scan(n);
    auto a = new long[](n);
    auto b = new long[](n);

    foreach (i ; 0 .. n) {
        scan(a[i], b[i]);
    }

    sort(zip(b, a));

    long t;

    foreach (i ; 0 .. n) {
        if (t + a[i] > b[i]) {
            writeln("No");
            return;
        }
        t += a[i];
    }

    writeln("Yes");
}











void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 5372
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long mod = 1000000007;

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 32; i++) {
		if ((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

long long Div(long long a, long long b, long long m) {
	return (a * modpow(b, m - 2, m)) % m;
}

long long ncr(long long n, long long r) {
	if (n < r || r < 0) return 0;
	long long rem = 1;
	for (long long i = n - r + 1; i <= n; i++) { rem *= i; rem %= mod; }
	for (int i = 1; i <= r; i++) rem = Div(rem, i, mod);
	return rem;
}

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

	long long V1 = modpow(2, N, mod); V1 = (V1 + mod - 1LL) % mod;
	long long V2 = ncr(N, A);
	long long V3 = ncr(N, B);
	cout << (V1 - V2 - V3 + mod * mod) % mod << endl;
	return 0;
}

Measured memory_bytes: 256
N = STDIN.gets.chomp.to_i

c = []
(N+1).times do |n|
  i = n.to_s[0].to_i
  j = n.to_s[-1].to_i

  c[i] = [] if c[i].nil?
  c[i][j] = 0 if c[i][j].nil?

  # n の先頭の桁の数はi、末尾はj
  c[i][j] += 1
end

ans = 0
10.times do |i|
  10.times do |j|
    next if i == 0 or j == 0
    next if c[i].nil? or c[j].nil?
    # puts "------ i:#{i} j:#{j} ----------"
    # c[i][j] : 先頭 i, 末尾j
    # c[j][i] : 先頭 j, 末尾i
    ans += c[i][j] * c[j][i] unless c[i][j].nil? or c[j][i].nil?
  end
end
puts ans



Measured memory_bytes: 1788
#include<stdio.h>

int main(void)
{
	int i, N;

	scanf("%d", &N);

	int A[N];
	
	for(i=0; i<N; i++){
		scanf("%d", &A[i]);
	}

	int max = A[0];
	int min = A[0];

	for(i=1; i<N; i++){
		if(max < A[i]){
			max =A[i];
		}
		if(min > A[i]){
			min = A[i];
		}
	}

	

	printf("%d\n", max - min);

	return 0;
}

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

long func(long sum, deque<long> &nums){
    if(nums.size()==1) return sum + nums.front();
    long n1 = nums.front(); nums.pop_front();
    long n2 = nums.front(); nums.pop_front();
    deque<long> nums1 = nums;
    deque<long> nums2 = nums;
    nums1.push_front(n1*10+n2);
    nums2.push_front(n2);
    return func(sum, nums1) + func(sum+n1, nums2);
}

int main(){
    string s;
    cin >> s;
    deque<long> nums;
    for(unsigned int i=0; i<s.size(); i++) nums.push_back( (long) s[i] - (long) '0');
    cout << func(0,nums) << endl;
}

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

bool compare_by_b(pair<int,int> a, pair<int,int> b){
  if(a.second != b.second){
    return a.second > b.second;
  }
  else{
    return a.first > b.first;
  }
}

vector<pair<int,int> > op;
priority_queue<int ,vector<int>, greater<int> > v;

int main(){
  int N, M;
  cin >> N >> M;
  for(int i=0; i<N; i++){
    int a; cin >> a;
    v.push(a);
  }
  for(int i=0; i<M; i++){
    int b, c;
    cin >> b >> c;
    pair<int, int> p(b,c);
    op.push_back(p);
  }
  sort(op.begin(), op.end(), compare_by_b);
  for(int i=0; i<M; i++){
    for(int j=0; j<op[i].first; j++){
      if(v.top()<op[i].second){
        v.pop();
        v.push(op[i].second);
      }
      else break;
    }
  }
  long sum=0;
  for(int i=0; i<N; i++){
      sum+=v.top();
      v.pop();
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1784
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

n = lines[0][0]
k = lines[0][1]
go_to = lines[1]

current_town = 1
travel_root = []
visited = []
for i in 1..n do
  visited[i-1] = false
end
for i in 1..n+1 do
  travel_root.push(current_town)
  if visited[current_town - 1] then
    first_visit = travel_root.index(current_town)
    second_visit = i - 1
    loop_num = second_visit - first_visit
    break
  end
  visited[current_town - 1] = true
  current_town = go_to[current_town - 1]
end
  
if first_visit == 0 then
  print travel_root[k % loop_num]
elsif k <= first_visit then
  print travel_root[k]
else
  num = (k - first_visit)
  print travel_root[(num % loop_num) + first_visit]
end


Measured memory_bytes: 31812
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
s = input()
k = ni()
n = len(s)
l = set()
for i in range(k):
    for j in range(0,n-i):
        l.add(s[j:j+i+1])
ls = sorted(list(l))
print(ls[k-1])


Measured memory_bytes: 10900
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

const int mxc2 = 186 * 185 / 2;
signed char mem[mxc2 * mxc2];

int ren[186][186], pre[186][186];

void init(){
	memset(mem, -1, sizeof(mem));
	int ix = 0;
	rep(i,0,185) rep(j,i,185){
		ren[i][j+1] = ix++;	
	}
}

signed char calc(int r1, int r2, int c1, int c2){
	int rn = ren[r1][r2] * mxc2 + ren[c1][c2];
	if(mem[rn] != -1) return mem[rn];
	int res = pre[r2][c2] - pre[r1][c2] - pre[r2][c1] + pre[r1][c1];
	if(res == 0 || res == (r2-r1)*(c2-c1)) return 0;
	int ans = 16;
	do {
		int lo = r1, hi = r2;
		while(lo+1 < hi){
			int mi = (lo+hi)/2;
			int m1 = calc(r1, mi, c1, c2);
			int m2 = calc(mi, r2, c1, c2);
			ans = min(ans, max(m1,m2)+1);
			if(ans <= 1+min(m1,m2)) break;
			(m1 > m2 ? hi : lo) = mi;
		}
	} while(false);
	do {
		int lo = c1, hi = c2;
		while(lo+1 < hi){
			int mi = (lo+hi)/2;
			int m1 = calc(r1, r2, c1, mi);
			int m2 = calc(r1, r2, mi, c2);
			ans = min(ans, max(m1,m2)+1);
			if(ans <= 1+min(m1,m2)) break;
			(m1 > m2 ? hi : lo) = mi;
		}
	} while(false);

	return mem[rn] = ans;
}

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);

	init();

	int h, w;
	cin >> h >> w;

	vector<string> as(h);
	trav(s, as) cin >> s;

	rep(i,0,h) rep(j,0,w) pre[i+1][j+1] = (as[i][j]=='#') + 
		pre[i+1][j] + pre[i][j+1] - pre[i][j];

	cout << (int)calc(0, h, 0, w) << endl;
}


Measured memory_bytes: 289664
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int N, m1, m2, tmp;
  long res1, res2;
  res1 = 0;
  res2 = 0;
  
  cin >> N;
  vector<int> A(N);
  
  for(int i=0; i<N; i++) {
    cin >> tmp;
    A[i] = tmp - (i+1);
  }
  sort(A.begin(), A.end());
  
  if(N%2==0) {
    m1 = A[N/2-1];
    m2 = A[N/2];
    for(int j=0; j<N; j++) {
      res1 += abs(A[j] - m1);
      res2 += abs(A[j] - m2);
    }
    if(res2 > res1) {
      res1 = res2;
    }
  } else {
    m1 = A[N/2];
    for(int j=0; j<N; j++) {
      res1 += abs(A[j] - m1); 
    }
  }
  
  cout << res1 << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ctype.h>
#include <math.h>
using namespace std;
 
int findSum(int n){
    int sum=0;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
    return sum;
}

int main(){
    int N;
    cin>>N;
    int ans=100;

    for(int i=1;i<N;i++){
        int sum=findSum(i)+findSum(N-i);
        if(ans>sum)ans=sum;
    }
    cout<<ans<<endl;
}

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

#define ll long long
#define vec vector<ll>
#define sortv(a); sort(a.begin(), a.end());
#define rev(a); reverse(a.begin(), a.end());
#define FOR(i,a,b) for (ll i = (ll)(a); i < (b); i++)
#define ROF(i,a,b) for (ll i = (ll)(b)-1; i >= (a); i--)
#define printarray(a) FOR(Q,0,(int)(a).size()) cout<<(a)[Q]<<" "; cout<<'\n';

ll MOD = 1000000007;
ll INF = 1LL << 60;

/*****************************************************************************/
int h,w;
int grid[102][102];

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>h>>w;
	FOR(i,0,h) {
		string s;cin>>s;
		FOR(j,0,w) {
			grid[i][j]=(s[j]!='.');
		}
	}

	int dp[h][w];
	dp[0][0]=grid[0][0];
	FOR(j,1,w) {
		dp[0][j]=dp[0][j-1]+(!grid[0][j-1]&&grid[0][j]);
	}
	FOR(i,1,h) {
		dp[i][0]=dp[i-1][0]+(!grid[i-1][0]&&grid[i][0]);
		FOR(j,1,w) {
			dp[i][j]=min(
				dp[i-1][j]+(!grid[i-1][j]&&grid[i][j]), 
				dp[i][j-1]+(!grid[i][j-1]&&grid[i][j]));
		}
	}

	cout<<dp[h-1][w-1];
}

Measured memory_bytes: 384
def main():
    N, M = map(int, input().split())
    temp = []

    for i in range(N):
        A, B = map(int, input().split())
        temp.append([A, B])
    
    temp.sort()
    ans = 0
    
    for i in range(N):
        if M == 0:
            break
        if M - temp[i][1] >= 0:
            M -= temp[i][1]
            ans += temp[i][0] * temp[i][1]
        else:
            ans += M  * temp[i][0]
            M = 0
        
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 20064
#include <bits/stdc++.h>
#include "atcoder/all"
using namespace std;
using namespace atcoder;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
const long long int sMod = 998244353;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

using mint=modint998244353;

struct S {
    mint a;
    int size;
};

struct F {
    mint a,b;
};

S op(S l,S r) { return S{l.a+r.a, l.size+r.size}; }

S e() { return S{0,0}; }

S mapping(F l,S r) { return S{r.a*l.a+r.size*l.b,r.size}; }

F composition(F l,F r) { return F{r.a*l.a, r.b*l.a+l.b}; }

F id() { return F{1,0}; }

void solve(){
    ll n,q;
    cin >> n >> q;
    vector<S> a(n);
    rp(i,n){
        ll x;
        cin >> x;
        a[i]=S{x,1};
    }
    lazy_segtree<S,op,e,F,mapping,composition,id> seg(a);
    while(q--){
        ll t;
        cin >> t;
        if(t==0){
            ll l,r,bi,ci;
            cin >> l >> r >> bi >> ci;
            mint b=bi,c=ci;
            seg.apply(l,r,F{b,c});
        }else{
            ll l,r;
            cin >> l >> r;
            print(seg.prod(l,r).a.val());
        }
    }
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 19624
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool bo[100];
#define ll long long 
#define mod 1000000007
int main()
{
	ll n;
	cin>>n;
	if(n==0)
	{
		cout<<0<<endl;
		return 0;
	}
	ll a=1;
	for(ll i=1;i<n;i+=a)
	{
		a++;
	}
	cout<<a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 100005;

int main() {
    int n;
    cin >> n;
    LL ans = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                ans += __gcd(__gcd(i, j), k);
            }
        }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#define _USE_MATH_DEFINES

#include<iostream>
#include<cmath>
#include<math.h>
#include<iomanip>
using namespace std;
using vec = pair<double, double>;


void koch(int d, vec p1, vec p2) {
	if (d == 0) return;

	vec s, u, t;
	double rad = M_PI * 60 / 180. ;

	// cauculate new coordinate
	// first : x, second : y
	s.first  = (p2.first  - p1.first)  / 3 + p1.first;
	s.second = (p2.second - p1.second) / 3 + p1.second;
	t.first  = (p2.first  - p1.first ) / 3 * 2 + p1.first;
	t.second = (p2.second - p1.second) / 3 * 2 + p1.second;
	u.first  = (t.first - s.first) * cos(rad) - (t.second - s.second) * sin(rad) + s.first;
	u.second = (t.first - s.first) * sin(rad) + (t.second - s.second) * cos(rad) + s.second;

	koch(d - 1, p1, s);
	printf("%.8f %.8f\n", s.first, s.second);
	koch(d - 1, s, u);
	printf("%.8f %.8f\n", u.first, u.second);
	koch(d - 1, u, t);
	printf("%.8f %.8f\n", t.first, t.second);
	koch(d - 1, t, p2);
}

int main() {
	int d;
	vec p1(0., 0.), p2(100., 0.);

	cin >> d;

	printf("%.8f %.8f\n", p1.first, p1.second);
	koch(d, p1, p2);
	printf("%.8f %.8f\n", p2.first, p2.second);
}

Measured memory_bytes: 3204
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
  int N, T, A, ans = -1, v;
  float kkk, minv = 1000000.0;
  cin >> N;
  cin >> T >> A;

  for (int i = 0; i < N; i++) {
    cin >> v;
    kkk = abs(float(A) - (float(T) - float(v * 0.006)));
    if (minv > kkk) {
      minv = kkk;
      ans = i + 1;
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        String[] s = sc.next().split("");
        int zero = 0;
        int one = 0;

        for (String value : s) {
            if (value.equals("0")) {
                zero++;
            } else {
                one++;
            }
        }

        System.out.println(2 * Math.min(zero, one));
    }
}


Measured memory_bytes: 33120
#include <bits/stdc++.h>
#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 irep(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(V, v)  for (auto &&V : v)
#define all(x)        (x).begin(), (x).end()
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = 1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s;
  cin >> s;
  char x = s[0];
  bool good = true;
  rep1 (i, s.size() - 1) {
    if (x == s[i]) good = false;
    x = s[i];
  }
  cout << (good ? "Good" : "Bad") << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long aTaihi = a;
		long b = sc.nextLong();
		long bTaihi = b;
		List<Long> sosuListA = new ArrayList<Long>();
		sosuListA.add((long)1);
		List<Long> sosuListB = new ArrayList<Long>();
		sosuListB.add((long)1);
		for(long i =2;i < Math.sqrt(aTaihi);) {
			if(a % i == 0) {
				while(a % i == 0) {
					sosuListA.add(i);
					a /=i;
				}
			}
			if(i ==2) {
				i++;
			}else {
				i +=2;
			}
		}
		if(a !=1) {
			sosuListA.add(a);
		}
		for(long i =2;i < Math.sqrt(bTaihi);) {
			if(b % i == 0) {
				while(b % i == 0) {
					sosuListB.add(i);
					b /=i;
				}
			}
			if(i ==2) {
				i++;
			}else {
				i +=2;
			}
		}
		if(b !=1) {
			sosuListB.add(b);
		}
		List<Long> sosuListADistinct = new ArrayList<Long>();
		for(int i =0;i < sosuListA.size();i++) {
			if(i ==0) {
				sosuListADistinct.add(sosuListA.get(i));
			}else {
				if(sosuListA.get(i) != sosuListA.get(i-1)){
					sosuListADistinct.add(sosuListA.get(i));
				}
			}
		}
		List<Long> sosuListBDistinct = new ArrayList<Long>();
		for(int i =0;i < sosuListB.size();i++) {
			if(i ==0) {
				sosuListBDistinct.add(sosuListB.get(i));
			}else {
				if(sosuListB.get(i) != sosuListB.get(i-1)){
					sosuListBDistinct.add(sosuListB.get(i));
				}
			}
		}
		long answer = 0;
		for(long aElement: sosuListADistinct) {
			for(long bElement: sosuListBDistinct) {
				if(aElement ==bElement) {
					answer++;
				}
			}
		}

		System.out.println(answer);
	}

}

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

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))

int main() {
    int a, b;
    string s;

    cin >> a >> b;
    cin >> s;
    bool rtn = (s[a] == '-');
    string pattern = "[0-9]{" + to_string(a) + "}-[0-9]{" + to_string(b) + "}"; 

    if(regex_match(s, regex(pattern))) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
//return x's divisor as vector
vector<ll> divisor(ll x){
  vector<ll> res;
  for(ll i=1;i*i<=x;++i){
    if(x%i==0){
      res.push_back(i);
      if(i!=x/i){
	res.push_back(x/i);
      }
    }
  }
  sort(res.begin(), res.end());
  return res;
}

int main()
{
  ll n;cin >> n;
  vector<ll> v = divisor(n);
  ll res = (1LL << 60);
  rep(i,v.size()) {
    ll x = n / v[i];
    res = min(res, x + v[i] - 2);
  }
  cout << res << "\n";
  return 0;
}


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

#define ll long long 
const int N = 1e3 + 10;
const int INF = 1e9;

int h, w;
char grid[N][N];
int dist[N][N];

void init(int n) {
    for (int i = 0; i <= n+1; i++) {
        for (int j = 0; j <= n+1; j++) {
            grid[i][j] = '#';
            dist[i][j] = INF;
        }
    }
}

bool ok(int i, int j) {
    return (not (i <= 0 or j <= 0 or i > h or j > w or grid[i][j] == '#'));
}

void bfs(int si, int sj) {
    dist[si][sj] = 0;

    vector<int> dx = {1, -1, 0, 0};
    vector<int> dy = {0, 0, 1, -1};

    deque<pair<int, int>> dq;
    dq.emplace_front(si, sj);

    while (not dq.empty()) {
        auto [thisx, thisy] = dq.front(); dq.pop_front();
        // immediately adjacent
        for (int i = 0; i < 4; i++) {
            int nx = thisx + dx[i];
            int ny = thisy + dy[i];
            if (not ok(nx, ny)) continue;
            if (dist[thisx][thisy] < dist[nx][ny]) {
                dist[nx][ny] = dist[thisx][thisy];
                dq.emplace_front(nx, ny);
            }
        }

        // can jump with magic (should sum 1 to ans)
        for (int nx = thisx - 2; nx <= thisx + 2; nx++) {
            for (int ny = thisy - 2; ny <= thisy + 2; ny++) {
                if (not ok(nx, ny)) continue;
                if (dist[thisx][thisy] + 1 < dist[nx][ny]) {
                    dist[nx][ny] = dist[thisx][thisy] + 1;
                    dq.emplace_back(nx, ny);
                }
            }
        }
        
    }
    
}

int main() {
    ios::sync_with_stdio(0); 

    cin >> h >> w;
    int si, sj; 
    int ei, ej;
    cin >> si >> sj >> ei >> ej;
    init(max(h, w));

    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> grid[i][j];
        }
    }


    bfs(si, sj);

    if (dist[ei][ej] == INF) {
        cout << -1 << endl;
    } else {
        cout << dist[ei][ej] << endl;
    }




    return 0; 
}



Measured memory_bytes: 8712
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc118a
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = ReadIntList();
            var a = ab[0];
            var b = ab[1];
            if (b % a == 0)
            {
                Console.WriteLine(a + b);
                return;
            }
            Console.WriteLine(b-a);
#if DEBUG
            Console.ReadKey();
#endif
        }

        private static bool IsRange(int a, int from, int to) => (from <= a && a <= to);
        private static int ReadInt() => int.Parse(Console.ReadLine());
        private static List<int> ReadIntList() => Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToList();
        private static List<int> Int2Digits(int a) => a.ToString().ToCharArray().Select(_ => int.Parse(_.ToString())).ToList();
    }
}


Measured memory_bytes: 13268
n=int(input())
a_1 = [int(i) for i in input().split()]
a_2 = [int(i) for i in input().split()]

output = 0
for i in range(1,n+1):
    tmp = sum(a_1[:i]) + sum(a_2[i-1:])
    if tmp > output:
        output = tmp

print(output)


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

unsigned long long n, a, b;

int main() {
    cin >> n >> a >> b;
    if(a > b)
        cout << "0";
    else if(n == 1)
        cout << (a == b);
    else
        cout << (b - a) * (n - 2) + 1;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#include<cmath>
#include<climits>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;

typedef long long ll;

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

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

ll f(ll x, ll a, ll m){
	if(x == 1) return 0;
	return f(a*x % m, a, m) + 1;
}

int main(){
	while(true){
		ll A, M, ans = 1;
		for(ll i = 0; i < 3; i++){
			cin >> A >> M;
			if(!A || !M) return 0;
			ans = lcm(ans, f( A % M, A, M ) + 1 );
		}
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()



int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];

    long long res = 0;
    long long two_factor = 1;
    for (int d = 0; d < 60; ++d) {
        long long even = 0, odd = 0;
        for (int i = 0; i < N; ++i) {
            if (A[i] & (1LL<<d)) ++odd;
            else ++even;
        }
        long long add = (odd * even) % MOD * two_factor % MOD;
        res = (res + add) % MOD;
        two_factor = (two_factor * 2) % MOD;
    }
    cout << res << endl;
}



Measured memory_bytes: 2560
#include <stdio.h>
int main(void){
  int n,a[100],i,j,b,p[2]={};
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for (i=0;i<n-1;i++){
    for (j=i+1;j<n;j++){
      if (a[i]<a[j]){
        b=a[i];
        a[i]=a[j];
        a[j]=b;
      }
    }
  }
  for (i=0;i<n;i++) p[i%2]+=a[i];
  printf("%d\n",p[0]-p[1]);
  return 0;
}

Measured memory_bytes: 128
ok=True
a1=[int(x) for x in input().split()]
a2=[int(x) for x in input().split()]
a3=[int(x) for x in input().split()]
b1=[a1[0]]+[a2[0]]+[a3[0]]
b2=[a1[1]]+[a2[1]]+[a3[1]]
b3=[a1[2]]+[a2[2]]+[a3[2]]
c1=[a1[0]]+[a2[1]]+[a3[2]]
c2=[a1[2]]+[a2[1]]+[a3[0]]
alle=[a1,a2,a3,b1,b2,b3,c1,c2]
val=int(input())
d=[]
for i in range(val):
    d=int(input())
    for i1 in alle:
        if d in i1:
            i1.remove(d)
for i in alle:
    if i==[]:
        print("Yes")
        ok=False
        break
if ok:
    print("No")

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

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

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

	// find cycle
	map<int,int> lastvisit;
	vector<int> pos_at_t;
	int t=0;
	int pos=1;
	while (lastvisit.count(pos)==0)
	{
		pos_at_t.push_back(pos);
		lastvisit[pos]=t;
		++t;
		pos=dest[pos];
	}
	int t_offset=lastvisit[pos];
	int cycle=t-t_offset;

	if (k<t_offset)
	{
		cout << pos_at_t[k] << endl;
		return 0;
	}
	k-=t_offset;
	k%=cycle;
	cout << pos_at_t[t_offset+k] << endl;
}









Measured memory_bytes: 13924
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	X := nextInt()

	if X == 3 || X == 5 || X == 7 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}


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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c;

    if (a > b) {
        d = a;
        a = b;
        b = d;
    }

    if (b > c) {
        d = b;
        b = c;
        c = d;
    }

    if (a > b) {
        d = a;
        a = b;
        b = d;
    }

    cout << a << " " << b << " " << c << endl;

    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,d,e,f;cin >> a >> b >> c >> d >> e >> f;
	int ans1 = a, ans2 = 0;
	double ma = -1;
	for(int i = 0; i <= f / 100; i += a){
		for(int j = 0; j <= f / 100 - i; j += b){
			if(i == 0 && j == 0) continue;
			int t = (i + j) * e;
			for(int k = 0; k <= t; k += c){
				for(int k1 = 0; k1 <= t - k; k1 += d){
					if((i + j) * 100 + k + k1 > f) break;
					if(ma < (double)100 * (k + k1) / ((i + j) * (double)100 + (k + k1))){
						ma = (double)100 * (k + k1) / ((i + j) * (double)100 + (k + k1));
						ans1 = (i + j) * 100;
						ans2 = (k + k1);
					}
				}
			}
		}
	}
	cout << ans1 + ans2 << " " << ans2 << endl;
}


Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_2_B&lang=jp
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int a,b,c;
  cin>>a>>b>>c;
  if(a<b&&b<c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}



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

using namespace std;
const int mod = 1e9 + 7;

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

  int n, m;
  cin >> n >> m;
  vector<int> x(n), y(m);
  for (auto &e : x) {
    cin >> e;
  }
  for (auto &e : y) {
    cin >> e;
  }
  uint64_t xarea = 0;
  for (size_t i = 0; i < x.size() - 1; ++i) {
    uint64_t t = i + 1;
    xarea = (xarea + t * (n - t) * (x[t] - x[i])) % mod;
  }
  uint64_t yarea = 0;
  for (size_t i = 0; i < y.size() - 1; ++i) {
    uint64_t t = i + 1;
    yarea = (yarea + t * (m - t) * (y[t] - y[i])) % mod;
  }
  cout << (xarea * yarea) % mod << "\n";
}


Measured memory_bytes: 1024