akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    while(1){
        int h, w; cin>>h>>w;
        if(h == 0) return 0;

        vector<string> s(h);
        for(int i=0; i<h; i++) cin>>s[i];

        int ans=0;
        vector<vector<bool>> visited(h, vector<bool>(w, false));
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                if(!visited[i][j]){
                    ans++;
                    visited[i][j] = true;
                    char ch = s[i][j];
                    
                    queue<P> que;
                    que.push(P(i, j));
                    while(que.size()){
                        int cy = que.front().fs;
                        int cx = que.front().sc;
                        que.pop();

                        for(int k=0; k<4; k++){
                            int ny = cy + dy[k];
                            int nx = cx + dx[k];

                            if(0 <= ny && ny < h && 0 <= nx && nx < w){
                                if(!visited[ny][nx] && s[ny][nx] == ch){
                                    visited[ny][nx] = true;
                                    que.push(P(ny, nx));
                                }
                            }
                        }
                    }
                }
            }
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 3036
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,d;
    int sum=0;
    int sum2=0;
    cin>>a>>b>>c>>d;
    if(a>b)
    {
      sum=b;
    }
    else if(a<=b)
    {
      sum=a;
    }
    if(c>d)
    {
        sum2=d;
    }
    else if(c<=d)
    {
        sum2=c;

    }
    cout<<sum+sum2;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007
#define intt int64_t

int main() {
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> v(n, 0);
    int ac=0;
    rep(i,q) {
        int c;
        cin >> c; c--;
        v.at(c)++;
        ac++;
    }
    rep(i,n) {
        if(v.at(i)-ac+k > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 ll INF = 1e21;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, q;
	cin >> a >> b >> q;
	vector<ll> s(a+2), t(b+2);
	rep(i,a) cin >> s[i];
	rep(i,b) cin >> t[i];
	s[a] = INF; s[a+1] = -INF;
	t[b] = INF; t[b+1] = -INF;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	ll x;
	rep(i,q){
		cin >> x;
		int s1, s2, t1, t2;
		s1 = lower_bound(s.begin(), s.end(), x) - s.begin();
		s2 = s1 - 1;
		t1 = lower_bound(t.begin(), t.end(), x) - t.begin();
		t2 = t1 - 1;
		ll ans = INF;
		if(s1 != 0 && t1 != 0 && s1 != a+1 && t1 != b+1) chmin(ans, max(s[s1],t[t1]) - x);
		if(s1 != 0 && t2 != 0 && s1 != a+1 && t2 != b+1) chmin(ans, 2*(s[s1]-x) + (x - t[t2]));
		if(s1 != 0 && t2 != 0 && s1 != a+1 && t2 != b+1) chmin(ans, 2*(x-t[t2]) + (s[s1] - x));
		if(s2 != 0 && t2 != 0 && s2 != a+1 && t2 != b+1) chmin(ans, x - min(s[s2],t[t2]));
		if(s2 != 0 && t1 != 0 && s2 != a+1 && t1 != b+1) chmin(ans, 2*(x-s[s2]) + (t[t1] - x));
		if(s2 != 0 && t1 != 0 && s2 != a+1 && t1 != b+1) chmin(ans, 2*(t[t1]-x) + (x - s[s2]));
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        int ans = 11;
        for (int i = 1 ; i <= Math.sqrt(n) ; i++) {
            if ((long) n % i == 0) {
                long b = (long) n / i;
                int c = 0;
                while (b > 0) {
                    b /= 10;
                    c++;
                }
                ans = Math.min(ans, c);
            }

        }
        System.out.println(ans);
    }

}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    int count=0;
    for(int i=0; i<N/2; i++){
        if(S.at(i)==S.at(i+N/2)){
            count++;
        }
    }
    if(N%2!=0 || N==1){
        cout << "No" << endl;
        return 0;
    }
    if(count==N/2){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

ll solve(pair<ll,ll> a,pair<ll,ll> b){
  ll x1=(a.first+a.second)/2;
  ll y1=(a.first-a.second)/2;
  ll x2=(b.first+b.second)/2;
  ll y2=(b.first-b.second)/2;
  return abs(x1-x2)+abs(y1-y2);
}

int main(){
  ll N;
  cin>>N;
  vector<pair<ll,ll>> xy(N),yx(N);
  for(ll i=0;i<N;i++){
    ll x,y;
    cin>>x>>y;
    xy[i]=make_pair(x+y,x-y);
    yx[i]=make_pair(x-y,x+y);
  }
  sort(xy.begin(),xy.end());
  sort(yx.begin(),yx.end());
  ll i=0;
  ll ans=0;
  for(ll j=0;j<N;j++){
    ans=max(ans,solve(xy[i],xy[j]));
  }
  while(xy[i].first==xy[i+1].first){
    i++;
    if(i==N-1){
      break;
    }
  }
  for(ll j=0;j<N;j++){
    ans=max(ans,solve(xy[i],xy[j]));
  }
  i=N-1;
  for(ll j=0;j<N;j++){
    ans=max(ans,solve(xy[i],xy[j]));
  }
  while(xy[i].first==xy[i-1].first){
    i--;
    if(i==0){
      break;
    }
  }
  for(ll j=0;j<N;j++){
    ans=max(ans,solve(xy[i],xy[j]));
  }

  i=0;
  for(ll j=0;j<N;j++){
    ans=max(ans,solve(yx[i],yx[j]));
  }
  while(yx[i].first==yx[i+1].first){
    i++;
    if(i==N-1){
      break;
    }
  }
  for(ll j=0;j<N;j++){
    ans=max(ans,solve(yx[i],yx[j]));
  }
  i=N-1;
  for(ll j=0;j<N;j++){
    ans=max(ans,solve(yx[i],yx[j]));
  }
  while(yx[i].first==yx[i-1].first){
    i--;
    if(i==0){
      break;
    }
  }
  for(ll j=0;j<N;j++){
    ans=max(ans,solve(yx[i],yx[j]));
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 9548
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vvi g;
vi a,par,s;
vl res;

void dfs(int v,int p){
	par[v]=p;
	s[v]++;
	for(auto u:g[v]) if(u!=p){
		dfs(u,v);
		s[v]+=s[u];
	}
}

void DFS(int v,map<int,int> &mp){
	int p=par[v];
	for(auto u:g[v]) if(u!=p){
		map<int,int> mp1;
		DFS(u,mp1);
		if(mp.size()<mp1.size()) swap(mp,mp1);
		for(auto q:mp1) mp[q.first]+=q.second;
	}
	if(p>=0&&a[p]!=a[v]){
		ll t=s[v]-mp[a[p]];
		res[a[p]]-=t*(t+1)/2;
	}
	if(p<0){
		for(int i=0;i<n;i++) if(i!=a[0]){
			ll t=n-mp[i];
			res[i]-=t*(t+1)/2;
		}
	}
	mp[a[v]]=s[v];
}

int main(){
	cin>>n;
	par=s=a=vi(n);
	g=vvi(n);
	res=vl(n,(ll)n*(n+1)/2);
	for(auto &i:a){
		cin>>i;
		i--;
	}
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0,-1);
	map<int,int> mp;
	DFS(0,mp);
	for(auto i:res) cout<<i<<endl;
}

Measured memory_bytes: 68024
import math 
a,b,x = map(int,input().split())
if 0.5*b*(a**2)<=x:
  t = math.degrees(math.atan(2*(a**2*b-x)/(a**3)))
  print(t)
else:
  t = 90-math.degrees(math.atan(2*x/(a*(b**2))))
  print(t)

Measured memory_bytes: 3064
#include <cstdio>
#include <cassert>
#include <queue>
#include <deque>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <cstdlib>
#include <string>
#include <unordered_map>
#include <sstream>
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef unsigned char byte;
typedef unsigned int uint;
typedef unsigned long long int ulli;

int main() {
    int n, m;
    lli s = 0;
    scanf("%d%d", &n, &m);
    int i;
    for (i=1; i<=n; ++i) {
        if (m == 0) s += n;
        else s += max(i - m, 0) * (lli)(n / i) + max(n % i - m + 1, 0);
    }
    printf("%lld\n", s);
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  i64 n, p;
  cin >> n >> p;
  i64 odd = 0;
  rep(i, n) {
    int a; cin >> a;
    if (a % 2 == 1) odd++;
  }
  if (p == 0) {
    if (odd == 0) cout << bit(n) << endl;
    else cout << bit(n) - bit(odd - 1) * bit(n - odd) << endl;
  } else {
    if (odd == 0) cout << 0 << endl;
    else cout << bit(odd - 1) * bit(n - odd) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int x[25];
int main(){
	int a,sum=0;
	cin>>a;
	for(int i=0;i<a;i++){
		cin>>x[i];
	}
	for(int i=0;i<a;i++)
	for(int j=i+1;j<a;j++)
	sum+=x[i]*x[j];
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iterator>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(v) begin(v), end(v)
#define rreps(i, a, n) for (ll i = (a); i <= (ll)(n); ++i)
#define rrep(i, n) rreps(i, 0, n)
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define each(i, n) for (auto&& i : n)
#define fill(x, y) memset(x,y,sizeof(x))
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <typename T> inline void print(const T& x) {cout << x << '\n';}

signed main()
{ 
  int n; cin>>n;
  string s; cin>>s;
  int cnt=0;
  reps(i,1,s.size())
  {
    if(s[i]=='E') cnt++;
  }
  int ans=cnt;
  rep(i,n-1)
  {
    if(s[i]=='W') cnt++;
    if(s[i+1]=='E') cnt--;
    ans=min(ans,cnt);
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 720
N, X = (int(x) for x in input().split())
list_a = [int(N) for N in input().split()]
a=0
count_a = 1
end = False
for i in range(0,N):
    a = list_a[i] + a
    if a <= X:
        count_a += 1
    else:
        end = True
print(count_a)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s[s.size()-1]=='s'){
        cout<<s<<"es"<<endl;
    }
    else{
        cout<<s<<"s"<<endl;
    }
  return(0);
}

Measured memory_bytes: 3624
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;

const ll LMT = pow(10,6) + 1;
ll mod[LMT];

void solver() {
	ll k;
	cin >> k;
	
	/**
	 * 配列の漸化式は
	 * a[i]=10*a[i-1]+7となる
	 * a[i]%k=0となるiが答え
	 * 
	 * a[i-1]-a[i-1]%kはkの倍数となるため、
	 * a[i]%kを考える時、(10*a[i-1])%k+7を考えればよい
	 * (kの倍数分を元から除外している)
	 */
	mod[0]=7%k;
	
	/**
	 * kが同じパターン出てくる場合は繰り返しになる
	 * 鳩ノ巣理論より、繰り返しに登場する数字はｋ個以上にならないため、
	 * k回ループのみで判定が可能である
	 */
	for (ll i=1; i<k; i++) {
		mod[i]=(mod[i-1]*10+7)%k;
	}
	
	ll ans = -1;
	for (ll i=0; i<k; i++) {
		if (mod[i]==0) {
			ans=i+1;
			break;
		}
	}
	cout << ans << endl;
}

int main() {
	solver();
	return 0;
}


Measured memory_bytes: 11408
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a=Integer.parseInt(scan.next());
		int b=Integer.parseInt(scan.next());
		int c=Integer.parseInt(scan.next());
		int temp=0;
		if(a>b){
			temp = a;
			a = b;
			b = temp;
		}if(a>c){
			temp = a;
			a = c;
			c = temp;
		}if(b>c){
			temp = b;
			b = c;
			c = temp;
		}
			System.out.println(a+" "+b+" "+c);
	}	
}

Measured memory_bytes: 17312
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n,k;
	while(cin >> n >> k) {
		vector<int> a(n);
		REP(i,n) cin >> a[i];
		sort(ALL(a));
		auto need = [&](int p) -> bool{
			DEBUG(p);
			bitset<5050> dp;
			dp[0] = 1;
			REP(i,n) if(i != p){
				dp |= dp<<a[i];
			}
			DEBUG(dp);
			REP(i,k){
				if(dp[i] and i+a[p] >= k){
					return true;
				}
			}
			DEBUG(false);
			return false;
		};
		LL sumall = accumulate(ALL(a),0ll);
		if(sumall < k or !need(n-1)){
			cout << n << endl;
		}else{
			if(need(0)){
				cout << 0 << endl;
			}else{
				int l = 0, r = n;
				while(l+1 < r){
					int m = (l+r)/2;
					if(need(m)){
						r = m;
					}else{
						l = m;
					}
				}
				cout << l+1 << endl;
			}
		}
	}
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 350;
const int INF = 1<<30;

int a, b, s, t, sum, d[N][N], f[N][N];

inline void ck_min( int &a, int b ) { if( a > b ) a = b; }
inline void ck_max( int &a, int b ) { if( a < b ) a = b; }

inline bool check( int x, int y, int val )
{
	int res = INF;
	for( int i = 0; i <= 100; i ++ )
		for( int j = 0; j <= 100; j ++ )
			if( f[i][j] >= 0 ) ck_min( res, i*x + j*y + f[i][j] );
	
//	printf( "x:%d, y:%d, res:%d\n", x, y, res );
	return res == val;
}

int main()
{
	memset( f, -1, sizeof( f ) );
	
	scanf( "%d%d", &a, &b );
	for( int i = 1; i <= a; i ++ )
		for( int j = 1; j <= b; j ++ )
			scanf( "%d", &d[i][j] );
			
	s = 201, t = 202; 
	// s --> 1 --> 2 --> ... --> 100
	// t <-- 101 <-- 102 <-- ... <-- 200
	
	for( int i = 0; i <= 100; i ++ )
		for( int j = 0; j <= 100; j ++ )
		{
			int tmp = -INF;
			for( int _a = 1; _a <= a; _a ++ )
				for( int _b = 1; _b <= b; _b ++ )
					ck_max( tmp, d[_a][_b] - i*_a - j*_b );	
			f[i][j] = tmp; 
			if( f[i][j] < 0 ) break;
			
			sum ++;
//			printf( "i:%d, j:%d, f:%d\n", i, j, f[i][j] );
		}

	for( int i = 1; i <= a; i ++ )
		for( int j = 1; j <= b; j ++ )	
			if( !check( i, j, d[i][j] ) ) {
				printf( "Impossible\n" ); return 0;
			} 
			
	printf( "Possible\n" );
	
	printf( "%d %d\n", 202, sum+200 );
	for( int i = 1; i < 100; i ++ )
		printf( "%d %d X\n%d %d Y\n", i, i+1, i+101, i+100 );
	printf( "%d %d X\n%d %d Y\n", s, 1, 101, t );
	for( int i = 0; i <= 100; i ++ )
		for( int j = 0; j <= 100; j ++ )
			if( f[i][j] >= 0 )  printf( "%d %d %d\n", !i ? s : i, !j ? t : j+100, f[i][j] );
	printf( "%d %d\n", s, t );
	
	return 0;
}

Measured memory_bytes: 768
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 999999999999971;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

Int Ceil(Int a, Int b) {
    if (a % b == 0) {
        return a / b;
    } else {
        return Floor(a, b) + 1;
    }
}

Int digits(Int n) {
    return (Int)to_string(n).size();
}

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

    Int k;
    cin >> k;

    if (k & 1) {
        Int a = 0;
        Int ans = 0;

        set<Int> s;
        do {
            ans++;
            a = a * 10 + 7;
            a %= k;

            if (s.count(a) == 1) {
                cout << -1 << endl;
                return 0;
            }
            s.insert(a);
        } while (a != 0);

        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 50508
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
int main() {
    int n;
    while (cin >> n, n) {
        vector <int> r, w;
        r = w = vector <int> (n);
        int sumR = 0, sumW = 0;
        rep (i, n) {
            cin >> r[i] >> w[i];
            sumR += r[i];
            sumW += w[i];
        }
        vector <int> copyR = r;
        sort(r.begin(), r.end());
        if (sumR >= 2*r.back()) {
            cout << sumR + sumW << endl;
            continue;
        }
        int gap = 2*r.back()-sumR;
        vector <int> dp(gap + 1, 0);
        dp[0] = true;
        range (i, 1, n + 1) {
            if (r.back() == copyR[i - 1]) {
                continue;
            }
            for(int j=gap;j>=0;j--){
                if (j - w[i - 1] < 0) continue;
                dp[j] |= dp[j - w[i - 1]];
            }
        }
        int maxJ = 0;
        rep (j, gap + 1) if (dp[j]) maxJ = max(maxJ, j);
        cout << sumR + sumW + (gap - maxJ) << endl;
    }
    return 0;
}


Measured memory_bytes: 3140
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#define il inline
#define re register
#define fo(i,j,k) for(register int i=j;i<=k;i++)
#define do(i,j,k) for(register int i=j;i>=k;i--) 
#define inf 0x7fffffff
typedef long long ll;
using namespace std;
il ll read()
{
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return f*x;	
}
int n,m,cnt; 
int ans;
/*int h[200010],dis[200010],v[200010];
int dp[1005][1005];
struct edge
{
	int v,w,next;
}e[200010*2];
il void add(int u,int v)
{
	e[++cnt].v=v;
//	e[cnt].w=w;
	e[cnt].next=h[u];
	h[u]=cnt;
}*/ 
int main()
{
	double r;
	cin>>r;
	printf("%lf",3.1415926*2.0*r);
	return 0;
}

Measured memory_bytes: 3784
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> P;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    lint a,b;
    cin>>a>>b;
    int ans=0;
    for(int i=0;i<(b-a);i++){
        ans+=(i+1);
    }
    cout<<ans-b<<endl;
    return 0;
}


Measured memory_bytes: 256
import bisect

n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
ans=0
for i in range(n):
  a=arr[i]
  for j in range(i+1,n):
    b=arr[j]
    tmp=a+b
    pos=bisect.bisect_left(arr,tmp)-1
    if pos<=j:
      continue
    else:
      ans+=(pos-j)
print(ans)

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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;

ll k;
vector<ll> a;
int n;
int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    cin>>n;
    cin>>k;
    a.resize(n);
    ll r;
    for(auto & b: a) cin>>b,r = max(r,b);
    ll l =1;
    while(r!=l){
        ll mid = (r+l)/2;
        ll sum = 0;
        for(int i=0;i<n;++i){
            sum += (a[i]-1)/mid;
        }
        if(sum <= k)r = mid;
        else l = mid+1;
    }
    cout << l << endl;
    
    return 0;
    
}

Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    map<char, int> mp;
    mp['r'] = P, mp['s'] = R, mp['p'] = S;
    bool win[N];
    int ans = 0;
    rep(i, K){
        win[i] = true;
        ans += mp[T[i]];
    }
    rep2(i, K, N-1){
        if(T[i] != T[i-K]){
            ans += mp[T[i]];
            win[i] = true;
        }
        elif(win[i-K]) win[i] = false;
        else{
            ans += mp[T[i]];
            win[i] = true;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long int
using namespace std;
signed main()
{
    int a,b,n;
    cin>>a>>b>>n;
    int x = min(b-1,n);
    cout<<floor((a*x)/b) - a*floor(x/b);
    return 0;
    
}


Measured memory_bytes: 3740
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N = I()
P = tuple(LI())
Q = tuple(LI())

ls = list(itertools.permutations(range(1,N+1)))
print(abs(ls.index(P) - ls.index(Q)))

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

int main () {
    string s;
    cin >> s;
    bool flag = false;
    rep(i, s.size()) {
        if('7' == s.at(i)) {
            flag = true;
        }
    }
    if(flag) {
        printf("Yes");
    }
    else {
        printf("No");
    }
}

Measured memory_bytes: 3648
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 1000000
#define LL long long
#define mod 924844033
#define rep(i,j,k) for(i=j;i<=k;++i)
#define down(i,j,k) for(i=j;i>=k;--i)
const int g=5;
struct E{
	int to,nxt;
}ed[N];
int n,i,j,k,top,u,v,len,bit,invg,invn,wn,w;
int head[N],sz[N],cnt[N],fac[N],inv[N],a[N],b[N],rev[N],omg[N][2];
void read(int &p){
	p=0; char x=getchar();
	while(x<'0' || x>'9') x=getchar();
	while(x>='0'&&x<='9'){p=p*10+x-'0'; x=getchar();}
}
int quick_mi(int a,int b){
	int sum=1;
	for(;b;b>>=1){
		if(b&1) sum=(sum*1LL*a)%mod;
		a=(a*1LL*a)%mod;
	}
	return sum;
}
void add(int u,int v){
	top++; ed[top]=(E){v,head[u]}; head[u]=top;
}
void dfs(int x,int fa){
	int i;
	sz[x]=1;
	for(i=head[x];i;i=ed[i].nxt)
	if(ed[i].to!=fa){
		dfs(ed[i].to,x);
		sz[x]+=sz[ed[i].to];
	}
	if(x!=1){
		cnt[sz[x]]++;
		cnt[n-sz[x]]++;
	}
}
void init(int n){
	len=1; bit=0;
	while(len<n) len<<=1,bit++;
	invn=quick_mi(len,mod-2); 
	invg=quick_mi(g,mod-2);
	rep(i,0,bit){
		omg[1<<i][0]=quick_mi(g,(mod-1)/(1<<i));
		omg[1<<i][1]=quick_mi(invg,(mod-1)/(1<<i));
	}
	rep(i,0,len-1) rev[i]=(rev[i>>1]>>1)|((i&1)<<(bit-1));
}
void ntt(int *a,int flag){
	rep(i,0,len-1)
	if(i<rev[i]) swap(a[i],a[rev[i]]);
	for(i=2;i<=len;i<<=1){
		wn=omg[i][flag];
		for(j=0;j<len;j+=i){
			w=1;
			rep(k,0,(i>>1)-1){
				int t=(w*1LL*a[j+k+(i>>1)])%mod;
				a[j+k+(i>>1)]=(((a[j+k]-t)%mod)+mod)%mod;
				a[j+k]=(a[j+k]+t)%mod;
				w=(w*1LL*wn)%mod;
			}
		}
	}
	if(flag)
	rep(i,0,len-1) a[i]=(a[i]*1LL*invn)%mod;
}
LL C(int n,int m){
	return (((fac[n]*1LL*inv[n-m])%mod)*1LL*inv[m])%mod;
}
int main(){
	read(n);
	rep(i,1,n-1){
		read(u); read(v);
		add(u,v); add(v,u);
	}
	fac[0]=1;
	rep(i,1,n) fac[i]=(fac[i-1]*1LL*i)%mod;
	inv[n]=quick_mi(fac[n],mod-2);
	down(i,n-1,0) b[n-i]=inv[i]=(inv[i+1]*1LL*(i+1LL))%mod;
	dfs(1,0);
	rep(i,1,n) a[i]=(cnt[i]*1LL*fac[i])%mod;
	init(n+n+2);
	ntt(a,0);
	ntt(b,0);
	rep(i,0,len-1) a[i]=(a[i]*1LL*b[i])%mod;
	ntt(a,1);
	rep(i,1,n){
		LL t=(((n*1LL*C(n,i))%mod)-((inv[i]*1LL*a[n+i])%mod))%mod;
		if(t<0) t+=mod;
		printf("%lld\n",t);
	}
	return 0;
}

Measured memory_bytes: 40832
#include<bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
#define ld long double
using namespace std;

int main()
{ 
fast;

ll n;
cin>>n;

ll a[n];
map<ll,ll> mapp;
for(ll i=0;i<n;i++)
{
    cin>>a[i];
    mapp[a[i]+i]++;
}

ll ans=0;
for(ll i=0;i<n;i++)
{
    ll z=i-a[i];
    if(mapp.find(z)!=mapp.end())
        ans+=mapp[z];
}
cout<<ans<<endl;

}

Measured memory_bytes: 17524
// from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } }
// macro_rules! debug { ($x: expr) => () }

#[allow(dead_code)]
fn show<T>(iter: T) -> String
where
    T: Iterator,
    T::Item: std::fmt::Display
{
    let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e));
    res.pop();
    res
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }
    
    input! {
        n: usize,
        m: usize,
        X: i32,
        Y: i32,
        x: [i32; n],
        y: [i32; m],
    }

    let mut ans = false;
    for z in (X+1)..(Y+1) {
        let mut f = true;
        for &e in &x {
            if e >= z {
                f = false;
            }
        }
        for &e in &y {
            if e < z {
                f = false;
            }
        }
        ans = ans || f;
    }
    if !ans {
        println!("War");
    } else {
        println!("No War");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    int cur = 1;
    for (int i = 0; i < n; ++i) {
        if(v[i] == cur) cur++;
    }
    if(cur == 1) puts("-1");
    else cout << n-cur+1 << "\n";
    return 0;
}

Measured memory_bytes: 1024
// C - Average Length
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)
#define all(x) (x).begin(),(x).end()

int main(){
	int N;
	cin>>N;
	vvi XY(N, vi(2));
	rpz(i, N) cin>>XY[i][0]>>XY[i][1];

	double ans = 0.0;

	vi p(N);
	rpz(i, N) p[i] = i;
	do {
		rpz(i, N-1){
			int dx = XY[p[i]][0] - XY[p[i+1]][0];
			int dy = XY[p[i]][1] - XY[p[i+1]][1];
			double d = sqrt(dx*dx + dy*dy);
			ans += d;
		}
	}
	while(next_permutation(all(p)));

	int n = 1;
	rp(i, 2, N+1) n *= i;
	printf("%.10f\n",ans/n);
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        mut x: i64,
        mut k: i64,
        d: i64,
    }

    if x < 0 {
        x *= -1;
    }

    let simple_move_cnt = x / d;
    if simple_move_cnt >= k {
        println!("{}", x - k * d);
        return;
    }

    x -= simple_move_cnt * d;
    k -= simple_move_cnt;
    if k % 2 == 0 {
        println!("{}", x.abs());
    } else {
        println!("{}", (x - d).abs());
    }
}


Measured memory_bytes: 2160
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int an[SIZE];
bool used[SIZE];
int main(){
    DRII(N,x);
    if(x==1||x==2*N-1)puts("No");
    else{
        if(x==2){
            an[N]=2;used[2]=1;
            an[N+1]=1;used[1]=1;
            int it=1;
            REPP(i,1,N){
                while(used[it])it++;
                an[i]=it++;
            }
            REPP(i,N+2,2*N){
                while(used[it])it++;
                an[i]=it++;
            }
        }
        else{
            an[N]=x;used[x]=1;
            an[N+1]=2*N-1;used[2*N-1]=1;
            an[N-1]=1;used[1]=1;
            if(N>=3){an[N+2]=2;used[2]=1;}
            int it=1;
            REPP(i,1,N){
                if(an[i])continue;
                while(used[it])it++;
                an[i]=it++;
            }
            REPP(i,N+2,2*N){
                if(an[i])continue;
                while(used[it])it++;
                an[i]=it++;
            }
        }
        puts("Yes");
        REPP(i,1,2*N)
            printf("%d\n",an[i]);  
    }
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

const int INF = 1001001001;
const int MAX_N = 112345;
vector<int> g[MAX_N];
int c[MAX_N], d[MAX_N];
int ans[MAX_N];

void dfs(int v, int parent) {
  for (int nxt : g[v]) if (nxt != parent) {
    dfs(nxt, v);
    c[v] = max(c[v], c[nxt] - 1);
    d[v] = min(d[v], d[nxt] + 1);
  }
}

void check(int v, int parent, int parent_value) {
  ans[v] = INF;
  for (int i = parent_value - 1; i <= parent_value + 1; i += 2) {
    if (c[v] <= i && i <= d[v]) {
      ans[v] = i;
      break;
    }
  }
  for (int nxt : g[v]) if (nxt != parent) {
    check(nxt, v, ans[v]);
  }
}

int main2() {
  REP(i, MAX_N) g[i].clear();
  REP(i, MAX_N) c[i] = -INF;
  REP(i, MAX_N) d[i] = INF;

  int N = nextInt();
  REP(i, N-1) {
    int a = nextInt()-1;
    int b = nextInt()-1;
    g[a].push_back(b);
    g[b].push_back(a);
  }


  int k0 = 0;
  int K = nextInt();
  REP(i, K) {
    int a = nextInt() - 1;
    int p = nextInt();
    c[a] = p;
    d[a] = p;
    k0 = a;
  }

  dfs(k0, -1);
  check(k0, -1, c[k0]+1);

  // pv(c, c + N);
  // pv(d, d + N);
  // pv(ans, ans + N);

  if (count(ans, ans + N, INF) == 0) {
    printf("Yes\n");
    REP(i, N) printf("%d\n", ans[i]);
  } else {
    printf("No\n");
  }

  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);
  int p;
  for (int i = 0; i < N; i++) {
    cin >> p;
    vec.at(i) = p;
  }
  sort(vec.begin(), vec.end());
  int Ans = 0;
  for (int i = 0; i < K; i++) {
    Ans += vec.at(i);
  }
  cout << Ans << endl;
}

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

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

  bool ans = false;
  if(S.at(0) != S.at(1) && S.at(0) != S.at(2) && S.at(1) != S.at(2))
    ans = true;

  if(ans == true) cout << "Yes" << endl;
  if(ans == false) cout << "No" << endl;
}

Measured memory_bytes: 3604
(let* ((x1 (read))
       (y1 (read))
       (x2 (read))
       (y2 (read))
       (dx (- x2 x1))
       (dy (- y2 y1)))
  (format t "~A ~A ~A ~A~%" (- x2 dy) (+ y2 dx) (- x1 dy) (+ y1 dx)))


Measured memory_bytes: 24088
/*------------------------- Bism Allah Alruhmin Alrahim -------------------------------*/
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i > -1; i--)
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define vc vector
#define f first
#define s second
#define pb(i) push_back(i)
#define mx(ar, n) (*max_element(ar, ar + n))
#define mn(ar, n) (*min_element(ar, ar + n))

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

ll LCM(ll x , ll y){
	return (x*y) / __gcd(x,y) ;
}

ll NumOfDiv(ll a , ll b , ll k){
	return b/k - a/k + (a%k == 0) ;
}
void start(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int res(int a , int b , int c){
	int x[3] = {a,b,c} ;
	sort(x,x+3);
	return x[1] ;
}

int main()
{
	start();
	int n ; 
    cin >> n ;
	int x[n] , y[n];
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] ;
        y[i] = x[i] ;
    }
    sort(x,x+n);
    int c = 0 ;
    for (int i = 0; i < n; i++)
    {
        if(x[i] != y[i]){
            c++ ;
        }
    }
    cout << ((c == 2 or c == 0)? "YES" : "NO") << endl;
	return 0 ;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main(){
	int n,a[M],b[M],tmp=0;
	bool ok=false;
	cin>>n;
	rep(i,n)cin>>a[i]>>b[i],a[i]--,b[i]--;
	for(int tmp=n;tmp>0;tmp--){
		int ttmp=0;
		rep(i,n)if(a[i]<=tmp&&tmp<=b[i])ttmp++;
		if(tmp<=ttmp){
			ok=true;
			print(tmp);
			break;
		}
		if(ok)break;
	}
	if(!ok)print(0);
}


Measured memory_bytes: 3872
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define REP(i,a,b) for(register int i=(a); i<(b); i++)
#define REPE(i,a,b) for(register int i=(a); i<=(b); i++)
#define PERE(i,a,b) for(register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
#define MAXN 200007
int hd[MAXN<<1], nxt[MAXN<<1], to[MAXN<<1], m=0;
inline void adde(int a, int b) {
	nxt[m]=hd[a]; hd[a]=m; to[m]=b; m++;
}
int q[MAXN], c[MAXN], ans[MAXN], vis[MAXN];
int use[3]={1,2,3};
int n;
int go(int v) {
	if(use[v]>n) {
		int r=use[2];
		use[2]+=3;
		return r;
	}
	int r=use[v];
	use[v]+=3;
	return r;
}
inline void bfs1() {
	int f=0, r=0;
	memset(vis,0,sizeof vis);
	ans[0]=0, ans[1]=0;
	q[f++]=1; c[1]=0; vis[1]=1; ans[0]++;
	while(r<f) {
		int n=q[r], s=c[n]^1; r++;
		for(int i=hd[n]; ~i; i=nxt[i]) {
			int t=to[i];
			if(!vis[t]) {
				vis[t]=1;
				c[t]=s;
				ans[s]++;
				q[f++]=t;
			}
		}
	}
}
int main() {
	memset(hd,-1,sizeof hd);
	scanf("%d", &n);
	REP(i,0,n) {
		int a,b; scanf("%d%d", &a, &b);
		adde(a,b); adde(b,a);
	}
	bfs1();
	if(ans[0]<=n/3) {
		int now=1, c2=3;
		REPE(i,1,n) {
			if(c[i]==0) {ans[i]=c2;c2+=3;}
		}
		REPE(i,1,n) {
			if(c[i]==1) {
				if(now%3==0 && now<c2) now++;
				ans[i]=now;
				now++;
			}
		}
	} else if(ans[1]<=n/3) {
		int now=1, c2=3;
		REPE(i,1,n) {
			if(c[i]==1) {ans[i]=c2;c2+=3;}
		}
		REPE(i,1,n) {
			if(c[i]==0) {
				if(now%3==0 && now<c2) now++;
				ans[i]=now;
				now++;
			}
		}
	} else {
		REPE(i,1,n) {
			ans[i]=go(c[i]);
		}
	}
	REPE(i,1,n) { if(i>1)putchar(' ');
		printf("%d", ans[i]);
	}
}


Measured memory_bytes: 9216
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

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

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
#pragma endregion

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << (H - h) * (W - w) << endl;
}

Measured memory_bytes: 256
#pragma region
// Author: Wenxing Mei
//   Date: 2018-09-01 20:51
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// using namespace __gnu_pbds;
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define per(i, r, l) for (int i = (int)(r); i >= (int)(l); --i)
#define repv(ele, vec) for (auto &ele : vec)
#define zero(mem) memset(mem, 0, sizeof(mem))
#define sd(_) scanf("%d", &_)
#define sdd(_, __) scanf("%d%d", &_, &__)
#define sddd(_, __, ___) scanf("%d%d%d", &_, &__, &___)
#define sdddd(_, __, ___, ____) scanf("%d%d%d%d", &_, &__, &___, &____)
#define sf(_) scanf("%lf", &_)
#define sff(_, __) scanf("%lf%lf", &_, &__)
#define sfff(_, __, ___) scanf("%lf%lf%lf", &_, &__, &___)
#define sffff(_, __, ___, ____) scanf("%lf%lf%lf%lf", &_, &__, &___, &____)
#define sl(_) scanf("%lld", &_)
#define sll(_, __) scanf("%lld%lld", &_, &__)
#define slll(_, __, ___) scanf("%lld%lld%lld", &_, &__, &___)
#define sllll(_, __, ___, ____) scanf("%lld%lld%lld%lld", &_, &__, &___, &____)
#define sc(_) scanf("%c", &_)
#define ss(_) scanf("%s", _)
#define sz(x) (int)(x).size()
#define boost                                                                                                          \
  ios_base::sync_with_stdio(0);                                                                                        \
  cin.tie(0);
#define mid(a, b) (((a) + (b)) >> 1)
#define lfg(x) x << 1
#define rht(x) x << 1 | 1
#define inf 0x3f3f3f3f
#define all(container) container.begin(), container.end()
//#define MOD 19260817
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define get0 get<0>
#define get1 get<1>
#define get2 get<2>
#define get3 get<3>
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#pragma endregion

// Read the question correctly
// What are the exact constraints?
// Look out for SPECIAL CASES (n=1? n=1000000000?) and overflow (ull vs int?)

int main() {
  ll n, k;
  sll(n, k);

  ll t = n / k;
  ll r = n % k;

  // vi a[k];
  // rep(i, 0, k) {
  //   a[i]
  // }

  ll sum = t * t * t;

  if (k % 2 == 0) {
    // ll x = t + r >= (k / 2) ? 1 : 0;
    ll x = t;
    if (r >= k / 2) ++x;
    // cout << "t:" << t << " x:" << x << " r:" << r << " k/2:" << k / 2 << endl;
    sum += x * x * x;
  }

  printf("%lld\n", sum);

  return 0;
}


Measured memory_bytes: 384
#include<iostream>

int main(){
  int a, b, c, n;
  std::cin >> a >> b >> c;
  if(a == b){
    if(a == c) n = 1;
    else n = 2;
  }else{
    if(a == c || b == c) n = 2;
    else n = 3;
  }
  std::cout << n << std::endl;
}

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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;





void one_case() {
    int n;
    cin >> n;
    vector<int> a(n);
    int m = 0, M = 0;
    for (auto& el : a) {
        cin >> el;
        m = min(m, el);
        M = max(M, el);
    }
    if (m == 0) {
        cout << n - 1 << "\n";
        for (int i = 1; i < n; ++i) {
            cout << i << " " << i + 1 << "\n";
        }
        return;
    }
    if (M == 0) {
        cout << n - 1 << "\n";
        for (int i = 0; i + 1 < n; ++i) {
            cout << n - i  << " " << n - i - 1 << "\n";
        }
        return;
    }
    if (M > abs(m)) {
        cout << n + n - 1 << "\n";
        int i = 1;
        for (i; i <= n; ++i) {
            if (a[i - 1] == M) {
                break;
            }
        }
        for (int j = 0; j < n; ++j) {
            cout << i << " " << j + 1 << "\n";
        }
        for (int i = 1; i < n; ++i) {
            cout << i << " " << i + 1 << "\n";
        }
    } else {
        cout << n + n - 1 << "\n";
        int i = 1;
        for (i; i <= n; ++i) {
            if (a[i - 1] == m) {
                break;
            }
        }
        for (int j = 0; j < n; ++j) {
            cout << i << " " << j + 1 << "\n";
        }
        for (int i = 0; i + 1 < n; ++i) {
            cout << n - i  << " " << n - i - 1 << "\n";
        }
    }

}


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


    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8


def solve(*args: str) -> str:
    k, s = map(int, args[0].split())

    ret = 0
    for x in range(k+1):
        for y in range(k+1):
            z = s-(x+y)
            if z < 0:
                break
            elif z <= k:
                ret += 1

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 2940
n, k = gets.chomp.split(" ").map(&:to_i)
v = gets.chomp.split(" ").map(&:to_i)

max_value = 0
1.upto(k) do |n_fetch|
  next if n_fetch > n
  0.upto(n_fetch) do |l_fetch|
    r_fetch = n_fetch - l_fetch
    l = v.first(l_fetch)
    r = v.last(r_fetch)
    vv = l.concat(r)
    cancel_v = vv.select {|v| v < 0}.sort.first(k - n_fetch).inject(&:+) || 0
    total_value = vv.inject(&:+) - cancel_v
    max_value = total_value if max_value < total_value
  end
end
puts max_value


Measured memory_bytes: 2172