akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;



int main(){
    int h,w;
    cin >> h >> w;

    int sx,sy,gx,gy;
    cin >> sy >> sx >> gy >> gx;
    sx--;sy--;gx--;gy--;

    pair<int,int> s = make_pair(sx,sy), g = make_pair(gx,gy); 
    vector<vector<int>> ans(h,vector<int>(w,mod));
    string sur[h];

    for(int i = 0; i < h; i++) cin >> sur[i];

    auto inout = [&](int x,int y){
        if(0 <= x && x < w && 0 <= y && y < h) return true;
        else return false;
    };

    auto add = [&](pair<int,int> now,int dx,int dy){
        pair<int,int> ret = make_pair(now.first+dx,now.second+dy);
        return ret;
    };

    auto answer = [&](pair<int,int> now){
        if(now == g){
            cout << ans[now.second][now.first] << endl;
            return true;
        } else return false;
    };

    queue<pair<int,int>> p,q;
    map<pair<int,int>,bool> seen;

    

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

    p.push(s);
    seen[s] = true;
    ans[s.second][s.first] = 0;

    int can = 0;

    while(!p.empty()){
        while(!p.empty()){
            pair<int,int> now = p.front();
            p.pop();
            for(int i = 0; i < 4; i++){
                pair<int,int> nxt = add(now,dx[i],dy[i]);
                if(inout(nxt.first,nxt.second)){
                    if(sur[nxt.second][nxt.first] == '.' && !seen[nxt]){
                        ans[nxt.second][nxt.first] = can;
                        seen[nxt] = true;
                        if(answer(nxt)) return 0;
                        p.push(nxt);
                    } else q.push(now);
                }
            }
        }
        can++;
        while(!q.empty()){
            pair<int,int> now = q.front();
            q.pop();
            for(int i = -2; i < 3; i++){
                for(int j = -2; j < 3; j++){
                    pair<int,int> nxt = make_pair(now.first+i,now.second+j);
                    if(inout(nxt.first,nxt.second)){
                        if(sur[nxt.second][nxt.first] == '.' && !seen[nxt]){
                            ans[nxt.second][nxt.first] = can;
                            seen[nxt] = true;
                            p.push(nxt);
                            if(answer(nxt)) return 0;
                        }
                    }
                }
            }
        }
    }

    cout << -1 << endl;

    return 0;
}


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

vector<string> split(const string &str, char sep) {
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while( getline(ss, buffer, sep) ) {
    v.push_back(buffer);
  }
  return v;
}

int main() {
  string str;
  stack<int> s;
  while (cin >> str) {
    auto f = [&s](function<int(int, int)> g) {
      int a = s.top(); s.pop();
      int b = s.top(); s.pop();
      s.push(g(b, a));
    };
    switch (str[0]) {
      case '+': {
        f([](int a, int b) { return a + b; });
        break;
      }
      case '-': {
        f([](int a, int b) { return a - b; });
        break;
      }
      case '*': {
        f([](int a, int b) { return a * b; });
        break;
      }
      default: s.push(stoi(str));
    }
  }
  cout << s.top() << endl;
  return 0;
}



Measured memory_bytes: 3188
import java.util.Scanner;

class Main{
	public static void main(String[] args) 	{
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a < b) System.out.printf("a < b\n");
		if(a > b) System.out.printf("a > b\n");
		if(a == b) System.out.printf("a == b\n");
		sc.close();
	}	
}


Measured memory_bytes: 26108
#include<bits/stdc++.h>
using namespace std;
int main(){
  char mark[]={'S','H','C','D'},c;
  int d[4][13]={0},n,m;
  cin>>n;
  for(int i=1;i<=n;++i){
    cin>>c>>m;
    switch(c){
    case 'S':
      d[0][m-1]=1;
      break;
    case 'H':
      d[1][m-1]=1;
      break;
    case 'C':
      d[2][m-1]=1;
      break;
    case 'D':
      d[3][m-1]=1;
      break;
    }
  }
  for(int i=0;i<4;++i)
    for(int j=0;j<13;++j)
      if(!d[i][j]) cout<<mark[i]<<" "<<j+1<<endl;
  return 0;
}


Measured memory_bytes: 3088
#include<iostream>
typedef long long ll; 
using namespace std;

int main(){
    ll num[3];
    for(int i = 0; i < 3; i++){
        cin >> num[i];
    }

    sort(num, num + 3);

    
    for (int i = 0; i < 3; i++){
        if(num[i] % 2== 0){
            cout << 0 << endl;
            return 0;
        }
    }

    cout << num[0] * num[1] << endl;
    return 0;
}

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

int main(){
    double n, k; cin >> n >> k;
    vector<double> a(100000);
    double mini_ids = 0;
    for(double i=0; i<n; i++){
        cin >> a[i];
        if(a[i]==1) mini_ids = i;
    }
    mini_ids++;
    double ans = ceil(mini_ids/(k-1)) + ceil((n-mini_ids)/(k-1));
    ans = ceil((n-1)/(k-1));
    cout << (int)ans << endl;
    return 0;

}

Measured memory_bytes: 4120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

int main(){
    ll a,b;cin>>a>>b;
    ll p,q,r;cin>>p>>q>>r;
    ll A,B;
    A=p*a;
    B=0;
    A=p*b;
    B=q*(b-a);
    if(A>B){
        double ans;
        ans=(double)(p*b+b*r+a*q)/(q+r);
        cout<<setprecision(20)<<ans<<endl;
    }else{
        
    }
    
    
    
    return 0;
}



Measured memory_bytes: 3296
using Yorukatsu028.Questions;
using Yorukatsu028.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu028.Questions
{
    /// <summary>
    /// ARC068 C
    /// </summary>
    public class QuestionC : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var x = inputStream.ReadLong();

            var elevenCount = x / 11;
            x -= 11 * elevenCount;
            long count = 2 * elevenCount;

            if (x == 0)
            {
                yield return count;
            }
            else if (x <= 6)
            {
                yield return count + 1;
            }
            else
            {
                yield return count + 2;
            }
        }
    }
}


namespace Yorukatsu028
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionC();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu028.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu028.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13140
def dist(x1, y1, x2, y2):
    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5

n = int(input())
x = []
y = []
for i in range(n):
    seg = input().split()
    x.append(float(seg[0]))
    y.append(float(seg[1]))

edges = n * (n - 1) / 2
frac = 1
for i in range(1, n + 1):
    frac *= i
mul = frac * (n - 1) / edges

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        ans += dist(x[i], y[i], x[j], y[j])

print(ans * mul / frac)


Measured memory_bytes: 3188
/*input
5
1 2 3 4 5
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
 
const int MOD = 1e9 + 7;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int i = 0;
    int j = 0;
    while(i < n)
    {
    	while(i < n && a[i] != j + 1) i++;
    	if(i == n) break;
    	j = a[i];
    	i++;
    }
    if(!j) cout << -1;
    else cout << n - j;
 
    return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			int count = Integer.parseInt(br.readLine());

			if (count == 0) {
				break;
			}

			String[] str = br.readLine().split(" ");
			double[] nums = new double[count];
			double sum = 0;
			for (int i = 0; i < count; i++) {
				nums[i] = Double.parseDouble(str[i]);
				sum += nums[i];
			}
			double avg = sum / count;
			double s = 0;

			for (int i = 0; i < count; i++) {
				s += Math.pow((nums[i] - avg),2);
			}
			System.out.println(Math.sqrt(s / count));
		}
	}
}

Measured memory_bytes: 26296
#include<bits/stdc++.h>
using namespace std;
 // upsolving . other coder's code. 
#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define pb push_back
#define ll long long
 
const int N = 1e5 + 10;
const ll oo = 1e18;
 
int n;
int a[20][20];
ll f[N];
 
ll calc(int mask) {
    ll res = 0ll;
    FOR(i, 1, n) FOR(j, 1, i - 1) if(((1 << (i - 1)) & mask) && ((1 << (j - 1)) & mask))
        res += 1ll * a[i][j];
    return res;
}
ll solve(int mask)  {
    if(!mask) return 0;
    if(f[mask] > -oo) return f[mask];
    int pos = 0;
    while(!(mask & (1 << pos))) pos ++;
    ll &res = f[mask];
    for(int submask = mask; submask; submask = ((submask - 1) & mask))
        if(submask & (1 << pos))
            res = max(res, solve(mask ^ submask) + calc(submask));
    return res;
}
 
signed main()
{
    //freopen("test.inp", "r", stdin);
    scanf("%d", &n);
    FOR(i, 0, N - 1) f[i] = -oo;
    FOR(i, 1, n) FOR(j, 1, n) scanf("%d", &a[i][j]);
    printf("%lld", solve((1 << n) - 1));
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int h, w;
string s[1010];
int d[1010][1010];
int dy[4] = {-1, 0, 1, 0};
int dx[4] = { 0, 1, 0, -1};
bool contain(int y, int x){
   return (0 <= y && y < h && 0 <= x && x < w);
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    rep(i, 0, h){
        cin >> s[i];
    }
    queue<P> q;
    rep(i, 0, h){
        rep(j, 0, w){
            d[i][j] = INF;
            if(s[i][j] == '#'){
                d[i][j] = 0;
                q.push({i, j});
            }
        }
    }
    while(!q.empty()){
        P p = q.front(); q.pop();
        rep(i, 0, 4){
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if(!contain(ny, nx)) continue;
            if(d[ny][nx] != INF) continue;
            d[ny][nx] = d[p.first][p.second] + 1;
            q.push({ny, nx});
        }
    }
    int ans = 0;
    rep(i, 0, h) rep(j, 0, w) ans = max(ans, d[i][j]);
    cout << ans << endl;
}

Measured memory_bytes: 25524
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MOD = 998244353;
const int MAX = 2e5 + 5;
ii robots[MAX];
int memo[MAX], nxt[MAX];
int n;

inline int add(int a, int b) {
    return (a + b) % MOD;
}

int roll(int idx) {
    if (idx > n) {
        return 1;
    }
    int &ans = memo[idx];
    if (~ans) {
        return ans;
    }
    ans = add(roll(idx + 1), roll(nxt[idx]));
    return ans;
}

int aaa[MAX];

int dumb(int x) {
    if (aaa[x] > 0) return aaa[x];
    int &until = aaa[x];
    until = x;
    fori (i, x + 1, n + 1) {
        if (robots[x].first + robots[x].second <= robots[i].first) break;
        until = max(until, dumb(i));
    }
    return until;
}

void solve() {
    cin >> n;
    fori (i, 1, n + 1) cin >> robots[i].first >> robots[i].second;
    sort(robots + 1, robots + n + 1);
    vector<ii> stac;
    ford (i, n, 1) {
        int farthest = lower_bound(robots + 1, robots + n + 1, ii(robots[i].first + robots[i].second, 0)) - robots - 1; 
        int got = -1;
        int left = 0, right = (int) stac.size() - 1;
        while (left <= right) {
            int mid = (left + right) / 2;
            if (stac[mid].first <= farthest) {
                got = stac[mid].second - 1;
                right = mid - 1;
            }
            else {
                left = mid + 1;
            }
        }
        nxt[i] = max(farthest, got) + 1;
        while (!stac.empty() and nxt[i] >= stac.back().second) {
            stac.pop_back();
        }
        stac.emplace_back(i, nxt[i]);
    }
    memset(memo, -1, sizeof memo);
    cout << roll(1) << endl;
}

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



Measured memory_bytes: 9600
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
typedef long double ll;
using namespace std;

int main()
{
   ll a,b,h,m;
   cin>>a>>b>>h>>m;
   ll f=5.0/6;
   //cout<<f<<" ";
   ll ang=abs(6-0.5)*(h*60+m);
   ang=ang/(180.0);
   ang=ang*(M_PI);
   ll c=max(a,b);
   ll d=min(a,b);
   ll j=a*a-2.0*a*b*(cos(ang))+b*b;
   ll o=(long double)pow(j,0.5);
   cout <<setprecision(11) << fixed;
   cout<<o;
   
   
}


Measured memory_bytes: 4168
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;

int main(){
  ll a,b,c=100000000000,d=0,e,f,g,h,m,n,ans=0;
  cin>>n;
  int aa[n];
  rep(i,0,n){
    cin>>aa[i];
  }
  rep(i,0,101){
    rep(j,0,n){
      d+=(aa[j]-i)*(aa[j]-i);
    }
    c=min(c,d);
    d=0;
  }
  co(c);
  
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
int main()
{
    //freopen("a.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    int sum=0;
	for(int i=1;i<=n;i++)sum+=a[i];
	double lim=1.0*sum/(4*m);
	for(int i=1;i<=n;i++){
		if(a[i]>=lim)m--;
	}
	if(m>0)cout<<"No\n";
	else cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 1000000007
using namespace std;
int main()
{
    speed_up
    ll n,sum=0,mn=MAX,neg=0,zr=0,ans;cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
	{
	  cin>>a[i];sum+=abs(a[i]);
	  if(a[i]<0) neg++;
	  if (a[i]==0) zr++;
	  mn=min(mn,abs(a[i]));
	} 
	if(neg%2==0 ||zr) ans=sum;
	else ans=sum-2*mn;
	cout<<ans;
	
     
	
	
	
	
	
 return 0;
}

Measured memory_bytes: 1024
import java.io.File;
import java.io.IOException;
import java.util.*;

import javax.swing.plaf.synth.SynthSeparatorUI;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String t = sc.next();
		char[] ss = s.toCharArray();
		Arrays.sort(ss);
		char[] tt = t.toCharArray();
		Arrays.sort(tt);
		
		int lenS = s.length();
		int lenT = t.length();
		int len = lenS;
		if(lenS > lenT) len = lenT;
		
		for(int i = 0; i < len; i++){
			if(ss[i] < tt[lenT-i-1]){
				System.out.println("Yes");
				return;
			}
			if(ss[i] > tt[lenT-i-1]){
				System.out.println("No");
				return;
			}
		}
		
		System.out.println((lenS < lenT) ? "Yes" : "No");
	}
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

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

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll i = 1; i < N; ++i) {
    ans += (N - 1) / i;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i,n) for (int i= 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n) {
     cin >> v[i];
  }
  sort(v.begin(), v.end());
  double ans = v[0];
  for ( int i = 1; i <n;i++) ans = (ans + v[i])/2;
  printf("%.10f\n",ans);
  return 0;
  }

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

int main(){
	int a[6],num,x,y;
	for(int i=0;i<6;i++)cin>>a[i];
	cin>>num;
	for(int i=0;i<num;i++){
		cin>>x>>y;
		if(x==a[0]&&y==a[1]||x==a[1]&&y==a[5]||x==a[5]&&y==a[4]||x==a[4]&&y==a[0]){
			cout<<a[2]<<endl;
		}

		if(x==a[1]&&y==a[0]||x==a[5]&&y==a[1]||x==a[4]&&y==a[5]||x==a[0]&&y==a[4]){
			cout<<a[3]<<endl;
		}

		if(x==a[3]&&y==a[1]||x==a[1]&&y==a[2]||x==a[2]&&y==a[4]||x==a[4]&&y==a[3]){
			cout<<a[0]<<endl;
		}

		if(x==a[1]&&y==a[3]||x==a[2]&&y==a[1]||x==a[4]&&y==a[2]||x==a[3]&&y==a[4]){
			cout<<a[5]<<endl;
		}

		if(x==a[0]&&y==a[3]||x==a[3]&&y==a[5]||x==a[5]&&y==a[2]||x==a[2]&&y==a[0]){
			cout<<a[1]<<endl;
		}

		if(x==a[3]&&y==a[0]||x==a[5]&&y==a[3]||x==a[2]&&y==a[5]||x==a[0]&&y==a[2]){
			cout<<a[4]<<endl;
		}		
	}
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLL = vector<PLL>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();
const unsigned long long int ULLINF = numeric_limits<unsigned long long int>::max();

int main(){

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

	LL h, w, ch, cw, dh, dw;
	cin >> h >> w >> ch >> cw >> dh >> dw;
    ch--; cw--; dh--; dw--;
	vector<string> s(h);
    REP(i,h) cin >> s[i];

	queue<PLL> que, que2;
    que.push(PLL(ch, cw));

    vector<VLL> cost(h, VLL(w, INF));
    cost[ch][cw] = 0;

    while(!que.empty()||!que2.empty()) {

        if (!que.empty()) {
            auto cur = que.front();
            que2.push(PLL(cur.first, cur.second));
            que.pop();
            REP(i,4) {
                LL ny = cur.first + dx[i];
                LL nx = cur.second + dy[i];
                if (ny<0 || ny>=h || nx<0 || nx>=w || s[ny][nx]=='#') continue;
                if (cost[cur.first][cur.second] < cost[ny][nx] && s[ny][nx]=='.') {
                    cost[ny][nx] = cost[cur.first][cur.second];
                    que.push(PLL(ny, nx));
                }
            }
        }

        else {
            auto cur = que2.front();
            que2.pop();
            for (int i=-2; i<=2; i++) {
                for (int j=-2; j<=2; j++) {
                    LL ny = cur.first + i;
                    LL nx = cur.second + j;
                    if (ny<0 || ny>=h || nx<0 || nx>=w || s[ny][nx]=='#') continue;
                    if (cost[cur.first][cur.second] + 1 < cost[ny][nx] && s[ny][nx]=='.') {
                        cost[ny][nx] = cost[cur.first][cur.second] + 1;
                        que.push(PLL(ny,nx));
                        //que2.push(PLL(ny, nx));
                    }
                }
            }
        }
    }

    if (cost[dh][dw]==INF) cout << -1 << endl;
    else cout << cost[dh][dw] << endl;

	return 0;
}


Measured memory_bytes: 13572
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main()
{
	int d, t;
	cin >> d;
	vector<int> c(26);
	rep(i, 0, 26)cin >> c[i];
	vector<vector<int>> s(d, vector<int>(26));
	vector<int> last(26, 0);
	rep(i, 0, d) {
		rep(i2, 0, 26)cin >> s[i][i2];
	}
	rep(i, 1, d + 1) {
		int p = 0;
		rep(j, 0, 26) {
			if (s[i - 1][j] > s[i - 1][p])p = j;
		}
		printf("%d\n", p + 1);
	}
	//ll ans = 0;
	/*rep(i, 1, d + 1) {
		cin >> t;
		t--;
		last[t] = i;
		ans += s[i - 1][t];
		rep(i2, 0, 26)ans -= c[i2] * (i - last[i2]);
		printf("%lld\n", ans);
	}*/
	return 0;
}

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

namespace ABC105
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = new int[] { 1, 2, 3, 5, 6, 9, 10, 13, 17 };
            string ans = "Yes";
            for (int i = 0; i < a.Length; i++)
            {
                if (n == a[i]) { ans = "No"; break; }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>

using namespace std;

int main() {
    int N; cin >> N;
    double x=0, ans=0;
    string u;
    
    for (int i = 0; i < N; i++) {
        cin >> x >> u;
        if (u == "BTC") {
            ans += x * 380000.0;
        }
        else {
            ans += x;
        }
    }
    printf("%f", ans);

    return 0;
} 


Measured memory_bytes: 256
#include<cstdio>
char S[1000010];
bool del[1000010];
int main(){
	scanf("%s",S);
	int n=0,c[3]={0};
	for(int i=0;S[i];del[i++]=0)if(!n||S[n-1]+'A'!=S[i])c[S[n++]=S[i]-'A']++;
	int x=0,y;
	for(int i=1;i<3;i++)c[i]<c[x]?x=i:1;
	y=(x+1+(c[(x+1)%3]<c[(x+2)%3]))%3;
	char*s=S;
	if(*s==y&&c[y]>c[x^y^3])s++,n--,c[y]--;
	if(s[n-1]==y&&c[y]>c[x^y^3])n--,c[y]--;
	int m=c[x]+(*s!=x)+(s[n-1]!=x)-1,k=0;
	for(int i=1;i+1<n;i++)if(s[i]==y&&s[i-1]==x&&s[i+1]==x)k++;
	for(int i=1;i+1<n&&k*2>m;i++)
		if(S[i]==y&&S[i-1]==x&&S[i+1]==x)del[i-1]=1,m--,k--;
	m=n;n=c[0]=c[1]=c[2]=0;
	for(int i=0;i<m;i++)if(!del[i]&&(!n||S[n-1]!=s[i]))c[S[n++]=s[i]]++;
	for(int l=0,r=0;l<n;l=r){
		if(S[l]==x)putchar('A'+x),r++;
		else{
			for(;r<n&&S[r]!=x;r++);
			m=l>0&&r<n;
			if(r-l-1>=m&&c[S[l]]>c[x^S[l]^3])c[S[l++]]--;
			if(r-l-1>=m&&c[S[r-1]]>c[x^S[r-1]^3])c[S[--r]]--;
			while(c[y]>c[x]&&c[x^y^3]>c[x]&&r-l-2>=m)l+=2,c[y]--,c[x^y^3]--;
			for(;l<r;l++)putchar('A'+S[l]);
			if(r<n&&S[r]!=x)r++;
		}
	}
	puts("");
}

Measured memory_bytes: 3072
//Collatz Problem

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    int s;cin>>s;
    vector<int> m(1000000);
    m[s]=1;int i;
    for(i = 1;;i++){
        if(s%2==0)s/=2;
        else s=3*s+1;
        m[s]+=1;
        if(m[s]==2)break;
    }
    cout << i+1 << endl;
    return 0;
}

Measured memory_bytes: 4096
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	diameter_of_a_tree
# CreatedDate:  2020-07-10 20:12:23 +0900
# LastModified: 2020-07-29 00:12:01 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from collections import deque


class Graph():
    def __init__(self, vertex):
        self.V = vertex
        self.path = [[] for _ in range(self.V)]
        self.distance = [0] * self.V
        self.Q = deque()

    def addedge(self, s, t, w):
        self.path[s].append([w, t])
        self.path[t].append([w, s])

    def bfs(self, init):
        prev = init
        self.Q.append([init, prev])
        while self.Q:
            u, prev = self.Q.popleft()
            for w, v in self.path[u]:
                if self.distance[u] + w > self.distance[v] and prev != v:
                    self.distance[v] = self.distance[u] + w
                    self.Q.append([v, u])

        return max(self.distance), self.distance.index(max(self.distance))

    def clear(self):
        self.distance = [0] * self.V


def main():
    n = int(input())
    graph = Graph(n)
    for _ in range(n-1):
        s, t, w = map(int, input().split())
        graph.addedge(s, t, w)
    _, nt = graph.bfs(0)
    graph.clear()
    ans, _ = graph.bfs(nt)
    print(ans)


'''
    for init in range(n):
        ans = max(ans, graph.bfs(init))
        graph.clear()
'''
    

if __name__ == "__main__":
    main()



Measured memory_bytes: 49636
#include<bits/stdc++.h>
using namespace std;
bool check ( string a ) {
	for ( int i = 0; i < a.size(); i++ ) {
		string tmp;
		for ( int j = 0; j < i; j++ )
			tmp += a[j];

	}
}
int main() {
	string a;
	cin >> a;
	int maxn = 0;
	int siz = a.size();
	for ( int i = 0; i < siz; i++ ) {
		string tmp;
		a.pop_back();
		int sizz = a.size();
		if ( sizz & 1 != 0 )
			continue;
		else {
			for ( int j = 0; j < sizz / 2; j++ )
				tmp += a[j];
			if ( a.rfind ( tmp ) == sizz / 2 ) {
				cout << siz - i - 1 << endl;
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using lli = unsigned long long;

lli X;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	lli v = 100;
	int ans = 0;
	cin >> X;
	while (v < X)
	{
		v += v / 100;
		++ans;
	}
	cout << ans;
}

Measured memory_bytes: 3652
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut ans: u128 = 1;
    for _ in 0..n {
        let i: u128 = read();

        if ans * i > 10u128.pow(18) {
            ans = 10u128.pow(18)+1;
        } else {
            ans *= i;
        }
    }
    if ans > 10u128.pow(18) {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}


Measured memory_bytes: 2176
#include <stdio.h>
int main(void){
   int i,N,a,b,c;
   scanf("%d",&N);
   for(i=1;i<=N;i++){
       scanf("%d %d %d",&a,&b,&c);
   if ((a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a)
     && (a > 0 && b > 0 && c > 0)) {
       printf("YES\n");
   }
 else {
   printf("NO\n");
 }  
     }
   return 0;   
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s, t;
    getline(cin, s);
    getline(cin, t);
    int dp[3001][3001];
    int n = s.length(), m = t.length();
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++){
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            if (s[i - 1] == t[j - 1])
                dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
        }
    /*
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++)
            cout << dp[i][j] <<" ";
        cout <<"\n";
    }
    */
    int r = n, c = m;
    
    string a = "";
    for (int i = 0; i < dp[n][m]; i++){
        while (dp[r][c] == dp[r - 1][c])
            r--;
            
        a += s[r - 1];
        
        r--;
        
        while (dp[r][c] == dp[r][c - 1])
            c--;
    }
    reverse(a.begin(), a.end());
    cout << a << "\n";
    //cout << dp[n][m] <<"\n";
    return 0;
}

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

int main() {
    int N; cin >> N;
    vector<ll> A(N); for(auto &x : A) cin >> x;
    sort(A.begin(), A.end(), greater<ll>());
    ll a = -1;
    for (int i = 0; i < N-1; i++) {
        if (A[i] == A[i+1]) {
            if (a == -1) {
                a = A[i];
                i++;
            } else {
                cout << a * A[i] << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
    return 0;
}


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///

typedef vvl Matrix;

Matrix add(Matrix a, Matrix b,ll mod) {
	int n = a.size(), m = a[0].size();
	assert(a.size() == b.size() && a[0].size() == b[0].size());
	Matrix res(n, vl(m, 0));
	REP(i, n) {
		REP(j, n) {
			res[i][j] = a[i][j] + b[i][j];
			res[i][j] %= mod;
		}
	}
	return res;
}

Matrix mult(Matrix  a, Matrix b,ll mod) {//a:n*m matrix,b:m*l matrix
	int n = a.size(), m = a[0].size(), l = b[0].size();
	Matrix res(n, vl(l, 0));
	REP(i, n) {
		REP(j, l) {
			REP(k, m) {
				res[i][j] += a[i][k] * b[k][j]%MOD;
				res[i][j] %= mod;
			}
		}
		
	}
	return res;
}

Matrix fact(Matrix a, int n,ll mod) {
	Matrix  e(a.size(), vl(a.size(), 0));
	REP(i, a.size()) {
		e[i][i] = 1;
	}
	while (n >= 1) {
		if (n % 2 == 1) e = mult(e, a,mod);
		a = mult(a, a,mod);
		n /= 2;
	}
	return e;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, a, b, c, t;
	while (cin >> n >> m >> a >> b >> c >> t, n) {

		Matrix s(n, vl(1));
		REP(i, n)cin >> s[i][0];
		Matrix v(n, vl(n, 0));
		REP(i, n) {
			if (i != 0)v[i][i - 1] = a;
			if (i != n - 1)v[i][i + 1] = c;
			v[i][i] = b;
		}
		Matrix ans = mult(fact(v, t,m), s,m);
		REP(i, n) {
			cout << ans[i][0];
			if (i != n - 1)cout << " ";
			else cout << endl;
		}
	}
}

Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    string s;
    cin >>s;
    ll ss=s.size(),z=0,o=0;
    for(ll i=0;i<ss;i++){
      if(s[i]=='0') z++;
      else o++;
    }
    cout <<min(z,o)*2<<endl;
  }


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
	
	while (1){
		int N, M, n[1500] = { 0 }, m[1500] = { 0 },now=1,i;
		cin >> N >> M;
		if (N == 0 && M == 0){
			break;
		}
		for (i = 1; i <= N; i++){
			cin >> n[i];
		}
		for (i = 1; i <= M; i++){
			cin >> m[i];
		}
		for (i = 1; i <= 10000; i++){
			now = now + m[i] + n[now + m[i]];
			if (now >= N){
				break;
			}

		}
		cout << i << endl;
	}
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int v[n+1], w[n+1];
  rep(i,n) cin >> v[i+1] >> w[i+1];
  int b = min(n,(1<<9)-1);
  vector<vector<int>> dp(b+1,vector<int>(MAX));
  for(int i = 1; i <= b; i++) {
    vector<int> c;
    int p = i;
    while(p > 0) {
      c.push_back(p);
      p /= 2;
    }
    int l = c.size();
    rep(j,1<<l) {
      int we = 0, va = 0;
      rep(k,l) {
        if(j & (1<<k)) {
          we += w[c[k]];
          va += v[c[k]];
        }
      }
      if(we <= MAX) dp[i][we] = max(dp[i][we],va); 
    }
    for(int j = 1; j < MAX; j++) dp[i][j] = max(dp[i][j],dp[i][j-1]);
  }
  int q;
  cin >> q;
  int ans[q];
  rep(i,q) {
    int p, l;
    cin >> p >> l;
    if(p <= b) ans[i] = dp[p][l];
    else {
      ans[i] = 0;
      vector<int> c;
      while(p > b) {
        c.push_back(p);
        p /= 2;
      }
      int s = c.size();
      rep(j,1<<s) {
        int we = 0, va = 0;
        rep(k,s) {
          if(j & (1<<k)) {
            we += w[c[k]];
            va += v[c[k]];
          }
        }
        if(we <= l) ans[i] = max(ans[i],va+dp[p][l-we]); 
      }
    }
  }
  for(auto x : ans) cout << x << endl;
  return 0;
}


Measured memory_bytes: 206452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    for(int i = 0;i < k;i++){
        if(i % 2 == 0){
            if(a%2 != 0)a--;
            b += a/2;
            a = a/2;
        }
        else{
            if(b%2 != 0)b--;
            a += b/2;
            b = b/2;
        }
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
N = int(input())
def f(n,s):
    if n == 0:
        print(s)
        return
    for i in [chr(ord("a") + i) for i in range(N-n+1)]:
        mx = 0
        for j in s:
            mx = max(mx,ord(j))
        if s != "" and ord(i) - mx > 1:
            return 
        f(n-1,s+i)
f(N,"")

Measured memory_bytes: 4340
#pragma GCC optimize(2) 
#include<bits/stdc++.h>
#define rg register
#define il inline
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int O=900010;
int n,m,k;
ll fac[O],inv[O],bin[O],ans,x=1;
il ll C(int xx,int yy){return fac[xx]*inv[yy]%mod*inv[xx-yy]%mod;}
int main(){
	scanf("%d%d%d",&n,&m,&k);n--;
	bin[0]=fac[0]=fac[1]=inv[0]=inv[1]=1ll;
	for(int i=1;i<O;++i)bin[i]=bin[i-1]*3ll%mod;
	for(int i=2;i<O;++i){
		inv[i]=(mod-mod/i)*inv[mod%i]%mod;
		fac[i]=fac[i-1]*i%mod;
	}
	if(m<k)swap(m,k);
	for(int i=2;i<O;++i)inv[i]=inv[i-1]*inv[i]%mod;
	for(int i=0;i<=m+k;++i){
		(ans+=C(n+i,n)*bin[m+k-i]%mod*x%mod)%=mod;
//		printf("%lld %lld %lld %lld\n",C(n+i,n),bin[m+k-i],x,ans<0?ans+mod:ans);
		if(i<k)(x*=2ll)%=mod;
        else if(i<m)x=((x*2ll-C(i,k))%mod+mod)%mod;
        else x=((x*2ll-C(i,k)-C(i,m))%mod+mod)%mod;
	}
	printf("%lld",ans<0?ans+mod:ans);
	return 0;
}


Measured memory_bytes: 21376
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n; cin>>n;
  int c[52];
  for(int i=0; i<52; i++)
    c[i] = 0;
  char s; int num;
  while(n--)
  {
    cin>>s>>num;
    if(s=='S') c[num-1] = 1;
    if(s=='H') c[num+12] = 1;
    if(s=='C') c[num+25] = 1;
    if(s=='D') c[num+38] = 1;
  }
  for(int i = 0; i < 52; i++)
  {
    if(c[i] == 0)
    {
      if (i<13)
        cout << "S " << i+1 << "\n";
      else if (i<26)
        cout << "H " << i%13+1 << "\n";
      else if (i<39)
        cout << "C " << i%13+1 << "\n";
      else
        cout << "D " << i%13+1 << "\n";
    }
  }
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int H,W;
    cin >> H >> W;
    vector<vector<char>> A(H,vector<char>(W));
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            cin >> A[i][j];
        }
    }
    for(int i=0;i < H;i++){
        for(int j = 0; j < W;j++){
            if(j == W-1)cout << A[i][j] << endl;
            else cout << A[i][j];
        }
        for(int j = 0; j < W;j++){
            if(j == W-1)cout << A[i][j] << endl;
            else cout << A[i][j];
        }
    }
}


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;
using P = pair<int,int>;

int main() {
    int a, b, ans=-1;
    cin >> a >> b;

    for (int i=1; i<1100; i++) {
        if (a == floor(i*0.08) && b == floor(i*0.1)) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;

int main() {
  int n;
  cin >> n;
  vi a(n + 1);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  int c = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[a[i]] == i) ++c;
  }
  cout << c / 2 << endl;
  return 0;
}

Measured memory_bytes: 768
N = int(input())
D = [int(i) for i in input().split()]

num_dict = {}
ans = 1

for i in range(N):
  num_dict[D[i]] = num_dict.get(D[i],0) + 1

if num_dict.get(0) == None or num_dict.get(0) >= 2 or D[0] != 0:
  ans = 0
else:
  for i in range(1,len(num_dict)):
    if num_dict.get(i) == None:
      ans = 0
      break
    else:
      ans *= num_dict.get(i-1) ** num_dict.get(i)

print(ans%998244353)


Measured memory_bytes: 19360
#include<stdio.h>
int  main()
{ int n,b;
  scanf("%d",&n);
  long int ar[n],c=0;
 for(b=0;b<n;b++)
   scanf("%ld",&ar[b]);
 for(b=1;b<n;b++)
 { if(ar[b]<ar[b-1])
 {
   c+=ar[b-1]-ar[b];
    ar[b]=ar[b-1]; 
   
 }   
   
 }
  printf("%ld",c);
  
  
  
  
  
  
  
  
}
  
  


Measured memory_bytes: 3248
using System;
using System.Collections.Generic;
using System.Linq;

public struct Robot
{
    public int X;
    public int L;

    public int Left { get { return X - L; } }
    public int Right { get { return X + L; } }

    public Robot(int x, int l)
    {
        X = x;
        L = l;
    }
}

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var robots = new List<Robot>();
        for (int i = 0; i < N; i++)
        {
            var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            robots.Add(new Robot(vals[0], vals[1]));
        }
        robots = robots.OrderBy(r => r.Right).ToList();
        var count = 0;
        var right = int.MinValue;
        foreach (var r in robots)
        {
            if (r.Left >= right)
            {
                count++;
                right = r.Right;
            }
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 22712
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <ctype.h>
#include <fstream>
#include <unordered_map>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;

int n, m;
char a[1002][1002];
LL dp[1002][1002];

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> a[i][j];
	dp[1][1] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			if (a[i][j] == '#')
				continue;
			dp[i][j] += dp[i - 1][j];
			dp[i][j] %= mod;
			dp[i][j] += dp[i][j - 1];
			dp[i][j] %= mod;
		}
	cout << dp[n][m] << endl;
	return 0;
}

/*


*/

Measured memory_bytes: 9088
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#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 hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
    ios
    int a,b;
    cin>>a>>b;

    cout<<(a*b-a-b+1);
}

Measured memory_bytes: 256
#!/usr/bin/env python
import math

l_s = set()
c = 0
n = int(input())
dup = {}

for i in range(n):
    st = sorted(input())
    s  = "".join(st)
    if s in l_s:
        if s in dup.keys():
            dup[s] += 1
        else:
            dup[s] = 1
        c += dup[s]
    l_s.add(s)

print(c)

Measured memory_bytes: 14788
from collections import*
s,_,*q=open(0)
d=deque(s[:-1])
p=1
for q in q:
  try:
    q,f,c=q.split()
    if(f<'2')^p:d+=c,
    else:d.appendleft(c)
  except:p^=1
print(''.join(d)[::p or-1])

Measured memory_bytes: 94116
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
    ll X, N;
    ll mask[105]{ 0 };
    cin >> X >> N;
    rep(i, N) {
        ll tmp;
        cin >> tmp;
        mask[tmp+1] = 1;
    }
//    cout << bitset<100>(bitMask) << endl;
    rep(i,100) {
        if (mask[X-i+1]==0) {
            cout << X- i<< endl;
            break;
        }
        else if (mask[X+i+1]==0) {
            cout << X + i << endl;
            break;
        }
    }
    return 0;
}

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

int main(){
  int N, M;
  cin >> N >>M;
  
  vector<int> vals(M);
  
  for(int i = 0; i < N ; i++){
    int K;
    cin >> K;
    for(int k = 0; k < K ;k++){
      int A;
      cin >> A ;
      vals.at(A-1) ++;
    }
  }
 
  int ans = 0;
  for(int i = 0 ; i < M ; i++){
    if(vals.at(i) == N) ans++;
  }
   
  cout << ans << endl;
  return 0;
  
}


Measured memory_bytes: 384
void main() {
    long[] tmp = readln.split.to!(long[]);
    long n = tmp[0], m = tmp[1];
    long[] a = new long[n], b = new long[n];
    foreach (i; 0 .. n) {
        tmp = readln.split.to!(long[]);
        a[i] = tmp[0], b[i] = tmp[1];
    }
    zip(a, b).sort!((x, y) => x[0] < y[0]);
    long cnt, money;
    foreach (i; 0 .. n) {
        if (cnt + b[i] < m) {
            money += a[i] * b[i];
            cnt += b[i];
        } else {
            money += a[i] * (m - cnt);
            break;
        }
    }
    money.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 4604
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n, steps=0;
    cin >> n;
    ll arr[n], i, tmp;
    for(i=0; i<n; i++){
        cin >> arr[i];
    }
    for(i=0; i<n-1; i++){
        if(arr[i]>arr[i+1]){
            tmp = arr[i]-arr[i+1];
            arr[i+1] += tmp;
            steps += tmp;
        }
    }
    cout << steps << endl;
    return 0;
}


Measured memory_bytes: 5160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll A[100010];
    cin >> N;
    rep(i,0,N) cin >> A[i];
    ll dp[100010][2] = {};
    dp[0][0] = 0;
    dp[0][1] = -INF;
    rep(i,0,N){
        dp[i+1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i]);
        dp[i+1][1] = max(dp[i][1] + A[i], dp[i][0] - A[i]);
    }
    print(dp[N][0]);


}

Measured memory_bytes: 2560
#include"bits/stdc++.h"
using namespace std;
char s[1000000];
char s2[] = { "abcdefghijklmnopqrstuvwxyz" };
char s3[26];
int main() {
	memset(s3, 0, sizeof(s3));
	memset(s, NULL, sizeof(s));
	cin >> s;
	int len = strlen(s);
	for (int i = 0; i < len; i++) {
		for (int j = 0; j < 26; j++) {
			if (s[i] == s2[j]) {
				s3[j]++;
				break;
			}
		}
	}
	for (int i = 0; i < 26; i++) {
		if (s3[i] == 0) {
			cout << s2[i] << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}

Measured memory_bytes: 1280