akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    set<int> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
    
    const lint maxv=2005;
    struct edge{lint to;lint cost;};
    vector<vector<edge>> x(maxv);
    lint d[maxv];
    void dijkstra(lint s){    
        priority_queue<P,vector<P>,greater<P>>que;
        fill(d,d+maxv,INF);
        d[s]=0;
        que.push(P(0,s));
            while(!que.empty()){
             P p=que.top();que.pop();
             lint v=p.second;
             if(d[v]<p.first)continue;
             rep(i,x[v].size()){
                 edge e=x[v][i];
                 if(d[e.to]>d[v]+e.cost){
                     d[e.to]=d[v]+e.cost;
                     que.push(P(d[e.to],e.to));
                 }
             }   
            }
}
    
  int main(){
       lint n,a,b;
       cin>>n>>a>>b;
        --a;--b;
        x[a].push_back({b,1});
        x[b].push_back({a,1});
        rep(i,n-1){
            x[i].push_back({i+1,1});
            x[i+1].push_back({i,1});
        }
    vector<lint> ans(2005);
    fill(all(ans),0);
    rep(i,n){
        dijkstra(i);
        rep(j,n){
            ans[d[j]]++;
        }
    }
    rep(i,n-1){
        cout<<ans[i+1]/2<<endl;
    }
  } 
      
      
    

  
          
  

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) (vec).begin(),(vec).end()
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void orz(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18;
/***********************************************************************/
struct edge {
  int fm, to;
  i64 w;
};
vector<int> vis;
vector<vector<int>> adj;
void dfs (int u) {
  vis[u] = 1;
  for (int v : adj[u]) if (!vis[v]) dfs(v);
}
int32_t main() {
 
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n, m; 
  i64 p;
  cin >> n >> m >> p;
  vector<edge> g;
  adj.resize(n);
  for (int i = 0; i < m; ++i) {
    int a, b; 
    i64 c;
    cin >> a >> b >> c;
    --a; --b;
    adj[a].push_back(b);
    g.push_back({a, b, p - c});
  }
  vis.assign(n, 0);
  dfs(0);
  auto rch = vis;
  //~ const i64 NEG_LIM = -1e10;
  vector<i64> dis(n, INF);
  dis[0] = 0;
  for (int iter = 0; iter < n - 1; ++iter) {
    for (const auto e : g) {
      uin(dis[e.to], dis[e.fm] + e.w);
    }
  }
  set<int> cand;
  for (const auto e : g) {
    if (uin(dis[e.to], dis[e.fm] + e.w) && rch[e.to]) cand.insert(e.to);
  }
  for (int c : cand) {
    vis.assign(n, 0);
    dfs(c);
    if (vis[n - 1]) orz(-1);
  }
  orz(max(0LL, -dis[n - 1]));
  
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, n, ans = 0, min = 1e9, a;
  bool now = false;
  scanf("%lld", &n);
  for(i = 0; i < n; ++i) {
    scanf("%lld", &a);
    if(a < 0) now = !now;
    a = a > 0 ? a : -a;
    ans += a;
    if(min > a) min = a;
  }
  if(now) ans -= min * 2;
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 128
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        n: usize, k: usize,
        a_vec: [usize; n],
    }

    let mut l = 0;
    let mut r = 1e9 as usize;

    while r - l > 1 {
        let m = ( l + r ) / 2;
        let ok = |m, k, a_vec: &Vec<usize>| {
            let t = a_vec.iter().map(|a| (a - 1) / m).sum::<usize>();
            t <= k
        };
        if ok(m, k, &a_vec) {
            r = m
        } else {
            l = m
        }
    }

    println!("{}", r);
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 5380
N = int(input())
flg = True
for a in range(0,N//4 + 1):
    for b in range(0,N//7 + 1):
        total = 4*a + 7*b
        if total == N:
            flg = False
            break
if(flg):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  unordered_set<string> set;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    set.insert(s);
  }
  cout<<set.size()<<endl;

  return 0;
}




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

int main() {
  int A,B;
  cin >> A >> B;
  int a = A*B;
  int b = a*2;
  int c = a*3;
  if(a%2 == 1 || b%2 == 1 || c%2 == 1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

int main(){
  int a, b, c, d;
  cin>>a >>b >>c;
  d = 3*max({a, b, c}) - (a+b+c);
  if(d % 2 == 0){
    cout<<d / 2<<endl;
  }else{
    cout<<d/2+2<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define INF 1000000001
#define MOD 100000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
int main(){
      ll n,a,b,c;
      cin>>n>>a>>b>>c;
      vector<int> d(n);
      REP(i,n)cin>>d[i];
      sort(d.begin(),d.end(),greater<int>());
      ll ans=c/a;
      REP(i,n){
            ll res=c;
            REP(j,i+1)res+=d[j];
            ans=max(ans,res/((i+1)*b+a));
      }
      cout<<ans<<endl;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
int main() {
    long long n,a,b;
    scanf("%lld %lld %lld",&n,&a,&b);
    if((b-a)%2==0) printf("%lld",(b-a)/2);
    else printf("%lld",min(a+(b-a-1)/2,n-b+1+(b-a-1)/2));
    return 0;
}


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

using namespace std;

int main() {
	int N;
	cin >> N;
	int P[8], Q[8];
	for (int i = 0; i < N; i++) {
		cin >> P[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> Q[i];
	}
	
	int ans1 = 0;
	int ans2 = 0;

	while (next_permutation(P, P + N)) {
		ans1++;
	}

	while (next_permutation(Q, Q + N)) {
		ans2++;
	}

	if (ans1 < ans2) {
		cout << ans2 - ans1;
	}
	else {
		cout << ans1 - ans2;
	}
	
	return 0;
}

Measured memory_bytes: 256
# ALDS1_6_B
def partition(a, p, r):
    x = a[r]
    i = p
    for j in range(p, r):
        if a[j] <= x: # 最後の要素が基準
            a[i], a[j] = a[j], a[i]
            i += 1
    a[i], a[r] = a[r], a[i]
    return i

n = int(input())
a = list(map(int, input().split()))
index = partition(a, 0, n-1)
print(*a[:index], "[" + str(a[index]) + "]", *a[index+1:])


Measured memory_bytes: 16384
#include<stdio.h>

int main() {
	int n,x,i=1,j;

	scanf("%d", &n);

	while (i <= n) {
		x = i;
		if (x % 3 == 0) {
			printf(" %d", i);
		}
		else {
			j = 0;
			while (x != 0&&j<1) {
				if (x % 10 == 3) {
					printf(" %d", i);
					j++;
				}
				x = x / 10;
			}
		}
		i++;
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2056
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <queue>
#define PII pair<int, int>
#define T3I tuple<int, int, int>
using namespace std;

typedef long long ll;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;

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

    int n, x, y;
    cin >> n >> x >> y;
    int d = y-x-1;
    for(int k = 1; k < n; ++k) {
        ll res = 0;
        res += max(x-k, 0);
        //cout << res << " ";
        res += max(n-y+1-k, 0);
        //cout << res << " ";
        for(int j = x+1; j <= y; ++j) {
            if(2*j > x+y+1) {
                int i = x+y+1-j-k;
                if(i >= 1 && i < x) ++res;
            }else {
                int i = j-k;
                if(i > 0 && i < x) ++res;
            }
        }
        //cout << res << " ";
        for(int i = 1; i < x; ++i) {
            int j = i+k+d;
            if(j > y && j <= n) ++res;
        }
        //cout << res << " ";
        int D = y-x+1;
        if(2*k <= D) {
            res += max(D-k, 0);
        }
        //cout << res << " ";
        for(int i = x; i <= y; ++i) {
            int j = y-x+1+i-k;
            if(j > i && j <= y && y-x+1 < 2*(j-i)) ++res;
        }
        //cout << res << " ";
        for(int i = x; i < y; ++i) {
            if(2*i+1 < x+y) {
                int j = x+y-1-i+k;
                if(j > y && j <= n) ++res;
            }else {
                int j = i+k;
                if(j > y && j <= n) ++res;
            }
        }
        //cout << res << " " << endl;
        if(k == 1 && y-x == 1) ++res;
        cout << res << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using plll=pair<ll,pll>;
using graph=vector<vector<int>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

void pushHeap(vector<int>& h,int n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]<h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

int popHeap(vector<int>& h){
  int n=h.size()-1;
  if(n==-1)return 0;
  int i,ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]<h[j+1])j++;
    if(h[i]<h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

int num=0;
int c[10000],d[10000];

void dfs(const graph &g,int v){
  d[v]=c[num++];
  for(auto i:g[v]){
    if(d[i]!=0)continue;
    dfs(g,i);
  }
}

int main(){
  int i,j,k,cnt=0;
  int n;
  cin>>n;
  int a[n-1],b[n-1];
  graph g(n);
  for(i=0;i<n-1;i++){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  for(i=0;i<n;i++)cin>>c[i];
  sort(c,c+n,greater<int>());
  for(i=0;i<n;i++)d[i]=0;
  dfs(g,0);
  ll ans=0;
  for(i=0;i<n-1;i++){
    ans+=min(d[a[i]],d[b[i]]);
  }
  cout<<ans<<endl;
  cout<<d[0];
  for(i=1;i<n;i++){
    cout<<" "<<d[i];
  }
  cout<<endl;
}

Measured memory_bytes: 1280
import math
N=int(input())
a=list(map(int,input().split()))
c_list=[]
for i in range(N):
    c_list.append(a[i]-i-1)
c_list.sort()

if len(c_list)%2!=0:
    ind=math.ceil(len(c_list)/2)
    b=c_list[ind-1]
else:
    ind=int(len(c_list)/2)
    b=math.floor((c_list[ind]+c_list[ind-1])/2)
d=0
for i in c_list:
    d+=abs(i-b)
print(d)
    
    

Measured memory_bytes: 26608
#include <iostream>
using namespace std;
 
void zibun(int n);
 
int main(){
    
    
    int n;
    cin>>n;
    zibun(n);
    
  
    
    return 0;
}
void zibun(int n){
    int b=1;
    for(int i=n;3<i;i=i-7){
        if(i%4==0){
            cout<<"Yes"<<endl;
            b=0;
            break;
        }else if(i%7==0){
            cout<<"Yes"<<endl;
            b=0;
            break;
        }    }
    if(b==1){
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<algorithm>
#include<string>

using namespace std;


int main()
{
	int t;
	string s;
	priority_queue<int> q;

	ios::sync_with_stdio(false);

	while(1)
	{
		cin >> s;
		if (s == "insert")
		{
			cin >> t;
			q.push(t);
		}
		else if (s == "end")
		{
			break;
		}
		else
		{
			cout << q.top() << endl;
			q.pop();
		}

	}

	
	

	return 0;

}


Measured memory_bytes: 7052
#encoding=utf-8
import sys

def inp():
    for line in sys.stdin:
        word = line.split()
        je(word[0])

def je(word):
    ans, i = 0, 0
    while True:
        if word[i] == "M":
            ans += 1000
        elif word[i] == "D":
            ans += 500
        elif word[i] == "C":
            ans += 100
            try:
                if word[i + 1] == "M":
                    ans += 800
                    i += 1
                elif word[i + 1] == "D":
                    ans += 300
                    i += 1
            except: pass

        elif word[i] == "L":
            ans += 50
        elif word[i] == "X":
            ans += 10
            try:
                if word[i + 1] == "C":
                    ans += 80
                    i += 1
                elif word[i + 1] == "L":
                    ans += 30
                    i += 1
            except: pass

        elif word[i] == "V":
            ans += 5
        elif word[i] == "I":
            ans += 1
            try:
                if word[i + 1] == "X":
                    ans += 8
                    i += 1
                elif word[i + 1] == "V":
                    ans += 3
                    i += 1
            except: pass

        i += 1
        if i == len(word):
            print ans
            break

if __name__ == "__main__":
    inp()

Measured memory_bytes: 6284
#include <bits/stdc++.h>
#define fup(i,a,b) for(int i=a;i<=b;++i)
#define fdw(i,a,b) for(int i=a;i>=b;--i)
#define sync ios::sync_with_stdio(false);cin.tie(0)
#define cl(a) memset(a,0,sizeof(a))
#define gcd __gcd
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
//ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//ll ksm(ll a,ll b,ll mod){ll ans=1;a%=mod;for(;b;b>>=1){if(b&1) ans=ans*a%mod;a=a*a%mod;}return ans;}
//ll oula(ll n){ ll res=n;for(ll i=2;i*i<=n;i++){if(n%i==0){ res=res-res/i;while(n%i==0) n/=i;}}if(n>1) res=res-res/n;return res;}
//bool MRT(ll x){if(x==2)return true;fup(i,1,30){ll now=rand()%(x-2)+2;if(ksm(now,x-1,x)!=1)return false;}return true;}
//void shai(int n)fup(i,2,n){if(isprime[i]){v.push_back(i);for(int j=2*i;j<=10000;j+=i)isprime[j]=0;}}//"埃氏筛筛选素数"
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const int N = 1e5 + 10 ;

int main()
{
    sync;
    string s,t,u;
    int a,b;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(u==s)
    {
        cout<<a-1<<' '<<b<<endl;
    }else cout<<a<<' '<<b-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>
#define ll int64_t
#define REP(i, n) for (ll i=0; i<n; i++)
using namespace std;

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

    ll H, W, D;
    cin >> H >> W >> D;
    vector<vector<ll>> A(H, vector<ll>(W));
    vector<pair<ll, ll>> grid(H*W);    
    REP (i, H) {
        REP (j, W) {
            cin >> A[i][j];
            A[i][j]--;
            grid[A[i][j]] = make_pair(i, j);
        }
    }
    ll Q;
    cin >> Q;
    vector<ll> L(Q), R(Q);
    REP (i, Q) cin >> L[i] >> R[i];


    vector<ll> cost(H*W, 0);
    for (ll i = 0; i <= H * W - D - 1; i++) {
        cost[i] = abs(grid[i+D].first - grid[i].first)
                + abs(grid[i+D].second - grid[i].second);       
    }

    // for (auto e : grid) {
    //     cout << e.first << " " << e.second << endl;
    // }

    vector<ll> s(H*W+D, 0);
    REP (i, H*W) {
        s[i+D] = s[i] + cost[i];
    }

    REP (i, Q) {
        cout << s[R[i]-1] - s[L[i]-1] << "\n";
    }

}

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

#define rep(i,a,b) for(int i=a;i<b;i++)

typedef tuple<int, int, int, int> tiiii;

int dx_l[4] = { 1, -1, 0, 0 };
int dy_l[4] = { 0, 0, 1, -1 };
int dx_r[4] = { -1, 1, 0, 0 };
int dy_r[4] = { 0, 0, 1, -1 };

string solve(int W, int H)
{
	char room_l[50][50];
	char room_r[50][50];

	rep(y, 0, H)
	{
		string l, r;
		cin >> l >> r;
		rep(x, 0, W) room_l[y][x] = l[x];
		rep(x, 0, W) room_r[y][x] = r[x];
	}

	int slx, sly, srx, sry;

	rep(y, 0, H) rep(x, 0, W)
	{
		if (room_l[y][x] == 'L')
		{
			slx = x;
			sly = y;
		}
		if (room_r[y][x] == 'R')
		{
			srx = x;
			sry = y;
		}
	}

	vector<bool> done(50 * 50 * 50 * 50, false);
	stack<tiiii> _stack;
	_stack.push(make_tuple(slx, sly, srx, sry));
	done[slx*50*50*50+sly*50*50+srx*50+sry] = true;
	while (!_stack.empty())
	{
		tiiii t = _stack.top();
		_stack.pop();

		int lx = get<0>(t);
		int ly = get<1>(t);
		int rx = get<2>(t);
		int ry = get<3>(t);

		rep(i, 0, 4)
		{
			int lxx = lx + dx_l[i];
			int lyy = ly + dy_l[i];
			int rxx = rx + dx_r[i];
			int ryy = ry + dy_r[i];
			
			if (lxx < 0 || W <= lxx) lxx = lx;
			if (lyy < 0 || H <= lyy) lyy = ly;
			if (rxx < 0 || W <= rxx) rxx = rx;
			if (ryy < 0 || H <= ryy) ryy = ry;

			if (room_l[lyy][lxx] == '%' && room_r[ryy][rxx] != '%') continue;
			if (room_l[lyy][lxx] != '%' && room_r[ryy][rxx] == '%') continue;
			if (room_l[lyy][lxx] == '%' && room_r[ryy][rxx] == '%') return "Yes";

			if (room_l[lyy][lxx] == '#')
			{
				lxx = lx;
				lyy = ly;
			}

			if (room_r[ryy][rxx] == '#')
			{
				rxx = rx;
				ryy = ry;
			}

			if (!done[lxx * 50 * 50 * 50 + lyy * 50 * 50 + rxx * 50 + ryy])
			{
				done[lxx * 50 * 50 * 50 + lyy * 50 * 50 + rxx * 50 + ryy] = true;
				_stack.push(make_tuple(lxx, lyy, rxx, ryy));
			}
		}
	}

	return "No";
}

int main()
{
	while (1)
	{
		int W, H;
		cin >> W >> H;
		if (W == 0) return 0;

		cout << solve(W, H) << endl;
	}
}

Measured memory_bytes: 9728
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
    string s;
    cin >> s;
    int counter = 0;
    int max_num = 0;
    for(size_t i = 0; i < s.size(); i++)
    {
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            counter ++;
        }else{
            max_num = max(counter, max_num);
            counter = 0;
        }
    }
    max_num = max(counter, max_num);
    cout << max_num << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String s = input.next();
        String ans = "No";
        for (int i = 0; i < s.length()-1; i++){
            if (s.substring(i,i+2).equals("AC")){
                ans = "Yes";
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23508
#include<iostream>
#include<string>
#include<cmath>

using namespace std;

int main() {
	string s, lis[100];
	char x;
	int n,len;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		len = s.length() - 1;
		if (i != 0&&x!=s[0]){
				cout << "No";
				return 0;
		}
		for (int j = 0; j < i; j++) {
			if (lis[j] == s) {
				cout << "No";
				return 0;
			}
		}
		x = s[len];
		lis[i] = s;
	}
	cout << "Yes";
	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<iomanip>
#include <algorithm>

#include <sstream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
static const int MAX = 101;

int N;
int F[MAX][11];
int P[MAX][11];

int main(int argc, const char * argv[]) {
    int i,j;

    cin >> N;
    for(i = 1; i <= N; i++) {
        for (j = 1; j <= 10 ; j++) {
            cin >> F[i][j];
        }
    }

    for(i = 1; i <= N; i++) {
        for (j = 0; j <= 10; j++) {
            cin >> P[i][j];
        }
    }
    
    ll ans = -99999999999;
    for (int a = 0; a <= 1; a++) {
        for (int b = 0; b <= 1; b++) {
            for (int c = 0; c <= 1; c++) {
                for (int d = 0; d <= 1; d++) {
                    for (int e = 0; e <= 1; e++) {
                        for (int f = 0; f <= 1; f++) {
                            for (int g = 0; g <= 1; g++) {
                                for (int h = 0; h <= 1; h++) {
                                    for (int k = 0; k <= 1; k++) {
                                        for (int l = 0; l <= 1; l++) {
                                            int R[] = {0,a,b,c,d,e,f,g,h,k,l};
                                            bool flag = false;
                                            for (i = 0; i < 10; i++) {
                                                if (R[i] == 1) {
                                                    flag = true;
                                                    break;
                                                }
                                            }
                                            if (!flag) continue;
                                            
                                            ll tmp = 0;
                                            for (i = 1; i <= N; i++) {
                                                int count = 0;
                                                for (j = 1; j <= 10; j++) {
                                                    if (F[i][j] == 1 && R[j] == 1) {
                                                        count++;
                                                    }
                                                }
                                                tmp += P[i][count];
                                            }
                                            ans = max(ans, tmp);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
    cout << ans << endl;
    

    

    return 0;
}


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

int main() {
	while(1){
		int a,b;
		char op;
		cin >> a >> op >> b;
		if(op == '?') break;
		if(op == '+') cout << a+b <<endl;
		else if(op == '-') cout << a-b <<endl;
		else if(op == '*') cout << a*b <<endl;
		else cout << a/b <<endl;
	}
	return 0;
}


Measured memory_bytes: 3108
import heapq
N , M = map(int , input().split())
jobs = [list(map(int , input().split())) for _ in range(N)]
jobs.sort()

q = []
index = 0
ans = 0
for limit in range(1 , M + 1):
    while index < N:
        time =jobs[index][0]
        reward = jobs[index][1]
        if limit >= time:
            heapq.heappush(q , -reward)
            index += 1
        else:
            break
    #print(q)
    if len(q) != 0:
        tmp = heapq.heappop(q)
        ans -= tmp

print(ans)


Measured memory_bytes: 78168
#include<iostream>
#include<vector>
#include<map>
#include<utility>
using namespace std;
using ll = long long int;
constexpr char L = 'L';
constexpr char R = 'R';
constexpr char U = 'U';
constexpr char D = 'D';


int h, w, n;
int sr, sc;
int rlu, clu;
int rrd, crd;
string s, t;
int scnt[4] = { 0 }, tcnt[4] = { 0 };

void setCharCnt(int* scnt, char c) {
	if (c == L)
		scnt[0]++;
	else if (c == R)
		scnt[1]++;
	else if (c == U)
		scnt[2]++;
	else
		scnt[3]++;
}

void move(char c) {
	if (c == L)
		sr--;
	else if (c == R)
		sr++;
	else if (c == U)
		sc--;
	else
		sc--;
}

int main(void) {
	cin >> h >> w >> n;
	cin >> sr >> sc;
	cin >> s;
	cin >> t;
	sr--; sc--;
	for (int i = 0; i < n; i++) {
		setCharCnt(scnt, s[i]);
		setCharCnt(tcnt, t[i]);
	}

	rlu = sr; clu = sc;
	rrd = sr; crd = sc;
	string ret = "YES";
	//左方向と上方向
	for (int i = 0; i < n; i++) {
		char si = s[i], ti = t[i];

		if (si == L)
			clu--;
		else if (si == R)
			crd++;
		else if (si == U)
			rlu--;
		else if (si == D)
			rrd++;
		if (0 <= rlu && rlu < h && 0 <= clu && clu < w && 0 <= rrd && rrd < h && 0 <= crd && crd < w) {
			if (ti == L && 0 < crd)
				crd--;
			else if (ti == R && clu < w - 1)
				clu++;
			else if (ti == U && 0 < rrd)
				rrd--;
			else if (ti == D && rlu < h - 1)
				rlu++;
		}
		else {
			ret = "NO";
			break;
		}
	}
	cout << ret << endl;
	return 0;

}

Measured memory_bytes: 776
inputs = [int(i) for i in input().split()]

min_abs_value = 1000
result = 0

for i in range(1, inputs[0]+1):
    value = inputs[1] + i - 1
    result += value
    if (abs(value) < abs(min_abs_value)):
        min_abs_value = value

result -= min_abs_value
print(result)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cmath>

#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{


    string s;
    
    cin >> s;
    
    if(s == "ABC")
    {
        cout << "ARC";
    }
    else
    {
        cout << "ABC";
    }
    
    
}

Measured memory_bytes: 3624
// 解答不能.
// 以下のソースコードを勉強する.
// pekempey氏.
// https://atcoder.jp/contests/abc141/submissions/7530985
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

using vec = bitset<100001>;

bool solve(vector<vec> A, int N, int M){
    int r = 0;
    for(int j = 0; j < M; j++){
        int p = -1;
        for(int i = r; i < N; i++){
            if(A[i][j]){
                p = i;
                break;
            }
        }
        if(p == -1) continue;
        swap(A[r], A[p]);
        for(int i = r + 1; i < N; i++) if(A[i][j]) A[i] ^= A[r];
        r++;
    }
    for(int i = r; i < N; i++) if(A[i][M]) return false;
    return true;
}

int main(){
    int N;
    scanf("%d", &N);
    vector<ll> A(N); rep(i, N) scanf("%lld", &A[i]);
    ll ans = 0;
    vector<int> f, taken;
    repr(i, 60){
        int cnt = 0;
        rep(j, N) if(A[j] >> i & 1) cnt++;
        if(cnt % 2 == 1){
            ans += 1LL << i;
        }else{
            f.push_back(i);
            vector<vec> X(f.size());
            rep(r, f.size()){
                rep(j, N) X[r][j] = A[j] >> f[r] & 1;
            }
            rep(r, taken.size()) X[r][N] = taken[r];
            X[taken.size()][N] = 1;
            if(solve(X, f.size(), N)) taken.push_back(1);
            else                      taken.push_back(0);
        }
    }
    rep(r, f.size()) if(taken[r]) ans += 1LL << f[r] + 1;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 2640
// ITP1_9_A
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// 大文字の区別しない
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    string w,t;
    cin>>w>>t;
    int ans=0;
    for(int i=0;i<w.size();i++){
        if('A'<=w[i] and w[i]<='Z')w[i]+='a'-'A';
    }
    while(t!="END_OF_TEXT"){
        for(int i=0;i<t.size();i++){
            if('A'<=t[i] and t[i]<='Z')t[i]+='a'-'A';
        }
        if(w==t) ans+=1;
        cin>>t;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3228
#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++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int n;cin>>n;
  string s;
  string o;
  cin>>s;
  o=s;
  set<string> st;
  st.insert(o);
  int c=0;
  rep(i,n-1){
    cin>>s;
    if(st.end()!=st.find(s)) c++;
    else{
      st.insert(s);
    }
    if(o[o.size()-1]!=s[0]){
      c++;
    }
    o=s;
  }
  Ans(c==0);
}


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

int main(){

    int n;cin >> n;
    vector<int> d(n,0);
    for(int i=0;i<n;++i)cin >> d.at(i);

    int sum=0;
    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j){
            sum+=d.at(i)*d.at(j);
        }
    }

    cout << sum << endl;

    return 0;

}


Measured memory_bytes: 256
N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]
ans = 0
for i in range(N):
	temp = 0
	for j in range(i+1):
		temp += A[0][j]
	for j in range(i, N): 
		temp += A[1][j]
	ans = max(ans, temp)
print(ans)

Measured memory_bytes: 3060
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007

long long int getpow(long long int x, long long int n)
{
    if (n == 0)
        return 1;
    long long int tmp = getpow(x, n / 2);
    long long int ans = (tmp * tmp) % MOD;
    if (n % 2 == 1)
        ans = (ans * x) % MOD;
    return ans;
}

int main()
{
    int n;
    cin >> n;
    long long int x[100000];
    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    long long int revsum[100010] = {};
    for (int i = 1; i <= n; i++)
    {
        revsum[i] = revsum[i - 1] + getpow(i, MOD - 2);
        revsum[i] %= MOD;
    }
    long long int ans = 0;
    for (int j = 0; j < n - 1; j++)
    {
        ans += (x[j + 1] - x[j]) * revsum[j + 1];
        ans %= MOD;
    }
    for (int i = 1; i <= n - 1; i++)
    {
        ans *= i;
        ans %= MOD;
    }
    cout << ans << endl;
}

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

const double PI = 3.141592653589;

int main() {
	int h, w, i, j;

	while(true) {
		cin >> h >> w;
		if (h == 0 && w == 0) break;

		for (i = 0; i < h; i++){
			for (j = 0; j < w; j++){
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;

	}

	return 0;
}


Measured memory_bytes: 3080
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a,0,sizeof(a))
#define minus(a) memset(a,0xff,sizeof(a))
#define chmax(a,b) a=min((a),(b))
#define chmin(a,b) a=max((a),(b))


#define MOD 1000000007



ll n, a,b;
ll x[100005];

int main(){
	scanf("%lld %lld %lld ", &n, &a, &b);
	rep(i, n) {
		scanf("%lld ", &x[i]);
	}
	ll ans = 0LL;
	FOR(i, 1, n-1) {
		ans += min(b, a*(x[i] - x[i - 1]));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n, m;
	cin >> n >> m;
	vector<set<int>> path(n);
	vector<int> h(n);
	rep(i, n) cin >> h[i];
	while (m--) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		path[a].insert(b);
		path[b].insert(a);
	}
	ll ans = 0;
	rep(i, n) {
		bool good = true;
		for (int x : path[i]){
			if (h[i] <= h[x]) {
				good = false;
				break;
			}
		}
		if (good) ans++;
	}
	cout << ans << endl;
}


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

using namespace std;

auto fft(vector<complex<double>> f, int n, int sign) {
  if (n == 1)
    return f;
  vector<complex<double>> f0(n/2), f1(n/2);
  for (int i = 0; i < n/2; i++) {
    f0[i] = f[2*i];
    f1[i] = f[2*i+1];
  }
  f0 = fft(f0, n/2, sign);
  f1 = fft(f1, n/2, sign);
  complex<double> zeta(cos(M_PI*2/n), sin(M_PI*2/n)*sign);
  complex<double> pow_zeta = 1;
  for (int i = 0; i < n; i++) {
    f[i] = f0[i%(n/2)] + pow_zeta*f1[i%(n/2)];
    pow_zeta *= zeta;
  }
  return f;
}

auto inv_fft(vector<complex<double>> f, int n) {
  f = fft(f, n, -1);
  for (auto& ff : f)
    ff /= n;
  return f;
}

auto multiply(vector<complex<double>> g, vector<complex<double>> h) {
  int n = 1;
  while (n <= g.size()+h.size())
    n*=2;
  g.resize(n);
  h.resize(n);
  auto gg = fft(g, n, 1);
  auto hh = fft(h, n, 1);
  vector<complex<double>> ff(n);
  for (int i = 0; i < n; i++) {
    ff[i] = gg[i] * hh[i];
  }
  return inv_fft(ff, n);
}

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

  long N,M; cin>>N>>M;
  vector<int> A(N);
  for (auto& a : A) cin>>a;

  const int max_A = *max_element(A.begin(), A.end());
  vector<complex<double>> cnt(max_A+1);
  for (auto a : A) cnt[a] += 1;

  auto cnv = multiply(cnt, cnt);
  long ans = 0;
  long buf = M;
  for (int i = max_A*2; i >= 0; i--) {
    auto n = min(long(cnv[i].real()+0.5), buf);
    ans += i * n;
    buf -= n;
    if (buf == 0)
      break;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 45244
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t=1,n,i,l,m,x,y,z;
    while(t--)
    {
        int j=0,s=0,k=0,g=0;
        cin>>m>>n>>l;
        vector <int> a;
        vector <int> b;
        for(i=0;i<m;i++)
        {
            cin>>x;
            a.push_back(x);
        }
        for(i=0;i<n;i++)
        {
            cin>>x;
            b.push_back(x);
        }
        int p=0;
        for(i=0;i<m;i++)
        {
            if(p+a[i]<=l)
            {
                p+=a[i];
                k++;
            }
            else break;
        }
        //if (i==m)
        {
            for (j=0;j<n;j++)
            {
                if (p+b[j]<=l) 
                {
                    p+=b[j];
                    k++;
                }
                else break;
            }
            s=k;
            // cout<<j<<" is j "<<endl;
        }
        //else 
        int j1=j;
        {
            for (z=i-1;z>=0;z--)
            {
                // cout<<z<<" z";
                p-=a[z];
                k-=1;
                // cout<<p<<" p "<<k<<" k ";
                for (;j1<n;j1++)
                {
                    // cout<<p+b[j1]<<endl;
                    if (p+b[j1]<=l)
                    {
                        p+=b[j1];
                        k++;
                        if (s<k) s=k;
                    }
                    else break;
                }
            }
            cout<<s<<endl;
        }
    }
}


Measured memory_bytes: 5628
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let s: String = scan(tokens);
    let s = s.into_bytes();
    if s[0] != s[1] {
        println!("Yes");
    } else if s[1] != s[2] {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

int main() {
  int N,M;
  cin >> N >> M;
  char A[N][N+1];
  char B[M][M+1];
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for(int i = 0; i < M; i++) {
    cin >> B[i];
  }

  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) {
      if(i + M > N || j + M > N) break;
      bool ok = true;
      for(int k = 0; k < M; k++) {
        for(int l = 0; l < M; l++) {
          if(A[i + k][j + l] != B[k][l]) {
            ok = false;
            k = M;
            break;
          }
        }
      }
      if(ok) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;

}


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

int main() {
	int n, x;
	bool card[4][13] = {{false}};
	char ch;

	cin >> n;
	
	for(int i = 0; i < n; i++){
		cin >> ch >> x;

		if(ch == 'S') card[0][x - 1] = true;
		else if(ch == 'H') card[1][x - 1] = true;
		else if(ch == 'C') card[2][x - 1] = true;
		else if(ch == 'D') card[3][x - 1] = true;
	}

	for (int j = 0; j < 4; j ++){
		for (int k = 0; k < 13; k++){
			if (!card[j][k]){
				if (j == 0) cout << "S" << " " << k + 1 << endl;
				else if (j == 1) cout << "H" << " " << k + 1 << endl;
				else if (j == 2) cout << "C" << " " << k + 1 << endl;
				else if (j == 3) cout << "D" << " " << k + 1 << endl;
			}
		}
	}


	return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define mod 1000000007
int dh[4]={1,0,-1,0};
int dw[4]={0,1,0,-1};
typedef struct{
    int h;
    int w;
}Pos;
int h,w;
int Max = 0;
string s[20];
void solve(int sh,int sw){
    queue<Pos> que;
    que.push((Pos){sh,sw});
    int map[20][20] = {0}; map[sh][sw] = 1;
    while(!que.empty()){
        int ch = que.front().h; int cw = que.front().w;
        if(Max<map[ch][cw]) Max = map[ch][cw];
        que.pop();
        for(int i=0;i<4;i++){
            int nh=ch+dh[i]; int nw=cw+dw[i];
            if(map[nh][nw]||nh<0||nh>=h||nw<0||nw>=w||s[nh][nw]=='#') continue;
            map[nh][nw] = map[ch][cw] + 1;
            que.push((Pos){nh,nw});
        }
    }
}
int main(void){
    cin >> h >> w;
    rep(i,h) cin >> s[i];
    //rep(i,h) cout << s[i] << endl;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#') continue;
            else solve(i,j);
        }
    }
    cout << Max - 1 << endl;
}






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

using namespace std;

const int N = 3e5 + 5;
int ans[N], n, a, b;

pair <int, int> check() {
	vector <int> f(n + 5, 0), g(n + 5, 0);
	int c, d; c = d = 0;
	for (int i = 1; i <= n; ++i) {
		f[i] = g[i] = 1;
		for (int j = 1; j < i; ++j) {
			if (ans[i] > ans[j]) f[i] = max(f[i], f[j] + 1);
			if (ans[i] < ans[j]) g[i] = max(g[i], g[j] + 1);
			c = max(c, f[i]);
			d = max(d, g[i]);
		}
	}
	return {c, d};
}

int main(int argc, char const *argv[])
{
	srand(time(NULL));
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> n >> a >> b;

	// for (int i = 1; i <= n; ++i) ans[i] = i; random_shuffle(ans + 1, ans + 1 + n);
	// a = check().first, b = check().second;
	// cout << a << ' ' << b << endl;
	// for (int i = 1; i <= n; ++i) cout << ans[i] << ' '; cout << endl;

	if (b == 1) {
		if (a != n) {
			cout << -1 << endl;
			return 0;
		}
		for (int i = 1; i <= n; ++i) cout << i << ' ';
		return 0;
	}

	for (int i = n - b + 1; i <= n; ++i) {
		ans[i] = n - (i - (n - b + 1));
	}
	int rem = n - b;
	a--;
	if (a > rem) {
		cout << -1 << endl;
		return 0;
	}
	if (a == rem) {
		for (int i = 1; i <= rem; ++i)
			ans[i] = i;
	} else {
		if (rem / b + (rem % b != 0) > a) {
			cout << -1 << endl;
			return 0;
		}
		for (int i = 1; i <= rem; ++i) ans[i] = i;
		int del = rem - a;
		int i = 1;
		for (i = 1; i <= n; i += b) {
			// cerr << i << ' ' << del << endl;
			if (del >= b - 1) {
				reverse(ans + i, ans + i + b);
				del -= b - 1;
			} else {
				reverse(ans + i, ans + del + i + 1);
				break;
			}
		}
	}
	for (int i = 1; i <= n; ++i) cout << ans[i] << ' ';
	cout << endl;
	// pair <int, int> D = check();
	// cout << D.first << ' ' << D.second << endl;

	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;

}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x) 
{
    return (ll)(log(x) / log(base));
}
ll lcm(ll x,ll y)
{
	return (x*y)/__gcd(x,y);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll j,l,m,h,w,f,n,k,b,ans;
    	string s;
    	cin>>s;
    	f=1;
    	rep(i,1,4)
    	{
    		if(s[i]==s[i-1])
    		f=0;
		}
		if(f)
		cout<<"Good";
		else
		cout<<"Bad";
    }
	return 0;
}

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

int N,M;
string A[50],B[50];

bool check(int si, int sj){
  for(int i = si; i < si + M; i++){
    for(int j = sj; j < sj + M; j++){
      if(A[i][j] == B[i-si][j-sj]) continue;
      else return false ;
    }
  }
  return true;
}

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

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

  for(int i = 0; i < N - M + 1; i++){
    for(int j = 0; j < N - M + 1; j++){
      if(check(i,j)){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256