akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

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

bool check(int row, int col){
  for(int r = 0; r < M; ++r){
    for(int c = 0; c < M; ++c){
      if(B[r][c] != A[row + r][col + c]) return false;
    }
  }

  return true;
}

inline bool solve(){

  for(int r = 0; N - r >= M; ++r){
    for(int c = 0; N - c >= M; ++c){
      if(check(r, c)) return true;
    }
  }

  return false;
}

int main(){
  FAST_IO
  cin >> N >> M;
  
  for(int r = 0; r < N; ++r) cin >> A[r];
  for(int r = 0; r < M; ++r) cin >> B[r];

  if(solve()) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


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

void doc(){
    freopen("OB.inp","r", stdin);
    freopen("OB.out","w", stdout);
}

long long res = 0;

void MergeSort(vector<int> &A, int l, int mid, int r){
    int n1 = mid - l + 1;
    int n2 = r - mid;
    vector<int> L(n1), R(n2);
    for(int i = 0; i < n1; i++) L[i] = A[i + l];
    for(int i = 0; i < n2; i++) R[i] = A[mid + i + 1];
    L.push_back(1e9 + 1);
    R.push_back(1e9 + 1);
    int i = 0, j = 0;
    //cout << l << " " << r << " ";
    for(int k = l; k <= r; k++){
        if (L[i] <= R[j]){
            A[k] = L[i];
            i++;
        }
        else{
            A[k] = R[j];
            j++;
            res += n1 - i;
        }
    }
   // cout << res << '\n';
}

void Merge(vector<int> &A, int l, int r){
    if (l >= r) return;
    //cerr << l << " " << r << '\n';
    int mid = (l + r) >> 1;
    Merge(A, l, mid);

    Merge(A, mid + 1, r);

    MergeSort(A, l, mid, r);
}

void solve(){
    int n;
    cin >> n;
    vector<int> a(n);
    a.clear();
    for(int i = 0; i < n; i++)
        cin >> a[i];
    Merge(a, 0, n - 1);
//    for(int i = 0; i < n; i++) cout << a[i] << " ";
//    cout << '\n';
    cout << res << '\n';
}

int main(){
  //  ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
   // doc();
    solve();
}



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

int main() {
    string s;
    cin >> s;
    for(int i=0;i<5;i++){
        cout << s.at(i);
    }
    cout << " ";
    for(int i=6;i<13;i++){
        cout << s.at(i);
    }
    cout << " ";
    for(int i=14;i<19;i++){
        cout << s.at(i);
    }
}

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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
const long long INF = 1LL<<60;
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;
}

int main(){
    int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;

    int maxXY;
    // int dif;
    if (X > Y) {
        maxXY = X;
        // dif = A * (X - Y);
    } else if (X < Y) {
        maxXY = Y;
        // dif = B * (Y - X);
    } else {
        maxXY = X;
        // dif = 0;
    }
    int ans = 1e9;
    for (int n = 0; n <= 2 * maxXY; n += 2) {
        int temp = A * max(0, X - n / 2) + B * max(0, Y - n / 2) + C * n;
        // cout << "X: " << X - n / 2 << "Y: " << Y - n / 2 << endl;
        // cout << temp << endl;
        if (temp < ans) ans = temp;
    }
    // cout << dif << endl;
    cout << ans << endl;
}

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

int main()
{
  long long int n;
  cin>>n;
  long long int x=7;
  long long int i=1;
  while(1)
  {
      x%=n;
      if(x==0)
      {
          cout<<i;
          return 0;
      }
      if(i>n)
      {
        cout<<-1;
        return 0;
      }
      x=x*10+7;
      i++;
  }
}



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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a);i>(b);i--)
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int,int> pii;

main(){
  int w,a,b; cin >> w >> a >> b;
  int ans = 0;

  if(a < b && a + w < b) ans = b - (a + w);
  else if(b < a && b + w < a) ans = a - (b +w);
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

// 標準入力を取得するScannerのインスタンスを作成
var scanner = bufio.NewScanner(os.Stdin)

// 標準入力で各行を読み込みintとして返す
func readLine() int {
	if scanner.Scan() {
		number, _ := strconv.Atoi(scanner.Text())
		return number
	}
	return 0
}

func main() {
	// 改行区切りから単語(スペース)区切りで読み込むように変更する
	scanner.Split(bufio.ScanWords)

	// 長さN
	N := readLine()

	// 整数列B
	B := make([]int, 0, N-1)
	for i := 0; i < N-1; i++ {
		B = append(B, readLine())
	}

	// 例
	// A0 A1 A2
	//  B0 B1

	// 問題文で提示された条件 -> Aに焦点をあて、条件を分解し分かりやすくする
	// B0 >= max(A0, A1)   -> A0 <= B0 && A1 <= B0
	// B1 >= max(A1, A2)   -> A1 <= B1 && A2 <= B1

	// A0 A1 A2ごとに条件を整理する
	// A0 <= B0
	// A1 <= B0 && A1 <= B1
	//             A2 <= B1

	// Aの要素の総和として考えられる値の最大値を求めるので
	// Aの各要素が最大になるケースを考える
	// A0 <= B0             -> A0 = B0
	// A2 <= B0 && A1 <= B1 -> A1 <= min(B0, B1)
	//             A2 <= B1 -> A2 = B1

	// 整数列A
	A := make([]int, 0, N)

	// A0 A1 A2を求め整数列Aのsliceに格納する
	for i := 0; i < N; i++ {
		n := 0
		if i == 0 {
			// A0 = B0
			n = B[0] //最初の要素を取り出す
			//fmt.Printf("i=%d B[%d]=%d\n", i, i, B[i])
		} else if i == N-1 {
			// A2 = B1
			n = B[len(B)-1] // 最後の要素を取り出す
			//fmt.Printf("i=%d B[%d]=%d\n", i, len(B)-1, B[len(B)-1])
		} else {
			//  A1 <= min(B0, B1)
			n = int(math.Min(float64(B[i-1]), float64(B[i]))) // 最小値を求める
			//fmt.Printf("i=%d B[%d]=%d B[%d]=%d\n", i, i-1, B[i-1], i, B[i])
		}
		A = append(A, n)
	}

	answer := 0 // 総和 A0 A1 A2
	for _, a := range A {
		answer += a
	}
	fmt.Println(answer)
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
#include <sstream>
#include <bitset>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
    string s;
    ll k;
    cin >> k >> s;
    if(k>=(ll)s.size()) {
        cout << s << endl;
    } else {
        for(ll i=0;i<k;i++) cout << s[i];
        cout << "..." << endl;
    }
}


Measured memory_bytes: 3600
#include<stdio.h>
 int main(void){
     int a[10],i,j,ch,n;
       for(i=0;i<10;i++){
        scanf("%d",&a[i]);
       }
       for(i=0;i<9;i++){
        for(j=i+1;j<10;j++){
            if(a[i]<a[j]){
                ch=a[i];
                a[i]=a[j];
                a[j]=ch;
        }
        }
        }
        printf("%d\n%d\n%d\n",a[0],a[1],a[2]);
       return 0;
 }

Measured memory_bytes: 600
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int m,d;
    cin>>m>>d;
    int ans=0;
    for(int i=3;i<=m;i++){
        for(int j=1;j<=d;j++){
            int jj=j;
            int d2=jj/10;
            int d1=jj%10;
            if(d2*d1==i&&d2>=2&&d1>=2){
                ans++;
            }

        }
    }
    cout<<ans<<endl;



    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, a, b;
    cin >> n >> a >> b;
    ll res = a * (n / (a + b));
    ll rem = n % (a + b);
    res += min(rem, a);
    cout << res << '\n';

    return 0;
}


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

using ll = long long;

using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int red[n+1];
    red[0] = 0;
    for (int i=0; i<n; i++) {
        red[i+1] = red[i] + (s[i] == 'R');
    }
    int ans = n;
    for (int i=0; i<=n; i++) {
        int l = red[i], r = red[n] - l;
        int w2r = i - l, r2w = r;
        ans = min(ans, max(w2r, r2w));
    }
    cout << ans << '\n';
    return 0;
}

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

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

  int sum = 0, devisor = 1;
  while (devisor <= N) {
    sum +=  N % ( 10 * devisor ) / devisor;
    devisor *= 10;
  }
  if ( sum != 0 && N % sum == 0 ) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
S = input()

ans = []
cnt = 0
rl = S[0]

if S[-1] == 'R':
    S += 'L'
else:
    S += 'R'

for s in S:
    if s == rl:
        cnt += 1
    elif rl == 'R' and s == 'L':
        for i in range(cnt-1):
            ans.append(0)
        ans.append(cnt)
        cnt = 1
        rl = 'L'
    else:
        r = ans.pop(-1)
        l = cnt
        ans.append((r+l)//2)
        ans.append((r+l)//2)
        if (r+l) % 2 == 1 and r % 2 == 0:
            ans[-1] += 1
        elif (r+l) % 2 == 1 and r % 2 == 1:
            ans[-2] += 1
        for i in range(l-1):
            ans.append(0)
        cnt = 1
        rl = 'R'

print(*ans)


Measured memory_bytes: 6408
#include<iostream>
#include <climits>
#include<vector>
#include<list>
#include<numeric>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

void koch(vector<pair<double, double>> &a, int n) {
	if (n == 0) {
		a.push_back({0, 0});
		a.push_back({100, 0});
	}
	else {
		vector<pair<double, double>> b;
		koch(b, n - 1);
		for (int i = 0;i < b.size() - 1;i++) {
			a.push_back(b[i]);
			double tmp1 = (b[i + 1].first - b[i].first) / 3;
			double tmp2 = (b[i + 1].second - b[i].second) / 3;
			pair<double, double> b1 = { b[i].first + tmp1, b[i].second + tmp2 };
			pair<double, double> b3 = { b[i].first + 2 * tmp1, b[i].second + 2 * tmp2 };
			pair<double, double> b2 = { (b1.first + b3.first) / 2 - sqrt(3)*(b3.second - b1.second) / 2,
										(b1.second + b3.second) / 2 + sqrt(3)*(b3.first - b1.first) / 2 };
			a.push_back(b1);
			a.push_back(b2);
			a.push_back(b3);
		}
		a.push_back(b[b.size() - 1]);
	}
}

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

	int n;
	cin >> n;
	vector<pair<double, double>> a;
	koch(a, n);
	REP(i, a.size()) {
		cout << a[i].first << " " << a[i].second << "\n";
	}

	return 0;
}


Measured memory_bytes: 3344
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define FOR(i,x,n) for(ll i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
int main()
{
    ll n, k; cin >> n >> k;
    vector<ll> p(n);
    vector<ll> c(n);
    rep(i, n){
        cin >> p[i];
        p[i]--;
    }
    rep(i, n) cin >> c[i];
    ll csum = 0;
    rep(i, n) csum += c[i];
 
    // pr(csum);
 
    ll ans = -INFL;
    rep(i, n){
        chmax(ans, c[i]);
    }
 
    if(k==1 || ans==0) {pr(ans); return 0;}
    rep(i, n){
        vector<ll> q(n, 0);
        vector<ll> path;
        ll d = 0;
        ll pos = i;
        ll mid = 0;
        path.push_back(i);
        for(d; d<min(n, k); d++){
            pos = p[pos];
            path.push_back(pos);
            mid += c[pos];
            q[pos] = mid;
            chmax(ans, mid);
            if(pos==i) {d++; break;}
        }
        
        // if(min(n, k) == k) continue;
        // if(mid <= 0) continue;
 
        // prvec(q);
 
        ll loop = k / d;
        ll md = k % d;
 
        rep(j, d){
            q[path[j]] += (loop-1)*mid;
            chmax(ans, q[path[j]]);
        }
 
        mid = q[i];
        pos = i;
        if(loop>0){
        rep(j, md){
            pos = p[pos];
            mid += c[pos];
            chmax(ans, mid);
        }
        }
    }
 
    pr(ans);
    return 0;}

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

char str[55];
// AKIHABARA
// KIHBR
// 2^4

char target[][30] = {
	"AKIHABAR",
	"AKIHABARA",
	"AKIHABR",
	"AKIHABRA",
	"AKIHBAR",
	"AKIHBARA",
	"AKIHBR",
	"AKIHBRA",
	"KIHABAR",
	"KIHABARA",
	"KIHABR",
	"KIHABRA",
	"KIHBAR",
	"KIHBARA",
	"KIHBR",
	"KIHBRA"
};

int main()
{
	scanf("%s", str);

	int i = 0;
	while (i < 16 && strcmp(target[i], str)) {
		i++;
	}

	if (i == 16) {
		puts("NO");
	}
	else {
		puts("YES");
	}

	return 0;
}


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

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int W = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if ((a - (b + W) <= 0 && a > b) || (b - (a + W) <= 0 && a < b) || a == b) {
            System.out.println("0");
            return;
        }
        if (a < b) {
            System.out.println(b - (a + W));
        } else {
            System.out.println(a - (b + W));
        }
    }
}

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

int main(){

    long long n;cin >> n;

    long long i=n;
    long long ans=0;
    while(1){
        if(i%2==0 && i%n==0){
            ans=i;
            break;
        }else i*=2;
    }

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int N;
vector<vector<int>> cand;
void DFS(vector<int> a) {
  if ((int)a.size() == N) {
    int num[4];
    num[0] = 0;
    num[1] = 0;
    num[2] = 0;
    num[3] = 0;
    for (int i = 0; i < N; i++) {
      num[a[i]]++;
    }
    if (num[1] != 0 && num[2] != 0 && num[3] != 0) {
      cand.push_back(a);
    }
    return ;
  }
  for (int i = 0; i < 4; i++) {
    a.push_back(i);
    DFS(a);
    a.pop_back();
  }
  return ;
}
int main() {
  int A,B,C;
  cin >> N >> A >> B >> C;
  int l[N];
  for (int i = 0; i < N; i++) cin >> l[i];
  vector<int> R(1);
  R[0] = 0;
  DFS(R);
  R[0] = 1;
  DFS(R);
  R[0] = 2;
  DFS(R);
  R[0] = 3;
  DFS(R);
  ll ans = 999999999999;
  for (int i = 0; i < cand.size(); i++) {
    int asum = 0;
    int anum = 0;
    int bsum = 0;
    int bnum = 0;
    int csum = 0;
    int cnum = 0;
    for (int j = 0; j < N; j++) {
      if (cand[i][j] == 1) {
        asum += l[j];
        anum++;
      }
      if (cand[i][j] == 2) {
        bsum += l[j];
        bnum++;
      }
      if (cand[i][j] == 3) {
        csum += l[j];
        cnum++;
      }
    }
    ll res = (anum + bnum + cnum - 3) * 10;
    res += abs(asum - A) + abs(bsum - B) + abs(csum - C);
    ans = min(ans,res);
  }
  cout << ans << endl;
  return 0;
}

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


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

    int ans = (a < 2*b) ? 0 : a - 2*b;
    cout << ans << endl;
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    int n, k;
    cin >> n >> k;
    if (k == 1) cout << 0 << endl;
    else cout << n - k << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point{
public:
  double x, y;

  Point(double x = 0, double y = 0): x(x), y(y) {}

  Point operator + (Point p) { return Point(x + p.x, y + p.y); }
  Point operator - (Point p) { return Point(x - p.x, y - p.y); }
  Point operator * (double a) { return Point(a * x, a * y); }
  Point operator / (double a) { return Point(x / a, y / a); }

  bool operator < (const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }

  bool operator == (const Point &p) const {
    return equals(x, p.x) && equals(y, p.y);
  }

  double abs() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
};

typedef Point Vector;

struct Segment{
  Point p1, p2;
};

typedef Segment Line;

double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }

bool isOrthogonal(Vector a, Vector b){
  return equals(dot(a, b), 0.0);
}

bool isOrthogonal(Point a1, Point a2, Point b1, Point b2){
  return equals(dot(a1 - a2, b1 - b2), 0.0);
}

bool isOrthogonal(Segment s1, Segment s2){
  return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

bool isParallel(Vector a, Vector b){
  return equals(cross(a, b), 0.0);
}

bool isParallel(Point a1, Point a2, Point b1, Point b2){
  return equals(cross(a1 - a2, b1 - b2), 0.0);
}

bool isParallel(Segment s1, Segment s2){
  return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

Point project(Segment s, Point p){
  Vector base = s.p2 - s.p1;
  double r = dot(p - s.p1, base) / base.norm();
  return s.p1 + base * r;
}

Point reflect(Segment s, Point p){
  return p + (project(s, p) - p) * 2.0;
}

int main(void){
  int q;
  double x0, y0, x1, y1, x2, y2, x3, y3;
  
  cin >> x1 >> y1 >> x2 >> y2;
  
  Segment s;
  Point *p1 = new Point(x1, y1);
  Point *p2 = new Point(x2, y2);
  s.p1 = *p1, s.p2 = *p2;
  
  cin >> q;
  for(int i = 0; i < q; i++){
    cin >> x0 >> y0;
    Point *p0 = new Point(x0, y0);
    Point reflection = reflect(s, *p0);
    printf("%.10f %.10f\n", reflection.x, reflection.y);
  }
  return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int X; cin >> X;

    int A = X / 100;
    int B = X % 100;

    bool mA = (1 <= A and A <= 12);
    bool mB = (1 <= B and B <= 12);

    string res = "NA";
    if(mA and mB){
        res = "AMBIGUOUS";
    }
    else if(mA){
        res = "MMYY";
    }
    else if(mB){
        res = "YYMM";
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	ll n;
	cin>>n;
	vector<ll> a(n);
	for(int i=0;i<n;i++)
	cin>>a[i];
	vector<ll> ans(n+4,INT_MAX);
	ans[0]=0;
	for(int i=0;i<n;i++){
		if((i+2)<n)
		ans[i+2]=min(ans[i+2],ans[i]+abs(a[i]-a[i+2]));
		if((i+1)<n)
		ans[i+1]=min(ans[i+1],ans[i]+abs(a[i]-a[i+1]));
	}
	cout<<ans[n-1]<<endl;
}

Measured memory_bytes: 4780
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

const ll mod = 1000000007;

vector<ll> fac(1000100), finv(1000100), inv(1000100);
void initcom(){
  fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
  for(int i=2; i<1000100; i++){
    fac[i] = (fac[i-1]*i) % mod;
    inv[i] = mod - inv[mod%i] * (mod/i) % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}
ll nCr(int n, int k){
  if(n<k) return 0;
  if(n<0 || k<0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}
ll mpow(ll a, ll x){
  if(x<0) return 0;
  ll res = 1;
  while(x > 0){
    if(x & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    x >>= 1;
  }
  return res;
}
int main(){
  int N; cin >> N;
  initcom();
  ll ans = 0;
  ans = mpow(10,N)-mpow(9,N)-mpow(9,N)+mpow(8,N);
  while(ans<0) ans += mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 26600
#include <iostream>
#include <string.h>
#include <algorithm>

using namespace std;

int main()
{
    char s[15];
    cin>>s;
    int n=strlen(s), a, m=1000, k, x, y, z;
    for(int i=0; i<n-2; i++){
        x=(s[i])-48;
        y=(s[i+1])-48;
        z=(s[i+2])-48;
        a=x*100+y*10+z;
        if(abs(a-753)<m){
            m=abs(a-753);
            k=abs(a-753);
        }
    }
    cout<<k;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

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


ll __lcm(ll a, ll b)
{
    return a / __gcd(a, b) * b;
}

ll lcm(vector<ll> v)
{
    ll ret = v[0];
    for (int i = 0; i < v.size(); i++)
    {
        ret = __lcm(ret, v[i]);
    }
    return ret;
}


int main() {
    int N;
    cin >> N;
    vector<ll> T(N);
    rep(i, N) cin >> T[i];

    //配列の最小公倍数を求める
    ll ans = lcm(T);
    cout << ans << endl;
    return 0;
}


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


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

int main()
{
    int n;
    cin >> n;
    /*
    int a[n];
    std::vector<int> v;
    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        a[i] = tmp;
    }
    */
    int ans = 0;
    if(n%10==3){
        cout << "bon" << endl;
    }else if(n%10==0 || n%10==1 || n%10==6 || n%10==8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
    
}

Measured memory_bytes: 3544
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
priority_queue<int,vector<int>,greater<int> > q;
int R,C,n,Max=-1;
struct node{
	int x,y,x1,y1,c1,c2;
}a[100010],b[200010];int cnt=0,num=0,sta[200010],top=0,N=0;
bool cmp(node a,node b) {return a.c1<b.c1;}
int qs(int x,int y)
{
	if(x==1) return y;
	if(y==C) return C+x-1;
	if(x==R) return R+C-1+C-y;
	return R+C+C-2+R-x;
}
int main()
{
	scanf("%d %d %d",&R,&C,&n);R++;C++;
	for(int i=1;i<=n;i++)
	{
		int x,y,x1,y1;scanf("%d %d %d %d",&x,&y,&x1,&y1);
		x++;y++;x1++;y1++;
		bool k1=(x==1||x==R||y==1||y==C);
		bool k2=(x1==1||x1==R||y1==1||y1==C);
		if(k1&&k2)
		{
			a[++cnt].x=x,a[cnt].y=y,a[cnt].x1=x1,a[cnt].y1=y1;
			a[cnt].c1=qs(x,y);a[cnt].c2=qs(x1,y1);
		}
	}
	for(int i=1;i<=cnt;i++) if(a[i].c1>a[i].c2) swap(a[i].c1,a[i].c2);
	sort(a+1,a+cnt+1,cmp);
	for(int i=1;i<=cnt;i++)
	{
		while(!q.empty()&&q.top()<=a[i].c1) q.pop();
		if(!q.empty())
		{
			int x=q.top();
			if(x<a[i].c2) {printf("NO");return 0;}
		}
		q.push(a[i].c2);
	}
	printf("YES");
}

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

/*If you are going to try,keep going until the end ,or don't even try to start*/

/* Remember, Hope is a good thing... May be the best of things... And No Good thing ever Dies !!!*/

using namespace std;

#define ll long long
#define nada "\n"
#define st string
#define S  second
#define F  first
#define pb push_back
#define MP make_pair
#define isnttriangle(a,b,c)  (a+b<c||a+c<b||b+c<a)
#define todegree(rad) rad*(180.0/pi)
#define rrp(i, a, b)  for(ll i = a; i >= b; i--)
#define repp(i,a,b)   for (int i = int(a); i <=int(b); i++)
#define rep(i, n)     for (int i = 0; i <n; i++)
#define rep1(i,n)     for (int i = 1; i <=n; i++)
#define allr(v)       ((v).rbegin()), ((v).rend())
#define all(v)        ((v).begin()),((v).end())
#define fx(n)         cout<<fixed<<setprecision(n);
#define sz(v)         ((int)(v).size())
#define Test          ll t;cin>>t;while(t--)
#define mod           1000000009LL


const double ME = 2.71828;
const int    N  = 3e5 + 20;
const int   inf = 0x3f3f3f3f;
const double pi = 3.141592653;




void LOSER()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void file()
{
    freopen("records.in", "r", stdin);
    //freopen("text.out", "w", stdout);
}

ll gcd(ll a, ll b)
{
    //Eculidean Algorthim
    return (!b) ? a : gcd(b, a % b);
    //complixty=log(ab);
}

ll lcm(ll a,ll b)
{
    return a / gcd(a, b) * b;
}

ll Fib_recur(ll n)
{
    vector<ll>v(n+5,0);
    //BaseCase
    v[1]=0;
    v[2]=1;
    repp(i,3,n)v[i]=v[i-1]+v[i-2];
    return v[n];
}

bool isprime(int n)
{
    for(int i = 2; i <= sqrt(n); i++)
    {
        if(n%i == 0)
            return false;
    }
    return true;
}

void Solve()
{
 st s,t;
 int cnt=0;
 cin>>s>>t;
  rep(i,sz(s))
  {
     if(s[i]!=t[i])cnt++;
  }
  cout<<cnt;
}






int main()
{
    // fx(7)
    //file();
    LOSER();
    //Test

    Solve();







}


Measured memory_bytes: 3776
open System.Collections.Generic

let p = 1000000007L

let h, w, k = stdin.ReadLine().Split() |> fun [|x1; x2; x3|] -> int x1,int x2,int x3

let addP x y = (x + y) % p
let timeP x y = x * y % p


let memoize fn =
    let hash = new Dictionary<_,_>()
    (fun x ->
        let mightValue = hash.TryGetValue(x)
        if fst mightValue then
            snd mightValue
        else 
            let v = fn x
            hash.Add(x, v)
            v)

/// (h=1,w)時の組み合わせ総数
let c = dict [
    (-1,0L)
    (0,1L)
    (1,1L)
    (2,2L)
    (3,3L)
    (4,5L)
    (5,8L)
    (6,13L)
    (7,21L)
    (8,34L)]

/// (h=1,w,kの時の初期値)
let ansH1 w k =
    match k with
    | 1 -> c.[w-1]
    | 2 -> c.[w-2]
    | _ -> 0L

//メモ化再帰を用いる。なぜこれで内部にmemoizeが働くのか原理は不明
let rec ans =
    let recAns (h,w,k) =
        match h, k with
        | _, 0  -> 0L 
        | _, k when k > w  -> 0L
        | 1, _ -> ansH1 w k
        | _ ->
            ans ((h-1), w, k) |> timeP c.[w-k] |> timeP c.[k-1]
            |> addP ( ans ((h-1), w, (k+1)) |> timeP c.[w-k-1] |> timeP c.[k-1] )
            |> addP ( ans ((h-1), w, (k-1)) |> timeP c.[w-k] |> timeP c.[k-2] )
    memoize recAns

let memAns = memoize ans
memAns (h, w, k) 
|> stdout.WriteLine


Measured memory_bytes: 14304
#include <iostream>

using namespace std;

int main(int argc, char** argv) {
    long N, A, B;
    cin >> N >> A >> B;
    long complete = N / (A + B);
    long left = N % (A+B);

    long res = complete * A + (left > A ? A : left);
    cout << res << endl;

    return 0;
}

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

using LL = long long;
using LD = long double;
 
LL mod = 10e9+7;

LL g[200000] = {0};
LL p = 0;

void recurse (LL pos, vector<LL> d, LL nd) {
	if (pos == nd) {
		LL val = 0;
		LL t = 1;
		for (LL i = nd-1; i >= 0; --i) {
			val += t*d[i];
			t *= 10; 
		}
		if (p >= 200000) {
			return;
		}
		else {
			g[p] = val;
			p++;
		}
		return;
	}
	if (d[pos-1] >= 1) {
		d[pos] = d[pos-1]-1;
		recurse(pos+1, d, nd);
	}
	d[pos] = d[pos-1];
	recurse (pos+1, d, nd);
	if (d[pos-1] <= 8) {
		d[pos] = d[pos-1]+1;
		recurse(pos+1, d, nd);
	}
}

void build (LL nd) {
	vector<LL> d(nd, 0);
	for (LL j = 1; j <= 9; ++j) {
		d[0] = j;
		recurse(1, d, nd);
		if (p >= 200000) {
			break;
		}
	}
}

int main()
{
	LL k;
	cin >> k;

	for (LL i = 1; i <= 10; ++i) {
		build (i);
		if (p >= 200000) {
			break;
		}
	}

	cout << g[k-1] << "\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>

#define ll long long
using namespace std;
ll dp[100009]{};
ll MAX = 1000000;
int main()
{

    ll N; cin>>N;
    ll height[N+1]{};
    for(ll i = 1; i<= N ; i++)cin>>height[i];
    memset(dp ,MAX, sizeof(dp[0])*100009);
    dp[0]=0;
    dp[1] = 0;

    for(int i = 2 ;i<=N ;i++)
    {
    if(i-1>=1)
    {
        dp[i] = min(dp[i],dp[i-1]+abs(height[i]-height[i-1]));
    }
    if(i-2>=1)
    {
        dp[i] = min(dp[i],dp[i-2]+abs(height[i]-height[i-2]));
    }
    }

    cout<<dp[N]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
long double b[1000];
long double ma = 1;
int main(){
	int a;

	cin >> a;
	for(int i = 0;i < a;i++){
		cin >> b[i];
	}
	sort(&b[0],&b[a]);
	for(int c = 0;c < a;c++){
		for(int d = 0;d < a;d++){
			if(c != d && (b[c] - b[d]) > 0){
				int g = (a-1);
				int h = (a-2);
			
			if(c != d && (c - d) > 0){
				int g = (a-1);
				int h = (a-2);
		
			if(g == c||g == d){
					g--;
					h--;
				}
			if(g == c||g == d){
					g--;
					h--;
				}
				if(h == c||h ==d) h--;

				double j = ((b[g]+b[h])/(b[c]-b[d]));
				if(ma < j){
					ma = j;
				}
			}
			}
	}
	}
	cout << fixed<< setprecision(5)<< ma<<endl;
	fflush(stdin);
	getchar();

		return 0;

}

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

#define MOD 1000000007
#define MAX 100005
#define ll long long
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define ss(x) scanf("%s",x)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vpii vector<pii >
#define vll vector<ll>
#define clr(x) memset(x,0,sizeof(x))

#define FILEIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);

using namespace std;

int a[MAX];
int ta[MAX];

int main(){
	int n;sd(n);
	int x;sd(x);
	for(int i=1;i<=n;i++){
		sd(a[i]);
		ta[i]=a[i];
	}
	ll ans1=0;
	for(int i=2;i<=n;i++){
		if(a[i]+a[i-1]>x){
			int diff=a[i]+a[i-1]-x;
			if(a[i]>=diff){
				ans1+=diff;
				a[i]-=diff;
			}else{
				a[i]=0;
				ans1+=diff;
			}
		}
	}
	ll ans2=0;
	for(int i=n-1;i>0;i--){
		if(ta[i]+ta[i+1]>x){
			int diff=ta[i]+ta[i+1]-x;
			ans2+=diff;
			if(ta[i]>=diff){
				ta[i]-=diff;
			}else{
				ta[i]=0;
			}
		}
	}
	plld(min(ans1,ans2));
	
}

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

#include <math.h>
#include <stdlib.h>


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

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

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        int l, r; cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;

    return 0;
}


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

int n, m;
queue<int> r;

void riffle()
{
    queue<int> p, q;
    for (int i = 0; i < 2 * n; i++)
    {
        int a = r.front();
        r.pop();
        if (i < n)
            p.push(a);
        else
            q.push(a);
    }
    for (int i = 0; i < 2 * n; i++)
    {
        if (i % 2 == 0)
        {
            int a = p.front();
            p.pop();
            r.push(a);
        }
        else
        {
            int a = q.front();
            q.pop();
            r.push(a);
        }
    }
}

void cut(int k)
{
    for (int i = 0; i < k; i++)
    {
        int p = r.front();
        r.pop();
        r.push(p);
    }
}

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= 2 * n; i++)
    {
        r.push(i);
    }
    for (int i = 0; i < m; i++)
    {
        int j = 0;
        cin >> j;
        if (j == 0)
            riffle();
        else
            cut(j);
    }
    for (int i = 0; i < 2 * n; i++)
    {
        int j = r.front();
        r.pop();
        cout << j << endl;
    }
}


Measured memory_bytes: 3156
N,X=list(map(int,input().strip().split(' ')))
L=list(map(int,input().strip().split(' ')))
index=0
Bounce=[0]
for i in range(len(L)):
    
        
    Bounce+=[L[i]+Bounce[-1]]
    
count=0
for x in Bounce:
    if x<=X:
        count+=1
print(count)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
    int w,h,n,i,j,a[100],x[100],y[100],xleft=0,xright,ybelow=0,yupper;
    scanf("%d %d %d",&w,&h,&n);
    xright=w;
    yupper=h;
    i=0;
    while(xleft<xright&&ybelow<yupper&&n>0){
        scanf("%d %d %d",&x[i],&y[i],&a[i]);
        if(a[i]==1){
            if(xleft<x[i])
            xleft=x[i];
        }else if(a[i]==2){
            if(xright>x[i])
            xright=x[i];
        }else if(a[i]==3){
            //a[i]==3の時は下を塗りつぶす
            if(y[i]>ybelow)
            ybelow=y[i];
        }else if(a[i]==4){
            if(y[i]<yupper)
            yupper=y[i];
        }
        n--;
        i++;
    }
    int area;
    //printf("%d %d %d %d\n",xleft,xright,ybelow,yupper);
    if(xleft>=xright||ybelow>=yupper){printf("0\n");
        return 0;
    }
    area=(xright-xleft)*(yupper-ybelow);
    printf("%d\n",area);
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const ll mod = 1e9+7;
const ll INF = 1e9;
const int MAXN = 101;

int main()
{
    bool flag=false;
    int n;
    int a[MAXN];
    cin>>n;
    rep(i,n)
    {
        int a;
        cin>>a;
        if(a%2==0)
        {
            if(a%3!=0 && a%5!=0)
            {
                flag=true;
            }
        }
    }
    if(flag)
    {
        cout<<"DENIED";
    }
    else
    {
        cout<<"APPROVED";
    }
    
}

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

int main(){
	int k,s,cnt=0;
	scanf("%d %d",&k,&s);
	for(int i=0;i<=k;++i){
		for(int j=0;j<=k;++j){
			if(s-j-i>=0 && s-j-i<=k)
				++cnt;
		}
	}
	printf("%d",cnt);
}


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

int num,a,b,c;
int out,result;
int base[5] = {0};
char str0[132],str1[] = "OUT",str2[] = "HIT",str3[] = "HOMERUN";

int main()
{
    scanf("%d",&num);
    for(int i = 1; i <= num; i++)
    {
        while(1)
        {
            scanf("%s",str0);
            a = strcmp(str0,str1);
            b = strcmp(str0,str2);
            c = strcmp(str0,str3);
            if(a == 0)
            {
                out++;
                if(out == 3)break;
            }
            if(b == 0)
            {
                if(base[2] == 1)
                {
                    result++;
                    base[2] = 0;
                }
                if(base[1] == 1)
                {
                    base[1] = 0;
                    base[2] = 1;
                }
                if(base[0] == 1)
                {
                    base[1] = 1;
                    base[0] = 0;
                }
                if(base[0] == 0)
                {
                    base[0] = 1;
                }
                //printf("(%d,%d,%d)\n",base[0],base[1],base[2]);
            }
            if(c == 0)
            {
                result++;
                for(int j = 0; j < 3; j++)
                {
                    if(base[j] == 1)
                    {
                        result++;
                        base[j] = 0;
                    }

                }
            }
            //printf("[%d]\n",result);
        }
        printf("%d\n",result);
        out = 0;result = 0;
        for(int j = 0; j < 3; j++)
        {
            base[j] = 0;
        }
    }
}

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

int main() {

	int N,K,sum=0;
	cin>>N>>K;
  vector<int>l(N);
  
  for(int i=0;i<N;i++){
    cin>>l.at(i);}
  sort(l.begin(),l.end());
  for(int i=N-1; i>N-K-1; i--){
     sum+=l.at(i);}
	cout<<sum<<endl;
}



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

#define mod 1e9 + 7
#define INF (int) 1e9 + 5

#define add emplace
#define pb push_back
#define eb emplace_back
#define all(x) begin(x), end(x)
#define len(x) ((int)(x).size())
#define exist(a, x) (a.find(x) != end(a))
#define log(x) cout << (x) << endl;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define loop(i,a,b) for(int i=(int)(a);i<(int)(b);++i)

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int,int>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vstr = vector<string>;


char st[1001][1001]={};
long dp[1001][1001]={};
int main() {
	int h, w;
	cin>>h>>w;

	rep (i, h)
		rep (j, w) cin >> st[i][j];

	dp[0][0] = 1;
	for (int r=0; r<h; ++r) {
		for (int c=0; c<w; ++c) {
			for (int rc: {r, r+1}) {
				int cl = c + (rc == r);

				if (rc < h && cl < w && st[rc][cl]=='.') {
					dp[rc][cl] += dp[r][c];

					if (dp[rc][cl] >= mod)
						dp[rc][cl] -= mod;
				}
			}
		}
	}

	log(dp[h-1][w-1])
	return 0;
}


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

int a[52];
int n,m,sum;

int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=n;i>=n-m+1;i--)
        sum+=a[i];
    cout<<sum;
}

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

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] p = new int[N];
		for(int i=0;i<N;i++) {
			p[i] = sc.nextInt();
		}

		int[] sorted_p = p.clone();
		Arrays.sort(p);

		int diff = 0;
		for(int i=0;i<N;i++) {
			if(p[i] != sorted_p[i]) {
				diff++;
			}

			if(diff > 2) {
				System.out.println("NO");
				return;
			}
		}
		System.out.println("YES");
	}

}


Measured memory_bytes: 23892
//
// Created by yamunaku on 2019/12/22.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int a,b;
    cin >> a >> b;
    cout << 6-a-b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int		main(void)
{
	int		i;
	int		num[2];
	int		result;

	result = 0;
	i = 0;
	scanf("%d %d",&num[0],&num[1]);
	while (i < 2)
	{
		if (num[0] > num[1])
		{
			result = result + num[0];
			num[0]--;
		}
		else
		{
			result = result + num[1];
			num[1]--;
		}
		i++;
	}
	printf("%d",result);
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ull unsigned long long
#define ld long double

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
template <class T>
using VVV = V<V<V<T>>>;

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define rep1(i, n) rep1(i, 1, n + 1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()  //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
    //    cout << std::setfill('0') << std::setw(2);

    long long N;
    std::cin >> N;
    V<pii> r(N), b(N);
    for (int i = 0; i < N; i++) {
        std::cin >> r[i].second;
        std::cin >> r[i].first;
    }
    for (int i = 0; i < N; i++) {
        std::cin >> b[i].first;
        std::cin >> b[i].second;
    }
    sort(all(r), greater<pii>());
    sort(all(b));

    int ans = 0;
    V<bool> f(N, false);
    rep(i, N) {
        rep(j, N) {
            if (r[j].second < b[i].first && r[j].first < b[i].second) {
                if (f[j]) continue;
                ans++;
                f[j] = true;
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


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

const int mod=1e9+7;
long long mpow(long long x, int y)
{
    long long res=1;
    while(y)
    {
        if(y&1) (res*=x)%=mod;
        x*=x;
        x%=mod;
        y/=2;
    }
    return res;
}

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

    int k; string s; cin>>k>>s;
    int n=s.size();

    const int siz=1<<21;
    long long fa[siz]={1},ifa[siz];
    for(int i=1; i<siz; i++) fa[i]=fa[i-1]*i%mod;
    ifa[siz-1]=mpow(fa[siz-1],mod-2);
    for(int i=siz-1; i>0; i--)
    {
        ifa[i-1]=ifa[i]*i%mod;
    }

    long long ans=0;
    for(int i=0; i<=k; i++)
    {
        long long bi=fa[k-i+n-1]*ifa[k-i]%mod*ifa[n-1]%mod;
        ans+=mpow(26,i)*mpow(25,k-i)%mod*bi%mod;
        ans%=mod;
    }
    cout << ans << "\n";
}

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

#include <bits/stdc++.h>
#include<chrono>
#define ll long long
using namespace std;
vector<ll>bit;
ll MOD = 1e9 + 7;
ll A, B, H, N, M, L, K, W, X, Y, Z;
ll ans = 0;

void add(ll a, ll w) {
	for (int x = a; x < 2 * N; x += x & -x) {
		bit[x] += w;
	}
}

int sum(ll a) {
	int res = 0;
	for (int x = a; x > 0; x -= x & -x)res += bit[x];
	return res;
}

bool isOK(int mid, vector<ll>a) {
	vector<ll>b(a.size() + 1);
	vector<ll>csum(a.size() + 1);
	csum[0] = 0;
	for (int i = 1; i < N + 1; i++) {
		if (a[i] >= mid)b[i] = 1;
		else b[i] = -1;
		csum[i] = csum[i - 1] + b[i];
	}
	ll invN = 0;
	add(csum[0] + N, 1);
	for (int i = 1; i < N + 1; i++) {
		invN += sum(csum[i] + N);
		add(csum[i] + N, 1);
	}
	return invN >= N * (N + 1) / 4;
}

int main() {
	cin >> N;
	vector<ll>a(N + 1), b(N + 1), csum(N + 2), copy(3 * N, 0);
	ll r = 0;
	ll l = 0;
	for (int i = 1; i < N + 1; i++) {
		cin >> a[i];
		r = max(r, a[i]);
	}
	r++;
	while (r - l > 1) {
		bit = copy;
		ll mid = (r + l) / 2;
		if (isOK(mid, a))l = mid;
		else r = mid;
	}
	cout << l << endl;
}

Measured memory_bytes: 9680