akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
from typing import List


class Solution:
    def numSubarrayProductLessThanK(self, nums: List[int], k: int) -> int:
        left = 0
        ans, prod = 0, 1
        lenght = 0
        for num in nums:
            if prod * num >= k:
                prod *= num
                lenght += 1
                while prod >= k:
                    prod //= nums[left]
                    left += 1
                    lenght -= 1
                ans += lenght
            else:
                prod *= num
                lenght += 1
                ans += lenght
            # print(ans)

        return ans



def main() -> None:
    r, g, b, n = map(int, input().split())

    cnt = 0
    for i in range(0, n + 1, r):
        for j in range(0, n + 1, g):
            k = n - i - j
            if k % b != 0:
                continue
            # k //= b

            if i + j + k == n and k >= 0:
                cnt += 1
            # print(i, j, k )

    print(cnt)



# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self, **kwargs):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 69768
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns #-}
import Data.Bits ((.&.),unsafeShiftL, unsafeShiftR)

import Control.Monad
import Control.Monad.ST
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV

main=do
  n<-readLn::IO Int
  as<-unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
  bs<-unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
  --
  print.sum.map (st n as bs) $ [0..28]
--

st::Int->[Int]->[Int]->Int->Int
st n as bs' k = if even$ sum $ map (\a->f n v k2 (a .&. km)) as then 0 else k2
  where
    k2 = unsafeShiftL 1 k
    km = (unsafeShiftL 1 (k+1)) - 1
    !v = bmod $ map (\b->b .&. km) bs'

bmod:: [Int]->V.Vector Int
bmod bs = runST $ do
  v <- V.thaw $ V.fromList bs
  sortv v 0 (MV.length v - 1)
  V.unsafeFreeze v
--
f::Int->V.Vector Int->Int->Int->Int
f n bs t a = b2 - b1 + n - b3
  where
    b1 = ubound bs (t-1-a) (-1,n)
    b2 = ubound bs ((unsafeShiftL t 1)-1-a) (-1,n)
    b3 = ubound bs (t*3-1-a) (-1,n)
--    b4 = ubound bs (4*t-1-a) (-1,n)

ubound v k (a,b)
    | a+1 == b = b
    | V.unsafeIndex v m <= k = ubound v k (m,b)
    | True = ubound v k (a,m)
    where m = unsafeShiftR (a+b) 1
--
{-# INLINE sortv #-}
sortv :: MV.STVector s Int -> Int -> Int -> ST s ()
sortv as b e = do
        l <- MV.unsafeRead as b
        r <- MV.unsafeRead as e
        p <- findP l (b+1) e
        case p of
            Nothing -> return ()
            Just piv -> do
                k <- partv as piv b e
                sortv as b (k-1)
                sortv as k e
    where
        findP a i e
            | i > e = return Nothing
            | True = do
                k <- MV.unsafeRead as i
                case (a < k, k < a) of
                    (True, _) -> return $ Just k
                    (_, True) -> return $ Just a
                    _ -> findP a (i+1) e

partv :: MV.STVector s Int -> Int -> Int -> Int -> ST s Int
partv as piv b e = do
    MV.unsafeSwap as b e
    l <- findF b
    r <- findT e
    if l <= r then partv as piv l r
              else return l
    where
        findF i = do
            k <- MV.unsafeRead as i
            if k < piv then findF (i+1) else return i
        findT j = do
            k <- MV.unsafeRead as j
            if k < piv then return j else findT (j-1)


Measured memory_bytes: 62588
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		long h = Long.parseLong(sc.next());
		long count = 0;
		int idx = 0;
		long[] a = new long[n];
		long[] b = new long[n];
		long amax = 0;
		for(int i=0; i<n; i++) {
		    a[i] = Long.parseLong(sc.next());
		    b[i] = Long.parseLong(sc.next());
		    if(a[i] > amax) {amax = a[i]; idx = i;}
		}
		
		long listsum = 0;
		ArrayList<Long> list = new ArrayList<>();
		for(int i=0; i<n; i++) {
		    if(i == idx) {continue;}
		    if(b[i] > amax) {list.add(b[i]); listsum += b[i];}
		}
		
		if(h > listsum+b[idx]) {
		    h -= listsum;
		    count += list.size();
		}else {
    		Collections.sort(list, Collections.reverseOrder());
    		for(long x : list) {
    		    if(h - b[idx] <= 0) {h -= b[idx]; count++; break;}
                else {count++; h -= x;}
                if(h <= 0) break;
            }
		}
 
        while(h > 0) {
            if(h - b[idx] <= 0) {count++; break;}
            else {h -= amax; count++;}
            
        }
		
		System.out.println(count);
	}
	
}

Measured memory_bytes: 57064
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N;
	in >> N;

	LL ans = 0;
	for (LL i = 1; i * i <= N; ++i)
	{
		LL m = (N - i) / i;
		if (m <= 0) continue;
		if (i * m + i == N && N / m == N % m) ans += m;
	}
	out << ans << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
typedef int64_t ll;
typedef uint64_t ull;

constexpr ll INF = 1000000000;/* 1e+9a */

void solve(istream &cin) {
    ll N;
    if (!(cin >> N)) { return; }
    ll mizu = 0;
    ll pre = 0;
    ll least = 0;
    for (int i = 0; i < N; ++i) {
        ll tmp;
        cin >> tmp;
        if(tmp <= pre) {
            mizu += pre - least;
            least = tmp;
        }
        pre = tmp;
    } // end i
    mizu += pre - least;
    cout << mizu << endl;
}

int main(int argc, char *argv[]) {
    string FileName("D"), Modifier("MEPH_");
    string ExecutionName = Modifier + FileName;
    string sub(argv[0]);
    // /home/USER/.../MEPH_X -> MEPH_X
    if (sub.size() > ExecutionName.size())
        sub = sub.substr(sub.size() - ExecutionName.size(), ExecutionName.size());

    cout << setprecision(16) << scientific;
    if (sub != ExecutionName) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        while (cin) { solve(cin); }
    } else {
        cerr << sub << " test" << endl;
        string inFile = FileName + ".txt";
        auto fs = fstream(inFile, fstream::in);
        while (fs) { solve(fs); }
    }
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

template<typename T> T minkowskiDistance(const vector<T> &a, const vector<T> &b, const int &p) {
  int n = a.size();
  T x = 0;
  rep(i, n) x += pow(abs(a[i] - b[i]), p);
  return pow(x, 1.0 / p);
}

template<typename T> T chebyshevDistance(const vector<T> &a, const vector<T> &b) {
  int n = a.size();
  T x = 0;
  rep(i, n) cmax(x, abs(a[i] - b[i]));
  return x;
}

main {
  int n;
  cin >> n;
  auto a = in(vector<double>(n));
  auto b = in(vector<double>(n));
  cout << prec(32);
  cout << minkowskiDistance(a, b, 1) << endl;
  cout << minkowskiDistance(a, b, 2) << endl;
  cout << minkowskiDistance(a, b, 3) << endl;
  cout << chebyshevDistance(a, b) << endl;
}



Measured memory_bytes: 3484
#include <iostream>
#include <climits>
#include <vector>
#include <stack>
using namespace std;
const int nmax=100005;
int n,m;
vector <int> muchii[nmax];
vector <int> reversa[nmax];
stack <int> st;
bool viz[nmax];
void topsort(int nod)
{
    viz[nod]=true;
    for (int i=0;i<muchii[nod].size();i++)
    {
        int vecin=muchii[nod][i];
        if (!viz[vecin])
            topsort(vecin);
    }
    st.push(nod);
}
int main()
{
    int dp[nmax],rez=0;
    cin >> n >> m;
    for (int i=1;i<=m;i++)
    {
        int x,y;
        cin >> x >> y;
        muchii[x].push_back(y);
        reversa[y].push_back(x);
    }
    for (int i=1;i<=n;i++)
    {
        dp[i]=0;
        if (!viz[i])
            topsort(i);
    }
    while (!st.empty())
    {
        int nod=st.top();
        for (int i=0;i<reversa[nod].size();i++)
        {
            dp[nod]=max(dp[reversa[nod][i]]+1,dp[nod]);
        }
        st.pop();
    }
    for (int i=1;i<=n;i++)
    {
        rez=max(dp[i],rez);
    }
    cout << rez;
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, L; cin >> N >> L;
  vector<string> S(N);
  for (ll i = 0; i < N; i++) cin >> S[i];
  sort(S.begin(), S.end());
  for (ll i = 0; i < N; i++) cout << S[i];
  cout << endl;


  return 0;
}



Measured memory_bytes: 3632
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

class AtCoder
{
    public void Slove()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).Select(x => x - 1).ToArray();
        var b = a.ToList();
        var result = new Stack<int>();
        foreach(int i in Enumerable.Range(1, n).Reverse())
        {
            int bLen = b.Count;
            foreach(int j in Enumerable.Range(0, i).Reverse())
            {
                if(b[j] == j)
                {
                    b.RemoveAt(j);
                    result.Push(j + 1);
                    //System.Console.WriteLine(j + 1);
                    break;
                }
            }
            if(b.Count == bLen)
            {
                System.Console.WriteLine(-1);
                return;
            }
        }
        System.Console.WriteLine(string.Join("\n", result));
        // var ts = new List<int>();
        // foreach(int i in result)
        // {
        //     ts.Insert(i - 1, i);
        // }
        // System.Console.WriteLine(string.Join(" ", ts));
        // System.Console.WriteLine(ts.SequenceEqual(a.Select(x => x + 1)));
    }
    static void Main()
    {
        var ac = new AtCoder();
        ac.Slove();
    }
}

Measured memory_bytes: 13524
#include<stdio.h>
int main(void)
{
    int n,num,i;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=n-1;i>=0;i-=2)
    {
        printf("%d ",a[i]);
    }
    for(i=(i+3)%2;i<n;i+=2)
    {
        printf("%d ",a[i]);
    }
    return 0;
}


Measured memory_bytes: 2816
import java.io.*;
import java.util.*;
import java.lang.*;

class Main{
  public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);
    String input=scan.next();
    int count=0;
    while(true){
      String str=scan.next();
      if(str.equals("END_OF_TEXT"))break;
      if(input.equalsIgnoreCase(str)){
        count++;
      }
    }
    System.out.println(count);
  }
}



Measured memory_bytes: 26080
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
 
using namespace std;
 
using ll = long long int; 
 
void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;
 
    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}
 
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}
 
ll keta(ll a){
  ll ans = 1;
  while(1){
    if(a/10 > 0){
      ans++;
      a = a/10;
    }
    if(a<10) break;
  }
  return ans;
}
 
const int MAX = 50;
const int MOD = 1000000007;
 
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(void){
 
    int n;
    cin>>n;
    vector<int> s(n);
    vector<int> p(n);
    vector<int> q(n);
    int a = 0;
    int b = 0;

    for(int i=0;i<n;i++){
        s[i] = i+1;
    }
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        p[i] = x;
    }
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        q[i] = x;
    }

    int count = 0;
    do {
        count++;
        for(int i=0;i<n;i++){
            if(s[i] != p[i]) break;
            if(i==n-1 && s[i]==p[i]) a = count;
        }
        
        for(int i=0;i<n;i++){
            if(s[i] != q[i]) break;
            if(i==n-1 && s[i]==q[i]) b = count;
        }
        if(a!= 0 && b!= 0)break;

    } while (std::next_permutation(s.begin(), s.end()));

    cout<<abs(b-a)<<endl;
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[1001];
    memset(a,0,sizeof(a));
    for(int i=1;i<=999;i++) {
            a[i] =i + a[i-1];

    }
    int c,d;
    cin>>c>>d;

	for (int x = 1; x <= 499500; x++)
    {
        for(int i=2;i<=999;i++)
       {
         if(a[i-1]-x==c && a[i]-x==d)
         {
            cout<<x<<endl;
            return 0;
         }
       }
    }

}


Measured memory_bytes: 256
N = int(input())
A = [int(input()) for i in range(N)]

keep = 0
maxcount = 0
for i in range(N):
    if A[i] >= maxcount:
        maxcount = A[i]
        keep = i
    
for i in range(N):
    if i == keep:
        A[i] = 1
        print(max(A))
    else:
        print(maxcount)

Measured memory_bytes: 12532
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  cin>>n;
  vi a(n);
  rep(i,n){
    cin>>a[i];
  }
  sort(all(a));
  bool flag=true;

  if(a[0]!=a[1]){
    if(a[n-1]-a[0]!=a[0]) flag=false;
    FOR(i,1,n){
      int j=i;
      if(a[i]-a[i-1]!=1) flag=false;
      while(j<n&&a[i]==a[j]) j++;
      if(j-i<2) flag=false;
      i=j-1;
    }
  }else{
    if(a[n-1]-a[0]+1!=a[0]) flag=false;
    if(a.size()>2&&a[2]==a[0]) flag=false;
    else{
      FOR(i,2,n){
        int j=i;
        if(a[i]-a[i-1]!=1) flag=false;
        while(j<n&&a[i]==a[j]) j++;
        if(j-i<2) flag=false;
        i=j-1;
      }
    }
  }


  if(flag||n==2&&a[0]==a[1]){
    cout<<"Possible"<<endl;
  }else{
    cout<<"Impossible"<<endl;
  }



}

Measured memory_bytes: 256
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.regex.Pattern
import java.util.{ArrayList, Collections, Comparator, List => JList}

import scala.collection.immutable.TreeMap
import scala.math._
import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val Array(n, m) = input.split(LINE_SEPARATOR).head.split(" ").map(_.toInt)
    val h = input.split(LINE_SEPARATOR).tail.head.split(" ").map(_.toInt)
    val lowerHills = input.split(LINE_SEPARATOR).tail.tail.foldLeft(Vector.empty[Int]){(list, abi) =>
      val Array(ai, bi) = abi.split(" ").map(_.toInt)
      if (h(ai - 1) > h(bi - 1)) bi +: list
      else if (h(ai -1) < h(bi - 1)) ai +: list
      else ai +: bi +: list
    }.distinct
    ((1 to n) diff lowerHills).length.toString
  }


  def factorize(x: Long): List[Long] = {
    def foo(x: Long, a: Long = 2, list: List[Long] = Nil): List[Long] = a*a > x match {
      case false if x % a == 0 => foo(x / a, a    , a :: list)
      case false               => foo(x    , a + 1, list)
      case true                => x :: list
    }
    foo(x)
  }

  def divisors(n: Long): Vector[Long] = {
    val halfList = (1 to sqrt(n).toInt).toVector.filter(_ % n == 0).map(_.toLong)
    val reversedList = if (sqrt(n).floor == sqrt(n)) halfList.reverse.tail.map(n/_) else halfList.reverse.map(n/_)
    halfList ++ reversedList
  }

  def gcd(m: Long, n: Long): Long = n match {
    case 0 => m
    case _ => gcd(n, m % n)
  }
  def lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

  val tests=List(
    """4 3
      |1 2 3 4
      |1 3
      |2 3
      |2 4""".stripMargin -> """2
                                   |
                                 |
                                   |""".stripMargin,
    """6 5
      |8 6 9 1 2 1
      |1 3
      |4 2
      |4 3
      |4 6
      |4 6""".stripMargin -> """3""".stripMargin
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 81776
def examA():
    a, b = LI()
    if a>0:
        ans = "Positive"
        print(ans)
        return
    if b>=0:
        ans = "Zero"
    else:
        judge = b-a
        if judge%2==1:
            ans = "Positive"
        else:
            ans = "Negative"
    print(ans)
    return

def examB():
    N, M = LI()
    boal = [1]*N
    d = defaultdict(bool)
    d[0] = True
    for _ in range(M):
        x,y = LI()
        boal[x-1] -=1
        boal[y-1] +=1
        if d[x-1]:
            d[y-1] = True
        if boal[x-1]==0:
            d[x-1] = False
    ans = sum(d.values())
    print(ans)
    return

def examC():
    N, L = LI()
    A = LI(); cur = -1
    ans = "Impossible"
    for i in range(N-1):
        if A[i]+A[i+1]>=L:
            ans = "Possible"
            cur = i
            break
    print(ans)
    if cur==-1:
        return
    ansC = []
    for i in range(cur):
        ansC.append(i)
    for i in range(N-2,cur,-1):
        ansC.append(i)
    ansC.append(cur)
    for v in ansC:
        print(v+1)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()


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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

mt19937 mt_engine(chrono::steady_clock::now().time_since_epoch().count());
template <class T> enable_if_t<is_integral_v<T>, T> rng(T l, T r) {
  return uniform_int_distribution<T>(l, r - 1)(mt_engine);
}
template <class T> enable_if_t<is_floating_point_v<T>, T> rng(T l, T r) {
  return uniform_real_distribution<T>(l, r)(mt_engine);
}

struct stopwatch {
  clock_t t = clock();
  void restart() { t = clock(); }
  int elapsed() const { return (clock() - t) * 1000 / CLOCKS_PER_SEC; }
  void operator()(string s = "Time") const {
    cerr << s + ": " << elapsed() << " ms\n";
  }
} sw;

template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

auto chmax = [](auto&& a, auto b) { return a < b ? a = b, 1 : 0; };

constexpr int n = 365, m = 26;
int c[m], s[n][m];

int type[n];
int score(int lim = n) {
  vector<int> last(m, -1);
  int res = 0;
  for (int i = 0; i < lim; ++i) {
    res += s[i][type[i]];
    last[type[i]] = i;
    for (int j = 0; j < m; ++j) {
      res -= c[j] * (i - last[j]);
    }
  }
  return res;
}

void solve() {
  vector<vector<pair<int, array<int, m>>>> v(n + 1);
  v[0].resize(1);
  v[0].back().second.fill(-1);
  for (int i = 0; i < n; ++i) {
    vector<pair<int, array<int, m>>> nxt;
    for (auto [sum, last] : v[i]) {
      int cost = 0;
      for (int j = 0; j < m; ++j) {
        cost += c[j] * (i - last[j]);
      }
      for (int j = 0; j < m; ++j) {
        int nsum = sum - cost;
        nsum += s[i][j];
        nsum += c[j] * (i - last[j]);
        auto nlast = last;
        nlast[j] = i;
        nxt.emplace_back(nsum, nlast);
      }
    }
    sort(rbegin(nxt), rend(nxt));
    set<array<int, m>> se;
    for (int k = 0; k < (int)size(nxt); ++k) {
      if (rng(0, 4 * (int)size(nxt)) < k) continue;
      auto [sum, last] = nxt[k];
      if (se.count(last)) break;
      se.insert(last);
      v[i + 1].emplace_back(sum, last);
      if (size(v[i + 1]) == 1000) {
        // cerr << k << ' ' << size(nxt) << '\n';
        break;
      }
    }
  }
  auto [sum, last] = v[n][0];
  for (int i = n; i--; ) {
    type[i] = max_element(begin(last), end(last)) - begin(last);
    assert(last[type[i]] == i);
    sum -= s[i][type[i]];
    for (int j = 0; j < m; ++j) {
      sum += c[j] * (i - last[j]);
    }
    for (auto [nsum, nlast] : v[i]) {
      last[type[i]] = nlast[type[i]];
      if (nsum == sum and nlast == last) {
        last = nlast;
        break;
      }
    }
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int _n;
  cin >> _n;
  assert(_n == n);
  for (int j = 0; j < m; ++j) {
    cin >> c[j];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> s[i][j];
    }
  }
  solve();
  for (int i = 0; i < n; ++i) {
    cout << type[i] + 1 << '\n';
  }
  sw();
  cerr << score() << '\n';
}


Measured memory_bytes: 34484
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	for(int i =1;i<=5;i++)
	{
		int x;
		cin>>x;
		if(x==0)
		{
		cout<<i<<endl;
		break;
	}
		
	}
}

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

using namespace std;

#define ll long long
#define INF (1LL<<62)

ll x[50],y[50];
int N,K;

int check(ll lx,ll ly,ll rx,ll ry){
	int ans = 0;
	for(int i = 0;i < N;i++){
		ll nx = x[i];
		ll ny = y[i];
		if(!(lx <= nx && nx <= rx))continue;
		if(!(ly <= ny && ny <= ry))continue;
		ans++;
	}
	return ans;
}

ll saiki(int num,int at,ll lx,ll ly,ll rx,ll ry){

	ll ret = (rx-lx)*(ry-ly);
	if(check(lx,ly,rx,ry)!=K)ret = INF;
	if(num == 4)return ret;

	for(int i = at;i<N;i++){
		ll nx = x[i];
		ll ny = y[i];
		ll v = saiki(num+1,i+1,min(lx,nx),min(ly,ny),max(rx,nx),max(ry,ny));
		ret = min(ret,v);
	}
	return ret;
}

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

	cout << saiki(0,0,INF,INF,-INF,-INF) << endl;
}

Measured memory_bytes: 256
/* h-ex9_1
   Ohshima */

#include <stdio.h>
#include <stdlib.h>
//スタックに格納するデータの最大数
#define SIZE 10

//スタックの定義
typedef struct stack{
  int size;
  int count;
  char data[SIZE + 1]; //topの初期位置を考慮
  char *top;
}stack;

//スタックの初期化
void initialize_stack(stack *stk){
  stk->count = 0;
  stk->size = SIZE;
  stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
  if(stk->count >= stk->size){
    fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
    exit(1);
  }else{
    stk->top--;
    *(stk->top) = elem;
    stk->count++;
  }
}

//データの取り出し
void pop(stack *stk){
  if(stk->count <= 0){
    fprintf(stdout, "Error: stack underflow.\n");
    exit(1);
  }else{
    stk->top++;
    stk->count--;
  }
}

//スタックの中身を古いものから出力
void print_stack(stack *stk){
  int i;
  for(i = 0; i < stk->count; i++){
    putchar(stk->data[SIZE - 1 - i]);
  }
  printf("\n");
}

int main(void){
  stack stk;
  char tmp;
  int i;
  //スタックを初期化（ポインタ渡しで関数にわたすこと）
  initialize_stack(&stk);
  //1文字ずつ標準入力から受け取り以下を実行
  while(scanf("%c", &tmp) != EOF && tmp != '\n'){ //テストケースの中に10文字+改行文字の場合が含まれている
    //B以外の文字のときスタックにデータを追加
    if(tmp != 'B'){
      push(&stk, tmp);
    }else{
      //Bがきた場合、文字列が空でないならデータを取り除く
      if(stk.count > 0){
        pop(&stk);
      }
    }
  }
  //最後に、スタックに残っている文字を古いものから1文字ずつ出力
  print_stack(&stk);
  return 0;
}


Measured memory_bytes: 1584
#include<iostream>
#include<vector>
using namespace std;
int main() {
	vector<bool>l;
	int C1, C2, C3;
	while (cin >> C1 >> C2 >> C3) {
		int sum = 0;
		for (int i = 1; i < 11; i++){
			if (i == C1 || i == C2 || i == C3)continue;
			else if (i + C1 + C2 <= 20)sum++;
		}
		l.push_back(sum >= 4);
	}
	for (bool i : l) {
		if (i)cout << "YES";
		else cout << "NO";
		cout << endl;
	}
}

Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main(){
  int n,ma,mb;cin>>n>>ma>>mb;
  int dp[n+1][401][401];
  rep(i,n+1) rep(j,401) rep(k,401) dp[i][j][k]=1e9+7;
  dp[0][0][0]=0;
  rep(i,n){
    int a,b,c;cin>>a>>b>>c;
    rep(j,401) rep(k,401){
      if((j-a<0)||(k-b<0)){
        dp[i+1][j][k]=dp[i][j][k];
      }
      else dp[i+1][j][k]=min(dp[i][j][k],dp[i][j-a][k-b]+c);
    }
  }
  int ans=1e9+7;
  rep(i,1,401){
    if(ma*i>400||mb*i>400)break;
    chmin(ans,dp[n][ma*i][mb*i]);
  }
  if(ans>1e9)cout<<-1<<endl;
  else cout<<ans<<endl;
}

Measured memory_bytes: 25984
#include <iostream>
#include <vector>
#include <array>
#include <cmath>

using namespace std;
#define ll long long


int main()
{
    // Value
    string S;
    string result = "YES";

    // Input
    cin>>S;

    // Cal
    ll size = S.size();
    ll cnt=0;
    for(;cnt<size-4;){
        //
        string five = S.substr(cnt, 5);
        string six;
        string seven;
        string ti;
        string tt;
        if(cnt<size-5) six = S.substr(cnt, 6);
        if(cnt<size-6) seven = S.substr(cnt, 7);
        if(cnt<size-9) ti = S.substr(cnt, 10);
        if(cnt<size-10) tt = S.substr(cnt, 11);
        if(cnt<size-10 && tt == "dreameraser"){
            cnt+=11;
        }else if(cnt<size-9 && ti == "dreamerase"){
            cnt+=10;
        }else if(cnt<size-6 && seven == "dreamer"){
            cnt+=7;
        }else if(cnt<size-5 && six == "eraser"){
            cnt+=6;
        }else if(five == "dream" || five == "erase"){
            cnt+=5;
        }else{
            result = "NO";
            break;
        }
    }
    if(cnt!=size) result="NO";

    // Output
    cout << result << endl;

    // Fin
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace::std;
 
int main(){
  	long long int a,b;
  	cin>>a>>b;
  	long long int g=__gcd(a,b),ans=1;
  	bool is=1;
  	for(long long int i=2;i<=g;i++){
    	if(is){
          	bool chc=0;
        	for(long long int j=2;j<=sqrt(g);j++)
              	if(!(g%j))
                  	chc=1;
        	if(!chc){
            	cout<<ans+1<<'\n';
              	return 0;
            }
            is=0;
        }
      	if(!(g%i) && (is=1,ans++))
          while(!(g%i)) g/=i;
    }
  	cout<<ans<<'\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

ll n,a[200005] = {};


int main(){
    
    IN n;
    inrep(n,a);
  
    rsort(a,a+n,ll);

    double c = a[0]/2;

    int sa = 1;

    rep(i,2,n){
        if(abs(c-a[sa]) > abs(c-a[i])){
            sa = i;
        }
    }

    cout << a[0] << " " << a[sa] << endl;
    
	return  0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdbool.h>

static const int alternatives[24][6] = {
    {0, 1, 2, 3, 4, 5},
    {0, 2, 4, 1, 3, 5},
    {0, 3, 1, 4, 2, 5},
    {0, 4, 3, 2, 1, 5},
    {1, 0, 3, 2, 5, 4},
    {1, 2, 0, 5, 3, 4},
    {1, 3, 5, 0, 2, 4},
    {1, 5, 2, 3, 0, 4},
    {2, 0, 1, 4, 5, 3},
    {2, 1, 5, 0, 4, 3},
    {2, 4, 0, 5, 1, 3},
    {2, 5, 4, 1, 0, 3},
    {3, 0, 4, 1, 5, 2},
    {3, 1, 0, 5, 4, 2},
    {3, 4, 5, 0, 1, 2},
    {3, 5, 1, 4, 0, 2},
    {4, 0, 2, 3, 5, 1},
    {4, 2, 5, 0, 3, 1},
    {4, 3, 0, 5, 2, 1},
    {4, 5, 3, 2, 0, 1},
    {5, 1, 3, 2, 4, 0},
    {5, 2, 1, 4, 3, 0},
    {5, 3, 4, 1, 2, 0},
    {5, 4, 2, 3, 1, 0},
};

#define DICENUM 2

int main(int argc, char *argv[])
{
    int dices[DICENUM][6];
    for (int i = 0; i < 2; ++i)
    {
        for (int *elm = dices[i], *const end = elm + 6; elm != end; ++elm)
        {
            scanf("%d", elm);
        }
    }
    bool matched = false;
    for (int i = 0; i < 24 && !matched; ++i)
    {
        int j;
        for (j = 0; j < 6; ++j)
        {
            if (dices[1][alternatives[i][j]] != dices[0][j])
            {
                break;
            }
        }
        matched = (j == 6);
    }
    printf("%s\n", matched ? "Yes" : "No");
    return 0;
}



Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define MOD                 1000000007LL
#define EPS                 1e-9
#define io                  ios_base::sync_with_stdio(false);cin.tie(NULL);

const int MAXN = 1e5+5;

int main(){
	io;
	int n;
	cin >> n;
	map<int, int> M;
	for(int i = 0;i < n; i++){
		int x;
		cin >> x;
		M[x]++;
	}
	ll ans = 0;
	for(auto p : M){
		int number = p.first;
		int occurences = p.second;
		if(occurences > number){
			ans += (occurences - number) * 1LL;
		}
		if(occurences < number)
			ans += occurences * 1LL;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4736
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    private static class Pair{
        Long key;
        Long value;

        public Pair(Long a, Long b){
            key=a;
            value=b;
        }

    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());
        List<Integer> pos = new ArrayList<>();
        List<Integer> neg = new ArrayList<>();
        long sumPos;
        long sumNeg;
        ArrayList<Pair> pair = new ArrayList<>();
        for(int i=0;i<n;i++) {
            int temp = Integer.parseInt(st.nextToken());
            if (temp >= 0) {
                pos.add(temp);
            } else {
                neg.add(temp);
            }
        }
            Collections.sort(pos);
            Collections.sort(neg);
            Collections.reverse(neg);
            sumPos = (neg.size()==0)? pos.get(0):neg.get(0);
            sumNeg=(pos.size()==0)?neg.get(0):pos.get(0);
            if(pos.size()>0) {
                for (int i = 1; i < pos.size() - 1; i++) {
                    pair.add(new Pair(sumPos, (long) pos.get(i)));
                    sumPos -= pos.get(i);
                }
                if (neg.size() == 0) {
                    pair.add(new Pair((long) pos.get(pos.size() - 1), sumPos));
                    sumPos = pos.get(pos.size() - 1) - sumPos;

                    System.out.println(sumPos);
                    for (Pair p : pair) {
                        System.out.println(p.key + " " + p.value);
                    }
                    return;
                }
            }
            if(neg.size()>0){
                for(int i=1; i<neg.size(); i++){
                    pair.add(new Pair(sumNeg, (long)neg.get(i)));
                    sumNeg-=neg.get(i);
                }
                if(pos.size()==0){
                    System.out.println(sumNeg);
                    for (Pair p : pair) {
                        System.out.println(p.key + " " + p.value);
                    }
                    return;
            }
            else {
                if(pos.size()>1){
                    pair.add(new Pair(sumPos, (long) pos.get(pos.size()-1)));
                    sumPos -= pos.get(pos.size()-1);
                }
                    
            }
                pair.add(new Pair(sumNeg,sumPos));
                System.out.println(sumNeg-sumPos);
                for(Pair p: pair){
                    System.out.println(p.key + " " + p.value);
                }
        }
    }
}

Measured memory_bytes: 65680
while True:
    n = int(input())
    if n == 0:
        break
    scores = list(map(int, input().split()))
    m = sum(scores) / n
    dev = list((i - m) for i in scores)
    var = sum((i ** 2) for i in dev) / n
    stdev = var ** 0.5
    print(stdev)



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

int sum(int x) {
  int xsum = 0;
  while (x > 0) {
    xsum += x % 10;
    x /= 10;
  }
  return xsum; // return忘れるのはさすがに草
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if ((a <= sum(i)) && (sum(i) <= b)) {
      ans += i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,m,a,b;
	cin >> n >> m;
	vector<P> V(n+1);
	for(int i = 0; i < n+1; i++) {
		V[i].fs = 0;
		V[i].sc = 0;
	}
	int flag = 0;
	for(ll i = 0; i < m; i++) {
		cin >> a >> b;
		if (a == 1){
			V[b].fs = 1;
		}
		if (b == n){
			V[a].sc = 1;
		}
	}

	for(ll i = 0; i < n+1; i++) {
		if (V[i].fs == 1 && V[i].sc == 1){
			flag = 1;
			break;
		}
	}
	if (flag == 1){
		cout << "POSSIBLE" << endl;
	}
	else{
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 3328
<?php
const MOD = 10 ** 9 + 7;
list($H, $W, $K) = ints();
// 動的計画法
// dp[i][j]: i行目の移動を終えた後、j列目にいるあみだくじの本数
$dp = array_fill(0, $H + 1, array_fill(1, $W, 0));
$dp[0][1] = 1;
for ($i = 1; $i <= $H; ++$i) {
    // i行目の線の引き方を全探索
    for ($j = 0; $j < 2 ** ($W - 1); ++$j) {
        $next = array_fill(1, $W, 0);
        for ($k = 0; $k < $W - 1; ++$k) {
            if ($j >> $k & 1) {
                // 既に線がある場合は「正しいあみだくじ」ではないのでスキップ
                if ($next[$k + 1] !== 0) continue 2;
                $next[$k + 1] = 1; // 今の列から右に伸びる
                $next[$k + 2] = -1; // 右隣の列から左に伸びる
            }
        }
        for ($x = 1; $x <= $W; ++$x) {
            $dp[$i][$x + $next[$x]] += $dp[$i - 1][$x];
            $dp[$i][$x + $next[$x]] %= MOD;
        }
    }
}
echo $dp[$H][$K];
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16104
def knot(N, L, a):
    res = []
    for i in range(N - 1):
        if a[i] + a[i + 1] >= L:
            res.append(i + 1)
            start = i
            break
    else:
        return res

    for i in range(start + 1, N - 1):
        res.append(i + 1)
    for i in range(start - 1, -1, -1):
        res.append(i + 1)
    return res


if __name__ == "__main__":
    N, L = map(int, input().split())
    a = list(map(int, input().split()))
    knot = knot(N, L, a)
    if not knot:
        print("Impossible")
    else:
        print("Possible")
        print(*knot[::-1], sep="\n")


Measured memory_bytes: 14620
#include<stdio.h>

int main()
{
    int n,i,flag;
    long long int num[4000],price[4000],ko[4000],sum[4001];

    while(scanf("%d",&n),n){

        flag=1;
        for(i=0;i<n;i++) scanf("%lld%lld%lld",&num[i],&price[i],&ko[i]);
        for(i=0;i<4001;i++) sum[i]=0;

        for(i=0;i<n;i++) sum[num[i]]+=price[i]*ko[i];
        for(i=0;i<n;i++){
            if(sum[num[i]]>=1000000){
                printf("%lld\n",num[i]);
                sum[num[i]]=0;
                flag=0;
            }   
        }   
        if(flag) puts("NA");
    }   
    return 0;
}

Measured memory_bytes: 680
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
using namespace std;

int main()
{
	string s[3];
	for (int i = 0; i < 3; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < 3; i++) {
		cout << s[i][i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

bool check(string s){
	rep(i,0,s.size()/2){
		if(s[i]!=s[s.size()-1-i]) return false;
	}
	return true;
}

signed main(){
	int n;
	cin>>n;
	int MIN=100000,ans=-1;
	rep(i,1,10002){
		stringstream ss;
		string s;
		ss<<i;
		ss>>s;
		if(check(s) && MIN>abs(n-i)){
			MIN=abs(n-i); ans=i;
		}
	}
	o(ans);
}

Measured memory_bytes: 1224
#include <iostream>
#include <iomanip>
#include <cmath>
#include <utility>
#include <cstdlib>
#include <string>		//string, .end(), .first() .size()
#include <algorithm>		//max(a,b) min(a,b) swap(a,b) sort(f,t) reverse(f,t) count(f,t,x) fill(f,t,x) sort(f,t greater<int>())
#include <queue>			//front(),priority_queue<int,vector<int>,greater<int>>
#include <stack>			//top()
#include <set> 			//.insert()
 
#define N_MAX 	100
#define W_MAX	10000

using namespace std;

int V[N_MAX+10][W_MAX+10];
pair<int , int>	Data[N_MAX+10];

int func(int i, int c){
	if(i <= 0 || c <= 0) return 0;
	return V[i][c];
}

void DispAns(int x,int y){
	for (int i = 0; i < x; ++i){
		for (int j = 0; j < y; ++j){
			cout << V[i][j] << " "; 
		}
		cout << endl;
	}
}

void solve(){
	int N,W;
	cin >> N >> W;
	for(int i = 1; i<=N; ++i) cin >> Data[i].first >> Data[i].second;
	for (int i = 0; i <= N; ++i){
		for (int j = 0; j <= W; ++j){
			if(j >= Data[i].second) V[i][j] = max(Data[i].first + func(i-1,j-Data[i].second),func(i-1,j));
			else V[i][j] = func(i-1,j);
		}
	}
	cout << V[N][W] << endl;
	// DispAns(N+1,W+1);
}

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

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

int main() {
    #ifdef LOCAL
    assert(freopen("b.in", "r", stdin));
    #else
    #endif
    int n, m;
    cin >> n >> m;
    vector<int> cnt(n, 1);
    vector<bool> can(n);
    can[0] = true;
    forn (i, m) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        if (can[x])
            can[y] = true;
        ++cnt[y];
        if (--cnt[x] == 0)
            can[x] = false;
    }
    int ans = 0;
    forn (i, n)
        if (can[i])
            ++ans;
    cout << ans << '\n';
}


Measured memory_bytes: 640
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string Yes[2] = {"Yes", "No"};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

using Graph = vector<vector<int>>;
Graph G;

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

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

    ll n, x, m; cin >> n >> x >> m;
    vector<ll> a(m + 2);
    vector<ll> sum(m + 2);
    vector<pair<bool,int>> seen(m + 2);
    a[0] = sum[0] = 0;
    a[1] = x;
    sum[1] = x;
    int bef_loop, aft_loop;
    for(int i = 1; i <= m; i++){
        seen[a[i]] = {true, i};
        a[i + 1] = (a[i] * a[i]) % m;
        if(seen[a[i + 1]].first){
            bef_loop = seen[a[i + 1]].second;
            aft_loop = i;
            break;
        }
        sum[i + 1] = sum[i] + a[i + 1];
        if(i + 1 == n){
            cout << sum[i + 1] << endl;
            return 0;
        }
        if(a[i + 1] == 0){
            cout << sum[i] << endl;
            return 0;
        }
    }
    //cout << bef_loop << " " << aft_loop << endl;
    ll ans = 0;
    ans += sum[bef_loop - 1];
    ll loop_num = n - bef_loop + 1;
    ll len = aft_loop - bef_loop + 1;
    ans += (sum[aft_loop] - sum[bef_loop - 1]) * (loop_num / len) + sum[bef_loop - 1 + loop_num % len] - sum[bef_loop - 1];
    cout << ans << endl;
}


Measured memory_bytes: 5572