akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> PDL;
typedef pair<LD, LD> PDD;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

template<class T>
void in(T& x) {
	cin >> x;
}

template<class T1,class T2>
void in(pair<T1, T2>& p) {
	in(p.first);
	in(p.second);
}

template<class T>
void in(vector<T>& v,LL st=-1,LL en=-1) {
	if (st == -1) {
		st = 0;
		en = v.size() - 1;
	}
	for (LL n = st; n <= en; n++) {
		in(v[n]);
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL H, N;
	cin >> H >> N;
	VLL at(N);
	VLL da(N);
	for (LL n = 0; n < N; n++) {
		cin >> at[n] >> da[n];
	}
	VLL DP(H + 1, 1e15);
	DP[0] = 0;
	for (LL n = 0; n < N; n++) {
		for (LL h = 1; h <= H; h++) {
			if (h >= at[n]) {
				if (DP[h - at[n]] != 1e15) {
					DP[h] = min(DP[h], DP[h - at[n]] + da[n]);
				}
			}
			else DP[h] = min(DP[h], da[n]);
		}
	}
	cout << DP[H] << "\n";
	return 0;
}

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

int main(){
  long int n,a;
  cin>>n;
  int ans=10;
  int s=pow(n,0.5)+2;
  rep(i,s){
    int cnt=1;
    if(n%i==0){
      a=n/i;
      while(a>=10){
        a=a/10;
        cnt++;
      }
      if(cnt<=ans) ans=cnt;
    }
    
  }
  cout<<ans<<endl;
}
    
    

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int A[10];
int N, M, Q;
int a[50], b[50], c[50], d[50];
int kotae;
void keisan(int n, int mae) {
	if (n == N) {
		int goukei = 0;
		rep(i, Q) {
			if (A[b[i]] - A[a[i]] == c[i]) goukei += d[i];
		}
		chmax(kotae, goukei);
		return;
	}
	
	for (int i = mae; i <= M; i++) {
		A[n] = i;
		keisan(n + 1, i);
	}
}

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


	cin >> N >> M >> Q;
	rep(i, Q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}

	keisan(0, 1);

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 3664
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

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

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <class T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

bool isPrime(ll num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    for (ll i = 3; i * i <= num; i += 2) {
        if (num % i == 0) { return false; }
    }

    return true;
};

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

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

template <class T>
bool is_integer(T x) {
    return std::floor(x) == x;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    int H, A;
    cin >> H >> A;
    cout << round_up(H, A) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int a = -1, z = -1;
    for(int i=0;i<n;i++){if(s[i]=='A'){a = i;} if(a!=-1){break;}}
    for(int i=n;i>=0;i--){if(s[i]=='Z'){z = i;}if(z!=-1){break;}}
    cout << z-a+1;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    long double a, b; cin >> a >> b;
    ll ans = floor(a*b);
    cout << ans << endl;
}

Measured memory_bytes: 3720
x1,y1,x2,y2 = map(int,input().split())
h = abs(x2-x1)
v = abs(y2-y1)
if x1 > x2:
  if y1 > y2: print(x2+v,y2-h,x1+v,y1-h)
  else:         print(x2-v,y2-h,x1-v,y1-h)
else:
  if y2 > y1: print(x2-v,y2+h,x1-v,y1+h)
  else:         print(x2+v,y2+h,x1+v,y1+h)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
int main() {
    int N;
    cin>>N;
    vector<int> ans(N);
    int tmp;
    for (int i = 0; i < N; ++i) {
        cin>>tmp; --tmp;
        ans[tmp]=i+1;

    }

    for (int i = 0; i < N-1; ++i) {
        cout<<ans[i]<<" ";
    }
    cout<<ans[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 1152
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	int k = 1;
	int ans = 0;
	while (k < n) {
		if (a[k] == a[k - 1]) {
			ans++;
			k += 2;
		}
		else {
			k++;
		}
	}
	cout << ans;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define inf (long long) 1e18

typedef long long ll;
typedef long double ld;

const int N = 123456;
const int M = 1234567;
const int P = 400004;
const int A = 256;


int main(int argc, char const *argv[])
{
	
	#ifdef Cyborg1o1
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif	

	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	// srand(time(0));

	int n, a, b;
	cin >> n >> a >> b;

	int diff = a - b;

	int x[123456];

	for(int i = 0; i < n; ++i)
		cin >> x[i];

	int l = 0;
	int r = (int) 1e9;

	while(l <= r){

		int mid = (l + r) >> 1;

		ll As = 0;

		for(int i = 0; i < n; ++i){

			ll h = x[i] - mid * 1ll * b;

			if(h > 0)
				As += (h + diff - 1) / diff;
			
		}

		if(As <= mid)
			r = mid - 1;
		else
			l = mid + 1;

	}

	cout << l << endl;

	return 0;					
}


Measured memory_bytes: 640
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<cmath>
#include<cstdlib>
#include<utility>
#include<queue>
#include<ctime>
#include<string>
#include<string.h>
#include<cstring>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<functional>
#include<cassert>
#include<complex>
#include<deque>
#include<stdio.h>
using namespace std;
int c[11][11]={0},h,k,a[200][200],number[10]={0},magic=1000000000,ans=0;
bool b[11]={0};
void dfs(int x,int now,int l){
	if (x==1||x==-1){
		magic=min(magic,now);
		return ;
	}
	if (now>=l) return ; 
	for (int i=0;i<=9;i++) if (b[i]==0&&i!=x&&c[x][i]<=l){
		b[i]=1;
		dfs(i,now+c[x][i],l);
		b[i]=0;
	}
}
int main()
{
	cin>>h>>k;
	for (int i=0;i<=9;i++)
		for (int j=0;j<=9;j++)
			cin>>c[i][j];
	for (int i=0;i<h;i++)
		for (int j=0;j<k;j++)
			cin>>a[i][j];
	number[1]=0;
	for (int i=0;i<h;i++)
		for (int j=0;j<k;j++){
			memset(b,0,11);
			magic=1000000000;
			if (number[a[i][j]]==0){
				dfs(a[i][j],0,c[a[i][j]][1]);
				number[a[i][j]]=magic;
			}
			ans+=number[a[i][j]];
		}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
// 今日はお盆前の最終出社日です
// いい加減寝ろ

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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

    ll a,b,c,d,maxi=0,f=0,mini=INF,sum=0;
    ll n;
    cin>>n;
    vector<ll> v(n);
    rep(i,n)cin>>v[i];
   // sort(all(v));
    vector<ll> l(n);
    vector<ll> r(n);
    l[0]=0;
    l[1]=v[0];
    r[n-2]=v[n-1];
    r[n-1] = 0;
    REP(i,2,n) l[i]=gcd(l[i-1],v[i-1]);
    for(ll i=n-3;i>=0;i--) r[i]=gcd(r[i+1],v[i+1]);
    
    rep(i,n){
        //cout<<l[i]<<" "<<r[i]<<endl;
        maxi=max(maxi,gcd(l[i],r[i]));
    }
    cout<<maxi<<endl;
    return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N; ll A[int(1e5+5)];

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

  ll cnt1 = 0, sum1 = 0;
  for (int i = 0; i < N; i++){
    sum1 += A[i];
    if (i % 2 == 0 && sum1 <= 0){
      cnt1 += abs(sum1) + 1;
      sum1 = 1;
    }else if (i % 2 != 0 && sum1 >= 0){
      cnt1 += sum1 + 1;
      sum1 = -1;
    }
  }

  ll cnt2 = 0, sum2 = 0;
  for (int i = 0; i < N; i++){
    sum2 += A[i];
    if (i % 2 == 0 && sum2 >= 0){
      cnt2 += sum2 + 1;
      sum2 = -1;
    }else if (i % 2 != 0 && sum2 <= 0){
      cnt2 += abs(sum2) + 1;
      sum2 = 1;
    }
  }

  cout << min(cnt1, cnt2) << endl;


  return 0;
}


Measured memory_bytes: 4364
S=input()

if S=='SUN':
    print(7)
elif S=='MON':
    print(6)
elif S=='TUE':
    print(5)
elif S=='WED':
    print(4)
elif S=='THU':
    print(3)
elif S=='FRI':
    print(2)
else:
    print(1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define mod 1000000007
bool isPrime[1000001];
ll power(ll a,ll b)
{
    ll result = 1;
    while(b>0)
    {
        if(b%2)
        {
            result = (a*result)%mod;
        }
        a = (a*a)%mod;
        b = b/2;
    }
    return result;
}
int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
void sieve()
{
    memset(isPrime,1,sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for(int i=2;i*i<=1000000;i++)
    {
        if(isPrime[i])
        {
            for(int j=i*i;j<=1000000;j+=i)
            {
                isPrime[j] = 0;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t,n;
    t = 1;
    for(int i=0;i<t;i++)
    {
        string s;
        cin>>s;
        if(s[s.size()-1]=='s')
        {
            s+="es";
        }
        else
        {
            s+='s';
        }
        cout<<s;
    }
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
using namespace std;
typedef long long ll;
ll MOD=1e9+7;
ll kai[200001];
ll gyaku[200001];

//a^kを求める
ll kuri2(ll a,ll k)
{
	ll ret=1;
	ll aa=a;
	while(k!=0)
	{
		if(k&1)
		{
			ret*=aa;
			ret%=MOD;
		}
		aa=aa*aa;
		aa%=MOD;
		k>>=1LL;
	}
	return ret;
}

int main()
{
	int h,w,a,b;
	ll ans=0;
	cin>>h>>w>>a>>b;
	kai[0]=1;
	for(int i=1;i<200001;i++)
	{
		kai[i]=kai[i-1]*(ll)i+MOD;
		kai[i]%=MOD;
	}
	for(int i=0;i<200001;i++)
		gyaku[i]=kuri2(kai[i],MOD-2);
	ans=kai[h+w-2]*gyaku[w-1];
	ans%=MOD;
	ans*=gyaku[h-1];
	ans%=MOD;
	cerr<<ans<<endl;
	for(int i=0;i<b;i++)
	{
		ll tmp=kai[h-a+i-1]*gyaku[i];
		tmp%=MOD;
		tmp*=gyaku[h-a-1];
		tmp%=MOD;
		ll tmp2=kai[a+w-i-2]*gyaku[w-i-1];
		tmp2%=MOD;
		tmp2*=gyaku[a-1];
		tmp2%=MOD;
		ans-=tmp*tmp2;
		ans%=MOD;
	}
	if(ans<0)
		ans+=MOD;
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    long a, b;
    vector<long> p, q;
    for (int i = 0; i < N; ++i) {
        cin >> a >> b;
        p.push_back(a + b);
        q.push_back(a - b);
    }
    sort(p.begin(), p.end(), less<int>());
    sort(q.begin(), q.end(), less<int>());
    cout << max(*p.rbegin() - *p.begin(), *q.rbegin() - *q.begin()) << endl;
    return 0;
}


Measured memory_bytes: 6596
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string a,b;
    cin >> a;
    cin >> b;
    int ans = 0;
    for (int i = 0; i < (int)a.length(); i++) {
        if (a[i] != b[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3820
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, x, y = list(map(int, input().split()))
graph = [0] + [[] for _ in range(n)]
for i in range(n - 1):
    graph[i+1].append(i+2)
    graph[i+2].append(i+1)
graph[x].append(y)
graph[y].append(x)

def bfs(graph, queue, dist, num):
    while queue:
        current = queue.pop(0)

        for c in graph[current]:
            if dist[c] != -1:
                continue
            dist[c] = dist[current] + 1
            num[dist[c]] += 1
            queue.append(c)

num = [0] + [0] * (n - 1)
for i in range(1, n+1):
    queue = [i]
    dist = [-1] + [-1] * n
    dist[i] = 0
    bfs(graph, queue, dist, num)

for v in num[1:]:
    print(v // 2)


Measured memory_bytes: 46684
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

long long gcd(long long x, long long y) {
    if (x < y) swap(x, y);
    while (x % y != 0) {
        long long divisor = x % y;
        x = y;
        y = divisor;
    }
    return y;
}

int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int gcd_front[N], gcd_back[N];
    gcd_front[0] = A[0];
    gcd_back[N - 1] = A[N - 1];
    
    for (int i = 1; i < N; i++) {
        gcd_front[i] = gcd(gcd_front[i - 1], A[i]);
        gcd_back[N - i - 1] = gcd(gcd_back[N - i], A[N - i - 1]);
    }
    long long maximum = max(gcd_back[1], gcd_front[N - 2]);

    for (int i = 1; i < N - 1; i++) {
        maximum = max(maximum, gcd(gcd_front[i - 1], gcd_back[i + 1]));
    }
    cout << maximum << endl;

    return 0;
}

Measured memory_bytes: 1408
/**
 *   created: 21 July 2019  12:00:05
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	optimizeIO();
	int tt=1;
	// cin>>tt;
	while(tt--){
		int n;
		cin>>n;
		vi v(n),v2(n);
		rep(i,0,n){
			cin>>v[i];
			v2[i] = v[i];
		}
		sort(all(v));
		int cnt=0;
		rep(i,0,n){
			if(v2[i]!=v[i])
				cnt++;
		}
		if(cnt<3){
			cout<<"YES";
		}
		else
			cout<<"NO";
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong(), b=sc.nextLong(), c=sc.nextLong();
		sc.close();
		long temp = c-a-b;
		if(temp>0 && 4*a*b<temp*temp) System.out.println("Yes");
		else System.out.println("No");
	}
}

Measured memory_bytes: 25044
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def main(readline=stdin.readline):
    while 1:
        h, w = (int(s) for s in readline().split())
        if h == 0:
            exit()

        room = [readline().rstrip() for col in range(h)]
        x = y = 0
        current = x * 1000 + y
        passed = set()

        while 1:
            passed.add(current)
            tile = room[y][x]

            if tile == '>':
                x += 1
            elif tile == '<':
                x -= 1
            elif tile == 'v':
                y += 1
            elif tile == '^':
                y -= 1
            else:
                print(x, y)
                break

            current = x * 1000 + y
            if current in passed:
                print('LOOP')
                break


if __name__ == '__main__':
    main()

Measured memory_bytes: 4284
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

ll rec(ll n, ll c2, ll c3, ll c5, ll c1, map<ll, ll> &memo) {
    if (memo.find(n) != memo.end()) return memo[n];

    if (n == 0) return 0;
    if (n == 1) return c1;

    auto t1 = [&](ll x, ll c) -> ll {
        ll target = n / x * x;
        ll one = (n - target) * c1;
        return rec(target / x, c2, c3, c5, c1, memo) + one + c;
    };


    auto t2 = [&](ll x, ll y) -> ll {
        if (n % x == 0) return INF;
        ll target = (n + x - 1) / x * x;
        assert(target > n);
        ll one = (target - n) * c1;
        return rec(target / x, c2, c3, c5, c1, memo) + one + y;
    };

    ll ans = n * c1;
    cmin(ans, t1(2, c2));
    cmin(ans, t1(3, c3));
    cmin(ans, t1(5, c5));
    cmin(ans, t2(2, c2));
    cmin(ans, t2(3, c3));
    cmin(ans, t2(5, c5));

    memo[n] = ans;
    return ans;

}

int main() {
    int t;
    cin >> t;
    rep(_, t) {
        ll n, a, b, c, d;
        cin >> n >> a >> b >> c >> d;

        map<ll, ll> memo;
        ll now = rec(n, a, b, c, d, memo);
        cout << now << endl;

    }

}


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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, y; cin >> n >> y;
  if(y % 1000 != 0) {
    cout << "-1 -1 -1" << endl;
    return 0;
  }

  int z = 0;

  z += (y % 5000) / 1000;
  y -= z * 1000;

  int s = (y%10000) / 5000;
  int t = (y-s*5000) / 10000;
  
  REP(i, s+1) {
    REP(j, t+1) {
      FOR(k, j, t+1) {
        if(z + (i * 1 + (s-i) * 5) + (j*1 + (k-j) * 2 + (t-k) * 10) == n) {
          cout << j << " "
               << (k-j) * 2 + i << " "
               << z + (s-i) * 5 + (t-k) * 10 << endl;
          return 0;
        }
      }
    }
  }

  cout << "-1 -1 -1" << endl;
}


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

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define deg(x) cout<<x<<" "

using ll = long long;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;

vector<int> graph[N];
bool vis[N];

void dfs(int u){
	vis[u]=true;
	for(auto v : graph[u]){
		if(!vis[v]){
			dfs(v);
		}
	}
}

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n,m;
	cin >> n >> m;
	f(i,0,m){
		int x,y,z;
		cin >> x >> y >> z;
		graph[x].pb(y);
		graph[y].pb(x);
	}
	ll c=0;
	memset(vis,false,sizeof(vis));
	f(i,1,n+1){
		if(!vis[i]){
			c++;
			dfs(i);
		}
	}
	cout << c << "\n";
	return 0;
}

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

#define pb push_back
#define F first
#define S second

#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define int long long
#define ll long long


	
void solve(){
	int n, k;
	cin >> n >> k;
	int a[n + 1], dp[n + 1] = {};
	for(int i = 1 ; i <= n ; i++){
		cin >> a[i];		
	}
	dp[1] = 0;
	for(int i = 2 ; i <= n ; i++){
		dp[i] = LLONG_MAX;
		for(int j = i - 1 ; j >= max(1ll, i - k) ; j--){
			dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
		}	
	}
	cout << dp[n];
}

signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long ll;

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

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N,M;
  cin>>N>>M;
  vector<int>H(N),A(M),B(M);
  vector<bool>ans(N, true);
  REP(i,N)cin>>H[i];
  REP(i,M){
    cin>>A[i]>>B[i];
    A[i]--;B[i]--;
    if(H[A[i]]>=H[B[i]]){
      ans[B[i]]=false;
    }
    if(H[B[i]]>=H[A[i]]){
      ans[A[i]]=false;
    }
  }
  int a=0;
  REP(i,N){
    a+=ans[i];
  }
  cout<<a<<endl;
}


Measured memory_bytes: 4520
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defun main (line)
  (let ((table (make-hash-table)))
    (mapc (lambda (x)
            (incf (gethash x table 0)))
          line)
    (loop for key being each hash-key of table
            using (hash-value value)
          sum
          (if (<= key value)
              (- value key)
              value))))

(let* ((n (read))
       (line (read-times n)))
  (princ (main line)))


Measured memory_bytes: 62524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int g = 0;
    for (int i = 0; i < n; i++) {
        g = gcd(g, a[i]);
    }

    string ans = "IMPOSSIBLE";
    for (int i = 0; i < n; i++) {
        int d = a[i] - k;
        if (d >= 0 && d % g == 0) ans = "POSSIBLE";
    }

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


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

int main() {
    int x,y;
    cin>>x>>y;
    if(x%y==0)
        cout<<-1<<"\n";
    else{
        for(ll i=x*2;i<10000000000000000000;i+=x){
            if(i%y!=0){
                cout<<i<<"\n";
                break;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <deque>
#include <functional>
#include <initializer_list>
#include <math.h>
#include <map>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <type_traits>
#include <queue>
#include <vector>


#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define SORT(A) std::sort((A).begin(), (A).end())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())

using lli = long long int;
using pii = std::pair<int, int>;

// グリッド上の縦横移動
constexpr std::array<std::pair<int, int>, 4> dxdy = {
    std::pair<int, int>( 1,  0),
    std::pair<int, int>(-1,  0),
    std::pair<int, int>( 0,  1),
    std::pair<int, int>( 0, -1)
};

void VintOut(std::vector<int>& A){
    const int n = A.size();
    if(n == 0){putchar('\n'); return;}
    printf("%d", A[0]);
    for(int i = 1; i < n; ++i) printf(" %d", A[i]);
    putchar('\n');
}
void VintOut(std::vector<long long int>& A){
    const int n = A.size();
    if(n == 0){ putchar('\n'); return;}
    printf("%lld", A[0]);
    for(int i = 1; i < n; ++i) printf(" %lld", A[i]);
    putchar('\n');
}

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

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

inline bool isIn(int x, int y, int H, int W){
    return 0 <= x and x < H and 0 <= y and y < W;
}
inline bool bitUP(int state, int k){ return (state >> k) & 1; }
inline bool bitUP(long long int state, int k){ return (state >> k) & 1;}

// z-algorithm
template <class T> std::vector<int> z_algorithm(const T &str) {
    const int n = str.size();
    std::vector<int> resOfCP(n); resOfCP[0] = n;
    int i = 1, j = 0;
    while (i < n) {
        while (i + j < n and str[j] == str[i + j]) ++j;
        resOfCP[i] = j;
        if (j == 0) { ++i; continue;}
        int k = 1;
        while (i + k < n and k + resOfCP[k] < j) resOfCP[i + k] = resOfCP[k], ++k;
        i += k; j -= k;
    }
    return resOfCP;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

std::vector<int> A;

int main(void){
    int n, k; scanf("%d%d", &n, &k);
    A.resize(n); REP(i, n) scanf("%d", &A[i]);
    std::sort(A.begin(), A.end());
    lli res = 0;
    const int t = n - k;
    REP(i, t) res += A[i];
    printf("%lld\n", res);
    
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗(i <= 20 まで)
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */

int main() {
    int n,q;cin >> n >> q;
    string s;
    cin >> s;
    vi ans(n-1);
    rep(i, n-1) {
        if(s[i]=='A'&&s[i+1]=='C') {
            ans[i]++;
            i++;
        }
    }
    // for(auto p:ans) cout << p << ' '; // 確認済
    vi rui(n);
    rui[0] = 0;
    rep1(i,n-1) rui[i] += rui[i-1]+ans[i-1];
    // for(auto p:rui) cout << p << ' '; // 確認済
    // cout << endl;
    rep(i, q) {
        int a, b;
        cin >> a >> b;
        cout << rui[b-1] - rui[a-1] << endl;
    }
    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

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

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

  x -= a;
  if (x < 0) {
    cout << "NO" << endl;
    return 0;
  }

  if (x > b) {
    cout << "NO" << endl;
    return 0;
  }

  cout << "YES" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#define INF 100000000

using namespace std;
int main(){
  while(1){
    int n,k;
    cin >> n >> k;
    if(n==0&&k==0)break;
    vector< vector<int> > gr( n+1 , vector<int>(n+1, 0) );  
    //  int gr[n+1][n+1];
    int D[n+1];
    int R[n+1];
    int p;
    int a,b,c,d;
    for(int j=0;j<k;j++){
      cin >> a;
      if(a==0){
	cin >> b >> c;
	//D syoki
	for(int i=0;i<n+1;i++){
	  D[i]=INF;
	  R[i]=0;
	}
	//
	D[b]=0;
	R[b]=1;
	p=b;
	while(1){
	  for(int i=1;i<n+1;i++){
	    if(gr[p][i]!=0){
	      D[i]=min(gr[p][i]+D[p],D[i]);
	    }
	  }
	  int mini=INF+1;
	  int minn=-1;
	  for(int i=1;i<n+1;i++){
	    if(R[i]==1)continue;
	    mini=min(D[i],mini);
	    if(mini==D[i])minn=i;
	  }
	  if(minn==-1)break;
	  else{
	    R[minn]=1;
	    p=minn;
	  }
	}
	if(D[c]==INF)cout << -1 << endl;
	else cout << D[c] << endl;
      }
      //
      else if(a==1){
	cin >> b >> c >> d;
	if(gr[b][c]>d||gr[b][c]==0){
	  gr[b][c]=d;
	  gr[c][b]=d;
	}
      }
    }
  }
  return 0;  
}

Measured memory_bytes: 3196
#include <stdio.h>
#include <math.h>
#include <string.h>
typedef long long ll;
int main(int argc,int *argv[])
{
	ll p,q,k;
	scanf("%lld%lld",&p,&q);
	if(q==1||p==1)
		k=1;
	else
	{
		if(p%2==0)
			k=(p/2)*q;
		else
			k=(p/2)*q + (q+1)/2;		
	}
	printf("%lld",k);
	return 0;
}


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

using namespace std;

#define MAX_V 100
#define MAX_E 10000

int V,E,par[MAX_V],rank[MAX_V];

struct Colony{
  double x,y,z,r;
  Colony(){}
  Colony(double x,double y,double z,double r) : x(x),y(y),z(z),r(r) {}
};

struct Edge{
  int u,v;
  double dist;
  Edge(){}
  Edge(int u,int v,double dist) : u(u),v(v),dist(dist) {}
};

bool comp(const Edge &e1,const Edge &e2){
  return e1.dist < e2.dist;
}

Edge es[MAX_E];

void init(){
  for(int i = 0 ; i < V ; i++){
    par[i] = i;
    rank[i] = 0;
  }
}

int find(int x){
  if(par[x] == x){
    return x;
  }
  return par[x] = find(par[x]);
}

void unite(int x,int y){
  x = find(x);
  y = find(y);

  if(x == y) return;

  if(rank[x] < rank[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(rank[x] == rank[y]){
      rank[x]++;
    }
  }
}

bool same(int x,int y){
  return find(x) == find(y);
}

double kruskal(){
  sort(es,es+E,comp);
  init();
  double res = 0.0;
  for(int i = 0 ; i < E ; i++){
    Edge e = es[i];
    if(!same(e.u,e.v)){
      unite(e.u,e.v);
      res += e.dist;
    }
  }
  return res;
}

double getDist(const Colony &c1,const Colony &c2){
  return sqrt(pow(c1.x-c2.x,2)+pow(c1.y-c2.y,2)+pow(c1.z-c2.z,2))-c1.r-c2.r;
}

int main(){
  while(cin >> V,V){
    E = 0;
    double x,y,z,r;
    Colony C[MAX_V];
    for(int i = 0 ; i < V ; i++){
      cin >> x >> y >> z >> r;
      C[i] = Colony(x,y,z,r);
    }
    
    for(int i = 0 ; i < V ; i++){
      for(int j = i+1 ; j < V ; j++){
        double dist = getDist(C[i],C[j]);
        es[E++] = Edge(i,j,max(dist,0.0));
      }
    }
    printf("%.3f\n",kruskal());
  }
  return 0;
}

Measured memory_bytes: 1336
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
    int n;
    cin >> n;
    int count = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int d0, d1;
        cin >> d0 >> d1;
        if (d0 == d1) {
            count++;
        } else {
            count = 0;
        }
        if (count >= 3) {
            ans = 1;
        }
    }

    if (ans == 0)
        cout << "No" << endl;
    else
    {
        cout << "Yes" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3628
import bisect

def main():
    A, B, Q = map(int, input().split())
    s = [-float('inf')]
    t = [-float('inf')]
    ans = []
    for _ in range(A):
        s.append(int(input()))
    for _ in range(B):
        t.append(int(input()))
    s.append(float('inf'))
    t.append(float('inf'))
    for _ in range(Q):
        x = int(input())
        i = bisect.bisect_right(s, x)
        j = bisect.bisect_right(t, x)
        a = float('inf')
        for ss in [s[i - 1], s[i]]:
            for tt in [t[j - 1], t[j]]:
                a = min(a, abs(ss - x) + abs(tt - ss),
                        abs(tt - x) + abs(ss - tt))
        ans.append(a)
    for a in ans:
        print(a)


main()


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

const int MAX = 10000000;
int cnt[MAX+1];
bitset<MAX+1> marked;

void sieve() {
    fill(cnt, cnt+MAX+1, 1);
    marked[0] = marked[1] = true;
    for (int i = 2; i <= MAX; i++) if (!marked[i]) {
        cnt[i]++;
        for (int j = i*2; j <= MAX ; j += i) {
            int n = j, c = 1;
            while (n%i == 0) n /= i, c++;
            cnt[j] *= c;
            marked[j] = true;
        }
    }
}

int main() {
	sieve();
	int n; cin>>n;
	unsigned long long ans = 0;
	for(ll i=1; i<=n; i++){
		ans+=(i*cnt[i]);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 43916
import math
A,B,C,D = map(int, input().split())
ans1 = B-B//C-B//D
g = math.gcd(C, D)
l = C*D//g
ans1 = ans1+B//l
ans2 = A-1-(A-1)//C-(A-1)//D
ans2 = ans2+(A-1)//l
ans = ans1-ans2
print(int(ans))


Measured memory_bytes: 9180
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<set>
#include<queue>
#include<string>
#include<sstream>
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<cstdio>
using namespace std;
int main()
{
	int n1[3] = { 0 };
	int n;
	int a, b;
	cin >> n >> a >> b;
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		if (t <= a)n1[0]++;
		else if (t <= b)n1[1]++;
		else n1[2]++;
	}
	int num;
	num = min(n1[0], min(n1[1], n1[2]));
	printf("%d", num);
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int d = a+b+c;
  if(d >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
}

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

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e6;
const int Nmax=2e5+1;
const int Nd=61;



int main(){
  int n;cin>>n;
  string c; cin>>c;
  int nr=0,nw=0;
  rep(i,n){
    if(c[i]=='R') nr++;
    else nw++;
  }
  int ans=0;
  rep(i,n){
    if(c[i]=='W' && i<nr){
      ans++;
    }
  }
  cout<<ans<<endl;


}


Measured memory_bytes: 3744
#include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>

using namespace std;

int main() {
	long long int x, y; cin >> x >> y;

	if (x%y==0) {
		cout << "-1" << endl;
	}
	else {
		cout << x << endl;
	}

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

bool used[100005];

int main(){
	LL n,m;
	LL i,j,k;
	LL a,b,c;
	cin>>n>>m;
	if(2*m>n+1){
		cout<<-1<<endl;
		return 0;
	}
	a=2*n,b=m+n-1,c=m+3*n-1;
	for(i=0;i<n;i++){
		if(a>=m+2*n)break;
		if(b<m)break;
		cout<<a<<" "<<b<<" "<<c<<endl;
		used[b-m]=true;
		a++,b-=2,c--;
	}
	a=2*n-1,b=m,c=m+2*n;
	for(;i<n;i++){
		while(b<m+n && used[b-m])b++;
		cout<<a<<" "<<b<<" "<<c<<endl;
		a--,b++,c++;
	}
}

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

using ll = long long int;
using P = std::pair<int, int>;

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

int main()
{
    std::string s;
    std::cin >> s;

    if (s == "RRR")
        std::cout << 3 << std::endl;

    else if (s == "SRR" || s == "RRS")
        std::cout << 2 << std::endl;

    else if (s == "SSS")
        std::cout << 0 << std::endl;
    else
    {
        std::cout << 1 << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define p(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
//#define int long long


using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(ll a, ll n) {//aのn乗を計算します。
	ll x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;

bool arr[1050000];
int sosuu[100010];
void Eratosthenes() {
	ll N = 1050000;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (int i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (int j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu[c] = i;
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}


bool prime(ll n) {
	if (n == 1)return false;
	if (n == 2)return true;
	for (int i = 2; i < (int)sqrt(n) + 1;i++) {
		if (n%i == 0)return false;
	}
	return true;
}
vector<ll>sosu;
map<ll, int>mp;
int main() {
	FOR(i, 2, 1000001) {
		if (prime(i))sosu.pb(i);
	}
	ll N, P;
	cin >> N >> P;
	if (N == 1) {
		p(P);
		return 0;
	}
	ll x = P;
	if (P == 1) {
		p(1);
		return 0;
	}
	while (x >= 2) {
		for (ll i = 2; i < (ll)sqrt(P) + 1; i++) {
			if (x%i == 0) {
				mp[i]++;
				x /= i;
				break;
			}
			if (i == (ll)sqrt(P))goto END;
		}
	}
	END:
	ll ans = 1;
	for (auto x : mp) {
		while (x.second / N > 0) {
			ans *= x.first;
			x.second -= N;
		}
	}
	p(ans);
}

Measured memory_bytes: 1400