akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

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

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	//n := r.nextInt()
	r.Scan(true)
	a := r.nextStringArray().toInts()

	ans := "APPROVED"
	for _, v := range a {
		if v%2 == 0 && (v%3 != 0 && v%5 != 0) {
			ans = "DENIED"
			break
		}
	}
	fmt.Fprintln(stdout, ans)
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N, M; cin >> N >> M;
    vector<LP> lpv(N);
    rep(i, N){
        ll a, b; cin >> a >> b;
        lpv[i] = make_pair(a, b);
    }
    sort(all(lpv));
    ll res=0;
    for(auto a: lpv){
        if(M - a.second > 0){
            res += a.first * a.second;
            M -= a.second;
        }else{
            res += a.first * M;
            break;
        }
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  if(!(n & 1))
    cout << 1.0/2 << "\n";
  else
    cout << (double)(n/2+1)/n << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX=1000;
int main()
{
  int n,t,i,j,res;
  bool fb,fe,f[N_MAX];
  int a[N_MAX][N_MAX],p[N_MAX];
  cin >> n;
  for(i=0;i<n;i++)
    for(j=0;j<n-1;j++){
      cin >> a[i][j];
      a[i][j]--;
    }
  fill(p,p+n,0);
  for(res=0;;res++){
    fb=0;
    fe=1;
    fill(f,f+n,0);
    for(i=0;i<n;i++){
      if(f[i]==1||p[i]==n-1)
        continue;
      fe=0;
      t=a[i][p[i]];
      if(f[t]==0&&a[t][p[t]]==i){
        f[i]=1;
        f[t]=1;
        p[i]++;
        p[t]++;
        fb=1;
      }
    }
    if(fe==1){
      cout << res << endl;
      return 0;
    }
    if(fb==0){
      cout << "-1" << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 7516
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){
  int N; ll L; cin >> N >> L;
  
  vector <ll> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }

  ll sum_max = 0;
  int point = 0;
  for (int i = 0; i < N - 1; i++){
    if (sum_max < A[i] + A[i + 1]){
      sum_max = A[i] + A[i + 1];
      point = i + 1;
    }
  }

  if (sum_max < L){
    cout << "Impossible" << endl;
  }else{
    cout << "Possible" << endl;

    vector <int> ans(N - 1);
    
    int cnt = 0;
    while (point <= N - 1){
      ans[cnt] = point;
      point++; cnt++;
    }
    point = ans[0] - 1;
    while (cnt < N - 1){
      ans[cnt] = point;
      point--; cnt++;
    }
    
    for (int i = N - 2; i >= 0; i--){
      cout << ans[i] << endl;
    }
    
    
  }



  return 0;
}


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

typedef pair<int, int> P;
typedef long long ll;
const int MAXN = 1e5 + 50;

priority_queue<P, vector<P>, greater<P> > pque;
vector<int> V[MAXN];
int n, m;
int a[MAXN];
int u[MAXN];
int x,y;

int find(int t){
    return (u[t] == t) ? t : (u[t] = find(u[t]));
}

int same(int x, int y){
    return find(x) == find(y);
}

void uni(int x, int y){
    int ux = find(x), uy = find(y);
    u[ux] = uy;
}


int main() {
    ll res = 1e9;
    cin >> n >> m;
    for(int i = 0; i < n; i++) u[i] = i;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i++){
        cin >> x >> y;
        uni(x, y);
    }
    for(int i = 0; i < n; i++){
        V[find(i)].push_back(i);
        pque.push(P(a[i], i));
    }

    if(n < 2 * (n-m-1)) return !printf("Impossible");
    if(n == m + 1) return !printf("0");
    priority_queue<P, vector<P>, greater<P> > alr;

    int mint = -1;
    for(int t : V[find(0)])
        if(res > (ll)a[t]) res = (ll)a[t], mint = t;
    for(int t : V[find(0)]) if(t != mint) alr.push(P(a[t], t));


    while(!pque.empty()){
        P p = pque.top(); pque.pop();
        if(same(p.second, 0)) continue;

        int k = find(p.second);
        uni(p.second, 0);
        //cout << "connecting " << p.second << " and " << alr.top().second << endl;
        //cout << "adding " << p.first << endl;
        res += (ll)(p.first);
        for(int t : V[k])
            if(t != p.second)
                alr.push(P(a[t], t));

    }
    for(int i = 0; i < 2*(n-m-1)-(n-m); i++){
        res += alr.top().first;
        //cout << "adding" << alr.top().first << endl;
        alr.pop();
    }

    cout << res;

}

Measured memory_bytes: 7284
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
int main()
{
    long long  n,m;
    cin>>n>>m;
    cout<<m*1900*(int)pow(2,m)+(n-m)*100*(int)pow(2,m)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<utility>
#include<cmath>
using namespace std;

int main(){
  int h,w,a[500][500],flag=0,cnt=0,x,y;
  vector<pair<int,int> > p;
  scanf("%d %d",&h,&w);
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      scanf("%d",&a[i][j]);
      a[i][j]%=2;
    }
  x=h-1;
  if(h%2)
    y=w-1;
  else
    y=0;
  for(int i=0;i<h;i++){
    if(i%2==0){
      for(int j=0;j<w;j++){
        if(flag)
          cnt++;
        if(a[i][j]==1){
          p.push_back(make_pair(i+1,j+1));
          if(flag)
            flag=0;
          else
            flag=1;
        }
      }
    }
    else{
      for(int j=w-1;j>=0;j--){
        if(flag)
          cnt++;
        if(a[i][j]==1){
          p.push_back(make_pair(i+1,j+1));
          if(flag)
            flag=0;
          else
            flag=1;
        }
      }
    }
  }
  printf("%d\n",cnt);
  for(int i=0;i<h;i++){
    if(i%2==0){
      for(int j=0;j<w;j++){
        if(a[i][j]%2==1&&(i!=x||j!=y)){
          if(j!=w-1){
            printf("%d %d %d %d\n",i+1,j+1,i+1,j+2);
            a[i][j+1]++;
          }
          else{
            printf("%d %d %d %d\n",i+1,j+1,i+2,j+1);
            a[i+1][j]++;
          }
        }
      }
    }
    else{
      for(int j=w-1;j>=0;j--){
        if(a[i][j]%2==1&&(i!=x||j!=y)){
          if(j!=0){
            printf("%d %d %d %d\n",i+1,j+1,i+1,j);
            a[i][j-1]++;
          }
          else{
            printf("%d %d %d %d\n",i+1,j+1,i+2,j+1);
            a[i+1][j]++;
          }
        }
      }
    }
  }
}

Measured memory_bytes: 5104
mod = 10 ** 9 + 7

n, k = gets.to_s.split.map{|e|e.to_i}

# ans = (k..n+1).map{|i| i * (n + n - i + 1) / 2 - i * ( i - 1 ) / 2 + 1 }.sum % mod
ans = n - k + 2
(k..n+1).each do |i|
  
  ans += i * (n - i + 1) 
  #ans %= mod if ans >= mod
end

puts ans % mod

Measured memory_bytes: 14380
#include <string>
#include<iostream>
#include <algorithm>

using namespace std;

int a[3];

int main ()
{
cin>>a[0]>>a[1]>>a[2];



sort(a,a+3);

if(a[0]==5 && a[1]==5 && a[2]==7  ){cout<<"YES"<<endl;}
else {cout<<"NO"<<endl;}
return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl a(n), b(n), c(n - 1);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n - 1) cin >> c[i];
  ll ans = 0, last = -1;
  rep(i, n) {
    ans += b[a[i] - 1];
    if(a[i] - 1 == last) ans += c[a[i] - 2];
    last = a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int N;
char alphabet[11]="abcdefghij";
string str="a";
void strplus(int l,int n){
    string s=str;
    if(l==N){
        cout << str << "\n";
    }else{
        for(int i=0; i<=n; i++){
            str+=alphabet[i];
            if(i==n) strplus(l+1,n+1);
            else strplus(l+1,n);
            str=s;
        }
    }
}
int main(){
    cin >> N;
    strplus(1,1);
    return 0;
}

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

#define ll long long
const int mod = 1e9 + 7;


ll int INF = 1e17;
ll int dp[105][100005];
int wgt[105];
int val[105];

ll int kil(int idx, int value)
{
  if(value < 0)
    return INF;

  if(idx == 0)
  {
    if(value == 0)
      return 0;
    return INF;
  }

  if(dp[idx][value] != -1)
    return dp[idx][value];

  dp[idx][value] = INF;

  dp[idx][value] = min(dp[idx][value], kil(idx-1, value));
  dp[idx][value] = min(dp[idx][value], kil(idx-1, value - val[idx]) + wgt[idx]);

  return dp[idx][value];
}

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

  memset(dp, -1, sizeof dp);

  int n, w;
  cin>>n>>w;
  for(int i=1;i<=n;i++)
    cin>>wgt[i]>>val[i];

  ll int res, ans=0;
  for(int i=100000;i>=0;i--)
  {
    res = kil(n, i);
    if(res <= w)
    {
      ans = i;
      break;
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 82304
# -*- coding: utf-8 -*-
N,M,C = [int(i) for i in input().split()]
B = list(map(int, input().split()))
A = []
for i in range(N):
    A.append([int(i) for i in input().split()])

ans = 0
for i in range(N):
    X = 0
    for j in range(M):
        X += A[i][j] * B[j]
    if X + C > 0:
        ans += 1
    else:
        ans += 0
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout << #x << " " << x << "\n"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 1e5 + 3;

ll n, m, mx[N], res;
vector<ll> g[N];

ll dfs(ll v) {
	if (mx[v] != -1) return mx[v];
	
	ll len = 0;
	for (ll& to: g[v]) {
		len = max(len, dfs(to) + 1);
	}
	return mx[v] = len;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	fill(mx, mx + N, -1);
	
	cin >> n >> m;
	while (m--) {
		ll x, y;
		cin >> x >> y;
		g[x].pb(y);
	}
	
	for (ll i = 1; i <= n; ++i) dfs(i);
	
	res = 0;
	for (ll i = 1; i <= n; ++i) {
		res = max(res, mx[i]);
	}
	cout << res;
	
	return 0;
}


Measured memory_bytes: 8576
import java.io.*;
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        String s = sc.next();
        if(a >= 3200){
            System.out.println(s);
        }else{
            System.out.println("red");
        }

    }


    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 21204
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#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 rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<par<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,p;
    cin>>n>>p;
    vi a(n);
    rep(i,n)cin>>a[i];
    bool f=false;
    int ans=1;
    rep(i,n){
        ans*=2;
        f|=a[i]%2;
    }
    if(!f)cout<<(p?0:ans)<<endl;
    else cout<<ans/2<<endl;
}

Measured memory_bytes: 256
#b
n,l=map(int, input().split())
result = 0
if l > 0:
    for i in range(n-1):
        result += i+l+1
elif l + n > 0:
    for i in range(n):
        result += i+l
else:
    for i in range(n-1):
        result += i+l
print(result)

Measured memory_bytes: 3060
#include<stdio.h>
#define max(x,y) (x>y?x:y)
int dx[]={1,0,-1,0};
int dy[]={0,-1,0,1};
typedef struct{
    int x;
    int y;
}data_t;
typedef struct{
    int head;
    int tail;
    data_t data[200000];
}queue_t;
queue_t queue;
void initqueue(){queue.head=queue.tail=0;}
void enqueue(data_t data){queue.data[queue.tail++]=data;}
data_t dequeue(){return queue.data[queue.head++];}

int h,w;
char map[1000][1000];

int bfs(data_t start,data_t goal){
    int dist[1000][1000];
    data_t now,move;

    initqueue();
    enqueue(start);
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            dist[i][j]=-1;
        }
    }
    dist[start.y][start.x]=0;

    while(queue.head!=queue.tail){   
        now=dequeue();
        for(int i=0;i<4;i++){
            move.x=now.x+dx[i];
            move.y=now.y+dy[i];
            if(move.x<0||w<=move.x||move.y<0||h<=move.y)continue;
            if(dist[move.y][move.x]!=-1||map[move.y][move.x]=='#')continue;
            enqueue(move);
            dist[move.y][move.x]=dist[now.y][now.x]+1;
        }
        if(dist[goal.y][goal.x]!=-1)return dist[goal.y][goal.x];
    }
    return -1;
}
int main(){
    scanf("%d %d",&h,&w);
    for(int i=0;i<h;i++)scanf("%s",map[i]);
    int ans=-1;
    data_t start,end;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(map[i][j]=='#')continue;
            for(int ii=0;ii<h;ii++){
                for(int jj=0;jj<w;jj++){
                    if(map[ii][jj]=='#')continue;
                    if(i==ii&&j==jj)continue;
                    start.x=j;
                    start.y=i;
                    end.x=jj;
                    end.y=ii;
                    ans=max(ans,bfs(start,end));
                }
            }
        }
    }
    printf("%d\n",ans);

    return 0;
}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007;

int main(){
    
    ll N,M;cin>>N>>M;
    vector<ll> A(N),B(M);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    ll sumA=0,sumB=0;
    for(ll i=1;i<N;i++){
        sumA+=((A[i]-A[i-1])*i*(N-i))%mod;
        sumA=sumA%mod;
    }
    for(int i=0;i<M;i++){
        cin>>B[i];
    }
    for(ll i=1;i<M;i++){
        sumB+=((B[i]-B[i-1])*i*(M-i))%mod;
        sumB=sumB%mod;
    }
    cout<<sumA*sumB%mod<<endl;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

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

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  long double A, B;
  cin >> A >> B;
  cout << (ll) (A * B) << endl;

  return 0;
}


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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    string s;
    cin >> s;
    char tmp = s[0];
    ll size,ans=0;
    size = s.size();
    REP(i,1,size){
        if(tmp != s[i]){
            tmp = s[i];
        }else{
            ans++;
            if(s[i]=='0') tmp = '1';
            else tmp = '0';
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <bitset>
#include <string>
#include <cstdio>
#include <math.h>
using namespace std;

const long long int INF = 1000000007;

int main(void)
{
    int N;
    cin >> N;
    vector<bool> a(N, false);
    for (int i = 0; i < N; i++)
    {
        int x, y;
        cin >> x >> y;

        if (x == y) a[i] = true;
    }

    int count = 0;
    for (int i = 0; i < N; i++)
    {
        if(a[i])
        {
            count++;
        }
        else
        {
            count = 0;
        }

        if (count == 3)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
}

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

int main(){
    unsigned long long n,k,mod,ans=0,tmp;
    char token[300000]={};
    fgets(token, sizeof(token), stdin);
    n=atoll(strtok(token, " "));k=atoll(strtok(NULL, " "));
    if (n>=k) {
        mod=n%k;
        tmp=k-mod;
        if (tmp<mod) ans=tmp;
        else ans=mod;
    }else{
        tmp=k-n;
        if (tmp<n) ans=tmp;
        else ans=n;
    }
    printf("%lld",ans);
    return 0;
}



Measured memory_bytes: 512
n, m = map(int, input().split())
tree = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)


# 橋となる辺を返す
def bridge(G, N):
    result = set()
    label = [None]*N
    gen = 0
    cost = [0]*N
    def dfs(u, p):
        nonlocal gen
        res = 0
        for v in G[u]:
            if v == p:
                continue
            if label[v] is not None:
                if label[v] < label[u]:
                    cost[v] += 1
                    res += 1
            else:
                label[v] = gen; gen += 1
                r = dfs(v, u)
                if r == 0:
                    result.add((u, v) if u < v else (v, u))
                res += r
        res -= cost[u]
        return res
    for v in range(N):
        if not label[v]:
            label[v] = gen; gen += 1
            r = dfs(v, -1)
            assert r == 0, r
    return result


print(len(bridge(tree, n)))

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

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

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int d, n; cin >> d >> n;
  int cnt2 = 0;
  int k = int(pow(100, d));
  for (int i = k; ; i += k) {
    int cnt = 0, j = i;
    while (j % 100 == 0) {
      cnt++;
      j /= 100;
    }
    if (cnt == d) {
      cnt2++;
      if (cnt2 == n) {
        outl(i);
        return;
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

int main() {
  long int A,B,ans=1;
  double a,b;
  cin >> A >> B;
  
  while(ans<=1000){
    a=ans*0.08;
    b=ans*0.1;
    if((int)a == A){
      if((int)b == B){
        cout << ans << endl;
        return 0;
      }
    }
    ans++;
  }
  
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 384
const main = lines => {
  const strArr = lines.split("");
  let result = "Yes";

  strArr.forEach((str, index) => {
    index += 1;
    if (index % 2 === 1) {
      if (str === "L") {
        result = "No";
      }
    } else {
      if (str === "R") {
        result = "No";
      }
    }
  });

  console.log(result);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
    int pat;
	long x, y, ans; cin >> x >> y;
	if(x<0){
	    swap(x, y);
	    if(x<=0){
	        x *= -1;
	        y *= -1;
	    }
	}
	if(x<=y) pat=1;
	else if(y>0) pat=2;
	else if(-y<=x) pat=3;
	else pat=4;
	switch(pat){
	    case 1:
	     ans=y-x;
	     break;
	    case 2:
	     ans=2+x-y;
	     break;
	    case 3:
	     ans=1+x+y;
	     break;
	    case 4:
	     ans=1-x-y;
	     break;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
tmp = list(map(int, input().split()))
n = tmp[0]
x = tmp[1]
l = list(map(int, input().split()))

ptr = 0
ans = 0
for i in range(n):
  ptr += l[i]
  ans = i+1
  if ptr > x:
    ans -= 1
    break

print (ans + 1)

Measured memory_bytes: 38384
#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>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s,t;
    cin>>s>>t;
    int max_cnt=-1;
    for(int i=0;i<s.size();i++){
        string u=s.substr(i,t.size());
        int cnt=0;
        if(t.size()!=u.size())break;
        for(int j=0;j<t.size();j++){
            if(t[j]==u[j])cnt++;
        }
        max_cnt=max(max_cnt,cnt);
    }
    cout<<t.size()-max_cnt<<endl;

    return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;

int main()
{
    long long  a,b,c,k;
    cin>>a>>b>>c>>k;
    long long a1,b1,c1;
    int flag=0;
    long long ans=0;
    if(k%2==0)
        ans = a-b;
    else 
        ans = b-a;
    if(ans>pow(10,18))
        flag=1;
    if(flag==0)
        cout<<ans<<endl;
    else
        cout<<"Unfair";


}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define SIZE 100000
ll inv[SIZE + 1];
ll kai[SIZE + 1];
ll invkai[SIZE + 1];
void invinit()
{
	inv[1] = 1;
	for (int i = 2; i <= SIZE; i++)
	{
		inv[i] = mod - (mod / i)*inv[mod%i] % mod;
	}
	kai[0] = invkai[0] = 1;
	for (int i = 1; i <= SIZE; i++)
	{
		kai[i] = kai[i - 1] * i%mod;
		invkai[i] = invkai[i - 1] * inv[i] % mod;
	}
}
ll com(ll a, ll b)
{
	if (b < 0 || a < b)return 0;
	return (invkai[b] * invkai[a - b]) % mod*kai[a] % mod;
}
int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	invinit();
	ll ans = a + 1;
	for (int k = 1; k < b; k++)
	{
		for (int l = 1; l <= b - k; l++)
		{
			ll t = com(b - 1, k - 1)*com(b - k - 1, l - 1) % mod;
			ans = (ans + t*com(a - (b - k) - (b - k - l) + 2, 2)) % mod;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
int main()
{
    string s;
    ll k,t=0;
    cin >> s >> k;
    vector<pair<char,int>> vp;
    for (char c : s) {
        if (vp.empty() || c != vp.back().first)
            vp.emplace_back(c,1);
        else
            vp.back().second++;
    }
    for (auto p : vp) t += p.second / 2;
    ll ans = 0;
    if (vp.size() == 1) {
        ans = k * s.size() / 2;
    } else if (vp[0].F == vp.back().F) {
        ans = (t-vp[0].S/2-vp.back().S/2)*k + (k-1) * ((vp[0].S+vp.back().S)/2) + vp[0].S/2 + vp.back().S/2;
    } else {
        ans = t * k;
    }
    cout << ans << endl;
}


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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	int max = 0;
	if (a >= b) {
		if (a >= c) {
			max = a;
		}
		else {
			max = c;
		}
	}
	else {
		if (b >= c) {
			max = b;
		}
		else {
			max = c;
		}
	}
	cout << a + b + c - max << flush;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

static const ll MOD  = 1e9 + 7;
static const ll INF  = 1e18;
static const double EPS = 1e-10;

static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

int main(){
    ll N, K; cin >> N >> K;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    ll ans = 0;
    for(int i = 0; i < N; i++){
        ll cntB = 0, cnts = 0;
        for(int j = 0; j < N; j++){
            if(i == j) continue;

            if(i < j && A[i] > A[j]) cntB++;
            if(i > j && A[i] > A[j]) cnts++; 
        }
        ans += K * (K + 1 ) / 2 % MOD * cntB % MOD;
        ans +=  K * ( K - 1 ) / 2 % MOD * cnts  % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;
   
  
   
int main(){
   
    int n; 
    int r[1000],w[1000];
    int sum_r=0,sum_w=0,idx=0;
	bool dp[1001][1000]={};
    while(scanf("%d",&n),n){
         
        sum_r=sum_w=idx=0;
        for(int i=0;i<n;i++){
            scanf("%d %d",&r[i],&w[i]);
            sum_r+=r[i];
            sum_w+=w[i];
            if(r[idx]<r[i]) idx=i;
        }
  
        int r0=r[idx],r=sum_r-r0;
        w[idx]=0;
 
        if(r0 <= r){
            cout<<sum_r+sum_w<<endl;
        }else{
  
            int res=2*r0;
            //vector<vector<bool> > dp(1001,vector<bool>(1000,false));
  
			fill(&dp[0][0],&dp[1001][0],false);
            dp[0][0]=true;
            for(int i=0;i<n;i++){
                for(int j=0;j<1000;j++){
                    if(dp[i][j]){
                        dp[i+1][j]=true; 
                        if(j+w[i]<1000)
                            dp[i+1][j+w[i]]=true; 
                    }
                }
            }
  
            int opt=r0-r;
            while(!dp[n][opt]) opt--;
  
            res+=sum_w-opt;
            printf("%d\n",res);
  
  
  
        }
          
          
    }
}

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

using namespace std;

typedef long long ll;
const int N = 1e4+10, OO = 0x3F3F3F3F;

int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
int n , m , mxDis;
char s[25][25];
int dis[25][25];
bool vis[25][25];

bool valid(int x , int y){
    return x >=0 && x < n && y >= 0 && y < m && s[x][y] != '#' && !vis[x][y];
}


int bfs(int sr , int sc){

    queue < pair < int , int > > q;
    q.push({sr , sc});
    dis[sr][sc] = 0;
    vis[sr][sc] = 1;
    mxDis = 0;
    while(!q.empty()){

        int px = q.front().first;
        int py = q.front().second;
        //printf("%d %d\n",px,py);
        q.pop();
        for(int d = 0 ; d < 4 ; ++d){
            int nr = px+dx[d];
            int nc = py+dy[d];
            if(valid(nr, nc)){
                if(dis[nr][nc] < dis[px][py] + 1){
                    q.push({nr , nc});
                    dis[nr][nc] = dis[px][py] + 1;
                    vis[nr][nc] = 1;
                    if(dis[nr][nc] > mxDis)
                        mxDis = dis[nr][nc];
                }

            }

        }


    }
    return mxDis;

}





int main()
{

    int ans = -OO;
    scanf("%d %d" , &n,&m);
    for(int i = 0 ; i < n ; ++i)
        scanf("%s",s[i]);

    for(int i = 0 ; i < n ; ++i){
        for(int j = 0 ; j < m ; ++j){
                if(s[i][j] == '.'){
                    ans = max(ans , bfs(i , j));
                    memset(dis , 0 , sizeof dis);
                    memset(vis, 0 , sizeof vis);
                }
        }
    }

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


    return 0;
}


Measured memory_bytes: 256
a,b=map(int,input().split(" "))
l=[]
for i in range(a):
    k=list(input())
    l.append(k)
ca=0
for i in range(a):
    for j in range(b):
        if l[i-ca][j]=="." and j+1==b:
            del l[i-ca]
            ca+=1
        elif l[i-ca][j]=="." :
            pass
        else:
            break
cb=0
for i in range(b):
    for j in range(a-ca):
        if l[j][i-cb]=="." and j+1==a-ca:
            for k in range(a-ca):
                del l[k][i-cb]
            else:
                cb+=1
        elif l[j][i-cb]==".":
            pass
        else:
            break
        
for i in l:
    print(*i,sep="")
    

Measured memory_bytes: 4596
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

ll gcd(ll a, ll b){if (b == 0) return a;return gcd(b, a % b);}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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


int main(){
    int N, x=0, ans=0;
    string S;
    cin >> N >> S;
    for(int i = 0; i < N; ++i){
        if(S[i] == 'I') x++;
        else x--;
        ans = max(ans, x);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef long double lldb;
typedef pair<ll, ll>  ii;
typedef pair<lldb, lldb>  iidb;
typedef pair<ll, ii>  iii;
typedef vector<ll>     vi;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9+7;
const lldb PI = acos(-1);
#define initseg ll new_nodo=(pnodo*2),mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 2020000
#define offset 200
#define ptr nodo*
const ll MOD=1e9+7;
map<int,int> mapa;
int primo[tam],totprimos[tam],v[tam];
void decomp(int num)
{
	mapa.clear();
	while(num!=1)
	{
		if (primo[num]==0)break;
		mapa[primo[num]]++;
		num/=primo[num];
	}
	if (num!=1)
		mapa[num]++;
	
}
int main()
{
	forr(i,2,tam)
	{
		if (primo[i]!=0)continue;
		forg(j,i+i,tam,i)
		{
			primo[j]=i;
		}
	}
	int tot=0,N;
	cin>>N;
	bool paircoprime=1;
	forr(i,0,N)
	{
		cin>>v[i];
		tot=__gcd(tot,v[i]);
		decomp(v[i]);
		for(auto ite:mapa)
		{
			if (totprimos[ite.fi]!=0)
				paircoprime=0;
			totprimos[ite.fi]+=ite.se;
		}
	}
	if (paircoprime)
	{
		cout<<"pairwise coprime\n";
	}
	else
	{
		if (tot==1)
			cout<<"setwise coprime\n";
		else
			cout<<"not coprime\n";
	}
	
}

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

using namespace std;

#define int 		long long
#define endl 		"\n"
#define mod			1000000007
#define inf			1e9
#define IOS			ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)


int32_t main() {

	IOS;

	int n;
	cin >> n;

	vector<int> v(n);

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

	int ans = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (v[j] <= v[i])
				continue;
			for (int k = 0; k < n; k++) {
				if (v[k] <= v[j])
					continue;

				if (v[i] + v[j] > v[k])
					ans++;
			}
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

vector<pair<int,int>> v[2][2];
int col[2][601][601];
bool used[601][601];

void dfs(int n,int d,int id){
	for(int i=0;i<2*n;i++){
		for(int j=0;j<2*n;j++){
			used[i][j]=false;
		}
	}
	vector<pair<int,int>> vec;
	for(int i=0;i<2*n;i++){
		for(int j=0;j<2*n;j++){
			if(i*i+j*j==d){
				vec.push_back(make_pair(i,j));
				vec.push_back(make_pair(-i,j));
				vec.push_back(make_pair(i,-j));
				vec.push_back(make_pair(-i,-j));
			}
		}
	}
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()),vec.end());
	for(int i=0;i<2*n;i++){
		for(int j=0;j<2*n;j++){
			if(used[i][j])continue;
			used[i][j]=1;
			queue<pair<int,int>> q;
			q.push(make_pair(i,j));
			while(q.size()){
				auto p=q.front(); q.pop();
				for(auto t:vec){
					int x=p.first+t.first,y=p.second+t.second;
					//cout << x << " " << y << endl;
					if(0<=x&&x<2*n&&0<=y&&y<2*n){
						if(used[x][y])continue;
						else{
							used[x][y]=1;
							col[id][x][y]=col[id][p.first][p.second]^1;
							q.push(make_pair(x,y));
						}
					}
				}
			}
		}
	}
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,d,dd; cin >> n >> d >> dd;
	dfs(n,d,0);
	dfs(n,dd,1);
	for(int i=0;i<2*n;i++){
		for(int j=0;j<2*n;j++){
			//cout << i << " " << j << " " << col[0][i][j] << " " << col[1][i][j] << endl;
			v[col[0][i][j]][col[1][i][j]].push_back(make_pair(i,j));
		}
	}
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			if(v[i][j].size()>=n*n){
				for(int k=0;k<n*n;k++){
					printf("%d %d\n",v[i][j][k].first,v[i][j][k].second);
				}
				return 0;
			}
		}
	}
}


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

int main()
{
    long long n,k;
    cin>>n>>k;
    long long heights[n];
    long long dp[n];
    for(int i=0;i<n;i++)
    {
        cin>>heights[i];
        dp[i]=-1;
    }
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i-j>=0)
            {
                if(dp[i]!=-1)
                dp[i]=min(dp[i],dp[i-j]+abs(heights[i]-heights[i-j]));
                else
                dp[i]=dp[i-j]+abs(heights[i]-heights[i-j]);
            }
        }
    }
    cout<<dp[n-1]<<endl;
}


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

flg = False
cnt = 0
while(True):
    i = 0
    for num in a:
        # get_odd_even = lambda x: x if (x%2)==0 else 0
        if num%2 == 0:
            a[i] = int(num/2)
        else:
            flg = True
        i += 1
    if flg:
        break
    cnt += 1

print(cnt)
    

Measured memory_bytes: 38896
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long  ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000003;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;

ll mod_pow(ll x, ll n) {
	x %= mod;
	ll ret = 1;
	while (n) {
		if (n % 2)ret = ret * x%mod;
		x = x * x%mod; n >>= 1;
	}
	return ret;
}
vector<ll> ra(mod + 1);
void solve() {
	ra[0] = 1;
	rep(i, mod) {
		ra[i + 1] = ra[i] * (i + 1) % mod;
	}
	int q; cin >> q;
	rep(i, q) {
		ll x, d, n;
		cin >> x >> d >> n;
		if (d == 0) {
			cout << mod_pow(x, n) << endl;
			continue;
		}
		else if (x == 0) {
			cout << 0 << endl; continue;
		}
		x = x * mod_pow(d, mod - 2)%mod;
		//cout << x << endl;
		ll le = x, ri = x + n - 1;
		if (ri >= mod) {
			cout << 0 << endl; continue;
		}
		ll ans = ra[ri] * mod_pow(ra[le-1], mod - 2)%mod;
		ans = ans * mod_pow(d, n) % mod;
		cout << ans % mod << endl;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//while (cin >> n)solve();
	solve();
	//stop
	return 0;
}

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

#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define END(x) do{cout<<(x)<<endl;exit(0);}while(0)
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define exp2(x)  (1LL<<(x))

using ll=long long;
using namespace std;

const ll MOD = 1e9+7;


vector<int> adj[100*1000+100];

int fact[100*1000+100];
ll ans = 1;
int K = -1;
void dfs(int u, int f, int c) {
    c = max(0, c);
    ans = (ans * c )% MOD;
    int cc = 0;
    if (f==-1) cc--;
    for(auto v : adj[u]) {
        if (f != v) {
            dfs(v, u, K-2-cc);
            cc++;
        }
    }
            
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N >> K;
    fact[0] = 1;
    rep(i, 1, 100*1000+9) fact[i] = fact[i-1] * i;
    rep(i, 0,N-2) {
        int u, v;
        cin >> u >> v;
        u--;v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dfs(0, -1, K);
    END(ans);
}


Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<set>
using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdi(a,b) for(int i=a-1;i>=b;--i)
#define fdj(a,b) for(int j=a-1;j>=b;--j)
#define fdo(a,b) for(int o=a-1;o>=b;--o)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
////////////////////

int const N = 241;
int const INF = 1e9 + 41;

int h, w;
int c[N][N];
int d[N][N];
int a[N][N];
int ans;

void dijk(int s){
	fi(0, 10) d[s][i] = INF;
	d[s][s] = 0;
	set<pii> t;
	t.insert(mp(0, s));
	while(sz(t)){
		pii cur = *t.begin();
		t.erase(cur);
		int di = cur.first;
		int id = cur.second;
		fi(0, 10){
			if(di + c[id][i] < d[s][i]){
				t.erase(mp(d[s][i], i));
				d[s][i] = di + c[id][i];
				t.insert(mp(d[s][i], i));
			}
		}
	}
}

void solve(){
	fi(0, 10) dijk(i);
	fi(0, h) fj(0, w){
		if(a[i][j] != -1) ans += d[a[i][j]][1];
	}
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%d %d",&h,&w);
	fi(0, 10) fj(0, 10) scanf("%d",&c[i][j]);
	fi(0, h) fj(0, w) scanf("%d",&a[i][j]);
	solve();

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

	return 0;
}

Measured memory_bytes: 512