akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#define max_p 10
#define MAX_N 50
#define MAX_STATE 120
#define INF 0x3f3f3f3f

using namespace std;

struct S{
	int x, y, k;
	S() {}
	S(int x, int y, int k) : x(x), y(y), k(k) {}
};
char mat[MAX_N][MAX_N];
vector<string> P;
int N, M;
int start_x, start_y, end_x, end_y;
int dp[MAX_N][MAX_N][MAX_STATE];
int next[MAX_STATE][4];
bool ng[MAX_STATE];

int h[] = {0, 0, -1, 1};
int v[] = {-1, 1, 0, 0};
char UDLR[] = "UDLR";

int solve(){
	vector<string> pfx;
	for(int i = 0; i < P.size(); i++){
		for(int j = 0; j <= P[i].length(); j++){
			pfx.push_back(P[i].substr(0, j));
		}
	}
	sort(pfx.begin(), pfx.end());
	pfx.erase(unique(pfx.begin(), pfx.end()), pfx.end());
	

	for(int i = 0; i < pfx.size(); i++){
		for(int j = 0; j < P.size(); j++){
			if(P[j].length() <= pfx[i].length() &&
					pfx[i].substr(pfx[i].length() - P[j].length(), P[j].length()) == P[j]){
				ng[i] = true;
				break;
			}
		}
		for(int j = 0; j < 4; j++){
			if(!ng[i]){
				string s = pfx[i] + UDLR[j];
				int k;
				for(;;){
					k = lower_bound(pfx.begin(), pfx.end(), s) - pfx.begin();
					if(k < pfx.size() && pfx[k] == s){
						next[i][j] = k;
						break;
					}
					s = s.substr(1);
				}
			}
		}
	}

	memset(dp, 0x3f, sizeof(dp));
	dp[start_x][start_y][0] = 0;
	queue<S> que;
	que.push(S(start_x, start_y, 0));

	while(!que.empty()){
		int cx = que.front().x, cy = que.front().y, ck = que.front().k;
		que.pop();

		if(cx == end_x && cy == end_y) return dp[cx][cy][ck];

		for(int i = 0; i < 4; i++){
			int nx = cx + v[i], ny = cy + h[i], nk = next[ck][i];
			if(!ng[nk]){
				if(0 <= nx && nx < N && 0 <= ny && ny < M && mat[nx][ny] != '#'){
					if(dp[nx][ny][nk] > dp[cx][cy][ck] + 1){
						dp[nx][ny][nk] = dp[cx][cy][ck] + 1;
						que.push(S(nx, ny, nk));
					}
				}
			}
		}
	}
	return -1;
}
void init(){
	P.clear();
	memset(ng, false, sizeof(ng));
	memset(next, 0, sizeof(next));
}
int main(){
	while(scanf("%d %d\n", &N, &M) && (N || M)){
		init();
		for(int i = 0; i < N; i++){
			scanf("%s", mat[i]);
			for(int j = 0; j < M; j++){
				if(mat[i][j] == 'S'){
					start_x = i;
					start_y = j;
				}
				else if(mat[i][j] == 'G'){
					end_x = i;
					end_y = j;
				}
			}
		}
		int tmp;
		cin>>tmp;
		for(int i = 0; i < tmp; i++){
			string s;
			cin>>s;
			P.push_back(s);
		}
		printf("%d\n", solve());
	}
	return 0;
}

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

#include <iostream>
#include <fstream>

#ifndef JHELPER1_COMMON_H
#define JHELPER1_COMMON_H

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

typedef long long ll;
using namespace std;

constexpr ll MOD = 1000 * 1000 * 1000 + 7;

#define READ_VEC(v) for(auto &e: v){in >> e;}
#define READ_PAIR_VEC(v) for(auto &e: v){in >> e.first >> e.second;}
#define ALL(c) std::begin(c), std::end(c)

// Returns x^y modulo MOD. O(log2(y)).
ll modPow(ll x, ll y) {
  ll res = 1, a = x;
  while (y > 0) {
    if ((y & 1) > 0) {
      res = (res * a) % MOD;
    }
    a = (a * a) % MOD;
    y >>= 1;
  }
  return res;
}

// Returns a^-1 module MOD.
ll inverse(ll a) {
  /*
   * Fermat's little theorem
   * http://en.wikipedia.org/wiki/Proofs_of_Fermat's_little_theorem
   *
   * <pre>
   * a^p = a (mod p)
   * a^(p-1) = 1 (mod p)
   * ..
   * 1/a = a^(p-2) (mod p)
   * </pre>
   */
  return modPow(a, MOD - 2);
}

#endif //JHELPER1_COMMON_H


class CRepsept {
public:
  void solve(std::istream& in, std::ostream& out) {
    ll K;
    in >> K;
    ll mo = 0;
    ll one = 1;
    for (int i = 1; i < 1000 * 1000 * 10; ++i) {
      mo += (7 * one) % K;
      mo %= K;
      if (mo == 0) {
        out << i << endl;
        return;
      }

      one *= 10;
      one %= K;
    }

    out << -1 << endl;
  }
};


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


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

int main(void) {

	short n, scoreT, scoreH;
	char cardT[100], cardH[100];
	int result;

	scanf("%d", &n);
	scoreT = scoreH = 0;

	for (int i = 1; i <= n; i++) {
		scanf("%s %s", cardT, cardH);

		result = strcmp(cardT, cardH);
		if (result > 0) {
			scoreT += 3;
		} else if (result < 0) {
			scoreH += 3;
		} else {
			scoreT += 1;
			scoreH += 1;
		}
	}

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

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a[i] = tmp;
  }
  vector<long long> ac(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    ac[i] = ac[i - 1] + a[i - 1];
  }
  vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, 0));
  for (int i = 0; i < n; i++) {
    dp[i][i + 1] = 0;
  }
  for (int dif = 2; dif <= n; dif++) {
    for (int i = 0; i + dif <= n; i++) {
      int j = i + dif;
      long long tmp = 1e18;
      for (int k = i + 1; k < j; k++) {
        tmp = min(tmp, dp[i][k] + dp[k][j]);
      }
      dp[i][j] = tmp - ac[i] + ac[j];
    }
  }
  cout << dp[0][n] << '\n';
  return 0;
}

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

using namespace std;

typedef long long ll;

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

    ll ret;

    string s;
    cin >> s;

    string ans = "";
    for (int i = 0;i < s.length() - 1;i++){
        ans += "9";
    }
    string n = ans;
    string next = ans;

    for (int i = 1;i < 10;i++){
         string a = to_string(i);
         next.insert(0,a);
         if (i == 9 && next <= s){
             ret = 9 * s.length();
             break;
         }else if (next <= s){
             ans = next;
             next = n;
         } else {
             ret = 9 * (s.length() - 1) + i - 1;
             break;
         }
    }

    cout << ret << endl;

    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int N,i,H[20],max=0,cnt=0;
    for(i=0;i<20;i++)
    H[i]=0;
    
    scanf("%d",&N);
    
    for(i=0;i<N;i++){
    scanf("%d",&H[i]);
    if(H[i]>=max){
    max=H[i];
    cnt++;
    }
    }
    printf("%d",cnt);
    
    return(0);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <set>
using namespace std;

int main() {
  string s, t, u = "abcdefghijklmnopqrstuvwxyz";
  cin >> s >> t;
  bool flag = true;
  set<char> a, b;
  for (int i = 0; i < u.size(); i++) {
    a.clear();
    b.clear();
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == u[i]) {
        a.insert(t[j]);
      }
      if (t[j] == u[i]) {
        b.insert(s[j]);
      }
    }
    if (a.size() > 1 || b.size() > 1) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 776
#define  _USE_MATH_DEFINES

#define  rep(i, n) for(int i = 0; i < n; i++)
#define  repx(i, a, n) for(int i = a; i < n; i++)
#define  loop while(1)
#define  lli long long int
 
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <utility>
#include <set>

using namespace std;

int main() {

  string masu;
  cin >> masu;
  
  int n = masu.size();
  vector<int> ans(n, 1);

  int cntR  = 0;
  int lastL = 0;
  int cntL  = 0;

  rep (i, n) {
    if (i == n - 1) {
      ans[lastL] += cntL + 1;
      ans[i] = 0;
    }
    else if (masu[i] == 'R' && masu[i + 1] == 'L') {
      ans[i] += cntR;
      cntR = 0;
      lastL = i + 1;
      i += 1;
    }
    else if (masu[i] == 'L' && masu[i + 1] == 'R') {
      ans[lastL] += cntL + 1;
      cntL = 0;
      ans[i] = 0;
    }
    else if (masu[i] == 'R') {
      cntR += 1;
      ans[i] = 0;
    }
    else if (masu[i] == 'L') {
      cntL += 1;
      ans[i] = 0;
    }
  }
  
  int tmp = 0;

  rep (i, n - 1) {
    if (ans[i] > 0) {
      tmp = ans[i] + ans[i + 1];
      if (ans[i] % 2 == ans[i + 1] % 2) {
        ans[i] = tmp / 2;
        ans[i + 1] = tmp / 2;
      }
      else {
        if (min(ans[i], ans[i + 1]) % 2 == 0) {
          if (ans[i] > ans[i + 1]) {
            ans[i] = tmp / 2 + 1;
            ans[i + 1] = tmp / 2;
          }
          else {
            ans[i] = tmp / 2;
            ans[i + 1] = tmp / 2 + 1;
          }
        }
        else {
          if (ans[i] > ans[i + 1]) {
            ans[i] = tmp / 2;
            ans[i + 1] = tmp / 2 + 1;
          }
          else {
            ans[i] = tmp / 2 + 1;
            ans[i + 1] = tmp / 2;
          }
        }
      }
    i += 1;
    }
  }
  rep (i, n) cout << ans[i] << (i < n - 1 ? " " : "\n");

  return 0;
}


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

int main(){
    string S;
    cin >> S;
    if(S == "BBB" || S == "AAA") cout << "No" <<endl;
    else cout << "Yes" << endl;
    return 0;
    
}

Measured memory_bytes: 256
n,m = gets.split.map {|x| x.to_i}
def max(x,y)
  return x > y ? x : y
end
def min(x,y)
  return x < y ? x : y
end
l0,r0 = gets.split.map {|x| x.to_i}
(m-1).times { |i|
  l,r  = gets.split.map {|x| x.to_i}
  l0 = max(l,l0)
  r0 = min(r,r0)
}
if r0 >= l0
  v = r0 - l0 + 1
else
  v = 0
end
puts v


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long  int n,k;
       cin>>n>>k;

      long long int health[n];

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

        sort(health,health+n);

          long long int sum=0;
        for(int i=0;i<=n-1-k;i++)
            sum+=health[i];

        cout<<sum;
}


Measured memory_bytes: 1792
#!/usr/bin/env python
S = raw_input()

while S != 'ABC':
	S2 = ""
	i = 0
	while True:
		if i >= len(S):
			break
		if S[i:min(len(S), i + 3)] == "ABC":
			S2 += "X"
			i += 2
		else:
			S2 += S[i]
		i += 1
	a_flag = 'A' in S2
	b_flag = 'B' in S2
	c_flag = 'C' in S2
	if not 'X' in S2:
		print "No"
		exit()
	if a_flag + b_flag + c_flag != 2:
		print "No"
		exit()
	SS = ''
	if not a_flag:
		SS = 'A'
	if not b_flag:
		SS = 'B'
	if not c_flag:
		SS = 'C'
	S3 = ''
	for c in S2:
		if c == 'X':
			S3 += SS
		else:
			S3 += c
	S = S3

print "Yes"


Measured memory_bytes: 4700
use std::io::{BufRead, Write};
use std::io;
use std::ops::{Add, Sub};

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let (a, b, c, d): (i8, i8, i8, i8) = {
        (buf[0..1].parse().unwrap(), buf[1..2].parse().unwrap(), buf[2..3].parse().unwrap(), buf[3..4].parse().unwrap())
    };
    let ops: [(fn(i8, i8) -> i8, char); 2] = [(i8::add, '+'), (i8::sub, '-')];
    'outer: for (i_op, i_chr) in ops.iter().cloned() {
        for (j_op, j_chr) in ops.iter().cloned() {
            for (k_op, k_chr) in ops.iter().cloned() {
                if (k_op(j_op(i_op(a, b), c), d)) == 7 {
                    writeln!(output, "{}{}{}{}{}{}{}=7", a, i_chr, b, j_chr, c, k_chr, d).unwrap();
                    break 'outer;
                }
            }
        }
    }
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "1222
",
            "1+2+2+2=7
",
        );
    }

    #[test]
    fn case2() {
        test(
            "0290
",
            "0-2+9+0=7
",
        );
    }

    #[test]
    fn case3() {
        test(
            "3242
",
            "3+2+4-2=7
",
        );
    }
}


Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
struct st
{
    string s;
    int num;
}ar[200000];
bool cmp(st a,st b)
{
    return a.s<b.s;
}
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        cin>>ar[i].s;
        ar[i].num=1;
    }
    sort(ar,ar+n,cmp);
    int cnt=1;
    for(i=1;i<n;i++)
    {
        if(ar[i-1].s==ar[i].s)
        {
            ar[i].num+=ar[i-1].num;
            ar[i-1].num=0;
            cnt=max(cnt,ar[i].num);
        }
    }
    for(i=0;i<n;i++)
    {
        if(ar[i].num==cnt)
            cout<<ar[i].s<<endl;
    }
    return 0;
}


Measured memory_bytes: 16640
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.ComTypes;
using System.Xml.Schema;
using System.ComponentModel.DataAnnotations;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, Q) = Slice2<long>();
            var S = ReadLine();
            var rui = new long[N + 1];
            for (var i = 1; i < N; ++i)
            {
                rui[i + 1] = rui[i];
                if (S.Substring(i - 1, 2) == "AC")
                    ++rui[i + 1];
            }
            for (var i = 0; i < Q; ++i)
            {
                var (l, r) = Slice2<long>();
                WriteLine(rui[r] - rui[l]);
            }
        }


        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

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

const int MAXH = 31;
const int MAXW = 31;
const int di[] = {0,1,0,-1,0};
const int dj[] = {1,0,-1,0,0};
int W, H;
char G[MAXH][MAXW];
int mem[MAXH][MAXW][MAXH][MAXW][2];

int main() {
  while(cin >> W >> H && (W|H)) {
    int sqi, sqj, sei, sej;
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        cin >> G[i][j];
        if(G[i][j] == 'Q') {
          sqi = i;
          sqj = j;
        }
        if(G[i][j] == 'A') {
          sei = i;
          sej = j;
        }
      }
    }
    
    fill(mem[0][0][0][0], mem[0][0][0][0] + sizeof(mem)/sizeof(int), 1);
    for(int qi = 0; qi < H; ++qi) {
      for(int qj = 0; qj < W; ++qj) {
        for(int ei = 0; ei < H; ++ei) {
          for(int ej = 0; ej < W; ++ej) {
            for(int t = 0; t < 2; ++t) {
              int &now = mem[qi][qj][ei][ej][t];
              if(G[qi][qj] == 'E' && t == 0) now = 2;
              if(qi == ei && qj == ej) now = 0;
            }
          }
        }
      }
    }
    
    for(bool update = true; update;) {
      update = false;
      for(int qi = 0; qi < H; ++qi) {
        for(int qj = 0; qj < W; ++qj) {
          for(int ei = 0; ei < H; ++ei) {
            for(int ej = 0; ej < W; ++ej) {
              for(int t = 0; t < 2; ++t) {
                int &now = mem[qi][qj][ei][ej][t];
                if(now != 1) continue;
                int tmp = t * 2;
                for(int k = 0; k < 5; ++k) {
                  int nqi =  t ? qi : qi + di[k];
                  int nqj =  t ? qj : qj + dj[k];
                  int nei = !t ? ei : ei + di[k];
                  int nej = !t ? ej : ej + dj[k];
                  if(nqi < 0 || nqi >= H) continue;
                  if(nqj < 0 || nqj >= W) continue;
                  if(nei < 0 || nei >= H) continue;
                  if(nej < 0 || nej >= W) continue;
                  if(G[nqi][nqj] == '#') continue;
                  if(G[nei][nej] == '#') continue;
                  if(t) tmp = min(tmp, mem[nqi][nqj][nei][nej][1-t]);
                  else  tmp = max(tmp, mem[nqi][nqj][nei][nej][1-t]);
                }
                if(tmp != 1) {
                  now = tmp;
                  update = true;
                }
              }
            }
          }
        }
      }
    }
    int res = mem[sqi][sqj][sei][sej][0];
    if(res == 0) cout << "Army can catch Queen." << endl;
    else if(res == 1) cout << "Queen can not escape and Army can not catch Queen." << endl;
    else cout << "Queen can escape." << endl;
  }
  return 0;
}

Measured memory_bytes: 8376
//https://codeforces.com/contest/1334/problem/A
//BROWNIE TK

#include <bits/stdc++.h>
using namespace std;

typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

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

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()

#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en

#define le length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second

#define pll pair<lli, lli>
#define pii pair<int, int>
#define pil pair<int, lli>

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)

#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)

#define bset(a, p) ((a) | (1ll << (p)))
#define bchk(a, p) ((a) & (1ll << (p)))
#define bxor(a, p) ((a) ^ (1ll << (p)));
#define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a))
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/

#define lb lower_bound
#define ub upper_bound
#define er equal_range

#define findnot find_first_not_of

#define maxe *max_element
#define mine *min_element

#define mod2 1000000007
#define mod 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements sbtriectly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order

/*STD funcions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli modi(lli a, lli m) { return power(a, m - 2, m); }
/*CODE BEGINS*/

int main()
{
    kira;
    lli n;
    cin>>n;
    cout<<n*n*n;
    return 0;
}

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

void solve() {
  int n;
  cin >> n;
  vector<double> x(n);
  vector<double> y(n);
  rep(i, n) cin >> x[i] >> y[i];
  vector<int> num(n);
  iota(num.begin(), num.end(), 0);
  double ans = 0;
  int count = 0;
  do {
    rep(i, n-1) {
      double lengthX = pow((x[num[i]] - x[num[i+1]]), 2);
      double lengthY = pow((y[num[i]] - y[num[i+1]]), 2);
      ans += sqrt(lengthX + lengthY);
    }
    count++;
  } while (next_permutation(num.begin(), num.end()));
  
  cout << setprecision(10) << ans / count << endl;
}


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


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>

///////////////////////////////////////////////////////////////
// namespace
///////////////////////////////////////////////////////////////
using namespace std;
// namespace mp = boost::multiprecision;

///////////////////////////////////////////////////////////////
// types
///////////////////////////////////////////////////////////////
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// using mpi = mp::cpp_int;
// using mpf = mp::number<mp::cpp_dec_float<1024>>;

///////////////////////////////////////////////////////////////
// mod https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
///////////////////////////////////////////////////////////////
// ll MOD = 1000000007;
//
// ll mod(long long val) {
//     long long res = val % MOD;
//     if (res < 0) res += MOD;
//     return res;
// }
//
// ll modinv(ll a) {
//     ll b = MOD, u = 1, v = 0;
//     while (b) {
//         ll t = a / b;
//         a -= t * b; swap(a, b);
//         u -= t * v; swap(u, v);
//     }
//     u %= MOD;
//     if (u < 0) u += MOD;
//     return u;
// }
//
// const int MAX = -1;
// ll fac[MAX], finv[MAX], inv[MAX];
// void com_init() {  // initialize nCk table with O(N)
//     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;
//     }
// }
// ll com(int n, int k){  // nCk
//     if (n < k) return 0;
//     if (n < 0 || k < 0) return 0;
//     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
// }

const int N = 55;
int h, w, num_w = 0;
char s[N][N];

struct P { int x, y; };

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

int main() {
    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> s[i][j];
            if (s[i][j] == '.') ++num_w;
        }
    }
    queue<pair<P, int>> q;
    q.emplace(P{0, 0}, 1);
    while (!q.empty()) {
        auto e = q.front(); q.pop();
        auto x = e.first.x;
        auto y = e.first.y;
        auto c = e.second;
        if (x == h - 1 && y == w - 1) {
            cout << num_w - c << endl;
            return 0;
        }
        if (x < 0 || x >= h || y < 0 || y >= w) continue;
        if (s[x][y] == '#') continue;
        s[x][y] = '#';
        for (int k = 0; k < 4; ++k) {
            auto next_x = x + dx[k];
            auto next_y = y + dy[k];
            q.emplace(P{next_x, next_y}, c + 1);
        }
    }
    cout << -1 << endl;
    return 0;
}


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

#define N 100000
#define MAX 1000000000000000000

int main (void)
{
    long long n, i = 0, j = 0;
    char s[100], s_tmp[100];

    scanf("%lld", &n);

    while (n > 0) {
        s_tmp[i] = 'a' + ((n - 1)% 26);

        n = (n - 1) / 26;
        i++;
    }

    s_tmp[i] = '\0';

    j = i;
    while (i > 0) {
        s[j - i] = s_tmp[i - 1];
        i--;
    }

    s[j] = '\0';

    printf("%s", s);

    return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair< int, int > P;
typedef pair< int, P > PP;

//-------------------------------------------------

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

	int n;
	cin >> n;
	ll cnt[n][21] = {};
	int kk;
	cin >> kk;
	cnt[1][kk] = 1;
	FOR(i, 1, n - 1) {
		int k;
		cin >> k;
        REP(j, 21) {
			if (j - k >= 0) cnt[i + 1][j - k] += cnt[i][j];
			if (j + k <= 20) cnt[i + 1][j + k] += cnt[i][j];
		}
	}
	int sum;
	cin >> sum;
	cout << cnt[n - 1][sum] << endl;

	return 0;
}




Measured memory_bytes: 3172
#include <stdio.h>
#include <algorithm>
using namespace std;

const int MAXN = (int)2e5 + 5;

int h[MAXN];
int a[MAXN];
long long bit[MAXN];

void add(long long val, int idx, int n) {
    while(idx <= n) {
        bit[idx] = max(bit[idx], val);
        idx += idx & -idx;
    }
    return;
}

long long query(int idx) {
    long long maxi = 0;
    while(idx > 0) {
        maxi = max(maxi, bit[idx]);
        idx -= idx & -idx;
    }
    return maxi;
}

long long solve(int n) {
    for (int i = 0; i < n; i++) {
        long long maxi = query(h[i]);
        add(maxi + a[i], h[i], n);
    }
    return query(n);
}

int main(void) {
    int n;

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

    long long ans = solve(n);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3328
import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().split()]
G = [[] for _ in range(N + 1)]
for _ in range(M):
    a, b = [int(x) for x in input().split()]
    G[a].append(b)
    G[b].append(a)
for i in range(1, (N + 1)):
    print(len(G[i]))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

int main() {
  string a,b,c;
  cin>>a>>b>>c;
  char ans='D';
    
  int cnt1=a.size();
  int cnt2=b.size();
  int cnt3=c.size();
  int cntall=0;
  int turn=1;//1=a;2=b;3=c
  int subcnt1=0;
  int subcnt2=0;
  int subcnt3=0;
  while(1){
    if(turn==1){
      if(cnt1==0){
        ans='A';
        break;
      }
      cnt1--;
      if(a[subcnt1]=='a')turn=1;
      if(a[subcnt1]=='b')turn=2;
      if(a[subcnt1]=='c')turn=3;
      subcnt1++;
    }
    else if(turn==2){
      if(cnt2==0){
        ans='B';
        break;
      }
      cnt2--;
      if(b[subcnt2]=='a')turn=1;
      if(b[subcnt2]=='b')turn=2;
      if(b[subcnt2]=='c')turn=3;
      subcnt2++;
    }
    else if(turn==3){
      if(cnt3==0){
        ans='C';
        break;
      }
      cnt3--;
      if(c[subcnt3]=='a')turn=1;
      if(c[subcnt3]=='b')turn=2;
      if(c[subcnt3]=='c')turn=3;
      subcnt3++;
    }
    cerr<<"loop:"<<cntall+1<<" next turn:"<<turn<<endl;
    cntall++;
  }
  
  cout<<ans;
     
}


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

int main(){
	int x, y;
	cin >> x >> y;
	
	if( x == 2 && y == 2 ){
		cout << "Yes" << endl;
	}
	
	else if( x == 4 || x == 6 || x == 9 || x == 11 ){
		if( y == 4 || y == 6 || y == 9 || y == 11 ){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	else if( x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12 ){
		if(  y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12 ){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	
	else{ cout << "No" << endl; }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int d[3],flag[8];
int main()
{
    cin>>d[0]>>d[1]>>d[2];
    for(int i=0;i<3;i++)
    {
        flag[d[i]]++;
    }
    if(flag[5]==2&&flag[7]==1)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <ctime>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 600010;

char s0[N];
int s[N], c[N];

int main()
{
	scanf("%s", s0 + 1);
	int len = strlen(s0 + 1);
	Rep(i, len) s[i] = s0[len - i + 1] - '0';
	
	Rep(i, len + 1) {
		s[i] = s[i] * 9 + c[i];
		c[i + 1] = s[i] / 10, s[i] %= 10;
	}
	if (s[len + 1]) len ++;
	int cnt = 0;
	Rep(i, len) cnt += s[i], c[i] = 0;
	int k = 1;
	while (true) {
		c[1] = 9;
		Rep(i, len + 1) {
			if (!c[i]) break;
			cnt -= s[i], s[i] += c[i], c[i] = 0;
			c[i + 1] = s[i] / 10, s[i] %= 10, cnt += s[i];
		}
		if (s[len + 1]) len ++;
		if (cnt <= k * 9) { printf("%d\n", k); return 0; }
		k ++;
	}
	
	return 0;
}

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

const long long MOD = 1000000007;

void solve(long long N) {
    long long res = 1;
  for (int i = 1; i <= N; i++) {
      res%=MOD;
      res*=i;
  }
  res%=MOD;
  cout << res << endl;
}

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

  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


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

int main() {
  double a, b, x;
  cin >> a >> b >> x;
  double v = a * a * b;
  double tan;
  if (2.0 * x < v) tan = a*b*b / (2.0 * x);
  else tan = 2.0 * (a*a*b-x) / (a*a*a);
  double deg = atan(tan) / pi * 180.0;
  cout << std::setprecision(10) << deg << endl;;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
  
int main(){
  string S;
  cin >> S;
  int K,A=S.size();
  cin >> K;
  for(int i=0;i<min(A,K);i++){
    if(S.at(i)!='1'){
      cout << S.at(i) << endl;
      return 0;
    }
  }
  cout << 1 << endl;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a > b){
       cout << "a > b" << endl;
    }
    if(a == b){
       cout << "a == b" << endl;
    }
    if(a < b){
       cout << "a < b" << endl;
    }

}




Measured memory_bytes: 3088
n, m, q= map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(q)]
ans = 0

for i1 in range(1, m+1):
    for i2 in range(i1, m+1):
        for i3 in range(i2, m+1):
            for i4 in range(i3, m+1):
                for i5 in range(i4, m+1):
                    for i6 in range(i5, m+1):
                        for i7 in range(i6, m+1):
                            for i8 in range(i7, m+1):
                                for i9 in range(i8, m+1):
                                    for i10 in range(i9, m+1):
                                        suuretsu = [i1, i2,i3,i4,i5,i6,i7,i8,i9,i10]
                                        tmp = 0
                                        for a,b,c,d in arr:
                                            if suuretsu[b-1] - suuretsu[a-1] == c:
                                                tmp += d
                                        ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 77388
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e8;
const ll infl = ll(1e18)+5;
/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

int main(){
 int n;
 ll k; cin >> n >> k;
 vector<ll> a(n);
 rep(i,n) cin >> a[i];
 sort(All(a));
 ll l=-infl,r=infl;
 //binary_search
 while(l+1 < r){
   ll mid = (l+r) / 2;
   //mid未満の数がk個未満か？
   bool ok = [&]{
     ll tot = 0;
     rep(i,n){
       //場合分け，
       if(a[i] < 0) {//ok,ngが入れ替わる l:ok,r:ng
         int l = -1,r = n;
         while(l+1 < r){
           int c = (l+r)/2;
           if(a[c]*a[i] < mid) r=c;else l=c;
         }
         tot+=n-r;//境界より右側はOK
       }else{
         int l = -1, r = n;
         while (l+1 < r)
         {
           int c = (l+r)/2;
           if(a[i]*a[c] < mid) l = c;else r = c;
         }
         tot+=r;
       }
       //自分自身
       if(a[i]*a[i] < mid) tot--;
     }
     tot/=2;//重複を省く
     return tot < k;
   }(); 
   if(ok) l = mid; else r = mid;
 }
 cout << l << endl;
 return 0;
}

Measured memory_bytes: 1920
from collections import Counter
n = int(input())
s = [input() for i in range(n)]

c = Counter(s)

for k in ['AC', 'WA', 'TLE', 'RE']:
    if k in c:
        print('{} x {}'.format(k, c[k]))
    else:
        print('{} x {}'.format(k, c[k]))

Measured memory_bytes: 16532
#include<bits/stdc++.h>
using namespace std;
int d[1001][1001];
int f[1001][1001];
signed main()
{
	int a,b;
	const int n=100;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=a;i++)
		for(int j=1;j<=b;j++)
			scanf("%d",&d[i][j]);
		
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n;j++)
			for(int x=1;x<=a;x++)
				for(int y=1;y<=b;y++)
					f[i][j]=max(f[i][j],d[x][y]-i*x-j*y);
	
	for(int x=1;x<=a;x++)
		for(int y=1;y<=b;y++)
		{
			int val=999999999;
			for(int i=0;i<=n;i++)
				for(int j=0;j<=n;j++)
					val=min(val,f[i][j]+i*x+j*y);
			if(val!=d[x][y])
			{
				printf("Impossible");
				return 0;
			}
		}
			
	printf("Possible\n");
	
	printf("202 10401\n");
	
	for(int i=1;i<=100;i++)
		printf("%d %d X\n",i,i+1);

	for(int i=102;i<202;i++)
		printf("%d %d Y\n",i,i+1);

	for(int i=0;i<=100;i++)
		for(int j=0;j<=100;j++)
			printf("%d %d %d\n",i+1,202-j,f[i][j]);
	printf("1 202\n");
	return 0;
}


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

typedef long long ll;
using namespace std;
const ll MOD=1000000007;
int main (){
    int n,m;
    cin >> n >> m;
    int a[m];
    for (int i = 0; i < m; i++){
        cin >> a[i];
    }
    int w[m+1];
    w[0]=a[0];
    w[m]=n-a[m-1];
    for (int i = 1; i < m; i++){
        w[i]=a[i]-a[i-1]-1;
    }
    ll fib[n+2];
    fib[0]=0;
    fib[1]=1;
    for (int i = 2; i < n+2; i++){
        fib[i]=fib[i-1]+fib[i-2];
        if(fib[i]>MOD) fib[i]-=MOD;
//        cout << i << " " <<  fib[i] << "\n";
    }
    ll ans=1;
    for (int i = 0; i < m+1; i++){
//        cout << i << " " << w[i] << " " << ans << "\n";
        ans*=fib[w[i]];
        ans%=MOD;
    }
    if(m==0) ans=fib[n+1];
    cout << ans << "\n";
}

Measured memory_bytes: 1792
N,W = map(int, input().split())
ws = []
vs = []
for i in range(N):
    w,v = map(int, input().split())
    ws.append(w)
    vs.append(v)
ws_m = [w-ws[0] for w in ws]

"""
i番目まで見て、n個選んでいて、重さがwのときのvの最大値
ただし、wはN個選んだときにW-N*[w[0]]となっているので、そこをmaxとする
dp[i][n][w] 
"""
dp = [[[-1]*(3*N+10) for i in range(N+1)] for j in range(N+1)]
dp[0][0][0] = 0
for i,(w,v)  in enumerate(zip(ws_m,vs)):
    for n in range(i+1):
        for j in range(3*N):
            dp[i+1][n][j] = max(dp[i+1][n][j], dp[i][n][j])
            # if dp[i][n][j] == -1: continue
            if j + (n+1)*ws[0] + w <= W:
                dp[i+1][n+1][j+w] = max(dp[i][n][j+w], dp[i][n][j] + v)

ans= 0
for i,As in enumerate(dp[N]):
    w = min(W - i*ws[0], sum(ws_m))
    if w >= 0:
        ans = max(ans,max(As[:w+1]))
print(ans)   


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

int main() {
  int n,k;
  cin >> n >> k;
  
  vector<int> x(n), y(n), xary(n), yary(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    xary[i] = x[i], yary[i] = y[i];
  }

  sort(xary.begin(),xary.end());
  sort(yary.begin(),yary.end());

  ll ans = 1LL * (xary[n - 1] - xary[0]) * (yary[n - 1] - yary[0]);
  for (int xi = 0; xi < n; xi++) {
    for (int xj = xi + 1; xj < n; xj++) {
      for (int yi = 0; yi < n; yi++) {
        for (int yj = yi + 1; yj < n; yj++) {

          int cnt = 0;
          ll lx = xary[xi], rx = xary[xj];
          ll by = yary[yi], uy = yary[yj];

          for (int i = 0; i < n; i++) {
            if(x[i] >= lx && x[i] <= rx && y[i] >= by && y[i] <= uy) {
              cnt++;
            }
          }
          if(cnt >= k) {
            ans = min(ans, 1LL * (rx - lx) * (uy - by));
          }
        }
      }
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long par[100005];
long long svertices[100005];
long long siz[100005];
long long bvertices[100005];
vector<long long int>v[100005];
long long a[100005];

long long int n,m;
vector< pair<long long,pair<long long,long long> > >vv;



long long int root(long long int A)
{
    while(A!=par[A])
    {
        A=par[A];
    }
    return A;
}


void union1(long long int A,long long int B,long long int len)
{
    long long int root_A=root(A);
    long long int root_B=root(B);
    if(root_A==root_B)
    {
        if(svertices[root_A]>=len)
        {
            bvertices[root_A]=0;
            return ;
        }
        else
        {
            bvertices[root_A]++;
        }
        return ;
    }
    long long sum=svertices[root_A]+svertices[root_B];
    if(sum>=len)
    {

        if(siz[root_A]>siz[root_B])
        {
            siz[root_A]+=siz[root_B];
            bvertices[root_A]=0;
            svertices[root_A]+=svertices[root_B];
            par[root_B]=root_A;
        }
        else if(siz[root_A]<=siz[root_B])
        {
            siz[root_B]+=siz[root_A];
            bvertices[root_B]=0;
            svertices[root_B]+=svertices[root_A];
            par[root_A]=root_B;
        }

        return ;
    }
    else
    {
        if(siz[root_A]>siz[root_B])
        {
            siz[root_A]+=siz[root_B];

            bvertices[root_A]+=bvertices[root_B]+1;

            svertices[root_A]+=svertices[root_B];
            par[root_B]=root_A;
        }
        else if(siz[root_A]<=siz[root_B])
        {
            siz[root_B]+=siz[root_A];
            bvertices[root_B]+=bvertices[root_A]+1;

            svertices[root_B]+=svertices[root_A];
            par[root_A]=root_B;
        }
        return ;
    }
    return ;
}
void initialise()
{
    int i;
    for(i=1;i<=n;i++)
    {
        siz[i]=1;
        par[i]=i;
        bvertices[i]=0;
        svertices[i]=a[i];
    }
}
int main()
{
    cin>>n>>m;

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

    initialise();
    long long int aa,bb,cc;
    for(i=1;i<=m;i++)
    {
        cin>>aa>>bb>>cc;
        vv.push_back(make_pair(cc,make_pair(aa,bb)));
    }
    sort(vv.begin(),vv.end());
    for(i=0;i<vv.size();i++)
    {
        long long int X=vv[i].first;
        long long int YX=vv[i].second.first;
        long long int YY=vv[i].second.second;
        union1(YX,YY,X);
    }
    map<long long int,long long int>m;
    for(i=1;i<=n;i++)
    {
        m[root(i)]=bvertices[root(i)];
    }
    long long int ans=0;
    for(auto it=m.begin();it!=m.end();it++)
    {
        ans+=it->second;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 11124
#include<iostream>

using namespace std;
typedef long long int ll;

ll h,w;
char grid[110][110],seq[210];
ll dp[110][110];

ll foo(int r,int c)
{
    if(dp[r][c]!=-1)
        return dp[r][c];
    if(r==h||c==w)
        return dp[r][c]=(1<<30);
    if(r==(h-1)&&c==(w-1))
        return dp[r][c]=(grid[r][c]=='#');
    return dp[r][c]=min((grid[r][c]=='#'&&grid[r+1][c]=='.')+foo(r+1,c),(grid[r][c]=='#'&&grid[r][c+1]=='.')+foo(r,c+1));
}

int main()
{
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>grid[i][j];
        }
    }
    for(int i=0;i<=h;i++){
        for(int j=0;j<=w;j++){
            dp[i][j]=-1;
        }
    }
    cout<<foo(0,0)<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0 ,1, 1, 1, 0, -1, -1, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int sumMod(int a, int b){return 0LL + a + b > mod ? a + b - mod : a + b;}
int H, W;
char v[1005][1005];
int dp[2][1005];
int f(int i, int j){
    if(i == H - 1 && j == W - 1)
        return 1;
    int &ans = dp[i][j];
    if(ans == -1){
        ans = 0;
        for(int k = 0; k < 2; k++){
            int x = i + dx[k];
            int y = j + dy[k];
            if(x >= 0 && x < H && y >= 0 && y < W && v[x][y] == '.')
                //ans = (ans % mod + f(x, y)% mod) % mod;
                ans = sumMod(ans, f(x, y));
        }
    }
    return ans;
}
int main(){
    //FL;
    FIN;
    cin >> H >> W;
    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++)
            cin >> v[i][j];
    for(int i = H - 1; i >= 0; i--){
        for(int j = W - 1; j >= 0; j--){
            int &ans = dp[i & 1][j];    
            if(i == H - 1 && j == W - 1){
                ans = 1;
                continue;
            } 
            ans = 0;
            for(int k = 0; k < 2; k++){
                int x = i + dx[k];
                int y = j + dy[k];
                if(x < H && y < W && v[x][y] == '.'){
                    ans = sumMod(ans, dp[x & 1][y]);
                }

            }
        }
    }
    cout << dp[0 & 1][0] << '\n';
    EjecuteTime;
    return 0;
}       

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

int main() {
  string S;
  cin >> S;
  
  int ans;
  if (S == "SUN")
    ans = 7;
  if (S == "MON")
    ans = 6;
  if (S == "TUE")
    ans = 5;
  if (S == "WED")
    ans = 4;
  if (S == "THU")
    ans = 3;
  if (S == "FRI")
    ans = 2;
  if (S == "SAT")
    ans = 1;
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
using namespace std;

typedef long long ll;

int main()
{
    int a,b;
    cin >> a >> b;
    cout << (b%a== 0? a+b : b-a) << "\n";
    return 0;
}

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

int gcd(int a, int b)
{   
    int c;
    while (a != 0) {
        c = a;
        a = b % a;
        b = c;
    }
    return b;
}

int main()
{
    int A, B, K;
    cin >> A >> B >> K;
    int g = gcd(A, B);
    if (K == 1) {
        cout << g << endl;
        return 0;
    }
    int c = 1;
    do {
        g--;
        if (A % g == 0 && B % g == 0) {
            c++;
            if (c == K) {
                cout << g << endl;
                return 0;
            }
        }
    } while (1);
}

Measured memory_bytes: 256
input = gets.chomp
arr = input.scan(/[ACGT]/)
i = 0
num = []
array = input.split("")
arr.each do |x|
  dix = array.index(x)
  return false unless dix
  num << dix
  array.delete_at(dix)
   
end
# Ruby2.4
#set = num.group_by(&:itself).transform_values(&:size)
set = num.group_by(&:itself)
.each_with_object({}) {|(k, v), hash| hash[k] = v.size}
s = set.max {|a, b| a[1] <=> b[1]}


puts s[1] rescue puts "0"



Measured memory_bytes: 1788
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O20")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
using ll = int_fast64_t; using namespace std;

#ifndef __GNUC__
string text =
R"X(HATAGAYA)X";
stringstream iss{text};
#endif

ll maxl;
int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	//ll N; iss >> N;
	string s; iss >> s;
	regex  re("(A|G|C|T)+");
	sregex_iterator it(begin(s), end(s), re);
	sregex_iterator end;
	for (; it != end; ++it) {
		auto &&m = *it;
		maxl = max(maxl, m.length( ));
	}
	cout << maxl << "\n";
}


Measured memory_bytes: 3784
a = input()
n = int(input())
t = 1
ar = []
while True:
    for i in range(len(a) - t + 1):
        if a[i:i+t] not in ar:
            ar.append(a[i:i+t])
    t += 1
    if t > len(a) or t > n:
        break
ar.sort()
print(ar[n-1])
        

Measured memory_bytes: 9948
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;
const string YES = "Yes";
const string NO = "No";

void solve(ll N, vector<vector<ll>> D) {
  ll cnt(0);
  REP(i, N) {
    if (D[i][0] == D[i][1])
      cnt++;
    else
      cnt = 0;
    if (cnt >= 3) {
      cout << YES << endl;
      return;
    }
  }
  cout << NO << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<vector<ll>> D(N, vector<ll>(2));
  REP(i, N) {
    REP(j, 2) {
      cin >> D[i][j];
    }
  }

  solve(N, move(D));

  return 0;
}


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

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	int N;
	cin >> N;
	std::vector<int> frimin(N);
	std::vector<int> frimax(N);
	for (int i = 0; i < N; i++) {
		cin >> frimin[i] >> frimax[i];
	}

	std::sort(frimin.begin(), frimin.end());
	std::sort(frimax.begin(), frimax.end());

	int ret = 0;
	int count = 1;
	int imin = -1;
	int imax = -1;
	for (int f = 2; f < N+2 && f <= frimax[N-1]; f++) {
		for (int i = imin+1; frimin[i] == f; i++) {
			count++;
			imin++;
		}
		for (int i = imax+1; frimax[i] == f-1; i++) {
			count--;
			imax++;
		}

		if ( count >= f && count != 1 ) {
			ret = f-1;
		}
	}

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3508