akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rg register
#define maxn 560000
#define inf 0x3f
inline int read()
{
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c<='9'&&c>='0')
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=getchar();
	}
	return x*f;
}
string s;
int k;
int main()
{
	cin>>s;
	int len=s.length();
	int leng=1;
	for(rg int i=0;i<len;++i)//aaaccacabaababc
	{
		if(s[i]==s[i+1]&&leng==1&&i==len-2) 
		{
			++k;
			break;
		}
		if(s[i]==s[i+1]&&leng==1) ++k,leng=2;
		else if(s[i]!=s[i+1]&&leng==2) ++k,leng=1,++i;
		else if(s[i]!=s[i+1]&&leng==1) ++k;
		else if(s[i]==s[i+1]&&leng==2) ++i,++k,leng=1;
	}
	cout<<k;
} 

Measured memory_bytes: 640
N, M = map(int,input().split())

L_max = 1
R_min = N

for i in range(M):
    L, R = map(int,input().split()) 
    L_max = max(L_max,L)
    R_min = min(R_min,R)
    
if R_min >= L_max:
    print(int(R_min - L_max + 1))
else:
    print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int K;
    string S;
    cin >> K >> S;
    if (S.length() > K) {
        cout << S.substr(0,K) << "..." << endl;
    } else {
        cout << S << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int mod = 200003;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define fr(s,n) for (int i=(int)(s);i<(int)(n);i++)
#define lc cout<<"\n"

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int x,y;
    cin>>x>>y;
    int l=0,h=x;
    string ans="No";
    while(h>=l){
        int mid=(l+h)/2;
        int s=4*mid+2*(x-mid);
        if(s==y){
            ans="Yes";
            break;
        }
        else if(s>y){
            h=mid-1;
        }
        else{
            l=mid+1;
        }
    }
    cout<<ans;
}





Measured memory_bytes: 3652
#include<stdio.h>
int main()
{
    int A, B, C;
    scanf("%d%d%d",&A, &B, &C);

    if(A==B)
    {
        printf("%d",C);
    }
    if(A==C)
    {
        printf("%d",B);
    }
    if(B==C)
    {
        printf("%d",A);
    }
    return 0;
}



Measured memory_bytes: 128
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		if(r<=x && x<=(W-r)&& r<=y && y <=(H-r)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

    }

}


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


int main() {
	int n, k;
	cin >> n >> k;
	vector<int> fruits(n);

	for (int i = 0; i < fruits.size(); i++) {
		cin >> fruits.at(i);
	}

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

	int sum = 0;
	for (int i = 0; i < k; i++) {
		sum += fruits.at(i);
	}
	cout << sum <<endl;
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<map>
using namespace std;

typedef long long ll;
int modulo = 1000000007; // 10^9 + 7


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

	ll hand_A = 0; // Aのカード a[0]～a[i]
	ll hand_B = 0; // Bのカード a[i+1]～a[N-1]
	for (int j = 0; j < N; j++) hand_B += a[j]; // 最初に全部足しておく
												// 後で調整

	ll ans = 1000000000000000;
	for (int i = 0; i < N - 1; i++) {
		hand_A += a[i]; 
		hand_B -= a[i];
		ll temp = abs(hand_A - hand_B);
		ans = min(ans, temp);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <boost/dynamic_bitset.hpp>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <vector>

#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPC(i, a) REP(i, 0, a)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
#define RREPC(i, a) RREP(i, a, 0)
#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_i = pair<ll, int>;
using i_ll = pair<int, ll>;
using d_i = pair<double, int>;
using ll_ll = pair<ll, ll>;
using d_d = pair<double, double>;

static constexpr ll LL_MOD = 1000000009;
static constexpr int I_MOD = 1000000007;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159265358979323846264338327950288;

static map<type_index, const char *const> scanType = {{typeid(int), "%d"},
                                                      {typeid(ll), "%lld"},
                                                      {typeid(double), "%lf"},
                                                      {typeid(char), "%c"}};

template <class T> static void scan(vector<T> &v);
static void scan(vector<string> &v, bool isWord = true);
static boost::dynamic_bitset<> scan(char trueValue = 'o');

int main(int argc, char *argv[]) {
  // INFILE();
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
  return 0;
}

template <class T> static void scan(vector<T> &v) {
  auto tFormat = scanType[typeid(T)];
  for (T &n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string> &v, bool isWord) {
  if (isWord) {
    for (auto &n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

static boost::dynamic_bitset<> scan(char trueValue) {
  string s;
  getline(cin, s);

  if (s.size() == 0) {
    getline(cin, s);
  }

  for_each(begin(s), end(s),
           [trueValue](char &c) { c = (c == trueValue) ? '1' : '0'; });
  return boost::dynamic_bitset<>(string(rbegin(s), rend(s)));
}


Measured memory_bytes: 384
import sys


scan = sys.stdin.readline


def main():
  n, m = map(int, scan().rstrip().split())
  l = 0
  r = n
  
  for _ in range(m):
    l_i, r_i = map(int, scan().rstrip().split())
    l = max(l, l_i)
    r = min(r, r_i)
    
  cards = r - l + 1 if r >= l else 0
  
  print(cards)
  

if __name__ == "__main__":
  main()


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

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  if (N % 2 == 0) {
    cout << 0.5 << endl;
  } else {
    double m = static_cast<double>(N / 2);
    cout << (m + 1) / N << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////


int main() {
	int N;
	cin >> N;
	cout << N * N*N << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
ans = 0
dic = {}
for i in range(n):
    s = input()
    c = Counter(s)
    tmp = ''.join([k+str(v) for k,v in sorted(c.items())])
    if tmp not in dic:
        dic[tmp] = 1
    else:
        ans += dic[tmp]
        dic[tmp] += 1
print(ans)

Measured memory_bytes: 18732
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
using P=pair<int,int>;
int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0, g = 0, b = 0;
    vector<ll> a(n);
    rep(i, n) {
        if (s.at(i) == 'R') a[i] = 0;
        if (s.at(i) == 'B') a[i] = 1;
        if (s.at(i) == 'G') a[i] = 2;
    }
    vector<ll> cnt(3);
    rep(i,n) cnt[a[i]]++;
    ll ans=1;
    rep(i,3) ans*=cnt[i];
    rep(j, n)rep(i, j) {
        int k = j + (j - i);
        if(k<n){
            if(a[i]==a[j]) continue;
            if(a[i]==a[k]) continue;
            if(a[k]==a[j]) continue;
            ans--;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll

signed main(){
    set<int> s;
    int n;
    VI a;
    scanf("%d",&n);
    REP(i,n){
        int tmp;
        scanf("%d",&tmp);
        a.pb(tmp);
        s.insert(tmp);
    }
    SORT(a);

    int ans = 0;
    for(set<int>::iterator it=s.begin();it!=s.end();it++){
        int item = *it;
        int num = UB(all(a),item) - LB(all(a),item);
        if(num>=item) ans += num - item;
        else ans += num;
    }

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


Measured memory_bytes: 5112
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto 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 dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);

int main(){
	ll s,w;
	cin>>s>>w;
	if(w>=s) cout<<"unsafe"<<endl;
	else cout<<"safe"<<endl;

	

}




Measured memory_bytes: 3592
N, Q = map(int, (input().split()))
S = list(input())
anslist = [0]*N
count =0
for n in range(N-1):
    if S[n] == 'A' and S[n+1] == 'C':
        count += 1
    anslist[n+1] = count
#print(anslist)    
for m in range(Q):
     l, r = map(int, input().split())
     ans = anslist[r-1]-anslist[l-1]
     print(ans)
    

Measured memory_bytes: 6872
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();

    int r;
    cin >> r;
    cout << r*r << endl;
}

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

using namespace std;

// input

vector<int> vec;


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

    int num;
    for(int i = 0;cin >> num;i++){
        vec.push_back(num);
    }

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

    for(auto it = vec.begin();it < vec.end();it++){
        if(it == vec.end()-1){
            cout << *it << "\n";
        }
        else{
            cout << *it << " ";
        }
    }
}


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

int X[100000];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N, M;
	cin >> N >> M;
	for(int i = 0; i < M; i++){
		cin >> X[i];
	}
	sort(X, X + M);

	vector<int> d;
	for(int i = 0; i < M - 1; i++){
		d.push_back(abs(X[i] - X[i + 1]));
	}
	sort(d.begin(), d.end());

	if(N >= M){
		cout << 0 << endl;
		return 0;
	}

	ll sum = 0;
	for(int i = 0; i < M - N; i++){
		sum += d[i];
	}
	cout << sum << endl;
}


Measured memory_bytes: 1276
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P;
map<int, int> dp;
#define REP(i, n) for (int i = 0; i < n; i++)

bool in(int target, int max) { return 0 <= target && target < max - 1; }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  string S;
  cin >> N >> K;
  cin >> S;
  S[K-1] = S[K-1] + 32;
  cout << S << endl;

  return 0;
}


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

ll mod_inverse(ll a,ll m)
{
	ll x=1;
	for(ll b=m,u=0;b;){
		ll t=a/b;
		swap(a-=b*t,b);
		swap(x-=u*t,u);
	}
	return (x+m)%m;
}

vl fact(200005);
vl ifact(200005);

ll ncr(ll n,ll r,ll m=MOD)
{
	return fact[n]*ifact[n-r]%m*ifact[r]%m;
}

int main()
{
	fact[0]=ifact[0]=1;
	repi(i,1,fact.size()) fact[i]=i*fact[i-1]%MOD;
	repi(i,1,ifact.size()) ifact[i]=mod_inverse(fact[i],MOD);

	for(ll h,w,a,b;cin>>h>>w>>a>>b && h|w|a|b;){
		ll d1=h-a,d2=a,r1=b,r2=w-b;
		ll res=ncr(h-1+w-1,h-1);
		ll sub=0;
		for(ll k=d1;k<=min(h-1,d1+r1-1);k++)
			(sub+=ncr(d1+r1-1,k)*ncr(h-1+w-1-(d1+r1-1),h-1-k))%=MOD;
		res=(res-sub+MOD)%MOD;
		cout<<res<<endl;
	}
}


Measured memory_bytes: 3328
#include <vector>
#include <queue>
#include <cstdio>
using namespace std;
typedef long long ll;
struct Point {
	int v, e;
	bool operator<(const Point b)const {
		return this->e > b.e;
	}
	Point(int a, int b) :v(a), e(b) {}
	Point() :v(0), e(0) {}
};

ll d[100000];
bool visit[100000] = { 0 };
vector <Point> G[100000];
priority_queue <Point> PQ;

const ll INF = 1e18;

void dj(int n, int r) {
	for (int i = 0; i < n; i++) d[i] = INF;
	d[r] = 0;
	PQ.push(Point(r, 0));
	Point p, q;
	while (!PQ.empty()) {
		p = PQ.top(); PQ.pop();
		visit[p.v] = 1;
		int du = G[p.v].size();
		for (int i = 0; i < du; i++) {
			q = G[p.v][i];
			if (!visit[q.v] && q.e + d[p.v] < d[q.v]) {
				d[q.v] = q.e + d[p.v];
				PQ.push(Point(q.v, d[q.v]));
			}
		}
	}
}
int main()
{
	int V, E, r, s, t, di; 
	scanf("%d%d%d", &V, &E, &r);
	while (E--) {
		scanf("%d%d%d", &s, &t, &di);
		G[s].push_back(Point(t, di));
	}
	dj(V, r);
	for (int i = 0; i < V; i++)
		if(d[i] == INF) puts("INF");
		else printf("%lld\n", d[i]);
	return 0;
}


Measured memory_bytes: 13004
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF  2000000000
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d); BR;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
#define SUM(a, n) accumulate(a, a+n, 0)
#define VSUM(v) accumulate(ALL(v), 0);
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

ll modpow(ll x, ll y){
    if(y == 0) return 1;
    if(y == 1) return x;
    return x * modpow(x, y-1) % MOD;
}

signed main(){ INIT;
    int n, t[1000], a[1000];
    cin >> n;
    REP(i, n) cin >> t[i] >> a[i];
    ll x = 1, y = 1;
    REP(i, n){
        ll s = max(1 + (x - 1) / t[i], 1 + (y - 1) / a[i]);
        x = t[i] * s; y = a[i] * s;
    }
    OUTL(x + y);
RET;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  for(int i=1;i<=3500;i++){
    for(int j=1;j<=3500;j++){
      if(4*i*j-n*i-n*j>0&&n*i*j%(4*i*j-n*i-n*j)==0&&n*i*j/(4*i*j-n*i-n*j)<=3500){
        cout<<i<<" "<<j<<" "<<n*i*j/(4*i*j-n*i-n*j);
        return 0;
      }
    }
  }
}


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

int main(){
    char x; int k;
    vector<int> ans(130);
    

    cin >> x;
    k = x;
    ans[k]++;

    cin >> x;
    k = x;
    ans[k]++;

    cin >> x;
    k = x;
    ans[k]++;

    cin >> x;
    k = x;
    ans[k]++;

    for( int a : ans){
        if( a == 0 || a == 2 ){
            continue;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }


    cout << "Yes" << endl;

}

Measured memory_bytes: 384
K, A, B = map(int, input().split())

if A + 2 < B:
    if A - 1 >= K:
        print(K + 1)
    else:
        if (K - A + 1) % 2 == 0:
            print((K - A + 1)//2*(B-A) + A)
        else:
            print((K - A + 1)//2*(B-A) + A + 1)
else:
    print(K + 1)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>
#include <math.h>

#define nl '\n'

using namespace std;

string a, b, c;

int main(){

    cin >> a >> b >> c;

    cout << "A" << b[0] << "C";




}

//g++ -std=c++14 comp.cpp -o b; ./b.exe

Measured memory_bytes: 256
def calcPattern(N, Y):
    for i in range(0, N+1):
        for j in range(0, N+1):
            if i == ((Y - 1000*N - 4000*j) / 9000):
                if (N-i-j) >= 0: return (str(i) + " " + str(j) + " " +str(N-i-j))
    return ("-1 -1 -1")

n,y = map(int, input().split())
print(calcPattern(n,y))

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


template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    vector<ll> boss(n);
    vector<ll> count(n);
    boss[0]=0;
    rep(i,n-1) cin >> boss[i+1];
    rep(i,n) a[i]=i+1;
    sort(all(boss));
    rep(i,n){
        auto itr1=upper_bound(all(boss),a[i]);
        auto itr2=lower_bound(all(boss),a[i]);
        count[i]=itr1-itr2;
    }
    
    rep(i,n) cout << count[i] << endl;
}

Measured memory_bytes: 8012
# たとえばLを目指す場合、
# 高橋くんは出てきたLをすべて使い、Rは使わない
# 青木君は出てきたRをすべて使い、Lを使わない
# 最初の位置が(r,c)とすると、Sに現れるLの個数がTに現れるRの個数を上回るタイミングがあれば
# 外に出すことができる。（同時に同じ個数になったときは先手の高橋君が外に出す）
# 4回ループ回してOK

H,W,N = map(int,input().split())
r,c = map(int,input().split())
S = input()
T = input()

# Lを試す
xl = c
for i in range(N):
  if S[i] == "L":
    xl -= 1
    if xl == 0:
      print("NO")
      exit(0)
  if T[i] == "R":
    if xl + 1 <= W:
      xl += 1
    

# Rを試す
xr = c
for i in range(N):
  if S[i] == "R":
    xr += 1
    if xr > W:
      print("NO")
      exit(0)
  if T[i] == "L":
    if xr - 1 > 0:
      xr -= 1

# Uを試す
xu = r
for i in range(N):
  if S[i] == "U":
    xu -= 1
    if xu == 0:
      print("NO")
      exit(0)
  if T[i] == "D":
    if xu + 1 <= H:
      xu += 1

# Dを試す
xd = r
for i in range(N):
  if S[i] == "D":
    xd += 1
    if xd > H:
      print("NO")
      exit(0)
  if T[i] == "U":
    if xd - 1 > 0:
      xd -= 1

print("YES")

Measured memory_bytes: 3888
#include <iostream>
#include <vector>

using namespace std;

int solve(int n, int p){
    vector<int> m(n, 0);
    int i = 0, x = p;
    for(; m[i]!=p; i==n-1? i=0: ++i){
        if(x)m[i]++, x--; else x = m[i], m[i] = 0;
    }
    return i;
}

int main(){
    int n, p;
    while(cin >> n >> p, n|p)cout << solve(n, p) << '\n';
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;
	int dp[N+1][N+1] = {};
	for(int i(N-1);i>=0;--i){
		for(int j(N-1);j>=0;--j){
			if(S[i] == S[j]) dp[i][j] = dp[i+1][j+1] + 1;
		}
	}
	int ans(0);
	for(int i(0);i<N;++i){
		for(int j(0);j<N;++j){
			if(abs(i-j) >= dp[i][j]) ans = max(ans, dp[i][j]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 97920
#ifdef _DEBUG
#include ".vscode/debug_print.hpp"
#else
#define debug(...)
#endif
#include <bits/stdc++.h>

using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1050000000;
constexpr long long INF64 = 4000000000000000000;
constexpr int MOD7        = 1000000007;
constexpr int MOD53       = 998244353;
constexpr long double PI  = 3.14159265358979323846;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

void vprint() { std::cout << '\n'; }
template <class H, class... T> void vprint(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << '\n';
    vprint(std::forward<T>(args)...);
}
template <class T> void vprint(std::vector<T> &v) {
    for (auto &&i : v) {
        std::cout << i << '\n';
    }
}

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

    int a, b, c, d;
    scan(a, b, c, d);
    int tak = ceil((double)a / d);
    int aok = ceil((double)c / b);
    if (tak >= aok) {
        print("Yes");
    } else {
        print("No");
    }

    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include <string>
#include <cstdlib> //絶対値利用のため
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)

//const int INF = INT_MAX / 2;
const int MOD = (int)1e9 + 7;
const int P = 2 * 1e5;


int main() {
	string S;
	cin >> S;
	int cnt = 0;
	int a = 0;
	for (size_t i = 0; i < S.length(); i++) {
		cnt++;
		if (S[i] != 'A' && S[i] != 'C' && S[i] != 'G' && S[i] != 'T') cnt = 0;
		a = max(a, cnt);
	}

	/*
	int n;
	int c[P + 5] = {0};
	int out;
	cin >> n >> c[0];
	int j = 1;
	for (int i = 1; i < n;i++) {
		cin >> c[j];
		if (c[j-1] != c[j]) j++;
	}
	for (int i = 0; i < n; i++) {
		for (int k = i + 1; k < n; k++) {

		}
	}
	reverse(S.begin(), S.end());
	for (size_t i = 0; i < S.size() - 1;) {
		int counter = 0;
		if (S[i] == 'A' && S[i + 1] == 'W') {
		
			for (size_t j = i + 1; j < S.size();j++) {
				if (S[j] != 'W') break;
				else counter++;
			}
			for (size_t j = i; j < i + counter; j++) {
				S[j] = 'C';
			}
			S[i + counter] = 'A';
			
		}
		i += counter + 1;
	}
	reverse(S.begin(), S.end());
	*/
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main(){
    double r;
    cin>>r;
    cout<<fixed<<setprecision(2)<<2*r*3.141592653589793238462643383279502884197169399375105820979445923078164062862089986280348253421170679821480865132823067647093844609550582231725359408128481117450284102701938521109555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378201667315642315632318742318732312842312832365832369732364722392310116732315642315632328732318742312832312832315842315832319742319732314772392310116732365632318712318722318742352832315842158323197423197323147723923101167323156423156323187223181231873231284231283231584231583231974231973231477239231011742345642318732328732362832315842315832369732314772392330172392310166732312842312832369682310882310116742312832312882319682310882310116742352862339642350882310116732312842312882319632310842310882310116732362832369632360882340169632312742312762314223101196323127423127623148223101923396323627623148223101196323127423127623148223101696323127423127423548101;
    return 0;
}


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

using namespace std;

int main(void){
    string S;
    int count = 0;
    cin >> S;
    for(auto &c : S){
        if(c == 'x') count++;
    }
    if(count >= 8) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


int N;
string S;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      S = readToken();
      const cntR = S.count('R');
      const cntB = S.count('B');
      writeln((cntR > cntB) ? "Yes" : "No");
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
	static int n, m;
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		sc.close();

		boolean ret = exec(n - 1);
		if (!ret) {
			throw new Exception();
		}
	}

	static boolean exec(int start) {
		boolean[] used = new boolean[n + 1];
		Set<Integer> set = new HashSet<>();
		int cnt = 0;
		int j = start;
		List<String> list = new ArrayList<>(m);
		for (int i = 1; i <= n; i++) {
			if (used[i]) {
				continue;
			}
			for ( ; j >= 0; j--) {
				if (j == 0) {
					j = n - 1;
				}
				if (set.contains(j)) {
					continue;
				}
				int i2 = i + j;
				if (i2 > n) {
					i2 -= n;
				}
				if (used[i2]) {
					continue;
				}
				if (j == n - j) {
					continue;
				}
				if (!set.contains(n - j)) {
					set.add(j);
					set.add(n - j);
					used[i] = true;
					used[i2] = true;
					list.add(Math.min(i, i2) + " " + Math.max(i, i2));
					cnt++;
					if (cnt == m) {
//						if (set.size() != m * 2) {
//							throw new RuntimeException();
//						}
//						int t = 0;
//						for (int k = 1; k <= n; k++) {
//							if (used[k]) {
//								t++;
//							}
//						}
//						if (t != m * 2) {
//							throw new RuntimeException();
//						}
						PrintWriter pw = new PrintWriter(System.out);
						for (int k = 0; k < m; k++) {
							pw.println(list.get(k));
						}
						pw.flush();
						return true;
					}
					break;
				}
			}
		}
		return false;
	}
}


Measured memory_bytes: 67668
if __name__ == '__main__':
	n = int(input())
	d = {}
	for i in range(n):
		a,s = map(str,input().split())
		if a == "insert":
			d[s] = 1
		elif a == "find":
			if s in d:
				print("yes")
			else:
				print("no")


Measured memory_bytes: 33116
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int main(){
ll n,a,b;
cin >> n >> a >> b;
ll che = n/(a+b);
ll ans = che*a;
che = n%(a+b);
if(che>a){
    ans+=a;
}
else ans+=che;
cout << ans << endl;
}




Measured memory_bytes: 256
def q(a,h):
 d[a]=str(h)
 for b in t[a]:q(b,h+1)
t,p,d={},{},{}
for _ in[0]*int(input()):
 e=input().split()
 t[e[0]]=e[2:]
 for i in e[2:]:p[i]=e[0]
r=(set(t)-set(p)).pop()
p[r]='-1'
q(r,0)
for i in sorted(map(int,t)):i=str(i);print('node',i+':','parent =',p[i]+',','depth =',d[i]+',','root,'if'-1'==p[i]else'internal node,'if t[i]else'leaf,',list(map(int,t[i])))


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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll S;
  cin >> S;
  ll z = (ll)1e9;

  ll x = (z - S % z) % z;
  ll y = (S + x) / z;
  cout << "0 0 1000000000 1 " << x << " " << y << '\n';
  return 0;
}


Measured memory_bytes: 256
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
use std::cmp::max;
fn main() {
    input! { n, t, mut ab: [(usize, usize); n] };
    ab.sort();
    let mut dp = vec![0; t];
    let mut ans = 0;
    for i in 0..n {
        let (a, b) = ab[i];
        ans = max(ans, dp[t - 1] + b);
        for j in (a..t).rev() {
            dp[j] = max(dp[j], dp[j - a] + b);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i< (int) n; i++)
#define PI  3.14159265358979323846264338327950
 
 
int main () {
    int N, x;
    cin >> N >> x;

    vector<int>a(N);
    rep(i,N)cin >> a[i];

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

    int ans=0;
    int i =0;
    for(int i =0;  i <a.size() ; i++){
        if(i == a.size()-1){
            if(x == a[i]){
                ans +=1;
                break;
            }else break;
        }
        
        if(x >= a[i]){
            ans += 1;
            x -= a[i];
        }
    }


    cout << ans << endl;

}


Measured memory_bytes: 256
//E

#include<bits/stdc++.h>
using namespace std;

int r;
int c;

int n;

int calc_id(int a, int b){
	if (a == 0){
		return b;
	}
	if (b == c){
		return c + a;
	}
	if (a == r){
		return r + c + (c - b);
	}
	if (b == 0){
		return r + c + c + (r - a);
	}
	return -1;
}
map<long long int, vector<long long int> > ins;

stack<int> stk;

int main(){
	cin >> r >> c >> n;
	int len = r * 2 + c * 2;
	for (int i = 0; i < n; i++){
		int x1, y1, x2, y2;
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		long long int f = calc_id(x1, y1);
		if (f != -1){
			long long int ff = calc_id(x2, y2);
			if (ff != -1){
				f %= len;
				ff %= len;
				if (f > ff){
					swap(f, ff);
				}
				ins[f].push_back(ff);
				ins[ff].push_back(-1);
			}
		}
	}
	long long int cur = -1;
	for (auto it = ins.begin(); it != ins.end(); it++){
		for (int j = 0; j < (*it).second.size(); j++){
			long long int go = (*it).second[j];
			long long int cc = (*it).first;
			if (go >= 0){
				stk.push(go);
			}
			else{
				if (stk.size() == 0){
					puts("NO");
					return 0;
				}
				if (stk.top() == cc){
					stk.pop();
				}
				else{
					puts("NO");
					return 0;
				}
			}
		}
	}
	puts("YES");
	return 0;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;

int main() {
	ll a, b;
	ll ans = 0;

	cin >> a >> b;

	FOR(i, a, b + 1) {
		string s = to_string(i);

		if (s[0] == s[4] && s[1] == s[3]) {
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long
typedef long double ld;

const ld PI = acos(-1);

struct Point {
	int x, y;

	Point() {}

	Point(int x_, int y_) {
		x = x_;
		y = y_;
	}

	Point operator-(const Point &other) const {
		return Point(x - other.x, y - other.y);
	}

	bool operator<(const Point &other) const {
		return make_pair(x, y) < make_pair(other.x, other.y);
	}

	int operator*(const Point &other) const {
		return x * other.y - y * other.x;
	}

	int operator%(const Point &other) const {
		return x * other.x + y * other.y;
	}

	int dist(const Point &other) const {
		int dx = x - other.x;
		int dy = y - other.y;
		return dx * dx + dy * dy;
	}
};

ld ag(const Point &a, const Point &b, const Point &c) {
	Point f = (a - b);
	Point s = (c - b);
	ld ans = atan2(f * s, f % s);
	if (ans < 0) ans += PI;
	return ans;
}

vector<Point> convex_hull(vector<Point> a) {
	int mn = min_element(a.begin(), a.end()) - a.begin();
	Point to = a[mn];
	a.erase(a.begin() + mn);
	auto cmp = [&](const Point &f, const Point &s) {
		Point ff = (f - to);
		Point ss = (s - to);
		if (ff * ss != 0) {
			return ff * ss > 0;
		} else {
			return to.dist(f) < to.dist(s);
		}
	};
	auto ok_ang = [&](const Point &f, const Point &s, const Point &t) {
		Point ff = (s - f);
		Point ss = (t - s);
		return ff * ss > 0;
	};
	sort(a.begin(), a.end(), cmp); 
	vector<Point> st = {to};
	for (auto t : a) {
		while (st.size() > 1 && !ok_ang(st.rbegin()[1], st.rbegin()[0], t)) {
			st.pop_back();
		}
		st.push_back(t);
	}
	return st;
}

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

	int n;
	cin >> n;
	vector<Point> a(n);
	vector<ld> ans(n);
	map<Point, int> ind;
	for (int i = 0; i < n; i++) {
		cin >> a[i].x >> a[i].y;
		ind[a[i]] = i;
	}
	a = convex_hull(a);
	n = (int)a.size();
	for (int i = 0; i < n; i++) {
		ld c = ag(a[(i - 1 + n) % n], a[i], a[(i + 1) % n]);
		if (n == 2) c = PI;
		ans[ind[a[i]]] = c / (2 * PI);
	}
	cout << fixed << setprecision(16);
	for (auto t : ans) {
		cout << t << '\n';
	}
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const int INF = 1e9;

struct Node {
    int vertex;
    int dist;
    
    Node(int vertex, int dist):vertex(vertex), dist(dist){}
    
    bool operator<(const Node& other) const {
        return dist > other.dist;
    }
};

struct Edge {
    int from, to;
    int weight;
    Edge(int from, int to, int weight):from(from), to(to), weight(weight){}   
};

struct BellmanFord {
    int n;
    vector<Edge> edges;
    vector<vector<int>> g;
    vector<int> dists;
    
    BellmanFord(int n):n(n) {
        g.assign(n + 1, vector<int>());
        dists.assign(n + 1, INF);
    }
    
    void addEdge(int from, int to, int w) {
        edges.push_back(Edge(from , to, w));
        g[from].push_back(edges.size() - 1);
    }
    
    bool solve(int s) {
        dists.assign(n + 1, INF);
        dists[s] = 0;
        for (int i = 0; i <= n; i++) {
            for (Edge edge: edges) {
                if (dists[edge.from] < INF && dists[edge.from] + edge.weight < dists[edge.to]) {
                    dists[edge.to] = dists[edge.from] + edge.weight;
                    if (i == n) {
                        return false;
                    }
                }
            }
        }
        return true;
    }
    
    bool hasNegativeCycle() {
        dists.assign(n + 1, 0);
        for (int i = 0; i <= n; i++) {
          
            for (Edge edge: edges) {
                if (dists[edge.from] < INF && dists[edge.from] + edge.weight < dists[edge.to]) {
                    dists[edge.to] = dists[edge.from] + edge.weight;
                    if (i == n) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    
};

int main() {
    int v, e, s;
    cin >> v >> e >> s;
    BellmanFord d(v);
    for (int i = 0; i < e; i++) {
        int from, to, w;
        cin >> from >> to >> w;
        d.addEdge(from, to, w);
    }
    if (!d.solve(s)) {
        cout << "NEGATIVE CYCLE" << endl;
    }
    
    else {
        for (int i = 0; i < v; i++) {
            if (d.dists[i] == INF) {
                cout << "INF" << endl;
            }
            else {
                cout << d.dists[i] << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3224