akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, char const* argv[]) {
	string s;
	cin >> s;
	int start;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A') {
			start = i;
			break;
		}
	}
	int end;
	for (int i = s.size() - 1; i >= 0; i--) {
		if (s[i] == 'Z') {
			end = i;
			break;
		}
	}
	printf("%d\n", end - start + 1);
	return 0;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
int main(){
   int i,j,k,n;
   cin >> n >>k;
   int arr[n];
   for(i=0;i<n;++i){
    cin >> arr[i];
   }
   int win[k+2];
   for(i=1;i<=k;++i){
    for(j=0;j<n;++j){
        if(i == arr[j]){
            win[i]=1;
            break;
        }
        if(i-arr[j]>=1 && win[i-arr[j]]!=1){
            win[i]=1;
            break;
        }
    }
    if(j==n)
        win[i]=0;
   }
   if(win[k])
    cout <<"First"<<endl;
   else
    cout <<"Second"<<endl;
  return 0;


}


Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll N; cin >> N;
  map<ll,ll> count;
  set<ll> s;
  for (ll i = 0; i < N; i++) {
    ll a; cin >> a; count[a]++; s.insert(a);
  }
  ll res = 0;
  for (auto it = s.begin(); it != s.end(); it++) {
    if (count[*it]%2 == 1) res++;
  }
  cout << res << endl;
}


Measured memory_bytes: 11136
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
anstable = [0] * (10 ** 6 + 1)
d = defaultdict(int)
for i in a:
    d[i] += 1

u = []
for i, v in d.items():
    if v == 1:
        u.append(i)
a = set(a)
for i in a:
    for j in range(i * 2, 10 ** 6 + 1, i):
        anstable[j] += 1

cnt = 0
for i in u:
    if anstable[i] == 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 53940
#include <bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("outp.txt","w",stdout);
    #endif
    ll i,j,n,m;
    string a,st;
    cin>>a;
    cin>>st;
    n=a.length();m=st.length();
    ll mini=1000000;
    for(i=0;i<=n-m;i++)
    {
        ll k=0;
        for(j=i;j<i+m;j++)
        {
            if(a[j]==st[j-i])
                k++;
        }
        ll ans=m-k;
        mini=min(mini,ans);
    }
    cout<<mini;
}

    


Measured memory_bytes: 3596
N, W = map(int, input().split())
w, v = [0]*N, [0]*N
for i in range(N):
  w[i], v[i] = map(int, input().split())

dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(1, N+1):
  for w_sum in range(1, W+1):
    if w_sum >= w[i-1]:
      dp[i][w_sum] = max(dp[i-1][w_sum-w[i-1]] + v[i-1], dp[i-1][w_sum])
    else:
      dp[i][w_sum] = dp[i-1][w_sum]
      
print(dp[N][W])

Measured memory_bytes: 119916
#include<bits/stdc++.h>
using namespace std;
const int nax = 1e6+5;
int dp[nax];
int main(){
    int n; cin >> n;
    
	dp[0] = 0, dp[1] = 1;
    
    for(int i=1;i<=1000000;i++){
    	
    	dp[i] = i;
    	
    	for(int j=6;j<=i;j*=6){
    		dp[i] = min(dp[i], 1 + dp[i-j]);
		}
		for(int j=9;j<=i;j*=9){
    		dp[i] = min(dp[i], 1 + dp[i-j]);
		}
	}
	
	cout << dp[n];
	
	return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>
#include <cstring>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<char> c(n);
    priority_queue<int> que;    
    rep(i, n) {
        cin >> c[i];
        if (c[i] == 'R') que.push(i);
    }
    ll ans = 0;
    rep(i, n) {
        if (c[i] == 'W') {
            if (que.empty()) break;
            int num = que.top(); que.pop();
            if (num > i) {
                swap(c[i], c[que.top()]);
                ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4416
// Last Change: 04/02/2019 22:11:47.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  string S, T;
  cin >> S >> T;

  int index = 0;
  int sSize = S.size();
  while (1) {
    if (index == sSize) {
      cout << "No" << endl;
      break;
    }

    string tmp = S.substr(index, sSize - index);
    tmp += S.substr(0, index);

    if (tmp == T) {
      cout << "Yes" << endl;
      break;
    }

    ++index;
  }

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    if(n%1000==0){
        cout << 0 << endl;
    }else{
      cout << 1000 - n % 1000 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


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

    int N,M;
    cin >> N >> M;
    if(N >= 13) cout << M << endl;
    else if(N >= 6 && N <= 12) cout << M/2 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  char a,b;
  cin>>a;
  rep(i,3){
    cin>>b;
    if(a==b){
      cout<<"Bad";
      return 0;
    }
    a=b;
  }
  cout<<"Good";
}

Measured memory_bytes: 256
using System;
class Program { 
  
  const int ORDERS = 5;
  
  static void Main(string[] args) {
    int[] otimes = new int[ORDERS];
    
    for (int i=0; i<ORDERS; i++) {
      otimes[i] = int.Parse(Console.ReadLine());
    }
    
    // 最後に持ってくる注文のインデックスの選定
    int lastOrderIndex = -1;
    int count = 10;
    for (int i=0; i<ORDERS; i++) {
      int tmpCount = otimes[i] % 10;
      if (tmpCount != 0 && tmpCount < count) {
        count = tmpCount;
        lastOrderIndex = i;
      }
    }
    
    int time = 0;
    for (int i=0; i<ORDERS; i++) {
      if (i == lastOrderIndex) {
        continue;
      } else {
        time += (int)(Math.Ceiling((double)otimes[i] / 10) * 10);
      }
    }
    if (lastOrderIndex != -1) {
      time += otimes[lastOrderIndex];
    }
    
    Console.WriteLine(time);
    return;
  }
}

Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
    int N,R,a;
    scanf("%d%d",&N,&R);
    if (N> 10){
        printf("%d\n",R);
    } 
    else{
        printf("%d\n",(R + 100*(10-N)));
    }

    return 0;
}

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

struct lines {
  int h;  //横線の高さ                                                            
  int p, q; //横線に繋がる縦線の番号                                              

  bool operator>(const lines &left) const {
    return h > left.h;
  }
};

int amida(int n, int m, int a, lines* line, int size) {
  for(unsigned int i = 0; i < size; i++) {
    if(line[i].p == a)
      a = line[i].q;
    else if(line[i].q == a)
      a = line[i].p;
  }
  return a;
}

int main() {
  int n; //縦線の本数                                                             
  int m; //横線の本数                                                             
  int a; //調べる縦線の番号                                                       
  vector<lines> line;

  while(1) {
    cin >> n >> m >> a;
    if(n == 0 && m == 0 && a == 0) break;

    for(int i = 0; i < m; i++) {
      lines l;
      cin >> l.h >> l.p >> l.q;
      line.push_back(l);
    }

    sort(line.begin(), line.end(), greater<lines>());
    cout << amida(n, m, a, &line.front(), line.size()) << endl;
    line.clear();
  }

  return 0;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
inline void fastIO(){
    ios_base::sync_with_stdio(0);cin.tie(0);
}

int main(){
   int n;
   cin>>n;
   bool key=true;
   for(int i=0;i<n;i++){
        int x;
        cin>>x;
        if(x%2==0){
            if(x%3!=0&&x%5!=0){
                key=false;
            }
        }
   }
   if(key){
        cout<<"APPROVED"<<endl;
   }else{
        cout<<"DENIED"<<endl;
   }
}
// - VERIFICAR LONG VS INT -


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

using namespace std;

int main(int argc, char *argv[]) {
    int N, M;
    cin >> N >> M;

    int e = (N * (N - 1)) / 2;
    int o = (M * (M - 1)) / 2;
    
    cout << e + o << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
// #include <bits/stdc++.h>
#include <vector>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <iostream>
#include <random>
#include <queue>
#include <algorithm>
#include <climits>
#include <map>
#include <set>
#include <stack>
#include <sstream>
#include <cstring>
#include <deque>

 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
typedef vector<cd> vcd;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vl> vvl;


#define FOR(i,a,b) for (int i=a; i<b; i++)
#define F0R(i,a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = b; i > a; i--)
#define F0Rd(i,a) for (int i = a; i > -1; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define que queue
#define pa pair
#define ex(m,i) m.find(i)!=m.end()
#define nex(m,i) m.find(i)==m.end()
#define ms(arr,i) memset(arr,i,sizeof(arr))

#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int inf = 1e9;
const int MX = 100001; //check the limits, dummy
const double epsilon = 1e-12;
const int ds[4][2] = {
    {-1,0},
    {1,0},
    {0,-1},
    {0,1}
};

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

    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);

    int n; cin >> n;
    if(n) printf("%d\n",0);
    else printf("%d\n",1);
    
    return 0;
}

Measured memory_bytes: 3216
def dogs():
    number = int(input())
    l = list('abcdefghijklmnopqrstuvwxyz')
    dogName = []
    ans = ''

    while number > 0:
        number = number - 1
        dogName.append(l[number % 26])
        number = number // 26

    dogName.reverse()

    for i in dogName:
        ans = ans + i
    print(ans)


dogs()

Measured memory_bytes: 9164
(stdin => {
  // Define Function
  const getA = (a, b) => a * b
  const getB = (a, b) => (a + b) * 2

  // Declare Variable
  const inputs = stdin.toString().trim().split(' ')
  const a = parseInt(inputs[0], 10)
  const b = parseInt(inputs[1], 10)

  console.log(getA(a, b), getB(a, b))
})(require('fs').readFileSync('/dev/stdin', 'utf8'))



Measured memory_bytes: 15136
n, k = map(int, input().split())
a = list(map(int, input().split()))

loop = 0
use = [0] * n
now = 0
use[now] = 1
x = [1]
for _ in range(n):
   next = a[now] - 1
   x.append(next+1)
   if use[next] == 0:
      use[next] = 1
      now = next
   else:
      break
loop = x.pop(-1)

tmp = x.index(loop)
y = x[:tmp]
x = x[tmp:]
#print(y, x)

if k < len(y):
   kk = k % len(y)
   print(y[kk])
else:
   k -= len(y)
   kk = k % len(x)
   print(x[kk])


Measured memory_bytes: 32248
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    static int N;
    static int[][] A;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        A = new int[2][];
        A[0] = sc.nextIntArray(N);
        A[1] = sc.nextIntArray(N);

        System.out.println(solve());
    }

    static int solve() {
        int ans = 0;
        for (int mid = 0; mid < N; mid++) {
            int sum = 0;
            for (int i = 0; i <= mid; i++) {
                sum += A[0][i];
            }
            for (int i = mid; i < N; i++) {
                sum += A[1][i];
            }
            ans = Math.max(sum, ans);
        }
        return ans;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 22740
#include<stdio.h>
#include<stdlib.h>
#include<math.h>


    
int main(){

	double a,b,c,d,e,f,kai1,kai2;

	while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){


		kai1=(c*e/b-f)/(a*e/b-d);

		kai2=(c-a*kai1)/b;



		printf("%.3lf %.3lf\n",kai1+0,00001,kai2+0,00001);

	}
    return 0;
}

Measured memory_bytes: 648
use io::*;

fn main() {
    let con = read_string();
    let mut sc = Scanner::new(&con);

    let n: usize = sc.next();
    let a: Vec<usize> = sc.next_vec(n);

    let mut ans = 0;
    let mut i = 0;
    while i < n {
        // if i + 2 < n && a[i] == a[i + 1] && a[i + 1] == a[i + 2] {
        //     ans += 1;
        //     i += 2;
        //     continue;
        // }

        if i + 1 < n && a[i] == a[i + 1] {
            ans += 1;
            i += 2;
        } else {
            i += 1;
        }
    }

    println!("{}", ans);
}

//-----

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <set>
#include <list>
#include <fstream>
#include <map>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <cmath>
using namespace std;

#define ll long long
#define mod 1000000007
#define infinity (ll)1e9+1
#define pdd pair<double,double>
#define pll pair<ll, ll>
#define pii pair<int,int>
#define MP make_pair
#define vi vector<ll>

#define FOR(i,a,b) for(ll i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(ll i = (b) - 1; i >= (a); --i)
#define REPEAT(i) FOR(counter1234,0,i)
#define ALL(a) a.begin(), a.end()

ll power(ll n, ll to)//by mod
{
	if (to == 0) return 1;
	if (to == 1) return n;
	ll exp = 1;
	ll ans = n;
	while (2 * exp <= to)
	{
		ans *= ans;
		ans %= mod;
		exp *= 2;
	}

	return ((ans*power(n, to - exp)) % mod);
}

ll C(ll n, ll k)//by mod
{
	ll* fact = new ll[k + 1];
	fact[0] = 1;
	FOR(i, 1, k + 1)
	{
		fact[i] = fact[i - 1] * i;
		fact[i] %= mod;
	}
	if (k > n - k) k = n - k;
	ll factK = fact[k];
	ll factNK = factK;
	FOR(i, k + 1, n - k + 1)
	{
		factNK *= i;
		factNK %= mod;
	}

	ll factN = factNK;
	FOR(i, n - k + 1, n + 1)
	{
		factN *= i;
		factN %= mod;
	}

	ll answer = factN;
	answer *= power(factK, mod - 2);
	answer %= mod;
	answer *= power(factNK, mod - 2);
	return answer%mod;
}


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

	vi x(n), y(m);
	FOR(i, 0, n)
		cin >> x[i];
	FOR(i, 0, m)
		cin >> y[i];

	ll ans = 0;

	sort(ALL(x));
	sort(ALL(y));

	ll sumX = 0, sumY = 0;

	for (int i = 0; i < n; ++i)
	{
		sumX -= x[i] * (n - 2 * i - 1);
	}

	for (int i = 0; i < m; ++i)
	{
		sumY -= y[i] * (m- 2 * i - 1);
	}


	sumX %= mod;
	sumY %= mod;

	ans = sumX * sumY;
	cout << ans%mod;
	return 0;
}	

Measured memory_bytes: 1920
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int H, W, K; scanf("%d%d%d", &H, &W, &K);
    int sx, sy, gx, gy; scanf("%d%d%d%d", &sx, &sy, &gx, &gy);
    sx--, sy--, gx--, gy--;
    vector<string> board(H);
    for(int i=0; i<H; i++) cin >> board[i];

    vector< vector< vector< int > > > dist(
        H,
        vector< vector<int> >(
            W,
            vector<int>(4, INF)
            )
        );
                                                                            
    queue< tuple<int, int, int> > v0, v1;
    for(int k=0; k<4; k++) {
        dist[sx][sy][k] = 0;
        v0.emplace(sx, sy, k);
    }

    for(int iter=0; v0.size(); iter++) {
        while(v0.size()) {
            int x, y, d; tie(x, y, d) = v0.front(); v0.pop();
            int m = dist[x][y][d];
            if(m < 0) continue;
            dist[x][y][d] = -1;
            if(m + 1 <= K) {
                int nx = x + dx[d], ny = y + dy[d];
                if(nx < 0 or nx >= H or ny < 0 or ny >= W) continue;
                if(board[nx][ny] == '@') continue;
                if(dist[nx][ny][d] > m + 1) {
                    v0.emplace(nx, ny, d);
                    v1.emplace(nx, ny, d);
                    dist[nx][ny][d] = m + 1;
                }
            }
        }

        while(v1.size()) {
            int x, y, d; tie(x, y, d) = v1.front(); v1.pop();
            if(x == gx and y == gy) {
                printf("%d\n", iter + 1);
                return 0;
            }
            for(int k=0; k<4; k++) {
                if(dist[x][y][k] == 0) continue;
                dist[x][y][k] = 0;
                v0.emplace(x, y, k);
            }
        }
    }
    puts("-1");
    return 0;
}


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

const int MOD = 1000000007;

// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

//最小公倍数
int lcm(int number1,int number2){
	return number1 * number2 / gcd(number1,number2);	
}
  
int main(){
string S, T;
cin >> S >> T;

REP(i, S.size()){

if(S == T){
    cout << "Yes" << endl;
    return 0;
}

S = S.back() + S.substr(0, S.size() - 1);

}
cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
#include<map>
using namespace std;

int main(){
    int n;
    cin>>n;
    map<string,int>mp;
    int maxv=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        mp[s]++;
        maxv=max(maxv,mp[s]);
    }
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        if(itr->second==maxv)cout<<itr->first<<endl;
    }
    return 0;
}

Measured memory_bytes: 19108
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

#define maxs(x,y) (x=std::max(x,y))
#define mins(x,y) (x=std::min(x,y))

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

  vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << vec[N-1] << '\n';
}


Measured memory_bytes: 888
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define MAX_v 100
typedef long long ll;
typedef unsigned long long ull;
typedef pair<string,int> P;
int main(){
	string s;
	while(cin >> s , s!="0"){
		int len = s.size();
		int check = -1;
		queue<P> Q;
		Q.push(P(s,0));
		set<string> vis;
		while( Q.size() ){
			P p = Q.front();Q.pop();
			string tmp = p.first;
			string k = p.first;
			//cout << "D:" << tmp << endl;
			bool f = false;
			if(vis.find(tmp) != vis.end())continue;
			rep(i,len-1){
				if(tmp[i] != tmp[i+1]){f = true;break;}
			}
			if(!f){check = p.second;break;}
			vis.insert(tmp);
			rep(i,len-1){
				if(tmp[i] < tmp[i+1]){
					swap(k[i],k[i+1]);
				}
				if(k[i]=='r'&&k[i+1]=='g'){k[i]=k[i+1]='b';Q.push(P(k,p.second+1));}
				else if(k[i]=='r'&&k[i+1]=='b'){k[i]=k[i+1]='g';Q.push(P(k,p.second+1));}
				else if(k[i]=='g'&&k[i+1]=='b'){k[i]=k[i+1]='r';Q.push(P(k,p.second+1));}
				k = p.first;
			}
		}
		(check != -1) ? printf("%d\n",check) : puts("NA");
	}
	return 0;
}

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

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	set<int>s;
	s.insert(a);
	s.insert(b);
	s.insert(c);

	cout << s.size() << endl;



	return 0;
}


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



class Program
{
    const int MOD = 1000000007;
    const int INF = 1 << 30;

    static void Main(string[] args)
    {
        Solve();
    }

    static void Solve()
    {
        Scaner sc = new Scaner();
        write wr = new write();
        //ここから

        int[] x=sc.IntArr;
        int a=x[0];
        int b=x[1];

        for(int i=-a+1+b;i<=a-1+b;++i){
            Console.Write(i);
            if(i==a-1+b)wr.wri("\n");
            else Console.Write(" ");
        }

        

        //ここまで
    }
    
        


    static int factmod(int X){
        int ret=1;
        for(int i=1;i<=X;++i){
            ret*=i;
            ret%=MOD;
        }
        return ret;
    }
}





class Scaner
{
    public string Str => Console.ReadLine();

    public string[] StrArr => Str.Split(' ');

    public long[] LongArr => StrArr.Select(long.Parse).ToArray();
    public int[] IntArr => StrArr.Select(int.Parse).ToArray();
    public char[] CharArr => Str.ToArray();
    public long Long1 => LongArr[0];
    public int Int1 => IntArr[0];
    
}



class write
{
    public  void wri<T>(T x)
    {
        Console.WriteLine(x);
    }
}



Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <math.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  string s,t;
  int a,b;
  cin>>s>>t>>a>>b;
  string u;
  cin>>u;
  if(s==u) a--;
  if(t==u) b--;
  cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 3592
using System;
using System.Linq;

namespace C___GeT_AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var N_Q = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = N_Q[0], Q = N_Q[1];
            var S = Console.ReadLine();
            var li_ri = Enumerable.Range(1, N_Q[1]).Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();

            var count = new int[N];

            for (int i = 1; i < N; i++)
            {
                count[i] = count[i - 1];
                if (S.Substring(i - 1, 2) == "AC") count[i]++;
            }

            for (int i = 0; i < Q; i++)
            {
                int l = li_ri[i][0] - 1, r = li_ri[i][1] - 1;
                Console.WriteLine(count[r] - count[l]);
            }
        }
    }
}


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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

pair<long long, long long> p[51],P[51];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, k;
    cin >> n >> k;

    for(int i = 0; i < n; ++i)
        cin >> p[i].first >> p[i].second;
    for(int i = 0; i < n; ++i)
        P[i] = make_pair(p[i].second, p[i].first);

    sort(p, p + n); sort(P, P + n);

    long long area = -1;
    for(int a = 0; a < n; ++a){
        long long lx = p[a].first;
        for(int c = 0; c < n; ++c){
            long long ly = P[c].first;
            for(int b = a; b < n; ++b){
                long long rx = p[b].first;
                for(int d = c; d < n; ++d){
                    long long ry = P[d].first;
                    if(area != -1 && (rx - lx) * (ry - ly) >= area) break;
                    int cnt = 0;
                    for(int i = 0; i < n && cnt < k; ++i){
                        if(p[i].first > rx) break;
                        if(lx > p[i].first) continue;
                        if(ly > p[i].second || p[i].second > ry) continue;
                        ++cnt;
                    }
                    if(cnt == k) area = (rx - lx) * (ry - ly);
                }
            }
        }
    }

    cout << area;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        int[] h = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(solve(n,h));
    }
    static int solve(int n, int[] h) {
        int count = 1;
        for(int i = 1; i < n; i ++) {
            for(int j = 0; j < i; j ++) {
                if(h[i] < h[j]) break;
                if(j==i-1) count ++;
            }
        }
        return count;
    }
}

Measured memory_bytes: 13396
#include <stdio.h>

#define MAX 100000
#define NIL -1

int getDepth(int);
void printChildren(int);


typedef struct {
  int pnt,lc,rs;
}node;

node T[MAX];

int main(){
  int n,dg,id,c,pre;
  int i,j;
  int root;
  
  scanf("%d",&n);

  for(i=0;i<n;i++)T[i].pnt=T[i].lc=T[i].rs=NIL;

  for(i=0;i<n;i++){
    scanf("%d%d",&id,&dg);
    for(j=0;j<dg;j++){
      scanf("%d",&c);

      if(j==0)T[id].lc=c;
      else  T[pre].rs=c;
      pre=c;

      T[c].pnt=id;
    }
  }

  for(i=0;i<n;i++){
    if(T[i].pnt==NIL)root=i;
  }

  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,T[i].pnt,getDepth(i));
    if(T[i].pnt==NIL)printf("root, ");
    else if(T[i].lc==NIL)printf("leaf, "); 
    else if(T[i].pnt!=NIL && T[i].lc!=NIL)printf("internal node, ");
    printf("[");
    printChildren(i);
    printf("]\n");
  }

 return 0;
}

  
int getDepth(int u){
  int d=0;
  while( T[u].pnt!=NIL){
    u=T[u].pnt;
    d++;
  }
  return d;
}

void printChildren(int u){
  int c;
  c=T[u].lc;
  while(c!=NIL){
    printf("%d",c);
    c=T[c].rs;
    if(c!=NIL)printf(", ");
  }
}
		       

Measured memory_bytes: 1788
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		for (int i = 1; i <= n; i++) {
			if (Integer.toString(i).length() % 2 != 0) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 27476
def gcd(a,b)
  return a if b == 0
  gcd(b,a%b)
end

def lcm(a,b)
  a * b / gcd(a,b)
end

def f(n)
  ret=0
  while(n%2==0)
    n/=2
    ret+=1
  end
  ret
end

n,m=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)

ff=f(a[0])
a.each do |v|
  if ff != f(v)
    puts 0
    exit
  end
end 

l=1
a.each do |v|
  l=lcm(l,v/2)
end

puts ((m/l)+1)/2

Measured memory_bytes: 13068
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

int main() {
    cin>>A>>B>>K;
    cout<<K<<' '<<A<<' '<<B<<endl;

}

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

static const int maxn = 100 + 2;

int selectionSort(int a[], int n) {
	int minj, sw = 0;
	for (int i = 0; i < n; i++) {
		minj = i;
		for (int j = i; j < n; j++) {
			if (a[j] < a[minj])
				minj = j;
		}
		if (a[i] != a[minj]) {
			swap(a[i], a[minj]);
			sw++;
		}
	}
	return sw;
}

int main() {
	// freopen("data.in", "r", stdin);
	// freopen("data.out", "w", stdout);
	int n, a[maxn];
	while (scanf("%d", &n) == 1) {
		for (int i = 0; i < n; i++) scanf("%d", &a[i]);
		int sw = selectionSort(a, n);
		for (int i = 0; i < n-1; i++)
			printf("%d ", a[i]);
		printf("%d\n%d\n", a[n-1], sw);
	}
	return 0;
}



Measured memory_bytes: 3216
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	Scanner input = new Scanner(System.in);
      	int K = input.nextInt();
      	int odds = (K + 1) / 2;
        int evens = K / 2;
      	System.out.print(odds * evens);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,c;
	cin>>a>>b>>c;
	if(a%2==0||b%2==0||c%2==0){
		cout<<0<<endl;
		return 0;
	}
	cout<<min(min(a*b,b*c),a*c)<<endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        t: [isize; n],
    }

    let mut ans = t[0];
    for &nt in t.iter().skip(1) {
        ans = lcm(ans, nt);
    }
    println!("{}", ans);
}

// O(log max(x, y))
fn gcd(x: isize, y: isize) -> isize {
    return if y != 0 { gcd(y, x % y) } else { x };
}

fn lcm(x: isize, y: isize) -> isize {
    x / gcd(x, y) * y
}

Measured memory_bytes: 2148
N,M=map(int,input().split())
A=list(map(int,input().split()))
mod=M
from collections import defaultdict
cnt=defaultdict(int)
ruiseki=[0]*(1+N)
cnt[0]+=1
ans=0
for i in range(N):
    ruiseki[i+1]=(ruiseki[i]+A[i])%mod
    ans+=cnt[ruiseki[i+1]]
    cnt[ruiseki[i+1]]+=1
print(ans)

Measured memory_bytes: 14936
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    string S;
    cin >> S;
    int N = S.size();
    int ans = 0;
    for(int i=1;i<N/2;++i){
        bool flag = true;
        for(int j=0;j<i;++j){
            if(S[j] != S[j+i]) flag = false;
        }
        if(flag) ans = max(ans,i*2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<pair<int64_t, int64_t>> v;
	for (int i = 0; i < N; i++) {
		pair<int64_t, int64_t> p;
		cin >> p.first >> p.second;
		v.push_back(p);
	}
	sort(v.begin(), v.end());

	//for (int i = 0; i < N; i++) {
	//	cout << v.at(i).first << ' ' << v.at(i).second << endl;
	//}

	int64_t sum = 0;
	sum += v.at(0).first - 1;
	sum += v.at(N - 1).second;
	sum += v.at(N - 1).first - v.at(0).first + 1;

	cout << sum << endl;
}


Measured memory_bytes: 5372
#include <stdio.h>

int main(void)
{
	int a, b, c, n, t, S = 0, A = 0, C = 0, D = 0;

	for (S = 0; ; ) {
		scanf("%d %d %d\n", &a, &b, &c);
		if (a < b) {t = a; a = b; b = t;}
		if (a < c) {t = a; a = c; c = t;}
		if (a >= b + c) break;
		S++;
		if      (a * a <  b * b + c * c) A++;
		else if (a * a == b * b + c * c) C++;
		else if (a * a >  b * b + c * c) D++;
	}
	printf("%d %d %d %d\n", S, C, A, D);
}



Measured memory_bytes: 2096
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

K, S = list(map(int, sys.stdin.readline().split()))

a = np.array(np.meshgrid(np.arange(K + 1), np.arange(K + 1))).sum(axis=0)
print(((S - K <= a) & (a <= S)).sum())


Measured memory_bytes: 208696
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=15;
const int MOD=1000000007;

int n,m;
int adj[MAXN];
int mem[1<<MAXN];
int bcnt[1<<MAXN];

int go(int mask) {
	if(mask==0) return 1;
	if(mem[mask]!=-1) return mem[mask];
	//printf("go(%d)\n",mask);
	int ret=0;
	int donemask=(1<<n)-1-mask;
	for(int nxtmask=(donemask+1)&mask;nxtmask!=0;nxtmask=(nxtmask+donemask+1)&mask) {
		bool a=(nxtmask&1)!=0,b=(nxtmask&2)!=0; if(a!=b) continue;
		int remmask=mask-nxtmask;
		int ways=1;
		REP(i,n) if(remmask&(1<<i)) {
			int cnt=bcnt[adj[i]&nxtmask];
			int curways=(1<<cnt)-1;
			ways=(ll)ways*curways%MOD;
		}
		REP(i,n) if(nxtmask&(1<<i)) {
			int cnt=bcnt[adj[i]&remmask];
			int curways=(1<<cnt);
			ways=(ll)ways*curways%MOD;
		}
		int res=go(remmask);
		ret=(ret+(ll)ways*res)%MOD;
	}
	return mem[mask]=ret;
}

void run() {
	scanf("%d%d",&n,&m); REP(i,n) adj[i]=0;
	REP(i,m) { int a,b; scanf("%d%d",&a,&b); --a,--b; adj[a]|=1<<b; }
	memset(mem,-1,sizeof(mem));
	bcnt[0]=0; FOR(i,1,1<<n) bcnt[i]=1+bcnt[i-(i&-i)];
	int tot=1; REP(i,m) tot=(ll)2*tot%MOD;
	int lose=go((1<<n)-1);
	int ret=(tot-lose+MOD)%MOD;
	printf("%d\n",ret);
}

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


Measured memory_bytes: 512
#後ろにある数字を消していく

n = int(input())
B = [int(i) for i in input().split()]

ans = []

while len(B) > 0:
    for i in range(len(B) - 1, -1, -1):
        if B[i] == i + 1:
            ans.append(i + 1)
            del B[i]
            break
    else:
        print(-1)
        exit()

print(*ans[::-1], sep='\n')

Measured memory_bytes: 3316
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;

char mmap[20][50];

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

int bfs(pi source, pi dest)
{
  int visited[20][20] = {};
  
  queue<pair<pi, int> > q;
  q.push(make_pair(source, 0));
  visited[source.first][source.second] = 1;
  
  while(!q.empty())
  {
    pair<pi, int> cur = q.front();
    q.pop();
    
    for(int i = 0; i < 4; i++)
    {
      int nexty = cur.first.first + dy[i];
      int nextx = cur.first.second + dx[i];
      
      if(nexty == dest.first && nextx == dest.second && visited[nexty][nextx] == 0)
        return cur.second+1;
      
      if (mmap[nexty][nextx] == '.' && visited[nexty][nextx] == 0)
      {
        q.push(make_pair(make_pair(nexty, nextx), cur.second+1));
        visited[nexty][nextx] = 1;
      }
    }
    
  }
  
  return 0;
}

int main()
{
  int h, w;
  scanf("%d %d", &h, &w);
  
  for(int i = 0; i < h; i++)
      scanf("%s", mmap[i]);
  //printf("%c",mmap[h-1][])
  
  int res = -1;
  
  for(int i = 0; i < h; i++)
    for(int j = 0; j < w; j++)
        for(int k = 0; k < h; k++)
          for(int l = 0; l < w; l++)
            if (mmap[i][j] == '.' && mmap[k][l] == '.')
              res = max(res, bfs(make_pair(i, j), make_pair(k, l)));
  
  printf("%d\n", res);
  //printf("%c\n", mmap[2][2]);
  return 0;
}


Measured memory_bytes: 256
//q100.cpp
//Sat Sep 19 15:04:19 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

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

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

	int flag = 1;
	int x = 1;
	while(x*(x-1)<=2*n){
		if (x*(x-1)==2*n){
			flag = 0;
			break;
		}
		x++;
	}

	if (flag){
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;
	cout << x << endl;
	vector<int> s[x];
	int num = 1;
	rep(i,x-1){
		rep(j,i+1){
			s[i].push_back(num);
			if (j==i){
				s[x-1].push_back(num);
			}else {
				s[j].push_back(num);
			}
			num++;
		}
	}

	rep(i,x){
		cout << s[i].size() << " ";
		rep(j,s[i].size()){
			cout << s[i][j] << " ";
		}
		printf("\n");
	}
}

Measured memory_bytes: 4328
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;


int main() {
	string s;
	cin >> s;
	ff(i, 0, 3) {
		if (s[i] == s[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, sys.stdin.readline().split())
    u -= 1
    v -= 1
    G[u].append((v, w))
    G[v].append((u, w))

done = {}
todo = [(0, 0, 0)]
while todo:
    i, c, d = todo.pop()
    for ni, dd in G[i]:
        if ni in done:
            continue
        nd = d + dd
        nc = nd % 2
        todo.append((ni, nc, nd))
    done[i] = c

for i in range(N):
    print(done[i])

Measured memory_bytes: 49380
n=int(input())
p=[int(s) for s in input().split()]

c=p[1]
b=p[0]
count=0
for i in range(2,n):
    c,b,a=p[i],c,b
    if b!=max(a,b,c) and b!=min(a,b,c):
            count+=1
print(count)

Measured memory_bytes: 3188
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	a := scanInt()
	b := scanInt()
	c := scanInt()
	d := scanInt()
	e := scanInt()
	f := scanInt()

	ansAll := 0
	ansSugar := 0
	con := -1.0
	memo := map[rec]bool{}

	var fn func(all,sugar int)
	fn = func(all,sugar int) {
		if memo[rec{all,sugar}] {
			return
		}
		memo[rec{all,sugar}] = true

		now := 100.0*float64(sugar)/float64(all)
		if con < now {
			con = now
			ansAll = all
			ansSugar = sugar
		}
		// fmt.Fprintln(os.Stderr, ansAll,ansSugar,con)
		if all+100*a <= f {
			fn(all+100*a,sugar)
		}
		if all+100*b <= f {
			fn(all+100*b,sugar)
		}
		if all+c <= f && sugar+c <= e*(all-sugar)/100 {
			fn(all+c,sugar+c)
		}
		if all+d <= f && sugar+d <= e*(all-sugar)/100 {
			fn(all+d,sugar+d)
		}
	}

	fn(0,0)

	fmt.Fprintln(wr, ansAll,ansSugar)

}

type rec struct {
	all,sugar int
}


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

while True:
    A_org = A[0:]
    min_A = max(A)
    min_index = A.index(min_A)
    for i in range(N):
        if A[i] < min_A and A[i] >= 1:
            min_A = A[i]
            min_index = i
    for i in range(N):
        if i == min_index:
            pass
        else:
            A[i] %= min_A
    if A == A_org:
        break

print(max(A))

Measured memory_bytes: 19948
INF = 1 << 28
N, q = gets.split.map(&:to_i)
S = gets

def move(pos, op)
  S[pos] != op[0] ? pos : (op[2] == ?L ? pos - 1 : pos + 1)
end

l,r = [0, N - 1]

$<.reverse_each do |op|
  l = (l - 1 .. l + 1).min_by{|pos| move(pos, op) >= l ? pos :  INF}
  r = (r - 1 .. r + 1).max_by{|pos| move(pos, op) <= r ? pos : -INF}
  break if r < l
end
puts r < l ? 0 : r - l + 1


Measured memory_bytes: 18708
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod=1e9+7;
ll addition(ll a , ll b)
{

    return (a%mod + b% mod)%mod;
}
int main()
{
    ll n,m,a;
    cin>>n>>m;
    set<int>s;
    for(int i=0;i<m;i++)
    {
        cin>>a;
        s.insert(a);
    }
    vector<int >ans(n+1,1);
    for(auto x:s)
    {
        ans[x]=0;
    }

    for(int i=2;i<=n;i++)
    {
        if(ans[i]!=0)
        {
            ans[i]=addition(ans[i-1],ans[i-2]);
        }
        //cout<<ans[i]<<" ";
    }
   // for(int i=0;i<n;i++) cout<<ans[i];
    cout<<ans[n];
}


Measured memory_bytes: 5376
while True:
  n, x = map(int, input().split())
  if n==0 and x==0:
    break
  ans=0
  for i in range(1,n+1):
    for j in range(1,n+1):
      if j<i:
        continue
      k=x-(i+j)
      if i<j and j<k and k<=n:
        ans+=1 
  print("%d"%(ans))
   
        


Measured memory_bytes: 5596
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;

struct UnionFind {
    vector<int> par;
    vector<int> siz;
    UnionFind(int N) : par(N), siz(N, 1) {
        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;
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }

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

    int size(int x) {
        return siz[root(x)];
    }
};

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

    ll n,m;
    cin >> n >> m;
    UnionFind tree(n);
    vector<int> a(m),b(m);
    rep(i,m) {
        cin >> a[i] >> b[i];
        --a[i]; --b[i];
    }
    ll now=n*(n-1)/2;
    vector<ll> ans(m);
    invrep(i,m) {
        ans[i]=now;
        if (!tree.issame(a[i],b[i])) {
            ll ta=tree.size(a[i]),tb=tree.size(b[i]);
            now-=ta*tb;
            tree.unite(a[i],b[i]);
        }
    }
    rep(i,m) cout << ans[i] << endl;

    return 0;   
}


Measured memory_bytes: 3712