akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include <assert.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
#include <climits>
using namespace std;
typedef unsigned long long ull;
#define ll long long int
ll mod = 1000000007;
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;


int main() {
	ll n;
	string s;
	vector<string> news;
	char a, b, c, d, e, f, g, h, i, j;
	cin >> n;
	for (int i = 0; i < n; i++) {
		vector<char> vec;
		cin >> s;
		for (int i = 0; i < 10; i++) {
			vec.push_back(s[i]);
		}
		sort(vec.begin(), vec.end());
		for (int i = 0; i < 10; i++) {
			s[i] = vec[i];
		}
		news.push_back(s);
	}
	sort(news.begin(), news.end());
	ll count = 1,y=0;
	for (int i = 1; i < news.size(); i++) {
		if (news[i] == news[i - 1]) {
			count++;
		}
		else {
			if (count != 1) {
				y += count * (count - 1) / 2;
			}
			count = 1;
		}
	}
	if (count != 1) {
		y += count * (count - 1) / 2;
	}
	cout << y << endl;
	return 0;
}

Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if((A + B) > (C + D))
  {
    cout << "Left" << endl;
  }
  else if((A + B) == (C + D))
  {
    cout << "Balanced" << endl;
  }
  else
  {
    cout << "Right" << endl;
  }
  
  
}

Measured memory_bytes: 256
import math

l = input().split()

if l[0] == 'H':
    if l[1] == 'H':
        result = 'H'
    else:
        result = 'D'
else:
    if l[1] == 'H':
        result = 'D'
    else:
        result = 'H'

print(result)




Measured memory_bytes: 2940
import sys
x,n=map(int,input().split())
p=set(list(map(int,input().split())))
for i in range(100):
    if x-i in p:
        if x+i in p:

            continue
        else:
            print(x+i)
            sys.exit()
    else:
        print(x-i)
        sys.exit()

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

ll dp[101][3][3]{};
ll mod = 10000;

void init(int a, int b) {
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (a == -1 && b == -1) {
                dp[1][i][j] = 1;
            } else if (a != -1 && b != -1) {
                dp[1][a][b] = 1;
                return;
            } else if (a == -1 && b != -1) {
                dp[1][i][b] = 1;
            } else if (a != -1 && b == -1) {
                dp[1][a][j] = 1;
            }
        }
    }
}

// d日目にa, d+1日目にb
void solve(int d, int a, int b) {
    if (a == -1 && b == -1) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    if (i == j && i == k) continue;
                    dp[d][i][j] += dp[d - 1][k][i];
                    dp[d][i][j] %= mod;
                }
            }
        }
    } else if (a != -1 && b != -1) {
        for (int i = 0; i < 3; i++) {
            if (i == a && a == b) continue;
            dp[d][a][b] += dp[d - 1][i][a];
            dp[d][a][b] %= mod;
        }
    } else if (a == -1 && b != -1) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (b == i && i == j) continue;
                dp[d][i][b] += dp[d - 1][j][i];
                dp[d][i][b] %= mod;
            }
        }
    } else if (a != -1 && b == -1) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (a == i && i == j) continue;
                dp[d][a][i] += dp[d - 1][j][a];
                dp[d][a][i] %= mod;
            }
        }
    }
}

int main() {
    int N, K;
    cin >> N >> K;
    int A[N], B[N];
    int C[N + 1];
    fill(C, C + N + 1, -1);
    for (int i = 0; i < K; i++) {
        cin >> A[i] >> B[i];
        B[i]--;
        C[A[i]] = B[i];
    }
    
    // dp[i][j][k] i日目にj、i+1日目にkの個数
    init(C[1], C[2]);
    for (int i = 2; i < N; i++) {
        solve(i, C[i], C[i + 1]);
    }
    ll ans = 0;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            ans += dp[N - 1][i][j];
        }
    }
    cout << ans % mod << "\n";
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
char k[10010];
int d,l,ans;
int g[10010][105];

int lmod(int r){
	if(r<0) r+=d;
	r%=d;
	return r;
}

void dfs(int t,int f){
	if(t>l){
		if(f==0) ans++,ans%=mod;
		return;
	}
	for(int i=0;i<k[t]-'0';i++){
		ans+=g[l-t][lmod(d-f-i)];
		ans%=mod;
	}
	dfs(t+1,(f+k[t]-'0')%d);
}

int main(){
	scanf("%s",k+1);
	scanf("%d",&d);
	l=strlen(k+1);
	g[0][0]=1;
	for(int i=0;i<=9;i++) g[1][i%d]++;
	for(int i=2;i<=10000;i++){
		for(int j=0;j<=9;j++){
			for(int k=0;k<d;k++){
				g[i][(k+j)%d]+=g[i-1][k];
				g[i][(k+j)%d]%=mod;
			}
		}
	}
	dfs(1,0);
	if(ans<1) ans+=mod;
	cout<<ans-1<<endl;
	
	return 0;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define    fios ios_base::sync_with_stdio(false); cin.tie(0);
#define    sf(x) scanf("%d",&x)
#define    sfl(x) scanf("%lld",&x)
#define    pf(x) printf("%d\n",x)
#define    pfl(x) printf("%lld\n",x)
#define    ll long long
#define    nl "\n"
#define    PB(x) push_back(x)
#define    For(i,n) for(int i=0; i<n; i++)
#define    PI acos(-1)
using namespace std;


int main()
{
  int a,b;
  
  cin>>a>>b;
  
  cout<<a*b<<nl;
  

    return 0;
}


Measured memory_bytes: 3544
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap, VecDeque};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;
#[allow(dead_code)]
const MOD: i32 = 1000_000_007;
#[allow(dead_code)]
const MODLL: i64 = 1000_000_007;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let s: String = sc.read();
    let s: Vec<char> = s.chars().collect();
    println!("{}", s.iter().fold(0, |a, c| a + if *c == '1' { 1 } else { 0} ));
}

Measured memory_bytes: 4352
import math
n = int(input())
sum = 0
for i in range(1,n+1):
    for j in range(i+1,n+1):
        for k in range(j+1,n+1):
            sum += math.gcd(math.gcd(k,j), i)
sum = sum * 6
sum_2 = 0
for i in range(1,n+1):
    for j in range(i+1,n+1):
         sum_2 += math.gcd(i,j)
     
sum_2= sum_2*3*2
sum_3 = n*(n+1)/2

sum= sum + sum_2+ sum_3
print(int(sum))

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

using std::ios_base;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using std::fixed;

using std::vector;
using std::string;
using std::stack;
using std::queue;
using std::deque;
using std::map;
using std::set;
using std::unordered_map;
using std::unordered_set;

using std::tuple;
using std::make_tuple;
using std::pair;
using std::make_pair;

using std::sort;
using std::reverse;
using std::nth_element;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()

const int MAXN = 100000;
const int INF = 1e9;
const int MOD = 1e9+7;
const int64_t L_INF = 4e18;

int a, b;
char field[100][100];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;

    cin >> a >> b;
    a--;
    for (int i = 1; i < 100 && a != 0; i += 2) {
        for (int j = 1; j < 100 && a != 0; j += 2) {
            field[i][j] = '.';
            a--;
        }
    }

    b--;
    for (int i = 0; i < 50; i++) {
        for (int j = 0; j < 100; j++) {
            if (field[i][j] != '.') {
                field[i][j] = '#';
            }
        }
    }

    for (int i = 98; i > 50 && b != 0; i -= 2) {
        for (int j = 1; j < 100 && b != 0; j += 2) {
            field[i][j] = '#';
            b--;
        }
    }
    for (int i = 50; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            if (field[i][j] != '#') {
                field[i][j] = '.';
            }
        }
    }

    cout << 100 << ' ' << 100 << '\n';
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            cout << field[i][j];
        }
        cout << '\n';
    }

    #ifdef LOCAL
        cerr << "\n== " << 1.0 * clock() / CLOCKS_PER_SEC << " sec.\n";
    #endif
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int a, b,c; cin >> a >>b>>c;
	if (a == b)cout << c;
	if (a == c)cout << b;
	if (c == b)cout << a;
	


	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,(n)-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n in O(log(n)) time

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
int N;
int a[3010];
/**********************************/


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) cin >> a[i];
    lng ans = 0;
    REP(i, N) {
        ans += a[i] - 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
/*Allah Vorosha*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define n_p next_permutation
#define p_p prev_permutation
#define in insert
#define rev reverse
#define pf push_front
#define pob pop_back
#define uniq(v)         v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define all(x) (x).begin(),(x).end()
#define pof pop_front
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define scn scanf
#define prt printf
#define rep(i, a, n) for(int i = a; i < n; i++)
#define mod 1000000007
#define yes cout << "YES\n"
#define no cout << "NO\n";
#define take for(auto &it : a) cin >> it;
#define out cout << a << "\n";
#define l_b lower_bound
#define u_b upper_bound
#define Max 100005
template<typename T> T mymax(T x, T y) {
    return (x > y ? x : y);
}

using namespace std;

const int N = 2e5 + 5;
int n;
vector<int> a;
int dp[N][3];

int myfucn(int i, int t) {
    if(i >= n) return 0;
    if(dp[i][t] != -1) return dp[i][t];
    int ret;
    if(t) {
        ret = myfucn(i + 1, 0);
        ret = min(ret, myfucn(i + 2, 0));
    }
    else {
        ret = myfucn(i + 1, 1) + (a[i] == 1);
        int o = 0;
        if(i + 1 < n) o = a[i + 1];
        ret = min(ret, myfucn(i + 2, 1) + (a[i] == 1) + o);
    }
    dp[i][t] = ret;
    return ret;
}
void solve() {
    scanf("%d", &n);
    a.resize(n);
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    ll ans = 0;
    for(int i = 1; i < n; i++) {
        if(a[i] < a[i - 1]) {
            ans += ((ll)a[i - 1] - a[i]);
            a[i] = a[i - 1];
        }
    }
    printf("%lld\n", ans);
    return;
}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 3880
def main():
    n = int(input())
    inlis = list(map(int, input().split()))

    tmp = 0
    ans = 0
    goukei = sum(inlis)
    while goukei > 0:
        for i in range(n):
            if inlis[i] > 0:
                #print(inlis)
                inlis[i] -= 1
                tmp += 1
                ans += 1
            else:
                if tmp > 0:
                    ans -= tmp - 1
                    tmp = 0
        if tmp > 0:
            ans -= tmp - 1
            tmp = 0
        goukei = sum(inlis)
        #print(ans, inlis, tmp)
        

    print(ans)

            



if __name__ == "__main__":
    main()

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

bool is_prime(int k)
{
    for(int j=2;j*j<=k;j++){
        if(k%j==0) {
            return false;
        }
    }
    return true;
}

int main()
{
    stringstream ss;
    // 入力
    int N;
    cin>>N;

    for(int i=0;i<=N/7;i++){
        if((N-7*i)%4==0){
            cout<<"Yes"<<endl;
            return 0;
            
        }
    }

    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N = int(input())
A = list(map(int, input().split()))

for a in A:
    if a % 2 == 0:
        if not (a % 3 == 0 or a % 5 == 0):
            print("DENIED")
            break
else:
    print("APPROVED")


Measured memory_bytes: 9376
use proconio::input;

fn main() {
    input! {
        n: usize,
        x: usize,
        mut a: [usize; n],
    }

    let mut clipping = 0;

    for i in 1..n {
        if a[i - 1] + a[i] > x {
            let must_remove = (a[i - 1] + a[i]) - x;
            if a[i] > must_remove {
                a[i] -= must_remove;
            } else {
                a[i] = 0;
            }
            clipping += must_remove;
        }
    }

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


Measured memory_bytes: 3764
#include<iostream>
#include<queue>
#include<map>
#define LEN 100
#define BASE 25

using namespace std;

int maps[LEN][LEN];
int off[LEN][LEN];

int checker[4];
int ncheck[4];

map<int, int> points[LEN];

class State {
public:
	char where;
	int enemy;
	int budget;
	int check[4];
	State() {check[0]=0;check[1]=0;check[2]=0;check[3]=0;}
	State(char w, int e, int b ) {
		where = w;
		enemy = e;
		budget = b; 
		check[0] = ncheck[0];
		check[1] = ncheck[1];
		check[2] = ncheck[2];
		check[3] = ncheck[3];
	}
};

inline bool operator< ( const State& a, const State& b) {
	return a.enemy < b.enemy;
}

inline bool operator> ( const State& a, const State& b) {
	return a.enemy > b.enemy;
}

priority_queue<State, vector<State>, greater<State> > status;

inline void copy ( State now ) {
	checker[0] = now.check[0];
	checker[1] = now.check[1];
	checker[2] = now.check[2];
	checker[3] = now.check[3];
}

inline void ncopy ( ) {
	ncheck[0] = checker[0];
	ncheck[1] = checker[1];
	ncheck[2] = checker[2];
	ncheck[3] = checker[3];
}

inline bool check ( int i ) {
	return 0 == ((1<<(i%25)) & checker[i/BASE]);
}

inline void add ( int i ) {
	ncheck[i/BASE] = ((1<<(i%25)) | checker[i/BASE]);
}

inline void insert ( int i, int e, int b ) {
	
	map<int,int>::iterator itr = points[i].find(e);
	if ( itr == points[i].end() ) {
		points[i][e] = b;
		status.push(State(i,e,b));
	} else if ( (*itr).second < b ) {
		(*itr).second = b;
		status.push(State(i,e,b));
	}
}

int main () {


	while ( true ) {
		int n,m,l;
		cin >> n >> m >> l;

		if ( n == 0 )
			break;

		for ( int i=0; i<n; i++ ) {
			for ( int j=0; j<n; j++ ) {
				maps[i][j] = -1;
				off[i][j] = 0;
			}
			points[i].clear();
		}

		for ( int i=0; i<m; i++ ) {
			int a,b,d,e;
			cin >> a >> b >> d >> e;

			maps[a-1][b-1] = maps[b-1][a-1] = d;
			off[a-1][b-1] = off[b-1][a-1] = e;
		}

		for ( int i=0; i<4; i++ ) {
			ncheck[i] = 0;
			checker[i] = 0;
		}

		priority_queue<State, vector<State>, greater<State> > empty;
		status = empty;

		ncheck[0] = 1;
		status.push(State(0,0,l));
		int count = 0;
		while(!status.empty()) {
			State now = status.top();
			status.pop();
			if ( now.where == n-1 ) {
				cout << now.enemy << endl;
				break;
			}

			copy(now);

			for ( int i=0; i<n; i++ ) {
				if ( maps[now.where][i] > 0 ) {
					if ( check( i ) ) {
						ncopy();
						add(i);
						int e, b;
						if ( off[now.where][i] == 0 ) {
							e = now.enemy;
							b = now.budget;
							insert(i,e,b);
						} else {
							if ( now.budget - maps[now.where][i] >= 0 ) {
								e = now.enemy;
								b = now.budget - maps[now.where][i];
								insert(i,e,b);
							}
							e = now.enemy + off[now.where][i];
							b = now.budget;
							insert(i,e,b);
						}
					}
				}
			}
		}
	}
}

		

Measured memory_bytes: 2580
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<vector<int>> vec(2,vector<int>(N));
for (int i = 0;i < 2;i++) {
  for (int j = 0;j < N;j++) cin >> vec.at(i).at(j);
}
int maxi = -1;
for (int i = 0;i < N;i++) {
  int cnt = 0;
  for (int j = 0;j <= i;j++) cnt += vec.at(0).at(j);
  
  for (int j = i;j < N;j++) cnt += vec.at(1).at(j);

  if (cnt > maxi) maxi = cnt;
}
cout << maxi << endl;


return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

signed main(){
    int d;
    while(cin>>d&&d){
        int n,m;
        cin>>n>>m;
        vector<int> v(n,0);
        rep(i,n-1){
            cin>>v[i];
        }
        sort(all(v));
        rep(i,n){
            v.pb(v[i]+d);
        }
        
        int sum = 0;
        rep(i,m){
            int p;
            cin>>p;
            
            auto it = lower_bound(all(v),p);
            int r = *it;
            int l = *prev(it);
            sum += min(abs(r-p),abs(l-p));
        }
        cout<<sum<<endl;
    }
}



Measured memory_bytes: 4472
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>

#define REP(i,n) for(int i=0; i<n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
 
#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9

using namespace std;
typedef long long ll;

int main(){
	int r;
	cin >> r;
	if (r<1200){
		cout << "ABC" << endl;
	}else if (r<2800){
		cout << "ARC" << endl;
	}else{
		cout << "AGC" << endl;
	}
	return 0;
}


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

typedef long long ll;
const int N = 100005;
const int M = 1000000007;

int n, l, q;
int a[N];
int nxt[20][N];

int main() {
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    scanf("%d%d", &l, &q);
    for (int i = 1, j = 1; i <= n; i++) {
      while (j <= n && a[j] - a[i] <= l) { j++; }
      nxt[0][i] = j - 1;
    }
    for (int i = 1; i < 20; i++) {
      for (int j = 1; j <= n; j++) {
        nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
      }
    }
    for (int i = 0, x, y; i < q; i++) {
      scanf("%d%d", &x, &y);
      if (x == y) { puts("0"); continue; }
      if (x > y) { swap(x, y); }
      int ans = 1;
      for (int i = 19; i >= 0; i--) {
        if (nxt[i][x] < y) { ans += 1 << i; x = nxt[i][x]; }
      }
      printf("%d\n", ans);
    }
  }
}


Measured memory_bytes: 8960
n,k=list(map(int, input().split()))
a= list(map(int, input().split()))
final=min(a)
ans=0
flag=-1
check=0
for v in a:
    if flag==-1 and v!=final:
        flag=2
        ans+=1
        check=0
        if flag==k:
            flag=-1
    elif flag>=0:
        if check==0 and v==final:
            flag-=1
            check=1
        flag+=1
        if flag==k:
            flag=-1
print(ans)

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

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

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

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

/*------------------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}
void solve() {
    const vll dy = { -1, -1, -1, 0, 1, 1, 1, 0 }, dx = { -1, 0, 1, 1, 1, 0, -1, -1 };

    while (true) {
        ll w, h; std::cin >> w >> h;

        if (w == 0 && h == 0) break;

        vvll g(h, vll(w));
        for (ll i = 0; i < h; i++) for (ll j = 0; j < w; j++)
            std::cin >> g[i][j];

        vvll flg(h, vll(w, 0));

        auto bfs = [&](ll sy, ll sx) -> void {
            flg[sy][sx]++;
            std::queue<pll> que; que.push({ sy, sx });

            while (!que.empty()) {
                pll p = que.front(); que.pop();
                ll cy = p.first, cx = p.second;
                for (ll i = 0; i < 8; i++) {
                    ll ny = cy + dy[i], nx = cx + dx[i];
                    if (0 <= ny && ny < h && 0 <= nx && nx < w
                        && g[ny][nx] && !flg[ny][nx]) {
                        flg[ny][nx]++;
                        que.push({ ny, nx });
                    }
                }
            }
        };

        ll ans = 0;
        for (ll i = 0; i < h; i++) for (ll j = 0; j < w; j++)
            if (g[i][j] && !flg[i][j]) {
                ans++; bfs(i, j);
            }

        std::cout << ans << '\n';
    }
}



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

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

    ll n, k; cin >> n >> k;
    vector<pair<int, int>> op;
    for (int i = 0; i < n; ++i) {
        int a, b; cin >> a >> b;
        op.push_back(make_pair(a, b));
    }

    sort(op.begin(), op.end());

    ll pos = 0;
    for (auto i : op) {
        pos += i.second;
        if (pos >= k) {
            cout << i.first << endl;
            return 0;
        }
    }
}

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

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

  if(S == "Sunny") cout << "Cloudy" << endl;
  else if(S == "Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
  
}

Measured memory_bytes: 3564
/*Ankon Ghosh
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
///#include <ext/pb_ds/detail/standard_policies.hpp>*/
///using namespace __gnu_pbds;
using namespace std;
using ll=long long;
#define inf 1e16
#define MAX 100005
#define mod 998244353
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) printf("Case %lld: ",i)
#define setpre(number) cout<<fixed<<setprecision(10)<<number<<endl
#define pf(a) printf("%lld ",a)
#define pff(a,b) printf("%lld %lld\n",a,b)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll i=x;i<=y;i++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p make_pair
#define ff first
#define ss second
#define p_b push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define output freopen("output.txt","w",stdout)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vpp1;
vector<pair<ll,ll> >vpp,vp1;
vector<ll>v,v1,v2,fin;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb,mb1;
ll a,b,c,n,d,e,f,ta,sum=0,cnt=0,m,l,req,sz,maxi,k;
priority_queue<ll>pq;

int main()
{
    fast;
    cin>>n;
    v.clear();
    FOR(i,n)
    {
        cin>>a;
        v.p_b(a);
    }
    ll now=0,ans=0;
    for(ll i=0;i<n;i++)
    {
        if(v[i]>now)
        {
            ans+=(v[i]-now);
            now=v[i];
        }
        else
        {
            now=v[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
vector<P> graph[100100];
int main()
{
	int n;
	cin >> n;
	rep(i,n-1){
		int a, b, w;
		cin >> a >> b >> w;
		--a, --b;
		graph[a].push_back({b,w});
		graph[b].push_back({a,w});
	}
	// 0 を黒にするって決めちゃえば後は自然に全部決まりそう
	vector<int> ans(n,-1);
	ans[0] = 0;
	vector<bool> seen(n,false);
	seen[0] = true;

	queue<int> que;
	que.push(0);
	while(!que.empty()){
		int p = que.front();
		que.pop();
		// p からいけるところ全部
		for(auto x : graph[p]){
			if(seen[x.first]) continue;
			// ans[p] が 0 のとき
			if(ans[p] == 0){
				// sedcond が 偶数ならok
				if(x.second % 2 == 0){
					ans[x.first] = 0;
				} else {
					ans[x.first] = 1;
				}
			} else {
				if(x.second % 2 == 1){
					ans[x.first] = 0;
				} else {
					ans[x.first] = 1;
				}
			}
			seen[x.first] = true;
			que.push(x.first);
		}
	} 
	rep(i,n){
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 9584
#include <stdio.h>
#include <string.h>
#define MN 100005
int ls,lt,cs[MN][2],ct[MN][2];
char s[MN],t[MN];
int main(){
	scanf("%s%s",s+1,t+1);
	ls=strlen(s+1),lt=strlen(t+1);
	for(int i=1;i<=ls;i++) {
		cs[i][0]=cs[i-1][0];
		cs[i][1]=cs[i-1][1];
		if(s[i]=='A')cs[i][0]++;
		if(s[i]=='B')cs[i][1]++;
	}
	for(int i=1;i<=lt;i++) {
		ct[i][0]=ct[i-1][0];
		ct[i][1]=ct[i-1][1];
		if(t[i]=='A')ct[i][0]++;
		if(t[i]=='B')ct[i][1]++;
	}
	int q; scanf("%d",&q);
	while(q--){
		int a,b,c,d,ps[2],pt[2],ex[2];
		scanf("%d%d%d%d",&a,&b,&c,&d);
		ps[0]=(cs[b][0]-cs[a-1][0])%3;
		ps[1]=(cs[b][1]-cs[a-1][1])%3;
		pt[0]=(ct[d][0]-ct[c-1][0])%3;
		pt[1]=(ct[d][1]-ct[c-1][1])%3;
		ex[0]=(pt[0]-ps[0]+3)%3;
		ex[1]=(pt[1]-ps[1]+ex[0]*2+3)%3;
		if(ex[1]==0)puts("YES");
		else puts("NO");
	}
}

Measured memory_bytes: 2304
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
        int a;
        cin >> a;
        int piv = a;
        int sum = 0;
        a = a * 2;
        int *listing = new int [a];
        for(int i = 0; i < a; i++){
                cin >> listing[i];
        }
        sort(listing,listing + a);
        for(int i = 0; i < piv; i++){
                sum = sum + listing[i*2];
        }
        cout << sum << "\n";
        return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);

    String s = stdIn.next();

    switch(s) {
      case "Sunny" :
      System.out.println("Cloudy");
      break;
      case "Cloudy" :
      System.out.println("Rainy");
      break;
      case "Rainy" :
      System.out.println("Sunny");
      break;
    }
  }
}


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

struct Edge {int from, to, weight;};
using Graph = vector<vector<Edge>>;

int D, N;
string TEXT;
vector<string> PIECE;

set<string> OK;

string text;

int DP[45][45];

bool Levenshtein(auto b, auto e) {
  for(auto j = b; j <= e; ++j) {
    int d = D + 1;
    for(auto i = 1; i <= TEXT.size(); ++i) {
      if(TEXT[i-1] == text[j-1]) DP[i][j] = DP[i-1][j-1];
      else                       DP[i][j] = 1 + min({DP[i-1][j], DP[i][j-1], DP[i-1][j-1]});
      d = min(d, DP[i][j]);
    }
    if(D < d) return false;
  }
  return true;
}

void dfs(const auto& G, auto& used, auto cur) {
  if(TEXT.size() + D < text.size()) return;

  if(!Levenshtein(text.size() - PIECE[cur].size() + 1, text.size())) return;

  if(used.count(text)) return;
  used.emplace(text);

  if(DP[TEXT.size()][text.size()] <= D) OK.emplace(text);

  auto dup = text;
  for(auto e: G[cur]) {
    text = dup + PIECE[e.to].substr(e.weight);
    dfs(G, used, e.to);
    text = dup;
  }
}

void solve() {
  Graph G(N);
  for(auto i = 0; i < N; ++i) for(auto j = 0; j < N; ++j) {
    auto lhs = PIECE[i];
    auto rhs = PIECE[j];
    for(auto k = 0; k < lhs.size(); ++k) if(lhs.substr(lhs.size() - k) == rhs.substr(0, k)) G[i].push_back({i, j, k});
  }
 
  unordered_set<string> used;
  for(auto i = 0; i < N; ++i) {
    text = PIECE[i];
    dfs(G, used, i);
  }
}

int main() {
  for(auto i = 0; i < 45; ++i) DP[i][0] = DP[0][i] = i;

  while(cin >> D >> N, D | N) {
    cin >> TEXT;
    PIECE = vector<string>(N);
    for(auto& i: PIECE) cin >> i;
 
    sort(begin(PIECE), end(PIECE));
    PIECE.erase(unique(begin(PIECE), end(PIECE)), end(PIECE));
    N = PIECE.size();
 
    OK.clear();
    solve();
    cout << OK.size() << endl;
    if(OK.size() <= 5) for(auto i: OK) cout << i << endl;
  }
}

Measured memory_bytes: 26228
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 97;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T >, rb_tree_tag, tree_order_statistics_node_update >;

//typedef uint64_t hash_t;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//const int HASH_COUNT = 2;
//const hash_t HASH_P = (uint32_t)-13337;
//uniform_int_distribution<hash_t> MULT_DIST(0.25 * HASH_P, 0.75 * HASH_P);
//const hash_t HASH_MULT[HASH_COUNT] = {MULT_DIST(rng), MULT_DIST(rng)};

int main(){
  int a, b;
  fastScan(a);
  fastScan(b);
  printf("%d\n", a * b);
}


Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
    int n, q, l, r;
    string s;

    cin >> n >> q >> s;
    vector<int> data(n+1, 0);
    for(int i = 1; i < n; i++){
        if(s[i-1] == 'A' && s[i] == 'C'){
            data[i] += 1;
        }
        data[i] += data[i-1]; 
    }
    data[n] += data[n-1]; 

    for(int i = 0; i < q; i++){
        scanf("%d%d", &l, &r);
        printf("%d\n", data[r-1] - data[l-1]);
    }

    return 0;
}

Measured memory_bytes: 1408
def bfs(dp, arr, i,  visited):
	q = []
	q.append(i)
	visited[i] = True
	while q:
		i = q.pop(0)
		visited[i] = True
		for j in arr[i]:
			if dp[j] == -1:
				dp[j] = dp[i] + 1
			elif dp[i] == dp[j]:
				return -1
			
			if visited[j] == False:
				visited[j] = True
				q.append(j)
	return 0

n=int(input())
i=0
arr=[]
degree = [0]*n
while i<n:
	s=input()
	a=[]
	for j,e in enumerate(s):
		if e=='1':
			a.append(j)
			degree[i]+=1
	arr.append(a)	
	i+=1

res = -1
ans = -1
for i in range(n):
	dp = [-1]*n
	visited=[False for x in range(n)]
	dp[i] = 1
	res=bfs(dp, arr, i, visited)
	if res  == 0:
		ans = max(ans , max(dp))

print(ans)

Measured memory_bytes: 3444
#include<iostream>
using namespace std;
int main(){
	int i,j,n,a[100],A,B,ans;
	A=0;
	B=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(a[i]>a[j])
				swap(a[i],a[j]);
		}
	}
	for(i=0;i<n;i++){
		if(i%2==0)
			A=A+a[i];
		else
			B=B+a[i];
	}
	ans=A-B;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
from itertools import product

N,M,X = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(N)]
 
DEF_VAL = 99999999
min_cost = DEF_VAL
for rows in product([True, False], repeat=N):
    cost = 0
    x = [0] * M
    for i in range(N):    
        if rows[i]:
            cost += data[i][0]
            for c in range(M):
                x[c] += data[i][c+1]
    if min(x) >= X and cost < min_cost:
        min_cost = cost

if min_cost == DEF_VAL:
    print(-1)
else:
    print(min_cost) 
       


Measured memory_bytes: 9208
#include <iostream>

using namespace std;

int main()
{
    long long int N,M;
    cin>>N>>M;
    long long int A[M];
    long long int tot=0;
if(N>=1&&M>=1&&N<=1000000&&M<=10000){
    for(int i=0;i<M;i++){
        cin>>A[i];
        if(A[i]<=10000&&A[i]>=1){
        tot+=A[i];
        }
    }
    if(tot<=N){
        cout<<N-tot;
    }
    else{
        cout<<-1;
    }
}
    return 0;
}

Measured memory_bytes: 3688
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read();
    println!("{}", 1.0 / (0..n).map(|_| 1.0 / read::<f64>()).fold(0.0, |a, b| a + b));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const int nmax = 40;
const int abmax = 10;
const int INF = 1<<29;

int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];

int main(){
    int N, Ma, Mb; cin >> N >> Ma >> Mb;
    vector<int> a(N+1), b(N+1), c(N+1);
    for(int i=1; i<=N; i++) cin >> a[i] >> b[i] >> c[i];


    for(int i=0; i<nmax+1; i++) for(int j=0; j<nmax*abmax+1; j++) for(int k=0; k<nmax*abmax+1; k++) dp[i][j][k] = INF;
    dp[0][0][0] = 0;
    
    for(int i=0; i<=N-1; i++){
        for(int j=0; j<=nmax*abmax; j++){
            for(int k=0; k<=nmax*abmax; k++){
                if(dp[i][j][k] == INF) continue; // <-これ書かないとREになる
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
                dp[i+1][j+a[i+1]][k+b[i+1]] = min(dp[i+1][j+a[i+1]][k+b[i+1]], dp[i][j][k]+c[i+1]);
            }
        }
    }

    int ans = INF;
    for(int j=1; j<=nmax*abmax; j++){
        for(int k=1; k<=nmax*abmax; k++){
            if(Ma*k == Mb*j) ans = min(ans, dp[N][j][k]);
        }
    }

    cout << ((ans == INF)? -1:ans) << endl;
}



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

int main() {
	int x, y, z, t;
	cin >> x >> y >> z;
	
	if(x > y){t = x; x = y; y = t;}
	if(y > z){t = y; y = z; z = t;}
	if(x > y){t = x; x = y; y = t;}
	
	cout << x << " " << y << " " << z << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

using namespace std;

int main() {
   int n; 
   cin >> n;
   int d[n];
   rep(i,n)
   cin >> d[i];
   int ans=0;
   rep(i,n){
      for(int j=i+1; j<n; j++){
      ans+=d[i]*d[j];
      }
   }
   cout << ans << endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << p.first << " " << p.second;return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if (it != v.begin())os << " ";os << *it;
  }return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void print(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void print(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;




int a[20][20], dp[20][20];
int dy[] = {1, 1, 1}, dx[] = {-1, 0, 1};
void init(){
	rep(i,20)rep(j,20)dp[i][j] = 0;
}

signed main(){
	while(1){
		int h, w;
		cin >> w >> h;
		if(w == 0 and h == 0)break;
		rep(i,h)rep(j,w)cin >> a[i][j];
		init();
		rep(i,w)if(a[0][i] == 0)dp[0][i] = 1;
		rep(i,h){
			rep(j,w){
				if(a[i][j] >= 1)continue;
				if(i == h-1){
					dp[i+1][j] += dp[i][j];
					continue;
				}
				rep(k,3){
					int yy = i+dy[k], xx = j+dx[k];
					if(xx < 0 or w <= xx)continue;
					while(k == 1 and a[yy][xx] == 2)yy += 2;
					if(a[yy][xx] == 2)continue;
					dp[yy][xx] += dp[i][j];
				}
			}
		}
		int ans = 0;
		repi(i,h,20)rep(j,w)ans += dp[i][j];
		cout << ans << endl;
	}
	return 0;
}







Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
const int mod = 998244353;

ll mpow(ll x, ll n) {
  ll res = 1;
  while (n) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n /= 2;
  }
  return res;
}

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  vi erat(1000001);
  for (int i = 0; i < erat.size(); ++i) erat[i] = i;
  for (int i = 2; i * i < erat.size(); ++i) if (erat[i] == i) {
    for (int j = i * i; j < erat.size(); j += i) erat[j] = i;
  }
/*  vvi d(erat.size());
  for (int i = 1; i < erat.size(); ++i) for (int j = i; j < erat.size(); j += i) d[j].push_back(i);
  vi mu(erat.size(), 1);
  for (int i = 2; i < erat.size(); ++i) {
    int p = erat[i];
    if (i / p % p == 0) mu[i] = 0;
    else mu[i] = -mu[i / p];
  }*/
  int n;
  cin >> n;
  vi a(n);
  vl c(erat.size()), s1(erat.size()), s2(erat.size());
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ++c[a[i]];
  }
  for (int i = 1; i < erat.size(); ++i) {
    for (int j = i; j < erat.size(); j += i) {
      s1[i] = (s1[i] + c[j] * j) % mod;
      s2[i] = (s2[i] + c[j] * j % mod * j) % mod;
    }
  }
  const ll inv2 = (mod + 1) / 2;
  vl v(erat.size());
  for (int i = 0; i < erat.size(); ++i) {
    v[i] = (s1[i] * s1[i] - s2[i]) % mod * inv2 % mod;
//    if (v[i]) cerr << i << ' ' << v[i] << endl;
  }
  ll res = 0;
  for (int i = (int)erat.size() - 1; i > 0; --i) {
    for (int j = 2 * i; j < erat.size(); j += i) {
      v[i] = (v[i] - v[j]) % mod;
    }
    res = (res + v[i] * mpow(i, mod - 2)) % mod;
//    if (v[i]) cerr << i << ' ' << v[i] << endl;
  }
  cout << (res % mod + mod) % mod << endl;
  return 0;
}


Measured memory_bytes: 36224
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define int ll
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
// const int MOD = 1000000007;

int A[11];
int n,m,q;
int a[51],b[51],c[51],d[51];
int ans = 0;

void dfs(int k){
	if(k == n){
		int res = 0;
		rep(i,q){
			if(A[b[i]]-A[a[i]] == c[i])res += d[i];
		}
		chmax(ans,res);
	}else{
		for(int i = A[k];i <= m;i++){
			A[k+1] = i;
			dfs(k+1);
		}
	}
	return;
}

/*----------------------------------------------------------------*/
signed main(){

	
	cin >> n>> m >> q;
	rep(i,q)cin >> a[i] >> b[i] >> c[i] >> d[i];

	A[0] = 1;
	dfs(0);
	cout << ans << endl;

	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://pakencamp-2019-day3.contest.atcoder.jp/tasks/pakencamp_2019_day3_c
// rm -r -f test;oj dl https://atcoder.jp/contests/abc164/tasks/abc164_b


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
//typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {

  ll n;
  std::cin >> n;
  vector<ll> a(n);

  ll rev_idx = -1, rev_count = 0;
  for(int i=0;i<n;i++) {
    std::cin >> a[i];
    if(a[i]!=i+1) rev_idx = i, rev_count++;
  }
  if(rev_count==0){
    std::cout << "YES" << '\n';
    return 0;
  }

  std::cout << (rev_count<=2&&a[a[rev_idx] - 1]== rev_idx+1?"YES":"NO") << '\n';
  return 0;
}


Measured memory_bytes: 256
N = int(input())

def F(A, B):
    return max(len(str(A)), len(str(B)))

ans = 1000000000
half = int((N+1)**(1/2) + 1)
for A in range(1, half):
    if N%A == 0:
        B = int(N / A)
        if F(A, B) < ans:
            ans = F(A, B)

print(ans)

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(ll)(n);i>0;i--)
#define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
#define mp make_pair


int main () {
  int n, m;
  cin >> n >> m;
  vl a(n);
  vl sum(n + 1);
  map<ll, ll> mp;
  mp[0] = 1;
  rep (i, n) {
    cin >> a[i];
    a[i] %= m;
    sum[i + 1] = (sum[i] + a[i]) % m;
    mp[sum[i + 1]]++;
  }
  ll ans = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    ll temp = itr->second;
    ans += temp * (temp - 1) / 2;
  }
  cout << ans << endl;
  
}


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

using namespace std;

int main() {
	long long int N, W, ans = 0;
	cin >> N >> W;
	map<long long int, long long int>dp;
	dp[0] = 0;
	for( size_t i = 0; i < N; i++ ) {
		long long int w, v;
		cin >> w >> v;
		auto memo = dp;
		for( auto x : memo ) {
			if( x.first + w <= W ) {
				dp[x.first + w] = max( dp[x.first + w], x.second + v );
				ans = max( ans, dp[x.first + w] );
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640