akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define DEC(i, s) for (int i = (s); i >= 0; i--)

#define SIZE(v) (int)((v).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())

int w, h;
int field[100][100];
bool visit[100][100];
const int dx[8] = { 1, 1, 1, 0, -1, -1, -1, 0 };
const int dy[8] = { 1, 0, -1, -1, -1, 0, 1, 1 };

void dfs(int x, int y) {
  if (visit[y][x]) { return; }
  visit[y][x] = true;
  REP(i, 8) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (nx < 0 || nx >= w || ny < 0 || ny >= h) { continue; }
    if (field[ny][nx] == 0) { continue; }
    dfs(nx, ny);
  }
}

int main() {
  while (scanf("%d %d", &w, &h), w|h) {
    MEMSET(field, 0);
    MEMSET(visit, false);
    REP(y, h) REP(x, w) {
      scanf("%d", &field[y][x]);
    }
    int ans = 0;
    REP(y, h) REP(x, w) {
      if (visit[y][x] || field[y][x] == 0) { continue; }
      ans++;
      dfs(x, y);
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
static const int MAX = 100;
static const ll INF = 10000000;
ll d[MAX][MAX];
int N, M;
 
struct  Data {
  int u, v;
  ll c;
  Data() {}
  Data(int u, int v, ll c) : u(u), v(v), c(c){}
};
 
void warshall_floyd() {
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if(i == j) d[i][j] = 0;
      else d[i][j] = INF;
    }
  }
 
  Data data[M];
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    data[i] = Data(a, b, c);
    d[a][b] = c;
    d[b][a] = c;
  }
  int cnt = 0;
  warshall_floyd();
 
  for (int i = 0; i < M; i++) {
    int a = data[i].u;
    int b = data[i].v;
    bool flag = true;
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        ll d1 = d[j][a] + data[i].c + d[b][k];
        ll d2 = d[j][k];
        if(d1 == d2) {
          flag = false;
          goto loop;
        }
      }
    }
    loop:
    if(flag) cnt++;
  }
  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.text.*;

class Main {
    public static void main(String[]args)throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int [][][] cnt = new int[4][3][10];
        while(n-- > 0) {
            int b = sc.nextInt() - 1;
            int f = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            int v = sc.nextInt();
            cnt[b][f][r] += v;
        }
        for(int b = 0; b < 4; b++) {
            if(b>0)System.out.println("####################");
            for(int f = 0; f < 3; f++) {
                for(int r = 0; r < 10; r++) {
                    System.out.print(" " + cnt[b][f][r]);
                }
                System.out.println();
            }
        }
    }
}

Measured memory_bytes: 21232
#include<stdio.h>
int main()
{
    int i;
    char s[3];
  	int ans = 0;
  	for(i=0;i<3;i++){
      scanf("%s", &s[i]);
      if(s[i] == '1'){
          ans++;
      }
    }
	printf("%d",ans);    
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int count = 0;
    bool ch = true;
    while(ch) {
        for (int i = 0; i < N; i++) {
            ch = a[i]%2 == 0;
            if (ch) {
                a[i] /= 2;
                if (i == N-1) count++;
            } else break;
        }
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

type City struct {
	num, year int
	id        string
}

type ByYear []City

func (a ByYear) Len() int           { return len(a) }
func (a ByYear) Less(i, j int) bool { return a[i].year < a[j].year }
func (a ByYear) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type ByNum []City

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, M := sc.nextInt(), sc.nextInt()
	cities := make([][]City, N+1)
	for i := 0; i < M; i++ {
		p, y := sc.nextInt(), sc.nextInt()
		cities[p] = append(cities[p], City{i, y, ""})
	}
	ans := []City{}
	for p, a := range cities {
		sort.Sort(ByYear(a))
		indx := 1
		for _, city := range a {
			city.id = fmt.Sprintf("%06d%06d", p, indx)
			indx++
			ans = append(ans, city)
		}
	}
	sort.Sort(ByNum(ans))
	for _, c := range ans {
		fmt.Fprintln(wtr, c.id)
	}
	wtr.Flush()
}


Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define R cin>>
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
const int MAX_V= 1002;
 
struct edge{
  int to,cap,cost,rev;
  edge(int to,int cap,int cost,int rev) :
    to(to),cap(cap),cost(cost),rev(rev) {}
};
  
vector<edge> G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];
  
void add_edge(int from,int to,int cap,int cost){
  G[from].push_back(edge(to,cap,cost,G[to].size()));
  G[to].push_back(edge(from,0,-cost,G[from].size()-1));
}
  
int min_cost_flow(int s,int t,int f){
  int res = 0;
  while(f>0){
    fill(dist,dist+MAX_V,MAX); dist[s] = 0;
    bool update=true;
    while(update){
      update=false;
      for(int v=0; v<MAX_V; v++){
        if(dist[v]==MAX) continue;
        for(int i=0; i<(int)G[v].size(); i++){
          edge &e=G[v][i];
          if(e.cap>0 && dist[e.to]>dist[v]+e.cost){
            dist[e.to]=dist[v]+e.cost;
            prevv[e.to]=v; preve[e.to]=i; update=true;
          }
        }
      }
    }
    if(dist[t]==MAX) return -1;
    int d = f;
    for(int v=t; v!=s; v=prevv[v]){
      d=min(d,G[prevv[v]][preve[v]].cap);
    }
    f-=d;res+=d*dist[t];
    for(int v=t; v!=s; v=prevv[v]){
      edge &e=G[prevv[v]][preve[v]];
      e.cap-=d;G[v][e.rev].cap+=d;
    }
  }
  return res;
}

int main() {
  int n;
  R n;
  int w[n][n],e[n][n];
  rep(i,n)rep(j,n) R w[i][j];
  rep(i,n)rep(j,n) R e[i][j];
  string s[n],t[n];
  rep(i,n) {
    R s[i];
    rep(j,n) t[i]+='.';
  }
  rep(i,n) {
    add_edge(201,i,1,0);
    add_edge(100+i,202,1,0);
    rep(j,n) {
      int sum=0;
      if(s[i][j]=='.') {
	sum+=w[i][j]*2;
	rep(k,n) if(s[i][k]=='o') sum+=e[i][k];
	rep(k,n) if(s[k][j]=='o') sum+=e[k][j];
      } else {
	rep(k,n) {
	  if(k==j) continue;
	  if(s[i][k]=='o') sum+=e[i][k];
	}
	rep(k,n) {
	  if(k==i) continue;
	  if(s[k][j]=='o') sum+=e[k][j];
	}
      }
      add_edge(i,j+100,1,sum);
    }
  }
  pr(min_cost_flow(201,202,n)/2);
  rep(i,n) {
    rep(j,G[i].size()) {
      edge p=G[i][j];
      if(!p.cap && p.to>=100 && p.to<200) t[i][p.to-100]='o';
     }
  }
  int cnt=0;
  rep(i,n) {
    rep(j,n) {
      if(s[i][j]!=t[i][j]) cnt++;
    }
  }
  pr(cnt);
  rep(i,n) {
    rep(j,n) {
      if(s[i][j]==t[i][j]) continue;
      cout << i+1 << " " << j+1;
      if(t[i][j]=='o') cout << " write" << endl;
      else cout << " erase" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
#define mod 998244353
using namespace std;
int read();
int n, k;
int fac[500005], caf[500005], lim = 500000;
int fsp(int bs, int p) {
    int rt = 1;
    while (p) {
        if (p & 1) rt = 1ll * rt * bs % mod;
        bs = 1ll * bs * bs % mod, p >>= 1;
    }
    return rt;
}
void init() {
    fac[0] = 1;
    for (int i = 1; i <= lim; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
    caf[lim] = fsp(fac[lim], mod - 2);
    for (int i = lim; i >= 1; --i) caf[i - 1] = 1ll * caf[i] * i % mod;
}
int C(int x, int y) { return 1ll * fac[x] * caf[y] % mod * caf[x - y] % mod; }

int main() {
    n = read(), k = read(), init();
    long long res = 0;
    for (int i = n; i <= k; ++i) res += C(k - 1, i - 1);
    printf("%lld\n", res % mod);
    return 0;
}
const int _SIZE = 1 << 22;
char ibuf[_SIZE], *iS = ibuf, *iT = ibuf;
#define gc                                                         \
    (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)), \
     (iS == iT ? EOF : *iS++) : *iS++)
int read() {
    int x = 0, f = 1;
    char c = gc;
    while (!isdigit(c)) f = (c == '-') ? -1 : f, c = gc;
    while (isdigit(c)) x = x * 10 + c - '0', c = gc;
    return x * f;
}

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

int main() {
    int H, W, M; cin >> H >> W >> M;
    unordered_map<int, int> x_counter;
    unordered_map<int, int> y_counter;
    unordered_map<int, unordered_set<int>> bombs;
    auto has = [&](int x, int y){
        if (bombs.count(x) == 0) return false;
        return static_cast<bool>(bombs.at(x).count(y));
    };
    for (int i = 0; i < M; ++i) {
        int x, y; cin >> x >> y; --x; --y;
        bombs[x].insert(y);
        x_counter[x]++;
        y_counter[y]++;
    }
    vector<pair<int, int>> vx;
    vector<pair<int, int>> vy;
    for (auto [x, c]: x_counter) {
        vx.emplace_back(c, x);
    }
    for (auto [y, c]: y_counter) {
        vy.emplace_back(c, y);
    }
    sort(vx.begin(), vx.end());
    sort(vy.begin(), vy.end());
    reverse(vx.begin(), vx.end());
    reverse(vy.begin(), vy.end());
    int ans = 0;
    for (int i = 0; i < min(vx.size(), (unsigned long)100); ++i) {
        for (int j = 0; j < vy.size(); ++j) {
            int x = vx[i].second;
            int x_count = vx[i].first;
            int y = vy[j].second;
            int y_count = vy[j].first;
            if (has(x, y)) {
                // cout << "*";
                // cout << x + 1 << " " << y + 1 << " " << x_count << " " << y_count << " " << x_count + y_count - 1 << endl;
                ans = max(ans, x_count + y_count - 1);
            } else {
                // cout << " ";
                // cout << x + 1 << " " << y + 1 << " " << x_count << " " << y_count << " " << x_count + y_count << endl;
                ans = max(ans, x_count + y_count);
            }
        }
    }
    for (int i = 0; i < vx.size(); ++i) {
        for (int j = 0; j < min(vy.size(), (unsigned long)100); ++j) {
            int x = vx[i].second;
            int x_count = vx[i].first;
            int y = vy[j].second;
            int y_count = vy[j].first;
            if (has(x, y)) {
                // cout << "*";
                // cout << x + 1 << " " << y + 1 << " " << x_count << " " << y_count << " " << x_count + y_count - 1 << endl;
                ans = max(ans, x_count + y_count - 1);
            } else {
                // cout << " ";
                // cout << x + 1 << " " << y + 1 << " " << x_count << " " << y_count << " " << x_count + y_count << endl;
                ans = max(ans, x_count + y_count);
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 84856
#include <cmath>
#include<vector>
#define rep(i, n) for (int i=0;i<n;i++)
#include <map> 
#include<algorithm>
#include <numeric>
#include<iostream>
#include<deque>
#include<queue>
#include<string>
#include <iomanip>
using namespace std;
typedef long long ll;

ll gcd(ll m, ll k){
    if (k==0){
        return m;
    }
    else{
        return gcd(k, m%k);
    }
}

int main(void){
    int n;
    cin>>n;
    vector <ll> a(n);
    rep(i, n){
        cin>>a[i];
    }
    vector <ll> l(n+1);
    vector<ll> r(n+1);
    l[0]=0;
    r[n]=0;
    rep(i, n){
        l[i+1]=gcd(l[i], a[i]);
        r[n-i-1]=gcd(r[n-i], a[n-i-1]);
    }
    ll maxg=0;
    for(ll i=0;i<=n-1;i++){
        ll g=gcd(l[i], r[i+1]);
        maxg=max(g, maxg);
        
    }
    cout<<maxg<<endl;

}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << x << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int a, b;
  cin >> a >> b;
  int mini = min(a, b);
  int maxi = max(a, b);
  int dif  = maxi - mini;
  if (dif & 1) cout << "IMPOSSIBLE" << endl;
  else cout << mini + dif / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a >= b){if(a >= c){a *= 10;}else{c *= 10;}}
else{if(b >= c){b *= 10;}else{c *= 10;}}
printf("%d\n",a+b+c);
return 0;
}


Measured memory_bytes: 128
I=input
for _ in [0]*int(I()):
    t=I()
    a=t[0]
    for x in range(1,len(t),3):
        if t[x+2] in a:continue
        if t[x]=='-':a+=t[x+2]
        else:a= t[x+2]+a
    print(a)

Measured memory_bytes: 7492
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    int r = 0, k = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') {
            k++;
        } else {
            k = 0;
        }
        r = max(r, k);
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 3620
#include<cstdio>
char a[101];
int main(){
    int h,w;
    scanf("%d%d",&h,&w);
    for(int i=0;i<=w+1;i++)printf("#");
    printf("\n");
    for(int i=0;i<h;i++){
        scanf("%s",a);
        printf("#%s#\n",a);
    }
    for(int i=0;i<=w+1;i++)printf("#");
    return 0;
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define nono(x, ite) for(__typeof((x).begin()) ite=(x).begin(); ite != (x).end(); ite++)

typedef long long ll;

ll ans = 0;

void solve(ll a, ll b) {
  if(a < b) swap(a, b);
  ll t = a % b;
  ans += 2 * (a - t);
  if(t > 0) solve(b, t);
  else ans -= b;
}

int main() {
  ios::sync_with_stdio(false);
  ll n, x;
  cin >> n >> x;
  ans = x + n - x;
  solve(x, n - x);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 200005
using namespace std;
int A[M],B[M];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	int head=1,tail=n;
	int f=0,k=n;
	while(head<=tail){
		if(f==0)B[head++]=A[k--];
		else B[tail--]=A[k--];
		f^=1;
	}
	for(int i=1;i<n;i++)printf("%d ",B[i]);
	printf("%d\n",B[n]);
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiil;
typedef pair<pll, ll> pplll;
typedef pair<pli, int> pplii;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<pll>> vvpll;
#define rep(i, a, b) for (ll i=(a); i<(b); i++)
#define rrep(i, a, b) for (ll i=(a); i>(b); i--)
#define pb push_back
#define tostr to_string
#define mkp make_pair
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

void print(ld out) { cout << fixed << setprecision(12) << out << '\n'; }
template<typename T> void print(T out) { cout << out << '\n'; }
template<typename T1, typename T2> void print(pair<T1, T2> out) { cout << out.first << ' ' << out.second << '\n'; }
template<typename T> void print(vector<T> A) { rep(i, 0, A.size()) { cout << A[i]; cout << (i == A.size()-1 ? '\n' : ' '); } }
template<typename T> void print(set<T> S) { vector<T> A(S.begin(), S.end()); print(A); }

template<typename T> inline bool chmax(T &x, T y) { return (y > x) ? x = y, true : false; }
template<typename T> inline bool chmin(T &x, T y) { return (y < x) ? x = y, true : false; }

ll sum(vector<ll> A) { ll res = 0; for (ll a: A) res += a; return res; }
ll max(vector<ll> A) { ll res = -INF; for (ll a: A) chmax(res, a); return res; }
ll min(vector<ll> A) { ll res = INF; for (ll a: A) chmin(res, a); return res; }

ll toint(string s) { ll res = 0; for (char c : s) { res *= 10; res += (c - '0'); } return res; }
int toint(char c) { return c - '0'; }
char tochar(int i) { return '0' + i; }

inline ll pow(int x, ll n) { ll res = 1; rep(_, 0, n) res *= x; return res; }
inline ll pow(ll x, ll n, int mod) { ll res = 1; while (n > 0) { if (n & 1) { res = (res * x) % mod; } x = (x * x) % mod; n >>= 1; } return res; }

inline ll floor(ll a, ll b) { if (a < 0) { return (a-b+1) / b; } else { return a / b; } }
inline ll ceil(ll a, ll b) { if (a >= 0) { return (a+b-1) / b; } else { return a / b; } }

int popcount(ll S) { return __builtin_popcountll(S); }
ll gcd(ll a, ll b) { return __gcd(a, b); }

ll N, M, Q;
vvl table;
vvl perm;

void rec(vector<ll> &li, ll depth) {
    if (depth == N) {
        perm.pb(li);
        return;
    }
    ll s;
    if (!li.empty()) {
        s = li.back();
    } else {
        s = 1;
    }
    rep(x, s, M+1) {
        li.pb(x);
        rec(li, depth+1);
        li.pop_back();
    }
}

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

    cin >> N >> M >> Q;
    table.resize(Q);
    ll a, b, c, d;
    rep(i, 0, Q) {
        cin >> a >> b >> c >> d;
        table[i] = {--a, --b, c, d};
    }

    vector<ll> li;
    rec(li, 0);

    ll ans = 0;
    for (auto A : perm) {
        ll cnt = 0;
        for (auto abcd : table) {
            if (A[abcd[1]] - A[abcd[0]] == abcd[2]) {
                cnt += abcd[3];
            }
        }
        chmax(ans, cnt);
    }
    print(ans);
    return 0;
}


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

using namespace std;

int main(){
    
    int a, b;
    cin>>a>>b;
    if (b<a){
        swap(a,b);
    }
    string s(b,'x');
    for (int i=0; i<b; i++){
        char c;
        c = '0'+a;
        s[i] = c;
    }
    cout<<s;
    
    return 0;
}

Measured memory_bytes: 256
#C
N = int(input())
name = str(input())
nlen = len(name)
S = [list(str(input())) for i in range(N)]

ans = 0
for i in range(N):
    s = S[i]
    
    flag = 0
    slen = len(s)
    for j in range(1,101):
        wide = j
        for k in range(slen):
            now = k
            kari = ""
            for l in range(nlen):
                if now < slen:
                    kari+=s[now]
                else:
                    break
                now+=wide
            if kari == name:
                flag = 1
                break
        if flag == 1:
            break
            
    if flag == 1:
        ans+=1

print(ans)


Measured memory_bytes: 5644
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		
		if((a * b) % 2 == 1) {
			System.out.println("Odd");			
		}else {
			System.out.println("Even");
		}
	}

}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
int d[11][11];
inline void chkmin(int &x,int y){
	if(y<x) x=y;
}
int main(){
	int n=read(),m=read();
	REP(i,0,9)REP(j,0,9) d[i][j]=read();
	REP(k,0,9)
		REP(i,0,9)
			REP(j,0,9)
				chkmin(d[i][j],d[i][k]+d[k][j]);
	int ans=0;
	REP(i,1,n)REP(j,1,m){
		int x=read();
		ans+=d[x][1];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main() {
    val reader = System.`in`.bufferedReader()
    val INF = 1000000
    var (H, W) = reader.readLine()!!.split(" ").map(String::toInt)
    var (CH, CW) = reader.readLine()!!.split(" ").map{it.toInt()-1}
    var (DH, DW) = reader.readLine()!!.split(" ").map{it.toInt()-1}
    var S = Array(H) {IntArray(W) {-1}}
    (0 .. H-1).forEach{ i ->
        var s = reader.readLine()!!
        (0 .. W-1).forEach{ j ->
            if (s[j] == '.') {
                S[i][j] = INF
            }
        }
    }

    // スタートノードから各ノードへの距離。ただし未訪問(初期状態)なら-1
    S[CH][CW] = 0
    
    // スタートノードをキューに入れる
    var q = LinkedList<Pair<Int, Int>>()
    q.offer(Pair(CH, CW))
    // 幅優先探索で、未訪問のマスをスタートマスから近い順に巡る
    var DIR1 = arrayOf(Pair(0, 1), Pair(1, 0), Pair(0, -1), Pair(-1, 0))
    var DIR2 = arrayOf(
        Pair(-2, -2), Pair(-2, -1), Pair(-2, 0), Pair(-2, 1), Pair(-2, 2),
        Pair(-1, -2), Pair(-1, -1), Pair(-1, 1), Pair(-1, 2),
        Pair(0, -2), Pair(0, 2),
        Pair(1, -2), Pair(1, -1), Pair(1, 1), Pair(1, 2),
        Pair(2, -2), Pair(2, -1), Pair(2, 0), Pair(2, 1), Pair(2, 2)
        )
    while (!q.isEmpty()) {
        var (y, x) = q.poll()
        var d = S[y][x]
        DIR1.forEach { (dy, dx) -> 
            var ny = y + dy
            var nx = x + dx
            if (0 <= ny && ny < H && 0 <= nx && nx < W && S[ny][nx] > d) {
                S[ny][nx] = d
                q.offerFirst(Pair(ny, nx))
            }
        }
        DIR2.forEach { (dy, dx) -> 
            var ny = y + dy
            var nx = x + dx
            if (0 <= ny && ny < H && 0 <= nx && nx < W && S[ny][nx] > d+1) {
                S[ny][nx] = d + 1
                q.offerLast(Pair(ny, nx))
            }
        }
    }
    println(if (S[DH][DW] == INF) -1 else S[DH][DW])
}


Measured memory_bytes: 65968
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define debug(x) cerr<<#x<<" "<<x<<endl;
#define f(i,n) for(ll i=0; i<n; i++)
#define f1(i,n) for(ll i=1; i<=n; i++)
#define fr(i,n) for(ll i=n-1; i>=0; i--)
#define f1r(i,n) for(ll i=n; i>0; i--)
#define mst(arr,val) memset(arr,val,sizeof(arr))
#define all(x) x.begin(),x.end()

typedef long long int ll;
typedef pair<ll,ll> pii;
ll M=1e9+7;
ll M2=998244353;
void show(vector<ll> v)
{
    for(ll i=0; i<v.size(); i++)
        cout<<v[i]<<" ";
    cout<<"\n";
}
void showrev(vector<ll> v)
{
    for(ll i=0; i<v.size(); i++)
        cout<<v[v.size()-i-1]<<" ";
    cout<<"\n";
}
void showarr(ll arr[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<arr[i]<<" ";
    cout<<"\n";
}
void showpv(vector<pair<ll,ll> > v)
{
    f(i,v.size())
        cout<<"("<<v[i].ff<<","<<v[i].ss<<")"<<" ";
    cout<<"\n";
}
int main()
{
    IOS
    ll T = 1,Q=1;
    //cin>>T;
    while(T--)
    {
        string str; cin>>str;
        if(str[2] == str[3] and str[4] == str[5])
            cout<<"Yes\n";
        else cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <bitset>
#include <map>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

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

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

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

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};
int main(){
	int N;
	bool flag = false;
	cin >> N;
	REP(i, N+1){
		int base = N;
		flag = false;
		vector<int> elem;
		for(int j = i;j >= 1;j--){
			if(base >= j){
				base -= j;
				elem.push_back(j);
				if(base == 0){
					REP(k, elem.size()){
						cout << elem[k] << endl;
					}
					i = N;
					break;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <functional>
#include <vector>
#include <math.h>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

const int N_MAX = 100001;
int N;
int d[N_MAX];
int L;

int main(){
    cin >> N;
    for (int i=0;i<N;i++){
        cin >> d[i];
    }
    sort(d, d+N);
    cout << d[N/2] - d[(N/2)-1] << endl;
}


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

#define ll long long
#define mp make_pair
#define rep(i, a, b) for(int i = (a);i <= (b);i++)
#define per(i, a, b) for(int i = (a);i >= (b);i--)

using namespace std;

typedef pair<int, int> pii;
typedef double db;
const int N = 1e6 + 50;
int n, k, a[N], cnt = 0, flag = 0; 
int ans = 0, maxx, minn, pmax, pmin;
int vis[N], f[N];
priority_queue < int, vector<int>, greater<int> > q;
priority_queue < int, vector<int>, less<int> > p;
inline int read(){
	int x = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') f = -1; ch = getchar();}
	while(ch >='0' && ch <='9'){x = (x<<3)+(x<<1)+(ch^48); ch = getchar();}
	return x*f;
}
void init(){
	n = read(); k = read();
	rep(i, 1, n) a[i] = read();
	rep(i, 1, k){
		p.push(a[i]); q.push(a[i]);
	}
	rep(i, 2, n){
		if(a[i] > a[i-1]){
			int sum = 0;
			while(a[i] > a[i-1] && i <= n){
				i++;
				sum++;
			}
//			cout << sum << endl;
			if(sum >= k-1){
				cnt ++;
			}
		}
	}
	ans = n-k+1;
	int l = 1, r = k;
	while(r <= n){
//		cout << l << " " << r << " "<<q.top() << " "<<p.top() <<endl; 	
		r++;
		if(r > n) break;
		while(vis[q.top()]) q.pop(); 
		while(f[p.top()]) p.pop();
//		cout << vis[1] << endl;
//		cout << vis[q.top()] << " " << q.top() << endl; 
		if(a[l] == q.top() && a[r] > p.top()){
			q.pop(); p.push(a[r]);
			q.push(a[r]);
			f[a[l]] = 1;
			ans --;
		}
		else if(a[l] == q.top() && a[r] < p.top()){
			q.pop(); p.push(a[r]);
			q.push(a[r]);
			f[a[l]] = 1;
		}
		else if(a[l] == p.top()){
			p.pop(); p.push(a[r]);
			q.push(a[r]);
			vis[a[l]] = 1;
//			cout << a[l] << " " <<100 << endl;
		}
		else if(a[l] != q.top() && a[l] != p.top()){
			p.push(a[r]); q.push(a[r]);
			f[a[l]] = 1, vis[a[l]] = 1;
//			cout << a[l] << " " << 100 << endl;
		}
		
		l++;
	}
	if(!cnt) printf("%d\n", ans);
	else printf("%d\n", ans - cnt+1);
}
int main(){
//	freopen("input.in","r",stdin);
//	freopen("output.out","w",stdout);
	init();
	return 0;
}
/*
10 5
1 8 3 2 4 6 7 5 9 10
*/

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

int main() {
    int r;
    cin >> r;
    cout << 3*r*r << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string st;
    while(cin>>st){
        string str=st;
        reverse(st.begin(),st.end());
        if(st==str) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  ll K, A, B;
  cin >> K >> A >> B;
  if (B-A<=2||K<A-1) cout << K+1 << endl;
  else {
    ll res = A;
    K -= A-1;
    if (K%2!=0) {
      res++;
      K--;
    }
    res += (B-A)*(K/2);
    cout << res << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define PUTS(x) cout << (x) << endl;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define PB push_back
#define perm(c)                   \
    sort((c).begin(), (c).end()); \
    for (bool c##p = 1; c##p; c##p = next_permutation((c).begin(), (c).end()))
int main() {
    const Int INF = 1e10;
    Int n, m, r;
    cin >> n >> m >> r;
    auto v = vector<Int>();
    rep(i, r) {
        Int x;
        cin >> x;
        x--;
        v.PB(x);
    }

    auto dp = vector<vector<Int>>(n, vector<Int>(n, INF));
    rep(i, n) {
        dp[i][i] = 0;
    }

    rep(i, m) {
        Int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        dp[a][b] = c;
        dp[b][a] = c;
    }

    rep(k, n) {
        rep(i, n) {
            rep(j, n) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }

    auto ans = INF;
    perm(v) {
        auto result = 0LL;
        reps(i, r - 1) {
            result += dp[v[i - 1]][v[i]];
        }
        ans = min(ans, result);
    }
    PUTS(ans);
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  sort(h.begin(), h.end());
  rep(i,k) {
    if(h.size()==0) break;
    h.pop_back();
  }
  ll ans = 0;
  for(auto p: h) {
    ans += p;
  }
   
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011LL
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pll a, pll b)//true for a before b
{
	if(a.F*b.S < b.F*a.S)
		return 1;
	if(a.F*b.S > b.F*a.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (2e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 100;
const int SQRT = BUCK+9;



void solve()
{
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if(k % 2LL == 0LL)
		cout << (a-b) << '\n';
	else
		cout << (b-a) << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        s: chars,
    }
    let mut count = s.iter().filter(|x| **x == '.').count();
    if count == n || count == 0 {
        println!("0");
        return;
    }
    let mut ans = count;
    for i in 0..n {
        match s[i] {
            '#' => count += 1,
            '.' => count -= 1,
            _ => {}
        }
        ans = std::cmp::min(ans, count);
    }
    println!("{}", ans);
}


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

int abs(int k){
  if(k>=0){
    return k;
  }
  else{
    return -k;
  }
}

int main() {
int x,N,ans,abst;
bool exit;
  cin >> x >> N;
if(N==0){
cout << x << endl;
}
else{
vector<int> p(N); 
  for(int i=0; i<N; i++){
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  ans = 0;
  abst = x;
  
  for(int i=0; i <= p.at(N-1)+1; i++){
    exit= false;
    for (int j=0; j < N; j++){
      if (p.at(j) == i){
        exit = true;
        break;
      }
    }
    if (exit == false && abs(x-i) < abst){
         ans = i;
         abst = abs(x-i);
    }
  }
  cout << ans << endl;
}
}

Measured memory_bytes: 3568
#include <stdio.h>

int main(void){
  int a, b;
  scanf("%d %d", &a, &b);
  if(a+b == 15){
    printf("+\n");
  }else if(a*b == 15){
    printf("*\n");
  }else{
    printf("x\n");
  }
  return 0;
}


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

int main() {
    int x,a,b;
    cin>>x>>a>>b;
    if (a>=b) cout<<"delicious"<<endl;
    else if((b-a)<=x) cout<<"safe"<<endl;
    else cout<<"dangerous"<<endl;
}


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

using namespace std;

const int maxn=1e6;
int n;
int a[maxn];
int cnt=0;
int vis[8];

int main()
{
    scanf("%d",&n);
    int l=1e9,r=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]>=1&&a[i]<=399)
            vis[0]=true;
        if(a[i]>=400&&a[i]<=799)
            vis[1]=true;
        if(a[i]>=800&&a[i]<=1199)
            vis[2]=true;
        if(a[i]>=1200&&a[i]<=1599)
            vis[3]=true;
        if(a[i]>=1600&&a[i]<=1999)
            vis[4]=true;
        if(a[i]>=2000&&a[i]<=2399)
            vis[5]=true;
        if(a[i]>=2400&&a[i]<=2799)
            vis[6]=true;
        if(a[i]>=2800&&a[i]<=3199)
            vis[7]=true;
        if(a[i]>=3200)
            cnt++;
    }
    int ans=0;
    bool flag=true;
    for(int i=0;i<8;i++)
       {
           if(vis[i])
            {
                ans++;
                flag=false;
            }
       }
    if(flag)
    {
        printf("1 %d",cnt);
    }
    else
    printf("%d %d",ans,ans+cnt);
    return 0;
}


Measured memory_bytes: 256
from collections import deque


H, W = map(int, input().split())
Ch, Cw = map(lambda x: int(x) - 1, input().split())
Dh, Dw = map(lambda x: int(x) - 1, input().split())
maze = [input() for _ in range(H)]

INF = 10 ** 12
path = [[INF] * W for _ in range(H)]  # path: 各マスへの移動コスト

# walk:移動A, warp:移動B
walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

q = deque()
path[Ch][Cw] = 0
q.append((Ch, Cw, 0))

while q:
    x, y, s = q.popleft()
    for dx, dy in walk:  # 移動A
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s:
            path[nx][ny] = s
            q.appendleft((nx, ny, s))  # 移動Aの場合はコスト0. キューの先頭に追加する.
    for dx, dy in warp:  # 移動B
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s + 1:
            path[nx][ny] = s + 1
            q.append((nx, ny, s + 1))  # 移動Bの場合はコスト1. キューの最後尾に追加する.
    
ans = path[Dh][Dw] if path[Dh][Dw] < INF else '-1'
print(ans)

Measured memory_bytes: 94192
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long quickpow(long long b, int e)
{
	return e ? ((e & 1 ? b : 1)*quickpow(((b%MOD)*(b%MOD)) % MOD, e >> 1)) % MOD : 1;
}

int n, m;
long long ans;
long long fac[500009];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	fac[0] = 1;
	for (int i = 1; i <= 500000; i++) {
		fac[i] = i * fac[i - 1];
		fac[i] %= MOD;
	}
	cin >> n >> m;
	int sign = 1;
	for (int i = 0; i <= n; i++) {
		long long C = fac[n] * quickpow(fac[n - i], MOD - 2);
		C %= MOD;
		C *= quickpow(fac[i], MOD - 2);
		C %= MOD;
		long long A = fac[m] * quickpow(fac[m - i], MOD - 2);
		A %= MOD;
		long long res = fac[m - i] * quickpow(fac[m - n], MOD - 2);
		res %= MOD;
		res *= res;
		res %= MOD;
		long long tmp = C * A;
		tmp %= MOD;
		tmp *= res;
		tmp %= MOD;
		if (sign > 0) {
			ans += tmp;
			ans %= MOD;
		}
		else {
			ans -= tmp;
			if (ans < 0) ans += MOD;
		}
		sign = -sign;
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 7564
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
using namespace std;

#define NUM 10

//string -> int
inline int toInt(string s){
  int v;
  istringstream iss(s);
  iss >> v;
  return v;
}

// ~~~ -> string
template<class T>
inline string toString(T x){
  ostringstream oss;
  oss << x;
  return oss.str();
}


int main(){
  int n;
  int t[10010] = {};
  
  cin >> n;
  int a;
  for(int i = 0 ; i < n ; i++){
    scanf("%d", &a);
    t[a]++;
  }
  
  vector<int> v;
  for(int i = 1 ; i <= 10000 ; i++){
    if(t[i] > 0){
      v.push_back(i);
      t[i]--;
      if(v.size() == NUM) break;
    }
    if(v.size() == NUM) break;
  }
  
  vector<int> vv;
  for(int i = 0 ; i < v.size() ; i++){
    for(int j = 0 ; j < v.size() ; j++){
      if(i == j) continue;
      string s, s1, s2;
      s1 = toString(v[i]);
      s2 = toString(v[j]);
      s = s1+s2;
      int p = toInt(s);
      vv.push_back(p);
    }
  }
  
  sort(vv.begin(), vv.end());
  
  cout << vv[2] << endl;
  return 0;
}



  
    

Measured memory_bytes: 1336
import std.stdio;
import std.conv;
import std.array;
import std.math;
import std.string;

int N;
string S;
int mem[100][1001];

void main()
{
  N = to!int(chomp(readln()));
  S = readln();
  writeln(dp(0b00000100, 0));
}

int dp(int n, int m)
{
  if(m == N)
    return 1;
  if(mem[n][m])
    return mem[n][m];
  int ans = 0;
  for(auto i = 0; i < 0b00001000; i++)
  {
    switch(S[m])
    {
      case 'J':
        if((i & 0b00000100) == 0)
          continue;
        break;
      case 'O':
        if((i & 0b00000010) == 0)
          continue;
        break;
      case 'I':
        if((i & 0b00000001) == 0)
          continue;
        break;
      default:
    }
    if((i & n) == 0)
      continue;
    ans += dp(i, m + 1);
  }
  return mem[n][m] = ans % 10007;
}

Measured memory_bytes: 1560
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	mp := make(map[int]int, n)
	for i := 1; i <= m; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		mp[a-1]++
		mp[b-1]++
	}

	for i := 0; i < n; i++ {
		fmt.Println(mp[i])
	}
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
long long INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
    int n;
    long long ans=1;
    scanf("%d",&n);
    map<int,int> res;

    for(int k=2;k<=n;++k){
        int nk=k;
        FOR(i,2,i*i){
            while(nk%i==0){
                ++res[i];
                nk/=i;
            }
        }
        if(nk!=1) res[nk] = 1;
    }

    for(auto itr=res.begin();itr!=res.end();++itr){
        ans = ans * (itr->second+1) % MOD;
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int q;
	cin>>s;
	cin>>q;
	bool d=false;
	string pr="",sf="";
	while(q--)
	{
		int t;
		cin>>t;
		if(t==1) {d=!d; continue;}
		int f; char c;
		cin>>f>>c;
		if((d && f==1) || (!d && f==2)) sf+=c;
		else pr+=c;
	}
	if(!d) 
	{
		reverse(pr.begin(),pr.end());
		cout<<pr<<s<<sf;
	}
	else
	{
		reverse(sf.begin(),sf.end());
		reverse(s.begin(),s.end());
		cout<<sf<<s<<pr;
	}
}

Measured memory_bytes: 1088
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int m = scanner.nextInt();

        final Map<Integer, List<Integer>> graph = new HashMap<>();
        for (int i = 0; i < m; i++) {
            final int a = scanner.nextInt();
            final int b = scanner.nextInt();

            graph.computeIfAbsent(a, v -> new ArrayList<>()).add(b);
            graph.computeIfAbsent(b, v -> new ArrayList<>()).add(a);
        }

        final boolean[] isVisited = new boolean[n + 1];
        final int answer = dfs(graph, 1, isVisited);
        System.out.println(answer);
    }

    private static int dfs(final Map<Integer, List<Integer>> graph, final int current, final boolean[] isVisited) {
        isVisited[current] = true;
        if (isVisitedAll(isVisited)) {
            return 1;
        }
        int sum = 0;
        for (final int next : graph.get(current)) {
            if (!isVisited[next]) {
                sum += dfs(graph, next, Arrays.copyOf(isVisited, isVisited.length));
            }
        }

        return sum;
    }

    private static boolean isVisitedAll(final boolean[] isVisited) {
        return IntStream.range(1, isVisited.length)
                .mapToObj(i -> isVisited[i])
                .allMatch(Boolean::booleanValue);
    }
}


Measured memory_bytes: 30932
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def local_input():# {{{
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)
# }}}

def solve():
    n,d = map(int,input().split())

    if n % (2*d+1) == 0:
        print( (n // (2*d+1)))
    else:
        print(n//(2*d+1) +1)
    return 0

if __name__ == "__main__":# {{{
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

# vim: set foldmethod=marker:}}}


Measured memory_bytes: 104940
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int MAXN = 205;
const int mod = 998244353;

int n, pwr[MAXN];
pi a[MAXN];

int ccw(pi a, pi b, pi c){
	int dx1 = b.first - a.first;
	int dy1 = b.second - a.second;
	int dx2 = c.first - a.first;
	int dy2 = c.second - a.second;
	return dx1 * dy2 - dy1 * dx2;
}

int main(){
	int n; cin >> n;
	pwr[0] = 1;
	for(int i=0; i<n; i++){
		pwr[i+1] = pwr[i] * 2 % mod;
		cin >> a[i].first >> a[i].second;
	}
	sort(a, a + n);
	lint ret = 1;
	for(int i=0; i<n; i++){
		sort(a + i + 1, a + n, [&](const pi &p, const pi &q){
			return ccw(a[i], p, q) > 0;
		});
		ret += 1;
		for(int j=i+1; j<n; ){
			int e = j;
			while(e < n && ccw(a[i], a[j], a[e]) == 0) e++;
		//	printf("%d %d\n", j, e);
			ret += pwr[e - j] - 1;
			j = e;
		}
		sort(a + i + 1, a + n);
	}
	ret %= mod;
	ret = mod - ret + pwr[n];
	ret %= mod;
	cout << ret << endl;
}


Measured memory_bytes: 256