akhauriyash/Code-Regression huggingface dataset:
// Problem : D - Coloring Edges on Tree
// Contest : AtCoder - AtCoder Beginner Contest 146
// URL : https://atcoder.jp/contests/abc146/tasks/abc146_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

int n,col[N],par[N];
vii g[N];

void solve(){
    cin>>n;
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        g[u].eb(v,i);
        g[v].eb(u,i);
    }
    int root = 0, mx = 0;
    for(int i=1;i<=n;i++){
        if(sz(g[i]) > mx) mx = sz(g[i]), root = i;
    }
    int ans = 0;
    queue<pii> q;
    q.push({root,0});
    while(!q.empty()){
        pii p = q.front();
        int avoid = p.se;
        int u = p.fi;
        q.pop();
        int cur = 1;
        for(auto [v,i] : g[u]){
            if(v == par[u]) continue;
            if(cur == avoid) cur++;
            col[i] = cur;
            ans = max(ans,cur);
            par[v] = u;
            q.push({v,cur});
            cur++;
        }
    }
    cout<<ans<<'\n';
    for(int i=0;i<n-1;i++) cout<<col[i]<<'\n';
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 12864
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int64_t n,x;
  cin >> n >>x;
  vector<int64_t>a(n);
  rep(i,n) cin >> a.at(i);
  vector<int64_t>b(n);
  rep(i,n) b.at(i) = abs(x - a.at(i) );
  sort(b.begin(), b.end());//bという配列を小さい方からソート
  reverse(b.begin(), b.end());
//  rep(i,n) cout<<b.at(i) <<endl;
  int64_t k,t,s,r;
  k = 0; t = 0; s = 0; r = 0;
  
  k = b.at(0);
    for(int i=0;i<n-1;i++){
      t = b.at(i+1);
      if(k > b.at(i+1)){
        for(;;){
          s = k/t;
          r = k%t;
          if(r==0)break;
          k = t;
          t = r;          
        }//mugenend
        k = t;
      }//ifend
      else{
          for(;;){
          s = t/k;
          r = t%k;
          if(r==0)break;
          t = k;
          k = r;        
          }//mugenend
      }//elseend
    }//forend
    cout << k <<endl;

  
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define ALL(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  string s ;
  cin >> s ;
  
  cout <<"ABC"<< s <<endl ;
  
    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int n;
	cin >> n;
	int a[n+1];
	int b[n];
	
	long long total = 0;
	
	for(int i = 0; i < n+1; i++){
		cin >> a[i];
	}
	for(int i = 0; i < n; i++){
		cin >> b[i];
		if(a[i] <= b[i]) {
			total += a[i];
			b[i] -= a[i];
			a[i] = 0;
			
			if(a[i+1] <= b[i]){
				total += a[i+1];
				a[i+1] = 0;
			}else{
				total += b[i];
				a[i+1] -= b[i];
			}
		}else{
			total += b[i];
			a[i] -= b[i];
		}
	}
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 4300
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int n,max = 0,ans = 0,a[105],b[105];
	scanf("%d",&n);
	for(int i = 1;i <= n; i++)
		scanf("%d",&a[i]);
		for(int i = 1;i <= n; i++)
			scanf("%d",&b[i]);
			for(int i = 1;i <= n; i++)
			{
				ans = 0;
				for(int j = 1;j <= i; j++)
					ans += a[j];
				for(int k = i;k <= n; k++)
						ans += b[k];				
						if(ans > max)
							max = ans;
			}
			printf("%d\n",max);
			return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n, k, ans;
int main() {
    cin >> n >> k;
    for(LL i = k + 1; i <= n; ++i) {
        if(n % i) {
            ans += (n / i) * (i - k);
            if(n % i >= k) {
                if(k) ans += n % i - k + 1; else ans += n % i;
            }
        }else {
            ans += (n / i) * (i - k);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
#include <map>

using namespace std;



int main(int argc, const char * argv[]) {
 
    long long x, y;
    cin >> x >> y;
    int cnt = 0;
    while(x <= y){
        x*=2;
        cnt++;
    }
    cout << cnt << endl;
    return 0;

}


Measured memory_bytes: 256
/*
 _     _    ___  ___  __ __ 
| |   | |  |__ \|__ \/_ /_ |
| |__ | |__   ) |  ) || || |
| '_ \| '_ \ / /  / / | || |
| |_) | |_) / /_ / /_ | || |
|_.__/|_.__/____|____||_||_|

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

#define N  100005
vi adj[N];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;

//	cin>>TESTS;
	while(TESTS--)
	{
		ll n,k;
		cin>>n>>k;
		ll ans=k;
		rep(i,0,n-1)
		{
			ll a,b;
			cin>>a>>b;
			adj[a].pb(b);
			adj[b].pb(a);
		}
		bool vis[N]={0};
		queue<int>q;
		vis[1]=1;
		for(auto u:adj[1])
			if(vis[u]==0)
			{q.push(u);vis[u]=1;}
		for(int i=0;i<q.size();i++)
		{
			ans*=(k-i-1);
			ans%=hell;
		}
		while(!q.empty())
		{
			ll t=q.front();
			q.pop();
			ll x=0;
			for(auto u:adj[t])
			{
				if(!vis[u])
				{
					q.push(u);
					vis[u]=1;
					x++;
				}
			}
			rep(i,0,x)
			{
				ans*=(k-i-2);
				ans%=hell;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 7028
#include<stdio.h>

int main (void){

    int N,K;
    int d[100];
    int a_val;
    int sunuke[100];
    int triCount=0;
    int it,iy,i;
    char c;


    scanf("%d %d",&N,&K);
    scanf("%c",&c);

    for(i=0;i<N;i++){
        sunuke[i]=1;
    }

    for(it=0;it<K;it++){
        scanf("%d",&d[it]);
        scanf("%c",&c);

        for(iy=0;iy<d[it];iy++){
            scanf("%d",&a_val);

            sunuke[a_val-1]=0;
        }
    }

    for(i=0;i<N;i++){
        if(sunuke[i]==1){
            triCount++;
        }
    }

    printf("%d",triCount);



    return 0;
}

Measured memory_bytes: 1736
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

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

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

bool query(deque<char> d1, deque<char> d2) {
	string s1, s2;
	each(i, d1)s1 += i;
	each(i, d2)s2 += i;

	printf("%s\n%s\n", s1.c_str(), s2.c_str()); fflush(stdout);
	char c; cin >> c;
	return c == 'T';
}

signed main() {

	int n;
	cin >> n;

	deque<char> d1, d2;

	bool re = false;

	auto unko = [&]() {
		if (!re) {
			d1.push_back('.');	d2.push_back('.'); if (query(d1, d2))return 0; d1.pop_back(); d2.pop_back();
			d1.push_back('.');	d2.push_back('#'); if (query(d1, d2))return 0; d1.pop_back(); d2.pop_back();
			d1.push_back('#');	d2.push_back('.'); if (query(d1, d2))return 0; d1.pop_back(); d2.pop_back();
			d1.push_back('#');	d2.push_back('#'); if (query(d1, d2))return 0; d1.pop_back(); d2.pop_back();
			return 1;
		}
		else {
			d1.push_front('.');	d2.push_front('.'); if (query(d1, d2))return 0; d1.pop_front(); d2.pop_front();
			d1.push_front('.');	d2.push_front('#'); if (query(d1, d2))return 0; d1.pop_front(); d2.pop_front();
			d1.push_front('#');	d2.push_front('.'); if (query(d1, d2))return 0; d1.pop_front(); d2.pop_front();
			d1.push_front('#');	d2.push_front('#'); if (query(d1, d2))return 0; d1.pop_front(); d2.pop_front();
		}
	};
	while (1) {
		int t = unko();
		if (t == 1)re = true;
		else
		if (d1.size() == n)return 0;
	}

	return 0;
}

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

const long long infinity = 1e18;

int w[100];
int v[100];

long long dp[100][100001];

int main()
{
    int n,W;
    cin>>n>>W;
    for(int i = 0; i < n; i++)
    {
        cin>>w[i]>>v[i];
    }

    dp[0][0] = 0;
    dp[0][w[0]] = v[0];

    for(int id = 1; id < n; id++)
    {
        dp[id][0] = 0;
        for(int j = 1; j <= W; j++)
        {
            // discard current object
            dp[id][j] = dp[id - 1][j];
            if(j >= w[id])
            dp[id][j] = max(dp[id][j],(v[id] + dp[id - 1][j - w[id]]));
        }
    }
    long long answer = -infinity;
    for(int j = 0; j <= W; j++)
    {
        answer = max(answer,dp[n - 1][j]);
    }
    cout<<answer<<endl;
    return 0;



    return 0;
}


Measured memory_bytes: 80848
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, M; cin >> N >> M;
    multiset<int> A;
    ll wa = 0;
    rep(i,N) {
        int a; cin >> a;
        A.insert(a);
        wa += a;
    }
    vector<pair<int,int>> BC(M);
    rep(i,M) {
        int b, c; cin >> b >> c;
        BC[i] = make_pair(c,b);
    }
    sort(BC.begin(), BC.end(), greater<pair<int,int>>());
    for (auto [c,b] : BC) {
        auto x = A.begin();
        if (*x >= c) break;
        while (b > 0 && *x < c)  {
            wa = wa - *x + c;
            A.erase(x);
            A.insert(c);
            b--;
            x = A.begin();
        }
    }
    cout << wa << endl;
}


Measured memory_bytes: 8812
/*
lakshaygpt28
Lakshay Gupta
*/

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

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
using vll = vector < ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;


#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

map < string, ll > cnt;

int main() {
    fast_io();
    ll n;
    cin >> n;
    for (ll i = 0; i < n; i++) {
        string s;
        cin >> s;
        sort(all(s));
        cnt[s]++;
    }
    ll ans = 0;
    for (auto x : cnt) {
        ans += ((x.second) * (x.second - 1)) / 2;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
 
/*** Template Begins ***/
 
typedef long long    ll;
typedef pair<ll,ll>  pll;
typedef pair<ll, pair<ll, ll> > plll;
typedef vector<long long>  vll;
typedef vector<pll>  vp;
typedef long double ld;
#define rep(i,a,b) for(i=a;i<=b;i++)
#define pb           push_back
#define INF          INT_MAX/10
#define F            first
#define S            second
#define mp           make_pair
#define ios          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hell         1000000007LL
// #define hell 163577857LL
// #define h 998244353
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p)
{
  ll res = 1;
  x = x % p;
  while (y > 0)
  { 
     if (y & 1) 
      res = (res*x) % p;
    y = y>>1;
    x = (x*x) % p;
  } 
  return res; 
} 
const int M = 1005;
const int N = 1005;
const long double PI = acos(-1);
// Debug //
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll euclid(ll x,ll y,ll a,ll b)
{
  return (a-x)*(a-x)+(b-y)*(b-y);
}
// Constants //
void solve()
{
  ll k;
  cin>>k;
	string s;
  cin>>s;
  if(s.length()<=k)
    cout<<s;
  else
    cout<<s.substr(0,k)+"...";
}
int main()
{ 
  ios;
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ll t,i;
  t=1;
  // cin>>t;
  // preprocess();
  while(t--)
  {
    solve();
    // cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;

const int N = 100005;
int n, m, a[N];
LL slen, sdt, cnt;
pii seg[N];
vector<pii> pos[N];

int calc(int x, int y){
	x -= y;
	if (x < 0) x += m;
	return x;
}

int main(){
	// freopen("d.in", "r", stdin);
	cin >> n >> m;
	REP(i, 1, n) cin >> a[i];
	REP(i, 1, n - 1){
		seg[i] = mp(a[i], a[i + 1]);
		pos[a[i]].pb(mp(1, a[i]));
		pos[a[i + 1]].pb(mp(-1, a[i]));
		slen += calc(a[i + 1], a[i]);
	}
	REP(i, 1, n - 1) if (a[i] > a[i + 1]){
		++cnt;
		sdt += 1 - a[i] + m;
	}
	// cerr << slen << ' ' << sdt << endl;
	LL ans = slen - sdt + cnt;
	REP(i, 2, m){
		RVC(j, pos[i - 1]){
			cnt += pos[i - 1][j].fi;
			if (pos[i - 1][j].fi == -1)
				sdt -= (calc(i - 1, pos[i - 1][j].se));
		}
		sdt += cnt;
		ans = min(ans, slen - sdt + cnt);
		// cerr << i << " : " << cnt << ' ' << sdt << ' ' << slen - sdt + cnt << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6528
def gi; gets.to_i end
def gs; gets.chomp end
def gli; gets.split(' ').map(&:to_i) end
def d(n); Math.log10(n).to_i + 1 end
class Integer
  # 約数の組み合わせを列挙する
  def divisor_combinations
    (1..Math.sqrt(self).to_i).
      select { |i| self % i == 0 }.
      map { |i| [i, self / i] }
  end
end

N = gi

def calc_moves(i, j)
  (i - 1) + (j - 1)
end

puts N.divisor_combinations.map { |d| calc_moves(*d) }.min


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

int main(void) {
  int M;
  scanf("%d", &M);
  printf("%d\n", 48-M);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

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

  ll n;
  cin >> n;
  ll a[n + 5];

  for (ll i = 1; i <= n; i++)
    cin >> a[i];

  map<ll, ll> par;

  ll res = 0;
  for (ll i = 1; i <= n; i++) {
    if (par.find(-i + a[i]) != par.end()) {
      res += par[-i + a[i]];
    }
    par[-i - a[i]]++;
  }
  cout << res << en;

  return 0;
}


Measured memory_bytes: 17572
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<int>;


int main()
{
	int N, D;
	cin >> N >> D;

	vec Heho(90001,0);

	for(int i=0;i<300;++i)
	{
		Heho[i*i] = 1;
	}

	mat X(N, vec(D));

	int ans = 0;
	for (int i = 0; i < N; ++i)
	{
		for (int k = 0; k < D; ++k)
		{
			cin >> X[i][k];
		}

		for (int j = 0; j < i; ++j)
		{
			int tmp = 0;
			for (int k = 0; k < D; ++k)
			{
				tmp += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
			}
			ans += Heho[tmp];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 896
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
function main()
  V=zeros(Int,3010,3010)
  dp=zeros(Int,3010,3010,4)
  R,C,K=parse.(Int,split(readline()))
  for i=1:K
    r,c,v=parse.(Int,split(readline()))
    V[r,c]=v
  end
  @simd for i=1:R
    @simd for j=1:C
      @simd for k=1:4
        #sita
        @inbounds dp[i+1,j+1,1]=max(dp[i+1,j+1,1],dp[i,j+1,k])
        @inbounds dp[i+1,j+1,2]=max(dp[i+1,j+1,2],dp[i,j+1,k]+V[i,j])
        #migi
        @inbounds dp[i+1,j+1,k]=max(dp[i+1,j+1,k],dp[i+1,j,k],k>1 ? dp[i+1,j,k-1]+V[i,j] : 0)
      end
    end
  end
  println(maximum(dp[R+1,C+1,:]))
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 578960
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, alice, bob int
	fmt.Scan(&n)
	cards := make([]int, n)
	for i :=0; i<n; i++ {
		fmt.Scan(&cards[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(cards)))

	for i := 0; i<n; i+=2 {
		alice += cards[i]
		if i+1 < n {
			bob += cards[i+1]
		}
	}
	fmt.Println(alice-bob)
}


Measured memory_bytes: 512
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n,m,a,b,c,d,x,y,z;
  string s,t;
  //

  // ここから
  IN(s);
  if(s=="a" || s=="i" || s=="u" || s=="e" || s=="o") OUT("vowel");
  else OUT("consonant");
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))


int main(){
	REP(i,3){
		int hms[2][3];
		int r[3];
		REP(j,2)REP(k,3)cin>>hms[j][k];
		REP(j,2){
			if(hms[1][2-j]>=hms[0][2-j]){
				r[2-j]=hms[1][2-j]-hms[0][2-j];
			}else{
				r[2-j]=60+hms[1][2-j]-hms[0][2-j];
				hms[1][1-j]--;
			}
		}
		r[0]=hms[1][0]-hms[0][0];
		cout<<r[0]<<" "<<r[1]<<" "<<r[2]<<endl;
	}
	return 0;
}

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

int main()
{
  int i,j,n,c=0,p=0;
  cin>> n;
  if(n>=30)
  {
    cout << "Yes" << endl;
  }
  else
  {cout << "No" << endl;}
  return 0;
}

Measured memory_bytes: 3580
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
out = [int(input()) for _ in range(D)]
last = [0] * 26
sat = 0

for d in range(D):
    j = out[d] - 1
    last[j] = d + 1
    for i in range(26):
        sat -= (d + 1 - last[i]) * c[i]
    sat += s[d][j]
    print(sat)


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

int main(){
  int N, K, x, S;
  cin >> N >> K;
  S = 0;
  for(int i = 0; i < N; i++){
    cin >> x;
    if((K-x) < x){
      S += (K-x)*2;
    }else if((K-x) >= x){
      S += x*2;
    }
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,i,k,kotae=0;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++){
    cin>>a[i];
    kotae+=a[i]-1;
  }
  cout<<kotae;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  int n,q;
  int count = 0;
  string s;
  cin >> n >> q >> s;
  vector<int> dp(n,0);
  for(int i = 0;i < n-1;i++) {
    if(s[i] == 'A' && s[i+1] == 'C') {
      dp[i+1] = dp[i] + 1;
    }else {
      dp[i+1] = dp[i];
    }
  }
  rep(i,q) {
    int l,r,ans = 0;
    cin >> l >> r;
    l--; r--;
    ans = dp[r] - dp[l];
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
   string s;
   cin>>s;
   cout<<s[0]<<s[1]<<s[2];

}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n;
  cin >> n;
  ll res = 0;
  for (ll i = 1; i <= n; i++)
  {
    string str = to_string(i);
    if (str.length() % 2 == 1)
    {
      res++;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
from sys import stdin

def main():
    n,w = map(int, input().split())
    ary = [list(map(int, stdin.readline().split())) for _ in range(n)]
    dp = [[0 for _ in range(w+1)] for _ in range(n)]
    for i in range(n):
        for y in range(1,w+1):
            if i == 0:
                dp[i][y] = ary[i][1] if ary[i][0] <= y else 0
            elif ary[i][0] <= y:
                dp[i][y] = max(dp[i-1][y-ary[i][0]] + ary[i][1],dp[i-1][y])
            else:
                dp[i][y] = dp[i-1][y]
    print(dp[n-1][w])

if __name__ == '__main__':
    main()

Measured memory_bytes: 171400
N = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
ans = b_list[a_list[0]-1]
for i in range(1, N):
    ans += b_list[a_list[i]-1]
    if a_list[i-1]+1 == a_list[i]:
        ans += c_list[a_list[i-1]-1]
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int sdkys(int a,int b){
    if(b==0) return a;
    return sdkys(b,a%b);
}
int sskbs(int a,int b){
    return a*b/sdkys(a,b);
}
int n,m,cnt=0,aa[220000],ans=0,ab[220000];
pair<int,int> pp[220000];
string s,sa[220000];
char ca[220000];
queue<int> que;
signed main(){
    cin>>n>>m>>cnt;
    if((n+m+cnt-max({n,m,cnt}))%2==1){
        cout<<((max({n,m,cnt})+1)*3-n-m-cnt)/2;
    }else{
        cout<<(max({n,m,cnt})*3-n-m-cnt)/2;
    }
}

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

using namespace std;

int N;
long long a[300000];

void solve() {
    long long num = 0;
    sort(a, a + N * 3, greater<>());
    for (int i = 0; i < N; i++) {
        num += a[2 * i + 1];
    }
    printf("%lld\n", num);
}

int main() {
    cin >> N;
    for (int i = 0; i < N * 3; ++i) cin >> a[i];
    solve();
    return 0;
}

Measured memory_bytes: 5952
import java.util.*;
// warm-up
// I thought Atcoder doesnt do time wasters...
public class Main {

	static char[][] g = null;
	static char[][] p = null;

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(), m=sc.nextInt(), t=n, i=0, j=0, c=0, r=0;
		boolean ok = true;
		g = new char[n][n];
		p = new char[m][m];
		while (t-->0) {
			j=0;
			for (char ch : sc.next().toCharArray()) g[i][j++] = ch;
			i++;
		}
		t=m; i=0;
		while (t-->0) {
			j=0;
			for (char ch : sc.next().toCharArray()) p[i][j++] = ch;
			i++;
		}
		i=0; j=0; c=r=n-m; 
		while (i<=r) {
			j=0;
			while (j<=c) {
				ok = true;
				// Check
				for (int l=0; l<m; l++) {
					for (int o=0; o<m; o++) {
						if (p[l][o]!=g[i+l][j+o]) {
							ok=false; break;
						}
					}
					if (!ok) break;
				}
				if (ok) {
					System.out.println("Yes");
					System.exit(0);
				}
				j++;
			}
			i++;
		}
		System.out.println("No");
		sc.close();			
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35928
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define ALL(A) A.begin(),A.end()
const long long mod=1000000007;
int main(){
    int a[5],b[5],bo=100,sum=0,temp;
    for(int i=0;i<5;i++){
        cin>>a[i];b[i]=a[i]%10;
    }
    for(int i=0;i<5;i++)
    {
        if(b[i]==0)
        continue;
        bo=min(b[i],bo);
    }
    int flag=0;
    for(int i=0;i<5;i++)
    {
        if(b[i]==bo&&flag!=1){
        sum+=a[i];flag=1;
        }
        else
        {
            while(a[i]%10!=0)
            a[i]++;
            sum+=a[i];
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int main() 
{
	int k;
	cin>>k;
	string s="ACL";
	string ans="";
	for(int i=1;i<=k;i++)
	{
		ans+=s;
	}
	cout<<ans;
	
	return 0;
} 

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

#define ll long long

ll n,W,V,v[101],w[101],memo[100001][101];
bool ready[100001][101];

ll dp(ll value,ll item)
{
    if(item==0 and value==0)
        return 0;
    if(item==0)
        return 1e15;
    if(ready[value][item])
        return memo[value][item];
    ready[value][item]=1;
    if(value<v[item])
        return memo[value][item]=dp(value,item-1);
    return memo[value][item]=min(dp(value,item-1),dp(value-v[item],item-1)+w[item]);
}

int main()
{
//    freopen("a.in","r",stdin);
    cin>>n>>W;
    for(ll i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
        V+=v[i];
    }
    for(ll i=V;i>=0;i--)
    {
        if(dp(i,n)<=W)
        {
            cout<<i;
            break;
        }
    }

}




Measured memory_bytes: 88320
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int top,mystack[1000];

void initializeStack()
{
    top=-1;
}

void push(int x)
{
    mystack[++top]=x;
}

int pop()
{
    return mystack[top--];
}

int main()
{
    char s[100];
    int a,b;
    while(scanf("%s",s)!=EOF)
    {
        if(s[0]=='+')
        {
            a=pop();
            b=pop();
            push(a+b);
        }
        else if(s[0]=='-')
        {
            b=pop();
            a=pop();
            push(a-b);
        }
        else if(s[0]=='*')
        {
            a=pop();
            b=pop();
            push(a*b);
        }
        else
        {
            push(atoi(s));
        }

    }

    printf("%d\n",pop());
    return 0;
}



Measured memory_bytes: 3212
Option Infer On
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim N As Integer = NextInt()
        Dim a As Integer() = New Integer(N - 1) {}

        For i = 0 To N - 1
            a(i) = NextInt()
        Next

        Dim j As Integer = 1
        Dim dic As Dictionary(Of Integer, Boolean) = New Dictionary(Of Integer, Boolean)

        For i = 1 To N
            dic(j) = True
            j = a(j - 1)
            If dic.ContainsKey(j) Then
                Exit For
            ElseIf j = 2 Then
                WriteLine(i)
                Exit Sub
            End If
        Next

        WriteLine(-1)
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


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

using pint = pair<int, int>;
int main(){
    int N, K; cin >> N >> K;
    int ma = (N-1)*(N-2) / 2;
    if (ma < K) cout << -1 << endl;
    else {
        vector<pint> res;
        for (int i = 1; i <= N-1; ++i) res.push_back({i, N});

        int rem = ma - K;
        int ci = 1, cj = 2;
        for (int i = 0; i < rem; ++i) {
            res.push_back({ci, cj});
            ++cj;
            if(cj == N) {
                ++ci;
                cj = ci+1;
            }
        }

        cout << res.size() << endl;
        for (auto p : res) cout << p.first << " " << p.second << endl;
    }

}


Measured memory_bytes: 384
N, M = (int(i) for i in input().split())
P, Y = ({}, {})
for i in range(M):
    pp, yy = (int(i) for i in input().split())
    P[i] = pp
    Y[i] = yy

Y = sorted(Y.items(), key=lambda x:x[1])
Pnum = {}
Res = {}
for i, yy in Y:
    pp = P[i]
    if Pnum.get(pp):
        Pnum[pp] += 1
    else:
        Pnum[pp] = 1
    Res[i] = "{:0=6}{:0=6}".format(pp, Pnum[pp])

Res = sorted(Res.items(), key=lambda x:x[0])
for i, rr in Res:
    print(rr)

Measured memory_bytes: 56200
import java.util.Scanner;


public class Main {

	public static void main(String[] args)  {

		Scanner sc = new Scanner(System.in);
		int x =  Integer.parseInt(sc.next());		
		long[] l = new long[121];
		for(int i = 0 ; i < 121 ; i++) {
			l[i] = multiplication(i);
		}
		
		boolean flag = false;
		int a = 0;
		int b = 0;
		for(int i = 0 ; i < 121 ; i++) {
			long temp = Math.abs(l[i] - x);
			for(int j = 0 ; j < 121 ; j++) {
				if(l[j] == temp) {
					flag = true;
					a = i;
					b = j;
					break;
				} 
				if(flag) {
					break;
				}
			}
			
			
		}
		
		
		long ans_a = multiplication(a);
		long ans_b = multiplication(b);
		
		if(ans_a + ans_b == x) {
			System.out.println(a + " " + -b);
		}else if(ans_a - ans_b == x) {
			System.out.println(a + " " + b);
		}else{
			System.out.println(b + " " + a);
		}
	 }

	
	
	public static long multiplication(int i) {
		
		long temp = i * i;
		temp = temp * temp * i;
		return temp;
	}
	
}


Measured memory_bytes: 27000
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        
        int[] array = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            array[i] = k + i;
            sum += array[i];
        }
        
        if (array[0] > 0) {
            sum -= array[0];
        } else if (array[n - 1] < 0) {
            sum -= array[n - 1];
        }
        
        System.out.println(sum);
        // System.out.println(Arrays.toString(array));
    }
}


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

int main(){
  int S;
  cin >> S;
  
  vector<bool> passed(1000000, false);
  passed.at(S) = true;
  int ans = 1;
  while (true){
    if (S % 2 == 0){
      S /= 2;
    }
    else{
      S = 3 * S + 1;
    }
    ans++;
    
    if (passed.at(S) == true){
      break;
    }
    
    passed.at(S) = true;
    
  }
  
  cout << ans << endl;
    
}

Measured memory_bytes: 3732
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cassert>
#include <deque>
#include <map>
#include <queue>
#include <climits>
#include <set>
#include <stack>
#include <cmath>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define MAX 1000
#define MAX1 10000
#define MAX2 100000
#define inf 1000000000
#define eps 1e-12
#define MOD 1000000007

char a[MAX + 5][MAX + 5];
int c[MAX + 5][MAX + 5];
set<int> graph[MAX * MAX + 5];
int dis[MAX * MAX + 5];

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

void dfs(int x, int y, int cc, int h, int w) {
    c[x][y] = cc;
    for (int i = 0; i < 4; ++i) {
        int xx = x + dir[i][0];
        int yy = y + dir[i][1];
        if (xx >= 0 and xx < h and yy >= 0 and yy < w and a[xx][yy] != '#' and !c[xx][yy]) {
            dfs(xx, yy, cc, h, w);
        }
    }
}

int bfs(int c1, int c2) {
    queue<int> q;
    q.push(c1);
    memset(dis, -1, sizeof(dis));
    dis[c1] = 0;
    while (!q.empty()) {
        auto z = q.front();
        q.pop();
        for (auto w:graph[z]) {
            if (dis[w] == -1) {
                dis[w] = dis[z] + 1;
                q.push(w);
            }
        }
    }
    return dis[c2];
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    int h, w, i, j, k, l, cc = 0;
    int s1, s2, d1, d2;
    cin >> h >> w;
    cin >> s1 >> s2 >> d1 >> d2;
    for (i = 0; i < h; ++i) {
        for (j = 0; j < w; ++j) {
            cin >> a[i][j];
        }
    }
    for (i = 0; i < h; ++i) {
        for (j = 0; j < w; ++j) {
            if (!c[i][j] and a[i][j] != '#') {
                dfs(i, j, ++cc, h, w);
            }
        }
    }
    for (i = 0; i < h; ++i) {
        for (j = 0; j < w; ++j) {
            if (a[i][j] == '#') {
                continue;
            }
            int x = i - 2, y = j - 2;
            for (k = x; k < x + 5; ++k) {
                for (l = y; l < y + 5; ++l) {
                    if (k >= 0 and k < h and l >= 0 and l < w and c[k][l] and c[k][l] != c[i][j]) {
                        graph[c[i][j]].insert(c[k][l]);
                    }
                }
            }
        }
    }
    cout << bfs(c[s1 - 1][s2 - 1], c[d1 - 1][d2 - 1]);

    return 0;
}


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

#define INF INT_MAX

using namespace std;

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

ll gcd(ll a,ll b)
{
	ll x = a * b;
	
	if(a<b){
		ll tmp = a;
		a = b;
		b = tmp;
	}
	
	ll r = a % b;
	while(r!=0){
		a = b;
		b = r;
		r = a % b;
	}
	return x/b;
}

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

	ll A,B,C,D;
	cin >> A >> B >> C >> D;
	
	ll bb = (B / C) + (B / D) - (B / gcd(C,D));
	// cout << gcd(C,D) << endl;
	ll aa = ((A-1) / C) + ((A-1) / D) - ((A-1) / gcd(C,D));

	

	cout << (B-A+1) - (bb - aa) << endl;

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main()
{
	int  x, y;
	for (int i = 0; ; i++) {
		cin >> x >> y;
		if (x == 0 && y == 0) break;
		if (x > y) {
			int tmp = x;
			x = y;
			y = tmp;
		}

		cout << x << ' ' << y << endl;
	}
	return 0;

}

Measured memory_bytes: 3060
#include <stdio.h>
 
int main(){
  int all_len=0,first_len=0,last_len,len_bin=0,flag=0,ret,flag2=0;
  long answer=0,k;
  char s,t,first,last;
  while(1){
    ret = scanf("%c",&s);
    if(flag == 0){
      first = s;
      t = s;
      flag = 1;
    }
    if(ret == EOF || s == '\n'){
      last = t;
      answer += ((long)len_bin)/2;
      last_len = len_bin;
      break;
    }
    if(s == t){
      ++len_bin;
      if(flag == 1) ++first_len;
    }
    else{
      answer += ((long)len_bin)/2;
      flag = 2;
      flag2 = 1;
      len_bin = 1;
    }
    t = s;
    
    all_len += 1;
  }
  scanf("%ld",&k);
  if(all_len == 1) answer = k/2;
  else if(flag2 == 0) answer = (k * (long)all_len)/2;
  else if(first == last){
    answer -= ((long)first_len)/2;
    answer -= ((long)last_len)/2;
    answer += ((long)first_len+(long)last_len)/2;
    answer *= k;
    answer -= ((long)first_len+(long)last_len)/2;
    answer += ((long)first_len)/2 + ((long)last_len)/2;
  }else answer *= k;
  printf("%ld\n",answer);
  return 0;
}

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


int main(){

    int n;
    cin >> n;
    
    int ans = 0;
    int maxi = -1;
    for(int i = 1; i <= n; i++) {
        
        int num = i;
        int cnt = 0;
        while(num%2 == 0){
            num /= 2;
            cnt++;
        }
        if(cnt > maxi){
            ans = i;
            maxi = cnt;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define DI(v,i) distance((v).begin(),(auto(i)))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes()
{
    cout << "Yes" << endl;
}
void no()
{
    cout << "No" << endl;
}
//-----------------------------------------

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

    int n ;
    cin >> n ;
    int cnt = 0 ;
    ll ans = 0 ;
    ll mini = LINF ;
    REP(i,n){
        ll a ;
        cin >> a ;
        mini = min(abs(a),mini) ;
        ans += abs(a) ;
        if(a<0){
            cnt++ ;
        }
    }
    if(cnt%2==1){
        ans -= 2*mini ;
    }
    cout << ans <<endl ;
    

    return 0;
}

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

  int p[1001];
  int N;
  int K;
  int ans;

int main(){
  cin >> N >> K;
  rep(i,N){
    cin >> p[i];
  }
  sort(p,p+N);

  rep(i,K){
    ans += p[i];
  }
  cout << ans << endl;

}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
auto speedup = [](){
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return nullptr;
}();

int main()
{
int a , b , c ,d;
cin>>a>>b>>c>>d;
int flag = 0;
int v1 = 0;
int v2 = 0;
if(c%b == 0)
    v2 = c/b;
else
{
    v2 = c/b +1;
}

if(a%d == 0)
    v1 = a/d;
else
{
    v1 = a/d +1;
}

if(v1>=v2)
    cout<<"Yes"<<endl;
else
{
    cout<<"No"<<endl;
}

}

Measured memory_bytes: 3652
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

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

using namespace std;

int n;
int id[100005], m[100005][4], s[100005][4];
void solve() {
    vector<pair<int, int>> vec;
    rep(i, n) {
        int sum = 0;
        rep(j, 4) sum += m[i][j] * 60 + s[i][j];
        vec.emplace_back(sum, id[i]);
    }
    sort(vec.begin(), vec.end());
    cout << vec[0].second << endl;
    cout << vec[1].second << endl;
    cout << vec[n - 2].second << endl;
}
int main() {
    while (cin >> n, n) {
        rep(i, n) {
            cin >> id[i];
            cin >> m[i][0] >> s[i][0];
            cin >> m[i][1] >> s[i][1];
            cin >> m[i][2] >> s[i][2];
            cin >> m[i][3] >> s[i][3];
        }
        solve();
    }
}

Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> num(N);
  
  for (int i = 0; i < N; i++) {
    cin >> num.at(i);
    num.at(i) -= (i + 1);
  }
  
  sort(num.begin(), num.end());
  
  int ma,mb;
  
  if (N % 2 == 0) {
    ma = num.at(N/2);
    mb = num.at(N/2 - 1);
  }
  else {
    ma = num.at((N - 1)/2);
    mb = num.at((N - 1)/2);
  }
  
  long sunuke1,sunuke2 = 0;
  
  for (int i = 0; i < N; i++) {
    sunuke1 = sunuke1 + abs(num.at(i) - ma);
    sunuke2 = sunuke2 + abs(num.at(i) - mb);
  }
  
  cout << min(sunuke1,sunuke2) << endl;
  
  return 0;
}

Measured memory_bytes: 1024