akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    int i = 0;
    rep(i, n) {
        cin >> vec[i];
    }
    sort(vec.begin(), vec.end());
    i = 0;
    rep(i, n-1) { 
        if (vec[i] == vec[i+1]) {
            cout << "NO" << endl;
            goto end;
        }
    }
    cout << "YES" << endl;
    end:
    ;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std ;
using ll = long long;

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

    ll l[Q];
    ll r[Q];
    for(int i=0; i<Q; i++){
        cin >> l[i] >> r[i];
    }

    //累積和
    ll sum[N+1] = {};
    for(int i=0; i<N; i++){
        if(i+1< N and S[i] == 'A' and S[i+1] == 'C'){
            sum[i+1] = sum[i] + 1;
        }else{
            sum[i+1] = sum[i];
        }
    }
    
    for(int i=0; i<Q; i++){
        r[i]--;
        l[i]--;
        cout << sum[r[i]]-sum[l[i]] << endl;
    }
    return 0 ;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

ll mod_mul(ll a, ll b){
    return ((a % MOD) * (b % MOD)) % MOD;
}

ll mod_pow(ll x, ll r){
    if (r == 0) return 1;

    else if (r == 1) return x % MOD;

    else if (r % 2 == 0){
        ll t = mod_pow(x, r/2) % MOD;
        return mod_mul(t, t);
    }

    else{
        ll t = mod_pow(x, r/2) % MOD;
        ll k = mod_mul(t, t);
        return (k % MOD) * (x % MOD);
    }
}

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

    ll n, tmp;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> mp;
    bool flg = false;

    rep(i, n){
        cin >> tmp;

        if(n%2){
            if(tmp%2){
                flg = true;
            }
            if(tmp==0 && mp[tmp]>0) flg = true;
            if(tmp!=0 && mp[tmp]>1) flg = true;
        }
        
        else{
            if(tmp%2){
                if(mp[tmp]>1) flg = true;
            }
            else flg = true;
        }

        if(flg){
            cout << 0 << endl;
            return 0;
        }

        ++mp[tmp];
    }

    if(n+tmp==0) cout << 1 << endl;
    else cout << mod_pow(2, n/2) << endl;

    return 0;
}

Measured memory_bytes: 4224
n,m=map(int,input().split())
if m==1:
  print("Yes")
  exit()
x=list(map(int,input().split()))

z=sum(x)
w=z/4/m
y=list(sorted(x,reverse=True))

if y[m-1]<w:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	int x = Integer.parseInt(br.readLine()); 
      	String y[] = br.readLine().split(" ");
       	int a;
      	int max = Integer.MIN_VALUE;
      	int min = Integer.MAX_VALUE;
      	long sum = 0;
      	for (int i = 0; i < x; i++) {
        	a = Integer.parseInt(y[i]);
          	if(a > max) {
            	max = a;
            }
            if(a < min) {
            	min = a;
            }
          	sum += a;
        }
      	System.out.println(min + " " + max + " " +sum);

    }
}


Measured memory_bytes: 28308
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s: String = read();
    println!("{}", s.chars().filter(|&c| c == '1').count());
}

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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 (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    string s;
    cin >> n >> s;
    map<char,ll> mp;
    for(int i = 0; i < n; i++) mp[s[i]]++;
    ll ans = 1;
    for(auto p : mp) {
        (ans *= p.second+1) %= MOD;
    }
    ans--;
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(void){
    int a,b,N,M,i,j,count,amax,bmin;
    amax = 0;
    bmin = 1000000;
    i = j = count = 0;
    int okbox[100002];
    for (i = 0; i < 100002; i++){
        okbox[i] = 0;
    }
    
    scanf("%d %d",&N,&M);

    for(i = 0; i < M ; i++){
        scanf("%d %d",&a,&b);
        if (a > amax){
            amax = a;
        }
        if (b < bmin){
            bmin = b;
        }

    }
    
    count = bmin - amax + 1;
    if (count <= 0){
        count = 0;
    }
   
    printf("%d",count);
}


Measured memory_bytes: 128
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.Graph as G
import qualified Data.ByteString.Char8 as B

readi b | Just (n, _) <- B.readInt b = n

bfs :: [G.Tree Int] -> [[Int]]
bfs [] = []
bfs ts = fmap root ts : bfs (concatMap sub ts)
  where
    root (G.Node r _)  = r
    sub  (G.Node _ sf) = sf

main :: IO ()
main = do
    [n, m] <- fmap readi . B.words <$> B.getLine :: IO [Int]
    as <- fmap ((\[a, b] -> (readi a, readi b)) . B.words) . B.lines <$> B.getContents

    let g = G.buildG (1, n) as
    let tree = G.dfs g [1]
    let bss = take 3 $ bfs tree

    if length bss < 3
        then putStrLn "IMPOSSIBLE"
        else do
            if any (== n) (bss !! 2)
                then putStrLn "POSSIBLE"
                else putStrLn "IMPOSSIBLE"

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

const int MOD=(int)1e9+7;
const int MAX=510000;

long long fac[MAX],finv[MAX],inv[MAX];

//テーブルを作る前処理
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<MAX;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

//二項係数の計算
long long 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]%MOD)%MOD;
}

int main(){
	long long N,K;
	cin >> N >> K;
	vector<long long> A(N);
	for(int i=0;i<N;i++)	cin >> A.at(i);

	sort(A.begin(),A.end());
	long long ans=0;
	COMinit();
	for(int i=0;i<N;i++){
		ans-=(A.at(i)*COM(N-i-1,K-1))%MOD;
		//cout << i << "," << COM(N-i-1,K-1) << endl;
	}
	for(int i=N-1;i>=0;i--){
		ans+=(A.at(i)*COM(i,K-1))%MOD;
	}
	cout << ans%MOD << endl;

	return 0;
}


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

using namespace std;

int main() {
  //  ifstream cin("A.in");
  //  ofstream cout("A.out");
    int a,b;
    ios::sync_with_stdio(false);
    cin >> a >> b;
    if(a <= 0 && b >= 0)
        cout << "Zero";
    else {
        if(a < 0) {
            if((b - a + 1) % 2 == 0)
               cout << "Positive";
            else
               cout << "Negative";
        }
        else
            cout << "Positive";
    }
    cout << endl;
   // cin.close();
   // cout.close();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define PB push_back
#define ar2 array<int,2>
typedef long long LL;
const LL P = 1e9+7;
const LL INF = 1e18;
const int N = 1e5+5;
mt19937 rng(time(0));

int x;

int main(){
	#ifndef ONLINE_JUDGE
	//freopen("test.in","r",stdin);
	#endif
	cin>>x;
	cout<<360/__gcd(360,x)<<endl;
	return 0;
}

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

int main(){
    int a, b;
    while(cin>>a >>b){
        if(a==0 && b==0)break;
        for(int i=0;i<a;i++){
            for(int j=0;j<b;j++){
                if((i+j)%2==0){
                    cout<<'#';
                }else{
                    cout<<'.';
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 3088
import itertools
N = list(input())
M = list(map(int, N))


def sign(a):
    if a == 0:
        return '+'
    else:
        return '-'


flag = 0
for b, c, d in itertools.product(range(2), range(2), range(2)):
    if M[1]*(-1)**b+M[2]*(-1)**c+M[3]*(-1)**d == 7-M[0]:
        b = sign(b)
        c = sign(c)
        d = sign(d)
        break

print(str(M[0])+b+str(M[1])+c+str(M[2])+d+str(M[3])+'=7')


Measured memory_bytes: 3064
//コンパイラ最適化用
#pragma GCC optimize("O3")
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

vector<ll> mincost;
vector<vector<vector<ll>>> Edges;
vector<bool> ncycle;
deque<ll> bfsrec;

//負閉路検出
void bfs(){
    ll s=SIZE(bfsrec);
    REP(i,s){
        ll now=*bfsrec.begin();
        bfsrec.pop_front();
        for(const auto& edge:Edges[now]){
            if(ncycle[edge[0]]==false){
                ncycle[edge[0]]=true;
                bfsrec.PB(edge[0]);
            }
        }
    }
    if(s)bfs();
}

bool bellmanford(ll n){
    //(l1-1)(普通のbellman)+1(検出)
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            if(mincost[j]!=INF){
                for(const auto& edge:Edges[j]){
                    ll new_mincost=mincost[j]+edge[1];
                    if(mincost[edge[0]]>new_mincost){
                        mincost[edge[0]]=new_mincost;
                        if(i==n-1){
                            ncycle[edge[0]]=true;//負の閉路があればtrue
                            bfsrec.PB(edge[0]);
                        }
                    }
                }
            }
        }
    }
    bfs();
    if(ncycle[n-1]==true)return true;
    return false;//Nを含む負の閉路がなければfalse
}


signed main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    ll n,m,p;cin>>n>>m>>p;
    mincost.resize(n);mincost[0]=0;
    FOR(i,1,n-1)mincost[i]=INF;
    Edges.resize(n);
    ncycle.resize(n);
    REP(i,n)ncycle[i]=false;
    //コストをpでマイナスしてそれを符号逆に
    REP(i,m){
        ll a,b,c;cin>>a>>b>>c;
        Edges[a-1].PB({b-1,p-c});
        //cout<<p-c<<endl;
    }
    //このもとでの最小を考える
    bool check=bellmanford(n);
    if(check or mincost[n-1]==INF){
        cout<<-1<<endl;
    }else{
        cout<<max(-mincost[n-1],ll(0))<<endl;
    }
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int x = max(a,b);
  int y = min(a,b);
  if(y <= c && c <= x) puts("Yes");
  else puts("No");
  return 0;
}


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

if a + b <= n:
    if a >= b:
        max = b
        min = 0
    else:
        max = a
        min = 0

else:
    if a >= b:
        max = b
        min = a + b - n
    else:
        max = a
        min = a + b - n

print(max, "", min)


Measured memory_bytes: 3060
import java.util.*;
class Main{
	Scanner sc=new Scanner(System.in);
	double x,h;
	void q(){
		while(true){
			x=sc.nextDouble();
			h=sc.nextDouble();
			if(x==0&&h==0)break;
		
		
			double s=x*x+x*Math.sqrt(x*x+h*h*4.0);
			System.out.println(s);
			
		}
	}
	public static void main(String[]agrs){
		new Main().q();
	}
}
		

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

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

  int sum = 0;
  vector<int> s(n);
  rep(i, n) {
    cin >> s[i];
    sum += s[i];
  }

  int m;
  cin >> m;
  vector<pair<int,int>> t(m);

  rep(i, m) {
    int p, x;
    cin >> p >> x;
    t[i].first = p;
    t[i].second = x;
  }

  rep(i, m) {
    cout << sum - s[t[i].first-1] + t[i].second << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
int n,k,a[200005];
int main() {
	cin>>k>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	a[n+1]=a[1]+k;
	int maxx=0;
	for(int i=2;i<=n+1;i++)maxx=max(maxx,a[i]-a[i-1]);
	cout<<k-maxx;
}


Measured memory_bytes: 1024
import copy
s = list(input())
def make1d(n):
    return [copy.deepcopy(1) for i in range(0,n)]
t = make1d(26)
for i in range(0, len(s)):
    t[ord(s[i]) - 97] = t[ord(s[i]) - 97] * (-1)
u = 0
for i in range(0, len(t)):
    u = u + t[i]
if u == 26:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 998244353
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;


int main(){

    int n;
    cin >> n;

    vector<ll> a;
    ll suml = 0;

    rep(i,n){
        ll tmp;
        cin >> tmp;
        a.pback(tmp);

        suml += tmp;
    }

    ll ans = LLONG_MAX;
    ll tmpl = 0;
    

    rep(i, n - 1){
        tmpl += a[i];

        ans = min(ans, abs(tmpl - (suml - tmpl)));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,A,B,C,D;
  cin>>N>>A>>B>>C>>D;
  A=N/1000;
  int E=A*1000;
  B=(N-E)/100;
  int F=B*100;
  C=(N-E-F)/10;
  int G=C*10;
  D=N-E-F-G;
  if((A==B&&B==C)||(B==C&&C==D)){
    cout<<"Yes"<<endl;}
  else{
    cout<<"No"<<endl;}
}





Measured memory_bytes: 256
'use strict';

function Main(input) {
    const tmp = input.split(" ").map(n => Number(n));
    tmp.sort((a, b) => {
        if (a > b) return -1;
        if (a < b) return 1;
        return 0;
    });
    console.log(tmp[0] * 10 + tmp[1] + tmp[2]);
}
//* この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
long long  h[110000];
long long dp[110000];//dp[i]:= i番目に行くのに必要なコストの最小値
int main()

{   int n,k;
    cin >> n >> k;
    h[0] = 0;
    rep(i,n){
        cin >> h[i+1];
    }
    dp[0] = 0;
    dp[1] = 0;
    for(int i = 2;i <= n;i++){
        dp[i] = 10000000000;
    }
    for(int i = 1;i <= n; i++){
        for(int j = 1;j < k+1;j++){
            if (i+j >n) continue;
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
        }

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

 

    return 0;
}

Measured memory_bytes: 1792
S = int(input())
X1, Y1, X2, Y2 = 0, 0, 10**9, 1
shou, amari = divmod(S, 10**9)
 
if amari == 0:
    Y3 = shou
    X3 = 0
else:
    Y3 = shou + 1
    X3 = -(amari - 10**9)
 
print(X1, Y1, X2, Y2, X3, Y3)

Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<utility>
#include<algorithm>
using namespace std;
bool cmp(pair<int,int> a,pair<int,int> b)
{
	if(a.second!=b.second)
	return a.second<b.second;
	return a.first<b.first;
}
int main()
{
	long int n;
	cin>>n;
	if(n%2==0)
		cout<<n;
	else
		cout<<2*n;
}

Measured memory_bytes: 764
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>


using namespace std;

int main() {
	int bingo[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> bingo[i][j];
		}
	}
	int N;
	cin >> N;
	vector<int>num(N);
	for (int i = 0; i < N; i++) {
		cin >> num[i];
	}
	vector<int>tate(3);
	vector<int>yoko(3);
	vector<int>naname(2);
	for (int x = 0; x < N; x++) {
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (num[x] == bingo[i][j]) {
					tate[j]++;
					yoko[i]++;
					if (i == j) {
						naname[0]++;
						if (i == 1)naname[1]++;
					}
					if (abs(i - j) == 2)naname[1]++;
				}
			}
		}
	}
	bool ok = true;
	if (find(tate.begin(), tate.end(), 3) == tate.end()) {
		if (find(yoko.begin(), yoko.end(), 3) == yoko.end()) {
			if (naname[0] != 3 && naname[1] != 3)ok = false;
		}
	}
	if (ok)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
H = list(map(int, input().split()))

ans = 0
cnt = 0
for i in range(1, len(H)):
    if H[i] <= H[i-1]:
        cnt += 1
    else:
        ans = max(ans, cnt)
        cnt = 0
        continue
ans = max(ans, cnt)
print(ans)



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

typedef long long ll;
int n;
ll a[19];
ll f(int l, int r, ll xl, ll xr) {
  if (r - l == 1) return a[l] * xl + a[r] * xr;
  ll ans = 1ll << 60;
  for (int i = l + 1; i < r; i++) {
    ans = min(ans, f(l, i, xl, xl + xr) + f(i, r, xl + xr, xr) - (xl + xr) * a[i]);
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  printf("%lld\n", f(1, n, 1, 1));
}


Measured memory_bytes: 256
n , m = map(int, input().split())
ac = set()
cb = set()
for i in range(m):
    a , b = map(int, input().split())
    if a == 1:
        ac.add(b)
    if b == n:
        cb.add(a)
if len(ac & cb)>=1:
    print("POSSIBLE")
else:
    print('IMPOSSIBLE')


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

int N,Q;
vector<ll> t;
map< ll , ll > mp[100005];

int main(){
  cin>>N>>Q;
  t.push_back(N);
  for(int i=0;i<Q;i++){
    ll x;
    cin>>x;
    while(!t.empty()&&t.back()>=x)t.pop_back();
    t.push_back(x);
  }

  mp[t.size()-1][ t.back() ]=1;

  for(int i=(int)t.size()-1;i>=1;i--){
    for( pair<ll,ll> p : mp[i] ){
      ll fi=p.first;
      ll se=p.second;

      ll v = fi / t[i-1];
      ll w = fi % t[i-1];
      
      if(v>0){
        mp[i-1][ t[i-1] ]+=v*se;
      }

      if(w>0){
        int target=lower_bound( t.begin(), t.end() , w) - t.begin();
        assert( target < i );
        mp[ target ][ w ]+=se;
      }
    }
  }

  vector<ll> ans(N+5);

  for( pair<ll,ll> p : mp[0] ){
    ans[ p.first ] += p.second;
  }
  for(int i=N;i>=1;i--)ans[i]+=ans[i+1];
  for(int i=1;i<=N;i++)cout<<ans[i]<<endl;
  return 0;
}


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

#define rep(i,a,n)     for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define int            long long 
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define eb             emplace_back
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define mem0(a)        memset(a,0,sizeof(a))
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define hell           1000000007
#define elasped_time   1.0 * clock() / CLOCKS_PER_SEC
using namespace std;

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}
const int MAXN=200005;
int fact[MAXN],inv[MAXN];
int xymodp(int x,int y,int p){
    int a=1;
    x%=p;
    while(y){
        if(y&1)a=(a*x)%p;
        x=(x*x)%p;
        y/=2;
    }
    return a;
}
void init(int MAXN=MAXN){
    fact[0]=1;
    rep(i,1,MAXN)fact[i]=(i*fact[i-1])%hell;
    rep(i,1,MAXN)inv[i]=xymodp(fact[i],hell-2,hell);
    inv[0]=1;inv[1]=1;
}
int ncr(int n,int r){
    if(n<r)return 0;
    if(r<0)return 0;
    return fact[n]*inv[r]%hell*inv[n-r]%hell;
}
int dp[30001];
int solve(){
 int h,w,n;cin>>h>>w>>n;
 vector<pii> v(n);
 rep3(n)cin>>v[i];
 sort(all(v),[&](pii &p1,pii &p2){return p1.x+p1.y<p2.x+p2.y;});
 v.eb(h,w);
 n++;
 for(int i=0;i<n;i++){
 	dp[i]=ncr(v[i].x+v[i].y-2,v[i].x-1);
 	for(int j=0;j<i;j++){
        if(v[j].x<=v[i].x && v[j].y<=v[i].y){
        	int ways=ncr(v[i].x+v[i].y-v[j].y-v[j].x,v[i].x-v[j].x);
        	dp[i]=((dp[i]-ways*dp[j]%hell)+hell)%hell;
        }
 	}
 }
 cout<<dp[n-1]<<endl;
 return 0;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef sieve
    sieve();
    #endif
    init();
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
 

Measured memory_bytes: 3580
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int N;cin>>N;
  vector<int> first(N),second(N);
  REP(i,0,N)cin>>first[i]>>second[i];

  int ans=N;

  REP(i,0,N)REP(j,0,N){
     // if(i==j)continue;
    int cnt=0;
    int xd=first[i]-first[j];
    int yd=second[i]-second[j];
    REP(k,0,N){
      bool isOk=false;
      REP(l,0,N){
        if(k!=l&&first[k]-first[l]==xd&&second[k]-second[l]==yd){
          isOk=true;
          br;
        }
      }
      if(!isOk){
        cnt++;
      }
    }
    ans=min(ans,cnt);
  }
  print(ans);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,a,b) for(int i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1<<30;
typedef long double ld;
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; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
int main(){
  int h,w,k;  cin >> h >> w >> k;
  string s[h];
  int d[h][w];
  rep(i,0,h){
    cin >> s[i];
  }
  int kk=1;
  rep(i,0,h)rep(j,0,w){
    if(s[i][j]=='#'){
      d[i][j] = kk;
      kk++;
    }else{
      d[i][j] = 0;
    }
  }
  rep(i,0,h)rep(j,0,w){
    if(d[i][j]!=0){
      int k = j;
      while(d[i][k+1]==0 && k+1<w){
        d[i][k+1] = d[i][k];
        k++;
      }
    }
  }
  rep(i,0,h)rep(j,0,w){
    if(d[i][j]!=0){
      int k = j;
      while(d[i][k-1]==0 && k-1>=0){
        d[i][k-1] = d[i][k];
        k--;
      }
    }
  }

  rep(i,0,h)rep(j,0,w){
    if(d[i][j]!=0){
      int k = i;
      while(d[k-1][j]==0 && k-1>=0){
        d[k-1][j] = d[k][j];
        k--;
      }
    }
  }

  rep(i,0,h)rep(j,0,w){
    if(d[i][j]!=0){
      int k = i;
      while(d[k+1][j]==0 && k+1<h){
        d[k+1][j] = d[k][j];
        k++;
      }
    }
  }
  rep(i,0,h){rep(j,0,w){
    cout << d[i][j] << " ";
  }
  cout << endl;
  }
  return 0;
}


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

int f(int n) {
    int cnt = 0;
    for (int a=1; a<=n; ++a) {
        if (n % a == 0) ++cnt;
    }
    return cnt;
}
int solve(int N) {
    int count = 0;
    for (int n=1; n<=N; n+=2) {
        if (f(n) == 8) ++count;
    }
    return count;
}

int main() {
    int N; cin >> N;
    cout << solve(N) << endl;
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
n.times do
    h, w = gets.split.map(&:to_i)
    f = h.times.map{gets.chomp}
    keys = Array.new
    f.each do |r|
        r.each_char do |c|
            keys.push(c) if !keys.include?(c) && c != "."
        end
    end
    if keys.empty?
        puts "SAFE"
        next
    end
    b = true
    rec = Hash.new(Array.new(4))
    f.each_with_index do |row, i|
        row.each_char.with_index do |ch, j|
            if !rec.has_key?(ch)
                rec[ch] = [i,j,i,j]
            else
                rec[ch][0] = i if i < rec[ch][0]
                rec[ch][1] = j if j < rec[ch][1]
                rec[ch][2] = i if i > rec[ch][2]
                rec[ch][3] = j if j > rec[ch][3]
            end
        end
    end
    keys.permutation(keys.size) do |p|
        b = true
        done = Hash.new(false)
        p.each do |c|
            for i in rec[c][0]..rec[c][2]
                for j in rec[c][1]..rec[c][3]
                    if f[i][j] != c && !done[f[i][j]]
                        b = false
                    end
                    break if !b
                end
            end
            break if !b
            done[c] = true
        end
        break if b
    end
    puts b ? "SAFE" : "SUSPICIOUS"
end

Measured memory_bytes: 6176
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int h, w;
    char[][] css;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        h = sc.nextInt();
        w = sc.nextInt();
        css = new char[h][];
        for (int i = 0; i < h; i++) {
            css[i] = sc.next().toCharArray();
        }
        solve();
    }

    void solve() {
        boolean flag = true;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                boolean ok = false;
                if (css[i][j] == '.') {
                    continue;
                }
                if (i > 0) {
                    if (css[i - 1][j] == css[i][j]) {
                        ok = true;
                    }
                }
                if (j > 0) {
                    if (css[i][j - 1] == css[i][j]) {
                        ok = true;
                    }
                }
                if (i < css.length - 1) {
                    if (css[i + 1][j] == css[i][j]) {
                        ok = true;
                    }
                }
                if (j < css[i].length - 1) {
                    if (css[i][j + 1] == css[i][j]) {
                        ok = true;
                    }
                }
                if (!ok) {
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 23124
var arr = require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n/);
	var length = arr.length;
	var x=[],y=[];
	var h,b;
	for(var i=0;i<length;i+=2){
		h=0;
		b=0;
		x = arr[i].trim().split(/\s/);
		y = arr[i+1].trim().split(/\s/);
		for(var j=0;j<4;j++){
			if(x[j]==y[j]){
				h++;
			}else{
				for(var k=0;k<4;k++){
					if(x[j]==y[k])b++;
				}
			}
		}
		console.log(h+' '+b);
	}

Measured memory_bytes: 15524
#include<cstdio>
int n,m,fa[100005],dis[100005];
bool ok=1;
int find(int x){
    if(fa[x]!=x){
        int nf=fa[x];
        fa[x]=find(fa[x]);
        dis[x]+=dis[nf];
    }
    return fa[x];
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        fa[i]=i;
    for(int i=1;i<=m;i++){
        int l,r,d;
        scanf("%d%d%d",&l,&r,&d);
        int rl=find(l),rr=find(r);
        if(rl==rr&&dis[l]-dis[r]!=d)
            ok=0;
        if(rl!=rr){
            fa[rl]=rr;
            dis[rl]=d+dis[r]-dis[l];
        }
    }
    if(ok)printf("Yes");
    else printf("No");
    return 0;
} 

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

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

	string ans = "No";

	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
		ans = "Yes";
	}
	else if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) {
		ans = "Yes";
	}
	else if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) {
		ans = "Yes";
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
def gi; gets.to_i end
def gs; gets.chomp end
def gli; gets.split(' ').map(&:to_i) end
def d(n); Math.log10(n).to_i + 1 end
class Integer
  # 約数の組み合わせを列挙する
  def divisor_combinations
    (1..Math.sqrt(self).to_i).
      select { |i| self % i == 0 }.
      map { |i| [i, self / i] }
  end
end

N = gi
P_N = gli
Q_N = gli

permutation = (1..N).to_a.permutation
a = permutation.find_index(P_N)
b = permutation.find_index(Q_N)
puts (a-b).abs


Measured memory_bytes: 3836
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#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++)
#define all(x) (x).begin(),(x).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 (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  vector<int>ma(n,1e9);
  rep(i,n-1)
  {
    int a;cin>>a;
    chmin(ma[i],a);
    chmin(ma[i+1],a);
  }
  int res=0;
  rep(i,n)res+=ma[i];
  cout<<res<<endl;
  return 0;

}


Measured memory_bytes: 256
i, j = map(int, input().split())
a = i % 2019
a_r = i // 2019

b = j % 2019
b_r = j // 2019

if a_r == b_r:
    minv = float('INF')
    for first in range(a, b):
        for second in range(a+1, b+1):
            result = first*second%2019
            if result < minv:
                minv = result

    print(minv)
else:
    print(0)

Measured memory_bytes: 3060
def main():
	n, k, *a = map(int, open(0).read().split())
	g = [0] * (k + 1)
	for i in range(min(a), k + 1):
		s = set(g[i - x] for x in a if i >= x)
		r = 0
		while r in s:
			r += 1
		g[i] = r
	print("First" if g[-1] else "Second")
	
if __name__=="__main__":
	main()

Measured memory_bytes: 3828
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
 
ll power(ll x, ll y); 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitcount(n) __builtin_popcountll(n)
#define in_edges(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"

const ll MOD = 1000000007;

vector<int> en[505];
int n, m, q;
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    quickio
    cin >> n >> m >> q;
    repp(i, 1, m){
        int l, r;
        cin >> l >> r;
        en[l].pb(r);
    }

    repp(i, 0, 500) sort(all(en[i]));

    while(q--){
        int l, r;
        cin >> l >> r;
        ll res = 0;
        repp(i, l, r) res += UB(all(en[i]), r) - en[i].begin();
        cout << res << endl;
    }
}

ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

Measured memory_bytes: 4780
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)
#include <string>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(ll i = 0;i < n;++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)

const ll INF = 1e9+7;

// 各桁の和
template<typename T>T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;}
template<typename T>T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

int main(){
  int a,b;cin>>a>>b;
  int ans = max(a+b,max(a-b,a*b));
  print(ans);
  return 0;
}


Measured memory_bytes: 256
input = gets(nil).chomp

def seq(a)
  s = []
  1.upto(10) do |i|
    if i == 1
      s[0] = a
      next
    end

    if i % 2 == 0
      s[i-1] = s[i-2]*2
    else
      s[i-1] = s[i-2]/3
    end
  end
  s.inject(:+)
end

input.split("\n").each do |line|
  a = line.to_f
  puts seq(a)
end

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

typedef long long ll;

ll gcd( ll x, ll y );
ll lcm( ll x, ll y );

int main()
{
    int x, y;

    while ( scanf("%d %d", &x, &y ) != EOF ) {
        printf("%d\n", x - y );
    }

    return 0;
}

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

ll lcm( ll x, ll y )
{
    return x / gcd( x, y ) * y;
}




Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int main(){
	int x;
	cin>>x;
	ll y=1;
	while(y*(y+1)/2<x) y++;
	//ll z=y*(y+1)/2-x;
	cout<<y; 
	return 0;
}

Measured memory_bytes: 3624
package main

import (
	"fmt"
	"io"
	"os"
)

const Mod = 1000000007

func main() {
	r := NewScanner(os.Stdin, 4096)
	h, w := r.Int(), r.Int()

	grid := make([][]byte, h)
	for i := 0; i < h; i++ {
		grid[i] = r.Bytes()
	}

	var dp [1001][1001]int
	dp[0][0] = 1

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if grid[i][j] != '.' {
				continue
			}
			if i == 0 && j == 0 {
				dp[i][j] = 1
				continue
			}
			if i == 0 {
				dp[i][j] = dp[i][j-1]
				continue
			}
			if j == 0 {
				dp[i][j] = dp[i-1][j]
				continue
			}

			dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % Mod
		}
	}

	fmt.Println(dp[h-1][w-1])
}

// generated by https://github.com/murosan/gollect

func ParseInt(b []byte) (n int) {
	var i int
	if b[0] == '-' {
		i++
	}
	for ; i < len(b); i++ {
		n *= 10
		n += int(b[i] - '0')
	}
	if b[0] == '-' {
		return -n
	}
	return
}

type Scanner struct {
	r     io.Reader
	buf   []byte
	delim byte
	size, eof,
	start, end int
}

func NewScanner(r io.Reader, size int) *Scanner {
	return &Scanner{
		r:     r,
		buf:   make([]byte, size),
		delim: ' ',
		size:  size,
		start: size,
		end:   size,
	}
}

func (s *Scanner) Bytes() (b []byte) {
	unsafe := s.next()
	b = make([]byte, len(unsafe))
	copy(b, unsafe)
	return
}

func (s *Scanner) Int() int { return ParseInt(s.next()) }

func (s *Scanner) next() (b []byte) {
	for {
		for i := s.end; i < s.size; i++ {
			atEOF := i == s.eof
			if v := s.buf[i]; atEOF || v == '\n' || v == s.delim {
				b = s.buf[s.start:i]
				s.start, s.end = i+1, i+1
				return
			}
		}
		s.end = s.size
		s.read()
	}
}

func (s *Scanner) read() {
	copy(s.buf, s.buf[s.start:s.end])
	s.end -= s.start
	s.start = 0
	n, _ := s.r.Read(s.buf[s.end:])
	s.eof = s.end + n
}


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

int main(void) {
    int64_t N;

    cin >> N;

    vector<int64_t> x(N);
    vector<int64_t> y(N);
    vector<int64_t> index(N);
    double sum;
    double cnt;
    double tmp;

    for(int i=0;i<N;i++) {
        index[i] = i;
        cin >> x[i] >> y[i];
    }

    sum = 0;
    cnt = 0;
    do {
        cnt += 1;
        for(int i=1;i<N;i++) {
            tmp = sqrt(((x[index[i]]-x[index[i-1]]) * (x[index[i]]-x[index[i-1]]))
                + ((y[index[i]]-y[index[i-1]]) * (y[index[i]]-y[index[i-1]])));
            sum += tmp;
                  
        }
    } while(next_permutation(index.begin(), index.end()));
    
    cout << setprecision(12) << (double)sum / (double)cnt << "\n";
    return 0;
}


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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

template <unsigned long long mod> class modint {
  public:
	unsigned long long v;
	modint(const long long x = 0) : v(x % mod) {}
	modint operator+(const modint rhs) { return modint(*this) += rhs; }
	modint operator-(const modint rhs) { return modint(*this) -= rhs; }
	modint operator*(const modint rhs) { return modint(*this) *= rhs; }
	modint operator/(const modint rhs) { return modint(*this) /= rhs; }
	modint operator-() { return modint(mod - this->v); }
	modint& operator+=(const modint rhs) {
		v += rhs.v;
		if (v >= mod) v -= mod;
		return *this;
	}
	modint& operator-=(const modint rhs) {
		if (v < rhs.v) v += mod;
		v -= rhs.v;
		return *this;
	}
	modint& operator*=(const modint rhs) {
		v = v * rhs.v % mod;
		return *this;
	}
	modint inverse(modint a) {
		unsigned long long exp = mod - 2;
		modint ret(1ULL);
		while (exp) {
			if (exp % 2) { ret *= a; }
			a *= a;
			exp >>= 1;
		}
		return ret;
	}
	modint& operator/=(modint rhs) {
		(*this) *= inverse(rhs);
		return *this;
	}
	friend ostream& operator<<(ostream& os, modint& u) {
		os << u.v;
		return (os);
	}
	friend istream& operator>>(istream& is, modint& u) {
		is >> u.v;
		return (is);
	}
};

const int MOD = 1000000007;
using mint = modint<MOD>;

class Solution {
public:
	void solve() {
		int n;
		string s;
		cin >> n >> s;
		int c = 0;
		mint ret = 1;
		for(int i=0; i < 2*n; i++){
			if(s[i] == 'B'){
				if(c&1){
					ret *= c--;
				}else{
					c++;
				}
			}else{
				if(c&1){
					c++;
				}else{
					ret *= c--;
				}
			}
		}
		if(c != 0){
			cout << 0 << endl;
			return;
		}
		for(int i=0; i < n; i++)ret *= (i+1);
		cout << ret << endl;
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <algorithm>
using namespace std;

int N, K;

int main() {
    int ans = 1e9;
    
    cin >> N >> K;
    
    vector<int> x(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    
    for (int i = 0; i < N - K + 1; i++) {
        
        int left = x[i] > 0? x[i]: -x[i];
        int right = x[i + K - 1] > 0? x[i + K - 1]: -x[i + K - 1];
        int distance = x[i + K - 1] - x[i];
        
        int time = left < right? left + distance: right + distance;
        ans = min(ans, time);
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 640
#include<stdio.h>
 
int main(void)
{
    char num[1000];
    int sum, i;
     
    while(1){
        scanf("%s", &num);
        if(num[0] == '0'){
            break;
        }
        sum = 0;
        for(i=0;num[i] != '\0';i++){
            sum += num[i] - '0';
        }
        printf("%d\n", sum);
    }
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> H(N);
    for (int i = 0;i < N;i++){
        cin >> H.at(i);
    }

    bool ans = true;
    for(int i = 1;i < N;i++){
        if(H.at(i-1) < H.at(i)){
            H.at(i) -= 1;
            continue;
        }
        else if (H.at(i) < H.at(i-1)){
            ans = false;
            break;
        }
    }

        if(ans){
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    int N,M;cin>>N>>M;
    VI A(N);
    int sum=0;
    REP(i,N){
        cin>>A[i];
        sum+=A[i];
    }
    int c=ceil((double)sum/4.0/M);
    sort(All(A));
    for(int i=N-1;i>N-1-M;i--){
        if(A[i]<c){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
	int n,ans=0;
	bool c[26]={0};
	char a;
	cin>>n;
	while(n--){
		cin>>a;
		c[a-'A']=1;
	}
	for(n=0;n<26;n++){
		if(c[n])ans++;
	}
	if(ans==3)cout<<"Three"<<endl;
	else cout<<"Four"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
int main(){
    using namespace std;
    int n,i;
    long long int min,max,sum,a;
    min = 1000000;
    max = -1000000;
    sum = 0;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a;
        sum = sum + a;
        if(a<min){
            min = a;
        }if(a>max){
            max = a;
        }
    }
    cout << min << " " << max << " " <<  sum << endl;
    return 0;
}

Measured memory_bytes: 3108
using System;
using System.Collections.Generic;

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] lines = Console.ReadLine().Split(' ');

            int[] x = new int[5];

            for (int i=0; i<5; i++)
            {
                x[i] = int.Parse(lines[i]);
                //Console.WriteLine(x[i]);
            }

            for (int i = 0; i < 5; i++)
            {
                if (x[i] == 0)
                {
                    Console.WriteLine(i + 1);
                    return;
                }
            }


        }
    }
}


Measured memory_bytes: 27196
N = int(input())
A = input().split()

toA = 0
for i in range(N):
    A[i] = int(A[i])
    toA += A[i]

ans = 0
for i in range(0, N):
    toA -= A[i]
    ans += A[i]*toA

print(ans % 1000000007)

Measured memory_bytes: 105472