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


int main()
{
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n)
  {
    cin >> a[i];
    a[i]--;
  }
  vector<int> c(n, -1);
  int crt = 0;
  int count = 0;
  while (c[crt] == -1)
  {
    c[crt] = count;
    crt = a[crt];
    count++;
    if (count == k)
    {
      cout << crt + 1 << endl;
      return 0;
    }
    if (c[crt] != -1)
      count -= c[crt];
  }
  k -= c[crt];
  k %= count;
  rep(i, n)
    if (c[i] - c[crt] == k)
    {
      cout << i + 1 << endl;
      return 0;
    }
  return 0;
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define l first
#define r second

using namespace std;

const int maxn = 3e5 + 1;

int n;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n; stack<int> st;
    int ans = 0, cc = 0, ld = 0;
    while (n) {
        ++cc; ans += n % 10;
        ld = n % 10; n /= 10;
    }
    ans = max(ans, (cc - 1) * 9 + ld - 1);
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
        double n1 = sc.nextDouble();
        double n2 = sc.nextDouble();
        if(n1 > n2){
        	System.out.println("GREATER");
        }else if(n1 < n2){
        	System.out.println("LESS");
        }else{
        	System.out.println("EQUAL");
        }
    }
}

Measured memory_bytes: 37332
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;

}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, E, F, K,L, W, H, P, Q, R, X, Y;
  ll ans;
  string S, T;
  cin >> S;
  rep(i, S.length()){
    if ((i+1)%2==0) {
      if(S[i]=='R'){
        cout <<"No" << endl;
        return 0;
      }
    }
    else {
      if(S[i]=='L'){
        cout <<"No" << endl;
        return 0;
      }
    }
  }
  cout <<"Yes" << endl;




}


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

void test();
string ReverseStr(string str);

int main(void)
{
	test();
	return 0;
}

void test()
{
	string s;

	cin >> s;

	s = ReverseStr(s);

	cout << s << endl;
}

string ReverseStr(string str)
{
	string s;
	int i, t;
	s = str;

	for (i = 0,t = str.size() - 1; i < str.size(); i++, t--)
	{
		str[i] = s[t];
	}

	return str;
}

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

typedef long long lint;
typedef long double louble;

const char lf = '\n';

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 303 , __ = _<<1;

int n,nn,ed[__][__]={0};

inline void make(int ps)
{
	int lg=0;
	while(ps%4==0)ps/=4,lg++;
	if(ps%4==1)
	{
		for(int i=1;i<=nn;i++)
			for(int j=1;j<=nn;j++)
				ed[i][j]|=(((i-1)>>lg)+((j-1)>>lg))&1;
	}
	else
	{
		for(int i=1;i<=nn;i++)
			for(int j=1;j<=nn;j++)
				ed[i][j]|=((i-1)>>lg)&1;
	}
}

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);
	
	n=ty(),nn=n+n,make(ty()),make(ty());
	int cnt=n*n;

	for(int i=1;i<=nn && cnt>0;i++)
		for(int j=1;j<=nn && cnt>0;j++)
			if(!ed[i][j])cout<<i-1<<' '<<j-1<<lf,cnt--;
	
	return 0;
}


Measured memory_bytes: 2304
N = int(input())
F = []
for i in range(N):
    f = list(map(int, input().split()))
    F.append(f)

P = []
for i in range(N):
    p = list(map(int, input().split()))
    P.append(p)

ans = (-10 ** 7) * 100 * 10

def f(a):
    if a.count(1) == 0:
        return
    prof = 0
    for i, fi in enumerate(F):
        c = 0
        for j in range(10):
            if a[j] == 1 and fi[j] == 1:
                c += 1
        prof += P[i][c]

    global ans
    ans = max(ans, prof)

def dfs(a):
    if len(a) == 10:
        f(a)
    else:
        dfs(a + [0])
        dfs(a + [1])

dfs([])
print(ans)

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, int> pli;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 200010;

int main(){
    int K, t;
    scanf("%d%d", &K, &t);
    int a[t];
    rep(i, t) scanf("%d", &a[i]);
    sort(a, a+t);
    printf("%d\n", max(0, a[t-1]-1-(K-a[t-1])));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
 /*   double t,x;
    cin>>t>>x;
    t=t/x;
    cout<<t*1.0<<'\n';*/
  
   /* int a,b,c;
    cin>>a>>b>>c;
    cout<<(a*b)/2<<'\n';*/

   /* int d;
    cin>>d;
    if(d==22){
        cout<<"Christmas Eve Eve Eve"<<'\n';
    }else if(d==23){
        cout<<"Christmas Eve Eve"<<'\n';
    }else if(d==24){
        cout<<"Christmas Eve"<<'\n';
    }else if(d==25){
        cout<<"Christmas"<<'\n';
    }*/

   /* int x,y;
    cin>>x>>y;
    y=y/2;
    cout<<x+y<<'\n';*/

    int n,a,b;
    cin>>n;
    if(n==1){
        cout<<"Hello World"<<'\n';
    }else{
        cin>>a>>b;
        cout<<a+b<<'\n';
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>

using namespace std;

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

int main(){
    string s,s1,s2;
    cin >> s;
    s1 = s.substr(0,4);
    s2 = s.substr(4,s.length()-1);
    cout << s1 << " " << s2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
//#define debug
//#define TRACE(x)

using namespace std;

typedef long long llint;

const int MAXN = 100010;
const llint INF = 1e18;

int n, t, e, x[MAXN];
llint f[MAXN], val[MAXN];

struct cmpf {
  bool operator()(const int& i, const int& j) {
    if (val[i] != val[j]) return val[i] < val[j];
    return i < j;
  }
};

set<int, cmpf> s1, s2;

int main(void) {
  scanf("%d %d %d",&n,&e,&t);
  REP(i, n) scanf("%d",&x[i]);

  int j = n - 1;
  
  for (int i = n - 1; i >= 0; --i) {
    val[i] = f[i+1] + t;
    s1.insert(i);
    
    for (; 2*(x[j] - x[i]) > t; --j) {
      s1.erase(j);
      val[j] = f[j+1] + 2*x[j];
      s2.insert(j);
    }

    f[i] = INF;
    if (!s1.empty()) f[i] = min(f[i], val[*s1.begin()]);
    if (!s2.empty()) f[i] = min(f[i], val[*s2.begin()] - 2*x[i]);
  }

  printf("%lld\n",f[0] + e);
  
  return 0;
}


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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)

int a, b;
bool can;

int main(void){
	cin>>a>>b;

	int ave = (a + b) / 2;
	if ((a + b) % 2 == 0) cout<< ave <<endl;
	else cout<< "IMPOSSIBLE" <<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
   int A,B,C;
   cin>>A>>B>>C;
  if(A>=0&&B>=0&&C!=0&&A>=B&&B<=20&&C<=20){
   if((B+C)>A){
       cout<<(B+C)-A;
   }
   if((B+C)<=A){
       cout<<0;
   }
   }
    return 0;
}

Measured memory_bytes: 3584
#include "stdio.h"

void countingSort(int input[], int output[], int input_size, int count_size){
  
  int* counter = new int [count_size];
  for(int i=0;i<count_size;i++){
    counter[i]=0;
  }
  
  for(int a=0;a<input_size;a++){
    counter[input[a]]++;
  }

  for(int i=1;i<count_size;i++){
    counter[i] = counter[i] + counter[i-1];
  }

  for(int a=input_size-1;a>=0;a--){
    output[counter[input[a]]-1] = input[a];
    counter[input[a]]--; 
  }

  delete [] counter;  

}

void outputMatrix(int matrix[], int N){
  for(int i=0;i<N;i++){
    if(i>0){
      printf(" ");
    }
    printf("%d", matrix[i]);
  }
  printf("\n");
}


int main(void){

  int N;
  scanf("%d", &N);

  int* input  = new int [N];
  int* output = new int [N]; 
  for(int i=0;i<N;i++){
    scanf("%d", &(input[i]));
  }

  int MAXSIZE = 20000;

  countingSort(input, output, N, MAXSIZE);
  outputMatrix(output, N);

  delete [] input;
  delete [] output;

  return 0;
}


Measured memory_bytes: 17868
{-# LANGUAGE BangPatterns #-}
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV

main=B.interact $ B.pack.g.take 2.B.lines
g [!s,!t]=mk "" (ls-1) (lt-1) where
    ls = B.length s
    lt = B.length t
    rd si ti = (aa V.! si) UV.! ti
    mk !as si ti
        | si<0 || ti<0 = as
        | B.index s si == B.index t ti = mk (B.index s si : as) (si-1) (ti-1)
        | rd (si+1) ti > rd si (ti+1) = mk as si (ti-1)
        | otherwise = mk as (si-1) ti
    aa :: V.Vector (UV.Vector Int)
    aa = V.scanl' p (UV.replicate (lt+1) 0) $ V.enumFromTo 1 ls where
        p v0 i = UV.scanl' m 0 $ UV.enumFromTo 1 lt where
            m pj j = if B.index s (i-1) == B.index t (j-1)
                then 1 + v0 UV.! (j-1)
                else max pj $ v0 UV.! j

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

#define _LL long long
#define rep(i, n) for(_LL i = 0; i < (_LL)(n); i++)

_LL gcd(_LL a, _LL b)
{
    if( b == 0 ) return a;
    return gcd(b, a % b);
}

int main()
{
    _LL n, x, d;
    cin >> n >> x >> d;

    if( d == 0 )
    {
        if( x == 0 )
        {
            cout << 1 << endl;
        }
        else
        {
            cout << n + 1 << endl;            
        }    

        return 0;
    }

    _LL g = gcd(x, d);
    x /= g; d /= g;
    map<_LL, vector<pair<_LL, _LL>>> mlist;

    // i個選ぶ場合
    rep(i, n + 1)
    {
        _LL m = (x * i) % d;
        if( m < 0 ) m += d;
        _LL k = (x * i - m) / d;
        _LL mint = (i - 1LL) * i / 2LL + k; 
        _LL maxt = ((n - i) + ( n - 1LL )) * i / 2LL + k;
//        cout << i << ":" << mint << "," << maxt << endl;
        mlist[m].push_back(make_pair(min(mint, maxt), -1));
        mlist[m].push_back(make_pair(max(mint, maxt) + 1LL, 1));
    }

    _LL ans = 0;
    for(auto itr = mlist.begin(); itr != mlist.end(); ++itr) 
    {
        sort(itr->second.begin(), itr->second.end());
        _LL count = 0;
        _LL pre = 0;
        for( auto itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++ )
        {
            if( count < 0 ) ans += itr2->first - pre;
            count += itr2->second;
            pre = itr2->first;
//            cout << itr2->first << "," << itr2->second << " : " << ans << endl;
        }
    }
    cout << ans << endl;
}

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

struct Job {
    long long A;
    long long B;
};

bool cmp(const Job &a, const Job &b) {
    return a.B < b.B;
}

int main() {
    cin >> N;
    vector<Job> job(N);
    long long total = 0;
    long long max = 0;
    for(long long i = 0; i < N; ++i) {
        cin >> job.at(i).A >> job.at(i).B;
    }

    sort(job.begin(), job.end(), cmp);

    for(int i = 0; i < N; ++i) {
        total += job.at(i).A;
        if(total > job.at(i).B) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

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

string s[1000];
int N, dx[] = {0, 1, 1, -1}, dy[] = {1, 0, 1, 1};

int search(int sx, int sy, int dx, int dy)
{
	int n = 0;
	int x = sx, y = sy;
	while(x >= 0 && x < N && y >= 0 && y < N && s[y][x] == '1')
	{
		n++;
		x += dx; y += dy;
	}
	return n;
}

int main() {
loop:
	cin >> N;
	if(!N)
	return 0;
	for(int i = 0; i < N; i++)
		cin >> s[i];
		
	int a = 0;
	for(int y = 0; y < N; y++)
	{
		for(int x = 0; x < N; x++)
		{
			for(int i = 0; i < 4; i++)
				a = max(a, search(x, y, dx[i], dy[i]));	
		}
	}
	cout << a << endl;
	goto loop;
}

Measured memory_bytes: 1300
n = int(input())
a = list(map(int, input().split()))
ans = 0
if n <= 2:
    print(1)
    exit()
pre = a[1] - a[0]
i = 2
while i < n:
    if pre * (a[i] - a[i-1]) < 0:
        ans += 1
        pre = 0
        i += 1
        if i == n:
            break
    if a[i] != a[i-1]:
        pre = a[i] - a[i-1]
    i += 1
print(ans + 1)


Measured memory_bytes: 14224
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		long n = sc.nextLong();
		
		// 計算
		long result = 1;
		int MOD = 1000000007;
		for(long i = 1; i <= n; i++){
		    result *= i;
		    result %= MOD;
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



Measured memory_bytes: 19284
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll a[maxn],n,tot;
const ll mod=1000000007;

inline ll pw(ll a,ll b)
{
	ll ans=1,base=a;
	while(b)
	{
		if(b&1) ans=(ans*base)%mod;
		base=(base*base)%mod; b>>=1;
	}
	return ans;
}

int main()
{
	n=read(); rep(i,1,n) a[i]=read(),tot=(tot+a[i])%mod;
	tot=(tot*tot)%mod;
	rep(i,1,n)
	{
		ll tmp=(a[i]*a[i])%mod;
		tot=(tot-tmp+mod)%mod;
	}
	ll p=pw(2,mod-2); tot=(tot*p)%mod; cout<<tot<<endl;
	return 0;
}

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

int main()
{
  int n, m, ans = 0;
  map<string, int> mp;
  cin >> n;
  rep(i, n)
  {
    string s;
    cin >> s;
    mp[s]++;
  }
  cin >> m;
  rep(i, m)
  {
    string s;
    cin >> s;
    mp[s]--;
  }
  for (auto x : mp)
  {
    ans = max(ans, x.second);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S,T;
    cin >> S >> T;
    int chk=T.size();
    int ans=chk;
    int count=0;
    for(int i=0; i<S.size()-T.size()+1; i++)
    {
        for(int j=0; j<chk; j++)
        {
            if(T.at(j)!=S.at(i+j))
            {
                count++;
            }
        }
        if(ans>count)
        {
            ans=count;
        }
        count=0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] c = sc.next().toCharArray();
		
		Arrays.sort(c);
		if (c[0] != 'a') System.out.println("No");
		else if (c[1] != 'b') System.out.println("No");
		else if (c[2] != 'c') System.out.println("No");
		else System.out.println("Yes");
	}
}


Measured memory_bytes: 21716
#include<iostream>
using namespace std;
int main(){
int h,w;
while(true){
  cin >>h>>w;
  if(h==0&&w==0){
    break;
  }else{
  for(int i=0;i<h;i++){
    for(int k=0;k<w;k++){
      if(k==0||i==0||i==h-1){
        cout <<"#";
      }else if(k==w-1){
        cout <<"#";
      }else{
        cout <<".";
      }
    }
    cout <<endl;
  }
  }
  cout <<endl;
}
return 0;
}

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

void chess1(int len){
  for(int i=0;i<len;i++){
    if(i%2==0){
      cout<<"#";
    }else{
      cout<<".";
    }
  }
  cout<<endl;
}

void chess2(int len){
  for(int i=0;i<len;i++){
    if(i%2==1){
      cout<<"#";
    }else{
      cout<<".";
    }
  }
  cout<<endl;
}


int main(){
  int H,W;
  int i,j;
  while(1){
    cin>>H>>W;
    if(H==0 && W==0) break;

   for(i=0;i<H;i++){
    if(i%2==0){
      chess1(W);
    }else{
      chess2(W);
    }
   }
   cout<<endl;
  }

  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

#define PB push_back
#define ALL(v) (v).begin(), (v).end()
#define SZ size()
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define REP(i, n) FOR((i), 0, (n))
#define GET(a) cin >> (a)
#define GET2(a, b) cin >> (a) >> (b)
#define GET3(a, b, c) cin >> (a) >> (b) >> (c)
#define SHOW(v) cout << (v) << endl
#define SHOW2(a, b) cout << (a) << " " << (b) << endl
#define SHOW3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define MOD 1000000007
template<class T> void GETV(T &v) { REP(i, v.size()) { GET(v[i]); } }
template<class T> void SHOWV(T &v) { REP(i, v.size()) { SHOW(v[i]); } }

typedef long long ll;


int main()
{
	int n, k;
	cin >> n >> k;
	
	if((n / 2) + (n % 2) >= k) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	
    return 0;
}

Measured memory_bytes: 256
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define pb push_back
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rii(x,y) ri(x), ri(y)
#define rll(x,y) rl(x), rl(y)

#define fst first
#define snd second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

const int MAXN = 1e5+5;
const ll MOD = 1e9+7;

ll sq(ll x){return x*x%MOD;}
ll powah(ll b, ll e){
	if(!e) return 1;
	return sq(powah(b,e>>1)) * (e&1? b : 1) %MOD;
}

ll fact[MAXN], ifact[MAXN];
int n, a[MAXN], seen[MAXN];


int main(){
	fact[0] = 1;
	FOR(i,1,MAXN) fact[i]=(i*fact[i-1])%MOD;
	ifact[0] = 1;
	FOR(i,1,MAXN) ifact[i]=powah(fact[i], MOD-2);
	ri(n);
	ms(seen,-1);
	int rest;
	FOR(i,0,n+1){
		ri(a[i]);
		if(seen[a[i]]!=-1){
			rest = n-i + seen[a[i]];
		}else{
			seen[a[i]] = i;
		}
	}
	FOR(k,1,n+2){
		ll ret = (fact[n+1]*ifact[k]%MOD)*ifact[n+1-k]%MOD;
		if(rest >= k-1) ret = (ret - (fact[rest]*ifact[k-1]%MOD)*ifact[rest-k+1]%MOD);
		ret = (ret%MOD + MOD)%MOD;
		printf("%lld\n",ret);
	}
}

Measured memory_bytes: 3584
#include <stdio.h>

#define INF 100000000
#define MAX_N 1000000

typedef struct {
	int num;
	int max;
	int last;
} FIELD;

int isPrime[ MAX_N + 1 ] = { 0, 0, 1 }, corner[ 1998 ] = { 2 }, coord[ 1000001 ], m;
FIELD field[ 1002 ][ 1001 ];
const int dx[ 7 ] = { 1, 0, -1 , 0, -1, 0, 1 }, dy[ 7 ] = { 0, -1, 0, 1, 1, 1, 1 };

void dfs( int, int );

int main( void ) {
	int i, j, add, x, y, d, cnt, n;

	for ( i = 3; i <= MAX_N; i += 2 )
		isPrime[ i ] = 1;

	for ( i = 3; i * i <= MAX_N; i += 2 )
		if ( isPrime[ i ] )
			for ( j = i * 2; j <= MAX_N; j += i )
				isPrime[ j ] = 0;

	add = 1;
	for ( i = 1; i < 1998; i++ ) {
		corner[ i ] = corner[ i - 1 ] + add;
		add += i & 1;
	}

	x = y = 500;
	d = cnt = 0;
	for ( i = 1; i <= 1000000; i++ ) {
		coord[ i ] = x * 1001 + y;
		field[ x ][ y ].num = i;

		if ( i == corner[ cnt ] ) {
			d = d + 1 & 3;
			cnt++;
		}

		x += dx[ d ];
		y += dy[ d ];
	}

	for ( x = 1002; x--; field[ x ][ 1000 ].num = INF ) ;
	for ( y = 1001; y--; field[ 0 ][ y ].num = field[ 1001 ][ y ].num = INF ) ;

	for ( ; scanf( "%d %d", &m, &n ), m; printf( "%d %d\n", field[ x ][ y ].max, field[ x ][ y ].last ) ) {
		for ( i = m; i; i-- ) {
			field[ x = coord[ i ] / 1001 ][ y = coord[ i ] % 1001 ].max = INF;
			field[ x ][ y ].last = 0;
		}

		dfs( x = coord[ n ] / 1001, y = coord[ n ] % 1001 );
	}

	return 0;
}

void dfs( int x, int y ) {
	int i;

	field[ x ][ y ].max = 0;
	for ( i = 7; i-- > 4;  ) {
		int nx = x + dx[ i ], ny = y + dy[ i ];

		if ( field[ nx ][ ny ].num <= m ) {
			if ( field[ nx ][ ny ].max == INF )
				dfs( nx, ny );

			if ( field[ x ][ y ].max < field[ nx ][ ny ].max ) {
				field[ x ][ y ].max = field[ nx ][ ny ].max;
				field[ x ][ y ].last = field[ nx ][ ny ].last;
			} else if ( field[ x ][ y ].max == field[ nx ][ ny ].max && field[ x ][ y ].last < field[ nx ][ ny ].last )
				field[ x ][ y ].last = field[ nx ][ ny ].last;
		}
	}

	if ( isPrime[ field[ x ][ y ].num ] ) {
		if ( !field[ x ][ y ].max )
			field[ x ][ y ].last = field[ x ][ y ].num;

		field[ x ][ y ].max++;
	}
}

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T>
constexpr T INF = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 2;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define ALL(v) (v).begin(), (v).end()

template<typename T>
istream& operator>>(istream& in, vector<T>& a) { for (T& x : a) in >> x; }

void LOG(int x) { cerr << x << "\n"; }
void LOG(vector<int>& a) { for (int x : a) cerr << x << " "; cerr << "\n"; }

int ceil(int a, int b) { return (a - 1) / b + 1; }

struct InitCpp { InitCpp() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
} } initCpp;

int F[102][10];
int P[102][11];
signed main() {
  int n;
  cin >> n;
  REP(i, n) REP(j, 10) cin >> F[i][j];
  REP(i, n) REP(j, 11) cin >> P[i][j];
  int res = -INF<int>;
  FOR(b, 1, 1 << 10) {
    int s = 0;
    REP(i, n) {
      int c = 0;
      REP(j, 10) {
        c += (b >> j) & F[i][j];
      }
      s += P[i][c];
    }
    res = max(res, s);
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int X, Y;

void solve() {
	cin >> X >> Y;
	if(X == 1 && Y == 1) {
		cout << 1000000 << "\n";
	}
	else {
		int a = 0, b = 0;
		if(X == 1) a = 300000;
		else if(X == 2) a = 200000;
		else if(X == 3) a = 100000;
		if(Y == 1) b = 300000;
		else if(Y == 2) b = 200000;
		else if(Y == 3) b = 100000;
		cout << a + b << "\n";
	}
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
{-# LANGUAGE BangPatterns, OverloadedStrings #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import qualified Data.Set as S
import System.IO.Unsafe
import Debug.Trace

unew :: VUM.Unbox a => Int -> VUM.IOVector a
unew !n = accursedUnutterablePerformIO $ VUM.unsafeNew n

uread :: VUM.Unbox a => Int -> VUM.IOVector a -> a
uread !i !v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VUM.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite !i !a !v =
  accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

uthaw :: VUM.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw !v = accursedUnutterablePerformIO $ VU.unsafeThaw v

ufreeze :: VUM.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze !v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

uset :: VUM.Unbox a => a -> VUM.IOVector a -> VUM.IOVector a
uset !a !v = accursedUnutterablePerformIO $ VUM.set v a >> return v

solve :: B.ByteString -> B.ByteString -> B.ByteString
solve !s !t = walk
 where
  toIndex !i !j = j * succ (B.length s) + i

  ifoldlB :: (a -> Int -> Char -> a) -> a -> B.ByteString -> a
  ifoldlB !f !x !bs = snd $ B.foldl'
    ( \(!i, !acc) !ch ->
      let i'   = i + 1
          acc' = f acc i ch
      in  i' `seq` acc' `seq` (i', acc')
    )
    (0, x)
    bs

  dp :: VU.Vector Int16
  dp = ufreeze $ ifoldlB
    ( \(!dp) !i !si -> ifoldlB
      ( \(!dp) !j !tj -> uwrite
        (toIndex (i + 1) (j + 1))
        ( if si == tj
          then uread (toIndex i j) dp + 1
          else max (uread (toIndex (i + 1) j) dp) (uread (toIndex i (j + 1)) dp)
        )
        dp
      )
      dp
      t
    )
    ( foldl'
      (\(!dp) (!i) -> uwrite (toIndex i 0) 0 $ uwrite (toIndex 0 i) 0 dp)
      (unew $ succ (B.length s) * succ (B.length t))
      [0 .. B.length s]
    )
    s

  walk =
    fst
      $ B.unfoldrN (fromIntegral $ dp VU.! toIndex (B.length s) (B.length t))
                   (\(x:xs) -> Just $ (,) (B.index s x) xs)
      $ fst
      $ fix
          ( \(!f) (!acc, (!i, !j)) -> if i == 0 || j == 0
            then (acc, (i, j))
            else if s `B.index` (i - 1) == t `B.index` (j - 1)
              then f ((i - 1) : acc, (i - 1, j - 1))
              else if dp VU.! toIndex (i - 1) j < dp VU.! toIndex i (j - 1)
                then f (acc, (i, j - 1))
                else f (acc, (i - 1, j))
          )
          ([], (B.length s, B.length t))

main = do
  s <- B.getLine
  t <- B.getLine
  B.putStrLn $ solve s t


Measured memory_bytes: 19452
#include<stdio.h>

int main(void){
  int n,i;
  int fib[44];
  
  scanf("%d",&n);

  fib[0] = 1;
  fib[1] = 1;

  i = 2;
  while(i <= n){
    fib[i] = fib[i-1]+fib[i-2];
    i++;
  }
  printf("%d",fib[n]);
  puts("");

  return 0;
}
       



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<=(int)k;i++)
#define per(i,j,k) for(int i=(int)j;i>=(int)k;i--)
using namespace std;
typedef long long LL;
const int N=2005;
const int P=1000000007;
inline int Pow(int a,int b){
    int c=1;
    for(;b;b>>=1,a=a*1ll*a%P)if(b&1)c=c*1ll*a%P;
    return c;
}
inline void add(int &a,int b){a+=b;if(a>=P)a-=P;}
inline void dec(int &a,int b){a-=b;if(a<0)a+=P;}
int n,k;
int C[2*N][2*N];
int f[N][N];
int main(){
    scanf("%d%d",&n,&k);
    rep(i,0,2*n){
        C[i][0]=C[i][i]=1;
        rep(j,1,i-1){
            C[i][j]=C[i-1][j];
            add(C[i][j],C[i-1][j-1]);
        }
    }
    f[0][0]=1;
    rep(i,0,n){
        if(i){rep(j,1,n)add(f[i][j],f[i][j-1]);}
        rep(j,0,n)if(f[i][j]){
            dec(f[i+1][j+2],f[i][j]);
            add(f[i+1][1],f[i][j]);
        }
    }
    if(n==k){
        int ans=0;
        rep(i,0,n-1)add(ans,f[n-1][i]);
        printf("%d\n",ans);
        return 0;
    }
    int ans=0;
    rep(i,n-k+1,n){
        rep(j,0,n-i){
            add(ans,(f[n-i][j]*1ll*C[i-1-(n-k)+j][j]%P)*1ll*C[i-2][n-k-1]%P);
        }
        //printf("__%d\n",ans);
    }
    ans=ans*1ll*Pow(2,n-k-1)%P;
    printf("%d\n",ans);
    return 0;
}





Measured memory_bytes: 78592
//A code
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define vec vector < ll >
#define pb push_back
#define po pop_back
#define f(i,x,n) for(ll i=x;i<n;i++)
#define rf(i,x,n) for(ll i = x; i >= n; i--)
#define all(c) c.begin(),c.end()
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 2e3 + 10; 
int main()
{   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s,t; cin>>s>>t;
  ll flag =0;
    f(i,0,s.length()){
    	if(s[i]!=t[i]) flag=1;
    }
    if(s.length()+1 != t.length()){
    	cout<<"No\n";
    	return 0;
    }
    flag ? cout<<"No\n" : cout<<"Yes\n";
}

Measured memory_bytes: 3656
from collections import deque

K = int(input())
d = deque([1,2,3,4,5,6,7,8,9])
ansq = deque([1,2,3,4,5,6,7,8,9])

while len(ansq)<=K:
    num = d.popleft()

    if str(num)[-1] == "0":
        d.append(num*10)
        d.append(num*10+1)
        ansq.append(num*10)
        ansq.append(num*10+1)
        continue

    if str(num)[-1] == "9":
        d.append(num*10+8)
        d.append(num*10+9)
        ansq.append(num*10+8)
        ansq.append(num*10+9)
        continue

    d.append(num*10+int(str(num)[-1])-1)
    d.append(num*10+int(str(num)[-1]))
    d.append(num*10+int(str(num)[-1])+1)
    ansq.append(num*10+int(str(num)[-1])-1)
    ansq.append(num*10+int(str(num)[-1]))
    ansq.append(num*10+int(str(num)[-1])+1)
    
print(ansq[K-1])

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//bool f[100001];//1000000以下の素数を調べよう！
//rrep(i,2,100001){
  //      f[i]=false;
    //}
//rrep(i,2,100001){
  //      if(!f[i]){
    //        for(int j=i+i;j<=100000;j+=i){
      //          f[j]=true;
        //    }
        //}
    //}
    //for(int i=3;i<=100000;i+=2){
      //  if(!f[i]){
        //    c[i]++;
      //  }
   // }

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

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

       cin >> n >> y;
       rep(i,n+1){
           rep(j,n-i+1){
               if(10000*i+5000*j==y-1000*(n-i-j)){
                   if(n-i-j>=0){
                   cout << i << " " << j << " " << n-i-j << endl;
                   return 0;
                   }
               }
           }
       }
       cout << -1 << " " << -1 << " " << -1 << endl;
       
return 0;
}


Measured memory_bytes: 256
N=int(input())
c=[[0]*10 for i in range(10)]
for n in range(1,N+1):
    c[int(str(n)[0])][int(str(n)[-1])]+=1
sum=0
for i in range(10):
    for j in range(10):
        sum+=c[i][j]*c[j][i]
print(sum)


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

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



	for (int i = 0; i < k; i++) {
		if (a >= b) {
			b *= 2;
		}
		else if (b >= c) {
			c *= 2;
		}
	}

	if (a < b&&b < c) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 3632
def d_lamp(H, W, Grid):
    field_horizontal = [[0] * W for _ in range(H)]
    field_vertical = [[0] * W for _ in range(H)]
    field = [[0] * W for _ in range(H)]

    for row in range(H):
        tmp = 0
        for col in range(W):
            if Grid[row][col] == '.':
                tmp += 1
                field_horizontal[row][col] = tmp
            else:
                tmp = 0
        max_val = 0
        for col in range(W - 1, -1, -1):
            if Grid[row][col] == '.':
                max_val = max(max_val, field_horizontal[row][col])
                field_horizontal[row][col] = max_val
            else:
                max_val = 0

    for col in range(W):
        tmp = 0
        for row in range(H):
            if Grid[row][col] == '.':
                tmp += 1
                field_vertical[row][col] = tmp
            else:
                tmp = 0
        max_val = 0
        for row in range(H - 1, -1, -1):
            if Grid[row][col] == '.':
                max_val = max(max_val, field_vertical[row][col])
                field_vertical[row][col] = max_val
            else:
                max_val = 0

    for row in range(H):
        for col in range(W):
            field[row][col] = field_horizontal[row][col] + field_vertical[row][col]

    ans = 0
    for row in range(H):
        for col in range(W):
            ans = max(ans, field[row][col])

    return max(ans - 1, 0)

H, W = [int(i) for i in input().split()]
Grid = [input() for _ in range(H)]
print(d_lamp(H, W, Grid))

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

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

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)2e5+111;
ll const LG=(ll)log2(N)+1;



void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        cin>>n>>k;
        vll a(n);
        for(i=0;i<n;i++){
                cin>>a[i];
        }
        sort(all(a));
        ll an=0;
        for(i=0;i<k;i++){
                an+=a[i];
        }
        cout<<an<<endl;
        
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}


Measured memory_bytes: 3624
// yo1.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include <bits/stdc++.h>

using namespace std;

int main()
{
	int a[6], ans = 0;
	for (int i = 0; i < 6; ++i) {
		cin >> a[i];
	}
	sort(a, a + 4);
	sort(a + 4, a + 6);

	for (int i = 1; i < 4; ++i) {
		ans += a[i];
	}
	ans += a[5];
	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3088
N = int(input())
a = list(map(int, input().split()))
minN = 0
ans = 0
temp = 0
cnt = 0
i = 1
while i < N:
    minN = min(a[i - 1], a[i])
    if a[i] == minN:
        cnt += 1
    if a[i] != minN or i == N - 1:
        if cnt > temp:
            ans = max(cnt, temp)
            temp = ans
        cnt = 0
    i += 1

print(ans)


Measured memory_bytes: 14224
// AOJ 2383: Rabbit Game Playing
// 2017.10.4 bal4u@uu
// 2017.11.12

#include <stdio.h>
#include <stdlib.h>

#define M 1000000007
int d[100002], n;

int cmp(int *a, int *b) { return *a - *b; }

int bsch(int x)
{
	int m, l = 0, r = n;

    while (l < r) {
        m = (l + r) >> 1;
        if (d[m] < x) l = m + 1; else r = m;
    }
	return l;
}

char buf[20], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int t, i;
	long long ans;

	fgets(p=buf, 20, stdin);
	n = getint(), p++, t = getint();
	for (i = 0; i < n; i++) fgets(p=buf, 10, stdin), d[i] = getint();
    qsort(d, n, sizeof(int), cmp);
    for (ans = 1, i = 0; i < n; i++) ans = (ans * (i+1-bsch(d[i]-t))) % M;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 2328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, u, d;
vector<ll> x, ans;

int main()
{
	scanf("%lld",&n);
	while(n > 1) {
		if(n%2) {x.push_back(1); n /= 2;}
		else {x.push_back(0); n--;}
	}
	reverse(x.begin(), x.end());
	ans.push_back(0);
	for(auto &T : x) {
		if(T) ans.push_back(++u);
		else ans.push_back(--d);
	}
	printf("%d\n",2*ans.size());
	for(ll i=0;i<ans.size();i++) printf("%lld ", i+1);
	for(ll i=0;i<ans.size();i++) printf("%lld ", ans[i]-d+1);
}


Measured memory_bytes: 256
N=input()
n=int(N)
N3=[int(x) for x in list(N)]
#n=int(N)
if n<10:
    print(n)
    exit()
else:
    ans=sum(N3)
    for i in range(len(N)-1):
        N2=int(N[:i+1])-1
        
        N1=[int(x) for x in list(str(N2))]
        ans=max(ans,sum(N1)+9*(len(N)-i-1))
    print(ans)

Measured memory_bytes: 3068
process.stdin.resume();
process.stdin.setEncoding("utf8");

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const lines = [];

reader.on("line", (line) => {
  lines.push(line);
});

reader.on("close", () => {
  const n = Number(lines[0]);
  let out = "";
  for (let i = 1; i <= n; i++) {
    let x = i;
    if (x % 3 === 0) {
      out += ` ${i}`;
    } else {
      while (x) {
        if (x % 10 === 3) {
          out += ` ${i}`;
          break;
        }
        x = Math.floor(x / 10);
      }
    }
  }
  console.log(out);
});



Measured memory_bytes: 18432
s = input()

first = int(s[:2])
second = int(s[2:])

def can_be_month(x):
    if 1 <= x <= 12:
        return True
    else:
        return False

if can_be_month(first) and can_be_month(second):
    print("AMBIGUOUS")
elif can_be_month(first) and not can_be_month(second):
    print("MMYY")
elif not can_be_month(first) and can_be_month(second):
    print("YYMM")
else:
    print("NA")


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

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int n, k, r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p;
    cin >> t;
    ll ans = 0;

    vector<vector<int> > num(k);
    rep(i, t.size()) {
        num[i % k].emplace_back(t[i]);
    }

    rep(i, k) {
        int mae = 1000;
        rep(j, num[i].size()) {
            if (mae == num[i][j]) {
                mae = 100;
                continue;
            }
            if (num[i][j] == 'r') ans += p;
            if (num[i][j] == 's') ans += r;
            if (num[i][j] == 'p') ans += s;
            mae = num[i][j];
        }
    }

    cout << ans << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 8348
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int n;
	while(scanf("%d", &n)==1)
	{
		vi l(n);

		for(int i=0;i<n;i++) scanf("%d", &l[i]);

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

		ll ans=0LL;
		for(int i=0;i+2<n;i++)
		{
			for(int j=i+1;j+1<n;j++)
			{
				auto it=lower_bound(l.begin()+j+1, l.end(), l[i]+l[j]);
				ans+=it-(l.begin()+j+1);
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 256