akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

import sys
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd

def input(): return sys.stdin.readline().strip()
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

class SegTree:
    """
    以下のクエリを処理する
    1.update:  i番目の値をxに更新する
    2.get_val: 区間[l, r)の値を得る
    """
 
    def __init__(self, n, func, init):
        """
        :param n: 要素数
        :param func: 値の操作に使う関数(min, max, addなど)
        :param init: 要素の初期値
        """
        n += 1
        self.n = n
        self.func = func
        self.init = init
        # nより大きい2の冪数
        n2 = 1
        while n2 < n:
            n2 <<= 1
        self.n2 = n2
        self.tree = [self.init] * (n2 << 1)
 
    def update(self, i, x):
        """
        i番目の値をxに更新
        :param i: index(0-indexed)
        :param x: update value
        """
        i += self.n2
        self.tree[i] = x
        while i > 1:
            self.tree[i >> 1] = x = self.func(x, self.tree[i ^ 1])
            i >>= 1
 
    def get_val(self, a, b):
        """
        [a, b)の値を得る
        :param a: index(0-indexed)
        :param b: index(0-indexed)
        """
        return self._get_val(a, b, 1, 0, self.n2)
 
    def _get_val(self, a, b, k, l, r):
        """
        [a, b)の値を得る内部関数
        :param k: 現在調べている区間のtree内index
        :param l, r: kが表す区間の左右端index [l, r)
        :return: kが表す区間と[a, b)の共通区間内での最小値。共通区間を持たない場合は初期値
        """
        # 範囲外なら初期値
        if r <= a or b <= l:
            return self.init
        # [a,b)が完全に[l,r)を包含するならtree[k]の値を採用
        if a <= l and r <= b:
            return self.tree[k]
        # 一部だけ範囲内なら2つに分けて再帰的に調査
        m = (l + r) // 2
        return self.func(
            self._get_val(a, b, k << 1, l, m),
            self._get_val(a, b, (k << 1) + 1, m, r)
        )

N=INT()
A=[0]+LIST()+[0]

st=SegTree(N+2, gcd, 0)
for i in range(N+2):
    st.update(i, A[i])

ans=0
for i in range(1, N+1):
    ans=max(ans, gcd(st.get_val(0, i), st.get_val(i+1, N+2)))
print(ans)


Measured memory_bytes: 117592
# -*- coding: utf-8 -*-

"""
stackの応用(水たまりの面積)
"""

from collections import deque

S = list(input())

# 総合面積
ans = 0
# 総合面積用スタック(直近の\の位置)
stack1 = deque()
# 個別用スタック(その水たまりを開始する\の位置, その時点での面積)
stack2 = deque()
for i in range(len(S)):
    if S[i] == '\\':
        stack1.append(i)
    # 一番最近いれた\を取り出せば、今回の/と対になる(同じ高さ)
    elif S[i] == '/' and stack1:
        # 両者の距離がその高さでの面積になる
        # (\/が三角形な分-1なのが半開区間だからちょうど合う)
        j = stack1.pop()
        ans += i - j

        # 各水たまりのマージ作業
        # stack2から、今回の合併候補を抽出
        # (条件：水たまりの開始位置が今回対になってる\より右側にある)
        pond = i - j
        while stack2 and stack2[-1][0] >= j:
            pond += stack2.pop()[1]
        # マージした水たまりの情報を詰める
        stack2.append([j, pond])
print(ans)
# リスト内包とアンパックできれいにまとまった
print(len(stack2), *[pond for j, pond in stack2])



Measured memory_bytes: 6948
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

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

const ll mod = 1e9 + 7;

vector<ll> dx = {1, -1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

vector<string> g;

long long mpow(const long long &v, const long long &n, const long long &mod)
{
    long long ret = 1;
    long long num = n;
    long long now = v;
    
    while (num > 0)
    {
        if (num & 1)
        {
            ret = ret * now % mod;
        }
        now = now * now % mod;
        num = num >> 1;
    }
    
    return ret;
}


int main() {
    
    
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    ll n, k;
    cin >> n >> k;
    
    
    vector<ll> r(k + 1, -1);
    
    for (ll i = k; i >= 1; --i)
    {
        ll count = mpow(k / i, n, mod);
        for (ll j = 2 * i; j <= k; j += i)
        {
            count -= r[j];
            if (count < 0)
            {
                count += mod;
            }
        }
        r[i] = count;
    }
    
    ll ret = 0;
    for (int i = 1; i <= k; ++i)
    {
        ret += i * r[i];
        ret %= mod;
    }
    
    cout << ret << endl;
    

    return 0;
}



Measured memory_bytes: 4004
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e18;
const ll MOD = 1000000007;  // 1e9 + 7

ll N, K;
vector<ll> A;
vector<ll> F;

bool condition(ll limit) {
  // all A[i] * B[i] must be equal or lower than limit.
  ll summed = 0; // The necessary decreasing count.
  rep(i, N) {
    ll cnt = limit / F[i];
    // F[i] * cnt <= limit.
    if (cnt <= A[i]) { // A[i] is larger than cnt
      summed += (A[i] - cnt);
    }
  }
  return (summed <= K);
}

int main(int argc, char** argv) {
  cin >> N >> K;
  A.resize(N);
  F.resize(N);
  rep(i, N) {
    cin >> A[i];
  }
  sort(all(A)); // increasing order
  rep(i, N) {
    cin >> F[i];
  }
  sort(all(F));
  reverse(all(F)); // decreasing order

  // cout << "A: ";
  // rep(i, N) {
  //   cout << A[i] << " ";
  // }
  // cout << endl;
  // cout << "F: ";
  // rep(i, N) {
  //   cout << F[i] << " ";
  // }
  // cout << endl;
  // ll summed = 0;
  // rep(i, N) {
  //   summed += A[i] * F[i];
  // }

  // We use binary search.
  ll l = -1;
  ll r = INF;
  while (r - l > 1) {
    ll mid = (l + r)/2;
    if (condition(mid)) { // ok
      r = mid;
    } else { // ng
      l = mid;
    }
  }

  cout << r << endl;
}


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

int main()
{
	string str;
	while (getline(cin, str))
	{
		for (int i = 0; i < str.size(); i++)
		{
			if ('a' <= str[i] && str[i] <= 'z') str[i] -= 'a' - 'A';
		}
		cout << str << endl;
	}
	return 0;
}


Measured memory_bytes: 3000
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#define mod 1000000007
#define ll long long
using namespace std;

ll qpow(ll x,ll t){
	ll ans=1;
	while(t){
		if(t&1)ans=(ans*x)%mod;
		x=(x*x)%mod;
		t>>=1;
	}
	return ans%mod;
}

ll n,c,a[410],b[410],dp[2][401][401];

int main(){
	scanf("%lld %lld",&n,&c);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%lld",&b[i]);

	for(int j=0;j<=c;j++)
		for(int k=a[1];k<=b[1];k++){
			dp[1%2][j][k]=qpow(k,j)%mod;
			dp[1%2][j][0]+=dp[1][j][k];
			dp[1%2][j][0]%=mod;
		}
	
	for(int i=2;i<=n;i++){
		
		memset(dp[i%2],0,sizeof(dp[i%2]));
		
		for(int k=a[i];k<=b[i];k++)
			dp[(i)%2][0][k]=dp[(i-1)%2][0][0];
		
		for(int k=a[i];k<=b[i];k++){
			for(int j=1;j<=c;j++){
				dp[(i)%2][j][k]+=(k*dp[(i)%2][j-1][k])%mod;
				dp[(i)%2][j][k]%=mod;
				
				dp[(i)%2][j][k]+=dp[(i-1)%2][j][0];
				dp[(i)%2][j][k]%=mod;
			}
		}
		for(int j=0;j<=c;j++)
			for(int k=a[i];k<=b[i];k++)		
				dp[(i)%2][j][0]=(dp[(i)%2][j][k]+dp[(i)%2][j][0])%mod;
	}
	
	cout<<dp[n%2][c][0]%mod;
}

Measured memory_bytes: 2816
n = int(input())
blue_cards = [input() for i in range(n)]
m = int(input())
red_cards = [input() for i in range(m)]

max_score = 0
for term in blue_cards:
    score = 0
    for card in blue_cards:
        if term == card:
            score +=1
    for card in red_cards:
        if term == card:
            score -=1
    if(max_score < score):
        max_score = score
if max_score < 0:
    max_score = 0

print(max_score)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    ll n,k; cin >> n >> k;
    vector<ll> a(n); rep(i,n) cin >> a[i];

    vector<ll> s(n+1,0); // sum of a[0,n)
    s[0] = 0;
    rep(i,n) s[i+1] = s[i] + a[i];

    vector<ll> ps(n+1,0);
    ps[0] = 0;
    rep(i,n) ps[i+1] = ps[i] + ((a[i]>0) ? a[i] : 0);

    /* cout << s << endl; */
    /* cout << ps << endl; */

    ll ans = 0;
    for(int i=0;i+k<=n;i++){
        ll x = ps[i];
        ll y = max(0LL,s[i+k] - s[i]);
        ll z = ps[n] - ps[i+k];
        ll w = x + y + z;
        /* cout << x << " " << y << " " << z << " " << w << endl; */
        ans = max(ans,w);
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define P 1000000007

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
	
	int n, k, a[1000];
	cin >> n >> k;
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	
	ll sum = 0;
	for(int i = 0; i < k; i++) sum += a[i];
	
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define endl '\n'
#include <math.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int S,W;
    cin>>S;
    cin>>W;
    if(W>=S) cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
    return 0;
}




Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(a[i] != i + 1){
            cnt++;
        }
    }
    if(cnt == 0 || cnt == 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void){
    long long int n, d, i, x, y,count=0; 
scanf("%lld %lld", &n, &d);
for(int i = 0; i<n;i++){
    scanf("%lld %lld", &x, &y);
    if(sqrt(x*x+y*y)<=d) count++;
    }
printf("%d\n", count);
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,w;
    cin >> n >> w;
    int v = 1e5;
    vector<long long> dp(v+1, INT_MAX);
    dp[0] = 0;
    int weight, value;
    for (int i = 0; i < n; i++)
    {
        cin>>weight>>value;
        for(int j = v-value; j>=0; j--){
            dp[j+value] = min(dp[j+value], dp[j]+weight);
        }
    }

    for(int i=v;i>=0;i--){
        if(dp[i] <= w){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}

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

int main(){

	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m;
    cin >> n >> m;
    int sum = 0;
    vector<int> v;
    for(int i=0;i<n;++i){
    	int x;
    	cin >>x;
    	sum+=x;
    	v.push_back(x); 
    }

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

    int val = v[m-1];

    if(sum <= (4*m*val)){
    	cout << "Yes\n";
    }
    else{
    	cout << "No\n";
    }

    

	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
		Scanner scan = new Scanner(System.in);
		double a = scan.nextDouble();
		double b = scan.nextDouble();
		double c = scan.nextDouble();
		double cRadian = Math.toRadians(c);
		double temp = 0.0;
		
		//??¢??? ??? ??????a * ???b sin(ab???????§????C)/2?????????C???????????¢????§???????????????????????????¨???
		temp = a*b * Math.sin(cRadian) /2 ;
		System.out.println(temp);
		
		//??¨ ??? a + b +???a?????? + b?????? - 2*a*b*cos(C)
		temp = (a+b) + Math.sqrt(a*a + b*b - 2*a*b*Math.cos(cRadian));
		System.out.println(temp);
		
		//?????? ??? b*sin(C)
		temp = b * Math.sin(cRadian);
		System.out.println(temp);
	}
}

Measured memory_bytes: 27920
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(string n){
    rep(i, n.length()){
        if(n.at(i) == '1')
            n.at(i) = '9';
        else if(n.at(i) == '9')
            n.at(i) = '1';
    }
    cout << n << endl;
}

int main(){
    string n;
    cin >> n;
    solve(n);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define forn(i,a,b) for(long long i=a;i<=b;i++)
#define fork(i,a,b,k) for(long long i=a;i<=b;i+=k)
using namespace std;
typedef long long ll;
ll n,a[3005],dp[3005][3005];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int l=n;l>=1;l--){
		for(int r=l;r<=n;r++){
			if(l==r){
				dp[l][r]=a[l];
			}
			else {
				dp[l][r]=max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);
			}
		}
	}
	cout<<dp[1][n];
}


Measured memory_bytes: 70016
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;

int n;
double r;
double theta;
int x[20];
int y[20];
double dp[20][20];
double buf[20][20];
bool check_angle_buf[20][20][20];
double dist_buf[20][20];

double dist(int i, int j) {
    int dx1 = x[j] - x[i];
    int dy1 = y[j] - y[i];
    return sqrt(dx1 * dx1 + dy1 * dy1);
}

bool check_angle(int i, int j, int k) {
    int dx1 = x[j] - x[i];
    int dy1 = y[j] - y[i];
    int dx2 = x[k] - x[j];
    int dy2 = y[k] - y[j];
    double arg = acos((dx1 * dx2 + dy1 * dy2) / (dist(i, j) * dist(j, k)));
    return arg <= theta;
}


void dumpdp() {
    for (int i = -1; i< n; ++i) {
        for (int j = -1; j < n; ++j) {
            if (i == -1) {
                if (j == -1) continue;
                cout << setw(10) << j;
                continue;
            }
            if (j == -1) {
                cout << i;
                continue;
            }
            if (dp[i][j] > 10000) {
                    cout << "        --";
                } else {
                    cout << setw(10) << setprecision(2) << fixed << dp[i][j];
                }
            //cout << "(" <<setw(4) << setprecision(2) << fixed << dist_buf[i][j];
        }
        cout << endl;
    }
    cout << endl;
}

int main () {
    cin >> n;
    cin >> r >> theta;
    theta = theta * M_PI / 180;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }

    int cmax = (int)r + 1;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            dp[i][j] = 10000000;
            dist_buf[i][j] = dist(i, j);
            for (int k = 0; k < n; ++k) {
                check_angle_buf[i][j][k] = check_angle(i, j, k);
                //cout << i << j << k << " " << (check_angle_buf[i][j][k] ? "OK": "NG") << endl;
            }
        }
    }
    double mind = r + 1;
    for (int i = 1; i < n; ++i) {
        dp[0][i] = dist(0, i);
        mind = min(mind, dp[0][i]);
        for (int j = 0; j < n; ++j) {
            dp[i][j] = 100000000;
            buf[0][j] = 100000000;
            buf[i][j] = 100000000;
        }
    }

    if (mind > r) {
        cout << 0 << endl;
        return 0;
    }
    dp[0][0] = 1000000;

    int c;
    for (c = 1; c <= cmax; ++c) {
        //dumpdp();
        for (int k = 0; k < n; ++k) {
            for (int j = 0; j < n; ++j) {
                if (j == k) continue;
                double d = dist_buf[j][k];
                double tmp = 1000000000;
                for (int i  = 0; i < n; ++i) {
                    if (j == i || k == i) continue;
                    if (!check_angle_buf[i][j][k]) continue;
                    tmp = min(tmp, d + dp[i][j]);
                }
                buf[j][k] = tmp;
            }
        }
        double minr = r + 1;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                dp[i][j] = buf[i][j];
                minr = min(minr, dp[i][j]);
                buf[i][j] = 10000000;
            }
        }
        if (minr > r) break;
    }
    cout << c << endl;
}


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

inline ll f(ll x, ll A, ll B)
{
  return floor((A * x) / B) - A * floor(x / B);
}

int main(void)
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  ll A, B, N; cin >> A >> B >> N;
  ll arg = ((B - 1) > N)? N: B - 1;
  ll ans = f(arg, A, B);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3584
N,Q=map(int,input().split())
S=input()
l=0
r=0
l=[0]*Q
r=[0]*Q
s=[]
s.append(0)

for i in range(1,N):
    if(S[i-1]=='A' and S[i]=='C'):

        s.append(s[i-1]+1)

    else:
        s.append(s[i-1])

for i in range(Q):

    l[i],r[i]=map(int,input().split())
for i in range(Q):
    print(s[r[i]-1]-s[l[i]-1])



Measured memory_bytes: 54416
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n;
pair<int,int> ab[110];
pair<int,int> cd[110];

bool abc[110]={};

int main(){
	cin>>n;
	REP(i,n){
		int t,s;
		cin>>t>>s;
		ab[i]=make_pair(t,s);
	}
	
	REP(i,n){
		int t,s;
		cin>>t>>s;
		cd[i]=make_pair(t,s);
	}
	
	sort(ab,ab+n);
	sort(cd,cd+n);
	
	int ans=0;
	
	REP(i,n){
		int t=1000;
		for(int j=0;ab[j].first<cd[i].first&&j<n;j++){
			if(ab[j].second<cd[i].second&&(!abc[j])){
				if(t==1000){
					t=j;
				}else if(ab[j].second>ab[t].second){
					t=j;
				}
			}
		}
		if(t!=1000){
			ans++;
			abc[t]=1;
			//cout<<i<<" "<<t<<endl;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;

string s;
int dp[1001][1000];

int dfs(int canPar,int round){
    if(round==s.size()-1){
        if(s[round]=='p') return 0;
        else if(canPar>0) return 1;
        else return 0;
    }
    int res = 0;
    if(s[round]=='p'){
        if(canPar==0) {
            if(dp[1][round+1]==-1){
                dp[1][round+1] = dfs(1,round+1);
            }
            res = dp[1][round+1] -1;
        }
        else {
            if(dp[canPar][round+1]==-1){
                dp[canPar][round+1] = dfs(canPar,round+1);
            }
            int g = dp[canPar][round+1] - 1;
            if(dp[canPar-1][round+1]==-1){
                dp[canPar-1][round+1] = dfs(canPar-1,round+1);
            }
            res = max(dp[canPar-1][round+1],g);
        }
    }
    else{
        if(canPar==0) {
            if(dp[1][round+1]==-1){
                dp[1][round+1] = dfs(1,round+1);
            }
            res = dp[1][round+1];
        }
        else{
            if(dp[canPar][round+1]==-1){
                dp[canPar][round+1] = dfs(canPar,round+1);
            }
            if(dp[canPar-1][round+1]==-1){
                dp[canPar-1][round+1] = dfs(canPar-1,round+1);
            }
            int p = dp[canPar-1][round+1] + 1;
            res = max(p,dp[canPar][round+1]);
        }
    }
    return res;
}

void solve(){
    fill(dp[0],dp[1000],-1);
    if(s.size()==1){
        cout << 0 << endl;
        return;
    }
    cout << dfs(1,1) << endl;
    return;
}

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

Measured memory_bytes: 9088
n,t=map(int,input().split())
a=[int(i) for i in input().split()]
mn,mx=10**10,-1
d={}
for i in range(n-1):
    mn=min(a[i],mn)
    mx=max(a[i+1]-mn,mx)
    d[a[i]]=i
d[a[n-1]]=n-1
ans=0
for i in range(1,n):
    if a[i]-mx in d and d[a[i]-mx]<i:
        ans+=1
print(ans)

Measured memory_bytes: 20668
/*input
10
oxooxoxoox
*/

#include <iostream>
#include <vector>

using namespace std;

bool check(int N, int first, int second, vector<int> &array, vector<int> &animals){

	// first is sheep && second sheep
	animals[0] = first;
	animals[1] = second;

	for(int i=2;i<N;i++){
		if(array[i-1] == 0 && animals[i-1] == 0){
			animals[i] = animals[i-2];
		}else if(array[i-1] == 0 && animals[i-1] == 1){
			animals[i] = 1 - animals[i-2];
		}else if(array[i-1] == 1 && animals[i-1] == 0){
			animals[i] = 1 - animals[i-2];
		}else{
			animals[i] = animals[i-2];
		}
	}

	bool result1;
	if(animals[N-1] == 0){ // last is sheep
		if(array[N-1] == 0){
			if(animals[N-2] == animals[0]) result1 = true;
			else result1 = false;
		}else{
			if(animals[N-2] == animals[0]) result1 = false;
			else result1 = true;
		}
	}else{ // last is wolf
		if(array[N-1] == 0){
			if(animals[N-2] != animals[0]) result1 = true;
			else result1 = false;
		}else{
			if(animals[N-2] != animals[0]) result1 = false;
			else result1 = true;
		}
	}

	bool result2;
	if(animals[0] == 0){ // first is sheep
		if(array[0] == 0){
			if(animals[N-1] == animals[1]) result2 = true;
			else result2 = false;
		}else{
			if(animals[N-1] == animals[1]) result2 = false;
			else result2 = true;
		}
	}else{ // first is wolf
		if(array[0] == 0){
			if(animals[N-1] != animals[1]) result2 = true;
			else result2 = false;
		}else{
			if(animals[N-1] != animals[1]) result2 = false;
			else result2 = true;
		}
	}

	return (result1 && result2);
}

void display(vector<int>&animals){
	for(int a:animals){
		if(a == 0){
			cout << "S";
		}else{
			cout << "W";
		}
	}
	cout << endl;
}

int main()
{

	int N;
	string s;

	cin >> N;
	cin >> s;

	vector<int> array(N);
	vector<int> animals(N);
	for(int i=0;i<N;i++){
		if(s[i] == 'o') array[i] = 0;
		else array[i] = 1;
		// cout << array[i] << " ";
	}
	// cout << endl;

	bool result;

	result = check(N, 0, 0, array, animals);
	if(result){
		display(animals);
		return 0;
	}

	result = check(N, 0, 1, array, animals);
	if(result){
		display(animals);
		return 0;
	}

	result = check(N, 1, 0, array, animals);
	if(result){
		display(animals);
		return 0;
	}

	result = check(N, 1, 1, array, animals);
	if(result){
		display(animals);
		return 0;
	}

	cout << (-1) << endl;

	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int n,k;cin >>n >> k;
	vector<int> a(n);
	rep(i,n)cin >> a[i];
	sort(a.begin(),a.end());
	int ret =0 ;
	rep(i,min(n,k)){
		ret += a[i];
	}
	cout << ret<< endl;
	return 0;
}

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N = 100005;
int deg[N];
set<int> adj[N];
int num[N];

int main(){
    int n; sd(n);
    set<pii> st;
    for(int i = 1; i < n; i++){
        int u, v; sd(u); sd(v); deg[u]++; deg[v]++;
        adj[u].insert(v);
        adj[v].insert(u);
    }
    for(int i = 0; i < n; i++) st.insert({deg[i], i});
    while(!st.empty()){
        auto it = *st.begin();
        int v = it.S;
        if(deg[v] == 1){
            int p = *adj[v].begin();
            if(deg[p] == 1){
                printf("1\n");
                return 0;
            }
            if(deg[p] == 2){
                adj[v].erase(p);
                adj[p].erase(v);
                st.erase({deg[p], p});
                deg[p]--;
                st.insert({deg[p], p});
                deg[v]--;
            } else{
                num[p]++;
            }
        } else{
            break;
        }
        st.erase(it);
    }
    int ans = 0;
    for(int i = 0; i < n; i++) ans += max(0, num[i] - 1);
    printf("%d\n", ans);
}

Measured memory_bytes: 19712
#include<bits/stdc++.h>
using namespace std;
int cnt[102];

int main()
{
    int n,m,d,a;
    cin>>n>>m;
    while(m--)
    {
        scanf("%d",&d);
        while(d--)
        {
            scanf("%d",&a);
            cnt[a]++;
        }
    }
    d=0;
    for(a=1; a<=n; a++)
        if(cnt[a]==0)d++;
    cout<<d<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int x;
  cin >> x;
  if (x >= 30) cout << "Yes\n"; else cout << "No\n";
  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k; cin >> n >> k;
	vector<int> h(n);
	for(int &m : h) cin >> m;
	vector<int> dp(n,INT_MAX);
	dp[0] = 0;                                                                                           
	for(int i = 1; i < n; i++) for(int j = max(0,i-k); j < i; j++){
        	dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
	}
	cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
    int H=0, W=0, h=0, w=0;
    cin >> H >> W >> h >> w;
    cout << (H-h)*(W-w) << endl;
}

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

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

int main(void){
    ll n;
    vector<ll> vec,ans;
    cin >> n;
    for(int i=0;i<n;i++){
        int t;
        cin >> t;
        vec.push_back(t);
    }
    reverse(vec.begin(), vec.end());
    if(n%2 == 0){
        for(int i=0; i<n/2;i++){
            ans.push_back(vec[i*2]);
        }
        reverse(vec.begin(), vec.end());
        for(int i=0; i<n/2;i++){
            ans.push_back(vec[i*2]);
        }
    }else{
        for(int i=0; i<(n/2+1);i++){
            ans.push_back(vec[i*2]);
        }
        reverse(vec.begin(), vec.end());
        for(int i=0; i<n/2;i++){
            ans.push_back(vec[i*2+1]);
        }
    }
    for(int i=0; i<n;i++){
        cout << ans[i];
        if(i != n-1){
        	cout << " ";
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 5488
#include<stdio.h>
main()
{
    long long int a, b, c, d, max;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    long long int s[4];

    s[0]=a*c;
    s[1]=a*d;
    s[2]=b*c;
    s[3]=b*d;

    max = s[0];
    for(int i=0; i<3; i++)
    {
        if(max>s[i+1]) continue;
        else max=s[i+1];
    }
    printf("%lld", max);
}


Measured memory_bytes: 2116
#include<stdio.h>
#include<string.h>
#define rep(i,n) for(int i = 0; i < n; i++)

int main(void) {
  char A[128];
  char B[128];
  scanf("%s", A);
  scanf("%s", B);

  int LA = strlen(A);
  int LB = strlen(B);
  
  if(LA < LB) {
    printf("LESS\n");
    return 0;
  } else if(LB < LA) {
    printf("GREATER\n");
    return 0;
  }

  rep(i, LA) {
    if(A[i] < B[i]) {
      printf("LESS\n");
      return 0;
    } else if(A[i] > B[i]) {
      printf("GREATER\n");
      return 0;
    }
  }
  printf("EQUAL\n");
  return 0;
}


Measured memory_bytes: 128
pub struct Scanner {
    line: Vec<String>,
    idx: usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        return Scanner {
            line: vec![],
            idx: 0,
        };
    }
    fn next<T: std::str::FromStr>(&mut self) -> T {
        if self.idx == self.line.len() {
            let mut buffer = String::new();
            std::io::stdin().read_line(&mut buffer).ok();
            let a: Vec<&str> = buffer.trim().split(' ').collect();
            self.line = a.iter().map(|&s| String::from(s)).collect();
            self.idx = 0;
        }
        let ret: T = self.line[self.idx].parse::<T>().ok().expect("Parse error.");
        self.idx += 1;
        ret
    }
    fn next_string(&mut self) -> Vec<char> {
        let s: String = self.next();
        return s.chars().collect::<Vec<char>>();
    }
    fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
}

#[allow(dead_code)]
fn gcd(a: u32, b: u32) -> u32 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn main(){
    let mut scan = Scanner::new();
    let k:u32 = scan.next();
    let mut s :u32 = 0;

    for a in 1..k+1{
        for b in 1..k+1{
            let x = gcd(a, b);
            for c in 1..k+1{
                s += gcd(x, c);
            }
        }
    }
    println!("{}", s);
}


Measured memory_bytes: 2148
#include <iostream>

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

    // 500 A
    // 100 B
    //  50 C

    int cnt = 0;

    for(int a=0; a<(A+1); a++)
    {
        for(int b=0; b<(B+1); b++)
        {
            for(int c=0; c<(C+1); c++)
            {
                if(500*a + 100*b + 50*c == X)
                    cnt++;
            }
        }
    }

    std::cout << cnt << std::endl;

}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };



int main() {
	int A, B, K;
	scanf("%d%d%d", &A, &B, &K);

	for (int i = A; i <= B; i++) {
		if (abs(i - A) < K || abs(i - B) < K) {
			printf("%d\n", i);
		}
	}



}





/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
・文字列の＜＜スペル＞＞は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

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

using namespace std;

int main(){
	string s;
	cin >> s;
	for(unsigned int i=0;i<s.size()-1;i++){
		if(s[i] == 'A' && s[i+1] == 'C'){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	
	return 0;
}

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

using namespace std;

int main(){
	char s;
	long long sum = 0;
	while(scanf("%c", &s) != EOF){
		if(s == '\n')
			break;
		sum += s - '0';
		sum %= 9;
	}

	if(sum%9 == 0)
		printf("Yes\n");
	else
		printf("No\n");
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpi(x1) fprintf(stderr, "#%s.%d (%s) = (%d)\n", __func__, __LINE__, #x1, x1);
#define dumpii(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%d, %d)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpiii(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%d, %d, %d)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

template<typename a>
struct S009 {
  a pow(a x, long n) {
    if( n == 0 ) return a(1);
    a t = pow(x, n / 2);
    return t * t * (n % 2 ? x : a(1));
  }
};

struct Solver {
  long n, k;
  Solver() {
    S002 r;
    r >= n >= k;
  }
  void solve() {
    S009<long> s;
    long res = k * s.pow(k - 1, n - 1);
    printf("%ld\n", res);
  }
};
 
int main() {
  for(;;) std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int prime[1000000]; // 1 -> prime, 0 -> not prime                               

void setPrime() {                                                               
    int i, j;                                                                   
                                                                                
    for (i = 2; i < 1000000; i++) {                                             
        prime[i] = 1;                                                           
    }                                                                           
                                                                                
    for (i = 2; i < 1000000; i++) {                                             
        if (prime[i] == 1) {                                                    
            for (j = i * 2; j < 1000000; j += i) {                              
                prime[j] = 0;                                                   
            }                                                                   
            if (i > 1000) break;                                                
        }                                                                       
    }                                                                           
}

int main(void) {                                                                
    int i, n;                                                                   
    int count = 0;                                                              
                                                                                
    setPrime();                                                                 
    while (scanf("%d", &n) != EOF) {                                            
        count = 0;                                                              
        for (i = 2; i <= n; i++) {                                              
            count += prime[i];                                                  
        }                                                                       
        printf("%d\n", count);                                                  
    }                                                                           
                                                                                
    return 0;                                                                   
}

Measured memory_bytes: 4500
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rev(i,n,a) for(ll i=n-1;i>=a;i--)
#define f first
#define s second
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vpii vector<pair<int,int>>
#define vpll vector<pll>
#define pll pair<ll,ll>
#define secreterror() ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve(){
    char ch;
    cin>>ch;

    if(ch>='a'&&ch<='z'){
        cout<<"a"<<endl;
    }
    else
    {
        cout<<"A"<<endl;
    }
    
    
}


int main()
{
    secreterror()
    // ll t;
    // cin>>t;
    //while(t--){
        solve();
        
    //}

}

Measured memory_bytes: 3568
#include <array>
#include <iostream>
#include <vector>

int main(int argc, char const* argv[])
{
    int n;
    std::cin >> n;

    std::array<std::vector<int>, 2> data = {
        std::vector<int>(n, 0),
        std::vector<int>(n, 0),
    };

    for (auto& vec : data) {
        for (auto& v : vec) {
            std::cin >> v;
        }
    }

    int max = 0;
    for (int i = 0; i < n; ++i) {
        int sum = 0;
        int pos = 0;
        for (int j = 0; j < n; ++j) {
            if (j == i) {
                sum += data[0][j];
                pos = 1;
            }
            sum += data[pos][j];
            /* std::cout << i << " " << sum << std::endl; */
        }
        max = std::max(sum, max);
    }

    std::cout << max << std::endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int n;
    char ud[3];
    int i,lf=0,rf=0,onebefore=-1;
    int count=0;
    while (1) {
        
        scanf("%d",&n);
        if (n==0) {
            break;
        }
        
        for (i = 0; i < n; i++) {
            
            scanf("%s",ud);
            
            if (0 == strcmp(ud,"ru")) {
                rf++;
                
                if (lf == rf && onebefore == 2) {
                    count++;
                }
                onebefore=0;

            } else if(0==strcmp(ud,"rd")){
                rf--;
                if (lf == rf && onebefore == 3) {
                    count++;
                }
                onebefore=1;
            } else if(0==strcmp(ud,"lu")){
                lf++;
                if (lf == rf && onebefore == 0) {
                    count++;
                }
                onebefore=2;
            } else if (0==strcmp(ud,"ld")){
                lf--;
                if (lf == rf && onebefore == 1) {
                    count++;
                }
                onebefore=3;
            }
            
                    }
        
        printf("%d\n",count);
        count=0;
        lf=0;
        rf=0;
        
        
    }
    return 0;
}

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

#define ll long long 

#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif

template <typename Arg1>
void __f(const char* name, Arg1&& arg1)
{
	cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << ": " << arg1 << " |";
	__f(comma + 1, args...);
}

const int N = 2e6+1;

ll int a[N] = {0};

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);
	cout.tie(nullptr);
	
	ll int n, k, r;
	cin >> n >> k;
	
	for(int i = 1; i <= n; ++i)
	{
		cin >> a[i];
		r = max(r, a[i]);
	}
	ll int l = 1, total ;
	while(r != l)
	{
		ll int mid;
		mid = (r + l)/2;
		ll cnt = 0;
		for(int i = 1; i<=n; ++i)
			cnt += (a[i] - 1) /mid;
			
	
		
		if(cnt <= k) r = mid;
		else l = mid + 1;
		
		
//		trace(r, mid, cnt, l);
	}
	cout << l << "\n";
	
	return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> vec{a + b, b + c, c + a};
    cout << *min_element(vec.begin(), vec.end()) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int maxn = 1e5 + 5;
const int inf = 1e9;
typedef long long ll;
typedef double db;
int a[maxn], b[maxn];
int ans[maxn];
int n;
ll cal(int flag) {
    int p1, p2, f;
    if (!flag) ans[(n+1)/2] = a[1], p1 = 2, p2 = 1, f = 1;
    else ans[(n+1)/2] = b[1], p1 = 1, p2 = 2, f = 0;
    int i = (n+1)/2-1, j = i+2;
    while(1) {
        if (i < 1 && j > n) break;
        if (f&1) {
            if (j <= n) {
                ans[j] = b[p2];
                ++j; ++ p2;
            }
            if (i >= 1) {
                ans[i] = b[p2];
                --i; ++ p2;
            }
        }
        else {
            if (j <= n) {
                ans[j] = a[p1];
                ++j; ++ p1;
            }
            if (i >= 1) {
                ans[i] = a[p1];
                --i; ++ p1;
            }
        }
        ++f;
    }
//    for (int i = 1 ; i <= n ; i ++) {
//        printf("%d%c", ans[i], " \n"[i==n]);
//    }
    ll res = 0;
    for (int i = 2 ; i <= n ; i ++) {
        res += abs(ans[i] - ans[i-1]);
    }
    return res;
}
void solve() {
    while(~scanf("%d", &n)) {
        for (int i = 1 ; i <= n ; i ++) {
            scanf("%d", a+i);
            b[i] = a[i];
        }
        sort(a+1, a+1+n); sort(b+1, b+1+n, greater<int>());
//        cout << cal(0) << endl;
        printf("%lld\n", max(cal(0), cal(1)));
    }
}

int main() {
   // freopen("in.txt", "r", stdin);
    int t= 1;
    //scanf("%d",&t);
    while(t--) {
        solve();
    }
}


Measured memory_bytes: 1408
(defun solve (n k p)
  (/ (if (= n k)
       (+ (loop for i from 0 below k
                sum (aref p i))
          k)
       (loop with cur = (+ (loop for i from 0 below k
                                 sum (aref p i))
                           k)
             for i from k below n
             maximizing (setf cur (+ (- cur (aref p (- i k)))
                                     (aref p i)))))
     2.0d0))

#-swank
(let* ((n (read))
       (k (read))
       (p (make-array n :element-type 'fixnum))
       (*read-default-float-format* 'double-float))
  (loop for i from 0 below n
        do (setf (aref p i) (read)))
  (format t "~A~%" (solve n k p)))


Measured memory_bytes: 59752
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>

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


int main(){
    int n;
    //string s;
    cin>>n;
    
    rep(i,n)cout<<"ACL";

cout<<endl;

} // end of main

//実行は、Opt + Ctl + N

Measured memory_bytes: 3588
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	n <- readInt
	print $ snd $ maximum $ zip ( map f [ 1 .. n ] ) [ 1 .. n ]

f k
	| k `mod` 2 == 1 = 0
	| otherwise = 1 + f ( k `div` 2 )


Measured memory_bytes: 508
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  double n,k;
  cin >> n >> k;
  double ans=0;
  vector<double>s(n+1);
  s[0]=0;
  rep(i,n){
    double p;
    cin >> p;
    s[i+1]=s[i]+(p+1)/2;
  }
  rep(i,n-k+1){
    ans=max(ans,s[i+k]-s[i]);
  }
  cout << fixed << setprecision(10) <<ans << endl;
}


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

int main(void){
	string W;
	cin >> W;
	string s;
	int ans = 0;
	while(s != "END_OF_TEXT"){
	transform(s.begin(), s.end(), s.begin(), ::tolower);
		if(s == W)ans++;
		cin >> s;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3140