akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string s;
    cin >> s;

    int K;
    cin >> K;

    priority_queue<string, vector<string>, less<>> pq;
    set<string> S;
    REP(i, s.size()) {
        string ss;
        FOR(j, i, s.size()) {
            ss += s[j];

            if (S.count(ss) > 0) continue;

            if (pq.size() < K) {
                pq.push(ss);
                S.insert(ss);
            } else {
                auto tp = pq.top();
                if (tp > ss) {
                    S.erase(tp);
                    pq.pop();
                    pq.push(ss);
                    S.insert(ss);
                } else {
                    break;
                }
            }
        }
    }

    print(pq.top());
    
}


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

//flagを用いたバブルソート
int bubbleSort(int A[], int N){
	int sw = 0;
	bool flag = 1;
	for( int i = 0; flag; i++){
		flag = 0;
		for(int j = N - 1; j >= i + 1; j --){
			if (A[j] < A[j - 1]){
				//隣接要素を交換する
				swap(A[j], A[j-1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main(){
	int A[100], N, sw;
	cin >> N;
	for( int i = 0; i < N; i++) cin >> A[i];

		sw = bubbleSort(A, N);

	for (int i  = 0; i < N; i++){
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;

	return 0;;
}


Measured memory_bytes: 3100
#include<stdio.h>

int main(){
	int n;
	scanf("%d", &n);
	long long sum = 0;

	for(int i=0; i<=n; i++){
		if(i%3==0 || i%5==0 || i%15==0){
			continue;
		}
		else{
			sum += i;
		}
	}
	printf("%lld", sum);
	
	return 0;
}

Measured memory_bytes: 1696
#include <algorithm>
#include <iostream>
#include <deque>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

    string s; cin >> s;
    deque<char> q;
    for (char c : s) q.push_back(c);

    bool flip = false;
    int n; cin >> n;

    REP(i, n) {
        int t; cin >> t;
        if (t == 1) flip = !flip;
        else {
            int f;
            char c;
            cin >> f >> c;
            if (flip) f = 3 - f;
            if (f == 1) q.push_front(c);
            else q.push_back(c);
        }
    }

    if (flip) reverse(q.begin(), q.end());
    string ans;
    for (auto c : q) ans += c;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1368
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = (1<<21);

int main() {
  int n;
  cin >> n;
  int cnt[n][n];
  int p[n+1];
  rep(i, n) {
    cin >> p[i] >> p[i+1];
  }

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

  FOR(l, 1, n) {
    rep(i, n-l) {
      int j = i+l;
      FOR(k, i, j) {
        cnt[i][j] = min(cnt[i][j], cnt[i][k] + cnt[k+1][j] + p[i] * p[k+1] * p[j+1]);
      }
    }
  }

  cout << cnt[0][n-1] << endl;



  
  return 0;
}


Measured memory_bytes: 3132
#include <stdio.h>

int main() {
	int n, r = 0, g = 0, b = 0;
	long long int ans=0;
	char S[4010];
	scanf("%d", &n);
	scanf("%s", &S);
	

	//printf("%s", S);

	int N[4][4010] = {0};
	char dd[4] = { '0','R','G','B' };

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (S[j] == 'B')N[3][i]++;
			if (S[j] == 'R')N[1][i]++;
			if (S[j] == 'G')N[2][i]++;
		}
	}
	//for (int i = 0; i < n; i++) printf("%d %d %d\n", N[1][i], N[2][i], N[3][i]);

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (S[i] == S[j]) continue;
			int o = 0;
			if ((S[i] == 'R' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'R'))o = 3;
			if ((S[i] == 'B' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'B'))o = 1;
			if ((S[i] == 'R' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'R'))o = 2;
			ans += N[o][j];
			if (2 * j - i < n) {
				if (S[2 * j - i] == dd[o])ans--;
			}
		}
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1800
#include <iostream>

int main(){
    int a, b;
    std::cin >> a >> b;

    int ans;
    switch(a + b){
        case 3:
            ans = 3;
            break;
        case 4:
            ans = 2;
            break;
        case 5:
            ans = 1;
            break;
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  string a;
  cin >> a;
  
  if (a.at(5) == '0') {
    if (a.at(6) == '1' || a.at(6) == '2' || a.at(6) == '3' || a.at(6) == '4')
      cout << "Heisei" << endl;
    else cout << "TBD" << endl; 
  } else {
    cout << "TBD" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int X = sc.nextInt();

    int count = 0;
    for(int a=0; a<=A; a++){
      for(int b=0; b<=B; b++){
        int c = (X - a * 500 - b * 100)/ 50;
        if( c >= 0 && c <= C)
          count++;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 22740
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
// 公約数
long int gcd(long int a, long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long int lcm(long int a, long int b){
  return a * b / gcd(a, b);
}


// min
int main(void){
  int n;
  long int b[101];
  long int ans = 0;
  
  scanf("%d", &n);

  for(int i = 0; i < n - 1; i++){
    scanf("%ld", &b[i]);
  }

  ans += b[0];
  //  printf("1ans = %ld\n", ans);
  for(int i = 0; i < n - 2; i++){
    if(b[i] < b[i + 1]){
      ans += b[i];
    }else{
      ans += b[i + 1];
    }
    //    printf("2ans = %ld\n", ans);
  }
  ans += b[n - 2];
  //  printf("3ans = %ld\n", ans);
  
  
  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
#define maxv 100001
#define che 1LL<<32
#define mod 1000000007
int main()
{
    ll k,s;
    cin>>k>>s;
    ll x,y,c=0,i,j;
    for(i=0;i<=k;i++)
    {
        for(j=0;j<=k;j++)
        {
            x=s-i-j;
            if(x<=k&&x>=0)
                c++;
        }
    }
    cout<<c<<endl;
}

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

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

    int n;
    cin >> n;
    map<int, int> mp;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        mp[a] = i + 1;
    }

    for(auto x: mp){
        cout << x.second << ' ';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 5504
import sys

class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = self.right = None

class BST:
    def __init__(self):
        self.root = None
    def insert(self, key):
        x, y, z = self.root, None, Node(key)
        while x != None: x, y = x.left if z.key < x.key else x.right, x
        if y == None: self.root = z
        elif z.key < y.key: y.left = z
        else: y.right = z
    def print_tree(self):
        def inorder(node):
            return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
        def preorder(node):
            return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''
        print(inorder(self.root))
        print(preorder(self.root))

tree = BST()
input()
for e in sys.stdin:
    if e[0] == 'i': tree.insert(int(e[7:]))
    else: tree.print_tree()


Measured memory_bytes: 63276
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;
ll MOD = 1e+9+7;

int main() {
    ll n, m; cin >> n >> m;
    vector<ll> a;
    rep(i, n+1){
        a.push_back(i);
    }
    ll sum = 0;
    ll mn = 0, mx = 0;
    for(int i=0; i<m-1; i++){
        mn += a.at(i);
        mn %= MOD;
        mx += a.at(n-i);
        mx %= MOD;
    }
    for(int i=m; i<=n+1; i++){
        mn += a.at(i-1);
        mn %= MOD;
        mx += a.at(n-i+1);
        mx %= MOD;
        ll a = (MOD + mx - mn + 1)%MOD;
        sum+=a;
    }
    sum %= MOD;

    cout << sum << endl;
    return 0;
}


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

int main() {
  int N; cin >> N;
  int K; cin >> K;
  string S; cin >> S;
  int happy = 0;
  
  for (int i = 0; i < N - 1; i++) {
    if (S.at(i) == S.at(i + 1)) {
      happy++;
    }
  }
  
  happy += 2 * K;
  
  if (happy >= N) {
    happy = N - 1;
  }
  
  cout << happy << endl;
}

Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define umap unordered_map
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


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

  vector<int> p(n);
  rep(i,n){
    cin>>p[i];
  }
  
  int ans=n;
  int st=0;
  repo(i,n+1){
    for(int j=st;j<n;j++){
      if(p[j]==i) {
      ans--;
      st=j;
      break;
      }
      if(ans!=n && j==n-1) {
        cout << ans << endl;
        return 0;
      }
    }
    if(ans==n) {
      cout << -1 << endl;
      return 0;
    }
    if(ans==0) {
    cout << 0 << endl;
    return 0;
    }
  }  
    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e7 + 10;
string n;
int len, num, i, f[N][2];
int main() {
	cin >> n;
	len = n.size();
	f[0][0] = 0; f[0][1] = 1;
	for (i = 0; i < len; i++) {
		num = n[i] - '0';
		f[i + 1][0] = min(f[i][0] + num, f[i][1] + 10 - num);
		f[i + 1][1] = min(f[i][0] + num + 1, f[i][1] + 9 - num);
	}
	cout << f[len][0];
	return 0;
}

Measured memory_bytes: 12108
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>
#define FR first
#define SE second
#define lowbit(x) (x&-x)

using namespace std;

int sumv[100005];

void add(int x,int num) {
  for(;x;x-=lowbit(x)) sumv[x]+=num;
}

int sum(int x,int n) {
  int s=0;
  for(;x<=n;x+=lowbit(x)) s+=sumv[x];
  return s;
}

typedef pair<int,int> pr;

pr a[300005];

bool cmp(pr x,pr y) {
  return x.SE-x.FR>y.SE-y.FR;
}

int ans[100005];

int main() {
  int n,m;
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i++) {
  	int x,y;
  	scanf("%d%d",&x,&y);
  	a[i]=pr(x,y);
  	add(y,1);
  	add(x-1,-1);
  }
  sort(a+1,a+n+1,cmp);
  int l=1;
  for(int i=m;i>0;i--) {
  	while (l<=n&&a[l].SE-a[l].FR>=i) {
  		add(a[l].SE,-1);
  		add(a[l].FR-1,1);
  		l++;
	  }
	ans[i]=l-1;
    for(int j=i;j<=m;j+=i) ans[i]+=sum(j,m);
  }
  for(int i=1;i<=m;i++) printf("%d\n",ans[i]);
  return 0;
}

Measured memory_bytes: 3968
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int a,b;cin >> a >> b;
    int  k;cin >> k;
    if(a==0) cout << b/k+1 << endl;
    else cout << b/k-(a-1)/k << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define N 100005
using namespace std;
int n,m,i,j,a,b,ans,vis[N];
long long h[N];
int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++){
		scanf("%ld",&h[i]);
	}
	for(i=1;i<=m;i++){
		scanf("%d%d",&a,&b);
		if(h[a]<=h[b]){
			vis[a]=1;
		}
		if(h[b]<=h[a]){
			vis[b]=1;
		}
	}
	for(i=1;i<=n;i++){
		if(vis[i]==0){
			ans++;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 4896
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007


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

  int ans = 0;
  for(int i = 0;i < 6;i++) {
    if(S.at(i) == '1') ans++;
  }

  cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int a, v;
    cin >> a >> v;

    int b, w;
    cin >> b >> w;

    int t;
    cin >> t;

    int d = abs(a - b);
    int u = v - w;

    int r = 1;
    if (u <= 0) r = 0;
    if ((ll)t * u < d) r = 0;

    cout << (r ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define p_b push_back
#define e_b emplace_back
#define m_p make_pair
#define m_t make_tuple

using namespace std;

int main() {
	string n;
	cin >> n;

	int c = 0;
	for (int i = 0; i < n.size(); i++) {
		c += n.at(i) - '0';
	}

	if (c % 9 == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;

	return 0;
}

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

int BubbleSort(int* a, int n) {
    int flag = 1;
    int num = 0;
    while (flag == 1) {
        flag = 0;
        for (int j=n-1; j>0; j--){
            if ( a[j] < a[j-1] ){
                swap(a[j], a[j-1]); 
                num++; 
                flag = 1;
            }
        }
    }
    return num;
}

int main(int argc, char const *argv[])
{
    int n, k;
    cin >> n;
    int a[n];
    for (int i=0; i<n; i++){
        cin >> a[i];
    }
    int* ap;
    ap = a;

    k = BubbleSort(ap, n);

    for (int i=0; i<n; i++){
        if (i == n-1){ cout << a[i] << endl; }
        else{ cout << a[i] << " "; }
    }

    cout << k << endl;

    return 0;
}



Measured memory_bytes: 3100
#include <stdio.h>
#include <string.h>

int main(){
	char a[3];
	int i,t;

	scanf("%s", a);

	t = strlen(a);
	
	if(t == 3){
	for(i=0; i < t/2; i++){
	char aa;
	aa = a[i];
	a[i] = a[t-i-1];
	a[t-i-1] = aa;
	}

	printf(" %s", a);
	}
	else{
	printf("%s",a);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define f(i,a,b) for(ll i=a; i<b; i++)
ll gcd(ll ina, ll inb) 
{     
    if (ina == 0) 
       return inb; 
    if (inb == 0) 
       return ina; 
   
    
    if (ina == inb) 
        return ina; 
   
    if (ina > inb) 
        return gcd(ina-inb, inb); 
    return gcd(ina, inb-ina); 
} 
ll lcm(ll in1, ll in2)
{ ll ans=1; ans=(in1*in2)/gcd(in1,in2); 
return ans;
}
int main()
{ ll n,k; cin>>n>>k; ll a[n]; f(i,0,n) { cin>>a[i];}  
ll dp[n]={}; 
f(i1,0,n) { dp[i1]=1000000000;}
 dp[0]=0; dp[1]=abs(a[1]-a[0]); if((k+1)>=2) { f(j,2,min(k+1,n)) { f(k1,0,j) {  dp[j]=min(dp[k1]+abs(a[j]-a[k1]),dp[j]);   }  } }
 f(i2,k+1,n) {f(i3,i2-k,i2) {dp[i2]=min(dp[i2],dp[i3]+abs(a[i3]-a[i2]));}}
cout<<dp[n-1]<<"\n"; }   






Measured memory_bytes: 5128
#include<bits/stdc++.h>
using namespace std;
int N,C[10000],D[5010][2],i,j;

main(){
    scanf("%d",&N);for(i=0;i<N-1;i++)scanf("%d",C+i);
    fill_n(*D+3,1e4,1e9);D[0][0]=1e9;
    for(i=0;i<N-1;i++)for(j=N/2;~j;j--)D[j+1][0]=min(D[j][0],D[j][1]+C[i]),D[j][1]=min(D[j][0]+C[i],D[j][1]);

    printf("%d\n",min(D[N/2][0],D[N/2][1]));
}

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

#define int long long

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

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()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N, M, K; cin >> N >> M >> K;
    REP(n, N+1)
    {
        REP(m, M+1)
        {
            if(n*(M-m)+(N-n)*m == K)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
x,k,d=map(int,input().split())
if x<0:
    x=-x
if x//d>=k:
    print(x-k*d)
else:
    a,b=x%d,abs(x%d-d)
    if min(a,b)==a:
        if (k-x//d)%2==0:
            print(a)
        else:
            print(b)
    else:
        if (k-x//d-1)%2==0:
            print(b)
        else:
            print(a)

Measured memory_bytes: 9092
#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
int main(){
    int n;
    cin >> n;
    ll aux, ans = 1;
    bool sw = 0, sw2 = 0;
    for(int i = 0; i < n; i++){
        cin >> aux;
        if(aux == 0)
            sw = 1;
        else if(ans > (1000000000000000000 / aux) || ans < 0)
            sw2 = 1;
        ans *= aux;
    }
    if(sw){
        cout << "0\n";
        return 0;
    }else if(sw2){
        cout << "-1\n";
        return 0;
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	string ans;
	while (N) {
		Int r;
		r = N % (-2);
		if (r<0) {
			r += 2;
		}

		ans += '0' + r;
		N = (N - r) / (-2);
	}

	reverse(ans.begin(), ans.end());
	if (ans=="") {
		cout << 0 << "\n";
		return 0;
	}
	cout << ans << "\n";

}


Measured memory_bytes: 256
// 2013/06/14 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	while(true){
		int a[21];
		int L;
		cin >> a[0] >> L;

		if(a[0]==0&&L==0)
			break;

		for(int i=1; i<=20; i++){
			int b = a[i-1];

			int tmp[6];
			for(int j=0; j<L; j++){
				tmp[j] = b%10;
				b /= 10;
			}

			sort(tmp, tmp+L);

			int b_max = 0;
			for(int j=L-1; j>=0; j--){
				b_max *= 10;
				b_max += tmp[j];
			}

			int b_min = 0;
			for(int j=0; j<L; j++){
				b_min *= 10;
				b_min += tmp[j];
			}

			a[i] = b_max-b_min;

//			cout << a[i] << endl;

			bool flg = false;

			for(int j=0; j<i; j++){
				if(a[j]==a[i]){
					cout << j << ' ' << a[i] << ' ' << i-j << endl;
					flg = true;
					break;
				}
			}

			if(flg)
				break;
		}
	}

	return 0;
}

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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
	int n, m, q;
	cin >> n >> m >> q;
	vector<vi> trains(vector<vi>(n, vi(n)));
	REP(i, m){
		int l, r;
		cin >> l >> r;
		if(l > r) swap(l, r);
		--l; --r;
		trains[l][r] += 1;
	}
	
	for(int i = n - 2; i >= 0; --i){
		REP(j, n){
			trains[i][j] += trains[i + 1][j];
		}
	}
	
	REP1(i, n - 1){
		REP(j, n){
			trains[j][i] += trains[j][i - 1];
		}
	}
	
	REP(iii, q){
		int p, q;
		cin >> p >> q;
		p--; q--;
		cout << trains[p][q] << "\n";
	}
	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int n;
	int ans;
	cin>>n;
	ans=n/3;
	cout<<ans<<endl;
}


Measured memory_bytes: 256
use std::collections::HashSet;
use std::io;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let mut vars = line.split_ascii_whitespace();
    let x = vars.next().unwrap().parse::<i64>().unwrap();
    let n = vars.next().unwrap().parse::<u64>().unwrap();
    assert!(vars.next().is_none());
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let ps: HashSet<_> = line
        .split_ascii_whitespace()
        .map(|p| p.parse::<i64>().unwrap())
        .collect();
    assert!(ps.len() == n as usize);
    let candidates = (0..=101).filter(|x| !ps.contains(x));
    let mut answer: Option<i64> = None;
    for c in candidates {
        if answer.is_none() || (x - answer.unwrap()).abs() > (x - c).abs() {
            answer = Some(c);
        }
    }
    println!("{}", answer.unwrap());
}


Measured memory_bytes: 2084
#!/usr/bin/perl

my ($n,$x,$m) = map { $_ - 0 } split(/\s+/,<STDIN>);

if( $m == 1 || $x == 0 ){
  print "0\n"; exit(0);
}
if( $x == 1 ){
  print "$n\n"; exit(0);
}

my @d = (); $#d = 101000;

my $cnt = 0;
my $xx = $x;
my $sum1 = 0;

while( !ref($d[$xx]) ){
  $d[$xx] = +[$cnt,$sum1];
  $sum1 += $xx;
  $xx = ($xx * $xx) % $m;
  $cnt ++;
  if( $cnt == $n || $xx == 0 ){
    print "$sum1\n";exit(0);
  }
}

my $cntm = $cnt - $d[$xx]->[0];
my $vv = $sum1 - $d[$xx]->[1];

# sum1 , cnt

my $nn = $n - $cnt;
my $res = $sum1;

my $nn1 = $nn % $cntm;
my $nn2 = ($nn - $nn1) / $cntm;

$res += $nn2 * $vv;
if( $nn1 > 0 ){
  $res += &sim($xx,$nn1);
}
print "$res\n";

exit (0);

sub sim {
  my $xx2 = shift;
  my $nn1 = shift;
  my $sum2 = 0;
  for(my $i=0;$i<$nn1;$i++){
    $sum2 += $xx2;
    $xx2  = ( $xx2 * $xx2 ) % $m;
    last if $xx2 == 0;
  }
  return $sum2;
}




Measured memory_bytes: 13912
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        a: i32,
        b: i32,
    }
    if (a + b).abs() % 2 == 0 {
        println!("{}", (a + b).abs() / 2);
    }
    else {
        println!("IMPOSSIBLE");
    }
}


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

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

  vector<ll> v;
  map<int, int> mp;
  rep(i,0,N-1) {
    int a;
    cin >> a;
    mp[a]++;
    if (mp[a] == 2) {
      v.push_back(a);
      mp[a] -= 2;
    }
  }

  sort(v.begin(), v.end(), greater<int>());

  ll ans;
  if (v.size() < 2) ans = 0;
  else ans = v[0] * v[1];

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


Measured memory_bytes: 8168
#include <bits/stdc++.h>
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl

using namespace std;

int main() {
    ll N, M;
    while (cin >> N >> M) {
        ll ans = 0;
        ll a = min(N, M / 2);
        ans += a;
        M -= a * 2;
        ans += M / 4;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tu = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl
#define first(v) get<0>(v)
#define second(v) get<1>(v)
#define third(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;



int main(){
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    for(ll i=0;i<N;i++){
        cin>>A[i]
    ;}
    //dp[j][1]はA[i]までに&1<<jな個数
    vector<vector<ll>> until(20, vector<ll>(N, 0));
    for(ll i=0;i<20;i++){
        if(A[0]&(1<<i))until[i][0]=1;
        else until[i][0]=0;
    ;}
    for(ll i=1;i<N;i++){
        for(ll j=0;j<20;j++){
            if(A[i]&(1<<j))until[j][i]=until[j][i-1]+1;
            else until[j][i]=until[j][i-1];
        ;}
    ;}
    ll ans=0;
    for(ll i=0;i<N;i++){
        ll mark=INF;
        for(ll j=0;j<20;j++){
            ll k;
            if(A[i]&(1<<j))
            k=upper_bound(until[j].begin(), until[j].end(), until[j][i])-until[j].begin();
            else 
            k=upper_bound(until[j].begin(), until[j].end(), until[j][i]+1)-until[j].begin();
            chmin(mark,k);
        ;}
        ans+=mark-i;
    ;}
    print(ans);
    return 0;
}


Measured memory_bytes: 34688
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

typedef struct Edge {ll from, to, cost;} Edge;
bool comp(const Edge& e1, const Edge& e2) {
    return e1.cost < e2.cost;
}

int main() {
    ll N; cin >> N;
    Edge *E = new Edge[(N-1) * 2];

    vector<tuple<ll,ll,ll>> VX(N); 
    vector<tuple<ll,ll,ll>> VY(N);
    rep(i, N) {
        ll x, y; cin >> x >> y;
        VX.at(i) = make_tuple(x,y,i);
        VY.at(i) = make_tuple(y,x,i);
    }
    sort(VX.begin(), VX.end());
    sort(VY.begin(), VY.end());
    /*
    fprintf(stderr, "-------------- VX --------------\n");
    for (auto x : VX) fprintf(stderr, "%ld %ld %ld\n", x.first.first, x.first.second, x.second);
    */
    int c = 0;
    auto prev = VX.begin();
    for (auto x = next(prev, 1); x != VX.end(); x++) { 
        ll  cost = min(abs(get<0>(*prev) - get<0>(*x)),
                       abs(get<1>(*prev) - get<1>(*x)));
        ll  u = get<2>(*prev), v = get<2>(*x);
        E[c++] = {u, v, cost};
        prev = x;
    }

    /*
    fprintf(stderr, "-------------- VY --------------\n");
    for (auto y : VY) fprintf(stderr, "%ld %ld %ld\n", y.first.second, y.first.first, y.second);
    */
    prev = VY.begin();
    for (auto y = next(prev, 1); y != VY.end(); y++) {
        ll cost = min(abs(get<0>(*prev) - get<0>(*y)),
                      abs(get<1>(*prev) - get<1>(*y)));
        ll u = get<2>(*prev), v = get<2>(*y);
        E[c++] = {u, v, cost};
        prev = y;
    }
    /*
    fprintf(stderr, "--------------  E --------------\n");
    for (auto x : E) {
        fprintf(stderr, "%ld %ld %ld\n", x.first.first, x.first.second, x.second);
    }
    */

    // Kruskal
    sort(E, E + ((N-1)*2), comp);
    UnionFind U = UnionFind(N);
    ll res = 0;
    rep(i, (N-1) * 2) {
       Edge e = E[i];
       if (!U.issame(e.from, e.to)) {
           U.merge(e.from, e.to);
           res += e.cost;
       }
    }

    cout << res << endl;
}


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

// const MOD: i32 = 1000000007;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: usize = read().unwrap();
    println!("{}", n/3);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long int
#define ld double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	int n, i;
	cin >> n;
	int arr[n];
	fo(i, 0, n)
	cin >> arr[i];
	int curr, ans = 0;
	curr = 0;
	fo(i, 1, n){
		if(arr[i] <= arr[i - 1])
		curr++;
		else{
			ans = max(ans, curr);
			curr = 0;
		}
	}
	ans = max(ans, curr);
	cout << ans;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

int main(){
    int n; cin >> n;
    vector<int> A(n);
    collect(A, n);
    
    vector<bool> makeable(40001,false);
    
    rep(i,pow(2,n)){
        int sum = 0;
        rep(j,n){
            if((i >> j) & 1) sum += A[j];
        }
        makeable[sum] = true;
    }
    
    int q; cin >> q;
    rep(Q,q){
        int m; cin >> m;
        cout << (makeable[m] ? "yes" : "no") << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    string s;
    cin>>s;
    int ans=0;
    int n=s.size();
    rep(i,n/2){
        if(s.at(i)!=s.at(n-1-i))ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3604
from operator import itemgetter
import sys
input = sys.stdin.readline

def main():
    N,M = map(int,input().split())
    f = []
    for i in range(M):
        P,Y = map(int,input().split())
        f.append([P,Y,i])
        
    f.sort(key = itemgetter(0,1))
    s = 1
    count = 0
    for i in range(M):
        if s != f[i][0]:
            s = f[i][0]
            count = 1
            f[i][1] = count
        else:
            count += 1
            f[i][1] = count
            
    ans = []
    for i in range(M):
        p,y,num = f[i]
        lp,ly = len(str(p)),len(str(y))
        ad = "0"*(6-lp) + str(p) + "0"*(6-ly) + str(y)
        ans.append((num,ad))
        
    ans.sort(key = itemgetter(0))
    for i in range(M):print(ans[i][1])
    
if __name__ == "__main__":
    main()


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

int main()
{
	const double EPS = 1e-10;
	const double PI = 4.*atan(1.);

	int n;cin>>n;
	for ( int i=0; i<n; i++ )
	{
		double x1,y1,x2,y2,x3,y3,x4,y4;
		cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
		complex<double> A(x1,y1),B(x2,y2),C(x3,y3),D(x4,y4);
		double a = arg((A-B)/(C-D));
		//cout << ( abs(a)<EPS || abs(a)>PI-EPS ? "YES" : "NO" ) << endl;
		cout << ( abs(a)==0 || abs(a)==PI ? "YES" : "NO" ) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int INF = INT32_MAX;

int main() {
    int n; cin >> n;
    vector<int> h(n); rep(i, n) cin >> h[i];
    vector<int> dp(n+10, INF); dp[0] = 0;
    rep(i, n-1) {
        if (i+1 < n) dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
        if (i+2 < n) dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
    }

    cout << dp[n-1] << endl;


    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
   int n, a;
   cin >> n >> a;
   for(int i = 0; i <= a; i++){
       for(int j = 0; j <= n; j += 500){
           int sum = i + j;
           if(sum == n){
               cout << "Yes"<< endl;
               return 0;
           }
       }
   }
   cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool bo[100];
#define ll long long int

int main()
{
	ll n;
	cin>>n;
	if(n<=6)
	{
		cout<<1<<endl;
		return 0;
	}
	if(n<=11)
	{
		cout<<2<<endl;
		return 0;
	}
	ll w=11;
	ll q=n/w;
	//cout<<n%w<<endl;
	if((n%w)>6)
	{
		cout<<(2*q)+2<<endl;
	}
	else if((n%w)>0)
	{
		cout<<(2*q)+1<<endl;
	}
	else
	{
		cout<<2*q<<endl;
	}
}


Measured memory_bytes: 256
private class B {
    fun solve() {
        val n = nextInt()
        val k = nextInt()
        val a = IntArray(n) { nextInt() }
        a.sort()
        var ans = 0
        for (i in 1..k) {
            ans += a[i - 1]
        }
        println(ans)
    }

    var tokenBuffer = listOf<String>()
    var bufferPosition = 0

    private fun checkBuffer() {
        if (bufferPosition == tokenBuffer.size) {
            tokenBuffer = nextLine().split(" ")
            bufferPosition = 0
        }
    }

    fun nextLine() = readLine()!!
    fun nextInt(): Int {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toInt()
    }

    fun nextLong(): Long {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toLong()
    }

    fun nextDouble(): Double {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toDouble()
    }

    fun nextToken(): String {
        checkBuffer()
        return tokenBuffer[bufferPosition++]
    }
}

fun main() {
    val reader = B().solve()

}


Measured memory_bytes: 40468
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <map>
#include <algorithm>  
#include <cmath>
#include <iomanip>
#define ll long long
using namespace std;
ll n;
ll mod=pow(10,9)+7;
ll arr[100005];
ll dp[100005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(ll i=0;i<n;++i)
    {
        cin>>arr[i];
    }
    dp[0]=0;
    for(ll i=1;i<n;++i)
    {
        ll ans=INT_MAX;
        ll add=abs(arr[i-1]-arr[i])+dp[i-1];
        if(i-2>=0)
        {
            add=min(add,abs(arr[i-2]-arr[i])+dp[i-2]);
        }
        dp[i]=add;
    }
    cout<<dp[n-1]<<endl;
}






































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

int main() {
	// your code goes here
	vector<int> a(3);
	cin>>a[0]>>a[1]>>a[2];
	sort(a.begin(),a.end());
	cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
	return 0;
}


Measured memory_bytes: 3128
#include <cstdio>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<fstream>

#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
using namespace std;

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
       
    ll i,j,k,x,y,z,p,q;
    ll n,m,tmp;
    string s[200000];
    string str;
    ll sum=0;
    ll strr[200005];
    cin>>i>>j>>k;
    if(i>j) j=i;
    i=k/j;
    if(k%j) i++;
    cout<<i<<endl;

    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for (int i = 0; i < N; ++i) cin >> h[i];
  
  int ans = 0;
  for (int i : h) {
    if (i >= K) ++ans;
  }
  
  cout << ans << endl;
  return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

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

  string a, b;
  while (cin >> a >> b) {
    for (int i = 0; i < 1000; ++i) {
      if (i < a.size()) cout << a[i];
      if (i < b.size()) cout << b[i];
    }
    cout << endl;
    
  }
  
  return 0;
}


Measured memory_bytes: 256
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> F;
void make(int x,int N,vector<int> A)
{
	vector<int> B=A;
	if(x<N)
	{
		B.push_back(1);
		make(x+1,N,B);
		A.push_back(0);
		make(x+1,N,A);
	}
	else
	{
		F.push_back(A);
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	

	int N,M;
	cin>>N>>M;
	vector<int> R;
	make(0,N,R);
	vector<vector<int>> C;
	for (int i = 0; i < M; ++i)
	{
		int k;
		cin>>k;
		vector<int> X;
		for (int j = 0; j < k; ++j)
		{
			int x;
			cin>>x;
			x--;
			X.push_back(x);
		}
		C.push_back(X);
	}
	vector<int> P;
	for (int i = 0; i < M; ++i)
	{
		int x;
		cin>>x;
		P.push_back(x);
	}
	int ans=0;
	for (int i = 0; i < F.size(); ++i)
	{
		int flag=true;
		for (int j = 0; j < M; ++j)
		{
			int val=0;
			for (int k = 0; k < C[j].size(); ++k)
			{
				val+=F[i][C[j][k]];
			}
			if(val%2!=P[j])
			{
				flag=false;
			}
		}
		if(flag)
		{
			ans++;
		}
	}
	cout<<ans<<endl;
	

	return 0;
}

Measured memory_bytes: 384
n, m = [int(i) for i in input().split()]
cnt = 0
l = []
r = []
for i in range(m):
    a, b = [int(i) for i in input().split()]
    l.append(a)
    r.append(b)
if(min(r) < max(l)):
    ans = 0
else:
    ans = min(r)-max(l)+1
print(ans)

Measured memory_bytes: 10996
#include<stdio.h>

int main(void){
  int a,b;
  char op;

  scanf("%d %c %d", &a, &op, &b);

  while(op!='?'){
    int ans;
    if(op=='+') ans = a + b;
    if(op=='-') ans = a - b;
    if(op=='*') ans = a * b;
    if(op=='/') ans = a / b;
    
    printf("%d\n", ans);
    
    scanf("%d %c %d", &a, &op, &b);
  }
  return 0;
}



Measured memory_bytes: 2052
#define _USE_MATH_DEFINES

#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max,count
#include <string>	//string
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt
#include <sstream>	//stringstream,getline
#include <cmath>	//ceil,M_PI

using namespace std;
inline double Median(vector<int>& A) {

	int temp = A.size();

	sort(A.begin(), A.end());

	if (temp % 2 == 0) {
		double ans = (A[(temp / 2) - 1] + A[temp / 2]) / 2.0;
		return ans;
	}
	else {
		return A[temp / 2];
	}
}

int main() {

	int S, W;
	cin >> S >> W;

	if (S <= W) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}

	return 0;

}

Measured memory_bytes: 3584
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	int N;
	cin >> N;

	string S;
	cin >> S;

	sort(S.begin(), S.end());

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


		int seq = 0;

		for (int j = i; j < N; j++) {
			if (S[i] == S[j]) {
				seq++;

				if (j == N - 1) {
					ans *= (seq+1);
					ans %= MOD;
					cout << ans - 1;
					return 0;
				}
			}
			else {
				i = j-1;
				ans *= (seq+1);
				ans %= MOD;
				break;
			}
		}
			   		 
	}


	cout << ans - 1;


}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main() {
	int h[6],k;
	for(int i=1; i<=5; i++)
		cin>>h[i];
	cin>>k;
	for(int j=1; j<=5; j++)
		for(int i=j+1; i<=5; i++) {
			if(abs(h[i]-h[j])>k) {
				cout<<":(";
				return 0;
			}
		}
	cout<<"Yay!";

	return 0;
}


Measured memory_bytes: 256
import bisect
N=int(input())
As=list(map(int,input().split()))
S=sum(As)
l=[]
x=0
for i in range(N):
  x+=As[i]
  l.append(x)
ha=bisect.bisect_left(l,S/2)
sa1=abs(l[ha]-(S-l[ha]))
if ha>0:
  sa2=abs(l[ha-1]-(S-l[ha-1]))
else:
  sa2=sa1+1#便宜的に
print(min([sa1,sa2]))

Measured memory_bytes: 26024