akhauriyash/Code-Regression huggingface dataset:
package main

import "fmt"

func main()  {
	var n, x int
	fmt.Scan(&n, &x)
	nums := ScanNums(n)
	boundNum := 1
	curPos := 0
	for i := 0; i < len(nums); i++ {
		curPos =  curPos + nums[i]
		if curPos > x {
			break
		}
		boundNum++
	}
	fmt.Println(boundNum)
}

func ScanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
  int D; cin >> D;
  vector<int> C(26); rep(i, 26) cin >> C[i]; //満足度減少係数
  vector<vector<ll>> S(D, vector<ll>(26));
  rep(i, D)rep(j, 26)cin >> S[i][j];

  ll score = 0;
  vector<int> last(26);
  vector<ll> res(D);
  rep(d, D){
    int T = -1; ll max_score = -LINF;
    //d+1日目にどのコンテストを開くか全探索する
    rep(t, 26){
      ll tmp = score + S[d][t]; //暫定スコア
      rep(i, 26){
        if(i==t)continue;
          tmp -= C[i] * ((d+1) - last[i]);
      }
      if(max_score < tmp){
        T = t;
        max_score = tmp;
      }     
    }
    //最も次のスコアが大きくなる場合を選択する
    res[d] = T;
    last[T] = d+1;
    score = max_score;
  }
  for(ll tmp: res){
    cout << tmp + 1 << ln;
  }
}



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

template <typename T>
void print(const T &v);

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    vector<int> dp(n);
    dp[0] = 0;
    for (int i = 1; i < n; i++)
    {
        set<int> s;
        for (int j = 1; j <= min(k, i); j++)
        {
            int cost = dp[i - j] + abs(h[i - j] - h[i]);
            s.insert(cost);
        }
        dp[i] = *begin(s);
    }
    cout << dp[n - 1] << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


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

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

    for (int i = 0; i < s.length(); i++) {
        if (s == t) {
            cout << "Yes" << endl;
            return 0;
        }
        s = s[s.length()-1] + s.substr(0,s.length()-1);
    }

    cout << "No" << endl;

}

Measured memory_bytes: 3612
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = a; i >= (b); --i)
#define repdl(i, a, b) for(ll i = a; i >= (b); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void writef(T ...tail) { write(tail...); cout << flush; }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  if (v.size()) {
    rep(i, 0, sz(v) - 1)
      out << v[i] << " ";
    out << v.back();
  }
  return out;
}
#endif
using namespace std;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int n; read(n);
  ll m = 0, ans = 0;
  rep(i, 0, n) {
    ll h; read(h);
    ans += max(m - h, 0ll);
    chmax(m, h);
  }
  write(ans);
}



Measured memory_bytes: 3688
import numpy as np

n, k = map(int, input().split())
A = np.array(list(map(int, input().split())))
A = np.sort(A)

zero = A[A==0]
pos = A[A>0]
neg = A[A<0]

def f(x):
    ans = 0
    if x >= 0:
        ans += n * len(zero)
    ans += np.searchsorted(A, x// pos, side="right").sum()
    ans += (n - np.searchsorted(A, (-x-1)//(-neg), side="right")).sum()
    ans -= np.count_nonzero(A*A<=x)
    return ans // 2

r = 10**18
l = - 10**18
while l < r:
    x = (l+r)//2
    if f(x) >= k:
        r = x
    else:
        l = x + 1
print(r)


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int t[n + 1], x[n + 1], y[n + 1];
    for (int i = 1; i <= n; i++) cin >> t[i] >> x[i] >> y[i];
    string res = "Yes";
    t[0] = x[0] = y[0] = 0;
    for (int i = 0; i < n; i++) {
        int td = abs(t[i + 1] - t[i]);
        int xd = abs(x[i + 1] - x[i]);
        int yd = abs(y[i + 1] - y[i]);
        if (xd + yd > td || (xd + yd + td) % 2) {
            res = "No";
            break;
        }
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
//#define endl "\n"
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define pii pair<int,int> 
long long MOD  = 1e9+7;
const int N = 1e5+10;
vector <int> a[N],inDegree(N);
int dp[N];

int n,m;

signed main(){
    fast;
    cin >> n >> m;
    for(int i=0 ; i<m ; i++){
        int x,y; cin >> x >> y;
        a[x].pb(y);
        inDegree[y]++;
    }

    queue <int> q;
    for(int i=1;  i<=n ; i++){
        if(inDegree[i]==0){
            q.push(i);
        }
    }


    while(!q.empty()){
        int u = q.front();
      //  cout << u << endl;
        q.pop();
        for(auto v : a[u]){
            dp[v] = max((dp[u] + 1) , dp[v]);
            inDegree[v]--;
            if(inDegree[v]==0){
                q.push(v);
            }
        }
    }

    int ans = 0;
    for(int i=1 ; i<=n ; i++){
      //  cout << dp[i] << " " ;
        ans = max(ans,dp[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 7296
fun main(args: Array<String>) {
    abc129d()
}

fun abc129d() {
    val (h, w) = readLine()!!.split(' ').map { it.toInt() }
    val wall = (1..h).map { readLine()!!.map { it == '#' }.toBooleanArray() }
        .toTypedArray()

    // down,up,right,left
    val cSumD = Array(h) { IntArray(w) }
    val cSumU = Array(h) { IntArray(w) }
    val cSumR = Array(h) { IntArray(w) }
    val cSumL = Array(h) { IntArray(w) }

    for (x in 0 until w) {
        for (y in 0 until h) {
            cSumD[y][x] = if (wall[y][x]) 0 else if (y == 0) 1 else cSumD[y - 1][x] + 1
            cSumR[y][x] = if (wall[y][x]) 0 else if (x == 0) 1 else cSumR[y][x - 1] + 1
        }
    }
    for (x in w - 1 downTo 0) {
        for (y in h - 1 downTo 0) {
            cSumU[y][x] = if (wall[y][x]) 0 else if (y == h - 1) 1 else cSumU[y + 1][x] + 1
            cSumL[y][x] = if (wall[y][x]) 0 else if (x == w - 1) 1 else cSumL[y][x + 1] + 1
        }
    }

    var answer = 0

    for (y in 0 until h) {
        for (x in 0 until w) {
            val curr = cSumD[y][x] + cSumU[y][x] + cSumR[y][x] + cSumL[y][x] - 3
            if (curr > answer) answer = curr
        }
    }
    println(answer)
}


Measured memory_bytes: 139824
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i=0,j=0,k=0;
        while(true)
        {
            int sum = 0;
            int n = sc.nextInt();
            int x = sc.nextInt();
            if(n == 0 && x == 0)
                break;
            for(i = 1 ; i <= n - 2 ; i++)
            {
                for(j = i + 1 ; j <= n - 1 ; j++)
                {
                    for(k = j + 1 ; k <= n ; k++)
                    {
                        if(i + j + k == x)
                            sum++;
                    }
                }
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 26932
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,bossNum,boss[200000]={};
  cin>>n;
  for(int i=0;i<n-1;i++){
    cin>>bossNum;
    boss[bossNum-1]++;
  }
  for(int i=0;i<n;i++)
    cout<<boss[i]<<endl;
}

Measured memory_bytes: 4372
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cstring>

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

using namespace std;

const int inf = 100000000;
int n, m;

signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    cin >> n >> m;

    int a[1000], b[1000], c[1000], dist[100][100];

    rep(i,m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
    }

    rep(i,n) rep(j,n) {
        if (i == j) {
            dist[i][j] = 0;
        } else {
            dist[i][j] = inf;
        }
    }

    rep(i,m) {
        dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
        dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
    }

    rep(k,n) rep(i,n) rep(j,n) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }

    int ans = m;
    rep(i,m) {
        bool shortest = false;
        rep(j,n) if (dist[j][a[i]] + c[i] == dist[j][b[i]]) shortest = true;
        if (shortest) {
            ans--;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 384
#include<stdio.h>
#define ll long long

ll k;

int main(){
  scanf("%lld",&k);
  ll ans=-1;
  ll tmp=7;
  for(int i=1;i<=k;i++){
    tmp%=k;
    if(tmp==0){
      ans=i;
      break;}
    tmp=10*tmp+7;}

  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 1728
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
f=array(N)
N.times do|i|
    f[i]=get_i
end
p=array(N)
N.times do|i|
    p[i]=get_i
end
M=10
ans=-INF
1.upto(2**M-1) do|bit|
        cnt=array(N,0)
    M.times do|i|
        unless (bit&(2**i)).zero?
            N.times do|k|
              cnt[k]+=1 if f[k][i]==1 
            end
        end
    end
        val=0
        N.times do|i|
          val+=p[i][cnt[i]] 
        end
        ans=max(ans,val)
end
puts ans

Measured memory_bytes: 14844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}


ll f(ll x){
  if(x==1){
    return 1;
  }
  
  else if(x%2==0){
    return 2*f(x/2)+1;
  }
  
  else{
    return 2*f(x/2)+1;
  }
  
}

int main(){
  ll h;cin>>h;
  cout<<f(h)<<endl;
}

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

int main(){
int a,b;cin >> a >> b;
int ans = 0;
if(a == b){
    for(int i = 0; i < a;i++) ans += a * pow(10,i);
}
else{
    if(a > b) swap(a,b);
    for(int i = 0; i < b;i++) ans += a * pow(10,i);
}

cout << ans << endl;
}

Measured memory_bytes: 384
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

min_idx = 0
min_diff = 10**9

for i in range(len(H)):
    h = H[i]
    diff = abs(A - (T - h*0.006))
    if diff < min_diff:
        min_diff = diff
        min_idx = i
print(min_idx+1)


Measured memory_bytes: 3060
using System;

namespace AtCoder.ABC098
{
    class a
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim();
            var spl = line.Split(' ');
            var a = int.Parse(spl[0]);
            var b = int.Parse(spl[1]);
            Console.WriteLine(Math.Max(a+b, Math.Max(a-b, a*b)));
        }
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

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

			int[] d1 = new int[n];
			int[] d2 = new int[n];

			for (int i = 0; i < n; i++) {
				d1[i] = sc.nextInt();
				d2[i] = sc.nextInt();
			}

			for (int i = 0; i < n - 2; i++) {
				if (d1[i] == d2[i] 
						&& d1[i + 1] == d2[i + 1] 
								&& d1[i + 2] == d2[i + 2]) {
					System.out.println("Yes");
					return;
				}
			}
			System.out.println("No");

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}

Measured memory_bytes: 36044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  string s, t;
  cin >> s >> t;
  string res;
  if (s.size() > t.size()) {
    res = "GREATER";
  } else if (s.size() < t.size()) {
    res = "LESS";
  } else {
    bool flag = 1;
    rep(i, s.size()) {
      if (s.at(i) > t.at(i)) {
        res = "GREATER";
        flag = 0;
        break;
      }
      if (s.at(i) < t.at(i)) {
        res = "LESS";
        flag = 0;
        break;
      }
    }
    if (flag) res = "EQUAL";
  }
  cout << res << endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let x: f64 = read();
    let mut index = 1.0;
    while 360.0 * index % x != 0.0 {
        index = index + 1.0
    }
    println!("{}", 360.0 * index / x)
}


Measured memory_bytes: 2712
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define input_i(x) scanf("%d", &x)
#define input_lli(x) scanf("%lld", &x)
#define input_s(x) scanf("%s", x)

#define BUFSIZE 100001
#define DIV 1000000007

int main(int argc, char const *argv[]) {
    int N, i, j;
    long long int K, match_a= 0, match_b= 0, b_pattern, ans;
    input_i(N);
    input_lli(K);
    int A[N];
    for(i= 0; i < N; i++) {
        input_i(A[i]);
    }

    for(i= 0; i < N; i++) {
        for(j= 0; j < N; j++) {
            if(A[i] > A[j]) {
                match_b++;
                if(i < j) match_a++;  //内部完結
            }
        }
    }
    b_pattern= K * (K - 1) / 2 % DIV;
    ans= (match_a * K) % DIV + (match_b * b_pattern) % DIV;
    printf("%lld\n", (ans % DIV));

    return 0;
}


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

#define PI 3.141592653589793

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false); 


	string s;
	string t;
	cin >> s;
	cin >> t;
	int ans = 0;
	for (int i = 0; i < s.size(); i++){
		if (s[i] != t[i]){
			ans++;
		}
	}
	cout << ans;
	
}

Measured memory_bytes: 3864
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;


int main(void){

    int N; cin>>N;
    vector<int> h(N);
    for (int i = 0; i < N; ++i) {
        cin>>h[i];
    }

    int sa=0,ans=0;
    sa = h[0]; ans = h[0];
    for (int i = 1; i < N; ++i) {
        if(h[i]>=h[i-1]){
            ans+=h[i]-h[i-1];
        }
    }

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

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

D = int(input().strip())
C = list(map(int,input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

ans = 0
score = [0 for i in range(26)]
last = [[-1] for i in range(26)]
schedule = []

for d in range(D):
  t = d%26
  last[t].append(d)
  score[t] += S[d][t]
  schedule.append(t)

for i in range(26):
  last[i].append(D)
  for k in range(len(last[i])-1):
    g = last[i][k+1]-last[i][k]-1
    score[i] -= C[i]*g*(g+1)//2

count = 2000000
import random
while count:
  count -= 1
  prev = score[:]
  d,q = random.choice(range(D)),score.index((min(score)))
  p = schedule[d]
  schedule[d] = q
  score[p] -= S[d][p]
  score[q] += S[d][q]
  
  pos = last[p].index(d)
  score[p] -= C[p]*(last[p][pos]-last[p][pos-1])*(last[p][pos+1]-last[p][pos])
  last[p].remove(d)
  
  pos = bisect.bisect(last[q],d)
  score[q] += C[q]*(d-last[q][pos-1])*(last[q][pos]-d)
  bisect.insort(last[q],d)
  if sum(score)<sum(prev):
    score = prev
    bisect.insort(last[p],d)
    last[q].remove(d)
    schedule[d] = p
    
for i in schedule:
  print(i+1)

Measured memory_bytes: 83796
an, bn, cn, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
la = len(a)
lb = len(b)
lc = len(c)

ans = [a[0] + b[0] + c[0]]
hq = [[a[0] + b[0] + c[0], 0, 0, 0]]
sumi = [[0, 0, 0]]
for _ in range(k - 1):
    mx = hq[0][0]
    ai = hq[0][1]
    bi = hq[0][2]
    ci = hq[0][3]
    hq = hq[1:]
    if ai + 1 < la and [ai + 1, bi, ci] not in sumi:
        hq += [[mx - a[ai] + a[ai + 1], ai + 1, bi, ci]]
        sumi += [[ai + 1, bi, ci]]
    if bi + 1 < lb and [ai, bi + 1, ci] not in sumi:
        hq += [[mx - b[bi] + b[bi + 1], ai, bi + 1, ci]]
        sumi += [[ai, bi + 1, ci]]
    if ci + 1 < lc and [ai, bi, ci + 1] not in sumi:
        hq += [[mx - c[ci] + c[ci + 1], ai, bi, ci + 1]]
        sumi += [[ai, bi, ci + 1]]
    hq.sort(reverse=True)
    ans += [hq[0][0]]

print(*ans,sep="\n")


Measured memory_bytes: 4976
from collections import Counter

H, W = map(int, input().split())
X = [input() for _ in range(H)]

ctr = Counter()
for s in X:
    for c in s:
        ctr[c] += 1

if H % 2 == 0 and W % 2 == 0:
    flg1 = all(v % 4 == 0 for v in ctr.values())
    flg2 = True
elif H % 2 == 1 and W % 2 == 1:
    flg1 = sum(v % 2 == 1 for v in ctr.values()) == 1
    flg2 = sum(v % 4 == 2 for v in ctr.values()) <= H // 2 + W // 2
else:
    flg1 = all(v % 2 == 0 for v in ctr.values())
    flg2 = sum(v % 4 == 2 for v in ctr.values()) <= (W // 2 if W % 2 == 0 else H // 2)

if flg1 and flg2:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38640
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	mod := int64(math.Pow10(9) + 7)
	N := nextInt64()
	K := nextInt64()
	M := N - K

	memo := map[int64]map[int64]int64{}

	for i := int64(1); i <= K; i++ {
		fmt.Println(mulm(combi(M+1, i, mod, memo), combi(K-1, i-1, mod, memo), mod))
	}
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)

	return i
}

// combi はn個の要素からr個の要素を取得する組み合わせ
func combi(n, r, mod int64, memo map[int64]map[int64]int64) int64 {
	if n < r {
		return 0
	}

	var m map[int64]int64

	if memo != nil {
		m, ok1 := memo[n]

		if ok1 {
			c, ok2 := m[r]

			if ok2 {
				return c
			}
		} else {
			m = map[int64]int64{}
			memo[n] = m
		}
	}

	var c int64 = 1

	for i := n; i >= (n - r + 1); i-- {
		c = mulm(c, i, mod)
	}
	for i := r; i >= 1; i-- {
		c = divm(c, i, mod)
	}
	if m != nil {
		m[r] = c
	}
	return c
}

// mod を法とする加算
func addm(a, b, mod int64) int64 {
	return (a + b) % mod
}

// mod を法とする減算
func subm(a, b, mod int64) int64 {
	return (a - b + mod) % mod
}

// mod を法とする乗算
func mulm(a, b, mod int64) int64 {
	return (a * b) % mod
}

// mod を法とする除算
func divm(a, b, mod int64) int64 {
	return mulm(a, invm(b, mod), mod)
}

// mod を法とした逆元
func invm(a, mod int64) int64 {
	// 拡張ユークリッドの互除法
	b := mod
	u := int64(1)
	v := int64(0)

	for b > 0 {
		t := a / b

		a -= t * b
		a, b = b, a

		u -= t * v
		u, v = v, u
	}

	return (u + mod) % mod
}


Measured memory_bytes: 640
import collections
n = int(input())
s = []
for i in range(n):
    s.append(input())
m = int(input())
t = []
for i in range(m):
    t.append(input())

cs = collections.Counter(s)
ct = collections.Counter(t)
#print(cs)
#l = max(n, m)
count = []
count.append(0)
for i in range(n):
    count.append(cs[s[i]] - ct[s[i]])

for j in range(m):
    count.append(cs[t[j]] - ct[t[j]])

print(max(count))
"""from statistics import mode

tmp_list = [1, 1, 1, 1, 0, 1, 1]
print(mode(tmp_list))
u = max(s)"""

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

using namespace std;

typedef long long ll;

int main () {
	ll k;
	string s;
	ll i, j;
	ll ret;
	
	cin >> k >> s;

	if(s.size()>k) {
		cout << s.substr(0,k) <<"..." << endl;
	} else {
		cout << s << endl;
	}
	return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//===

const ll mod = 1000000007;


ll mpow(ll x, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1) res = res * x % mod;
		n >>= 1;
		x = x * x % mod;
	}
	return res;
}


int main() {
	int N, M;
	cin >> N >> M;
	Vi a(M);
	for (int i = 0; i < M; ++i) {
		cin >> a[i];
	}

	map<int, int> m;
	int dmin, dmax;
	if (M == 0) {
		dmin = N + 1;
		dmax = N + 1;
		++m[N + 1];
	}
	else {
		dmin = a[0];
		dmax = a[0];
		++m[a[0]];

		int d;

		for (int i = 0; i < M - 1; ++i) {
			d = a[i + 1] - a[i] - 1;
			dmin = min(dmin, d);
			dmax = max(dmax, d);
			++m[d];
		}

		d = N - a[M - 1];
		dmin = min(dmin, d);
		dmax = max(dmax, d);
		++m[d];
	}




	if (dmin == 0) {
		cout << 0 << endl;
		return 0;
	}

	Vl cnt(dmax + 1);
	cnt[0] = 0;
	cnt[1] = 1;
	cnt[2] = 1;
	for (int i = 3; i <= dmax; ++i) {
		cnt[i] = (cnt[i - 1] + cnt[i - 2]) % mod;
	}

	ll ans = 1;
	for (const auto& kv : m) {
		ans = ans * mpow(cnt[kv.first], kv.second) % mod;
	}

	cout << ans << endl;
}

Measured memory_bytes: 1024
#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)<<"\n"

int main(){
    int n;cin >>n;
    vector<int> a(n),b(n);
    ll sum_a=0,sum_b=0;
    REP(i,n){
        cin >> a[i];
        sum_a+=a[i];
    }
    REP(i,n){
        cin >> b[i];
        sum_b+=b[i];
    }
    int ans=0;
    if(sum_a<sum_b)ans=-1;
    else{
        vector<int> diff;
        ll sum_diff=0;
        REP(i,n){
            if(a[i]<b[i]){
                sum_diff+=(b[i]-a[i]);
                ans++;
            }
            else if(a[i]>b[i]){
                diff.push_back(a[i]-b[i]);
            }
        }
        sort(diff.begin(),diff.end(),greater<>());
        if(ans!=0){
            for(int x:diff){
                sum_diff-=x;
                ans++;
                if(sum_diff<=0)break;
            }
        }
    }
    COUT(ans);
    return 0;
}

Measured memory_bytes: 1408
#!/usr/bin/perl -w
my ($a,$b,$k)=split(/ /,<>);
my @ab;
push @ab,$a;
push @ab,$b;
my ($i);


for($i=0;$i<$k;$i++){
    
    if($ab[$i%2]%2==1){
        $ab[$i%2]--;
    }
    $ab[1-$i%2]+=($ab[$i%2]/2);
    $ab[$i%2]/=2;

}
print "$ab[0] $ab[1]";

Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
long long ans=1e18+5;
long long f(long long b,long long n) {
	if(n<b) {
		return n;
	} else {
		return f(b,n/b)+n%b;
	}
}
long long int m,n,s;
int main() {
	cin>>m>>s;
	if(s>m) {
		cout<<"-1";
		return 0;
	}
	if(s==m) {
		cout<<m+1<<endl;
		return 0;
	}
	long long nn=sqrt(m)+1;
	for(long long x=2; x<=nn; x++) {
	if(f(x,m)==s)
	{
		cout<<x<<endl;
		return 0;
	}
	}
	m-=s;
	for(long long x=1;x*x<=m;x++)
	{
		if(m%x==0)
		{
			long long b=m/x+1;
			if(f(b,m+s)==s)
			{
				ans=min(ans,b);
			}
		}
	}
	if(ans==1e18+5)
	{
		cout<<-1<<endl;
	}
	else
	{
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>

using namespace std;

//Kよりも小さい数字がN%KかK-(N%K)のどちらかなのでそのうちで小さいほうが答えとなる最小値になる。
int main(void) {
	long long int N, K;
	cin >> N >> K;
	long long  int a = N % K;
	long long int b = K - (N % K);
	long long int Ans = min(a, b);
	cout << Ans << endl;
}

//このコード↓のままだとサンプルケースの3つ目が出力が出てこない。多分タイムオーバーにでもなっているのでしょう。

//int main(void) {
//	long long int N, K;
//	cin >> N >> K;
//	//----------------
//	
//	for (long long int i = 0;i < pow(10,18) + 10; i++) {
//		long long int zettaiti = N - K;
//		if ((N - K) < 0) {
//			zettaiti = zettaiti * -1;
//		}
//		if (N < zettaiti) {
//			cout << N << endl;
//			break;
//		}
//		else if (N == zettaiti) {
//			cout << "0" << endl;
//			break;
//		}
//		else if (N > zettaiti) {
//			N = zettaiti;
//		}
//	}
//}



Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

#define ll long long
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll Mypow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}


ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

ll N, A;
vec x;
ll dp[60][5000];

int main(){
  cin >> N >> A;
  x.resize(N);
  rep(i, N){
    cin >> x[i];
    x[i] -= A;
  }


  dp[0][2500] = 1;
  for(int i = 1; i <= N; i++){
    for(int j = 0; j < 5000; j++){
      if(j-x[i-1] < 0)dp[i][j] = dp[i-1][j];
      else dp[i][j] = dp[i-1][j] + dp[i-1][j-x[i-1]];
    }
  }
  cout << dp[N][2500] - 1 << endl;

}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <utility> 
#include <tuple>
#include <iterator>
#include <functional>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; i++)



// union by size + path having
class UnionFind
{
public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_)
    {
        siz.assign(sz_, 1LL); // assign: 再代入
        par.resize(sz_);      // resize: 再確保
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
 
    // Member Function
    // Find
    ll root(ll x)
    { // 根の検索
        while (par[x] != x)
        {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }
 
    // Union(Unite, Merge)
    bool merge(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }
 
    bool issame(ll x, ll y)
    { // 連結判定
        return root(x) == root(y);
    }
 
    ll size(ll x)
    { // 素集合のサイズ
        return siz[root(x)];
    }
};



int main(){
    ll n, m, x, y;
  cin >> n >> m;
  vector<pair<ll, ll>> v(m);
  rep(i,m){
    ll a,b;
    cin >> a >> b;
    v[i].first = a-1;
    v[i].second = b-1;
  }
  
  vector<ll> ans(m);
  ans[m-1] = n*(n-1)/2; 
  UnionFind uf(n);
  for(ll i=m-1; i>=1; --i){
     x = v[i].first;
     y = v[i].second;
     if(uf.issame(x,y)) 
      {ans[i-1] = ans[i];}
    else
    {ans[i-1] = ans[i] - (uf.size(x)*uf.size(y));
     uf.merge(x,y);}
  }
  //reverse(p.begin(), p.end());
  for(ll i=0; i<m; i++){
    cout << ans[i] << "\n"; 
  }
  return 0;
}


Measured memory_bytes: 5248
struct DFS {
    g: Vec<Vec<(usize, usize)>>,
    set: Vec<Vec<usize>>,
}

impl DFS {
    fn new(n: usize) -> DFS {
        DFS {
            g: vec![vec![]; n],
            set: vec![vec![0; n]; n],
        }
    }

    fn search(&mut self, r: usize, u: usize, p: usize, s: usize) {
        self.set[r][u] = s;
        for (v, t) in self.g[u].clone() {
            if v != p {
                self.search(r, v, u, s | t);
            }
        }
    }
}

fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };
    let mut dfs = DFS::new(n);
    for i in 0..(n - 1) {
        let [a, b]: [usize; 2] = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            let mut iter = buf.split_whitespace();
            [
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
            ]
        };
        dfs.g[a].push((b, 1 << i));
        dfs.g[b].push((a, 1 << i));
    }
    for i in 0..n {
        dfs.search(i, i, !0, 0);
    }
    let m: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };
    let mut set: Vec<usize> = Vec::with_capacity(m);
    for _ in 0..m {
        let [u, v]: [usize; 2] = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            let mut iter = buf.split_whitespace();
            [
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
            ]
        };
        set.push(dfs.set[u][v]);
    }

    let mut ans = 1usize << (n - 1);
    for i in 1usize..(1 << m) {
        let mut sum = 0;
        for j in 0..m {
            if i & (1 << j) > 0 {
                sum |= set[j];
            }
        }
        let res = 1 << (n - 1 - sum.count_ones() as usize);
        if i.count_ones() % 2 == 1 {
            ans -= res;
        } else {
            ans += res;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2184
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
	int n, a[100000], ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int j = 1; j < n; j++) {
		if (a[j] > a[j - 1]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3476
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => {
  const x = parseInt(input.split(" ")[0]);
  const y = parseInt(input.split(" ")[1]);  
  const area = x * y;
  const perimeter = 2 * (x + y);
  console.log(area, + " " + perimeter);
});


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

template<typename _Tp>
constexpr _Tp floor(_Tp __x)
{ return __builtin_floor(__x); }

template<typename _Tp>
constexpr _Tp sqrt(_Tp __x)
{ return __builtin_sqrt(__x); }

template<int N>
struct sqrn
{
	constexpr static int max_sqrn = floor(sqrt(N));
	int value[max_sqrn + 1];

	sqrn() : value()
	{
		for (int i = 0; i <= max_sqrn; ++i)
		{
			value[i] = i * i;
		}
	}
  
    int max_under(int n)
    {
      auto p = std::lower_bound(value, value + max_sqrn + 1, n);
      return *p == n ? n : *(p - 1);
    }
};

sqrn<1000000000> SQR;

int main()
{
  int n;
  scanf("%d", &n);
  printf("%d\n", SQR.max_under(n));
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {
	int n,k;
	cin >> n>>k;
	int a[300000] = {};
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int b = 0;
	int c = 0;
	int d[300000] = {};
	for(int i = 1;i<=n;i++){
		if (a[i] != a[i - 1]) {
			d[c] = i-b;
			c++;
			b = i;
		}
	}
	sort(d, d + c+1);
	int ans = 0;
	for (int i = 0; i < c + 1 - k; i++) {
		ans += d[i];
	}
	cout << ans << endl;
	getchar();
	getchar();
	return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
double sigo(double);
double re(double,double,double,double);

main(){
  int a,b,c,d,e,f;
  double x,y;

  while(scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f)!=EOF){
    x=re(a*e,c*e,d*b,f*b);  
    y=re(b*d,c*d,e*a,f*a);
    printf("%.3f %.3f\n",sigo(x),sigo(y));
}
  return 0;
}

double sigo(double a){
  if(a>0){
    a=a*10000+5; 
  }
  else{
    a=a*10000-5;
  }  
  a/=10;
  a=(int)a;  
  return a/1000;
}

double re(double a,double c,double b,double f){  
  return (c-f)/(a-b);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define fr(i,j,n)   for(int i=j;i<n;i++)
#define pb          push_back
#define rf(i,j,p)   for(int i=p;i>=j;i--)
#define vi          vector<int>
#define vll         vector<long long>
#define ll          long long
#define hmm         "\n"
#define sp          " "
#define srt(v)      sort(v.begin(), v.end());
#define down        cout<<hmm;
#define faaast      ios_base::sync_with_stdio(0);cin.tie(nullptr);
using namespace std;
int main()
{
 vector<pair<int, int>>v ;
 int n ; cin >> n ;
 fr(i,1,n+1)
 {
      int tem ;  cin >> tem ;
     v.pb({tem,i});
 }
 srt(v);
 fr(i,0,n)
 {
     cout<<v[i].second<<sp;
 }down ;
}


Measured memory_bytes: 4324
#!/usr/bin/env python3
import sys
import math


input = sys.stdin.readline
def IS(cb): return cb(input().strip())
def IL(cb): return [cb(s) for s in input().strip().split()]
def IR(cb, rows): return [IS(cb) for _ in range(rows)]
def ILL(cb, rows): return [IL(cb) for _ in range(rows)]


def solve():
    A, B, H, M = IL(int)
    A_x = A * math.cos(2 * math.pi * (H * 60 + M) / 12 / 60)
    A_y = A * math.sin(2 * math.pi * (H * 60 + M) / 12 / 60)
    B_x = B * math.cos(2 * math.pi * M / 60)
    B_y = B * math.sin(2 * math.pi * M / 60)
    print(math.sqrt((A_x - B_x) ** 2 + (A_y - B_y) ** 2))
    # theta = 2 * math.pi * abs(H / (12 * 60) - M / 60)
    # print(math.sqrt(A ** 2 + B ** 2 - 2 + A * B * math.cos(theta)))


solve()


Measured memory_bytes: 9604
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
from math import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)

K = ii()
ans = 0

memo = dp3(-1, K+1, K+1, K+1)

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            #l = sorted([i, j, k])
            #l = [i, j, k]
            #a, b, c = l[0], l[1], l[2]
            #a, b, c = i, j, k
            #if memo[a][b][c] != -1:
                #ans += memo[a][b][c]
            #else:
            #memo[i][j][k] = gcd_list([i, j, k])
                #memo[i][k][j] = memo[k][i][j] = memo[k][j][i] = memo[j][i][k] = memo[j][k][i] = memo[i][j][k]
                #memo[i][k][j] = memo[i][j][k]
                #memo[k][i][j] = memo[i][j][k]
                #memo[k][j][i] = memo[i][j][k]
                #memo[j][j][i] = memo[i][j][k]
                #memo[j][i][k] = memo[i][j][k]
            ans += gcd_list([i, j, k])
            #ans += gcd_list([i, j, k])


print(ans)

Measured memory_bytes: 136500
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

if n == m:
    for i in range(n):
        if a[i] != b[i]:
            break
    else:
        print("Yes")
        exit()
    print("No")
    exit()

for i in range(n-m):
    start_h = i
    end_h = i+m
    for j in range(n-m):
        start_w = j
        end_w = j+m
        for k in range(m):
            if a[start_h+k][start_w:end_w] != b[k]:
                break
        else:
            print("Yes")
            exit()
print("No")



Measured memory_bytes: 62948
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <map>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

int main(){
  int mod=1000000007;
  int H,W,K;
  cin>>H>>W>>K;
  int dp[H+1][W];
  for(int h=0;h<H+1;++h){
    for(int w=0;w<W;++w){
      dp[h][w]=0;
    }
  }
  dp[0][0]=1;
  for(int i=0;i<H;++i){
    for(int j=0;j<W;++j){
    for(int k=0;k<(1<<(W-1));++k){
      bool ok=true;
      for(int l=0;l<W-2;++l){
        if(((k>>l)&1)&&((k>>l+1)&1)){
          ok=false;
        }}
      if(ok){
        if(j>=1 && ((k>>(j-1))&1)){
          //move to left
          dp[i+1][j-1]+=dp[i][j];
          dp[i+1][j-1]%=mod;
        }
        else if(j<=W-2 && ((k>>j)&1)){
          //move to right
          dp[i+1][j+1]+=dp[i][j];
          dp[i+1][j+1]%=mod;
        }
        else{
          //not move
          dp[i+1][j]+=dp[i][j];
          dp[i+1][j]%=mod;
        }
      }
      }
    
  }}
  cout<<dp[H][K-1]<<'\n';
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
    const int MAX =200002;
const int MOD =1000000007;

     signed main(){
     int n;
     cin>>n;
     int dp[n][n];
     for(int i=0;i<n;i++)fill(dp[i],dp[i]+n,-MOD*MOD);
      int mx[n],mmx=-MOD*MOD;fill(mx,mx+n,-MOD*MOD);
     int a[3*n],ans2=0;
     for(int i=0;i<3*n;i++){
         cin>>a[i];
         a[i]--;
     }
     dp[a[0]][a[1]]=0;dp[a[1]][a[0]]=0;
     mx[a[0]]=0;mx[a[1]]=0;mmx=0;
     for(int m=0;m<n-1;m++){
         int t=0;
         if(a[3*m+2]==a[3*m+3]&&a[3*m+3]==a[3*m+4]){t=1;ans2++;}
         int z[3];
         for(int i=0;i<3;i++)z[i]=dp[a[3*m+2+i]][a[3*m+2+i]]+1-t;
         if(t==0){
             for(int i=0;i<3;i++){
                 int j=(i+1)%3;
                 int k=(j+1)%3;
                 if(a[3*m+2+i]==a[3*m+2+j]){
                     int b[n];
                     for(int i0=0;i0<n;i0++)b[i0]=dp[a[3*m+2+i]][i0]+1;
                     for(int i0=0;i0<n;i0++){
                         dp[a[3*m+2+k]][i0]=max(b[i0], dp[a[3*m+2+k]][i0]);
                         dp[i0][a[3*m+2+k]]=dp[a[3*m+2+k]][i0];
                     }
                 }
             }
         }
         for(int i=0;i<3;i++){
             int j=(i+1)%3;
             int k=(j+1)%3;
            dp[a[3*m+2+j]][a[3*m+2+k]]=max(dp[a[3*m+2+j]][a[3*m+2+k]],z[i]);
            dp[a[3*m+2+k]][a[3*m+2+j]]=dp[a[3*m+2+j]][a[3*m+2+k]];
         }
         for(int i=0;i<3;i++){
            for(int i0=0;i0<n;i0++) {
                dp[a[3*m+2+i]][i0]=max(dp[a[3*m+2+i]][i0],mx[i0]-t);
                dp[i0][a[3*m+2+i]]=dp[a[3*m+2+i]][i0];
            }
         }
         for(int i=0;i<3;i++){
             int j=(i+1)%3;
             dp[a[3*m+2+i]][a[3*m+2+j]]=max(dp[a[3*m+2+i]][a[3*m+2+j]],mmx-t);
             dp[a[3*m+2+j]][a[3*m+2+i]]=max(dp[a[3*m+2+j]][a[3*m+2+i]],mmx-t);
         }
         for(int i=0;i<3;i++)for(int i0=0;i0<n;i0++){
             mx[i0]=max(mx[i0],dp[a[3*m+2+i]][i0]);
             mmx=max(mx[i0],mmx);
             mx[a[3*m+2+i]]=max(mx[a[3*m+2+i]],dp[a[3*m+2+i]][i0]);
         }


     }
     cout<<max(mmx,dp[a[3*n-1]][a[3*n-1]]+1)+ans2<<endl;
     

     }


 


 






    





      

        


Measured memory_bytes: 34964
#include<stdio.h>
#include<algorithm>
#define N 100005
using namespace std;
long long A[N],B[N],C[N],ans;
int opt[N],m,n,i;
void addconst(int l,int r,int v){
	A[l]+=v;A[r+1]-=v;
}
void addvar(int l,int r,int st,int d){
	B[l]+=st;B[r+1]-=st+(r-l)*d;
	C[l+1]+=d;C[r+1]-=d;
}
void work(int x,int y){
	if (x<y){
		addconst(y+1,n,y-x);
		addconst(1,x,y-x);
		addvar(x+1,y,y-x,-1);
	}else {
		addvar(x+1,n,y+n-x,-1);
		addvar(1,y,y,-1);
		addconst(y+1,x,y+n-x);
	}
}
int main(){
	scanf("%d%d",&m,&n);
	for (i=1;i<=m;i++)
		scanf("%d",&opt[i]);
	for (i=1;i<m;i++)
		work(opt[i],opt[i+1]);
	ans=1e18;
	for (i=1;i<=n;i++){
		A[i]+=A[i-1];
		C[i]+=C[i-1];
		B[i]+=B[i-1];
		B[i]+=C[i];
		ans=min(ans,A[i]+B[i]);
	}
	printf("%lld\n",ans);
}

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

#define ll long long
#define rep(i,N) for(ll i=0; i<N; i++)
const int mx = 2e5;

  vector<ll> path[mx];
  bool seen[mx];
  ll shirushi[mx];
  vector<ll> tg;

void search(){
  vector<ll> tg2;
  rep(i,tg.size()){
    rep(j,path[tg[i]].size()){
      if(!seen[path[tg[i]][j]]){
        seen[path[tg[i]][j]] = true;
        shirushi[path[tg[i]][j]] = tg[i];
        tg2.push_back(path[tg[i]][j]);
      }
    }
  }
  tg.clear();
  rep(i,tg2.size()) tg.push_back(tg2[i]);
  if(tg.size()!=0) search();
  return;
}

void out(ll a){
  if(shirushi[a] == 0 ) return;
  cout << shirushi[a]+1 << " ";
  out(shirushi[a]);
}

int main(void){
  ll N,M;
  cin >> N >> M;
  rep(i,N) seen[i] = false;
  rep(i,N) shirushi[i] = -1;
  rep(i,M){
    ll A,B;
    cin >> A >> B;
    path[A-1].push_back(B-1);
    path[B-1].push_back(A-1);
  }
  
  tg.push_back(0);
  seen[0] = true;
  search();
  
  bool ys=true;
  for(ll i=1; i<N; i++){
    if(!seen[i]) ys = false;
    //cout << i <<":" << seen[i]<<"\n";
  }
  
  if(!ys){
    cout << "No";
  }else{
    cout << "Yes" << "\n";
    for(ll i=1; i<N; i++){
      //cout << i+1 << " ";
      cout << shirushi[i]+1;
      //out(i);
      cout << "\n";
    }
  }
    
  return 0;
}

Measured memory_bytes: 26272
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;

int main(){
    ll N;cin>>N;
    vel B(N-1); rep0(i,N-1){cin>>B[i];
    //cout<<B[i]<<endl;
    }
    ll ans=0;
    vel A(N);
    A[0]=B[0];
    A[N-1]=B[N-2];
    rep0(i,N){
        if(i!=0&&i!=N-1){
            A[i]=min(B[i-1],B[i]);
        }
        //cout<<A[i]<<endl;
    }
    rep0(i,N){
        ans+=A[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * 1625.cc: Origami, or the art of folding paper
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 32;
const int MAX_W = 32;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

int cs[2][MAX_H][MAX_W];

/* subroutines */

/* main */

int main() {
  for (int w, h, t, p;
       scanf("%d%d%d%d", &w, &h, &t, &p) == 4 && w > 0;) {

    for (int y = 0; y < h; y++) fill(cs[0][y], cs[0][y] + w, 1);
    int cur = 0, nxt = 1;

    while (t--) {
      int di, ci;
      scanf("%d%d", &di, &ci);

      memset(cs[nxt], 0, sizeof(cs[nxt]));
      if (di == 1) {
	for (int y = 0; y < h; y++)
	  for (int x = 0; x < w; x++) {
	    if (x < ci) cs[nxt][y][ci - x - 1] += cs[cur][y][x];
	    else cs[nxt][y][x - ci] += cs[cur][y][x];
	  }
	w = max(ci, w - ci);
      }
      else {
	for (int x = 0; x < w; x++)
	  for (int y = 0; y < h; y++) {
	    if (y < ci) cs[nxt][ci - y - 1][x] += cs[cur][y][x];
	    else cs[nxt][y - ci][x] += cs[cur][y][x];
	  }
	h = max(ci, h - ci);
      }

      swap(cur, nxt);
    }

    while (p--) {
      int px, py;
      scanf("%d%d", &px, &py);
      printf("%d\n", cs[cur][py][px]);
    }
  }
  return 0;
}



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

int digitsum(int a){
  int ten=1;
  while(ten<a) ten *= 10;
  int ret=0;
  while(a!=0){ten /= 10; ret += a / ten; a %= ten;}
  return ret;
}

bool check(int a){
  int ten=1;
  while(ten<a) ten *= 10;
  return ten == a;
}

int main(){
  int n;
  cin >> n;
  if(check(n)) cout << 10 << endl;
  else cout << digitsum(n) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	//aは縦の長さ、bは横の長さ、areaは面積を格納、circutiは周の長さを格納
	int a,b,area,circuit;

	//scanf関数でデータを取得
	scanf("%d%d",&a,&b);
	//面積を求める
	area = a*b;
	//周の長さを求める
	circuit = 2*a + 2*b;

	//結果の出力
	printf("%d %d\n",area,circuit);

	return 0;
}


Measured memory_bytes: 1896