akhauriyash/Code-Regression huggingface dataset:
import sys, re
import math
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul	# 
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd	# 最大公約数
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# -*- coding: utf-8 -*-

k = INT()
s = input()
if len(s) > k:
    text = s[0:k] + "..."
    print(text)
else:
    print(s)

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

int main(){
	int a[10];
	for(int i=0;i<10;i++){
		cin>>a[i];
	}
	sort(a,a+10);
	for(int i=9;i>6;i--){
		cout<<a[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3104
#include <cstdio>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

vector<int> X(1000001,0);

int main() {
    unsigned int s;
    int answer=1;
    cin >> s;

    X[s]++;
    while(true){
        if(s%2 == 1){
            s = 3*s+1;
            X[s]++;
        }else{
            s = s/2;
            X[s]++;
        }
        answer++;
        if(X[s]>1) break;
    }
    cout << answer << endl;
    return 0;
}



Measured memory_bytes: 4096
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,q;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s,t[ohara];
bool fl;
struct edge{int to,cost;};
unordered_map<string,ll> mp;
    
//------ Believe yourself as a genius!!!!!! ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>s>>k;
    rep(i,Size(s)){
        string co="";
        rrep(j,i,min((ll)i+k,(ll)Size(s))){
            co+=s[j];
            if(mp[co]!=0)continue;
            mp[co]++;
            t[cnt++]=co;
        }
    }
    sort(t,t+cnt);
    Cout(t[k-1]);
    return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>
#include <string.h>
#define MAX 100005

typedef struct Proc {
    char name[20];
    int time;
} P;

P Q[MAX];
int head, tail, n;

void enqueue(P x)
{
    Q[tail] = x;
    tail = (tail + 1) % MAX;
}

P dequeue()
{
    P x = Q[head];
    head = (head + 1) % MAX;
    return x;
}

int min(int a, int b)
{
    return a < b ? a : b;
}

int main()
{
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);

    for (i = 1; i < n+1; i++) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].time);
    }
    head = 1;
    tail = n + 1;

    while (head != tail) {
        u = dequeue();
        c = min(q, u.time);
        u.time -= c;
        elaps += c;
        if (u.time > 0) {
            enqueue(u);
        } else {
            printf("%s %d\n", u.name, elaps);
        }
    }

    return 0;
}


Measured memory_bytes: 4052
import sys


def main():

    # Get Args
    args = _input_args()  # get arguments as an array from console/script parameters.

    # Call main Logic
    result = _main(args)

    # Output a result in a correct way.
    _output_result(result)


def _main(args):
    """Write Main Logic here for the contest.

    :param args: arguments
    :type args: list
    :return: result
    :rtype: depends on your logic.
    """
    hash = HashMap()

    for value in args:
        hash.add(value)

    # Return something.
    return hash.find_unique()


class HashMap(object):
    def __init__(self):
        self.map = {}

    def add(self, value):
        if self.map.get(value) is None:
            self.map[value] = [value]
        else:
            self.map[value].append(value)

    def find_unique(self):
        for value, array in self.map.items():
            if len(array) == 1:
                return array[0]


def _input_args():

    arguments = _input().split()  # ptn2: get args from 1 line console prompt with space separated.

    return arguments  # This will be array.


def _input():
    # If Subject requires interactive input, use this and patch mock in unittest.
    return input()  # Change if necessary.


def _output_result(result):

    print('{}'.format(str(result)))  # Same as above, but more versatile.


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i, N)   cin >> h[i];
    sort(h.begin(), h.end());
    int ans = 1e9;
    rep(i, N-K+1){
        ans = min(ans, (h[i+K-1] - h[i]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#-*-coding:utf-8-*-

def main():
    k = int(input())
    a, b = map(int, input().split())
    for i in range(a, b+1):
        if i % k == 0:
            print('OK')
            exit()
    print('NG')
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9180
A,B,C,D=list(map(int, input().split()))

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def lcm(a,b):
  return a*b//gcd(a,b)

E=lcm(C,D)

A-=1

Cmin=A-A%C
Cmax=B-B%C
Dmin=A-A%D
Dmax=B-B%D
Emin=A-A%E
Emax=B-B%E

num = ((Cmax-Cmin)//C)+((Dmax-Dmin)//D)-((Emax-Emin)//E)



print(int(B-A-num))


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

using namespace std;

int main() {

	while(true) {
		int N;
		cin >> N;
		if(N == 0) break;
		string c;
		cin >> c;
		int maisu[10];
		for (int i = 0; i < N; i++){
			maisu[i] = 0;
		}
		int ba = 0;
		int turn = 0;
		for (int i = 0; i < c.size(); i++) {
			if(c[i] == 'M') {
				maisu[turn]++;
			}
			else if (c[i] == 'S') {
				maisu[turn]++;
				ba += maisu[turn];
				maisu[turn] = 0;
			}
			else {
				maisu[turn]++;
				maisu[turn] += ba;
				ba = 0;
			}
			turn ++;
			turn %= N;
		}
		sort(maisu, maisu+N);

		for(int i = 0; i < N; i++) {
			cout << maisu[i] << " ";
		}
		cout << ba << endl;
	}
		
	return 0;
}

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

typedef long long ll;

const int MAXN = 200005;
const int MAXBIT = 29;

int n;
int A[MAXN], B[MAXN];
int AA[MAXN], BB[MAXN];

ll count(int L, int R) {
    ll res = 0;
    for (int i = n, l = 1, r = 1; i >= 1; i--) {
        while (r <= n && AA[i] + BB[r] < R)
            r++;
        while (l <= n && AA[i] + BB[l] < L)
            l++;
        res += r - l;
    }
    return res;
}

bool solve(int T) {
    sort(AA + 1, AA + n + 1);
    sort(BB + 1, BB + n + 1);
    return (count(T, T << 1) + count(3 * T, T << 2)) & 1;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", A + i);
    for (int i = 1; i <= n; i++)
        scanf("%d", B + i);

    int ans = 0;
    for (int b = 0, T; b < MAXBIT; b++) {
        T = 1 << b;
        for (int i = 1; i <= n; i++) {
            AA[i] = A[i] % (T << 1);
            BB[i] = B[i] % (T << 1);
        }
        ans += solve(T) << b;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define INF 100000

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

  vector<int> suki(m, 0);

  int k, a;
  rep(i, n) {
    cin >> k;
    rep(j, k) {
      cin >> a;
      ++suki[a-1];
    }
  }

  int cnt = 0;
  for(int e : suki) {
    if (e == n) {
      ++cnt;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a % b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }
// 桁和
LL Ketawa_s(string s) { LL a = 0; FOR(i, 0, s.length())a += s[i] - '0'; return a; }

//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p % i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

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

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

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL A, B;
	cin >> A >> B;

	if (B % A == 0) {
		O(A + B);
	}
	else {
		O(B - A);
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>

typedef long long ll;

int N;
double a[2];
double ans;

int main() {
    std::cin >> N;
    for (int i=0; i<N; ++i) {
        double x;
        std::string u;
        std::cin >> x >> u;
        if ( u == "JPY" ) a[0] += x;
        else              a[1] += x;
    }
    ans = a[0] + 380000.0 * a[1];
    printf("%.5lf\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}


int main(){
    ll n,y; cin >> n >> y;
    auto solve = [&]() -> vector<ll>{
        vector<ll> ret(3);
        rep(i,n+1)rep(j,n+1){
            ll t = y - i*10000 - j*5000;
            if(0 <= t && t%1000 == 0 && t/1000 == n-i-j){
                return ret = {i,j,n-i-j};
            }
        }
        return ret = {-1,-1,-1};
    };
    vector<ll> ans = solve();
    print(ans);
}

Measured memory_bytes: 256
N = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
# S = gets.chomp.chars

res = Array.new(N, -1)
(N - 1).downto(0).each do |i|
  # We want to test the multiple of i
  r = 0  # This is the amount of value larger than i
  k = 2
  while (k * (i + 1) <= N) do
    r += res[k * (i + 1) - 1]
    k += 1
  end
  
  if (r % 2) == a[i]  # parity match
    res[i] = 0
  else
    res[i] = 1
  end
end

cnt = 0
a = []
0.upto(res.size - 1).each do |i|
  if res[i] == 1
    cnt += 1
    a << i + 1
  end
end

# For Debug
# p res

p cnt
if cnt > 0
  print a.join(" ")
end

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

using namespace std;

using ll = long long;

int main() {
    ll N, K, Q;
    cin >> N >> K >> Q;

    std::vector<ll> person(N);

    {
        ll x;
        for (ll i = 0; i < Q; ++i) {
            cin >> x;
            ++person[x - 1];
        }
    }

    for (ll i = 0; i < N; ++i) {
        if (person[i] > Q - K) {
            std::cout << "Yes" << std::endl;
        } else {
            std::cout << "No" << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 1408
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        char[] s = sc.next().toCharArray();
        ArrayDeque<Integer> ad = new ArrayDeque<>();
        ad.add(0);
        boolean zeroStarted = false;
        int zeroSec = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == '0') {
                if (!zeroStarted) {
                    zeroStarted = true;
                    if (zeroSec >= k) {
                        ans = Math.max(ans, i - ad.poll());
                        continue;
                    }
                }
            }else{
                if (zeroStarted) {
                    zeroStarted = false;
                    ad.add(i);
                    if(zeroSec < k) zeroSec++;
                }
            }
        }
        ans = Math.max(ans, n - ad.poll());
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 26628
if __name__ == '__main__':
    n = int(input())
    a0 = input().split()
    a = [int(i) for i in a0]
    s1 = 0
    s2 = 0
    m1 = 0
    m2 = 0
    o = 1
    e = -1
    for i in a:
        s1 += i
        if s1 == 0:
            m1 += 1
            s1 = o
        elif o * s1 < 0:
            m1 += abs(s1) + 1
            s1 = o
        o *= -1

        s2 += i
        if s2 == 0:
            m2 += 1
            s2 = e
        elif e * s2 < 0:
            m2 += abs(s2) + 1
            s2 = e
        e *= -1
    print(min(m1, m2))

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

public class Main{

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
            int[] arr = new int[3];
            
            for(int i=0 ; i<3 ; i++){
                arr[i] = in.nextInt();
            }
            int sum1 = Math.abs(arr[0]-arr[1]) + Math.abs(arr[1] -arr[2]);
            int sum2 =  Math.abs(arr[0]-arr[2]) + Math.abs(arr[1] -arr[2]);
            int sum3 =  Math.abs(arr[1]-arr[0]) + Math.abs(arr[0] -arr[2]);
            int sum4 =  Math.abs(arr[1]-arr[2]) + Math.abs(arr[0] -arr[2]);
            int sum5 =  Math.abs(arr[2]-arr[0]) + Math.abs(arr[0] -arr[1]);
            int sum6 =  Math.abs(arr[2]-arr[1]) + Math.abs(arr[0] -arr[2]);
           


            int result = Math.min(sum1 , sum2);
            result = Math.min(result , sum3);
            result = Math.min(result , sum4);
            result = Math.min(result , sum5);
            result = Math.min(result , sum6);
            
           System.out.println(result);
        }
    }


Measured memory_bytes: 21844
#include <sstream>
#include <fstream>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <utility>
#include <cassert>
#include <bitset>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define per(i,x,n) for(int i=n-1;i>=x;i--)
using namespace std;
#define ll long long
//head
int n, L;
int l, r, mid;
struct Bottle {
    int up, down, val;
    bool operator < (const Bottle a)const {
        return val > a.val;
    }
} a[100005];
ll b[100005], c[100005], sum[100005];
bool check(int x) {
    x--;
    rep(k, 1, n + 1) {
        if(c[k] <= x)
            continue;
        ll p = L - a[k].up, go = 0;
        if(k <= x && sum[x + 1] - a[k].val >= p)
            return 1;
        if(k > x && sum[x] >= p)
            return 1;
    }
    return 0;
}
inline char gc() {
    static char buf[1<<20], *head = buf, *tail = buf;
    return (head == tail && (tail = (head = buf) + fread(buf, 1, 1 << 20, stdin), head == tail)? -1: *head++);
}
template <typename T> inline bool read(T &x) {
    static bool f;
    static char c;
    for (c = gc(), f = false; !isdigit(c); c =gc()) {
        if (c == EOF)
            return false;
        else if (c == 45)
            f = true;
    }
    for (x = 0; isdigit(c); c = gc())
        x = x * 10 + c - 48;
    if (f)
        x = -x;
    return true;
}
int main() {
    read(n);read(L);
    rep(i, 1, n + 1)read(a[i].up),read(a[i].down),a[i].val = a[i].up - a[i].down;
    rep(i, 1, n + 1)read(b[i]);
    sort(a + 1, a + n + 1);
    rep(i, 1, n + 1)sum[i] = sum[i - 1] + a[i].val;
    ll cnt = 1, dis = 0;
    rep(i, 2, n + 1) {
        dis += (a[i].val - b[cnt]);
        if(dis <= 0)
            break;
        cnt++;
    }
    c[1] = cnt;
    int k = 2;
    for(; k <= n; k++) {
        if(cnt < k - 1 || cnt == n)
            break;
        dis += (a[k - 1].val - a[k].val);
        while(dis > 0 && cnt < n)
            cnt++, dis += (a[cnt + 1].val - b[cnt]);
        c[k] = cnt;
    }
    for(; k <= n; k++)
        c[k] = cnt;
    int day = 1;
    for(int i = 1; a[i].val > 0 && i <= n; i++, day++);
    l = 1, r = day;
    while(l < r) {
        mid = (l + r) / 2;
        if(check(mid))
            r = mid;
        else
            l = mid + 1;
    }
    if(check(l))
        cout << l << endl;
    else
        cout << -1 << endl;
    return 0;
}



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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl ;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 100000002;

int main(){
	int n, p; cin >> n >> p;
	string s; cin >> s;
	if(10%p == 0){
		ll ans = 0;
		rep(r,n){
			if((s[r]-'0') % p == 0){
				ans += r+1;
			}
		}
		cout << ans << endl;
		return 0;
	}
	vi d(n+1);
	int ten = 1;
	for(int i = n-1; i>=0; i--){
		int a = (s[i]-'0') * ten % p;
		d[i] = (d[i+1]+a) % p;
		ten *= 10; ten %= p;
	}
	vi cnt(p);

	ll ans = 0;
	for(int i=n; i>=0; i--){
		ans += cnt[d[i]];
		cnt[d[i]] ++;
	}
	cout << ans << endl;
}

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

typedef int keytype;

//quicksort(<#keytype *a#>, <#int first#>, <#int last#>)

void quicksort(keytype a[], int first, int last){
    int i, j;
    keytype x, t;
    
    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int gcd(int x, int y){
    if (y == 0) return x;
    else        return gcd(y, x % y);
}

int main() {
    int x,y,ans=0;
    //int a[3];
    scanf("%d %d",&x,&y);
    
    if (x==1 && y ==1){
        ans = ans + 400000;
    }
    if (x==1){
        ans = ans + 300000;
    }else if (x==2){
        ans = ans + 200000;
    }else if (x==3){
        ans = ans + 100000;
    }
    if (y==1){
        ans = ans + 300000;
    }else if (y==2){
        ans = ans + 200000;
    }else if (y==3){
        ans = ans + 100000;
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100

string r = "yuiophjklnm";

void calc(string s){

  bool last = false;
  int ans = 0;
  
  for(int i=0;i<11;i++) last |= s[0]==r[i];
  
  for(int i=1;i<s.size();i++){
    bool f = false;

    for(int j=0;j<11;j++) f |= s[i]==r[j];

    if(f ^ last){
      ans++;
      last = f;
    }
  }

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

int main(){
  string s;
  
  while(1){
    cin >> s;
    
    if(s=="#") break;
    
    calc(s);
  }

  return 0;
}

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

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

  int sz = S.size();
  int tot = 0;
  for (int i = 0; i < sz; i++) {
    if (S.at(i) != T.at(i)) tot++;
  }

  cout << tot << endl;
}

Measured memory_bytes: 3860
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const long long int  mx=1e9+7  ;
ll sum[200005];
int main()
{
 
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 cout.tie(NULL);
 
 int n,k;
 cin>>n>>k;
 
 sum[0]=0;
 
 for(int i=1;i<=n+1;i++)
 sum[i]=sum[i-1]+i;
 
 ll minsum,maxsum,ans=0;
 
 for(int i=k;i<=n+1;i++)
 {
    minsum = sum[i-1];
    
    maxsum = sum[n]-sum[n-i];
    
    ans =ans + (maxsum - minsum +1);
    
    ans %=mx;
 }
 
 cout<<ans%mx<<endl;
 
 return 0;
}

Measured memory_bytes: 5120
#define FILEIO(a) freopen(a".in", "r", stdin); freopen(a".out", "w", stdout);
#include <cstdio>
#include <queue>

const int N = 200005, M = 17;

int n, A[N];

int lg[N], st[M][N];

inline int pmin(int a, int b) {
	return A[a] < A[b] ? a : b;
}
void init() {
	for (int i = 2; i <= n; ++i) lg[i] = lg[i >> 1] + 1;
	for (int i = 1; i <= 2 * n; ++i) st[0][i] = i;
	for (int j = 0; j < lg[n]; ++j) {
		for (int i = (4 << j) - 1; i <= 2 * n; ++i) {
			st[j + 1][i] = pmin(st[j][i - (2 << j)], st[j][i]);
		}
	}
}
inline int query(int l, int r) {
	int k = lg[(r - l) / 2 + 1];
	return pmin(st[k][l + (2 << k) - 2], st[k][r]);
}

struct node {
	int l, r, u;
	node(int l, int r): l(l), r(r), u(query(l, r - 1)) {}
	inline bool operator<(const node &b) const {
		return A[u] > A[b.u];
	}
};

int main() {
//	FILEIO("seq")
	scanf("%d", &n); n /= 2;
	for (int i = 1; i <= 2 * n; ++i) scanf("%d", A + i);
	init();
	std::priority_queue<node> q;
	q.push(node(1, 2 * n));
	while (!q.empty()) {
		node cur = q.top(); q.pop();
		int v = query(cur.u + 1, cur.r);
		printf("%d %d ", A[cur.u], A[v]);
		if (cur.u != cur.l) q.push(node(cur.l, cur.u - 1));
		if (v != cur.r) q.push(node(v + 1, cur.r));
		if (cur.u + 1 != v) q.push(node(cur.u + 1, v - 1));
	}
	puts("");
	return 0;
}

Measured memory_bytes: 16892
#include <iostream>
#include <algorithm>
#include <set>
#include <numeric>
#include <vector>
#include <math.h>
#include <string>

using namespace std;

int main()
{
	long long N;

	cin >> N;

	vector<int> num;
	while (1)
	{
		num.insert(num.begin(), N % 10);
		N /= 10;

		if (N == 0)
		{
			break;
		}
	}
	
	long long kekka = 0;
	for (int p = 0; p < pow(2, num.size()-1); p++)
	{
		long long sum = 0;
		long long k = num[0];

		for (int i = 1; i < num.size(); i++)
		{
			if ((p & (1 << i-1)) == 0)
			{
				k = k * 10 + num[i];
			}
			else
			{
				sum += k;
				k = num[i];
			}
		}
		kekka += sum+k;
	}


	cout << kekka << endl;

	return 0;
}

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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
ll inf = 1e18;

ll N, K;
const int NODE_SIZE = 101010;

ll start;  //開始ノード番号

vector<ll> edge[NODE_SIZE];    //ノードの接続関係 <エッジの重み, 接続先ノード>
struct mint { int n; mint(int n_ = 0) : n(n_) {} };
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};

void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}

mint I(int n) { check_fact(abs(n)); return n >= 0 ? I_[n] : -I_[n]; }
mint F(int n) { check_fact(n); return n < 0 ? 0 : F_[n]; }
mint R(ll n) { check_fact(n); return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(ll n, ll r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

//幅優先探索

mint bfs_vec(){
    queue<ll> q; //<ノード>
    bool visited[NODE_SIZE];
    for(int i=0; i<N; i++) visited[i]=false;    //初期位置を設定
    q.push(start);  //開始ノードを追加
	mint ans = (mint) K;
	while(!q.empty()){
        ll curNode = q.front();
        q.pop();
        if(visited[curNode]) continue;
        visited[curNode] = true;
		if(curNode == start) ans *= P(K-1, (ll) edge[curNode].size());
		else ans *= P(K-2, (ll) edge[curNode].size()-1);
		for(ll nextNode: edge[curNode]){
            if(!visited[nextNode]){     //未到達のノードだけpush.
                q.push(nextNode);
            }
        }
    }
	return ans;
}

int main(){
	cin >> N >> K;
	REP(i,0,N-1){
		ll a, b;
		cin >> a >> b;
		a--;b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	start = 0;
	p(bfs_vec());
	return 0;
}

Measured memory_bytes: 8692
import java.util.*;

public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] one = new int[N];
		for(int i = 0; i < N; i++) {
			one[i] = sc.nextInt();
		}
		
		int[] result = new int[N];
		Arrays.fill(result, 0);
		
		for(int i = N; i > 0; i--) {
			int sum = 0;
			for(int j = 2; j * i <= N; j++) {
				sum += result[j * i - 1];
			}
			result[i - 1] = (sum % 2) ^ one[i - 1];
		}
		
		ArrayDeque<Integer> queue = new ArrayDeque<>();
		
		for(int i = 0; i < N; i++) {
			if(result[i] == 1)queue.add(i + 1);
		}
		System.out.println(queue.size());
		while(!queue.isEmpty()) {
			System.out.print(queue.poll()+((queue.isEmpty()?"":" ")));
		}
		System.out.println();
	}
}

Measured memory_bytes: 96084
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		if(N.length() == 1) {
			System.out.println(N);
		}else if(N.substring(1).matches("9+")) {
			System.out.println((N.charAt(0) - '0' ) + (N.length() - 1) * 9);
		}else {
			System.out.println((N.charAt(0) - '0' - 1) + (N.length() - 1) * 9);
		}
	}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;

typedef pair<int, int> P;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    

    int H, W, sx, sy;
    cin >> H >> W;
    char s[H][W];
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
          cin >> s[i][j];
        }
    }
        
    int ans = 0;
    for(int m=0;m<H;m++){
      for(int n=0;n<W;n++){
        if(s[m][n] == '#') continue;
        sx = m;
        sy = n;
        int dist[25][25];
        fill((int*)dist, (int*)(dist + H), INF);
        queue<P> que;
        dist[sx][sy] = 0;
        que.push(P(sx, sy));
        while(!que.empty()){
            P p = que.front();
            que.pop();
            int x = p.first;
            int y = p.second;
            
            for(int i = 0; i < 4; ++i){
                int nx = x + dx[i], ny = y + dy[i];
                if(nx < 0 || nx >= H || ny < 0 || ny >= W)  continue;
                if(s[nx][ny] == '#')    continue;
                
                if(dist[nx][ny] > dist[x][y] + 1){
                    dist[nx][ny] = dist[x][y] + 1;
                    que.push(P(nx, ny));
                    ans = max(ans, dist[nx][ny]);
                }
            }
        }
      }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n = int(input())
a = [int(input()) for i in range(n)]
mod = 10**9+7
dp = [0]*(n+1)
mae = [-2]*(max(a)+1)
mae2 = [0]*(max(a)+1)
dp[0] = 1
for i in range(n):
        if mae[a[i]] != -2 and mae[a[i]] != i-1:
                dp[i+1] = dp[i] + mae2[a[i]]
        else:
                dp[i+1] = dp[i]
        dp[i+1] %= mod
        if mae[a[i]] == i-1:
                mae[a[i]] = i
                continue
        mae[a[i]] = i
        mae2[a[i]] += dp[i]
        mae2[a[i]] %= mod
print(dp[n]%mod)

Measured memory_bytes: 56256
n, x = map(int,input().split())
A = list(map(int,input().split()))
if A[0] > x:
    ans = A[0] - x
    A[0] -= ans
else:
    ans = 0
for j in range(n):
    if j != n-1:
        if A[j]+A[j+1]> x:
            diff = A[j+1]+A[j]-x
            ans += diff
            if A[j+1] - diff > 0:
                A[j+1] -= diff
            else:
                A[j+1] = 0
    else:
        if A[j]> x:
            diff = A[j]-x
            ans += diff
print(ans)

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

 using namespace std;
 typedef long long ll;

 int digit_sum(int x) {
   int ans = 0;
   while (x > 0) {
     ans += x % 10;
     x /= 10;
   }
   return ans;
 }

 int main() {
   int N;

   cin >> N;

   int min_a = 10000;
   for (int A = 1; A < N; A++) {
     min_a = min(min_a, digit_sum(A) + digit_sum(N - A));
   }

   cout << min_a << endl;
}


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

using namespace std;

string bin_string(int size, int n) {
    string ret = "";
    for (int i = size - 1; i >= 0; i--) {
        int k = n >> i;
        if (k & 1) {
            ret += "1";
        } else {
            ret += "0";
        }
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> testimonies(n);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        for (int k = 0; k < a; k++) {
            int x, y;
            cin >> x >> y;
            testimonies[i].emplace_back(make_pair(x, y));
        }
    }
    int ans = 0;
    for (int i = 0; i < pow(2, n); i++) {
        string s = bin_string(n, i);
        vector<int> honest(n + 1, -1);
        int count = 0;
        bool able = true;
        for (int l = 0; l < n; l++) {
            if (s[l] == '1') {
                count++;
                for (auto e: testimonies[l]) {
                    if (e.second == 1) {
                        if (honest[e.first] == 0 || s[e.first - 1] == '0') {
                            able = false;
                        } else {
                            honest[e.first] = 1;
                        }
                    } else {
                        if (honest[e.first] == 1 || s[e.first - 1] == '1') {
                            able = false;
                        } else {
                            honest[e.first] = 0;
                        }
                    }
                }
            }
        }
        if (able) {
            ans = max(ans, count);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,a,b = map(int, input().split())
t=0
for i in range(1,n+1):
    orign=i
    total = 0
    for ii in range(len(str(i))):
        total += i%10
        i=int(i/10)
    if total>=a and total<=b:
        t+=orign
print(t)

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

int main(int argc, char** argv){
  string S;
  cin >> S;
  
  int num = S.size();
  int maxv = 0;
  for(int cnt0=0; cnt0 < num; cnt0++){
    int tmpmax=0;
    for(int cnt1=cnt0; cnt1 < num; cnt1++){
      if(S[cnt1] == 'A' || \
         S[cnt1] == 'T' || \
         S[cnt1] == 'G' || \
         S[cnt1] == 'C') {
        tmpmax = cnt1-cnt0 + 1;
        continue;
      }
      break;
    }
    maxv = max(maxv, tmpmax);
  }
  cout << maxv << endl;
  return 0;  
}


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

int a, b, k;

int main() {
	int i;
	
	cin >> a >> b >> k;
	for (i = 0; i < k; i++) {
		if (i % 2 == 0) {
			if (a % 2 == 1) a--;
			b += a / 2;
			a -= a / 2;
		}
		else {
			if (b % 2 == 1) b--;
			a += b / 2;
			b -= b / 2;
		}
	}
	
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int a;
	cin >> a;
	int ans = 0;
	for(int i = 105; i <= a; i++) {
		if(i%2==0) continue;
		int cnt = 0;
		for(int j = 1; j <= i; j++) {
			if(i%j==0) cnt++;
		}
		if(cnt==8) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int box[5001];
	int i,j;
	int sum;
	int MAX;
	while(1){
		cin>>n;
		if(n==0)	break;
		for(i=0;i<n;i++)	cin>>box[i];
		MAX=INT_MIN;
		for(i=0;i<n;i++){
			sum=box[i];
			//cout<<sum<<endl;
			MAX=max(MAX,sum);
			for(j=i+1;j<n;j++){
				sum+=box[j];
			//	cout<<sum<<endl;
				MAX=max(MAX,sum);
			}
		}
		cout<<MAX<<endl;
	}
	return 0;
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> G[n];
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;  b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  queue<ll> q;
  q.push(0);
  vector<ll> prev(n, INF);
  prev[0] = 0;

  while(!q.empty()) {
    ll pos = q.front();
    q.pop();
    rep(i, ll(G[pos].size())) {
      if (prev[G[pos][i]] != INF) continue;
      prev[G[pos][i]] = pos+1;
      q.push(G[pos][i]);
    }
  }

  if (find(prev.begin(), prev.end(), INF) != prev.end())
    cout << "No" << endl;
  else {
    cout << "Yes" << endl;
    reps1(i, n) {
      cout << prev[i] << endl;
    }
  }


  return 0;
}


Measured memory_bytes: 12824
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	if N == 0 {
		fmt.Println(1)
	} else {
		fmt.Println(0)
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

#define N 100001

char gStack[N];
int gSNum = 0;

void push(char);

int main(void) {
    int i, cnt = 0;
    char s[N];

    scanf("%s", s);

    i = strlen(s) - 1;

    while (i >= 0) {
        if (s[i] != s[i - 1] && i > 0) {
            cnt++;
            i-=2;
        } else if (gSNum != 0 && gStack[gSNum - 1] != s[i]) {
            cnt++;
            gSNum--;
            i--;
        } else {
            push(s[i]);
            i--;
        }
    }

    printf("%d\n", cnt * 2);

    return 0;
}

void push(char x) {
    gStack[gSNum] = x;
    gSNum++;
}




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

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

using namespace std;

typedef pair<int,int> ii;

int H,W;
int G[11][11],INDEX[11][11],ep_bitmask,sp,V;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
vector<int> edges[25][4];

bool isValid(int x,int y) { return 0 <= x && x < W && 0 <= y && y < H; }

inline void INIT(){
  ep_bitmask = 0, sp = -1;
  rep(i,11) rep(j,11) INDEX[i][j] = -1;
  rep(i,25) rep(j,4) edges[i][j].clear();
}

inline void make_edges(){
  rep(i,H) rep(j,W) if( G[i][j] != 0 ) {
    int x = j, y = i;
    rep(k,4){
      int nx = x + dx[k], ny = y + dy[k];
      while( isValid(nx,ny) ){
        if( G[ny][nx] == 1 ) edges[INDEX[i][j]][k].push_back(INDEX[ny][nx]);
        nx += dx[k], ny += dy[k];
      }
    }
  }
}

inline void calc_last_point(int x,int y){
  rep(i,4) {
    int nx = x + dx[i], ny = y + dy[i];
    while( isValid(nx,ny) ){
      if( G[ny][nx] == 1 ) ep_bitmask |= (1<<INDEX[ny][nx]);
      nx += dx[i], ny += dy[i];
    }
  }
}

int dfs(int cur,int visited,int remain,int ep_remain){

  if( ep_remain == 0 && remain != 0 ) return 0;
  if( remain <= 0 ) return ( (ep_bitmask>>cur) & 1 );

  int ret = 0;
  rep(k,4){
    rep(i,edges[cur][k].size()){
      int next = edges[cur][k][i];
      if( (visited>>next) & 1 ) continue;
      ret += dfs(next,visited|(1<<next),remain-1,ep_remain-((ep_bitmask>>next)&1));
      break;
    }
  }

  return ret;
}

int main(){
  while( scanf("%d%d",&W,&H), H|W ){
    INIT();
    int idx = 0,remain = 0,sx,sy;
    rep(i,H) rep(j,W) {
      scanf("%d",&G[i][j]);
      if( G[i][j] == 1 ) INDEX[i][j] = idx++, remain++;
      if( G[i][j] == 2 ) sx = j, sy = i;
    }
    sp = INDEX[sy][sx] = idx++;
    make_edges();

    calc_last_point(sx,sy);
    assert(remain <= 23);
    V = remain;
    printf("%d\n",dfs(sp,0,remain,__builtin_popcount(ep_bitmask)));

  }
  return 0;
}

Measured memory_bytes: 1220
n = gets.to_i
ary = gets.split.map(&:to_i)

ary_0 = ary.sort
ary = ary.sort.reverse

ans = 1

if ary_0[0] == 0
  puts "0"
else 
  ary.each do |a|
  ans *= a
    if ans > 10 ** 18
      puts "-1"
      break
    end
  end
  
  if ans <= 10 ** 18
    puts ans
  end
end

Measured memory_bytes: 23896
#include"bits/stdc++.h"
using namespace std;

void Main() {
  long long l, r;
  cin >> l >> r;

  if (l % 2019 == 0 || r % 2019 == 0) {
    cout << 0 << endl;
  } else {
    if (((l / 2019) + 1) * 2019 <= r) {
      cout << 0 << endl;
    } else {
      int ans = 2019;
      for (long long i = l; i < r; i++) {
        for (long long j = i + 1; j <= r; j++) {
          ans = min(ans, (int)((i % 2019) * (j % 2019)) % 2019);
        }
      }
      cout << ans << endl;
    }
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int main()
{
	int m, f, r;
	vector<char> grade;
	do {
		cin >> m >> f >> r;
		if (!(m == -1 && f == -1 && r == -1)) {
			if (m == -1 || f == -1) grade.push_back('F');
			else if (m + f >= 80) grade.push_back('A');
			else if (m + f >= 65 && m + f < 80) grade.push_back('B');
			else if (m + f >= 50 && m + f < 65) grade.push_back('C');
			else if (m + f >= 30 && m + f < 50) {
				if (r >= 50) grade.push_back('C');
				else grade.push_back('D');
			}
			else if (m + f < 30) grade.push_back('F');
		}
	} while (!(m == -1 && f == -1 && r == -1));

	for (vector<int>::size_type i = 0; i < grade.size(); i++)
		cout << grade[i] << "\n";
}

Measured memory_bytes: 1172
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;


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

	int n; cin >> n;

	int a[n],b[n],c[n];
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<n;i++) cin >> b[i];
	for(int i=0;i<n;i++) cin >> c[i];

	sort(a,a+n); sort(b,b+n); sort(c,c+n);

	int u,m,d;
	long long ans=0;
	for(int i=0;i<n;i++){
		m = b[i];
		ans += (lower_bound(a,a+n,m)-a) * (c+n - upper_bound(c,c+n,m));
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
using namespace std;

int main(){
  int N,L;
  cin>>N>>L;
  int ans=0;
  int mn=1000000,absmn;
  for(int i=1; i<=N; ++i){
    ans += L+i-1;
    if(abs(L+i-1)<mn){
      mn=abs(L+i-1);
      absmn=L+i-1;
    }
  }
  if(L<=0 && L+N-1>=0) cout<<ans<<endl;
  else cout<<ans-absmn<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n, m, k;

main(){
	int i,j;
	while(cin >> n >> m >> k, n){
		double ans = 0;
		if(n == 1){
			for(int i=1;i<=m;i++) ans += max(1, i-k) / (double)m;
		}else{
			vector<double> prob(n*m+1);
			prob[0] = 1.0;
			REP(i, n){
				vector<double> next(n*m+1);
				for(int j=0;j<=n*m;j++) for(int k=1;k<=m&&k+j<=n*m;k++) next[k+j] += prob[j] / double(m);
				prob = next;
			}
			REP(i, n*m+1) ans += max(1, i-k)*prob[i];
		}
		printf("%.9f\n", ans);
	}
	return 0;
}

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

int main(){
	long long int max[200000] = {}, a[200000] = {}, maxw = 1, b[200000] = {}, maxt = -1000000000;
	int n;
	cin >> n;

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

	for (int j = 0; j < n; j++){
		b[n-j-1] = a[j];
	}
	for (int l = 0; l < n; l++){
		if (maxw < b[l]){
			maxw = b[l];
		}
		max[n-l-1] = maxw;
	}

	for (int k = 0; k < n-1; k++){
		if (max[n-k-1]-a[n-k-2] > maxt) maxt = max[n-k-1]-a[n-k-2];
	}

	cout << maxt << "\n";

	return 0;
}


Measured memory_bytes: 7808