akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  int h,w,k; cin >> h >> w >> k;
  char grid[h][w];
  int ans[h][w];

  int colour = 1;

  map<int,vector<int>> mp;

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      ans[i][j] = 0;
      cin >> grid[i][j];
      if(grid[i][j]=='#'){ 
        ans[i][j] = colour;
        mp[i].pb(j);
        colour++;
      }
    }
  }


  for(auto p : mp){
    int x = p.first;
    vector<int>& temp = p.second;
    for(int i=0;i<temp.size();i++){
      int y = temp[i];
      // go back
      for(int j=y-1;j>=0;j--){
        if(ans[x][j]==0) ans[x][j] = ans[x][j+1];
        else break;
      }
      // go fwd
      for(int j=y+1;j<w;j++){
        if(ans[x][j]==0) ans[x][j] = ans[x][j-1];
        else break;
      }
    }
  }


  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      
        //go up
        for(int r1=i-1;r1>=0;r1--){
          if(ans[r1][j]==0) ans[r1][j] = ans[r1+1][j];
          else break;
        } 
        //go down
        for(int r1=i+1;r1<h;r1++){
          if(ans[r1][j]==0) ans[r1][j] = ans[r1-1][j];
          else break;
        } 
      
    }
  }


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

  return 0;
}


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

int main(void){
    using namespace std;
    int n,d,b,c,ans=0;
    cin>>n>>d;
    int a[n][d];
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++)cin>>a[i][j];
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            b=0;
            for(int k=0;k<d;k++){
                b+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
            }
            c=1;
            while(c*c<=b){
                if(c*c==b)ans++;
                c++;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

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

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    int N = inputValue();
    int D = inputValue();
    int X[10][10];
    for(int i=0;i<N;i++){
      for(int j=0;j<D;j++){
        X[i][j] = inputValue();
      }
    }

    int cnt = 0;
    for(int i=0;i<N-1;i++){
      for(int j=i+1;j<N;j++){
        double val = 0;
        for(int k=0;k<D;k++){
          val += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        }
        int ival = (int)sqrt(val);
        if(sqrt(val) - ival < 1e-6){
          cnt++;
        }
      }
    }
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード

//ループ
#define rep(i, n) for(int i = 0; i < n; i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ

//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;

using namespace std;

//#include "./lib/generic/search.h"

int main(){
    int d, t, s;
    cin >> d >> t >> s;
    int dis = t*s;
    if(dis>=d) cout << "Yes" << endl; 
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3668
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

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

qsort(d, n, sizeof(int), compare_int);

int m = n/2;

    printf("%d\n", d[m]-d[m-1]);

    return 0;
}

Measured memory_bytes: 892
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
C = [I() for i in range(N)]

dic = {}

ans = 0
tmp = "None"
for i in C:
  if i == tmp:
    continue
  else:
    tmp = i
    if i not in dic:
      dic[i] = ans
    else:
      ans += dic[i] + 1
      dic[i] = ans

print((ans+1)%mod)

Measured memory_bytes: 29460
#include <assert.h>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

//const ll MOD = 998244353;
const ll MOD = 1e9+7;

// UnionFind
template<class T>
struct UnionFind {
  std::vector<T> uni;
  T num;
  UnionFind(T s) : uni(s, -1), num(s) {}

  //頂点aが所属するグループ
  T root(T a) {
    if (uni[a] < 0) {
      return a;
    }
    return uni[a] = root(uni[a]);
  }

  // a,bをつなげる
  bool connect(T a, T b) {
    a = root(a);
    b = root(b);
    if (a == b) {
      return false;
    }

    if (uni[a] > uni[b]) {
      std::swap(a, b);
    }

    uni[a] += uni[b];
    uni[b] = a;
    return true;
  }

  // a,bが同グループか確認
  bool isConnect(T a, T b) { return root(a) == root(b); }

  // aが属するグループの要素数
  T size(T a) { return -uni[root(a)]; }

  //グループ数を返す
  T groups() {
    std::set<T> b;
    for (T i = 0; i < num; i++) {
      b.insert(root(i));
    }
    return b.size();
  }
};

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,m,ans=0;
  std::cin>>n>>m;
  std::vector<ll> p(n);
  rep(i,0,n)std::cin>>p[i];
  UnionFind<ll> a(n);
  rep(i,0,m){
    ll x,y;
    std::cin>>x>>y;
    x--;y--;
    a.connect(x,y);
  }

  rep(i,0,n){
    if(a.isConnect(i,p[i]-1))ans++;
  }

  std::cout<<ans;
  return 0;
}

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

using ll = long long;

#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_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

int L;

int N, M; // N<=20, M<=60
int u[63], v[63], w[63];

void set(int a, int b, int c) {
  u[M] = a;
  v[M] = b;
  w[M] = c;
  ++M;
}

void solve() {
  for(int i=L;i;i/=2)N++;
  for_(i, 1, N) {
    set(i, i+1, 1<<(i-1));
    set(i, i+1, 0);
  }
  rfor_(i, 1, N) {
    if(L & (1<<(i-1))) {
      L -= 1<<(i-1);
      set(i, N, L);
    }
  }
}

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

  cin>>L;

  solve();

  cout<<N<<' '<<M<<endl;

  rep(i, M)cout<<u[i]<<' '<<v[i]<<' '<<w[i]<<endl;

  return 0;
}


Measured memory_bytes: 888
#include <cstdio>
#include <algorithm>
#include <functional>

int main()
{
  int n; long long k;
  scanf("%d%lld", &n, &k);
  long long a[1000000];
  long long f[1000000];
  for (int i = 0; i < n; ++i)
  {
    scanf("%lld", a + i);
  }
  for (int i = 0; i < n; ++i)
  {
    scanf("%lld", f + i);
  }
  std::sort(a, a + n, std::greater<int>());
  std::sort(f, f + n);
  long long l = -1; long long r = (long long)1e12 + 1;
  while (r - l > 1)
  {
    long long kk = k;
    long long mid = l + (r - l) / 2;
    bool ok = true;
    for (int i = n - 1; i >= 0; --i)
    {
      if (a[i] * f[i] <= mid) continue;
      long long dec = a[i] - mid / f[i];
      if (dec <= kk)
      {
        kk -= dec;
      }
      else
      {
        ok = false;
        break;
      }
    }
    if (ok)
    {
      r = mid;
    }
    else
    {
      l = mid;
    }
  }
  printf("%lld\n", r);
  return 0;
}

Measured memory_bytes: 7424
#141c
N,K,Q = map(int, input().split()) #1≤N≤10^5 , 1≤Q≤10^5
point_list=[K-(1*Q)]*N #最初から正解者以外の文の減算をしておく

for i in range(Q):
    A = int(input())
    point_list[A-1] += 1 #減算分を戻す
#このラウンドの参加者は N 人であり、1 から N までの番号がついています。ラウンド開始時点では全員が Kポイントを持っています。
#誰かが問題に正解すると、その人以外の N−1人のポイントが 1減ります。これ以外によるポイントの変動はありません。
#ラウンド終了時にポイントが 0以下の参加者は敗退し、残りの参加者が勝ち抜けます。
#このラウンドでは Q回の正解が出て、i 番目に正解したのは参加者 Ai でした。

#N 行出力してください。i 行目には、参加者 i が勝ち抜けたなら Yes を、敗退したなら No を出力してください。
for i in range(N):
    if point_list[i] <= 0:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 6596
#include<stdio.h>

void solve(int N,int K,int Q){

    int A[Q];
    for (int i = 0; i < Q; i+=1){
        scanf("%d", &A[i]);
        A[i] -= 1;
    }

    int P[N];
    for (int i = 0; i < N; i += 1){P[i] = 0;}

    for (int i = 0; i < Q; i += 1){
        P[A[i]] += 1;
    }

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

        if(P[i] > Q-K){printf("Yes\n");}
        else{printf("No\n");}
    }
}

int main(){

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

    solve(N, K, Q);

    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define vel vector<long long>
#define vech vector<char>
#define ves vector<string>
#define veb vector<bool>
#define vvel vector<vel>
#define vvech vector<vech>
#define int long long
#define pin pair<int,int>
#define ppin pair<int,pin>
#define mkp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define maxel(vec, j) *max_element(vec.begin(), vec.begin()+j)

using namespace std;
void mmin(int &a, int b) { a = min(a, b); }
void mmax(int &a, int b) { a = max(a, b); }
int vsum(vel v){ return accumulate(v.begin(), v.end(), 0); }
int msum(vvel v){
    int ans = 0;
    rep(i, v.size()){
        ans += vsum(v[i]);
    }
    return ans;
}
bool greater_by_second(pair<int, pair<string, int>> el1, pair<int, pair<string, int>> el2){
    return el1.second > el2.second;
}
struct Info
{
    int index;
    string S;
    int P;

    Info()
    {
    }
    Info(int index, string S, int P): index(index), S(S), P(P)
    {
    }
    bool operator<(const Info &another) const
    {
        if(this->S != another.S){
            return this->S < another.S;
        }else{
            return this->P > another.P;
        }
    };
    //2つのconstを付けないとコンパイルエラーになるので注意!!
};
signed main() {
    int pr = 1000;
    pr *= pr * pr; pr += 7;
    int N;
    cin >> N;
    vector<Info> SP(N);
    rep(i, N){
        cin >> SP[i].S;
        cin >> SP[i].P;
        SP[i].index = i+1;
    }
    sort(SP.begin(), SP.end());
    rep(i, N){
        cout << SP[i].index<<endl;
    }
    return 0;
}
/*
 */


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,ans=0;
    cin>>a>>b;
    int diff=max(a,b)-min(a,b);
    for(int i=1;i<=diff;i++)
    ans+=i;
    cout<<ans-max(a,b)<<endl;
}

Measured memory_bytes: 3628
def main():
    k = int(input())

    if k % 2 ==0:
        print(-1)
        return
    last = 0
    for i in range(1000000):
        if (last*10 + 7) % k == 0:
            print(i+1)
            return
        last = (last*10 + 7) % k
    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9172
#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {
	int n;
	cin>>n;
	map<string,int>m;
	while(n--){
	    string s;
	    cin>>s;
	    m[s]++;
	}
	cout<<"AC"<<" "<<"x"<<" "<<m["AC"]<<endl;
	cout<<"WA"<<" "<<"x"<<" "<<m["WA"]<<endl;
	cout<<"TLE"<<" "<<"x"<<" "<<m["TLE"]<<endl;
	cout<<"RE"<<" "<<"x"<<" "<<m["RE"]<<endl;
	return 0;
}


Measured memory_bytes: 3640
S=list(input())
mod=10**9+7
dp=[[0 for i in range(4)]for j in range(len(S)+1)]

dp[0][0]=1
for i in range(1,len(dp)):
    if S[i-1]!="?":
        dp[i][0]+=dp[i-1][0]
        dp[i][1]+=dp[i-1][1]
        dp[i][2]+=dp[i-1][2]
        dp[i][3]+=dp[i-1][3]
        if S[i-1]=="A":
            dp[i][1]+=dp[i-1][0]
        if S[i-1]=="B":
            dp[i][2]+=dp[i-1][1]
        if S[i-1]=="C":
            dp[i][3]+=dp[i-1][2]
        dp[i][0]%=mod
        dp[i][1]%=mod
        dp[i][2]%=mod
        dp[i][3]%=mod
    else:
        dp[i][0]+=dp[i-1][0]*3
        dp[i][1]+=dp[i-1][1]*3
        dp[i][2]+=dp[i-1][2]*3
        dp[i][3]+=dp[i-1][3]*3
        dp[i][1]+=dp[i-1][0]
        dp[i][2]+=dp[i-1][1]
        dp[i][3]+=dp[i-1][2]
        dp[i][0]%=mod
        dp[i][1]%=mod
        dp[i][2]%=mod
        dp[i][3]%=mod
print(dp[len(S)][3])
        

Measured memory_bytes: 28264
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MOD = 1e9+7;

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

    int n;
    cin >> n;

    int x = n%10;
    if(x == 3){
        cout << "bon" << endl;
        return 0;
    }else if(x == 0 || x == 1 || x == 6 || x == 8 ){
        cout << "pon" << endl;
        return 0;
    }else{
        cout << "hon" << endl;
        return 0;
    }


    return 0;
}

Measured memory_bytes: 3648
# -*- coding: utf-8 -*-
N=input()
s=raw_input()

dp=[ [0 for r in range(N+1)] for l in range(N+1)]


for r in range(N-1,-1,-1):
	for l in range(r-1,-1,-1):
		if s[l]==s[r]:
			dp[l][r]=min(abs(r-l),dp[l+1][r+1]+1)
		else:
			dp[l][r]=0

ans=0
for l in range(N):
	ans=max(ans,max(dp[l]))

print ans

Measured memory_bytes: 231196
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val A = new Array[Int](N+2)

  for(i <- 1 to N)
    A(i) = in.next().toInt


  //
  var l = 1; var r = 1
  var now = A(1).toBinaryString
  var ans = 0L
  var bits = new Array[Boolean](21)

  def debug(): Unit = {
    val hoge = bits.map { x =>
      if(x) "1" else "0"
    }.mkString("").reverse
    println(hoge)
  }

  def check(_now: String): Boolean = {
    val now = _now.reverse
    var res = true
    for(i <- 0 until now.length) {
      if(now(i) == '1' && bits(i))
        res = false
    }

    res
  }

  def add(_bit: String): Unit = {
    val bit = _bit.reverse
    for(i <- 0 until bit.length) {
      if(bit(i) == '1')
        bits(i) = true
    }
  }

  def sub(_bit: String): Unit = {
    val bit = _bit.reverse
    for(i <- 0 until bit.length) {
      if(bit(i) == '1')
        bits(i) = false
    }
  }

  //
  while(r <= N) {
    // println(l, r)
    // debug()


    if(check(now)) {
      add(now)
      r += 1
      now = A(r).toBinaryString
    }
    else {
      // println(l, r)
      ans += r - l
      sub(A(l).toBinaryString)
      l += 1
    }
  }


  // 最後の処理
  while(l <= N){
    ans += (N + 1 - l)
    l += 1
  }

  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}



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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int N, t[100], v[100];

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

    cin >> N;
    rep(i, N) cin >> t[i];
    rep(i, N) cin >> v[i];
    double res = 0, vv = 0;
    bool upper, timeup;
    rep(i, N) for(double j = 0; j < t[i]; j += 0.5) {
        double latte;
        double after = latte = t[i] - (j + 0.5);
        upper = false, timeup = false;
        FOR(k, i + 1, N) {
            after += t[k];
            if(vv + 0.5 - after > v[k + 1]) upper = true;
            if(vv - v[k + 1] > after) timeup = true;
        }
        if(vv + 0.5 <= v[i] && vv + 0.5 - latte <= v[i + 1] && !upper) {
            res += vv * 0.5 + (0.5 * 0.5 / 2.);
            vv += 0.5;
        }
        else if(!timeup && vv - v[i + 1] <= latte) res += vv * 0.5;
        else {
            res += (vv - 0.5) * 0.5 + (0.5 * 0.5 / 2.);
            vv -= 0.5;
        }
    }
    cout << fixed << setprecision(10) << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
// #define int cpp_int
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}

inline void solve(void){
  long N;
  in(N);
  vector<long>W(N);
  rep(i,N)in(W[i]);
  long sum=accumulate(all(W),0L);
  long ans=LONG_MAX,tmp=0;
  rep(i,N){
    tmp+=W[i];
    chmin(ans,abs(sum-2*tmp));
  }
  out(ans);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	int n,m;
	cin>>n>>m;
	vector<string> im1(n), im2(m);
	for(int i=0;i<n;i++){
		cin>>im1[i];
	}
	for(int i=0;i<m;i++){
		cin>>im2[i];
	}

	for(int i=0;i+m-1<n;i++){
		for(int j=0;j+m-1<n;j++){
			int fg = 0;
			for(int k=i;k<i+m;k++){
				for(int l=j;l<j+m;l++){
					if(im1[k][l] != im2[k-i][l-j]){
						fg = 1;
					}
				}
			}
			if(!fg){
				// cout<<i<<" "<<j<<endl;
				cout<<"Yes"<<endl;
				return;
			}
		}
	}
	cout<<"No"<<endl;
	
}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

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

    int n = sc.nextInt();

    Set<Integer> s = new HashSet<>();

    for (int i = 0; i < n; i++) {
      if (!s.add(sc.nextInt())) {
        System.out.println("NO");
        return;
      }
    }

    System.out.println("YES");

    sc.close();
  }
}

Measured memory_bytes: 102128
#include<stdio.h>

int main(void){
	int N,times=0,times_max=0,times_max_N=1,temp;
	scanf("%d",&N);
	for(int i=1;i<=N;i++){
		temp=i;
		times=0;
		while(temp%2==0){
			times++;
			temp/=2;
			}
		if(times>times_max){
			times_max=times;
			times_max_N=i;
			}
		}
	printf("%d\n",times_max_N);
}

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

 
int main(){
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int ans = 0;
  int left = 0;
  while(left<n){
    int sum = 0;
    int right = left;
    int nleft = 0;
    int cnt = 0, mcnt=0;
    if(s[left]=='0') cnt++;
    while(right < n && cnt<=k){
      sum++;
      if(nleft==0&&cnt>0&&s[right]=='1'){
        nleft = right;
        mcnt = right - left;
      }
      if(s[right]=='1'&& s[right+1]=='0') cnt++;
      right++;
    }
    ans = max(sum, ans);
    if(right>=n-1){
      break;
    }
    if(nleft>0){
      left = nleft;
    }else{
      left++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3704
//Area of Polygon
import java.io.*;

public class Main{
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		double a,b,c,x1,x2,x3,y1,y2,y3,z,S=0;
		
		//???????????????????????±?????????
		String[] str1 = br.readLine().split(",");
		x1 = Double.parseDouble(str1[0]);
		y1 = Double.parseDouble(str1[1]);
		String[] str2 = br.readLine().split(",");
		x2 = Double.parseDouble(str2[0]);
		y2 = Double.parseDouble(str2[1]);
		String str = br.readLine();
		
		while(str != null){
			String[] str3 = str.split(",");
			x3 = Double.parseDouble(str3[0]);
			y3 = Double.parseDouble(str3[1]);
			a = Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2));
			b = Math.sqrt(Math.pow(x3-x2,2)+Math.pow(y3-y2,2));
			c = Math.sqrt(Math.pow(x3-x1, 2)+Math.pow(y3-y1, 2));
			z = (a+b+c)/2;
			S += Math.sqrt(z*(z-a)*(z-b)*(z-c));
			str = br.readLine();
			x2 = x3;
			y2 = y3;
		}
		System.out.println(S);
		
		br.close();
	}
}

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

int n, x=0, temp;

int main() {
    cin >> n;
    int a[n];
    for (int i=0; i<n; i++) cin >> a[i];
    for (int i=0; i<n; i++) {
        if (a[i] <= a[n-1]) {
            temp = a[x];
            a[x] = a[i];
            a[i] = temp;
            x++;
        }
    }
    x = x-1;
    for (int i=0; i<x; i++) cout << a[i] << " ";
    cout << "[" << a[x] << "]";
    for (int i=x+1; i<n; i++) cout << " " << a[i];
    cout << endl;
}


Measured memory_bytes: 3476
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] array = new int[3];
        for (int i = 0; i < 3; i++) {
            array[i] = sc.nextInt();
        }
        Arrays.sort(array);
        System.out.println(array[0] + array[1]);
    }
}

Measured memory_bytes: 23764
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define mod 1000000007 
#define MN 23000000
#define MM 10000000
using namespace std;
inline int in(){
    int x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
int num[MN+5],sum,n,res;
inline int qpow(int x,int k){
	int bas=1;while (k){
		if (k&1) bas=(1ll*bas*x)%mod;
		x=(1ll*x*x)%mod;k>>=1;
	}return bas;
}
int main()
{
	n=in();
	for (int i=1;i<=MN;++i) num[i]=num[i/10]+1;
	for (int hd=1,tl=0;hd<MM;++hd){
		while (sum<n) ++tl,sum+=num[tl];
		if (sum==n) ++res;sum-=num[hd];
	}
	for (int i=1;i<=(n>>3);++i){
		res=(res+1)%mod;
		if (!(n%i)) res=(res+1ll*(qpow(10,n/i)+mod-qpow(10,n/i-1))%mod+mod-i)%mod;
	}printf("%d",res);return 0;
}

Measured memory_bytes: 89984
while n = gets.split.map(& :to_i)
  if n[0] == 0 && n[1] == 0
    break
  end
  n[0].times do |i|
    if i % 2 == 1
      n[1].times do |j|
        if j % 2 == 1
          print "#"
        else
          print "."
        end
      end
      puts ""
    else
      n[1].times do |j|
        if j % 2 == 1
          print "."
        else
          print "#"
        end
      end
      puts ""
    end
  end
  puts ""
end

Measured memory_bytes: 8700
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// 標準入力からデータを読み込む準備
Scanner sc = new Scanner(System.in);
// 最初の文字の固まりを整数値と想定して読み込む
int x = sc.nextInt();
int answer = x*x*x /* ここを変えて3乗しよう！ */;
System.out.println(answer);
sc.close();
}
}


Measured memory_bytes: 26116
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans=0
before=-1

for i in a:
	ans+=b[i-1]
	if before+1==i:
		ans+=c[i-2]
	before=i
print(ans)

Measured memory_bytes: 3060
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
ans = set()
cnt = 0
for _ in range(k):
    d = int(readline())
    a = list(map(int, readline().split()))
    ans |= set(a)
for i in range(n):
    if (i + 1) not in ans:
        cnt += 1
print(cnt)


Measured memory_bytes: 67536
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void No() { cout << "No" << endl; }
	void Yes() { cout << "Yes" << endl; }
	void Solve() {
		UL H, W, h, w; cin >> H >> W >> h >> w;
		if (H % h == 0 && W % w == 0) { No(); return; }
		Yes();
		if (H % h) {
			int t = H * 2;
			rep(y, H) {
				rep(x, W) {
					if (x != 0) cout << " ";
					if (y % h == 0) cout << ((h - 1) * t - 1);
					else cout << -t;
				}
				cout << endl;
			}
		}
		else {
			int t = W * 2;
			rep(y, H) {
				rep(x, W) {
					if (x != 0) cout << " ";
					if (x % w == 0) cout << ((w - 1) * t - 1);
					else cout << -t;
				}
				cout << endl;
			}
		}
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 1664
#include <cstdio>



int main() {
    int sx, sy, tx, ty;
    scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
    for (int i = sy; i < ty; i++)
        fputc('U', stdout);
    for (int i = sx; i < tx; i++)
        fputc('R', stdout);
    for (int i = ty; i > sy; i--)
        fputc('D', stdout);
    for (int i = tx; i > sx; i--)
        fputc('L', stdout);

    fputc('L', stdout);

    for (int i = sy; i < ty + 1; i++)
        fputc('U', stdout);
    for (int i = sx; i < tx + 1; i++)
        fputc('R', stdout);

    fputc('D', stdout);
    fputc('R', stdout);

    for (int i = ty; i > sy - 1; i--)
        fputc('D', stdout);
    for (int i = tx; i > sx - 1; i--)
        fputc('L', stdout);

    fputc('U', stdout);
    return 0;
}


Measured memory_bytes: 256
#!usr/bim/python
#! -*- coding: utf-8 -*-

from collections import OrderedDict
import numpy as np
import copy

n = raw_input()
n = int(n)

dic = OrderedDict()
for i in range(26):
    dic[chr(97+i)] = 0

counter = np.zeros([26,n],dtype=np.int16)

for i in range(n):
    new_dic = copy.deepcopy(dic)
    s = raw_input()
    for j in range(len(s)):
        new_dic[s[j]] += 1
    j = 0
    for key,val in new_dic.items():
        counter[j][i] = val
        j += 1

ans_list = np.zeros(26,dtype=np.int32)
for i in range(26):
     ans_list[i] = np.min(counter[i])

ans = ""
for i in range(26):
    for j in range(ans_list[i]):
        ans += chr(97+i)

print ans


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

int main() {

  int n, m, l;
  cin >> n >> m >> l;

  vector<vector<int>> A(n, vector<int>(m));
  vector<vector<int>> B(m, vector<int>(l));

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> B[i][j];
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      long long c = 0;
      for (int k = 0; k < m; k++) {
        c +=(long long) A[i][k] * B[k][j];
      }
      cout << c;
      if (j != l - 1) {
        cout << " ";
      }
    }
    cout << endl;
  }

  return 0;

}


Measured memory_bytes: 3248
MOD=10**9+7
S=input()
N=len(S)

dp=[[0]*4 for i in range(N+1)]

dp[0][0]=1

for i in range(N):
    dp[i+1][0]=dp[i][0] if (S[i]!='?') else dp[i][0]*3%MOD
    dp[i+1][1]=dp[i][1] if (S[i]!='A' and S[i]!='?') else (dp[i][1]+dp[i][0])%MOD if (S[i]=='A') else (dp[i][0]+dp[i][1]*3)%MOD
    dp[i+1][2]=dp[i][2] if (S[i]!='B' and S[i]!='?') else (dp[i][2]+dp[i][1])%MOD if (S[i]=='B') else (dp[i][1]+dp[i][2]*3)%MOD
    dp[i+1][3]=dp[i][3] if (S[i]!='C' and S[i]!='?') else (dp[i][3]+dp[i][2])%MOD if (S[i]=='C') else (dp[i][2]+dp[i][3]*3)%MOD

print(dp[N][3])

Measured memory_bytes: 31784
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,t;
    cin>>n>>t;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    int current_time=0;
    int result=0;
    for(int i=0;i<n;i++)
    {
        int start_time=v[i];
        current_time=v[i]+t;
        bool inside=false;
        while(i<n&&v[i]<current_time){
            current_time=v[i]+t;
            i++;
            inside=true;
        }
        if(inside)i--;
        result+=current_time-start_time;
    }
    cout<<result<<endl;
}

Measured memory_bytes: 3984
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,k,a[MAXN];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int cnt=1,ans=0;
    for(int i=2;i<=n;i++)
    {
        if(a[i]==a[i-1]) cnt++;
        else
        {
            ans+=cnt/2;
            cnt=1;
        }
    }
    ans+=cnt/2;
    printf("%d\n",ans);
    return 0;
}



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

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("O3", "Ofast", "unroll-loops", "fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


#define int long long
#define endl '\n'

using namespace std;

vector < vector < int > > a;
int n, m;
void gen(vector < int > cur){
    if (cur.size() == n){
        a.push_back(cur);
        return;
    }
    for (int i = cur.back(); i <= m; i++){
        cur.push_back(i);
        gen(cur);
        cur.pop_back();
    }
}


signed main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    int q, i, j;
    cin >> n >> m >> q;
    for (i = 1; i <= m; i++){
        gen({i});
    }
    vector < vector < int > > p(q, vector < int > (4));
    for (i = 0; i < q; i++){
        cin >> p[i][0] >> p[i][1] >> p[i][2] >> p[i][3];
        p[i][0]--; p[i][1]--;
    }
    int ans = 0;
    for (auto cur : a){
        int tec = 0;
        for (i = 0; i < q; i++){
            if (cur[p[i][1]] - cur[p[i][0]] == p[i][2]){
                tec += p[i][3];
            }
        }
        ans = max(ans, tec);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13932
n, k = map(int, input().split())
p = list(map(int, input().split()))

sum_reg = (sum(p[0:k])+k)/2
max_reg = sum_reg
for i in range(k, n):
  sum_reg = sum_reg + (p[i]-p[i-k])/2
  max_reg = max(max_reg, sum_reg)
  
print(max_reg)

Measured memory_bytes: 98952
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  map<int, int> m;
  int n;
  cin >> n;
  rep(i, n) {
    int x;
    cin >> x;
    if (m.find(x) == m.end()) {
      m[x] = 1;
    } else {
      m[x]++;
    }
  }
  int ans = 0;
  for (auto& x : m) {
    if (x.first < x.second) {
      ans += (x.second - x.first);
    } else if (x.first > x.second) {
      ans += x.second;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int x=0;
  string S;
  cin >> N >> S;
  for(int i=0;i<N-2; i++){
    if(S.at(i)=='A'&&S.at(i+1)=='B'&&S.at(i+2)=='C'){
      x++;
    }
  }
  cout << x << endl;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES // for C++  
#include <cmath> 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <functional>
#include <bitset>
#define LL long long

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if ((a*100+b*10+c)%4==0)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
} 

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
int main()
{
  long long int a,b,n;
  cin>>a>>b>>n;
  long long int ans=0;
  if(n<b)
  {
    ans=((a*n)/b);
  }
  if(n==b)
  {
    ans=(a*(n-1))/b;
  }
  if(n>b)
  {
    for(long long int i=b-1;i<=b+1;i++)
    {
      if((((a*i)/b)-a*(i/b))>ans)
      {
        
        ans=((a*i)/b)-a*(i/b);
      }
    }
  }
  if(ans>0)
  {
  cout<<ans;
  }
  else
  {
    cout<<"0";
  }
}

Measured memory_bytes: 3632
import collections
N = int(input())
D = list(map(int, input().split()))
d = collections.Counter(D)
maxnum = max(D)
ans = 1
for i in range(maxnum+1):
    if i == 0:
        if D[0] != 0 or d.get(0,0) != 1:
            ans = 0
            break
    else:
        if d.get(i, 0) == 0:
            ans = 0
            break
        ans *= d[i-1]**d[i]

print(ans%998244353)

Measured memory_bytes: 62260
#include <algorithm>
#include <cstdio>

int main() {
  char c;
  long long ans = 0, k = 0;
  while ((c = getchar()) != EOF) {
    if (c == 'B') ++k;
    if (c == 'W') ans += k;
  }
  printf("%lld\n", ans);
}

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

int main () {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  a = a + b;
  c = c + d;
  a = a - c;
  if ( a < 0 ) {
    cout << "Right" << endl;
  }
  if ( a == 0 ) {
    cout << "Balanced" << endl;
  }
  if ( a > 0 ) {
    cout << "Left" << endl;
  }
}


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

int main(){
    int n,m;
    cin>>n>>m;
    int a[n],i;
    for(i=0;i<m;i++)cin>>a[i];
    long long s=0;
    for(i=0;i<m;i++)s+=a[i];
    if(s>n)cout<<"-1"<<endl;
    else cout<<n-s<<endl;
	return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <sstream>

using namespace std;
using ll = long long;

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

	vector<int> argD(argN);
	for (int i = 0; i < argN; ++i) {
		cin >> argD.at(i);
	}

	sort(argD.begin(), argD.end(), greater<int>());
	int counter = 0;
	for (int i = 0; i < argN; ++i) {
		if (i == 0) {
			counter++;
		}
		else if (argD.at(i) != argD.at(i - 1)) {
			counter++;
		}
	}

	cout << counter << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long

using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a, b;
    cin>>a>>b;
    if(a > 9 or a < 1 or b > 9 or b < 1){
    	cout<<-1<<endl;
    } else {
    	cout<<a * b<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
mod=10**9+7
t=[int(input()) for i in range(m)] 
dp=[-1]*(n+1)

dp[0]=1
dp[1]=1
for i in range(m):
    dp[t[i]]=0


for i in range(2,n+1):
    if dp[i]==-1:
        dp[i]=dp[i-1]+dp[i-2]
print(dp[-1]%mod)


Measured memory_bytes: 460020
#include<bits/stdc++.h>
#define nikal ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    nikal;
    int x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  ll h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s.at(i);

  vector<ll> dx{1, 0, -1, 0};
  vector<ll> dy{0, 1, 0, -1};
  const ll inf = 10000000000000000;
  queue<pair<ll, ll>> que;
  que.push(make_pair(0, 0));
  vector<vector<ll>> d(h, vector<ll>(w, inf));
  d.at(0).at(0) = 0;

  while (que.size()) {
    pair<ll, ll> p = que.front();
    que.pop();

    if (p.first == w - 1 and p.second == h - 1) break;

    for (int i = 0; i < 4; ++i) {
      ll nx = p.first + dx.at(i), ny = p.second + dy.at(i);
      if (0 <= nx and nx < w and 0 <= ny and ny < h and s.at(ny).at(nx) != '#' and d.at(ny).at(nx) == inf) {
        que.push(make_pair(nx, ny));
        d.at(ny).at(nx) = d.at(p.second).at(p.first) + 1;
      }
    }

  }

  ll firsharp = 0;
  rep(i, h) rep(j, w) {
      if (s.at(i).at(j) == '#') ++firsharp;
    }
  if (d.at(h - 1).at(w - 1) != inf and s.at(0).at(0) != '#') {
    ll ans = h * w - d.at(h - 1).at(w - 1) - 1 - firsharp;
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

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

int main(){
    ll n,k,x,y; cin >> n >> k >> x >> y;
    if(n > k) cout << (n-k)*y + k*x << endl;
    else cout << n*x << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int inf=0x3f3f3f3f;
#define N 100010
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,m,a[N],b[N],c[N],d[N],ans;
int X;
vector<int> Y,Z;
bool ok[N];
struct Union{
	int f[N],siz[N];
	void init(int n){
		for(int i=1;i<=n;++i){
			f[i]=i,siz[i]=1;
		}
	}
	inline int getf(int x){
		return f[x]==x?x:f[x]=getf(f[x]);
	}
	void Merge(int x,int y){
		++d[x];
		int fx=getf(x),fy=getf(y);
		if(fx^fy){
			siz[fx]+=siz[fy];
			siz[fy]=0;
			f[fy]=fx;
		}
	}
}S;
int main(){
	n=read(),m=read();
	S.init(n);
	for(int i=1;i<=m;++i){
		a[i]=read(),b[i]=read(),c[i]=read()-1;
		S.Merge(a[i],b[i]);
	}
	for(int i=1;i<=n;++i){
		if(d[i]>1)ok[S.getf(i)]=true;
	}
	for(int i=1;i<=n;++i){
		if(S.getf(i)==i){
			if(!ok[i]&&S.siz[i]>1)++X;
		}
	}
	int now=0;
	bool flag=false;
	for(int i=1;i<=m;++i){
		if(c[i]){
			if(ok[S.getf(a[i])]){
				if(a[i]==b[i])Z.push_back(c[i]); //case 3 (circle)
				else now+=c[i],flag=true;  //case 3 (not circle)
			}
			else{
				if(a[i]==b[i])Y.push_back(c[i]-1); //case 2 
				else now+=c[i];   // case 1 
			}
		}
	}
	sort(Y.begin(),Y.end(),greater<int>());
	sort(Z.begin(),Z.end(),greater<int>());
	for(auto x:Y)now+=x;
	ans=inf;
	for(int i=0,j=(int)Y.size()-1;"ZYK AK IOI!";++i){
		// i: amount of case 3
		// j: amount of case 2
		while(~j&&now-Y[j]>=X)now-=Y[j--];
		if(now>=X&&(flag||i||!X))ans=min(ans,i+2*(j+1));
		if(i==(int)Z.size())break;
		now+=Z[i];
	}
	if(ans==inf){
		printf("-1\n");
	}
	else{
		for(int i=1;i<=m;++i){
			ans+=(a[i]!=b[i]);
		}
		printf("%d\n",ans+X);
	}
	return 0;
}



Measured memory_bytes: 6180
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 111

const int val = 100;

int A, B, i, j, n, m;
int v[maxN][maxN];
int least[maxN][maxN];
vector< pair<pair<int, int>, int> > edges;

void execute(int x, int y, int need) {
    int i, j;

    for (i = 0; i <= val; i++)
        for (j = 0; j <= val; j++)
            least[i][j] = max(least[i][j], need - (x * i + y * j));

}

bool check(int x, int y, int need) {
    int i, j;

    int act = 1 << 30;

    for (i = 0; i <= val; i++)
        for (j = 0; j <= val; j++)
            act = min(act, i * x + j * y + least[i][j]);

    if (act != need) return false;
    return true;
}

void add_edge(int x, int y, int v) {
    edges.pb(mp(mp(x, y), v));
    m++;
}

int main()
{
   // freopen("test.in","r",stdin);
   // freopen("test.out","w",stdout);

    cin >> A >> B;
    for (i = 1; i <= A; i++) {
        for (j = 1; j <= B; j++) {
            cin >> v[i][j];

            execute(i, j, v[i][j]);
        }
    }

    for (i = 1; i <= A; i++) {
        for (j = 1; j <= B; j++) {
            if (!check(i, j, v[i][j])) {
                cout << "Impossible";
                return 0;
            }
        }
    }

    cout << "Possible\n";

    add_edge(1, 2, 0);
    for (i = 2; i + 1 <= val + 2; i++)
        add_edge(i, i + 1, -1);

    for (i = val + 3; i + 1 <= 2 * val + 3; i++)
        add_edge(i + 1, i, -2);

    add_edge(val + 3, 2 * val + 4, 0);

    for (i = 0; i <= val; i++)
        for (j = 0; j <= val; j++)
            add_edge(i + 2, j + val + 3, least[i][j]);

    n = 2 * val + 4;

    cout << n << ' ' << m << '\n';
    for (auto e : edges) {
        cout << e.first.first << ' ' << e.first.second << ' ';
        if (e.second == -1) cout << "X\n";
        if (e.second == -2) cout << "Y\n";
        if (e.second >= 0) cout << e.second << "\n";
    }

    cout << 1 << ' ' << n;


    return 0;
}


Measured memory_bytes: 704
#include<cstdio>

struct union_find{
  int par[10000];
  int rank[10000];

  union_find(){
    for(int i=0;i<10000;i++){
      par[i] = i;
      rank[i] = 0;
    }
  }
  int find(int x){
    if(par[x]==x) return x;
    else return par[x] = find(par[x]);
  }
  void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(rank[x]<rank[y]){
      par[x] = y;
    }else{
      par[y] = x;
      if(rank[x]==rank[y]) rank[x]++;
    }
  }
  bool same(int x,int y){return find(x)==find(y);}
};

int main(){
  int n,q;
  union_find uf;
  scanf("%d %d",&n,&q);
  for(int i=0;i<q;i++){
    int cmd,x,y;
    scanf("%d %d %d",&cmd,&x,&y);
    if(cmd==0) uf.unite(x,y);
    else if(cmd==1){
      if(uf.same(x,y)) printf("1\n");
      else printf("0\n");
    }
  }
  return 0;
}

Measured memory_bytes: 2760
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define  fo(i,a,b) for(ll i=a;i<b;i++)
#define rfo(i,a,b) for(ll i=a;i>=b;i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)

#define err() cout<<"----------"<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define pb push_back
#define deb(x) cout<< #x << " = "<<x<<endl;
#define F first
#define S second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589
const ll MOD=1e9+7;
ll mod(ll x)
{
   return (x%MOD+MOD)%MOD;
   // works for neg and pos values of x.
}
void solve()
{
    ll n,x,time;
    cin>>n>>x>>time;
    if(n%x==0)
    {
        cout<<n/x*time;
        return;
    }
    cout<<(n/x+1)*time;
    return;
}
int main()
{

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
//  clock_t time_req;
//  time_req = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

// time_req = clock()-time_req;
//  cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;

    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define int long long int
using namespace std;
int32_t main()
{
	vector<pair<int,int>>v;
	int n;
	cin>>n;
	int a,b;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		v.push_back({a,b});
	}	
	int flag=0;
	for(int i=0;i<n-2;i++)
	{
		if(v[i].first==v[i].second&&v[i+1].first==v[i+1].second&&v[i+2].first==v[i+2].second)
		{
			cout<<"Yes";
			flag=1;
			break;
		}
	}
	if(flag==0)
		cout<<"No";
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	priority_queue<int, vector<int>, greater<int> > que;
	for (int i = 0; i < n; i++){
		int x;
		cin >> x;
		que.push(x);
	}
	vector<pair<int, int> > vec;
	for (int i = 0; i < m; i++){
		int b, c;
		cin >> b >> c;
		vec.push_back(make_pair(c, b));
	}
	sort(vec.begin(), vec.end(), greater<pair<int, int> >());

	for (int i = 0; i < m; i++){
		for (int j = 0; j < vec[i].second; j++){
			if (que.top() < vec[i].first){
				que.pop();
				que.push(vec[i].first);
			}else{
				i = MOD;
				break;
			}
		}
	}

	ll ans = 0;
	while(!que.empty()){
		ans += que.top();
		que.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4720
let n = Int(readLine()!)!
let a = readLine()!.split(separator: " ").map(String.init).lazy.map { Int($0)! }

var acc = 0
var min = 0

for num in a {
  if min > num {
    acc = acc &+ (min - num)
  } else {
    min = num
  }
}

print(acc)


Measured memory_bytes: 20980
#include<iostream>
#include<string>
#include<stdio.h>
#include<cstdio>
#include<math.h>
using namespace std;
int main(){
    int a1,a2,b1,b2,c1,c2,d1,d2,e1,e2,max=-10000;
    int sum[100];
    char ch;
    while(1){
        cin>>a1>>a2;
        if(a1==0 && a2==0){
            break;
        }
        cin>>b1>>b2>>c1>>c2>>d1>>d2>>e1>>e2;
        sum[0]=a1+a2;sum[1]=b1+b2;sum[2]=c1+c2;sum[3]=d1+d2;sum[4]=e1+e2;
        for(int i=0;i<5;i++){
            if(sum[i]>max){
                   max=sum[i];
                ch='A'+i;
            }
        }
        cout<<ch<<" "<<max<<endl;
        max=-10000;
    }
    return 0;
}

Measured memory_bytes: 3056