akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;
using pr  = pair<ll, ll>;

const ll MOD = 1000000007;

int main()
{
	string S, T;
	cin >> S >> T;

	for (int i = 0; i < S.length(); ++i)
	{
		if (S[i] == T[i]) { continue; }

		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
void sunday(string s)
{
    if(s == "SUN")
        cout<<7;
    else if(s == "MON")
        cout<<6;
    else if(s == "TUE")
        cout<<5;
    else if(s == "WED")
        cout<<4;
    else if(s == "THU")
        cout<<3;
    else if(s == "FRI")
        cout<<2;
    else if(s == "SAT")
        cout<<1;
}
int main()
{
    string s;
    cin>>s;
    sunday(s);
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
typedef unsigned long long ll;

int main(){
ll N,K; cin >> N >> K ;
vector<ll> H(N);
for(ll i = 0; i < N; i++){
	cin >> H[i];
}
sort(H.rbegin(),H.rend());
if(N <= K){
	cout << 0 << endl;
}
else{
	ll sum = 0;
	for(ll i = 0; i < K; i++){
		H[i] = 0;
	}
	for(ll i = 0; i < N;i++){
		sum += H[i];
	}
	cout << sum << endl;
}
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  vector<vector<ll>> dp(n+1, vector<ll>(n+1, LINF));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) dp[i][1] = h[i-1];
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      for (int l = 2; l <= j+1; l++)
        chmin(dp[i][l], dp[j][l-1]+max(h[i-1]-h[j-1], 0));
    }
  }
  ll ans = LINF;
  rep(i, n+1)
    chmin(ans, dp[i][n-k]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
# ABC069D
from collections import deque
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

ans_list = [[0] * W for _ in range(H)]
ans = 0
cnt = 0
for h in range(H):
    if h % 2 == 0:
        for w in range(W):
            if cnt == A[ans]:
                cnt = 0
                ans += 1
            ans_list[h][w] = ans + 1
            cnt += 1
    else:
        for w in range(W-1, -1, -1):
            if cnt == A[ans]:
                cnt = 0
                ans += 1
            ans_list[h][w] = ans + 1
            cnt += 1

for a in ans_list:
    print(*a)

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int r, D, x;
    cin>> r>>D>>x;

    REP(i, 10){
        x=r*x-D;
        cout<<x<<endl;
    }



   return 0;
}

Measured memory_bytes: 256
j,p[1<<20],n;
main(i)
{
	for(;++i<999;)
		if(!p[i])
			for(j=i+i;j<1<<20;j+=i)
				p[j]=1;
	for(;scanf("%d",&n),j=0,n;printf("%d\n",j))
		for(i=2;i<=n/2;i++)if(!p[i]&!p[n-i])j++;
	exit(0);



}

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

typedef struct node{
	int key=0;
	node *left=nullptr,*right=nullptr;
	node(){};
	node(int s):key(s){};
}node;

class BinarySearchTree{
private:
	node *root = new node;
	vector<int> inorder,preorder;
	int num_of_nodes=0;
public:
	BinarySearchTree(){};
	void insert(int value){
		if(num_of_nodes==0){
			root->key=value;
			num_of_nodes++;
			return;
		}
		getInsertPosition(root, value);
	}
	void getInsertPosition(node *now,int value){
		if(now->key>value){
			if(now->left==nullptr){
				node *tmp = new node;
				tmp->key=value;
				now->left=tmp;
			}else getInsertPosition(now->left, value);
		}else{
			if(now->right==nullptr){
				node *tmp = new node;
				tmp->key=value;
				now->right=tmp;
			}else getInsertPosition(now->right, value);
		}
	}
	void dfs(node *now){
		// cout<<"root = "<<root->key<<endl;
		num_of_nodes+=1;
// 		if(num_of_nodes>20)return ;
		preorder.push_back(now->key);
		// cout<<now->key<<endl;
		if(now->left!=nullptr)dfs(now->left);
		inorder.push_back(now->key);
		if(now->right!=nullptr)dfs(now->right);
		return;
	}
	void printVector(vector<int> a){
		for(auto x:a)cout<<" "<<x;
		cout<<endl;
	}

	void solve(){
		inorder.clear(),preorder.clear();
		dfs(root);
		// cout<<"DFS!!!"<<endl;
		printVector(inorder);
		printVector(preorder);
	}
};


int main()
{
	int n;
	cin>>n;
	BinarySearchTree BST;
	rep(i,n){
		string command;
		cin>>command;
		if(command=="insert"){
			int value;
			cin>>value;
			BST.insert(value);
		}else{
			BST.solve();
		}
	}

	return 0;
}


Measured memory_bytes: 24592
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n,m = readline() |> split |> parseMap
	dp = (10^9)*ones(Int,m+1,2^n)
	dp[1,1] = 0
	for i in 1:m
		a,b = readline() |> split |> parseMap
		c = readline() |> split |> parseMap
		d = 0
		for j in 1:b
			d += 2^(c[j]-1)
		end
		for j in 1:2^n
			dp[i+1,j] = dp[i,j]
		end
		for j in 1:2^n
			dp[i+1,((j-1)|d)+1] = min(dp[i+1,((j-1)|d)+1],dp[i,j]+a)
		end
	end
	if dp[m+1,2^n] == 10^9
		println(-1)
	else
		println(dp[m+1,2^n])
	end
end
main()

Measured memory_bytes: 176076
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

int main(void){
	string s; cin >> s;
	int k = 0;
	while(s[k] == 'T') k++;
	int cnt = 0;
	int ans = 0;
	for (int i = k; i < s.size(); ++i){
		if(s[i] == 'S') cnt++;
		else if(s[i] == 'T'){
			if(cnt > 0){
				ans++; cnt--;
			}
		}
	}
	printf("%d\n", s.size() - ans * 2);
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#include <complex>
#include <atcoder/all>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
using namespace atcoder;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vii = vector<vi>;
using vl = vector<ll>; using vll = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();

int main()
{
  int n,m; cin >> n >> m;
  vector<ll> a(n);
  rep(i,n) {
    scanf("%lld", &a[i]);	
  }
  vector<ll> b(m);
  rep(i,m) {
    scanf("%lld", &b[i]);	
  }

  
  vector<ll> res = convolution<998244353>(a, b);
  for(auto val: res) cout << val << " ";
  cout << "\n";
  
  return 0;
}


Measured memory_bytes: 27264
#include <bits/stdc++.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
signed main(){
	int a;
	cin>>a;
	for(int i=a;;i++){
		bool b=true;
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				b=false;
				break;
			}
		}
		if(b){
			cout<<i<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005
bool palin(string x)
{
	ll n=x.length();
	rep(i,0,n/2)
	{
		if(x[i]!=x[n-i-1])
			return false;
	}
	return true;
}
int main()
{
	
	io

	string x;
	cin>>x;
	ll n=x.length();
	string s1="",s2="";
	rep(i,0,n/2)
	{
		s1+=x[i];
	}
	rep(i,n/2+1,n)
	{
		s2+=x[i];
	}
	if(palin(s1)&& palin(s2)&& palin(x))
		cout<<"Yes";
	else
		cout<<"No";
	
}

Measured memory_bytes: 256
use std::io;
use std::io::prelude::*;

fn main() -> io::Result<()> {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input)?;
    io::stdout().write_all(match input.as_str() {
        "ABC\n" => b"ARC\n",
        "ARC\n" => b"ABC\n",
        _ => panic!("Unknown event"),
    })?;
    Ok(())
}

Measured memory_bytes: 2132
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <codecvt>
#include <locale>
using namespace std;
using ll = long long;

int main() {
    char a, b;
    cin >> a >> b;
    if(a == 'H' && b == 'H' || a == 'D' && b == 'D') {
        cout << 'H' << endl;
    } else {
        cout << 'D' << endl;
    }
}


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

int N,M;
int A[10000];

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

  if(N < sum) {
    puts("-1");
    return 0;
  }
  cout << N-sum<<endl;
}

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    print(min(b, n * a));

    return 0;
}


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

struct node{
long long a,b;
}arr[100005];
int main()
{
    int n,i,j;
    while(~scanf("%d",&n))
    {
        long long cnt=0;
        for(i=0;i<n;i++)
            scanf("%lld%lld",&arr[i].a,&arr[i].b);
        for(i=n-1;i>=0;i--)
        {
            arr[i].a+=cnt;
            if(arr[i].a%arr[i].b)
                cnt+=(arr[i].b-arr[i].a%arr[i].b);
        }
        printf("%lld\n",cnt);
    }
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
const int INF = 1e18;

int z[90001];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w, d, q; cin >> h >> w >> d;
    map<int,pair<int,int>> mp;
    REP(i,h)REP(j,w){
        int a; cin >> a;
        mp[a] = {i,j};
    }
    for(int i=d+1; i <= h*w; i++){
        z[i] = z[i-d] + abs(mp[i].first-mp[i-d].first) + abs(mp[i].second-mp[i-d].second);
    }
    cin >> q;
    while(q--){
        int l, r; cin >> l >> r;
        cout << z[r] - z[l] << '\n';
    }
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
//useful library
int long long gcd(int long long a, int long long b){
    return b?gcd(b,a%b):a;
} //最大公約数
int long long lcm(int long long a, int long long b){
    return a/gcd(a,b)*b;
} //最小公倍数
int long long GetDigit(int long long num){
    int long long digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
} //桁数
int long long GetDigitN(int long long num, int long long N){
    int long long digit=0;
    while(num!=0){
        num /= N;
        digit++;
    }
    return digit;
} //十進数でnumの際のN進数における桁数

int main(){
    unsigned int long long A;
    long double B;
    cin >> A >> B;
    //int C = B * 1000;
    cout << std::fixed << std::setprecision(0) << floor((A*B)) << endl;
    return 0;
}


Measured memory_bytes: 3828
import sys
import collections
import bisect


def main():
    n = int(input())
    a = [str(i + 1)[0] + str(i + 1)[-1] for i in range(n)]
    b = [str(i + 1)[-1] + str(i + 1)[0] for i in range(n)]
    ac, bc = collections.Counter(a), collections.Counter(b)
    acKeys = ac.keys()
    bcKeys = bc.keys()
    cnt = 0
    for i in acKeys:
        cnt += ac[i] * bc[i]
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 37760
import sys
sys.setrecursionlimit(10**6)
n,m=map(int,input().split())
adj=[]
dp=[0 for i in range(0,n+1)]
def dfs(i,p,adj,dp):
    # print(i)
    # print(i,p)
    if dp[i]!=0:
        return dp[i]
    for j in (adj[i]):
        if j==p:
            continue 
        else:
            dfs(j,i,adj,dp)
            dp[i]=max(dp[i],1+dp[j])
    return dp[i]
    
for i in range(n+1):
    adj.append([])
for _ in range(m):
    u,v=map(int,input().split())
    adj[u].append(v)

for i in range(1,n+1):
    if dp[i]==0:
        dfs(i,i,adj,dp)
# print(dp)
print(max(dp))

Measured memory_bytes: 59056
h, w = map(int, input().split())
s = ['.' + input() + '.' for _ in range(h)]
s = ['.' * (w + 2)] + s + ['.' * (w + 2)]

for y in range(1, h + 1):
    for x in range(1, w + 1):
        if s[y][x] == '.':
            continue
        ok = False
        for dy, dx in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            if s[y + dy][x + dx] == '#':
                ok = True
        if not ok:
            print('No')
            exit()
print('Yes')


Measured memory_bytes: 9100
import sys
import queue

n=int(input())

clis=[[] for i in range(n)]

for i in range(n-1):
  ai,bi,ci=map(int,input().split())
  clis[ai-1].append([bi,ci])
  clis[bi-1].append([ai,ci])

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

xy=[]

for i in range(q):
  xy.append(list(map(int,input().split())))


distance=[0 for i in range(n)]
seen=[0 for i in range(n)]

que=queue.Queue()

que.put(k)
seen[k-1]=1

while not que.empty():
  c=que.get()
  for aa,cc in clis[c-1]:
    if seen[aa-1]==0:
      distance[aa-1]=distance[c-1]+cc
      seen[aa-1]=1
      que.put(aa)

for i in range(q):
  print(distance[xy[i][0]-1]+distance[xy[i][1]-1])

Measured memory_bytes: 69816
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
    int a[3] = {};
    int A, B;
    cin >> A >> B;
    a[A - 1]++;
    a[B - 1]++;
    for(int i = 0; i < 3; i++) {
        if(a[i] == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <climits>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
void solve(int n){
	long dp[10][10],ans=INT_MAX,ans2;
	rep(i,10) rep(j,10) dp[i][j]=INT_MAX;

	rep(i,n){
		int f,t,l;
		cin>>f>>t>>l;
		dp[f][t]=l;dp[t][f]=l;
		dp[i][i]=0;
	}

	rep(k,10) rep(i,10) rep(j,10) dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
	int numofnINF=0;

	rep(i,10) if(dp[0][i]!=INT_MAX) numofnINF++;

	rep(i,10){
		long acc=0;
		rep(j,numofnINF) acc+=dp[i][j];
		if(ans>acc){ans=acc;ans2=i;}
	}
	cout<<ans2<<' '<<ans<<endl;
	return;
}

int main(){
	int c;
	cin>>c;
	while(c){
		solve(c);
		cin>>c;
	}
	return 0;
}

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


int main(){
	string s,s2;
	cin >> s >> s2;
	sort(s.begin(),s.end());
	sort(s2.rbegin(),s2.rend());
	if(s.size()==s2.size()){
		if(s<s2) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else{
		int x=min(s.size(),s2.size());
		for(int i=0;i<x;i++){
			if(s[i]>s2[i]){
				cout << "No" << endl;
				return 0;
			}
			else if(s[i]<s2[i]){
				cout << "Yes" << endl;
				return 0;
			}
		}
		if(s.size()<s2.size()) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N,_=gets.chomp.split(" ").map{|n| n.to_i}
A=gets.chomp.split(" ").map{|n| n.to_i}
mode = 0
cnt = 0
for i in 1..(A.size-1)
	if(mode==0)
		if(A[i] < A[i-1])
			# puts "mode -1"
			mode = -1
		elsif(A[i] > A[i-1])
			# puts "mode 1"
			mode = 1
		end
	else
		if(mode==1 && A[i] < A[i-1])
			# puts "hoge"
			mode = 0
			cnt += 1
		end
		if(mode==-1 && A[i] > A[i-1])
			mode = 0
			cnt += 1
		end
	end
end
puts cnt+1




Measured memory_bytes: 9476
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    int N, K;
    cin >> N >> K;
    vector<ll> H(N);
    for(int i = 0; i < N; i++) cin >> H[i];
    sort(all(H));
    ll min_n = LL_INF;
    for(int i = 0; i < N - K + 1; i++){
        min_n = min(min_n, H[i + K - 1] - H[i]);
    }
    cout << min_n << endl;
}

Measured memory_bytes: 4040
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    ll N; cin >> N;
    vector<ll> H(N);
    for (ll i = 0; i < N; ++i) cin >> H[i];

    reverse(H.begin(), H.end());

    for (ll i = 0; i < N - 1; ++i) {
        if (H[i] >= H[i + 1]) { continue; }
        else if (H[i]+1 == H[i + 1]) { --H[i+1]; }
        else { cout << "No" << endl; return 0; }
    }
    cout << "Yes" << endl; return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000
#define ff first
#define ss second
#define ll long long
#define int long long
#define mod 1000000007
#define pii pair<ll,ll>
#define vi vector<ll>
#define mii map<ll,ll>
#define pb push_back
#define mp make_pair
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) ll x; cin>>x; while(x--)
#define endl '\n'
#define str string
void kehsihba(){
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
	//kehsihba();
	str s;
	cin>>s;
	stack<char>st;
	int n=s.length();
	for(int i=0;i<n;i++){
		if(s[i]!='B'){
			st.push(s[i]);
		}
		else{
			if(st.empty()!=1){
				st.pop();
			}
		}
	}
	str ans="";
	while(st.empty()!=1){
		ans=st.top()+ans;
		st.pop();
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
struct Service{
  int index;
  ll w;
  int t, x;
  bool operator < (const Service& s) const {
    if(w != s.w) return w < s.w;
    else return index < s.index;
  }
};

int main(){
  int N, Q;
  while(cin >> N >> Q){
    vector<Service> ss(N);
    REP(i, N) cin >> ss[i].w >> ss[i].t >> ss[i].x;
    REP(i, N) ss[i].index = i;
    sort(ss.begin(), ss.end());
    const int D = 3652425;
    vector<ll> rp(D + 2, 0);
    ll k[3] = {};
    k[0] = 1;
    static ll dk[D + 2][3] = {};
    memset(dk, 0, sizeof(dk));
    vector<int> rp_day(N, INF);
    int ans = INF;
    int ss_idx = 0;
    for(ll d = 1; d <= D + 1; d++){
      ll p = rp[d - 1];
      while(ss_idx < N && p >= ss[ss_idx].w){
        Service& s = ss[ss_idx++];
        rp_day[s.index] = d - 1;
        if(s.t == 0){
          k[0]++;
          if(d + s.x <= D + 1) dk[d + s.x][0] ++;
        }else if(s.t == 1){
          k[1]++;
          k[0] += -(d - 1);
          if(d + s.x <= D + 1){
            dk[d + s.x][1] ++;
            dk[d + s.x][0] += -(d - 1);
          }
        }else{
          k[2]++;
          k[1] += -2 * (d - 1);
          k[0] += (d - 1) * (d - 1);
          if(d + s.x <= D + 1){
            dk[d + s.x][2] ++;
            dk[d + s.x][1] += -2 * (d - 1);
            dk[d + s.x][0] += (d - 1) * (d - 1);
          }
        }
      }
      REP(i, 3) k[i] -= dk[d][i];
      rp[d] = p + k[0] + k[1] * d + k[2] * d * d;
    }
    REP(i, N) {
      if(rp_day[i] > D) cout << "Many years later" << endl;
      else cout << rp_day[i] << endl;
    }
    REP(i, Q){
      int y; cin >> y;
      cout << rp[y] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 118048
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}

void solve(){
    ll n, k;
    cin >> n ;
    vector<ll> v;
    rep(i, n)
    {
        ll x; cin >> x;
        if(v.empty())v.pb(x);
        else if(v.back() != x) v.pb(x);
    }
    ll ans = 0;
    for(ll i = 0, j = 0; i < v.size();){
        if(v[i] > v[i+1]){
            while(v[j] > v[j+1] && j+1 < v.size()) j++; j++;
        }
        else{
            while(v[j] < v[j+1] && j+1 < v.size()) j++; j++;
        }
        ans++; //cout << j << " ";
        i = j;
    }
    cout << ans;
}

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}



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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 200010

ll N;
vector<ll> A;


void Dump(const vector< pair<ll, ll> >& cur) {
    REP(i, cur.size()) { DBG("cur[%lld] = {%lld, %lld}\n", i, cur[i].first, cur[i].second); }
}

// 文字種 alph_max で A を乗り切れるなら true
bool check(ll alph_max) {
    vector< pair<ll, ll> > cur;
    cur.clear();
    // 現在の文字列
    // first: インデックス second: 値
    // 未入力部分は基本 1 が入ることになる
    //cur.push_back(make_pair(A[0], 1));
    //Dump(cur);

    for(ll i = 1; i < N; ++i) {
        DBG("i: %lld A[i]: %lld\n", i, A[i]);
        if(A[i - 1] < A[i]) {
            // 長くなるなら、後ろに最小文字を追加
            //cur.push_back(make_pair(A[i], 1));
        }
        else {
            if(alph_max == 1) {
                DBG("FALSE1\n");
                return false;
            }

            // 見る必要のないインデックスの値は捨てる
            while(cur.size() > 0 && cur[cur.size()-1].first > A[i]) {
                cur.pop_back();
            }
            if(cur.size() == 0) {
                cur.push_back(make_pair(A[i], 2));
                continue;
            }

            bool isOk = false;
            ll ind = A[i];
            for(ll j = cur.size()-1; j >= 0; --j) {
                if(cur[j].first != ind) {
                    assert(cur[j].first < ind);
                    // 自分より後ろをクリア
                    while(cur.size() > j + 1) { cur.pop_back(); }
                    cur.push_back(make_pair(ind, 2));
                    isOk = true;
                    break;
                }
                else if(cur[j].second < alph_max) {
                    cur[j].second += 1;
                    // 自分より後ろをクリア
                    while(cur.size() > j + 1) { cur.pop_back(); }
                    isOk = true;
                    break;
                }
                ind--;
            }
            if(!isOk) {
                if(ind > 0) {
                    cur.clear();
                    cur.push_back(make_pair(ind, 2));
                }
                else {
                    DBG("FALSE2\n");
                    return false;
                }
            }
        }
        Dump(cur);
    }
    DBG("TRUE\n");
    return true;
}

ll solve() {
    ll lb = 1;
    ll ub = N;
    while(ub - lb > 1) {
        ll mid = (lb + ub) / 2;
        DBG("-----\n");
        DBG("mid: %lld\n", mid);
        if(check(mid)) { ub = mid; }
        else { lb = mid + 1; }
    }
    DBG("-----\n");
    DBG("lb: %lld\n", lb);
    if(check(lb)) { return lb; }
    DBG("-----\n");
    DBG("ub: %lld\n", ub);
    assert(check(ub));
    return ub;
}

signed main()
{
    cin >> N;
    A.resize(N);
    REP(i, N) { cin >> A[i]; }
    ll ans = solve();
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;
using PII = pair<ll, ll>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << '\n'; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<'\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define p_yes() p("YES")
#define p_no() p("NO")
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())
#define MP make_pair

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

const ll mod = 1e9 + 7;
const ll inf = 1e18;
const double PI = acos(-1);

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

    // input
    ll N; 
    cin >> N;
    
    string s,t;cin>>s>>t;

    rep(i, N){
      cout << s[i] << t[i];
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main(){
  var N int
  fmt.Scanf("%d", &N)
  n := N % 10
  
  if n == 3 {
    fmt.Println("bon")
    return
  }else if n == 0 || n == 1 || n == 6 || n == 8{
    fmt.Println("pon")
    return
  }
  fmt.Println("hon")
}


Measured memory_bytes: 1820
class Tree
  def initialize(edges)
    @edges = edges
  end

  def diameter
    r = @edges.keys.first
    v, _ = farthest_vertex(r)
    u, d = farthest_vertex(v)
    [v, u, d]
  end

  private

  def farthest_vertex(s)
    queue = [[s, 0]]
    dist = -1
    fv = -1
    visited = Hash.new(false)

    until queue.empty?
      v, d = queue.shift

      next if visited[v]
      visited[v] = true

      if dist < d
        dist = d
        fv = v
      end

      @edges[v].each do |u|
        queue.push([u, d + 1])
      end
    end

    [fv, dist]
  end
end

N = gets.to_i
E = Hash.new { |h, k| h[k] = [] }

(N - 1).times do 
  a, b = gets.split.map(&:to_i)

  E[a] << b
  E[b] << a
end

tree = Tree.new(E)

_, _, dist = tree.diameter

if N == 1
  puts 'First'
elsif (dist - 1) % 3 == 0
  puts 'Second'
else
  puts 'First'
end


Measured memory_bytes: 80220
#include <stdio.h>
int main()
{
	int i,mon[10],height[3],j,index;
	for(i=0;i<10;i++)scanf("%d",&mon[i]);
	for(i=0;i<3;i++)
	{
		height[i]=0;
		for(j=1;j<10;j++)
			if(mon[j]>mon[height[i]])
			{
				height[i]=j;
			}
		index=height[i];
		height[i]=mon[height[i]];
		mon[index]=0;
	}
	for(i=0;i<3;i++)printf("%d\n",height[i]);
	return 0;
}

Measured memory_bytes: 1740
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <set>
#include <sstream>
#include <vector>
using namespace std;

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

    long long N;
    cin >> N;

    int min = numeric_limits<int>::max();
    for (long long i = 1; i * i <= N; i++)
    {
        if (N % i == 0)
        {
            int di = (int)(floor(log10(i)) + 1);
            int dm = (int)(floor(log10(N / i)) + 1);

            int t = (di >= dm) ? di : dm;
            if (t < min)
            {
                min = t;
            }
        }
    }

    cout << min << endl;
    return 0;
}

Measured memory_bytes: 640
def resolve():
    n, y = map(int, input().split())
    for i in range(n+1):
        for j in range(n+1):
            if 10000*i+5000*j+1000*(n-i-j) == y and n-i-j >= 0:
                print('{} {} {}'.format(i, j, n-i-j))
                return
    print('-1 -1 -1')
resolve()

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;


int main(){
   string s;
   cin>>s;
   int ans1=0;
   int ans2=0;
   for(int i=0;i<s.size();i++){
       //0101
       if(i%2==0){
           if(s[i]=='1')ans1++;
       }
       else {
           if(s[i]=='0')ans1++;
       }
   }
   for(int i=0;i<s.size();i++){
       //1010
       if(i%2==0){
           if(s[i]=='0')ans2++;
       }
       else {
           if(s[i]=='1')ans2++;
       }
   }
   cout<<min(ans1,ans2)<<endl;

    
}


Measured memory_bytes: 512
let partition (a : int array) p r =
  let i = ref p in
  for j = p to r - 1 do
    if a.(j) <= a.(r) then begin
      let tmp = a.(!i) in
      a.(!i) <- a.(j);
      a.(j) <- tmp;
      incr i;
    end
  done;
  let tmp = a.(!i) in
  a.(!i) <- a.(r);
  a.(r) <- tmp;
  !i

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  let k = partition a 0 (n - 1) in
  Array.iteri
    (fun i e ->
      if i = 0 then print_int e
      else if i = k then (print_string " ["; print_int e; print_string "]")
      else (print_string " "; print_int e))
    a;
  print_newline ()

Measured memory_bytes: 5268
n = int(input())

counts = {(i + 1, j + 1): [0, 0] for i in range(9) for j in range(i, 9)}
for i in range(n):
  num = str(i + 1)
  s = int(num[0])
  e = int(num[-1])
  if e == 0:
    continue
  if s <= e:
    counts[(s, e)][0] += 1
  else:
    counts[(e, s)][1] += 1

count = 0
for (a, b), (v1, v2) in counts.items():
  if a == b:
    count += v1 * v1
  else:
    count += v1 * v2 * 2

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <string>

using namespace std;

int main(){
    int qtd = 0;
    string s;
    cin >> s;
    for(char i = 'a'; i <='z'; i++){
        qtd = 0;
        for(int j = 0; j < s.size(); j++){
            if(s[j]==i){
                qtd++;
            }
        }
        if(qtd==0){
            cout << i;
            break;
        }
    }
    if(qtd > 0){
        cout << "None";
    }
    return 0;
}

Measured memory_bytes: 512
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int N, K;
    string S;
    
    cin >> N >> K;
    cin >> S;
    string ans = "";
    S.at(K-1) = tolower(S.at(K-1));
    
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
x,k,d = gets.split.map(&:to_i)

if x.abs > k*d
  p (x.abs - k*d)
else
  w = x.abs/d
  k2 = k - w
  x2 = x.abs - w*d
  x2 *= -1 if x < 0
  if k2%2==0
    p x2.abs
  else
    p (x2.abs-d).abs
  end
end

Measured memory_bytes: 14384
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n,m,k;

int main() {
  cin >> n >> m >> k;
  bool ok = false;

  for(ll i = 0; i <= n; i++) {
    for(ll j = 0; j <= m; j++) {
      if(k == n * j + m * i - 2 * i * j) {
	ok = true;
	break;
      }
    }
  }

  if(ok) cout << "Yes" <<endl;
  else cout << "No" << endl;
}
  


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

int main(){
  string sa,sb,sc;
  cin >> sa >> sb >> sc;

  int ca=0,cb=0,cc=0;
  char card = 'a';

  while(true){
    if(card=='a'){
      if(ca>=sa.size()){
        cout << 'A' << endl;
        return 0;
      }
      card = sa[ca];
      ca++;
    }
    else if(card=='b'){
      if(cb>=sb.size()){
        cout << 'B' << endl;
        return 0;
      }
      card = sb[cb];
      cb++;
    }
    else {
      if(cc>=sc.size()){
        cout << 'C' << endl;
        return 0;
      }
      card = sc[cc];
      cc++;
    }
  }
}

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

int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	int N;
	N = B / A;
	int answer;
	answer = min(N, C);
	cout << answer << endl;


	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a[10000], b[10000];
	int sumA, sumB;
	int n;
	int i;
	
	sumA = 0;
	sumB = 0;
	
	while(1){
		scanf("%d", &n);
		
		if(n==0) break;
		
		for(i=0; i<n; i++){
			scanf("%d %d", a+i, b+i);
		}
		
		/*
		for(i=0; i<n; i++){
			printf("%d %d\n", a[i], b[i]);
		}
		*/
		
		for(i=0;i<n;i++){
			if(a[i] > b[i]) sumA += a[i]+b[i];
			if(a[i] < b[i]) sumB += a[i]+b[i];
			if(a[i] == b[i]){
				sumA += a[i];
				sumB += b[i];
			}
		}
		
		printf("%d %d\n", sumA, sumB);
		
		sumA = 0;
		sumB = 0;
		
	};
	
}

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

ans = 0
for i in range(n):
    code_num = 0
    for j in range(m):
        code_num += b[j] * a[i][j]
    code_num += c
    if code_num > 0:
        ans += 1
print(ans)


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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong a, b, k;
    cin >> a >> b >> k;

    cout << max((llong)0, a-k) << " " << max(b - max((llong)0, k - a), (llong)0) << endl;
    
    return 0;
}


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

public class Main {
  Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    new Main().run();
  }

  void run() {
    String str = sc.nextLine();
    String ans = "CODEFESTIVAL2016";
    int cnt = 0;
    for (int i = 0; i < str.length(); ++i) {
      if (str.charAt(i) != ans.charAt(i)) {
        ++cnt;
      }
    }
    System.out.println(cnt);
  }

  int ni() {
    return Integer.parseInt(sc.next());
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 10188
#include <cstdio>
#include <algorithm>
using namespace std;

#define ll long long
#define mul(a, b) (((ll)(a) * (ll)(b)) % MOD)

int N, K, MOD;

int f1[155][155];
int f[155][80][80][80];

int work_easy(int siz, int consec)
{
    for (int i = 0; i < 155; i++) {
        for (int j = 0; j < 155; j++) {
            f1[i][j] = 0;
        }
    }
    f1[0][0] = 1;
    for (int i = 0; i < siz; i++) {
        for (int j = 0; j <= consec; j++) {
            f1[i+1][j+1] += f1[i][j];
            if (f1[i+1][j+1] >= MOD) f1[i+1][j+1] -= MOD;
            f1[i+1][0] += f1[i][j];
            if (f1[i+1][0] >= MOD) f1[i+1][0] -= MOD;
        }
    }
    int ans = 0;
    for (int i = 0; i <= consec; i++) {
        ans += f1[siz][i];
        if (ans >= MOD) ans -= MOD;
    }
    return ans;
}

int main()
{
    scanf("%d%d%d", &N, &K, &MOD);
    if (K % 2 == 0) {
        printf("%d", (int)mul(work_easy(N / 2, K / 2),
            work_easy(N / 2 + (N % 2), K / 2)));
        return 0;
    }
    f[0][0][0][N / 2 + 2] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= N / 2 + 1; j++) {
            for (int k = 0; k <= N / 2 + 1; k++) {
                for (int l = max(j, k) + 1; l <= N / 2 + 2; l++) {
                    int& add0 = f[i+1][0][j][j <= k ? N / 2 + 2 : l];
                    int& add1 = f[i+1][k+1][j][
                        (k+1 <= j || j == 0 || 2 * k < K + 1) ? l
                        : min(max(k + 1 + (K + 1 - 2 * j) / 2, 0), l)];
                    add0 += f[i][j][k][l];
                    if (add0 >= MOD) add0 -= MOD;
                    add1 += f[i][j][k][l];
                    if (add1 >= MOD) add1 -= MOD;
                }
            }
        }
    }
    int ans = 0;
    for (int j = 0; j <= N / 2 + 1; j++) {
        for (int k = 0; k <= N / 2 + 1; k++) {
            for (int l = max(j, k) + 1; l <= N / 2 + 2; l++) {
                ans += f[N][j][k][l];
                if (ans >= MOD) ans -= MOD;
            }
        }
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 295992
use std::io::BufRead;
fn main() {
    let stdin = std::io::stdin();
    let mut lines: Vec<Vec<i64>> = stdin
        .lock()
        .lines()
        .map(|l| {
            l.unwrap()
                .split_whitespace()
                .map(|w| w.parse().unwrap())
                .collect()
        })
        .collect();
    let (n, k, mut al, mut fl) = (lines[0][0], lines[0][1], lines.remove(1), lines.remove(1));
    if al.iter().sum::<i64>() <= k {
        println!("0");
        return;
    } else {
        al.sort();
        al.reverse();
        fl.sort();
        let mut list: Vec<_> = al.iter().zip(fl.iter()).collect();
        list.sort();
        list.reverse();
        let mut lp:i64 = 1;
        let mut rp:i64;
        match list[0] {
            (a, f) => rp = a * f,
        }
        let mut mp:i64 = 1 << 60;//(lp + rp) / 2;
        while (lp!=mp)||(mp!=rp) {
            let cnt: i64 = list
                .iter()
                .filter(|&&(a, f)| (a * f) > mp)
                .map(|&(a, f)| a - (mp / f))
                .sum();
            // let mut cnt =0;
            // for &(a, f) in &list {
            //     if (a * f) > mp {
            //         cnt += a - (mp / f);
            //     } else {
            //         break;
            //     }
            // }
            if k < cnt {
                lp = mp + 1;
            } else {
                rp = mp;
            }
            mp = (lp + rp) / 2;
        }
        println!("{}", mp);
    }
}


Measured memory_bytes: 15068
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N;
  cin >> N;

  if (N % 2 != 0)
    cout << 0 << endl;
  else
  {
    ll x = N / 2;

    ll ans = 0;
    for (ll y = 5; y <= x; y *= 5)
    {
      ans += x / y;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256