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

#define INF (1<<29)

int cost[102][102];
char g[102][102];

int d[102][102][1<<5];

int main(){
	int h,w;
	int sy,sx;
	int cnt=0;
	cin>>w>>h;
	for(int i=0;i<=h+1;i++)
		for(int j=0;j<=w+1;j++)
			cost[i][j]=1,g[i][j]='#';
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>g[i][j];
			if(g[i][j]=='#'){
				for(int dy=-2;dy<=2;dy++){
					for(int dx=-2;dx<=2;dx++){
						if(!dy&&!dx)continue;
						if(i+dy<1||h<i+dy||j+dx<1||w<j+dx)continue;
						cost[i+dy][j+dx]=max(cost[i+dy][j+dx],4-max(abs(dy),abs(dx)));
					}
				}
			}else if(g[i][j]=='S'){
				sy=i;
				sx=j;
			}else if(g[i][j]=='M'){
				g[i][j]='0'+cnt++;
			}
		}
	}
	int dy[]={1,0,-1,0};
	int dx[]={0,1,0,-1};
	int ans=-1,qidx=0;
	queue<pair<pair<int,int>,int> > q[4];
	q[0].push(make_pair(make_pair(sy,sx),0));
	fill((int*)d,(int*)(d+102),INF);
	d[sy][sx][0]=0;
	while(1){
		while(q[qidx].empty())qidx=(qidx+1)&3;
		pair<pair<int,int>,int> a,b;
		a=q[qidx].front();
		q[qidx].pop();
		if(g[a.first.first][a.first.second]=='G'&&(1<<cnt)-1==a.second){
			ans=d[a.first.first][a.first.second][a.second];
			break;
		}
		for(int i=0;i<4;i++){
			b=a;
			b.first.first+=dy[i];
			b.first.second+=dx[i];
			int y=b.first.first;
			int x=b.first.second;
			if(g[y][x]=='#')continue;
			if('0'<=g[y][x]&&g[y][x]<'5')b.second|=1<<g[y][x]-'0';
			int c=cost[a.first.first][a.first.second];
			if(d[a.first.first][a.first.second][a.second]+c<d[y][x][b.second]){
				d[y][x][b.second]=d[a.first.first][a.first.second][a.second]+c;
				q[(qidx+c)&3].push(b);
			}
		}
	}
	cout<<ans<<endl;	
	return 0;
}

Measured memory_bytes: 2620
use std::iter::once;

fn solve(n: usize, s: String) -> i32 {
    let v = once(0)
        .chain(
            s.chars()
                .scan(0, |s, c| {
                    *s = *s + if c == 'E' { 1 }  else { 0 };
                    Some(*s)
                }
            )
        )
        .collect::<Vec<usize>>();
    (0..(n+1))
        .map(|i| i - v[i] + v[n] - v[i])
        .min()
        .map(|i| i as i32)
        .unwrap()
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let n = s.trim().parse().ok().unwrap();
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s = s.trim().to_string();
    let res = solve(n, s);
    println!("{}", res);
}


Measured memory_bytes: 10568
#include <stdio.h>
#include <string.h>
int main(){
    int n, AC = 0, WA = 0, TLE = 0, RE = 0;
    char a[5];
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        scanf("%s", a);
        if (strcmp(a, "AC") == 0){
            AC = AC + 1;
        }else if (strcmp(a, "WA") == 0){
            WA = WA + 1;
        }else if (strcmp(a, "TLE") == 0){
            TLE = TLE + 1;
        }else{
            RE = RE + 1;
        }
    }
    printf("AC x %d\n", AC);
    printf("WA x %d\n", WA);
    printf("TLE x %d\n", TLE);
    printf("RE x %d\n", RE);
    return 0;
}

Measured memory_bytes: 1736
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------

signed main() {
	int n, a[1000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	reverse(a, a + n);
	for (int i = 0; i < n; i++) {
		cout << (i ? " " : "") << a[i];
	}
	cout << endl;
}


Measured memory_bytes: 3112
package main

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

func main() {
	n, m := getInt(), getInt()
	xs := make([]int, m)
	for i := range xs {
		xs[i] = getInt()
	}
	sort.Ints(xs)

	ds := make([]int, m-1)
	for i := 0; i < m-1; i++ {
		ds[i] = abs(xs[i] - xs[i+1])
	}
	sort.Ints(ds)

	ans := 0
	for i := 0; i < m-n; i++ {
		ans += ds[i]
	}

	fmt.Println(ans)
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 2944
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double PI = (double)acos(-1);
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int K, A, B;

signed main() {
  cin >> K >> A >> B;

  if ((B - A) / 2 <= 1 || K + 1 <= A) {
    cout << K + 1 << endl;
    return 0;
  }

  cout << A + (B - A) * ((K + 1 - A) / 2) + ((K + 1 - A) % 2 == 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();

    let a: usize = iter.next().unwrap().parse().unwrap();

    let mut ds = Vec::with_capacity(a);

    for _ in 0..a {
        let d: usize = iter.next().unwrap().parse().unwrap();
        ds.push(d);
    }

    let mut max = 0;
    for i in 0..a {
        if i * 10 > max {
            println!("{}", "no");
            return;
        } else {
            max = std::cmp::max(max, i * 10 + ds[i]);
        }
    }

    let mut min: isize = (a - 1) as isize * 10;

    for i in (0..a).rev() {
        if i as isize * 10 < min {
            println!("{}", "no");
            return;
        } else {
            min = std::cmp::min(min, i as isize * 10 - ds[i] as isize);
        }
    }

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



Measured memory_bytes: 14204
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n;
char s[1010101];
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	int ans=0;
	for(int i=1;i<=n-2;i++)
	if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
	printf("%d\n",ans);
	return 0;
}


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

#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef pair<ll,ll> pll;

const int N = 10+2;
int n, m, x;
char ar[N][N];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m >> x;
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> ar[i][j];
        }
    }
    int a = (1<<n);
    int b = (1<<m);
    int ans = 0;
    for (int i = 0; i < a; i++)
    {
        for (int j = 0; j < b; j++)
        {
            int cnt = 0;
            for (int k = 0; k < n; k++)
            {
                for (int l = 0; l < m; l++)
                {
                    if ((i&(1<<k)) || (j&(1<<l)))
                        continue;
                    cnt += (ar[k][l] == '#');
                }
            }
            // cout << i << ' ' << j << " -> " << cnt << '\n';
            if (cnt == x)
                ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  long long ans = 0;
  if (n % 2 == 0) {
    for (int i = 0; i < n / 2; i++) {
      ans += 2 * (a[n / 2] - a[i]);
      ans += 2 * (a[n - 1 - i] - a[n / 2]);
    }
    ans -= a[n / 2] - a[n / 2 - 1];
  } else {
    int mn = 1e9;
    for (int i = 0; i < (n - 1) / 2; i++) {
      mn = min(mn, a[(n - 1) / 2] - a[i]);
      mn = min(mn, a[n - 1 - i] - a[(n - 1) / 2]);
      ans += 2 * (a[(n - 1) / 2] - a[i]);
      ans += 2 * (a[n - 1 - i] - a[(n - 1) / 2]);
    }
    ans -= mn;
  }
  cout << ans << endl;
}



Measured memory_bytes: 640
// In The Name of Almighty Allah
#include<bits/stdc++.h>
using namespace std;
#define             fastio              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define             ff                  first
#define             ss                  second
#define             int                 long long
#define             pb                  push_back
#define             pf                  push_front
#define             pii                 pair<int,int>
#define             print(x)            for(auto it : x) cout<<it<<' '; cout<<'\n';
#define             debug(x)            cout << #x << " --->> " << x << endl;
#define             mod                 1000000007
#define             inf                 1e18
#define             PI                  (acos(-1))
#define             eps                 (1e-8)
#define             clear(x)            memset(x,0,sizeof(x));


main()
{
	fastio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int a, b, c, k, x, y, z, p, q, r, n, m;
	cin >> k;
	int g, ans = 0;
	for (int i = 1; i <= k; i++)
	{
		for (int j = 1; j <= k; j++)
		{
			for (int j1 = 1; j1 <= k; j1++)
			{
				g = __gcd(i, j);
				g = __gcd(g, j1);
				ans += g;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
vector<int> g[100001];
int ans[100001];
int dfs(int i)
{
  if(ans[i]>=0)
  {
    return ans[i];
  }
  int a=0;
  for (auto j:g[i])
  {
    a= max(dfs(j)+1,a);
  }
  ans[i]= a;
  return a;
}
int main()
{
  int n,m,i,j,k,out=0;
  cin>>n>>m;
  for(i=0;i<m;i++)
  {
    int x,y;
    cin>>x>>y;
    g[x].push_back(y);
  }
  for(i=0;i<=n;i++)
  {
    ans[i]=-1;
  }
  for(i=0;i<=n;i++)
  {
    if(ans[i]>=0)
    {
      continue;
    }
    ans[i]=dfs(i);
    out=max(ans[i],out);
  }
  cout<<out;
  return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = b*(n-1) + a -(a*(n-1) + b) + 1;
    if(ans < 0) ans = 0;

    cout << ans << "\n";
}

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

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

int main() {
	long long ans,mn=(long long)1e18;
	int n,s=0;
	cin>>n;
	int a[n+5];
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int i=-100;i<=100;i++)
	{
	 ans=0;
	 for(int j=0;j<n;j++)
	 ans+=(a[j]-i)*(a[j]-i);
	 mn=min(mn,ans);
	}
	cout<<mn<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int main()
{
 int a,b;
 scanf("%d%d",&a,&b);
 if(a<=0&&b>=0)puts("Zero");
 else if(b<0)
 {
  if((a-b+1)%2)puts("Negative");
  else puts("Positive");
 }
 else puts("Positive");
 return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split(" "))

count = [0 for i in range(K)]

for i in range(N):
    tmp = list(map(int, input().split(" ")))
    for j in range(tmp[0]):
        count[tmp[1+j]-1] += 1

ans = 0
for i in range(K):
    if count[i] == N:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>

#define N 100000

int main(void) {
    char OorX[N];
    int i;
    int n;
    int count = 0;
    int answer = 0;

    scanf("%d", &n);
    scanf("%s", OorX);

    for (i = 0; i < n; i++) {
        if (OorX[i] == 'x')
            count++;
        if (count >= 2)
            break;
        if (OorX[i] == 'o')
            count = 0;

        answer++;
    }
    printf("%d\n", answer);

    return 0;
}

Measured memory_bytes: 1932
#include <iostream>
#include <complex>
#include <vector>
#include <cstdio>
using namespace std;
typedef complex<int> P;

int cross(const P& a, const P& b){
    return imag(conj(a)*b);
}

int main(){
    int n;
    while(cin >> n, n){
        vector<vector<int> > oresen(n+1);
        vector<int> r_motosen;
        for(int i=0;i<=n;i++){
            int m;
            cin >> m;
            vector<P> input(m);
            for(int j=0;j<m;j++){
                int x,y;
                scanf("%d%d",&x,&y);
                input[j] = P(x,y);
            }
            for(int j=0;j+1<m;j++){
                P v = input[j+1] - input[j];
                oresen[i].push_back(abs(real(v)) + abs(imag(v)));
                if(j+2<m){
                    P v2 = input[j+2] - input[j+1];
                    if(cross(v, v2)>0) oresen[i].push_back(1);
                    else oresen[i].push_back(0);
                }
            }
            if(i==0){
                for(int j=m-1;j-1>=0;j--){
                    P v = input[j-1] - input[j];
                    r_motosen.push_back(abs(real(v)) + abs(imag(v)));
                    if(j-2>=0){
                        P v2 = input[j-2] - input[j-1];
                        if(cross(v, v2)>0) r_motosen.push_back(1);
                        else r_motosen.push_back(0);
                    }
                }
            }
        }
        /*
        for(int i=0;i<oresen[0].size();i++){
            cout<<oresen[0][i]<<" ";
        }
        cout<<endl;
        for(int i=0;i<r_motosen.size();i++){
            cout<<r_motosen[i]<<" ";
        }
        cout<<endl;
        */
        for(int i=1;i<=n;i++){
            if(oresen[i]==oresen[0]||oresen[i]==r_motosen){
                cout << i << endl;
            }
        }/*
        for(int i=1;i<=n;i++){
            if(oresen[i].size()!=oresen[0].size())continue;
            bool same = true;
            for(int j=0;j<oresen[0].size();j++){
                if(oresen[0][j]!=oresen[i][j]){
                    same = false;
                    break;
                }
            }
            if(!same){
                same = true;
                for(int j=0;j<r_motosen.size();j++){
                    if(r_motosen[j]!=oresen[i][j]){
                        same = false;
                        break;
                    }
                }
                if(!same) continue;
            }
            cout << i << endl;
        }
        */
        cout << "+++++" << endl;
        //break;
    }

    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXN 50

int main(int argc,char const* argv[])
{
  int n,a,i,j,k,l,xmax=0;
  long long int ans=0;
  cin >> n >> a;
  xmax=a;
  vector <int> x(n,0);
  for(i=0;i<n;i++)
    {
      cin >> x[i];
      if(x[i]>=xmax) xmax=x[i];
    }
  long long int dp[n+1][n+1][n*xmax+1];
  for(j=0;j<=n;j++)
    {
      for(k=0;k<=n;k++)
	{
	  for(l=0;l<=n*xmax;l++)
	    {
	      if(j==0 && k==0 && l==0) dp[j][k][l]=1;
	      else if(j>=1 && l<x[j-1]) dp[j][k][l]=dp[j-1][k][l];
	      else if(j>=1 && k>=1 && l>=x[j-1])
		{
		  dp[j][k][l]=dp[j-1][k][l]+dp[j-1][k-1][l-x[j-1]];
		}
	      else dp[j][k][l]=0;
	    }
	}
    }
  for(k=1;k<=n;k++)
    {
      ans+=dp[n][k][k*a];
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 51072
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000011
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
  int n;
  cin>>n;
  
  int cnt=0;
  
  for(int i=1;i<=n;i++){
    int k=0;
    int va=i;
    while(va>=1){
      va/=10;
      k++;}
    if(k%2==1){
      cnt++;}
  }
  
  cout<<cnt<<endl;
      
    
 
 
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
  int A,B;
  cin>>A>>B;

  int ans=0;
  int S;

  for(int i=A;i<=B;++i){
    string K=to_string(i); 
    S=K.size();
    for(int j=0;j<S/2;++j){
      if(K[j]!=K[S-j-1]){goto xyz;}
    }
    ++ans;
  xyz:;
  }

cout<<ans<<endl;

}

Measured memory_bytes: 256
N, M = map(int, input().split())
K = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))

ans = 0
# pow(2,N)のbit全探索
for num in range(1 << N):
    # 全ての電灯を確認
    # print(num)
    flag = True
    for m in range(M):
        count_m = 0
        for j in K[m][1:]:
            if num & (1 << (j - 1)):
                count_m += 1
        # print(m, count_m, K[m], P[m])
        if count_m % 2 != P[m]:
            flag = False
            break
    # print(num, flag)
    if flag:
        ans += 1

print(ans)

Measured memory_bytes: 70428
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;

void main() {
	auto N = to!int(readln.chomp);
	foreach (i; 0..N) {
		auto input = readln.split.map!(to!int);
		if (input[2] >= 5 && input[3] >= 2) {
			writeln((input[0] * input[2] + input[1] * input[3]) * 4 / 5);
		} else if (input[2] >= 5) {
			int a = input[0] * input[2] + input[1] * input[3];
			int b = (input[0] * input[2] + input[1] * 2) * 4 / 5;
			writeln(min(a, b));
		} else if (input[3] >= 2) {
			int a = input[0] * input[2] + input[1] * input[3];
			int b = (input[0] * 5 + input[1] * input[3]) * 4 / 5;
			writeln(min(a, b));
		} else {
			int a = input[0] * input[2] + input[1] * input[3];
			int b = (input[0] * 5 + input[1] * 2) * 4 / 5;
			writeln(min(a, b));
		}
	}
}

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

int main()
{
  int N,K,d,w,count=0;
  int sum[101]{0};
  cin>>N>>K;
  for(int i=0;i<K;i++){
    cin>>d;
    for(int j=0;j<d;j++){
      int w;
      cin>>w;
      sum[w-1]=1;
    }
  }
  for(int i=0;i<N;i++){
    if(sum[i]==0)count++;
  }
  cout<<count;
  return 0;
}

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

li floor(li a, li b) {
    return (a - a%b) / b;
}

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

    li a, b, n, x; cin >> a >> b >> n;

    if (n>=b-1) x = b-1;
    else x = n;

    cout << floor((a*x), b) - a * floor(x/b) << "\n";

    return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define int long long
using namespace std;

int m[100010];
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, L;
    cin >> N >> L;
    int mx = 0, pos = 0;
    for (int i = 0; i < N ; i++ ){
        cin >> m[i];
        if (i && mx < m[i - 1] + m[i]) {
            mx = m[i - 1] + m[i];
            pos = i;
        }
    }
    if (mx < L) {
        cout << "Impossible\n";
        return 0;
    }
    cout << "Possible\n";
    for (int i = 1; i < pos; i++) 
        cout << i << '\n';
    for (int i = N - 1; i >= pos; i --) 
        cout << i << '\n';
    return 0;

}


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

typedef long long ll;

ll arr[200000];
ll newArr[200000];

struct compare
{
	bool operator()(int const& a, int const& b)
	{
		return newArr[a] < newArr[b];
	}
};

priority_queue<int, vector<int>, compare> pq;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> newArr[i];
	}
	for (int i = 0; i < n; i++)
	{
		pq.push(i);
	}
	int elementsLeft = n;
	ll result = 0;
	while (elementsLeft > 0)
	{
		int u = pq.top();
		pq.pop();
		if (newArr[u] == arr[u])
		{
			elementsLeft--;
			continue;
		}
		if (newArr[u] < arr[u])
		{
			cout << -1 << endl;
			return 0;
		}
		ll sum = newArr[(u + 1) % n] + newArr[(u + n - 1) % n];
		newArr[u] -= arr[u];
		ll quotient = newArr[u] / sum;
		if (quotient <= 0) {cout << -1 << endl; return 0;}
		newArr[u] %= sum;
		newArr[u] += arr[u];
		pq.push(u);
		result += quotient;
	}
	cout << result << endl;
	return 0;
}

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

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

const int MAXN = 200000;
const int MAXSUMLEN = 1000000;
const int MAXNODE = MAXSUMLEN + 1;
struct Node { int nxt[26], subtreecntwith[26], subtreecnt; int cnt; };

int n;
char s[MAXSUMLEN + 1];
int offset[MAXN + 1], len[MAXN];

Node node[MAXNODE]; int nnode, root;

int makenode() { int ret = nnode++; REP(i, 26) node[ret].nxt[i] = -1, node[ret].subtreecntwith[i] = 0; node[ret].cnt = node[ret].subtreecnt = 0; return ret; }

ll dfs(int at) {
	ll ret = 0;
	node[at].subtreecnt = node[at].cnt;
	REP(x, 26) {
		int to = node[at].nxt[x]; if (to == -1) continue;
		ret += dfs(to);
		node[at].subtreecnt += node[to].subtreecnt;
		REP(y, 26) node[at].subtreecntwith[y] += y == x ? node[to].subtreecnt : node[to].subtreecntwith[y];
	}
	if (node[at].cnt > 0) {
		ret += (ll)node[at].cnt * (node[at].subtreecnt - node[at].cnt);
	}
	REP(x, 26) {
		int to = node[at].nxt[x]; if (to == -1) continue;
		if (node[to].cnt == 0) continue;
		ret += (ll)node[to].cnt * (node[at].subtreecntwith[x] - node[to].subtreecnt);
	}
	return ret;
}

ll solve() {
	nnode = 0;
	root = makenode();
	REP(i, n) {
		int at = root;
		for (int j = len[i] - 1; j >= 0; --j) {
			char c = s[offset[i] + j];
			int x = c - 'a';
			if (node[at].nxt[x] == -1) { int to = makenode(); node[at].nxt[x] = to; }
			at = node[at].nxt[x];
		}
		++node[at].cnt;
	}
	return dfs(root);
}

void run() {
	scanf("%d", &n);
	offset[0] = 0;
	REP(i, n) {
		scanf("%s", s + offset[i]);
		len[i] = strlen(s + offset[i]);
		offset[i + 1] = offset[i] + len[i];
	}
	printf("%lld\n", solve());
}

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


Measured memory_bytes: 288924
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <random>
#include <deque>
#include <bitset>
#include <string>
#include <queue>
#include <complex>
 
//#define int long long
 
#define mp(a, b) make_pair(a, b)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
 
#define endl '\n'
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
mt19937 mrand(random_device{}());
 
double PI = acos((double)-1);
const ld eps = 1e-7;
const ll inf0 = 1023 * 1024 * 1024;
const ll inf = inf0 * inf0;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
	
void solve();
void scan();
 
signed main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
	cout << fixed; cout.precision(15);
	solve();
	return 0;
}

void solve() {
	int n; cin >> n;
	vector<int> a(n);
	map<int, int> kek;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		kek[a[i]] += 1;
	}
	ll su = 0;
	for (auto u : kek) {
		su += (u.second) * 1ll * (u.second - 1) / 2;
	}
	for (int i = 0; i < n; i++) {
		ll ans = su - kek[a[i]] + 1;
		cout << ans << endl;
	}
    return;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >>n;
    string s,t;
    cin >>s>>t;
    string ans;
    
    for(int i=0;i<n;i++){
        ans += s.at(i);
        ans += t.at(i);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<cmath>
bool isprime(int n) {
	if (n == 2)return true;
	if (n % 2 == 0)return false;
	for (int i = 3; i <= sqrt(n); i += 2) if (n%i == 0)return false;
	return true;
}
int main() {
	int n; while (cin >> n, n) {
		int cnt = 0;
		for (int i = 2; i <= n / 2; i++) {
			if (isprime(i) && isprime(n - i))cnt++;
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 3008
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    int N, M;
    cin >> N >> M;
    vector<int> vec(2*M), count(60, 0);
    REP(i, 2*M) cin >> vec[i];
    
    // calculation
    REP(i, 2*M) {
        count[vec[i]]++;
    }
    
    REPN(i, N) {
        cout << count[i] << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N = II()
    import math
    X = math.ceil(N / 1.08)
    if int(X*1.08) == N:
        print(X)
    else:
        print(':(')



if __name__ == '__main__':
    main()

Measured memory_bytes: 38620
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
int main(){
	ll a,b,c,k;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
	if(k&1)printf("%lld\n",b-a);
	else printf("%lld\n",a-b);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, i;
    cin >> n >> i;
    out(n - i + 1);
    re0;
}

Measured memory_bytes: 256
n, m, x = map(int, input().split())
cost = []
l = []
for i in range(n):
    tmp = list(map(int, input().split()))
    cost.append(tmp[0])
    l.append(tmp[1: ])

mx = 9999999999999
for i in range(2 ** n):
    ans = [0] * m
    price = 0
    s = bin(i)[2: ]
    s = '0' * (n - len(s)) + s
    # print(s, ans)
    for j in range(len(s)):
        if s[j] == '1':
            for k in range(m):
                ans[k] += l[j][k]
            price += cost[j]
    # print(s, ans)
    # print()
    ch = 1
    for j in range(m):
        if ans[j] < x:
            ch = 0
            break
    if ch:
        mx = min(mx, price)
if mx == 9999999999999: print(-1)
else: print(mx)

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

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

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

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

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

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

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

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

fn main() {
    input!(
        S : String,
    );

//    let S: String = "".to_string();
    let s = S.chars().collect::<Vec<_>>();
    let mut ans_op = 0;

    for i in 0..1 << s.len() {
        let mut ans = 0;
        ans = s[0] as i32 - 48;
        for j in 0..3 {
            let a1 = s[j + 1] as i32 - 48;
            if i >> j & 1 == 1 {
                ans += a1;
            } else {
                ans -= a1;
            }
        }
        if ans == 7 {
            ans_op = i;
            break;
        }
    }
    // answer
    print!("{}", s[0]);
    for i in 0..3 {
        let a1 = s[i + 1] as i32 - 48;
        print!("{}{}",
               if ans_op >> i & 1 == 1 {
                   "+"
               } else {
                   "-"
               },
               a1);
    }
    println!("=7");
}

Measured memory_bytes: 4352
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
ll dp[1000100][2];


int main(){
    string s;
    cin>>s;
    s='0'+s;
    int n=s.length();

    for(int i=0;i<n+3;i++){
        dp[i][0]=INF;
        dp[i][1]=INF;
    }

    dp[n-1][0]=s[n-1]-'0';
    dp[n-1][1]=10-(s[n-1]-'0');

    for(int i=n-1;i>0;i--){
        int now=s[i-1]-'0';

        /// keta=0
        for(int a=0;a<10;a++){
            int b=a-now;
            if(b<0){
                b+=10;
                dp[i-1][1]=min(dp[i-1][1],dp[i][0]+a+b);
            }else{
                dp[i-1][0]=min(dp[i-1][0],dp[i][0]+a+b);
            }
        }
        /// keta=1
        for(int a=-1;a<9;a++){
            int b=a-now;
            if(b<0){
                b+=10;
                dp[i-1][1]=min(dp[i-1][1],dp[i][1]+a+b+1);
            }else{
                dp[i-1][0]=min(dp[i-1][0],dp[i][1]+a+b+1);
            }
        }

    }

    cout<<dp[0][0]<<endl;
    
}

Measured memory_bytes: 20064
n = int(input())

if n == 1 or n == 2 or n == 3:
    ans = 0
else:
    prime = [2,3]
    fac = [0] * (n+1)
    fac[2] = 1
    fac[3] = 1
    for i in range(4,n+1):
        ii = i
        for j in range(2,i+1):
            det = 0
            if j in prime:
                if ii % j == 0:
                    det = 1
                while ii % j == 0:
                    fac[j] += 1
                    ii = ii // j
            if det == 0:
                prime.append(ii)
    
    #print(fac)
    c = [0] * 5
    for k in range(2,n+1):
        if fac[k] >= 74:
            c[4] += 1
        if fac[k] >= 24:
            c[3] += 1
        if fac[k] >= 14:
            c[2] += 1
        if fac[k] >= 4:
            c[1] += 1
        if fac[k] >= 2:
            c[0] += 1
    #print(c)
    pos = [0] * 4
    pos[0] = (c[1]*(c[1]-1)*(c[0]-2))//2
    pos[1] = c[4]
    pos[2] = c[2]*(c[1]-1)
    pos[3] = c[3]*(c[0]-1)
    ans = sum(pos)

print(ans)
    
        



Measured memory_bytes: 38768
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	const long MOD = 1000000007;
	static int[] G => ReadLine().Split().Select(int.Parse).ToArray();
	int N;
	long ans, D;
	long[] ds, dt, cs, ct;
	bool[] done;
	List<E>[] g;
	public K()
	{
		var I = G; N = I[0]; var M = I[1];
		I = G; int s = I[0] - 1, t = I[1] - 1;
		g = new List<E>[N];
		for (var i = 0; i < N; i++) g[i] = new List<E>();
		for (var i = 0; i < M; i++)
		{
			I = G; int a = I[0] - 1, b = I[1] - 1, c = I[2];
			g[a].Add(new E(b, c));
			g[b].Add(new E(a, c));
		}
		DijkstraFrom(s, ref ds, ref cs);
		DijkstraFrom(t, ref dt, ref ct);
		ans = S(cs[t]);
		D = ds[t];
		done = new bool[N];
		DFS(t);
		WriteLine((ans %= MOD) < 0 ? ans + MOD : ans);
	}
	long S(long x) => x * x % MOD;
	void DFS(int u)
	{
		if (done[u]) return;
		done[u] = true;
		if (2 * ds[u] == D) ans -= S(cs[u] * ct[u] % MOD);
		foreach (var e in g[u]) if (ds[e.V] + e.D == ds[u])
			{
				if (2 * ds[u] > D && 2 * ds[e.V] < D) ans -= S(ct[u] * cs[e.V] % MOD);
				DFS(e.V);
			}
	}
	void DijkstraFrom(int u, ref long[] d, ref long[] c)
	{
		d = new long[N]; c = new long[N];
		for (var v = 0; v < N; v++) d[v] = 4011686018427387913L;
		var queue = new PriorityQueue();
		d[u] = 0; c[u] = 1;
		queue.Enqueue(new E(u, 0));
		while (queue.Count > 0)
		{
			var p = queue.Dequeue();
			var v = p.V;
			if (d[v] < p.D) continue;
			foreach (var e in g[v])
			{
				var t = d[v] + e.D;
				if (d[e.V] > t) { queue.Enqueue(new E(e.V, d[e.V] = t)); c[e.V] = c[v]; }
				else if (d[e.V] == t) c[e.V] = (c[e.V] + c[v]) % MOD;
			}
		}
	}
}
struct E
{
	public readonly int V;
	public readonly long D;
	public E(int v, long d) { V = v; D = d; }
	public int CompareTo(E e) => D.CompareTo(e.D);
}
class PriorityQueue
{
	readonly List<E> a = new List<E>();
	public int Count { get; private set; } = 0;
	public void Enqueue(E x)
	{
		var i = Count++;
		a.Add(x);
		while (i > 0)
		{
			var p = (i - 1) / 2;
			if (a[p].CompareTo(x) <= 0) break;
			a[i] = a[p];
			i = p;
		}
		a[i] = x;
	}
	public E Dequeue()
	{
		var v = a[0];
		var x = a[--Count];
		a.RemoveAt(Count);
		if (Count == 0) return v;
		var i = 0;
		while (i * 2 + 1 < Count)
		{
			var l = 2 * i + 1;
			var r = 2 * i + 2;
			if (r < Count && a[r].CompareTo(a[l]) < 0) l = r;
			if (a[l].CompareTo(x) >= 0) break;
			a[i] = a[l];
			i = l;
		}
		a[i] = x;
		return v;
	}
	public E Peek() => a[0];
}


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

using namespace std;
typedef long long ll;

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

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

  for (int i = 1; i < n; i++) {
    a[0][i] += a[0][i - 1];
  }
  for (int i = 0; i < n; i++) {
    if (i == 0) a[1][i] += a[0][i];
    else a[1][i] += max(a[1][i - 1], a[0][i]);
  }
  cout << a[1][n - 1] << endl;

  return 0;
}

Measured memory_bytes: 256
H, W, D = gets.split.map(&:to_i)
As = H.times.map{gets.split.map(&:to_i)}
Q = gets.to_i
LRs = readlines.map{|l| l.split.map(&:to_i)}

as = As.flatten
x, y = [], []
(1 .. H).each do |h|
  (1 .. W).each do |w|
    n = as.shift
    x[n] = h
    y[n] = w
  end
end
N = H * W
k = Array.new(N + 1, 0)
(D+1 .. N).each{|i| k[i] = k[i - D] + (x[i] - x[i - D]).abs + (y[i] - y[i - D]).abs}
LRs.each do |l, r|
  puts k[r] - k[l]
end

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

using namespace std;


int main(){
    ios_base::sync_with_stdio(0);
    int n,a,b;cin>>n>>a>>b;
    if((b-a) & 1) {
        cout<<"Borys"<<endl;
    } else {
        cout<<"Alice"<<endl;
    }
    

    return 0;
}


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


int main()
{
	int n, m, taro[101], hanako[101], sumtaro, sumhanako, min, anstaro, anshanako;
	while (cin >> n >> m, n || m){

		//初期化
		for (int i = 0; i < 101; i++){
			taro[i] = 0;
			hanako[i] = 0;
		}
		sumtaro = 0;
		sumhanako = 0;
		min = 1000;


		//入力
		for (int i = 0; i < n; i++){
			cin >> taro[i];
			sumtaro += taro[i];
		}
		for (int i = 0; i < m; i++){
			cin >> hanako[i];
			sumhanako += hanako[i];
		}


		//交換
		for (int i = 0; i < n; i++){
			for (int j = 0; j < m; j++){
				if (sumtaro - taro[i] + hanako[j] == sumhanako - hanako[j] + taro[i]){
					if (taro[i] + hanako[j] < min){
						min = taro[i] + hanako[j];
						anstaro = taro[i];
						anshanako = hanako[j];
					}
				}
			}
		}

		if (min == 1000)
			cout << -1 << endl;
		else
			cout << anstaro << " " << anshanako << endl;

	}



	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int x,y,z,x1,z1,GO;
    scanf("%d %d %d",&x,&y,&z);
    for(x1=x;x1<=y;x1++){
        z1=z%x1;
        if(z1==0){
            GO++;
        }
    }
    printf("%d\n",GO);
    return 0;
}


Measured memory_bytes: 2108
from collections import defaultdict, deque
s = int(input())
d = defaultdict(int)
d[s] = 1
index = 1
while(1):
  if s % 2 == 0:
    s = s // 2
  else:
    s = 3 * s + 1
  index += 1
  if d[s] == 1:
    break
  d[s] = 1
print(index)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long int ll;
const ll mod=1e9+7;
ll f[2006];
int main()
{
	ios;
	f[0]=1;
	for(int i=3;i<=2000;++i)
		for(int j=3;j<=i;++j)
		{
			f[i]=(f[i]+f[i-j])%mod;
		}
	int s;
	cin>>s;
	cout<<f[s]<<'\n';
}

Measured memory_bytes: 3656
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
int b=scan.nextInt();
if(a*b%2==1) {
	System.out.println("Yes");
	
}
else {
	System.out.println("No");
	
}
	}

}


Measured memory_bytes: 21716
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007

int now,L,R;

int main(){
  int ans=2019*2019;
  cin >> L >> R;
  int RL=(R-L);
  if (RL>2019)RL=RL%2019+2019;
  L%=2019;
  R=L+RL;
  
  for(int j=L+1;j<=R;j++){
      for(int i=L;i<j;i++){
          ans=min(ans,(i*j)%2019);
      }
  }

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

Measured memory_bytes: 256
S = list(input())
N = len(S)
S = [int(s) for s in S]
S = S[::-1]
l = [0] * 2019
index = 0
tmp = 0
z = 1
for i, s in enumerate(S):
    tmp += s * pow(10, i, 2019)
    l[tmp%2019] += 1

ans = l[0]

for v in l:
    ans += v * (v-1) // 2
print(ans)

Measured memory_bytes: 12224
s = input()
x = s.replace('<>', '<|>').split('|')


def func(t):
    c1 = t.count('>')
    c2 = len(t) - c1
    return list(reversed(range(1, c1 + 1))) + list(range(c2 + 1))


a = func(x[0])
for i in range(1, len(x)):
    ai = func(x[i])
    a[-1] = max(a[-1], ai[0])
    a.extend(ai[1:])

# print(a)
ans = sum(a)
print(ans)


Measured memory_bytes: 29912
//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

const int N = 1e5 + 7;
int n, m, d;
char a[N], b[N];

int main() {
	rd(n, m), d = __gcd(n, m);
	rds(a, n), rds(b, m);
	int s = n / d, t = m / d;
	for (int i = 1, j = 1; i <= n; i += s, j += t)
		if (a[i] != b[j]) return print(-1), 0;
	print(1ll * n * m / d);
	return 0;
}

Measured memory_bytes: 3832
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
  	int n;
  cin>>n;
  vector<int> a,b,c;
  for(int i=0;i<n; i++) {
    int temp1,temp2,temp3;
    cin>>temp1>>temp2>>temp3;
    a.push_back(temp1);
    b.push_back(temp2);
    c.push_back(temp3);
  }
   vector<vector<int>> dp(n,vector<int>(3,0));
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
	for(int i=1; i<n; i++) {
      	dp[i][0] = a[i] + max(dp[i-1][1],dp[i-1][2]);
      	dp[i][1] = b[i] + max(dp[i-1][0],dp[i-1][2]);
      	dp[i][2] = c[i] + max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
}


Measured memory_bytes: 9800
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
 
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)
 
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;
  

int main() {
    int N;
    cin >> N;
    int A[200100];
    rep(i,N) cin >> A[i];

    int res = 0;
    int cnt = 1;
    rep(i,N) {
        if (A[i] == cnt) cnt += 1;
        else res += 1;
    }

    if (cnt == 1) res = -1;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024