akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0)
const double Pi=3.14159265;
const int N=1e4+5;
const ull base=163;
const int INF=0x3f3f3f3f;
using namespace std;
int main(){
    string s;cin>>s;
    ll x;cin>>x;
    int now=0;
    for(int i=0;s[i];++i){
        if(s[i]!='1'){
            now=i;
            break;
        }
    }
    if(now==0&&s[0]=='1')now=s.size();
    if(x<=now)cout<<1;
    else cout<<s[now];
    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

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

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

  cout << "-1 -1 -1";
}

Measured memory_bytes: 3612
import java.util.*;

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

        int A = sc.nextInt();
        int B = sc.nextInt();
        String S = sc.next();

        for(int i=0; i<A+B+1; i++){
            if(i==A && !S.substring(i,i+1).equals("-")){
                System.out.println("No");
                break;
            }
            else if(i!=A && S.substring(i,i+1).equals("-")){
                System.out.println("No");
                break;
            }
            if(i==A+B){
                System.out.println("Yes");
            }
        }
    } 
}

Measured memory_bytes: 23764
H, W = map(int, input().split())
S = [[c == "." for c in input()] for _ in range(H)]
to_right = [[0] * W for _ in range(H)]
to_left = [[0] * W for _ in range(H)]
for i in range(H):
    right = 0
    left = 0
    for j in range(W):
        if S[i][j]:
            right += 1
        else:
            right = 0
        to_right[i][j] = right
        if S[i][-(j + 1)]:
            left += 1
        else:
            left = 0
        to_left[i][-(j + 1)] = left
to_bottom = [[0] * W for _ in range(H)]
to_top = [[0] * W for _ in range(H)]
for j in range(W):
    bottom = 0
    top = 0
    for i in range(H):
        if S[i][j]:
            bottom += 1
        else:
            bottom = 0
        to_bottom[i][j] = bottom
        if S[-(i + 1)][j]:
            top += 1
        else:
            top = 0
        to_top[-(i + 1)][j] = top
ans = 0
for i in range(H):
    right = 0
    left = 0
    for j in range(W):
        if not S[i][j]:
            continue
        ans = max(ans, sum((to_right[i][j], to_left[i][j], to_bottom[i][j], to_top[i][j])))
print(ans - 3)

Measured memory_bytes: 195720
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int main() {
    string s; cin >> s;
    bool c_flag = false;
    rep(i,s.size()){
        if (i==0){
            if(s[0] != 'A'){
                print("WA");
                return 0;
            }
            continue;
        }
        if (2 <= i && i <= s.size()-2){
            if (s[i] == 'C'){
                if (c_flag){
                    print("WA");
                    return 0;
                }
                c_flag = true;
                continue;
            }
        }
        if (s[i] < 'a'){
            print("WA");
            return 0;
        }
    }
    if (c_flag){
        print("AC");
    }else{
        print("WA");
    }
}

Measured memory_bytes: 256
from collections import defaultdict

n = int(input())
ns = defaultdict(int)

for i in range(1, n + 1):
    ns[(str(i)[0], str(i)[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += ns[(str(i), str(j))] * ns[(str(j), str(i))]
print(ans)


Measured memory_bytes: 73640
#include <iostream>

using namespace std;

int main() {
    int n;

    cin >> n;

    int a[100010], count[100010] = {0};

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

    if (n%2 == 1) {
        count[0]++;
    }

    for (int i = (n+1)%2; i < n; i += 2) {
        if (count[i] != 2) {
            cout << 0 << endl;
            return 0;
        }
    }

    long long ans = 1;

    for (int i = 0; i < n/2; i++) {
        ans *= 2;
        ans %= 1000000007;
    }

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


Measured memory_bytes: 1024
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    A, B = MI()

    for N in range(1, 10**5):
        if int(N * 0.08) == A and int(N * 0.1) == B:
            print(N)
            return

    print(-1)
    # print(low, high)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38764
#include<stdio.h>

typedef long long int llu;

llu max(llu a, llu b) {
    return (a < b) ? b : a;
}

int main() {
    int N, W;
    scanf("%d%d", &N, &W);

    // INITIALIZE
    llu dp[W+1];
    for (int j = 0; j <= W; ++j) {
        dp[j] = 0;
    }

    // DP
    int w, v;
    for (int i = 0; i < N; ++i) {
        scanf("%d%d", &w, &v);
        for (int j = W; j >= w; --j) {
            dp[j] = max( dp[j-w] + v , dp[j] );
        }
    }

    // OUTPUT
    printf("%llu\n", dp[W]);
}

Measured memory_bytes: 896
#include<iostream>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
const ll INF=1e9;

main(){
  ll N;
  cin >> N;
  ll h[N];
  for(ll ii=0;ii<N;ii++)cin >> h[ii];
  ll dp[N+3];
  for(ll ii=0;ii<=N+1;ii++)dp[ii]=INF;
  dp[0]=0;
  for(ll ii=0;ii<N-1;ii++){
    if(ii==0)dp[ii+1]=min(dp[ii+1],dp[ii]+abs(h[ii+1]-h[ii]));
    dp[ii+2]=min(dp[ii+2],min(dp[ii]+abs(h[ii+2]-h[ii]),dp[ii+1]+abs(h[ii+2]-h[ii+1])));
  }
  cout << dp[N-1] << endl;
  //for(ll ii=0;ii<=N;ii++)cout << dp[ii] << endl;
}


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

int N, A, B, num[37], cumsum[37];

int main() {
    cin >> N >> A >> B;

    for (int i = 1; i <= N; ++i) {
        int j = i, sum = 0;

        while (j) {
            sum += j % 10;
            j /= 10;
        }

        num[sum] += i;
    }

    cumsum[0] = num[0];

    for (int i = 1; i <= 36; ++i) {
        cumsum[i] = cumsum[i - 1] + num[i];
    }

    if (A == 0) {
        cout << cumsum[B] << endl;
    } else {
        cout << cumsum[B] - cumsum[A - 1] << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

int main() {
    char a[11], b[11], c[11];
    scanf("%s %s %s", a, b, c);
    if (a[strlen(a) - 1] == b[0] && b[strlen(b) - 1] == c[0]) {
        puts("YES");
    }
    else {
        puts("NO");
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N, K; std::cin >> N >> K;
  // start graph : max (N-1)(N-2)/2
  int M = (N-1)*(N-2)/2;
  if ( K > M ) {
    std::cout << -1 << std::endl;
    return 0;
  } 

  std::vector<std::pair<int,int>> ans;
  for(int i=2; i<=N; i++) ans.push_back( {1, i} );

  int k = 0;
  for(int i=2; i<=N; i++) {
    for(int j=i+1; j<=N; j++) {
      if ( k == M - K ) {
        std::cout << sz(ans) << std::endl;
        rep(z,sz(ans)) std::cout << ans[z].first << " " << ans[z].second << std::endl;
        return 0;
      }
      ans.push_back( {i, j} );
      k++;
    }
    if ( k == M - K ) {
      std::cout << sz(ans) << std::endl;
      rep(z,sz(ans)) std::cout << ans[z].first << " " << ans[z].second << std::endl;
      return 0;
    }
  }

  std::cout << -1 << std::endl;

  return 0;
}


Measured memory_bytes: 384
def swap(a,i,j):
	t=a[i]
	a[i]=a[j]
	a[j]=t

def partition(a,p,r):
	x=a[r]
	i=p-1
	for j in range(r):
		if a[j]<=x:
			i+=1
			swap(a,i,j)
	swap(a,i+1,r)
	return i+1

n=int(input())
a=list(map(int,input().split()))
p=partition(a,0,n-1)
for i in range(n):
	if i==p:print('[',end='')
	print(a[i],end='')
	if i==p:print(']',end='')
	if i!=n-1:print(' ',end='')
print()



Measured memory_bytes: 16392
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    a,b = input().split()
    a = int(a)
    b = round(float(b) * 100)
    ans = a * b // 100
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68992
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int ans = 0;
        if (2 * c < a && 2 * c < b) {
            int p = Math.max(x, y);
            ans = 2 * p * c;
        } else if (2 * c < a) {
            int p = Math.max(0, y - x);
            ans = 2 * x * c + b * p;
        } else if (2 * c < b) {
            int p = Math.max(0, x - y);
            ans = 2 * y * c + a * p;
        } else if (2 * c < a + b) {
            if (x < y) {
                ans += 2 * x * c;
                ans += (y - x) * b;
            } else {
                ans += 2 * y * c;
                ans += (x - y) * a;
            }
        } else {
            ans = a * x + b * y;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

int main(){
  int num[3], K, ans=0;

  cin >> num[0] >> num[1] >> num[2] >> K;

  sort(num, num+3);

  ans += num[0] + num[1];

  for(int i = 0; i < K; i++) num[2] = num[2]*2;
  ans += num[2];

  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
    string s;
    cin >> s;
    auto isPalindrome = [](const string& s) {
        for (size_t i = 0; i < s.size() / 2; i++) if (s[i] != s[s.size() - i - 1]) return false;
        return true;
    };
    cout << (isPalindrome(s) && isPalindrome(s.substr(0, s.size() / 2)) && isPalindrome(s.substr(0, s.size() / 2)) ? "Yes" : "No") << endl;
}

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


int main() {
    string s;
    cin >> s ;
    int ans = 0;
    rep(i,4){
        if(s[i] == '+')ans++;
        else ans --;
    }
    cout << ans << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll powmod(ll a, ll b) {
	a %= MOD;
	ll res = 1;
	while (b > 0) {
		if (b % 2 == 1)res = res * a % MOD;
		a = a * a % MOD;
		b /= 2;
	}
	return res;
}

ll f[210000];
void cominit() {
	f[0] = 1;
	REP(i, 200000)f[i + 1] = f[i] * (i + 1) % MOD;
}

ll com(ll n, ll r) {
	if (n < r)return 0;
	if (n < 0 or r < 0)return 0;
	return f[n] * powmod(f[r] * f[n - r], MOD - 2) % MOD;
}

ll perm(ll n, ll r) {
	if (n < r)return 0;
	if (n < 0 or r < 0)return 0;
	return f[n] * powmod(f[n - r], MOD - 2) % MOD;
}

ll n, k, mi, ma;
int main() {
	cominit();
	cin >> n >> k;
	vector<ll> s(n);
	REP(i, n)cin >> s[i];
	sort(ALL(s));
	REP(i, n) {
		ma += com(i, k - 1) * s[i];
		ma = (ma + MOD) % MOD;
		mi += com(n - i - 1, k - 1) * s[i];
		mi = (mi + MOD) % MOD;
	}
	cout << (ma - mi + MOD) % MOD << endl;

}


Measured memory_bytes: 2560
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int MOD=1e9+7;
int main()
{
    ll n; cin>>n;
    n++;
    int d;
    int ct=0;
    bool c[41]={};
    for(int i=0; i<41; i++){
        if(n<(1ll<<i)){
            d=i;
            break;
        }
        if(n&(1ll<<i)){
            c[i]=1; ct++;
        }
    }
    vector<int> ans;
    int ct1=ct;
    for(int i=0; i<d-1; i++){
        if(c[i]){
            ct1--; ans.push_back(d-1+ct1);
        }
        ans.push_back(i+1);
    }
    for(int i=0; i<d-1; i++) ans.push_back(i+1);
    for(int i=0; i<ct-1; i++) ans.push_back(d+i);
    cout<<ans.size()<<endl;
    for(int i=0; i<ans.size(); i++){
        cout<<ans[i];
        if(i<(int)ans.size()-1) cout<<" ";
        else cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    vector<ll> P(N); for(auto& in:P) cin >> in;

    ll minP = LINF;
    for(int i = 0; i < N;i++){
        minP = min(minP,P[i]);
        if(P[i] <= minP) res++;
    }

    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

int main(void) {
    int64_t N;
    int64_t sum = 0;
    int64_t c;
    cin >> N;
    
    vector<int64_t> L(N); 
    for(int i=0;i<N;i++) {
        cin >> L[i];
    }

    sort(L.begin(), L.end());
    for(int i=0;i<N-1;i++) {
        for(int j=i+1;j<N;j++) {
            auto it = lower_bound(L.begin(), L.end(), L[i]+L[j]);
            --it;
            if((*it) >= (L[i]+L[j])) continue;
            size_t index = distance(L.begin(), it);
//printf("L[%d]:%ld + L[%d]:%ld = %ld ind:%ld *it:%ld add:%ld\n", i,L[i],j,L[j],L[i]+L[j],index,*it,index-j);
            if(index > j) {
                sum += (index - j);
            }
        }
    }

    cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 256
N = int(input())
max = 0
max2 = 0
n_max = 0
A = []
for _ in range(N):
  a = int(input())
  A.append(a)
  if a > max:
    max2 = max
    max = a
    n_max = 1
  elif a == max:
    n_max += 1
  elif a > max2:
    max2 = a

for a in A:
  if a == max:
    if n_max == 1:
      print(max2)
    else:
      print(max)
  else:
    print(max)

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

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl


int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(1){
        c -= b;
        if(c<=0){
            COUT("Yes");
            break;
        }
        a -= d;
        if(a<=0){
            COUT("No");
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define PI 3.14159265358979323846264338327950L
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main(void){
    // Your code here!
    string n;
    cin >> n;
    if(n[0] == '7' || n[1] == '7' || n[2] == '7'){
        cout << "Yes" << endl;
    }
    else {cout << "No" << endl;}
    return 0;
}

Measured memory_bytes: 3568
n,m,c=map(int,input().split())
b=list(map(int, input().split()))
u=0
for i in range(n):
    inp=list(map(int,input().split()))
    s=0
    for j in range(m):
        s+=inp[j]*(b[j])
    s+=c
    if s>0:
        u+=1
print(u)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int cc[3][3];
    rep(i,3){
        rep(j,3){
            cin >> cc[i][j];
        }
    }
    bool can = true;
    int a,b,c,d;
    rep(i,3){
        if(!i){
            a=cc[i][0]-cc[i][1]; b=cc[i][1]-cc[i][2];
            c=cc[0][i]-cc[1][i]; d=cc[1][i]-cc[2][i];
        }
        else {
            if(a==cc[i][0]-cc[i][1]&&b==cc[i][1]-cc[i][2]&&
            c==cc[0][i]-cc[1][i]&&d==cc[1][i]-cc[2][i]);
            else can = false;
        }
    }
    cout << (can ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
def solve():
    n = int(input())
    w = list(map(int, input().split()))
    mindiff = -1
    for i in range(1,n):
        left = sum(w[:i])
        right = sum(w[i:])
        diff = abs(left - right)
        if (mindiff == -1 or diff < mindiff):
            mindiff = diff
    print(mindiff)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3060
n,y=map(int, input().split())
 
count=0
for i in range(n+1):
  for j in range(n+1):
      k=n-i-j
      if 10000*i+5000*j+1000*k==y and 0<=k:
        print(i,j,k)
        count+=1
        exit(0)
      else:
        continue

        
      
if count==0:
  print('-1 -1 -1')

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    L, R, d = [int(i) for i in input().strip().split()]
    ans = 0
    for i in range(L, R + 1):
        if i % d == 0:
            ans += 1
    return ans


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 61660
program prob5
    implicit none
    integer :: a,b,c
    read(*,*) a,b,c

    if(a == b .and. b /= c) then
        write(*,*) "Yes"
        stop
    end if
    if(a == c .and. b /= c) then
        write(*,*) "Yes"
        stop
    end if
    if(c == b .and. a /= c) then
        write(*,*) "Yes"
        stop
    end if
    write(*,*) "No"

    stop
contains
end program prob5

Measured memory_bytes: 2792
import math

n, q = map(int, input().split())

# make a list whose length is 2^i - 1.
n = pow(2, math.ceil(math.log2(n)))
max_v = 2147483647

A = [max_v for i in range(2 * n - 1)]


def update(i, x):
    i += n - 1
    A[i] = x

    while i > 0:
        i = (i - 1) // 2
        A[i] = min(A[i * 2 + 1], A[i * 2 + 2])

def find(a, b, k, l, r):
    if r <= a or b <= l:
        return max_v
    if a <= l and r <= b:
        return A[k]
    else:
        vl = find(a, b, k * 2 + 1, l, (l + r) // 2)
        vr = find(a, b, k * 2 + 2, (l + r) // 2, r)
        return min(vl, vr)


for i in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        update(x, y)
    else:
        ans = find(x, y + 1, 0, 0, n)
        print(ans)

Measured memory_bytes: 11136
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2019-12-29 23:28:38
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;
template<class T> ostream& operator<<(ostream& os, vector<T>& _) { os << '{'; for (T& x : _) { os << x; if (&x != &_.back()) os << ','; } os << '}'; return os; }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

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

  int64 a, b, k; cin >> a >> b >> k;
  cout << max(a - k, 0LL) << " " << max(b - max(k - a, 0LL), 0LL) << endl;  

  return 0;
}

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

cnt = 0
for i in range(1, n+1):
    if i % k == 0:
        cnt += 1

cnt_2 = 0
if k % 2 == 0:
    for i in range(1, n+1):
        if i % k == k//2:
            cnt_2 += 1

res = cnt ** 3 + cnt_2 ** 3

print(res)

Measured memory_bytes: 3060
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        a = a.substring(0,1);
        b = b.substring(0,1);
        c = c.substring(0,1);
        System.out.println(""+a.toUpperCase()+b.toUpperCase()+c.toUpperCase()+"");
    }

}

Measured memory_bytes: 21844
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N;
vector<int> A;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  A.resize(N);
  int ans = INF;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    int cnt = 0;
    while (A[i] % 2 == 0) {
      A[i] /= 2;
      cnt++;
    }
    ans = min(ans, cnt);
  }


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

Measured memory_bytes: 256
n = int(input())
S = []
T = []
for _ in range(n):
  s, t = input().split()
  S.append(s)
  T.append(int(t))
x = input()
index = S.index(x)
if index == n - 1:
  print(0)
else:
  print(sum(T[index+1:]))


Measured memory_bytes: 3060
H, W, K = [int(i) for i in input().split()]
c = [""]*H
for i in range(H):
    c[i] = input()

ans = 0

def cnt(a, h, w):
    global ans
    ret = 0
    for i,s in enumerate(a):
        if h[i]!=0:
            continue
        for j,c in enumerate(s):
            if w[j] !=0:
                continue
            ret += 1 if c == "#" else 0
    if K == ret:
        ans += 1

def hf(h):
    if len(h) == H:
        wf(h,[])
        return
    hf(h+[0])
    hf(h+[1])

def wf(h,w):
    if len(w) == W:
        cnt(c, h, w)
        return
    wf(h, w+[0])
    wf(h, w+[1])

hf([])
print(ans)

Measured memory_bytes: 9248
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
using System.ComponentModel;

class Program
{
    static void Main(string[] args)
    {
        var alice = new Magatro();
        alice.Scan();
        alice.Solve();
    }
}

public class Scanner
{
    private StreamReader Sr;
    private string[] S;
    private int Index;
    private const char Separator = ' ';

    public Scanner() : this(Console.OpenStandardInput())
    {
        Index = 0;
        S = new string[0];
    }
    public Scanner(Stream source)
    {
        Sr = new StreamReader(source);
    }

    private string[] Line()
    {
        return Sr.ReadLine().Split(Separator);
    }

    public string Next()
    {
        string result;
        if (Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    public T Next<T>()
    {
        var converter = TypeDescriptor.GetConverter(typeof(T));
        return (T)converter.ConvertFromString(Next());

    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public decimal NextDecimal()
    {
        return decimal.Parse(Next());
    }
    public string[] StringArray(int index = 0)
    {
        Next();
        Index = S.Length;
        return S.Skip(index).ToArray();
    }
    public int[] IntArray(int index = 0)
    {
        return StringArray(index).Select(int.Parse).ToArray();
    }
    public long[] LongArray(int index = 0)
    {
        return StringArray(index).Select(long.Parse).ToArray();
    }
    public bool EndOfStream
    {
        get { return Sr.EndOfStream; }
    }
}

public class Magatro
{
    private bool A, H;
    public void Scan()
    {
        Scanner cin = new Scanner();
        A = Convert(cin.Next());
        H = Convert(cin.Next());
    }

    private bool Convert(string s)
    {
        return s=="H" ? true : false;
    }

    public void Solve()
    {
        bool ans = !(A ^ H);
        Console.WriteLine(ans ? "H" : "D");
    }

}



Measured memory_bytes: 13140
// a
fn main() {
    input! {
        n: usize,
        d: [(usize, usize); n]
    }

    let mut cnt = 0;
    let mut ok = false;
    for z in d {
        if z.0 == z.1 {
            cnt += 1
        } else {
            cnt = 0
        }

        if cnt >= 3 {
            ok = true
        }
    }

    if ok {
        println!("Yes");
    } else {
        println!("No");
    }
}

#[macro_export(local_inner_maccros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[macro_export(lcal_inner_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[macro_export(lcal_inner_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


Measured memory_bytes: 2172
import numpy as np

N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
f = np.zeros(3100, np.int64)

ans = 0
f[0] = 1
for a in A:
    g = f.copy()
    f[a:] += g[:-a]
    f += g
    f %= mod

print(f[S])



Measured memory_bytes: 27252
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    ll n;
    cin >> n;
    ll ans = 1;
    int cnt = 1;
    while(1) {
        if ( cnt == n + 1 ) break;
        ans = ans * cnt % mod;
        ++cnt;
    }
    cout << ans << endl;
    return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MAX 1000010
#define MOD 1000000007

using ll = long long;
using Graph = vector<vector<int>>;


int main(){
  int N;cin>>N;
  string S; cin>>S;
  int res = 0;
  rep1(i,N){
    set<char> s1,s2;
    rep(j,N){
      if(j<i)s1.insert(S.at(j));
      else s2.insert(S.at(j));
    }
    int tmp = 0;
    for(auto c:s1){
      if(s2.count(c))tmp++;
    }
    res=max(res,tmp);
  }
  cout<<res<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

// 0-indexed bottom up Segment Tree
// UNIT is the identity element of operation func
template <typename T = int>
struct SegmentTree {
    using F = function<T(T, T)>;
    int n;
    vector<T> dat;
    F func;
    T UNIT;

    SegmentTree(int n_, F func_, T UNIT_) : func(func_), UNIT(UNIT_) {
        n = 1;
        // full binary tree: num of leaves = n = 2^k >= n_
        while (n < n_)
            n *= 2;
        dat.assign(2 * n - 1, UNIT);
    }
    SegmentTree(vector<T> v_, F func_, T UNIT_) : func(func_), UNIT(UNIT_) {
        n = 1;
        while (n < v_.size())
            n *= 2;
        dat.assign(2 * n - 1, UNIT);
        for (int i = 0; i < v_.size(); ++i) {
            dat[n - 1 + i] = v_[i];
        }
        for (int i = n - 2; i >= 0; --i) {
            dat[i] = func(dat[2 * i + 1], dat[2 * i + 2]);
        }
    }
    void update(int k, T a) {
        // leaves are at index n-1 to 2*n-2
        k += n - 1;
        dat[k] = a;
        while (k > 0) {
            // k -> parent node
            k = (k - 1) / 2;
            // func(child nodes)
            dat[k] = func(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }
    // get result of func() in [l, r)
    T query(int l, int r) {
        l += n - 1;
        r += n - 1;
        T ret = UNIT;
        while (l < r) {
            if ((l & 1) == 0)
                ret = func(ret, dat[l]);
            if ((r & 1) == 0)
                ret = func(ret, dat[r - 1]);
            l = l / 2;
            r = (r - 1) / 2;
        }
        return ret;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vl l(m), r(m), c(m);
    vector<pair<pii, ll>> lrc(m);
    for (int i = 0; i < m; ++i) {
        cin >> l[i] >> r[i] >> c[i];
        l[i]--, r[i]--;
        lrc[i] = {{l[i], r[i]}, c[i]};
    }
    auto f = [](ll l, ll r) { return min(l, r); };
    SegmentTree<ll> st(n, f, INF);
    st.update(0, 0);
    sort(lrc.begin(), lrc.end());
    for (int i = 0; i < m; ++i) {
        ll curr = st.query(lrc[i].first.second, lrc[i].first.second + 1);
        ll ne   = st.query(lrc[i].first.first, lrc[i].first.second + 1) + lrc[i].second;
        if (curr > ne)
            st.update(lrc[i].first.second, ne);
    }
    if (st.query(n - 1, n) == INF) {
        cout << -1 << "\n";
    } else {
        cout << st.query(n - 1, n) << "\n";
    }
    return 0;
}

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

int main() {
  int a;
  cin >> a;
  int b,c,d;
  b = a % 10;
  c = ( a - b ) % 100 / 10;
  d = ( a - b - c * 10 ) / 100;
  cout << b + c + d << endl;
}


Measured memory_bytes: 3588
import Data.List ( sort, sortBy )
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [_,k] <- readInts 
  ls    <- readInts 
--  print $ maxSnuke k ls
  print $ solve ls k 

maxSnuke
  :: Int -> [Int] -> Int
maxSnuke k = sum . take k . sortBy (flip compare)

-- https://atcoder.jp/contests/abc067/submissions/4912288
solve :: [Int] -> Int -> Int
solve = ((.) sum ) . (flip take) . sortBy (flip compare)

Measured memory_bytes: 508
s = input()
if len(s) == 2:
    if s[0] == s[1]:
        print("1 2")
        exit()
for i in range(len(s)-2):
    if s[i] == s[i+1] or s[i] == s[i+2] or s[i+1] == s[i+2]:
        print("{0} {1}".format(i+1, i+3))
        exit()
print("-1 -1")

Measured memory_bytes: 3188
import sys
input = sys.stdin.readline
N = int(input())
i = 0
ans = []
if N == 0:
    print(0)
    sys.exit()
while N != 0:
    i += 1
    if N % 2 == 0:
        N //= 2
        ans.append("0")
    else:
        if i % 2 == 1:
            N -= 1
            N //= 2
            ans.append("1")
        else:
            N += 1
            N //= 2
            ans.append("1")
print("".join(ans[::-1]))





Measured memory_bytes: 38256
package main

import (
	"fmt"
)

func main() {
	var a, b, c, x int

	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&x)

	count := 0
	for i := 0; i <= a; i++ {
		for j := 0; j <= b; j++ {
			for k := 0; k <= c; k++ {
				if i*500+j*100+k*50 == x {
					count++
				}

			}
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
while(1){
  long long i,j,N,D,E;
  double e,min=100000,p;
  cin>>D>>E;
  e=(double)E;
  if(D+E==0)return 0;
  for(i=0;i<=D/2;i++){
    j=(D-i)*(D-i)+i*i;
    p=(double)j;
    p=fabs(sqrt(p)-e);
    if(p<min)min=p;
  }
  cout << min << endl;
}}


Measured memory_bytes: 3204
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=5e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;

string a;
ll ans;
ll go(int indx,ll curr){
	if(indx == sz(a))return curr;
	ll ret = 0;
	for(int i=indx;i<sz(a);i++){
		ret+=go(i+1,curr+stoll(a.substr(indx,i-indx+1)));
	}
	return ret;	
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();	
	cin>>a;
	cout<<go(0,0)<<endl;
}		


Measured memory_bytes: 256
N,K = map(int,input().split())
num = list(sorted(map(int,input().split())))
cnt = 0
while num[0]!=num[-1]:
  for i in range(1,K):
    if cnt<1:
      num[i]=num[i-1]
    else:  
      j = (K-1)*cnt
      if i + j>=num[-1]:
        break
      num[i+j]=num[j]
      
  cnt+=1
print(cnt)

Measured memory_bytes: 13880
n, k = map(int, input().split())
mod = 10**9 + 7

SIZE = 2 * 10 ** 5 + 1
fact = [0] * SIZE
inv = [0] * SIZE
finv = [0] * SIZE
fact[0], fact[1] = 1, 1
inv[1] = 1
finv[0], finv[1] = 1, 1
for i in range(2, SIZE):
    fact[i] = fact[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod


def nCr(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    return fact[n] * (finv[r] * finv[n - r] % mod) % mod


ans = 1
limit = min(k+1, n)
for i in range(1, limit):
    vacant = i
    fill = n-i
    add = i
    pattern = nCr(n, vacant) * nCr(add+fill-1, add)
    ans = (ans + pattern) % mod

print(ans)

Measured memory_bytes: 44400
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    ll n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    a = n/3;
    b = n/5;

    k = n/15;


    n*=(n+1);
    n>>=1;

    a*=(a+1);
    a>>=1;

    b*=(b+1);
    b>>=1;

    k*=(k+1);
    k>>=1;

    m = n-3*a-5*b+15*k;

    cout<<m<<"\n";

    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n, m;
    cin >> n >> m;

    vector<ll> A(m);
    rep(i, m) cin >> A[i];
    sort(all(A));
    reverse(all(A));
    
    vector<ll> num = {
        0, 2, 5,5,4,5,6,3,7,6
    };

    vector<ll> dp(n + 1, -1);
    dp[0] = 0;
    rep(i, n) {
        rep(j, m) {
            if ((i+1)-num[A[j]] >= 0){
                dp[i+1] = max(dp[i+1], dp[(i+1)-num[A[j]]] + 1);
            }
        }
    }

    ll rest = n;
    for (ll i = 0; i < dp[n]; i++) {
        rep(j, m) {
            if (rest- num[A[j]] >= 0) {
                if (dp[rest] - 1 == dp[rest - num[A[j]]]) {
                    cout << A[j];
                    rest -= num[A[j]];
                    break;
                }
            }
        }
    }

    cout << endl;
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> field(h, vector<char>(w));
    int cntt = 0;
    int posx = 0;
    int lposx = 0;
    bool flag = true;
    vector<int> v;
    for(int i = 0; i < h; i++)
    {
        bool tflag = false;
        for(int j = 0; j < w; j++)
        {
            cin >> field[i][j];
            if(field[i][j] == '#' && flag)
            {
                posx = i;
                flag = false;
            }
            if(field[i][j] == '#')
            {
                lposx = i;
                tflag = true;
            }
        }
        if(!tflag)
        {
            v.push_back(i);
        }
    }
        
    vector<vector<int>> ans(h, vector<int>(w));
    int chick = 1;
    int x = 0, y = 0;
    int right = 1;
    int pos = 0;
    while(true)
    {
        ans[x][y] = chick;
        if(field[x][y] == '#')
        {
            chick++;
            pos = y;
        }
        if(right == 1)
        {
            y++;
            if(y == w)
            {
                for(int i = w-1; i >= pos; i--)
                {
                    if(chick >= 2) ans[x][i] = chick-1;
                    else ans[x][i] = chick;
                }
                x++;
                y--;
                right *= -1;
            }
        }
        else
        {
            y--;
            if(y == -1)
            {
                for(int i = 0; i <= pos; i++)
                {
                    if(chick >= 2) ans[x][i] = chick-1;
                    else ans[x][i] = chick;
                }
                x++;
                y++;
                right *= -1;
            }
        }
        if(x == h) break;
    }
    for(int i = posx; i >= 1; i--)
    {
        for(int j = 0; j < w; j++)
        {
            ans[i-1][j] = ans[i][j];
        }
    }
    for(int i = lposx; i < h-1; i++)
    {
        for(int j = 0; j < w; j++)
        {
            ans[i+1][j] = ans[i][j];
        }
    }
    for(int line : v)
    {
        if(line < posx || line > lposx) continue;
        for(int j = 0; j < w; j++)
        {
            ans[line][j] = ans[line-1][j];
        }
    }

    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll h,w;
char s[100][100];
int main(){
	cin >> h >> w;
	REP(i,h) {
		cin >> s[i];
	}

	REP(i,h) {
		REP(j,w) {
			if(s[i][j] == '.')
				continue;

			bool f = true;
			REP(k,4) {
				ll x = i + dx[k],y = j + dy[k];
				if((0 <= x && x < h && 0 <= y && y < w) && s[x][y] == '#'){
					f = false;
				}
			}
			if(f) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

constexpr int MOD = 1'000'000'007;

template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    const int MAX = n * m;
    vector<int> a(MAX + 1, -1), b(MAX + 1, -1);
    for (int i = 0; i < n; i++) {
        int e;
        cin >> e;
        a[e] = i;
    }
    for (int i = 0; i < m; i++) {
        int e;
        cin >> e;
        b[e] = i;
    }
    
    int h = 0, w = 0;
    ModInt<MOD> ans = 1;
    for (int i = MAX; i > 0; i--) {
        if (a[i] != -1 and b[i] != -1) {
            h++; w++;
        } else if (a[i] != -1) {
            h++;
            ans *= w;
        } else if (b[i] != -1) {
            w++;
            ans *= h;
        } else {
            int res = h * w - (MAX - i);
            ans *= res;
        }
    }
    
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 8064