akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <map>
#include <unordered_set>
#include <tuple>
#include <queue>
#include <set>
#include <cstring>
#include <functional>
#include <random>
#include <chrono>

#define ar array
#define all(arr) (arr).begin(), (arr).end()
#define range(i, n) for (int i=0; i < n; ++i)
#define rall(arr) (arr).rbegin(), (arr).rend()

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

const ll INF = 1e18;
const int INFi = 2e9;
const int maxN = 1e6 + 5;
const int md = 998244353;
const int md2 = 1e9 + 7;

double getTime() { return clock() / (double) CLOCKS_PER_SEC; };

pair<ll, pair<ll, ll>> gcd(ll a, ll b) {
    if (b == 0) {
        return {a, {1, 0}};
    }
    auto p = gcd(b, a % b);
    // a % b = a - (a / b) * b
    // b * k1 + (a - (a / b) * b) * l1 = g
    // b * k1 + a * l1 - (a/b) * b * l1 = g
    // b * (k1 - (a/b) * l1) + a * l1 = g
    return {p.first, {p.second.second, p.second.first - (a/b) * p.second.second}};
}

pair<ll, ll> solve_diof(ll a, ll b, ll c) {
    auto p = gcd(abs(a), abs(b));
    if (a < 0) p.second.first *= -1;
    if (b < 0) p.second.second *= -1;
    if (c % p.first != 0) return {INF, INF};
    p.second.first *= c / p.first;
    p.second.second *= c / p.first;
    ll b1 = b / p.first, a1 = a / p.first;
    if (p.second.first < 0) {
        ll k = (-p.second.first) / b1 + 1;
        p.second.first += b1 * k;
        p.second.second -= a1 * k;
    }
    ll k = p.second.first / b1;
    p.second.first -= b1 * k;
    p.second.second += a1 * k;
    return p.second;
}

void solve() {
    ll n;
    cin >> n;
    ll wewe = n;
    if (n == 1) {
        cout << "1\n";
        return;
    }
    n *= 2;
    ll answer = INF;
    vector<ll> pk, ph;
    for (ll i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            pk.emplace_back(1);
            while (n % i == 0) {
                pk.back() *= i;
                n /= i;
            }
            ph.emplace_back(pk.back() - pk.back() / i);
        }
    }
    if (n != 1) {
        pk.emplace_back(n);
        ph.emplace_back(n - 1);
    }
    int s = pk.size();
    if (s == 1) {
        cout << pk.back() - 1 << "\n";
        return;
    }
    range(mask, 1 << s) {
        vector<ll> a(s);
        ll x1 = 1, x2 = 1;
        range(i, s) if ((1 << i) & mask) {
            x1 *= pk[i];
        } else {
            x2 *= pk[i];
        }
        // - x1 * e + x2 * f = 1
        ll cur = solve_diof(-x1, x2, 1).first * x1;
        if (cur == 1 || cur == 0) {
            continue;
        }
        answer = min(answer, cur);
    }
    cout << answer << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //cout << setprecision(15) << fixed;
    int tests = 1;
    //cin >> tests;
    range(_, tests) {
        solve();
    }
    return 0;
}

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

int n;
int c[200010];
int ne[200010];

#define MOD 1000000007

long long memo[200010];

long long dp(int i){
    if(i == n) return 1;
    if(memo[i] != -1) return memo[i];

    if(ne[i] == -1 || ne[i] == i+1){
        return memo[i] = dp(i+1);
    }else{
        return memo[i] = (dp(i+1) + dp(ne[i])) % MOD;
    }
}

int main(){
    cin >> n;

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

    int tmp[200010] = {};
    memset(tmp, -1, sizeof(tmp));

    for(int i = n-1;i >= 0;i--){
        if(tmp[c[i]] == -1){
            ne[i] = -1;
        }else{
            ne[i] = tmp[c[i]];
        }
        tmp[c[i]] = i;
    }

    memset(memo, -1, sizeof(memo));

    cout << dp(0) << endl;

    return 0;
}






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

void solve(long long N, long long K) {
    if (N % K == 0) {
        cout << 0 << endl;
    } else {
        cout << 1 << endl;
    }
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 3632
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

#N = int(input())
X, Y = map(int, input().split())

a, b = 4 * X - Y, Y - 2 * X

if a >= 0 and b >= 0 and a % 2 == 0 and b % 2 == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 65344
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

int main() {
	lnt n,d;
	std::cin >> n >> d;
	lnt count=0;
	rep(i,n) {
		lnt x,y;
		std::cin >> x >> y;
		if(x*x+y*y<=d*d) count++;
	}
	print(count);
}


Measured memory_bytes: 3636
#include<stdio.h>
#define N 1020000

void merge(int*,int,int,int);
void mergeSort(int*, int, int);

int cnt=0;

     

int main(){

  int num,i,B[N];

  scanf("%d",&num);

  for(i=0;i<num;i++){
    scanf("%d",&B[i]);
  }




 
  mergeSort(B,0,num);

  for(i=0;i<num-1;i++){
    printf("%d ",B[i]);
  }
  printf("%d\n",B[i]);

  printf("%d\n",cnt);
  return 0;
}


void merge(int *A,int left ,int mid, int right){

  int n1,n2,i,j,k;


  n1 = mid - left;
  n2 = right - mid;
  int L[n1+1],R[n2+1];

 

  for( i = 0 ; i <= n1-1 ;i++){

    L[i] = A[left + i];
  }



  for (i = 0;i <= n2-1; i++){
    R[i] = A[mid +i];
    
  }

  L[n1] = 1000000100;
  R[n2] = 1000000100;

  i = 0;
  j = 0;

  
  for (k = left; k <= right-1;k++){
    cnt++;
    if (L[i] <= R[j]){
      A[k] = L[i];


      i = i + 1;
    }

    else {
      A[k] = R[j];
  
    j = j + 1;
    }
  }
}

void mergeSort(int *A,int left,int right){

  int mid;

  if( left+1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
      
  }
}
 

Measured memory_bytes: 4948
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
const ll MOD = 1e9 + 7;
const ll INF = (ll)1e18;

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}

int main() {
#ifdef HIRO
  string quiz(QUIZ);
  ifstream cin("input/" + quiz + ".txt");
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  ll n, m, k;
  cin >> n >> m >> k;
  if((n==m&&m!=k) || (n==k&&n!=m) || (m==k&&m!=n))
    cout << "Yes";
  else
    cout << "No";
  
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
// 2016-11-25
#include <iostream>
#include <string>

char c[10][5] = {
	{' ', ' ', ' ', ' ', ' '},
	{'.', ',', '!', '?', ' '},
	{'a', 'b', 'c', ' ', ' '},
	{'d', 'e', 'f', ' ', ' '},
	{'g', 'h', 'i', ' ', ' '},
	{'j', 'k', 'l', ' ', ' '},
	{'m', 'n', 'o', ' ', ' '},
	{'p', 'q', 'r', 's', ' '},
	{'t', 'u', 'v', ' ', ' '},
	{'w', 'x', 'y', 'z', ' '},
};
int l[10] = {0, 5, 3, 3, 3, 3, 3, 4, 3, 4};

int main() {
	int n;
	std::string s;
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> s;
		int m = s.length();
		int x = 0;
		int y = 0;
		for (int j = 0; j < m; j++) {
			int a = int(s[j] - '0');
			if (a == 0) {
				if (x != 0) {
					std::cout << c[x][y];
					x = 0;
				}
			} else {
				if (a == x) {
					y = (y + 1) % l[x];
				} else {
					x = a;
					y = 0;
				}
			}
		}
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3164
#include<iostream>
#include<string>
#include<map>
using namespace std;

int main() {
	int n, o;
	while (cin >> n, n) {
		map<char, char>m;

		for (int i = 0;i < n;i++) {
			char a, b;
			cin >> a >> b;
			m[a]=b;
		}

		cin >> o;
		string sa;

		for (int i = 0;i < o;i++) {
			char a;
			cin >> a;
			auto itr = m.find(a);
			if (itr != m.end()) {
				sa += itr->second;
			}
			else {
				sa += a;
			}
		}

		cout << sa << endl;

	}
	return 0;
}

Measured memory_bytes: 3260
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

struct UnionFind {
	vector<int> par; // 親を指すvector,-par[親]は木のサイズ
	UnionFind(int n):par(n, -1) {} // uniteで親を埋め込んでいく必要あり
	int root(int x) { // 親をたどる&データの整理
		if(par[x] < 0) return x;
		return par[x] = root(par[x]);
	}
	bool unite(int x, int y) { // データの結合
		x = root(x);
		y = root(y);
		if(x == y) return false;
		if(par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}
	bool same(int x, int y) {return root(x) == root(y);} // 所属判定
	int size(int x) {return -par[root(x)];} // 木のサイズ
};

#define N 200100

//head

int n;
pair<P, int> xy[N];
UnionFind uft(N);
stack<P> st;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	rep(i, n) {
		int x, y;
		cin >> x >> y;
		xy[i] = {P(x, y), i};
	}
	sort(xy, xy+n);
	rep(i, n) {
		if(!i) {
			st.emplace(xy[i].first.second, xy[i].second);
			continue;
		}
		P z = st.top();
		if(z.first > xy[i].first.second) {
			st.emplace(xy[i].first.second, xy[i].second);
		}
		else {
			while(!st.empty() and st.top().first < xy[i].first.second) {
				uft.unite(st.top().second, xy[i].second);
				st.pop();
			}
			st.emplace(z);
		}
	}
	rep(i, n) cout << uft.size(i) << endl;
}

Measured memory_bytes: 6572
#ifndef LOCAL
#pragma GCC optimize("O2")
#endif
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;

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

   int score = 0;
   for(int i=0; i<N; i++){
       for(int j=i+1; j<N; j++){
           score += d[i] * d[j];
       }
   } 

    cout << score << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC80(void);
void ABC81(void);
void ABC82(void);
void ABC83(void);
void ABC84(void);
void ABC85(void);
void ABC86(void);
void ABC87(void);
void ABC88(void);
void ABC89(void);

int main(void){
    ABC83();
}

void ABC83(){
    int n,a,c,b,ans=0,i,j,d=1;
    cin>>n>>c>>b;
    for(i=0;i<=n;i++){
        a=0;
        for(j=0;j<=4;j++){
            a+=(i/d)%10;
            d*=10;
        }
        if(a>=c&&a<=b)ans+=i;
        d=1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long
 
int
main(void){
	ll n, m, k; cin >> n >> m >> k;
	vector<ll> a(n), b(m);
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int j = 0; j < m; j++) cin >> b[j];
	for(int i = 1; i < n; i++) a[i] += a[i - 1];
	for(int j = 1; j < m; j++) b[j] += b[j - 1];
	
	ll beg = 1, end = n + m;
	ll ans = 0;
	while(beg <= end){
		ll mid = (beg + end)/2;
		ll temp = mid;
		bool correct = false;
		ll it1 = min(n, (ll)temp);
		temp -= it1;
		ll it2 = temp;
		it1--; it2--;
		//cout << mid << " " << beg << " " << end << endl;
		if(it2 < 0){
			if(a[it1] <= k) correct = true;
			it2++;
			it1--;
			//cout << it1 << "....\n";
		}
		for(int i = it1; i >= 0; i--){
			ll val = a[i] + b[it2];
			if(val <= k){
				correct = true;
				break;
			}
			it1--;
			it2++;
			if(it2 >= m) break;
		}
		if(it2 < m && it1 < 0){
			if(b[it2] <= k) correct = true;
		}
		if(correct){
			beg = mid + 1; 
			ans = max(ans, mid);
		}
		else{
			end = mid - 1;
		}
	}
	cout << ans;
}

Measured memory_bytes: 6432
n = int(input())
print(0)
sl = input()
if sl == 'Vacant':
    exit()
l, r = 0, n - 1
pm = -1
while True:
    # print(l, r)
    m = (l + r) // 2
    if pm == m:
        m += 1
    print(m)
    sm = input()
    if sm == 'Vacant':
        break
    if sl == sm:
        if (m - l) & 1:
            r = m
        else:
            l = m
            sl = sm
    else:
        if (m - l) & 1:
            l = m
            sl = sm
        else:
            r = m
    pm = m


Measured memory_bytes: 3660
#include<stdio.h>
#include<stdlib.h>
#define MAX 100

int main()
{
  int c,i;
  char number[100];

  i = 0;
  while((c = getchar()) != EOF) {
    number[i] = (char)c;
    i++;
  }
  c = atoi(number);
  printf("%d\n", c * c * c);

  return 0;
}

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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mp(v1, v2)       make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  arr(a,n);

  vec head;
  vec tail;
  rep(i,n){
    if((i+1)%2) head.pb(a[i]);
    if(i%2) tail.pb(a[i]);
  }

  vec ans;
  if(n%2){
    reverse(all(head));
    rep(i,head.size()){
      ans.pb(head[i]);
    }
    rep(i,tail.size()){
      ans.pb(tail[i]);
    }
  } else {
    {
      reverse(all(tail));
      rep(i,tail.size()){
        ans.pb(tail[i]);
      }
      rep(i,head.size()){
        ans.pb(head[i]);
      }
    }
  }

  prtall(ans);
}


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

int main()
{
    long long n, n_cop, sum = 0;
    cin >> n;
    n_cop = n;

    while (n > 0)
    {
        sum += n % 10;
        n /= 10;
    }

    if (n_cop % sum == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

using namespace std;

int main(){
    long long  N;
    cin >> N;
    string alpha[26] = {"z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y"};

    string ans = "";
    while (N > 0)
    {

            ans = ans + alpha[(N % 26)];
            if(N%26!=0){
            N /= 26;
            }else{
                N /= 26;
                N -= 1;
            }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << "\n";
}


Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

void solve()
{
	int r, g, b;
	cin >> r >> g >> b;
	int num = r * 100 + g * 10 + b;
	if (num % 4 == 0)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
int main(){
	string A, B;
	cin>>A>>B;
	A += B;
	int c = toInt(A);
	for(int i = 1; i <= 1000; ++i){
		if(i * i == c){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

int main() {
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	cout << s1[0] << s2[1] << s3[2] << endl;
}


Measured memory_bytes: 3616
a,b,c,x,y=map(int, input().split())
z = 0#xy
l= []
l.append(a * x+b * y)
while x > 0 or y > 0:
    x -= 1
    y -= 1
    z += 2
    x1 = x
    if x1 < 0: x1 = 0
    y1 = y
    if y1 < 0: y1 = 0
    l.append(a * x1 + y1 * b + z * c)
print(min(l))

Measured memory_bytes: 7064
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().unwrap_or_else(|_| panic!("Faild to parse {}", s))
}

fn main(){
    let n: usize = read();
    let m: usize = read();
    let mut from1 = vec![false; n + 1];
    let mut fromn = vec![false; n + 1];
    for _ in 0..m {
        let a: usize = read();
        let b: usize = read();
        from1[b] |= a == 1;
        from1[a] |= b == 1;
        fromn[b] |= a == n;
        fromn[a] |= b == n;
    }
    let flg = from1.iter().zip(fromn.iter()).fold(false, |acc, (&a, &b)| acc || a && b);
    println!("{}", if flg { "POSSIBLE" } else { "IMPOSSIBLE" });
}


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

int main() {
  int n,k;
  cin >> n>> k;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin >>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  int ans =vec.at(k-1) - vec.at(0) ;
  for(int i=1;i+k-1<n;i++){
   if(ans > vec.at(i+k-1) - vec.at(i) ){
     ans =vec.at(i+k-1) - vec.at(i);
   }
  }
  cout << ans ;
    
}


Measured memory_bytes: 768
#include<stdio.h>
#include<iostream>
#include<vector>

int main(){

  int n, k;
  
  int ans=0;
  
  std::cin>>n>>k;
  
  std::vector<int> okashi(n, 1);
  
  //std::cout<<n<<k<<std::endl;
  
  for(int i=0; i<k; i++){
  	
  	int d1;
    std::cin>>d1;
    
    
    for(int i0=0; i0<d1; i0++){
    	int j1;
      	std::cin>>j1;
      
      	okashi[j1-1]=0;
    }
  
  }
  
  for(int i=0; i<n; i++){
    
    if(okashi[i]==1){
    	ans = ans + 1;
    }
    
  }
  
  std::cout<<ans;
  
  
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;

int main()
{
    vector<int> a(3);
    for (int i = 0; i < 3; i++) {
        cin >> a[i];
    }
    auto f = [](const int i, const int j) {
        if (j <= i) { return i - j; }
        return (j - i + 1) / 2 + (j % 2 == i % 2 ? 0 : 1);
    };
    int ans = INF<int>;
    for (int i = -100; i < 100; i++) {
        int sum = 0;
        for (int j = 0; j < 3; j++) {
            sum += f(a[j], i);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
solve :: [Int] -> Int
solve [] = 0
solve as | length as < 3 = 0
         | (x > y && y > z) = 1 + (solve (tail as))
         | (x < y && y < z) = 1 + (solve (tail as))
         | otherwise = solve (tail as)
            where
                x = as!!0
                y = as!!1
                z = as!!2

main = do
    n <- readLn :: IO Int
    pn <- map read . words <$> getLine :: IO [Int]
    print $ solve pn


Measured memory_bytes: 3992
n,m = map(int,input().split())
line = sorted(list(map(int,input().split())),reverse = True)
sums = sum(line)
if sums % (4*m) != 0:
  least = sums//(4*m) + 1
else:
  least = sums//(4*m)
box = []
for i in line:
  if i >= least:
    box.append(i)
if len(box) >= m:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = ;
const long long INF_LL = 1e18+3; const int INF_int = 1e9+3;
#define ll long long
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto itr = a.begin();itr!=a.end();itr++) cout << *itr << " ";cout << endl;
int main(){
    int arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    //assert(arr.size()==32)
    cout << arr[k-1] << endl;
}


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

int main(){
  ll n;
  cin>>n;
  ll ans=0;
  rep(i,n){
    ans+=i;
  }
  cout<<ans;
}


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

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

    int i;

    i = A+B;

    if(i < 10){
        cout << i << endl;
    }
    else{
        cout << "error" << endl;
    }

    return 0;
}

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

int main() {

    int n,k,x,y;

    cin >> n >> k >> x >> y;

    int ans = 0;

    for(int i=1; i<=min(k,n); i++){
        ans += x;
    }

    for(int i=k+1; i<=n; i++){
        ans += y;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
H,W,K = map(int,input().split())
MOD = 10**9+7

dp = [[0]*W for _ in range(H+1)]
dp[0][0] = 1
for i in range(H):
    for b in range(1<<(W-1)):
        if '11' in bin(b): continue
        for k in range(W):
            if k and b&(1<<(k-1)):
                dp[i+1][k-1] += dp[i][k]
            elif b&(1<<k):
                dp[i+1][k+1] += dp[i][k]
            else:
                dp[i+1][k] += dp[i][k]

print(dp[-1][K-1] % MOD)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

class Dice{
public:
     //  コンストラクタ
     Dice();
     //  デストラクタ
     ~Dice();
     //  メソッド
     int east();
     int west();
     int south();
     int north();
     int side();
     void set(int sai[6]);
     int look(int men);
private:
     int me[7];
};

//  コンストラクタ
Dice::Dice()
{
}
//  デストラクタ
Dice::~Dice()
{
}
void Dice::set(int sai[6])
{
    int i;
    for(i = 0;i<6; i++) {
//        cout << sai[i] << endl;
        me[i+1] = sai[i];
    }
}
int Dice::east()
{
    int tmp = me[4];
    me[4] = me[6];
    me[6] = me[3];
    me[3] = me[1];
    me[1] = tmp;
    return(tmp);
}
int Dice::west()
{
    int tmp = me[3];
    me[3] = me[6];
    me[6] = me[4];
    me[4] = me[1];
    me[1] = tmp;
    return(tmp);
}
int Dice::south()
{
    int tmp     = me[5];
    me[5] = me[6];
    me[6] = me[2];
    me[2] = me[1];
    me[1] = tmp;
    return(tmp);
}
int Dice::north()
{
    int tmp     = me[2];
    me[2] = me[6];
    me[6] = me[5];
    me[5] = me[1];
    me[1] = tmp;
    return(tmp);
}
int Dice::side()
{
    int tmp     = me[3];
    me[3] = me[5];
    me[5] = me[4];
    me[4] = me[2];
    me[2] = tmp;
    return(tmp);
}
int Dice::look(int men)
{
    return(me[men]);
}
int main() {
    int sai[6];
    int i, l, n, t, f, flg=1;
    char c;
    for(i =0; i < 6; i++){
        cin >> l;
        sai[i] = l;
    }
    Dice d;
    d.set(sai);
    for(i =0; i < 6; i++){
        cin >> l;
        sai[i] = l;
    }
    Dice e;
    e.set(sai);
    t = e.look(1);
    for (l = 0; l < 3; l++) {
        if (t == d.east())  break;
        if (t == d.north()) break;
    }
    f = e.look(2);
    l = d.look(2);
    i = 4;
    while (l != f) {
        l = d.side();
        if(i-- < 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    for (l = 0; l < 3; l++) {
        if (e.east() != d.east())  break;
        if (e.north() != d.north()) break;
    }
    if (l < 3) {
        cout << "No" << endl;
    } else { 
        cout << "Yes" << endl;
    }
    return 0;
}



Measured memory_bytes: 3084
#include<iostream>
using namespace std;
bool    isprime(int num){
    if(num == 1)  return  false;
    for(int i = 2; i * i <= num; ++i)
        if(num % i == 0)    return  false;
    return  true;
}
int main(){
    int num, N;     cin >> N;
    int ans = 0;
    while(N--){
        cin >> num;
        if(isprime(num))    ans++;
    }
    cout << ans << endl;
    return  0;
}


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

int main() {
    int X, Y; cin >> X >> Y;
    if (Y % 2 == 0) {
        int A = Y / 2 - X;
        int B = 2 * X - Y / 2;
        if (A >= 0 && B >= 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else cout << "No" << endl;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(b,a%b);
}
void solve(){
	ll a,b,tmp;
	int ans=0;
	scanf("%lld %lld",&a,&b);
	tmp=gcd(a,b);
	for(ll i=2;i*i<=tmp;i++){
		if(tmp%i==0){
			ans++;
			while(tmp%i==0)tmp/=i;
		}
	}
	if(tmp>1)ans++;
	printf("%d",ans+1);
}
signed main(){
    int t=1;
    //scanf("%d",&t);
    for(int i=1;i<=t;i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3836
#include <cstdio>
#include <cmath>

int main(){
	double a, b, C;
	scanf("%lf %lf %lf", &a, &b, &C);
	double ra = C * M_PI / 180;
	double h = sin(ra) * b;
	double S = h * a / 2;
	double L1 = a*a + b*b -2*a*b*cos(ra);
	double L = a + b + sqrt(L1);
	printf("%f\n%f\n%f\n", S, L, h);
	return 0;
}

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class E
{
	public static void Main()
	{
		int N = GetInt();
		int K = GetInt();
		int[] A = Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();

		int sum = A.Sum();
		var divisors = new List<int>();
		for(int i = 1; i * i <= sum; i++)
		{
			if(sum % i == 0)
			{
				if(i * i == sum)
					divisors.Add(i);
				else
				{
					divisors.Add(i);
					divisors.Add(sum / i);
				}
			}
		}

		int ans = 1;
		foreach(int divisor in divisors)
		{
			if(sum % divisor != 0)
				continue;

			int[] r = A.Select(x => x % divisor).Where(x => x > 0).ToArray();
			Array.Sort(r);

			int len = r.Length;
			int[] minus = new int[len + 1];
			int[] plus = new int[len + 1];
			for(int i = 0; i < len; i++)
			{
				minus[i + 1] = minus[i] + r[i];
				plus[i + 1] = plus[i] + (divisor - r[i]);
			}

			int numOp = int.MaxValue;
			for(int i = 0; i <= len; i++)
			{
				int tmpMinus = minus[i];
				int tmpPlus = plus[len] - plus[i];
				if(tmpMinus == tmpPlus)
					numOp = Math.Min(numOp, tmpMinus);				
			}

			if(numOp <= K)
				ans = Math.Max(ans, divisor);
		}

		Console.WriteLine(ans);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 15540
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
   for (int i = 0; i < N; i++) {
     cin >> vec.at(i);
   }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int x = 0;
   for (int i = 0; i < N; i++) {
     if (i % 2 == 0)
       x += vec.at(i);
     else
       x -= vec.at(i);
   }
  cout << x << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int INF = 1e9;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int H,W;
char maze[30][30];
int d[30][30];
int dy[4] = {1,0,-1,0};
int dx[4] = {0,1,0,-1};

void dfs(int a,int b) {
    queue<P> que;
    for(int i = 0;i < H;i++) {
        for(int j = 0;j < W;j++) {
            d[i][j] = INF;
        }
    }
    que.push(P(a,b));
    d[a][b] = 0;
    while(!que.empty()) {
        P p = que.front();
        que.pop();
        for(int i = 0;i < 4;i++) {
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if(0 <= ny && ny < H && 0 <= nx && nx < W && maze[ny][nx] != '#' && d[ny][nx] == INF) {
                que.push(P(ny,nx));
                d[ny][nx] = d[p.first][p.second] + 1;
            }
        }
    }
    return;
}

int main() {
    cin >> H >> W;
    for(int i = 0;i < H;i++) {
        for(int j = 0;j < W;j++) {
            cin >> maze[i][j];
        }
    }
    int ret = 0;
    for(int i = 0;i < H;i++) {
        for(int j = 0;j < W;j++) {
            if(maze[i][j] != '#') {
                dfs(i,j);
                for(int k = 0;k < H;k++) {
                    for(int l = 0;l < W;l++) {
                        if(d[k][l] != INF) {
                            ret = max(ret,d[k][l]);
                        }
                    }
                }
            }
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
N, M, X = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
ans = float('inf')

for i in range(2**N):
    cnt = [0] * M
    c = 0
    idx = 0
    while i:
        if i % 2:
            c += A[idx][0]
            for j in range(1, M+1):
                cnt[j-1] += A[idx][j]
        idx += 1
        i //= 2
        
    for j in cnt:
        if j < X: break
    else: ans = min(ans, c)
    
if ans == float('inf'): ans = -1
print(ans)

Measured memory_bytes: 9236
using System;
using System.Collections.Generic;
public class Hello{
    public static void Main(){
     　float n,m;
            // = int.Parse(Console.ReadLine()); //標準入力
            string[] str = Console.ReadLine().Split(' ');
            n=float.Parse(str[0]);
         
           
           Console.WriteLine((int)(n/2+0.5));//改行付き出力
    }
}


Measured memory_bytes: 11220
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#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

using namespace std;
 
int main(){
    int A,B;
    cin >> A >> B;
    if((A*B) %2 > 0){
        cout << "Odd" << endl;
    }
    else cout << "Even" << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cmath>

using namespace std;

int main(){
	int n, ans = 0;
	cin >> n;
    ans = pow(3, n);
    int t = 1;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        if(x % 2 == 0){
            t *= 2;
        }
    }
    ans -= t;
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int i,j,a,b,c;
    cin>>a>>b>>c;
    j=0;
    i=min(a,b);
    while(true) {
      if(a%i==0 && b%i==0)
        j++;
      if(j==c)
        break;
      i--;
    }
    cout<<i<<endl;
    return 0;
}


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

ll = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: -x[1])

mm=sorted([list(map(int,input().split())) for _ in range(n)])
count_num=0
for i,j in mm:
  for k,h in ll:
    if k<=i and h<=j:
      count_num+=1
      ll.remove([k,h])
      break
print(count_num)


Measured memory_bytes: 3060
use std::error::Error;
use std::io;

fn main() {
    if let Err(e) = run() {
        println!("{}", e);
    }
}

fn run() -> Result<(), Box<Error>> {
    io::stdin().read_line(&mut String::new())?;
    let mut s = String::new();
    io::stdin().read_line(&mut s)?;
    let mut a: Vec<u64> = s.trim().split(" ").map(|x| x.parse().expect("")).collect();
    a.sort();
    a.reverse();
    let mut n = 0;
    let mut pre = 0;
    let mut ans = 0;
    for x in a {
        if pre == x {
            n += 1;
            if n == 2 {
                if ans == 0 {
                    ans = x;
                } else {
                    println!("{}", ans * x);
                    return Ok(());
                }
                n = 0;
            }
            continue;
        }
        pre = x;
        n = 1;
    }
    if n == 2 && ans != 0 {
        println!("{}", ans * pre);
        return Ok(());
    }
    println!("0");
    Ok(())
}


Measured memory_bytes: 6396
import sys
from collections import deque
N,M=map(int,input().split())
L=[0]*N
table=[[] for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    table[a].append(b)
    table[b].append(a)
    L[a]+=1
    L[b]+=1
for i in range(N):
    if L[i]%2==1:
        print('No')
        sys.exit()
H=[]
for i in range(N):
    if L[i]>=6:
        print('Yes')
        sys.exit()
    if L[i]==4:
        H.append(i)
if len(H)<2:
    print('No')
    sys.exit()
if len(H)>2:
    print('Yes')
    sys.exit()
s=H[0]
t=H[1]
#print(L,table)
def f(x):
    visit=[0]*N
    S=deque()
    S.append(x)
    visit[s]=1
    visit[x]=1
    while S:
        y=S.popleft()
        if y==s:
            return True
        if y==t:
            return False
        for i in table[y]:
            if visit[i]==0:
                S.append(i)
                visit[i]=1
    return True
for x in table[s]:
    #print(f(x),x)
    if f(x):
        print('Yes')
        sys.exit()
print('No')



Measured memory_bytes: 63136
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }
 
int main(){
    ll n, m;
    cin >> n;
    map<int, int> num;
    for (ll i = 0; i < n; i++){
        ll x;
        cin >> x;
        num[x]++;
    }
    cin >> m;
    for (ll i = 0; i < m; i++){
        ll x;
        cin >> x;
        num[x]--;
        if(num[x] < 0){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 9600
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+7;

int main()
{
    ll n;
    cin >> n;
    ll digit1=n/100;
    if(n<=digit1*111){
        cout << digit1*111 << endl;
    }
    else{
        cout << (digit1+1)*111 << endl;
    }
    return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2501,M=5001;
int a[M],b[M],c[M],used[N];
vector<int>v[N];
long long dis[N];
int n;
bool pos[N];
void dfspos(int x)
{
	pos[x]=1;
	for(int y:v[x])
		if(!pos[y])dfspos(y);
}
bool dfs(int x)
{
	if(x==n)return 1;
	bool ans=0;
	used[x]=1;
	for(int y:v[x])
		if(!used[y])ans|=dfs(y);
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int m,i,j,t;
	cin>>n>>m>>t;
	for(i=0;i<m;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
		v[a[i]].push_back(b[i]);
	}
	dfspos(1);
	dis[1]=0;
	for(i=2;i<=n;i++)
		dis[i]=int(1e5)*(-M);
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
		{
			if(dis[a[j]]+c[j]-t>dis[b[j]])
				dis[b[j]]=dis[a[j]]+c[j]-t;
		}
	for(i=0;i<m;i++)
		if(dis[a[i]]+c[i]-t>dis[b[i]])
		{
			if(pos[b[i]] && dfs(b[i]))
			{
				cout<<"-1\n";
				return 0;
			}
		}
	cout<<max(dis[n],0ll)<<'\n';
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  int max = 0;
  int koho = 999999;
  for (int i = b; i < a+b; i++) {
    max += i;
    if (abs(koho) > abs(i)) {
      koho = i;
    }
  }
  cout << max - koho << endl;
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";
*/


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

using namespace std;

using ll = long long;
using ld = long double;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    // cout << setprecision(8) << setiosflags(ios::fixed);

    int h, w;
    cin >> h >> w;

    vector<string> s(h);
    for (auto &s_i : s) cin >> s_i;

    vector<vector<int>> up(h, vector<int>(w)), down(h, vector<int>(w));
    vector<vector<int>> left(h, vector<int>(w)), right(h, vector<int>(w));

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == '#') continue;

            ++up[i][j];
            ++left[i][j];
            if (i != 0) up[i][j] += up[i - 1][j];
            if (j != 0) left[i][j] += left[i][j - 1];
        }
    }

    for (int i = h - 1; 0 <= i; --i) {
        for (int j = w - 1; 0 <= j; --j) {
            if (s[i][j] == '#') continue;

            ++down[i][j];
            ++right[i][j];
            if (i != h - 1) down[i][j] += down[i + 1][j];
            if (j != w - 1) right[i][j] += right[i][j + 1];
        }
    }

    int max_spot = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == '#') continue;
            int sum = up[i][j] + down[i][j] + left[i][j] + right[i][j];
            max_spot = max(max_spot, sum - 3);
        }
    }

    cout << max_spot << endl;

    return 0;
}


Measured memory_bytes: 67328
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

bool isShiritori(string a, string b){
	int asize = a.size();
	return a[asize - 1] == b[0];
}

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

	string a, b, c;
	cin >> a >> b >> c;

	if(isShiritori(a, b) && isShiritori(b, c)){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

signed main(){
	ll n,x,pos = 0,cnt = 1;
	cin >> n >> x;
	ll l[n] = {};
	
	rep(i,0,n){
		cin >> l[i];
		
		if((pos +=  l[i]) > x) break;
		
		cnt++;
		
	}
	
	cout << cnt << endl;
	
	
    return 0;
}

Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())
v = [tx - sx, ty - sy]
ans = []
ans.append(("").join(["R"] * v[0]))
ans.append(("").join(["U"] * v[1]))
ans.append(("").join(["L"] * v[0]))
ans.append(("").join(["D"] * (v[1] + 1)))
ans.append(("").join(["R"] * (v[0] + 1)))
ans.append(("").join(["U"] * (v[1] + 1)))
ans.append("LU")
ans.append(("").join(["L"] * (v[0] + 1)))
ans.append(("").join(["D"] * (v[1] + 1)))
ans.append("R")
print(("").join(ans))


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

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define endl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using lli = long long int ;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

lli fact[100005];

void init(int n)
  {
    fact[0] = 1;
    for (int i = 1 ; i <= n ; i++)
      fact[i] = fact[i - 1] * i % mod;
  }

lli Pow(lli b, lli e)
  {
    if(e==0) return 1;
    lli ret=Pow(b, e/2);
    ret=ret*ret%mod;
    if(e&1) ret=ret*b%mod;
    return ret;
  }


lli getInverse(lli n)
  {
    return Pow(n, mod-2);
  }

lli divide(lli a, lli b)
  {
    return a*getInverse(b)%mod;
  }

lli nCr(lli n , lli r)
  {
    if(r>n) return 0 ;
    return divide(divide(fact[n],fact[r]), fact[n - r])%mod ;
  }

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    lli n, x, d=-1 ;
    cin>> n ;
    vlli a(n+1) ;
    map<int, int> cnt ;
    init(n+1) ;
    for(int i=0 ; i<=n ; i++)
      {
        cin>> a[i] ;
        if(cnt[a[i]]) x=a[i] ;
        cnt[a[i]]++ ;
      }
    for(int i=0 ; i<=n ; i++)
      if(a[i]==x && d==-1) d=i ;
      else if(a[i]==x) d=i-d ;
    for(int i=1 ; i<=n+1 ; i++)
      cout<< (nCr(n+1, i)-nCr(n-d, i-1)+mod)%mod << endl ;
  }


Measured memory_bytes: 7424
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int count_substr(const string& word,const string& q) {
	int count = 0;
	for (string::size_type pos = 0; (pos = word.find(q, pos)) != string::npos; pos += q.size()) {
		++count;
	}
	return count;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	vector<int> A=vecin(N),B=vecin(N),C(N);
	iota(ALL(C),1);
	int num=0,numA=0,numB=0;
	do{
		bool sameA=true,sameB=true;
		REP(i,N){
			if(C[i]!=A[i]) sameA = false;
			if(C[i]!=B[i]) sameB = false;
		}
		if(sameA) numA = num;
		if(sameB) numB = num;
		num++;
	}while(next_permutation(ALL(C)));
	out(abs(numA-numB));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define U [1<<17]={}
typedef long long L;using namespace std;map<L,L> T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p,r;char s U;L D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}L G(L a){r=A[a]+A[P[a]]+C[a];return r%k?r:0;}L M(L i){return i?B[i]+M(i-(i&-i)):0;}L S(L x,L i){for(x=G(x)-M(i+1)+M(i++);i<1<<17;B[i]+=x,i+=i&-i);}L W(){for(c=0;p=X[a],n=X[b],p-n;a=P[p])E[p]<E[n]?swap(p,n),swap(a,b),0:0,c+=M(O[a])-M(O[p])+G(p);cout<<c+abs(M(O[a])-M(O[b]))<<endl;}main(){for(cin>>n>>k;++p<n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(c=p=0);p<n;p++)if(!p|H[P[p]]-p)for(a=p;!c|a;S(a=H[a],O[a]=c++))X[a]=p;for(cin>>a;cin>>s>>a>>b;*s&2?W():A[a]+=b,S(H[a],O[a]),a?S(a,O[a]-1):0);}

Measured memory_bytes: 33468
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
# define MOD 1000000000+7
# define INF 1000000000
typedef long long ll;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }


int main() {

	char c;
	cin >> c;

	if (c == 'A') { cout << 'T' << endl; }
	if (c == 'T') { cout << 'A' << endl; }
	if (c == 'C') { cout << 'G' << endl; }
	if (c == 'G') { cout << 'C' << endl; }

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define io_ ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

int main(){
    io_
    long long int n, m; cin >> n >> m;
    long long int sum=0;
    while(m--){
        long long int x; cin >> x; 
        sum+=x;
    }
    if(sum>n){
        cout << -1 << "\n";
    }else{
        cout << n-sum << "\n";
    }
    
}


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

string s,t,u;
int a,b;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin>>s>>t>>a>>b>>u;
    if(u==s)
    {
    	cout<<a-1<<" "<<b<<endl;
	}
	else 
	{
		cout<<a<<" "<<b-1<<endl;
	}
    
    
	return 0;
	
	
}

Measured memory_bytes: 256