akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(v) (ll((v).size()))
#define forn(i,n) for(ll i=0;i<(n);i++)
#define forr(i,n) for(ll i=(n)-1;i>=0;i--)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))

const ll mod =1e9+7;

void add_self(ll &a, ll b){a+=b;if(a>=mod)a-=mod;}
void sub_self(ll &a, ll b){a-=b;if(a<0)a+=mod;}
void mul_self(ll &a, ll b){a*=b;a%=mod;}

ll power(ll a, ll x){ll ret=1;while(x){if(x%2)mul_self(ret,a);x/=2;mul_self(a,a);}return ret;}
ll n=10;




struct mat{

	vector<vector<ll> >t;

	mat() { t.resize(n, vector<ll> (n));forn(i,n)t[i][i]=1;}

	mat operator * ( mat const &b)
	{
		mat c;forn(i,n)c.t[i][i]=0;
		forn(i,n)forn(j,n)forn(k,n){ll x=1;mul_self(x,t[i][k]);mul_self(x,b.t[k][j]);add_self(c.t[i][j],x);}
		return c;
	}

	void print(){forn(i,n){forn(j,n)cout<<t[i][j]<<" ";cout<<endl;}cout<<endl;}

};

int main()
{
    ios_base::sync_with_stdio(false);

	ll k;cin>>n>>k;
	mat a,b;
	forn(i,n)forn(j,n)cin>>a.t[i][j];

	while(k)
	{
		if(k%2)b=b*a;
		a=a*a;
		k/=2;
	}

	ll x=0;forn(i,n)forn(j,n)add_self(x,b.t[i][j]);
	cout<<x<<endl;

}


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

typedef long long int ll;

int main(){
  ll n;
  cin>>n;
  ll x=n/500;
  ll ans=0;
  ans+=(x*1000);
  n-=(x*500);
  ans+=(n/5)*5;
  cout<<ans<<endl;

  return 0;
}


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

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

	ll a[n];
	ll abs_min = 1000000001;
	int minus_cnt = 0;
	ll ans=0;

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

		if(a[i] < 0) 
			minus_cnt++;

		if(abs(a[i]) < abs_min)
			abs_min = abs(a[i]);

		ans += abs(a[i]);
	}

	if(minus_cnt % 2 == 1)
		ans -= 2*abs_min;
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int maxN = 100005;

class TaskD {
private:
	Debugger debugger;

public:
	void solveOne(int it){
		int n, m;
		cin >> n >> m;
		vector<vector<int>> graph(n, vector<int>());
		for(int i = 0; i < m; i++){
			int x, y;
			cin >> x >> y;
			x--; y--;
			graph[x].push_back(y);
			graph[y].push_back(x);
		}
		const int INF = 1e9;
		queue<int> q;
		vector<int> dist(n, INF);
		q.push(0);
		dist[0] = 0;
		vector<int> ans(n);
		while(!q.empty()){
			int u = q.front();
			q.pop();
			for(int nxt : graph[u]){
				if(1 + dist[u] < dist[nxt]){
					dist[nxt] = 1 + dist[u];
					q.push(nxt);
					ans[nxt] = u;
				}
			}
		}
		for(int i = 0; i < n; i++){
			if(dist[i] >= INF){
				cout << "No" << endl;
				return;
			}
		}
		cout << "Yes" << endl;
		for(int i = 1; i < n; i++){
			cout << ans[i] + 1 << endl;
		}

	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskD solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 10540
#include<iostream>
#include<vector>
using namespace std;
int main(void){
	int n,m;
	cin>>n>>m;
	vector<int> a(m),b(m);
	vector<int> num(n,0);
	for(int i=0;i<m;i++){
		cin>>a[i]>>b[i];
		num[a[i]-1]++;
		num[b[i]-1]++;
	}
	bool ans=true;
	for(int i=0;i<n;i++){
		if(num[i]%2!=0)ans=false;
	}
	if(ans){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}

	return 0;
}

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

int main() {
  int M,N,i,j;
  cin>>N;
  vector<int> d(N);
  for(i=0;i<N;i++){
    cin>>d.at(i);
  }
  sort(d.begin(),d.end(),greater<int>());

int count=1;
  for(i=1;i<N;i++){
    if(d.at(i-1)!=d.at(i))count++;
  }
  cout<<count<<endl;

}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R


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

	cin >> N;
	vector<int>p(N + 1);
	vector<int>v(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> p[i];
		v[p[i]] = i;
	}
	vector<long long int>closed(N + 1);
	vector<long long int>place(N + 1);
	vector<long long int>op(N + 1);
	for (int i = 1; i <= N; i++)place[i] = closed[i] = i * MOD;
	int m = N;
	for (int i = N; i >= 1; i--) {
		op[i] = --place[min(v[i], m)];
		m = min(m, v[i]);
	}
	//for (int i = 1; i <= N; i++)cout << v[i] << endl;
	vector<pair<long long int, int>>ret;
	for (int i = 1; i <= N; i++) {
		ret.push_back({ op[i],1 });
		ret.push_back({ closed[i],-1 });
	}
	sort(ret.begin(), ret.end());
	vector<int>box(N + 1);
	stack<int>st;
	int usedop = 1;
	int usedcl = 1;
	for (int i = 0; i < ret.size(); i++) {
		if (ret[i].second == 1)st.push(usedop++);
		else {
			box[st.top()] = usedcl++;
			st.pop();
		}
	}
	if (v != box) {
		cout << ":(\n";
		return 0;
	}
	for (auto i : ret) {
		if (i.second == 1)cout << '(';
		else cout << ')';
	}
	cout << endl;
}


Measured memory_bytes: 10172
import Data.List
import Control.Monad

main = do
  [sa, sb, sc] <- replicateM 3 getLine
  putStrLn $ solve 'a' (sa, sb, sc)

solve 'a' ([], _, _) = "A"
solve 'b' (_, [], _) = "B"
solve 'c' (_, _, []) = "C"
solve 'a' (x:xs, sb, sc) = solve x (xs, sb, sc)
solve 'b' (sa, x:xs, sc) = solve x (sa, xs, sc)
solve 'c' (sa, sb, x:xs) = solve x (sa, sb, xs)

Measured memory_bytes: 508
s = input().rstrip()

allow = set(('A', 'T', 'G', 'C'))
maximum = 0

for i in range(len(s)):
    for j in range(len(s)-i):
        tmp = s[i:j+i+1]
        count = tmp.count('A') + tmp.count('G') + tmp.count('T') + tmp.count('C')
        if count == len(tmp):
            if maximum < count:
                maximum = count

print(maximum)


Measured memory_bytes: 3060
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 char") 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 d: Vec<u64> = (0..n).map(|_| read()).collect();
    d.sort();
    println!("{}", d[n / 2] - d[n / 2 - 1]);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
int main(){
 int h,w; cin>>h>>w;
 vector<string> M(h);
 for(int i=0;i<h;i++){
  cin>>M[i];
 }
 for(int i=0;i<h*2;i++){
  for(int j=0;j<w;j++){
   cout<<M[i/2][j];
  }
  cout<<endl;
 }
 return 0;
}

Measured memory_bytes: 256
// C - Many Medians
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vector<pair<int,int>> X(N+1);
	rp(i, 1, N+1){
		int x; cin>>x;
		X[i] = make_pair(x, i);
	}
	sort(all(X));
	vi ans(N+1);
	rp(i, 1, N+1) ans[X[i].second] = i<=N/2? X[N/2 + 1].first: X[N/2].first;
	rp(i, 1, N+1) cout<< ans[i] <<endl;
}

Measured memory_bytes: 4480
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace D_ABC169
{
    class MainClass
    {

        static long[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
            long n = s[0];
            var d = Divisor(n);
            var ans = 0;

            foreach (var item in d)
            {
                // WriteLine(item.Key);
                // WriteLine(item.Value);
                long cnt = item.Value;
                long tmp = 1;
                while (cnt > 0)
                {

                    var div = (long)Pow(item.Value, tmp);
                    n /= div;
                    tmp++;
                    ans++;
                    cnt -= tmp;
                }

            }
            WriteLine(ans);


        }

        public static Dictionary<long, long> Divisor(long l)
        {
            long N = l;
            var dic = new Dictionary<long, long>();
            for (long i = 2; i * i <= N; i++)
            {
                if (l % i != 0) continue;
                long ex = 0;
                while (l % i == 0)
                {
                    ex++;
                    l /= i;
                }
                // WriteLine("dicadd {0}",i);


                dic.Add(i, ex);
            }
            if (l != 1)
            {
                dic.Add(l, 1);
            }

            return dic;
        }
    }
}


Measured memory_bytes: 28528
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,x;
    cin >> n >> x;
    vector<int> l(n);
    for (int i=0;i<n;i++) cin >> l[i];
    int tl=0,ans=1;
    for (int i=0;i<n;i++) {
        tl+=l[i];
        if (tl<=x) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MX 1000005
typedef long long ll;
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define mem(a) memset(a,0,sizeof(a))
map<char,char>mp,mp1;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ////////////////////////////////////
    string s,s1;
    cin>>s>>s1;
    for(int i=0; i<s.size(); i++)
    {
        if(!mp[s[i]])
        {
            mp[s[i]]=s1[i];
        }
        else if(mp[s[i]]!=s1[i])
        {
            cout<<"No"<<endl;
            return 0;
        }
        if(!mp1[s1[i]])
        {
            mp1[s1[i]]=s[i];
        }
        else if(mp1[s1[i]]!=s[i])
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


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

#define froop1(a,n) for(double i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	double N,K,sum = 0;
  cin >> N >> K;
  froop1(1,N+1){
   double present = i,per = 1;
    while(present < K){
      per *= 0.5;
      present *= 2;
    }
    per *= (1 / N);
    sum += per;
  }
	printf("%.12f\n",sum);
return 0;
}

Measured memory_bytes: 3736
# -*- coding: utf-8 -*-

a = list(map(int, input().split()))
K = int(input())

max_sum = max(a)
for i in range(0,K):
    max_sum = max_sum*2

check = 0
for i in a:
    if i == max(a):
        if check == 0:
            check = 1        
        else:
            max_sum = max_sum + i
    else:
        max_sum = max_sum + i

print(max_sum)

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


typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
  //cout.precision(10);
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<pair<int,ll>> a(N);
  rep(i,N){
    cin >> a[i].first;
    a[i].second = i;
  }

  sort(ALL(a));
  
  vector<ll> sum(N);
  
  sum[0] = a[0].first;
  
  rep(i,N-1) sum[i+1] = sum[i] + a[i+1].first;
  
  int tmp = 0;
    
  rep(i,N-1){  //i = 1 ~ N-2
    if(2 * sum[i] < a[i+1].first){
      tmp = i+1;
    }
  }
  
  cout << N - tmp << endl;  
  
}


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

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

// order statistics tree
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> indexed_set;

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

const int N = 1e5+10;

int n;
int even[N], odd[N];

int main() {
  cin.tie(0); cin.exceptions(cin.failbit);

  scanf("%d", &n);
  rep(i, 0, n){
    int v;
    scanf("%d", &v);

    if(i%2==0){
      even[v]++;
    } else {
      odd[v]++;
    }
  }

  // find highest, second highest
  int ehi = 0, ev=0;
  rep(i, 1, N){
    if(even[i] > ehi){
      ehi = even[i];
      ev = i;
    }
  }

  int eshi =0, esv=0;
  rep(i, 1, N){
    if(i == ev) continue;

    if(even[i] > eshi){
      eshi = even[i];
      esv = i;
    }
  }

  // first and second
  int ohi=0, ov = 0;
  rep(i, 1, N){
    if(odd[i] > ohi){
      ohi = odd[i];
      ov = i;
    }
  }

  int oshi=0, osv = 0;
  rep(i, 1, N){
    if(i == ov) continue;
    if(odd[i] > oshi){
      oshi = odd[i];
      osv = i;
    }
  }

  int ans = 0;

  // printf("%d %d, s: %d %d\n", ev, ov, esv, osv);
  if(ev != ov){
    ans = n-ehi-ohi;
  } else {
    if(esv == 0 && osv == 0){ // no secondaries
      ans = n-ehi; // have to change n/2 - ehi + n/2
    } else if(esv && osv){ // both have secondaries
      if(ehi+oshi > ohi+eshi) ans = n-ehi-oshi;
      else ans = n-ohi-eshi;
    } else { // only one has secondary
      if(esv){
        ans = n-ohi-eshi;
      } else if(osv){
        ans = n-ehi-oshi;
      }
    }
  }

  printf("%d\n", ans);

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    double a, b, x;
    cin >> a >> b >> x;
    double ans;
    if (2*x > a*a*b) {
        ans = atan(2*(b-x/(a*a))/a);
    }
    else {
        ans = atan(a*b*b/(2*x));
    }
    ans *= ((double)180/3.14159265358979323846264338327950288419716939937510);

    printf("%.10f", ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        
        int N=sc.nextInt();
        String S=sc.next();
        String[] s=new String[N];
        
        for(int i=0;i<N;i++){
            s[i]=S.substring(i,i+1);
        }
        int ans=0;
        for(int i=1;i<N;i++){
            if(s[i].equals("E")){
                ans++;
            }
        }
        int com=ans;
        for(int i=1;i<N;i++){
            if(s[i].equals("E")){
                com--;
            }
            if(s[i-1].equals("W")){
                com++;
            }
            if(com<ans){
                ans=com;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 53156
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=n-1;i > m;i--)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define RS(n) sort(n.begin(), n.end());reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
int main(){
  lli A,B,C=INF,D=0,E=0,F=INF,G=INF,H=0,N,M,K,S;
  cin >> A >> B;
  Out(max(A+B,max(A-B,A*B)));
}


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

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> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = 0; i < (a); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

int digit(ll n) {
  int ret = 0;
  while(n > 0) {
    n /= 10;
    ret++;
  }
  return ret;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  int ans = INF;
  for(ll i = 1LL; i * i <= n; ++i) {
    if(n % i == 0) {
      ans = min(ans, max(digit(n / i), digit(i)));
    }
  }
  out(ans);
  return 0;
}


Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        m: usize,
    }

    println!("{}", (n-1)*(m-1));
}


Measured memory_bytes: 2172
import Control.Applicative
import Text.Printf

main :: IO ()
main = do
  [a, b] <- map read . words <$> getLine
  let (s, p) = solve a b
  printf "%d %d\n" s p

solve :: Int -> Int -> (Int, Int)
solve a b = (a * b, 2 * (a + b))



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

int main(){
    int d[12]={1,6,36,216,1296,7776,46656,9,81,729,6561,59049};
    int dp[100100];
    fill(dp,dp+100100, 101000);
    dp[0]=0;
    for(int i=0; i<100100; i++){
        for(int j=0; j<12; j++){
            if(i+1-d[j]>=0){
                dp[i+1]=min(dp[i+1], dp[i+1-d[j]]+1);
            }
        }
    }
    int N;
    cin >> N;
    cout << dp[N] << endl;
}

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



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
 
   
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans = 1;
    for(int i=1;i<n;i++){
        if(s[i]!=s[i-1]) ans++;
    }
    cout << ans << endl;
}

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

int H, W;
string S[410];

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) cin >> S[i];

    UnionFind tree(H*W);

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (i >= 1 && S[i][j] != S[i-1][j]) {
                tree.unite(W*i+j, W*(i-1)+j);
            }
            if (j >= 1 && S[i][j] != S[i][j-1]) {
                tree.unite(W*i+j, W*i+(j-1));
            }
            if (i <= H-2 && S[i][j] != S[i+1][j]) {
                tree.unite(W*i+j, W*(i+1)+j);
            }
            if (j <= W-2 && S[i][j] != S[i][j+1]) {
                tree.unite(W*i+j, W*i+(j+1));
            }
        }
    }

    map<int, pair<ll, ll> > mp;
    for (int i = 0; i < H*W; i++) {
        int white = mp[tree.root(i)].first;
        int black = mp[tree.root(i)].second;
        if (S[i/W][i%W] == '#') {
            mp[tree.root(i)] = make_pair(white, black+1);
        }
        else {
            mp[tree.root(i)] = make_pair(white+1, black);
        }
    }    

    ll ans = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        ll white = itr->second.first;
        ll black = itr->second.second;
        ans += white * black;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007



int main() {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    vi L, R;
    bool f;
    if (S[0] == '1') {
        L.pb(0); f = true;
    }
    else {
        R.pb(0); f = false;
    }
    rep(i, N - 1) {
        if (S[i + 1] != S[i]) {
            if (f) {
                f = false;
                R.pb(i + 1);
            }
            else {
                f = true;
                L.pb(i + 1);
            }
        }
    }

    R.pb(N);

    int ans = 0;

    if((int)R.size() -1 <= K) {
         ans = N;
    }
    else {
        ans = max(ans, R[K]);

        int i;
        if (R[0] == 0) i = 0;
        else i = 1;

        int j = 1;

        while (R[K + j] < N) {
            ans = max(ans, R[K + j] - L[i]);
            i++; j++;
        }

        ans = max(ans, N - L[i]);

    }

    cout << ans << endl;

}


Measured memory_bytes: 1024
def MM(num: int):
    return 1 <= num <= 12

def solve():
    S = input()
    first = int(S[:2])
    second = int(S[2:])
    if MM(first) and MM(second):
        print('AMBIGUOUS')
    elif MM(first):
        print('MMYY')
    elif MM(second):
        print('YYMM')
    else:
        print('NA')

solve()

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

vector<vector<pair<int,int64_t>>> G;
vector<int64_t> r;

void DFS(int a){
  for(pair<int,int64_t> x:G.at(a)){
    int b;
    int64_t l;
    tie(b,l)=x;
    if(r.at(b)==-1){
      r.at(b)=r.at(a)+l;
      DFS(b);
    }
  }
}

int main() {
  int N;
  cin>>N;
  r.resize(N);
  G.resize(N);
  r.at(0)=-1;
  for(int i=1;i<N;i++){
    r.at(i)=-1;
    int a,b;
    int64_t c;
    cin>>a>>b>>c;
    a--,b--;
    G.at(a).push_back(make_pair(b,c));
    G.at(b).push_back(make_pair(a,c));
  }
  int Q,K;
  cin>>Q>>K;
  K--;
  r.at(K)=0;
  DFS(K);
  for(int i=0;i<Q;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    cout<<r.at(a)+r.at(b)<<endl;
  }
}

Measured memory_bytes: 15600
import math
N = int(input())

num_list = []
num_list2 = []
for i in range(N):
    num_list.append(int(input()))
    
def isprime(x):
  if x == 2:
    return True

  if x < 2 or x % 2 == 0:
    return False

  i = 3
  while i <= math.sqrt(x):
    if x % i == 0:
      return False
    
    i = i + 2
  return True
  
for i in num_list:
    if not isprime(i):
        continue
    else:
        num_list2.append(i)
  
print(len(num_list2))


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

typedef tuple<double, long long, long long> TP;

int main()
{
	int N;
	cin >> N;
	vector<TP> xy( N * 2 );
	for( int i = 0; i < N; i++ ) {
		cin >> get<1>( xy[i] ) >> get<2>( xy[i] );
		get<0>( xy[i] ) = atan2( (double)get<2>( xy[i] ), (double)get<1>( xy[i] ) );
	}

	sort( xy.begin(), xy.begin() + N );
	for( int i = 0; i < N; i++ ) {
		xy[i + N] = xy[i];
	}
	long long ans = 0;
	for( int i = 0; i < N; i++ ) {
		long long x = 0;
		long long y = 0;
		for( int j = i; j < i + N; j++ ) {
			x += get<1>( xy[j] );
			y += get<2>( xy[j] );
			ans = max( ans, x * x + y * y );
		}
	}

	cout << fixed << setprecision(12) << sqrt( (double)ans ) << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define cls(s,v) memset(s,v,sizeof(s))
#define mp(a,b) make_pair<int,int>(a,b)
#define cp pair<int,int>
using namespace std;
const int maxn = 200005,maxm = 100005,INF = 0x3f3f3f3f;
inline int read(){
	int out = 0,flag = 1; char c = getchar();
	while (c < 48 || c > 57){if (c == '-') flag = 0; c = getchar();}
	while (c >= 48 && c <= 57){out = (out << 1) + (out << 3) + c - 48; c = getchar();}
	return flag ? out : -out;
}
char s[maxn];
int main(){
	int n = read();
	scanf("%s",s + 1);
	int l = 1,r = n,ans = 0;
	while (l < r){
		while (l < r && s[l] == 'R') l++;
		while (l < r && s[r] == 'W') r--;
		if (l < r && s[l] == 'W' && s[r] == 'R') ans++,s[l] = 'R',s[r] = 'W';
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3924
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    n: usize, k: usize,
    ab: [(i32, i32); n-1],
    }
    let mut g: Vec<Vec<i32>> = vec![vec![]; n];
    for i in 0..n-1 {
        let (a, b) = ab[i];
        g[(a-1) as usize].push(b-1);
        g[(b-1) as usize].push(a-1);
    }
    let ans = dfs(&g, 0, -1, k, k);
    println!("{}", ans);
}

const MOD: usize = 1_000_000_000 + 7;

fn dfs(ref g: &Vec<Vec<i32>>, x: i32, y: i32, f: usize, k:usize) -> usize {
    let mut case_num = f;
    let mut color_num = if f == k {
         k - 1
    } else {
         k - 2};
    for u in &g[x as usize] {
        let u = *u;
        if u == y {
            continue;
        }
        let tmp = dfs(&g, u, x, color_num, k);
        if tmp == 0 {
            case_num = 0;
            break;
        }
        case_num = case_num * tmp % MOD;
        color_num -= 1;
    }
    return case_num
}

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

int main(){
    ll N,M;cin>>N>>M;
    ll ans=0;
    if(N>=3 and M>=3)ans=(N-2)*(M-2);
    else if(N==1 and M==1)ans=1;
    else if(N==1 or M==1)ans=N*M-2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
start=time.time()
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n=ri()

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
print(num2alpha(n).lower())

Measured memory_bytes: 61984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long ul;
// for文短縮類
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)

// iteratorのbeginとendをまとめて渡す
#define ALL(x) (x).begin(), (x).end()
//略
#define PB push_back  // vectorヘの挿入
#define MP make_pair  // pairのコンストラクタ
#define F first       // pairの一つ目の要素
#define S second      // pairの二つ目の要素
//出力
#define COUT(x) cout << (x) << endl
#define SCOUT(x) cout << (x) << " "
#define ENDL cout << endl
/************ Combination wtih MOD ************
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// preprocess for some tables
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
// combination
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

ll const MOD = 1000000007;
int main(int argc, char *argv[])
{
    // input高速化。cinとcoutの結合解除。scanfとprintfは使えない。
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    ll n, m;
    cin >> m >> n;

    ll ans = 1;

    while(n != 0){
        if(n & 1 == 1){
            ans *= m;
            ans %= MOD;
        }

        m *= m;
        m %= MOD;
        n >>= 1;
    }

    cout << ans << endl;

}


Measured memory_bytes: 3188
#include <stdio.h>
#include <string.h>

int main()
{
	char s[102],
	     sDouble[204],
	     p[102];
	char *presult;
	
	scanf("%s",s);
	strncpy(sDouble,s,sizeof(s)-1);
	strncat(sDouble,s,(sizeof(s)/2));
	scanf("%s",p);
	presult = strstr(sDouble,p);
	
	(presult == NULL) ? printf("%s\n","No") : printf("%s\n","Yes");
	return 0;
}

Measured memory_bytes: 544
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
        int N, K, h;
        cin >> N >> K;
        
        int answer = 0;
        
        for (int i = 0; i < N; i++)
        {
                cin >> h;
                if (h >= K) answer++;
        }
        
        cout << answer << endl;
        
        return (0);
        }

Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end
N=gets.to_i
s=array(N)
N.times do|i|
    s[i]=gets.chomp
end
s.sort!
M=gets.to_i
t=array(M)
M.times do|i|
    t[i]=gets.chomp
end
ans=0
i=0
while i<N
    cnt_s=s.count(s[i])
    cnt_t=t.count(s[i])
    val=cnt_s-cnt_t
    ans=(val>ans ? val : ans)
    i+=cnt_s
end
puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    vector<ll> a(n);
    map<ll,ll> mp;
    rep(i,n) {
        cin>>a[i];
        a[i]-=i;
        mp[a[i]]++;
    }
    ll res = 0;
    rep(i,n) {
        mp[a[i]]--;
        ll cur = -1 * (a[i] + 2*i);
        res += mp[cur];
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 27392
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n;
  cin >> n;
  map<int,int>mp1;
  map<int,int>mp2;
  rep(i,n){
    int x;
    cin >> x;
    mp1[i+1]=x;
    mp2[x]=i+1;
  }
  int m;
  cin >> m;
  rep(i,m){
    int a;
    cin >> a;
    if(mp1[a]==2019 ||mp2[mp1[a]+1]>0)continue;
    mp2[mp1[a]]=0;
    mp2[mp1[a]+1]=a;
    mp1[a]++;
  }
  for(auto p:mp1){
    cout << p.second << endl;
  }
  return 0;
}



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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int a; cin >> a;
	cout << a + a*a + a*a*a << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3688
#include<iostream>

using namespace std;

int main()
{
	int x;
	cin>>x;
	if(x>=400&&x<=599) cout<<8<<endl;
	else if(x>=600&&x<=799) cout<<7<<endl;
	else if(x>=800&&x<=999) cout<<6<<endl;
	else if(x>=1000&&x<=1199) cout<<5<<endl;
	else if(x>=1200&&x<=1399) cout<<4<<endl;
	else if(x>=1400&&x<=1599) cout<<3<<endl;
	else if(x>=1600&&x<=1799) cout<<2<<endl;
	else if(x>=1800&&x<=1999) cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 3632
N, A, B, C = gets.split.map(&:to_i)
l = N.times.map{gets.to_i}
INF = 9999999999

def bmb(a, b, c, n, l)
  if n < N
    adda = bmb(a+l[n], b, c, n+1, l) + (a == 0 ? 0 : 10)
    addb = bmb(a, b+l[n], c, n+1, l) + (b == 0 ? 0 : 10)
    addc = bmb(a, b, c+l[n], n+1, l) + (c == 0 ? 0 : 10)
    addno = bmb(a, b, c, n+1, l)
    return [adda, addb, addc, addno].min
  else
    if a * b * c == 0
      return INF
    else
      return (A-a).abs + (B-b).abs + (C-c).abs
    end
  end
end

puts bmb(0, 0, 0, 0, l)

Measured memory_bytes: 1788
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, X, Y = map(int, readline().split())

    X -= 1
    Y -= 1

    ans = [0] * N

    for i in range(N - 1):
        for j in range(i + 1, N):
            d = min(j - i, abs(i - X) + 1 + abs(Y - j), abs(j - X) + 1 + abs(X - i))
            ans[d] += 1

    print('\n'.join(map(str, ans[1:])))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 74312
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =1e6+10;
const int mod=1e9+7;

int h,w,k;
int sx,sy,ex,ey;
string s[maxn];
vector<vector<int>>d(maxn);
int xx[5]={58,0,0,1,-1};
int yy[5]={58,1,-1,0,0};

struct ac
{
    int x,y,step;
};

void bfs()
{
    queue<ac>q;
    q.push({sx,sy,0});
    d[sx][sy]=0;
    while(!q.empty())
    {
        ac u=q.front();
        q.pop();
        for(int i=1;i<=4;i++)
        {
            for(int j=1;j<=k;j++)
            {
                int tx=u.x+xx[i]*j;
                int ty=u.y+yy[i]*j;
                if(tx<0||tx>=h||ty<0||ty>=w||s[tx][ty]=='@'||d[tx][ty]<u.step+1)
                    break;
                if(d[tx][ty]>u.step+1)
                {
                    q.push({tx,ty,u.step+1});
                    d[tx][ty]=u.step+1;

                }

            }
        }
    }
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>h>>w>>k;
    cin>>sx>>sy>>ex>>ey;
    for(int i=0;i<h;i++)
    {
        d[i].resize(w);
    }
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            d[i][j]=1e9;
        }
    }
    sx--,sy--,ex--,ey--;
    for(int i=0;i<h;i++)
        cin>>s[i];
    bfs();
    if(d[ex][ey]==1e9)
        cout<<-1<<'\n';
    else
        cout<<d[ex][ey]<<'\n';





}


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

int main(){
    int W,H,N;
    cin>>W>>H>>N;
    vector<int> x(N),y(N),a(N);
    for(int i=0;i<N;i++){
        cin>>x[i]>>y[i]>>a[i];
    }
    int hidari=0,migi=W,ue=H,sita=0;
    for(int i=0;i<N;i++){
        switch(a[i]){
            case 1:
                if(x[i]>hidari){
                    hidari=x[i];
                    
                } 
                break;
            case 2:
                if(x[i]<migi){
                    migi=x[i];
                    
                    
                } 
                break;   
            case 3:
                if(y[i]>sita){
                    sita=y[i];
                    
                    
                } 
                break;  

            case 4:
                if(y[i]<ue){
                    ue=y[i];
                   
                }  
                break;
                  
        }
    }
    int resW=W,resH=H;
    resW-=hidari;
    resW-=(W-migi);
    resH-=sita;
    resH-=(H-ue);
    if(migi>hidari&&ue>sita){
     cout<<resW*resH<<endl;
    }else cout<<0<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define ll long long int
#define MOD ((int)(1e9) + 7)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 ll h, w;
 cin >> h >> w;
 if(h == 1 || w == 1) cout << "1\n";
 else
 cout << (h * (w/2)) + ((w%2) * (h+2-1)/2) << '\n';
  return 0;
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<string> s(n);
rep(i,n){
    cin>>s[i];
    sort(s[i].begin(),s[i].end());
}
map<char,map<int,int>> dic;
rep(i,n){
    int m=s[i].size();
    int j=0;
    while(j<m){
        char c=s[i][j];
        int num=1;
        while(j<m&&c==s[i][j]){
            dic[c][num]++;
            num++;
            j++;
        }
    }
}
string ans="";
for(auto v:dic){
    string t="";
    int num=0;
    for(auto d:v.second){
        if(d.second==n){
            num=max(d.first,num);
        }
    }
    rep(i,num){
        t=t+v.first;
    }
    ans=ans+t;
}
sort(ans.begin(),ans.end());
cout<<ans<<endl;
return 0;
}

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

int main() {
    int N,K;
    string S;
    cin >> N >> K;
    cin >> S;
    
    vector<int> Nums;
    int now = 1;
    int cnt = 0;

    rep(i, N) {
        if(S[i] == (char)('0')+now) cnt++;
        else {
            Nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if (cnt!=0) Nums.push_back(cnt);
    if (Nums.size()%2==0) Nums.push_back(0);
    int Add = 2*K+1;
    int ans = 0;
    int left = 0;
    int right = 0;
    int tmp = 0; // [left, right)
    for(int i = 0; i < Nums.size(); i+=2) {
        int Nextleft = i;
        int Nextright = min(i+Add, (int)Nums.size());
        while (Nextleft > left) {
            tmp -= Nums[left];
            left++;
        }
        while (Nextright > right) {
            tmp += Nums[right];
            right++;
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1020
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
#include<queue>
#include<functional>
#include<numeric>
#include<sstream>
#include<math.h>
#include <iomanip>
#define ll long long
#define PLL pair<ll,ll>
#define VS vector<string>
#define VL vector<ll>
#define VB vector<bool>
#define VPLL vector<pair<ll,ll> >
#define VVL vector<vector<ll> >
#define VVB vector<vector<bool> >
#define rep(i,a) for (ll i=0;i<a;i++)
#define nrep(i,n,a) for (ll i=n;i<a;i++)
#define mrep(i,a) for(ll i=a;i>=0;i--)
#define INF 1145141919810
#define PI 3.141592653589793238
#define VMIN(vec) *std::max_element(vec.begin(),vec.end())
#define VMIN(vec) *std::max_element(vec.begin(),vec.end())
#define VSUM(vec) std::accumulate(vec.begin(),vec.end(),0LL)
#define LTS(n) to_string(n)
#define STL(str) stoll(str)

using namespace std;

ll mod = 1e9 + 7;

ll kaijo(ll x){
	cout << x << endl;
	return (x == 1 ? x : (x*kaijo(x-1)) % mod);
}

int main() {
	ll n,sum=1;
	cin >> n;
	while (n){
		sum = (sum*n) % mod;
		n--;
	}
	cout << sum % mod << endl;
	return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func main() {
	scanner.Split(bufio.ScanWords)

	const maxCapacity = 512 * 1024
	buf := make([]byte, maxCapacity)
	scanner.Buffer(buf, maxCapacity)

	aStr := nextString()
	bStr := nextString()

	a, _ := new(big.Int).SetString(aStr, 10)
	b, _ := new(big.Int).SetString(bStr, 10)
	c := big.NewInt(0).Add(a, b)

	fmt.Println(c)
}



Measured memory_bytes: 6972
A,B,K = gets.split.map(&:to_i)
Aarray = Array.new
Barray = Array.new

for i in 1..A
 if A%i == 0
  Aarray.push(i)
 end
end

for i in 1..B
 if B%i == 0
  Barray.push(i)
 end
end

Carray = Array.new
for x in 0..(Aarray.length-1)
 for y in 0..(Barray.length-1)
  if Aarray[x] == Barray[y]
   Carray.push(Aarray[x])
  end
 end
end

puts(Carray[Carray.length-K])

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template<class T> void chmax(T& a, T b){ if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b){ if (a > b) { a = b; } }

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    cout << (((b / k) * k >= a) ? "OK" : "NG") << endl;

    return 0;
}

Measured memory_bytes: 3644