akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int64_t MAXH = 510, MAXW = 510;
int64_t Grid[MAXH][MAXW];

int main()
{
  int64_t H, W;
  cin >> H >> W;
  for (int h = 0; h < H; h++)
  {
    for (int w = 0; w < W; w++)
    {
      cin >> Grid[h][w];
    }
  }
  queue<tuple<int, int, int, int>> ans;
  for (int h = 0; h < H; h++)
  {
    for (int w = 0; w < W; w++)
    {
      int64_t c = Grid[h][w];
      if (c % 2 == 0) // 偶数の場合はスキップ
        continue;
      if (h == H - 1 && w == W - 1) // 最後のマスはスキップ
        continue;
      if (h == H - 1 || Grid[h][w + 1] % 2)
      {
        Grid[h][w]--;
        Grid[h][w + 1]++; // 右に動かす
        ans.push(make_tuple(h + 1, w + 1, h + 1, w + 2));
      }
      else
      {
        Grid[h][w]--;
        Grid[h + 1][w]++; // 下に動かす
        ans.push(make_tuple(h + 1, w + 1, h + 2, w + 1));
      }
    }
  }
  cout << ans.size() << endl;
  int64_t a, b, c, d;
  while (!ans.empty())
  {
    tie(a, b, c, d) = ans.front();
    ans.pop();
    cout << a << ' ' << b << ' ' << c << ' ' << d << endl;
  }
}

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

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

int main(){
  long int a,b,n;

  cin >> a >> b >> n;
  if(b==1){
    cout << 0 << endl;
    return 0;
  }

  long int c;
  if(a%b==0) c = a/b;
  else c = a/b + 1;
  if(n>=b){
    cout << a-c << endl;
  }else{
    cout << (a*n)/b - a*(n/b) << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		int C = scanner.nextInt();
		int ans;
		int[] num = {A,B,C};
		scanner.close();		
	
		Arrays.sort(num);
		System.out.println(num[0]+num[1]+(num[2]*10));		
	}
}

Measured memory_bytes: 22612
#include <cstdio>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>

typedef long long ll;
typedef long long int lli;

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

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

struct py{
    int p;
    int y;
    int num;
};
int main() {
    int ans = 0;
    int N,M,A;
    int K[100];
    int meal[100]={0};
    cin >> N >> M;
    rep(i,N){
        cin >> K[i];
        rep(j, K[i]){
            cin >> A;
            meal[A]++;
        }
    }

    rep(i, 50){
        if(meal[i] == N)
            ans++;
    }

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define elif(a) else if(a)
#define INF INT_MAX
#define F first
#define S second
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ans=0,n,w[101];
  cin>>n;
  FOR(i,n){
    cin>>w[i];
    ans+=w[i];
  }
  int sum=0,mabs=INF;
  FOR(i,n){
      sum+=w[i];
      if(mabs>abs((ans-sum)-sum)){
        mabs=abs((ans-sum)-sum);
      }else{
        break;
      }
  }
  cout<<mabs<<endl;
  return 0;
}



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

int main(){
    double r;
    cin >> r;
    double s = M_PI * r * r;
    double per = 2.0 * M_PI * r;
    cout << fixed << setprecision(7);
    cout << s << " " << per << endl;
    return 0;
}


Measured memory_bytes: 3208
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    a, b, c = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(list)
    for i in range(a, 10 ** 10, a):
        if i % b not in d:
            d[i % b]
        else:
            break
    print("YES" if c in d else "NO")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,m;
	cin>>n>>m;
	if(n==m){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
	// your code goes here
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<string> s(n),origin(n);
  vector<int> num(n);
  for(int i=0;i<n;i++){
    cin>>s[i]>>num[i];
    origin[i]=s[i];
  }
  sort(s.begin(),s.end());
  for(int i=0;i<n;i++){
    int a,log=-1;
    for(int j=0;j<n;j++){
      if(s[i]==origin[j]){
        if(num[j]>log){
          log=num[j];
          a=j;
        }
      }
    }
    num[a]=-1;
    cout<<a+1<<endl;
  }
}


Measured memory_bytes: 256
def yu(x, y):
    min_v = min(x, y)
    max_v = max(x, y)

    mod = max_v % min_v
    if mod != 0:
        min_v = yu(min_v, mod)
    return min_v


a, b = map(int, input().split())

print(a*b//yu(a, b))


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

using namespace std;

int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}

void solve()
{
	int n;
	string s, t;
	cin >> n;
	cin >> s;
	cin >> t;
	for(int i = 0; i < n; i++)
	{
		if(s.substr(i) == t.substr(0, n - i))
		{
			cout << n + i << "\n";
			return;
		}
	}
	cout << 2 * n << "\n";
}

int main()
{
	solve();
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n, m, x, y;
    
    int xa[105], ya[105];
    
    int i;
    
    int sx, sy;
    
    scanf("%d %d %d %d\n", &n, &m, &x, &y);
    
    for(i = 0; i < n; i++) {
        if(i == n - 1) {
            scanf("%d\n", &xa[i]);
        } else {
            scanf("%d", &xa[i]);
        }
    }
    xa[n] = x;
    
    for(i = 0; i < m; i++) {
        if(i == m - 1) {
            scanf("%d", &ya[i]);
        } else {
            scanf("%d", &ya[i]);
        }
    }
    ya[m] = y;
    
    for(i = 0; i <= n; i++) {
        if(i == 0) {
            sx = xa[i];
        } else {
            if(sx < xa[i]) {
                sx = xa[i];
            }
        }
    }
    
    for(i = 0; i <= m; i++) {
        if(i == 0) {
            sy = ya[i];
        } else {
            if(sy > ya[i]) {
                sy = ya[i];
            }
        }
    }
    
    //printf("%d %d\n", sx, sy);
    
    if(sx >= sy) {
        printf("War\n");
    } else {
        printf("No War\n");
    }
    
    return 0;
}


Measured memory_bytes: 128
n = int(input())
divide_dict = {0:1,2:1,4:2,6:1,8:3}
array = [int(x) for x in input().split()]
res = 0
for num in array:
    if num % 2 != 0:
        continue
    else:
        while num % 2 == 0:
            res += 1
            num /= 2
print(res)

Measured memory_bytes: 4276
#include <iostream>

using namespace std;

#define MAX 100000

long w[MAX] = { 0 };
int n, k;

int solver( int p ) {
	int i = 0;
	for ( int j = 0 ; j < k ; j++ ) {
		long s = 0; 
		// cout << j << endl;
		while ( s + w[i] <= p ) {
			s += w[i];
			i++;
			if ( i == n ) return i;
		}
	}
	return i;
}

int solve() {
	long long left = 0;
	long long right = 100000 * 10000;
	long long mid;

	while ( right - left > 1 ) {
		mid = ( right + left ) / 2;
		//cout << "mid is " << mid << endl;
		int v = solver( mid );
		if ( v >= n ) {
			right = mid;
		} else {
			left = mid;
		}
	}
	return right;
}

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

	for ( int i = 0 ; i < n ; i++ ) {
		cin >> w[i];
	}
	cout << solve() << endl;
	return 0;
}



Measured memory_bytes: 3900
//TINY_OUNCE911666
// You are not prepared!
 
#include <bits/stdc++.h>
using namespace std;
 
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;

const int N = 407;
const ll INF = 1e18L+7;

int32_t main() {
	_upgrade
	
	int n; cin >> n;
	vector<int> a(n);
	for (int& x : a) {
		cin >> x;
	}
	
	vector<vector<ll>> dp(N, vector<ll>(N, 0));
	
	for (int l = n-1; l >= 0; --l) {
		for (int r = l; r < n; ++r) {
			if (r == l) {
				dp[l][r] = 0;
			}
			else {
				dp[l][r] = INF;
				
				ll sum = 0;
				for (int i = l; i <= r; ++i) {
					sum += a[i];
				}
				
				for (int i = l; i <= r; ++i) {
					dp[l][r] = min(dp[l][r], dp[l][i] + dp[i+1][r] + sum);
				}
			}
		}
	}
	
	cout << dp[0][n-1] << "\n";
}


Measured memory_bytes: 1536
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        long[][] XL = new long[N][2];
        for (int i = 0; i < N; i++) {
            XL[i][0] = Integer.parseInt(scanner.next());
            XL[i][1] = Integer.parseInt(scanner.next());
        }
        Arrays.sort(XL, Comparator.comparingLong(x -> x[0]));

        int cnt = 0;
        int prev = 0;
        for (int i = 1; i < N; i++) {
            if (XL[prev][0] + XL[prev][1] >= XL[i][0] - XL[i][1] + 1) {
                cnt++;
                if (XL[prev][0] + XL[prev][1] > XL[i][0] + XL[i][1]) {
                    prev = i;
                }
            } else {
                prev = i;
            }
        }

        System.out.println(N - cnt);
    }

}



Measured memory_bytes: 64608
import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;
import java.util.Comparator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.HashMap;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		
		Arrays.sort(a);
		
		int b = 0;
		int c = 0;
		
		for (int i = 0; i < n; i++) {
			if (i % 2 == 1) {
				b += a[i];
			} else {
				c += a[i];
			}
		}
		
		System.out.println(Math.abs(b-c));
	}
		
}
	
	


Measured memory_bytes: 21844
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
constexpr int INF = 1e9 + 7;
constexpr ll LINF = 1LL << 60;

V<int> enum_divisor(int n) {
    V<int> res;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i != 0) continue;
        res.push_back(i);
        if (i != n / i) res.push_back(n / i);
    }
    return res;
}

void solve() {
    int n;
    cin >> n;
    int ans = 0;
    reps(i, 1, n + 1) {
        if (i % 2 == 0) continue;
        V<int> divs = enum_divisor(i);
        if (divs.size() == 8) ans++;
    }
    cout << ans << "\n";
}
int main() {
    cin.tie(nullptr);
    // ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3604
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    vll a(n);
    for (ll i = 0; i < n; i++) cin >> a[i];
    ll low = 1, high = HIGHINF;
    while (low < high) {
        ll mid = (low + high) >> 1;
        ll tmpk = 0;
        for (ll i = 0; i < n; i++) {
            tmpk += (a[i] + mid - 1) / mid - 1;
            if (tmpk > k) break;
        }
        if (tmpk > k) low = mid + 1;
        else high = mid;
    }
    cout << low << '\n';
    return 0;
}


Measured memory_bytes: 4760
#include <cstdio>
#include <vector>
std::vector<int> adj[100005];
int dfs(int u, int fa = -1)
{
	int ans = 0, zero = 0;
	for (int v : adj[u])
	{
		if (v == fa)
			continue;
		int res = dfs(v, u);
		ans += res;
		zero += !res;
	}
	return ans + (zero ? zero - 1 : 0);
}
int main()
{
	// freopen("F.in", "r", stdin);
	int n;
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	int rt = -1;
	for (int i = 0; i < n && rt == -1; i++)
	{
		if (adj[i].size() >= 3)
			rt = i;
	}
	if (-1 == rt)
		puts("1");
	else
		printf("%d\n", dfs(rt));
	return 0;
}


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

int main(){
  int N; cin >> N;
  for(int i=1; i<=9; i++){
    if(N%i==0&&N/i<10){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

int main()
{
    long long comfort=0;
    long long n;
    cin>>n;
    vector<long long> v(n);
    for(long long i=0;i<n;i++)    cin>>v[i];
    sort(v.begin(),v.end(),greater<long long>());
    priority_queue<pair<long long,long long>> q;
    q.push(make_pair(v[0],v[0]));
    for(long long i=1;i<n;i++)
    {
        pair<long long,long long> p=q.top();
        q.pop();
        comfort+=min(p.first,p.second);
        q.push(make_pair((p.first<v[i]?p.first:v[i]),(p.first<v[i]?v[i]:p.first)));
        q.push(make_pair((p.second<v[i]?p.second:v[i]),(p.second<v[i]?v[i]:p.second)));
    }
    cout<<comfort;
}


Measured memory_bytes: 8964
(n,m)=map(int,input().split())
a=input().split()
a=list(map(int,a))
l=[]
k=0
a=sorted(a)
for i in range(m-1):
    d=abs(a[i]-a[i+1])
    k=k+d
    l.append(d)
# k=k-d
c=n-k
l.append(c)
l=sorted(l)
l1=sum(l)
print(l1-l[-1])

Measured memory_bytes: 26444
#include<stdio.h>
#include<math.h>

int wari(int j){
    int a=0;
    if(j%2==0){
        int b=wari(j/2);
        return 1+b;
    }else{
        return 0;
    }
}

int main(void){
    int u,n,t=pow(10,9);
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        if(a[i]%2==1){
            printf("0\n");
            return 0;
        }
        if(a[i]%u!=0){
            t=wari(a[i]);
            u=pow(2,t);
        }
    }
    printf("%d",t);
    
    return 0;
}

Measured memory_bytes: 384
n, x = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
sum = 0
count = 0
for i in 0...n do
  sum += a[i]
  if sum <= x
    count += 1
  else
    break
  end
end
count -= 1 if sum < x
puts count


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

using namespace std;

int n, cnt = 0;
vector<int> a, b;

int main()
{
    cin >> n;
    a.assign(n, 0);
    b.assign(n, 0);
    for(int i = 0; i < (int)a.size(); ++i)
    {
        cin >> a[i];
        a[i]--;
        b[a[i]] = i;
    }
    for(int i = 0; i < (int)b.size(); ++i)
    {
        if(b[i] != i) cnt++;
    }
    cout << ((cnt == 2 || cnt == 0) ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdlib>


using namespace std;

using ll = long long;


const ll MAX = 1000000000 + 7;


ll factorial(ll x)
{
    if (x == 0 || x == 1)
        return 1;
    return (factorial(x - 1) * x) % MAX;
}


int main()
{
    ll N, M;
    cin >> N >> M;
    if (abs(N - M) > 1) {
        cout << 0 << endl;
    } else if (abs(N - M) == 1) {
        cout << (factorial(N) * factorial(M)) % MAX << endl;
    } else {
        cout << 2 * (factorial(N) * factorial(M)) % MAX << endl;
    }
}


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

int main(){
    vector<int> a(3);
    cin >> a.at(0) >> a.at(1) >>a.at(2);
    int i,j,tmp;
    for(i=0;i<2;i++){
        for(j=1;j+i<3;j++){
            if(a.at(i)>a.at(i+j)){
                tmp=a.at(i);
                a.at(i)=a.at(i+j);
                a.at(i+j)=tmp;
            }
        }
    }
    cout << a.at(0)+a.at(1) << endl;
    return 0;
}

Measured memory_bytes: 256
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
k=0
cnt = 0
a=[]

for i in range(N):
    a.append(list(map(int, input().split())))

for i in range(N):
    for j in range(M):
        k += B[j]*a[i][j]
    if k + C > 0:
        cnt += 1
    k = 0
    
print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
#include <numeric>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back


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

    int N;
    cin >> N;
    int a = N%10;
    if(a == 3) cout << "bon" << endl;
    else if(a == 0 || a==1 || a==6 || a==8) cout << "pon" << endl;
    else cout << "hon" << endl;

    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	Int ans;
	if (N == 1) {
		ans = 0;
	}
	else {
		ans = N * (N - 1) / 2;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main()
{
  int n, m;
  cin >> n >> m;
  if(n == m){
    cout << "Yes";
  } else{
    cout << "No";
  }
  return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var p = ReadArrayInt();
            var ans = 0;
            for (int i = 1; i < n - 1; i++)
            {
                if (!(p[i] < p[i - 1] && p[i] < p[i + 1]) && !(p[i] > p[i - 1] && p[i] > p[i + 1]))
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#define W 31
#define S 3001

using namespace std;

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    int water[W], sugar[S];
    for (int i = 0; i < W; i++) {
        water[i] = 0;
    }
    for (int i = 0; i < S; i++) {
        sugar[i] = 0;
    }
    water[A] = 1; water[B] = 1; water[0] = 1;
    for (int i = B; i < W; i++) {
        if (water[i - A] == 1 or water[i - B] == 1){
            water[i] = 1;
        }
        else {
            water[i] = 0;
        }
    }
    sugar[C] = 1; sugar[D] = 1; sugar[0] = 1;
    for (int i = D; i < S; i++) {
        if (sugar[i - C] == 1 or sugar[i - D] == 1){
            sugar[i] = 1;
        }
        else {
            sugar[i] = 0;
        }
    }
    
    double max_par = 0, th = (double)F;
    int max_sw = 0, max_s = 0;
    for (int w = 0; w < W; w++) {

        if (water[w] == 0) continue;

        for (int s = 1; s <= min(w * E, S); s++) {

            if (sugar[s] == 0) continue;

            double weight = (double)w * 100 + s;
            double temp_par = 100 * s / weight;
            if (max_par <= temp_par and weight <= th) {
                max_par = temp_par;
                max_sw = weight;
                max_s = s;
            }
        }
    }

    if (max_sw == 0) {
        max_sw = A * 100;
    }
    cout << max_sw << ' ' << max_s << '\n';
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}
template <typename T>
string make_string(T N)
{
    string ret;
    T now = N;
    while (now > 0)
    {
        T x = now % 10;
        ret += (char)('0' + x);
        now /= 10;
    }
    reverse(all(ret));
    return ret;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll N, M;
    cin >> N >> M;
    vector<ll> x(N), y(M);
    loop(i, N) cin >> x[i];
    loop(i, M) cin >> y[i];
    ll X = 0, Y = 0;
    loop(i, N)
    {
        X += ((2 * (i + 1) - N - 1) * x[i]) % mod;
        if (X < 0)
            X += mod;
        else
            X %= mod;
    }
    loop(i, M)
    {
        Y += ((2 * (i + 1) - M - 1) * y[i]) % mod;
        if (Y < 0)
            Y += mod;
        else
            Y %= mod;
    }
    X *= Y;
    X %= mod;
    putout(X);
    return 0;
}


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

using namespace std;

const int maxn = 210;

int n,p[maxn];
vector<int> sol;

void swap(int &a,int &b) {
    int tg=a;
    a=b;
    b=tg;
}

void go(int k) {
    sol.push_back(k);
    for (int i=k;i<n;i++) swap(p[i],p[i-k]);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for (int i=0;i<n;i++) cin>>p[i];
    bool tested = true;
    while (tested) {
        tested = false;
        for (int i=0;i<n;i++) {
            if (p[0]!=0 && p[n-1] > p[0]) {
                tested = true;
                go(n-1);
            }
            go(1);
        }
      //  for (int i=0;i<n;i++) cout<<p[i]<<" ";
       // cout<<endl;
    }
    while (p[0]!=0) go(1);
    cout<<sol.size()<<endl;
    for (int i=0;i<sol.size();i++) cout<<sol[i]<<endl;
}


Measured memory_bytes: 764
#include <cstdio>
#include <algorithm>
#define maxn 1000010
using namespace std;
char s[maxn];
struct node{
	int l,r;
}a[maxn];
int tot;
int cmp(node a,node b){
	return a.l-a.r>b.l-b.r;
}
int main(){
	int n,i,j,l,r,ln,rn;
	ln=rn=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		l=r=0;
		scanf("%s",s+1);
		for(j=1;s[j];j++){
			if(s[j]=='(')l++;
			else if(s[j]==')'){
				if(l)l--;
				else r++;
			}
		}
		if(l&&!r)ln+=l;
		else if(!l&&r)rn+=r;
		else if(l&&r) a[++tot]=(node){l,r};
	}
	sort(a+1,a+1+tot,cmp);
	for(i=1;i<=tot;i++){
		if(ln<a[i].r)return printf("No\n")*0;
		ln-=a[i].r,ln+=a[i].l;
	}
	if(ln!=rn)return printf("No\n")*0;
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 3228
s = input()
judge = False
if s[0] == s[1]:
  if s[2] == s[3]:
    if s[0] != s[2]:
      judge = True
if s[0] == s[2]:
  if s[1] == s[3]:
    if s[0] != s[1]:
      judge = True
if s[0] == s[3]:
  if s[2] == s[1]:
    if s[0] != s[2]:
      judge = True
      
if judge:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
def main():
    s = IS()
    t = IS()
    for i in range(len(s)):
        if t == s[i:] + s[0:i]: print('Yes'); exit(0)
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let a: i64 = itr.next().unwrap().parse().unwrap();
    let b: i64 = itr.next().unwrap().parse().unwrap();
    let c: i64 = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();

    if k % 2 == 0 {
        println!("{}", a - b);
    } else {
        let aa = b + c;
        let ab = a + c;
        println!("{}", aa - ab);
    }
}


Measured memory_bytes: 2144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_7_B
{
    class Program
    {
        static void Main(string[] args)
        {

            while (true)
            {
                string[] str = Console.ReadLine().Split(' ');
                int n = int.Parse(str[0]);
                int x = int.Parse(str[1]);
                int sum = 0;
                if (n == 0 && x == 0) break;
                for (int i = 1; i <= n; i++)
                    for (int j = i + 1; j <= n; j++)
                    {
                        int answer = x - j - i;
                        if (answer > j && answer <= n)
                        {
                            sum++;
                        }
                    }
                Console.WriteLine("{0}", sum);

            }
        }
    }
}



Measured memory_bytes: 17956
import heapq

X, Y, Z, K = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
B = list(map(int, input().split(" ")))
C = list(map(int, input().split(" ")))
AB_que = []

for i in range(X):
    for j in range(Y):
        heapq.heappush(AB_que, A[i] + B[j])

while len(AB_que) > K:
    heapq.heappop(AB_que)

que = []
for ab in AB_que:
    for i in range(Z):
        heapq.heappush(que, -(ab + C[i]))

while K > 0:
    print(-heapq.heappop(que))
    K -= 1

Measured memory_bytes: 170780
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    int N;
    cin >> N;
    vector<int> b(N+1);
    rep1(i,N) cin >> b[i];
    rep1(i,N) if(b[i] > i){pr(-1); return 0;}
    
    vector<int> ans;
    while(sz(b) > 1){
        for(int i = sz(b)-1; i >= 1; --i) if(b[i] == i){
            ans.pb(i);
            b.erase(b.begin()+i);
            break;
        }
    }
    reverse(ALL(ans));
    for(auto e:ans) pr(e);
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
typedef long long LL;
LL n,x;
LL ask(LL a,LL b)
{
	if(!b)return -a;
	if(a<b)swap(a,b);
	return ask(b,a%b)+(a/b)*2*b;
}
int main()
{
	cin>>n>>x;
	cout<<ask(n-x,x)+n<<endl;
}

Measured memory_bytes: 256
// C++のテンプレート
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<int> a(N);
    bool flag=0;
    for(int i=0;i<N;i++)
        cin >> a[i];
    int min = -1;
    int val = -1;
    for(int value = -100;value <= 100;value++){
        int sum = 0;
        for(int i=0;i<N;i++){
            sum += (a[i]-value)*(a[i]-value);
        }
        if(min == -1){
            min = sum;
            val = value;
        }else if(min > sum){
            min = sum;
            val = value;
        }
    }
    cout << min << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;


struct Myon2
{
    int a;
}

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    int N;

    void calc()
    {

        if (calc2()) Console.WriteLine("Yes");
        else Console.WriteLine("No");

    }

    bool calc2()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int A = cin.nextInt() - 1;
        int B = cin.nextInt() - 1;
        int C = cin.nextInt() - 1;
        int D = cin.nextInt() - 1;
        string S = cin.next();

        bool[] useB = new bool[N];
        int cnt = 1;
        useB[B] = true;
        while(D > B)
        {
            if (S[B + 1] != '#') B++;
            else if (S[B + 2] != '#') B += 2;
            else return false;
            useB[B] = true;
            cnt++;
        }

        int[] dist = new int[N];
        int MAX = 9999999;
        for (int i = 0; i < N; i++)
        {
            dist[i] = MAX;
        }
        dist[A] = 0;
        for (int i = A + 1; i <= C; i++)
        {
            if (S[i] == '#') continue;
            int add = 0;
            if (useB[i]) add++;
            if (i >= 2) dist[i] = Math.Min(dist[i], dist[i - 2] + add);
            if (i >= 1) dist[i] = Math.Min(dist[i], dist[i - 1] + add);
        }


        if (dist[C] == MAX) return false;
        if (dist[C] == cnt && C > D) return false;

        return true;
    }
}




class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13408
S = input()
N = len(S)

# 各桁の和
def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)

ans = digitSum(S)
candidate = (int(S[0]) - 1) * pow(10, N-1) + (pow(10, N-1) - 1)
candidate = digitSum(candidate)

if ans > candidate:
    print(ans)
else:
    print(candidate)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		//??????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;

		while ((str = br.readLine()) != null){
			int num = 0;
			int input = Integer.parseInt(str);
			for (int i = 0; i <= 9; i++) {
				for (int j = 0; j <=9; j++) {
					for (int k = 0; k <= 9; k++) {
						for (int l = 0; l <= 9; l++) {
							if (i + j + k + l == input) {
								num++;
							}
						}
					}
				}
			}
			System.out.println(num);
		}
	}
}

Measured memory_bytes: 24844
from itertools import permutations
A = [ int( input()) for _ in range(5)]
ans = 1000
for p in permutations( range(5)):
    now = A[p[0]]
    for i in range(4):
        if now%10 == 0:
            now += A[p[i+1]]
        else:
            now = (now//10+1)*10
            now += A[p[i+1]]
    ans = min( ans, now)
print( ans)


Measured memory_bytes: 3060
#include <iostream>

int integral(int d){
    int area = 0;
    for(int i = 1; i < (600 / d); ++i){
        area += (d * (i  * d) * (i * d));
    }
    return area;
}

int main(){
    int d;
    while(std::cin >> d){
        if(d == -1)  break;
        std::cout << integral(d) << std::endl;
    }
    return 0;
}

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

int main(){
    string s; cin >> s;
    vector<char> travel_plan(s.size());
    for (int i;i<s.size();i++){
        travel_plan[i] = s[i];
    }
    sort(travel_plan.begin(), travel_plan.end());
    travel_plan.erase(unique(travel_plan.begin(), travel_plan.end()), travel_plan.end());

    if (find(travel_plan.begin(), travel_plan.end(), 'N') != travel_plan.end()){
        if (find(travel_plan.begin(), travel_plan.end(), 'S') == travel_plan.end()){
            cout << "No" << endl;
            return 0;
        }
    }

    if (find(travel_plan.begin(), travel_plan.end(), 'S') != travel_plan.end()){
        if (find(travel_plan.begin(), travel_plan.end(), 'N') == travel_plan.end()){
            cout << "No" << endl;
            return 0;
        }
    }

    if (find(travel_plan.begin(), travel_plan.end(), 'W') != travel_plan.end()){
        if (find(travel_plan.begin(), travel_plan.end(), 'E') == travel_plan.end()){
            cout << "No" << endl;
            return 0;
        }
    }

    if (find(travel_plan.begin(), travel_plan.end(), 'E') != travel_plan.end()){
        if (find(travel_plan.begin(), travel_plan.end(), 'W') == travel_plan.end()){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" <<endl;
    return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {a: u32, b: u32};

    let mut t = true;

    for i in 1..1010 {
        if i * 8 / 100 == a && i / 10 == b {
            println!("{}", i);
            t = false;
            break;
        }
    }

    if t {
        println!("-1")
    }
}


Measured memory_bytes: 2136
import itertools

n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(q)]

def A_score(A):
    dsum = 0
    for i in range(q):
        a, b, c, d = abcd[i]
        if A[b-1] - A[a-1] == c:
            dsum += d
    return dsum

seq = [i for i in range(1,m+1)]
A_comb = list(itertools.combinations_with_replacement(seq, n))
ans = 0

for t in A_comb:
    score = A_score(t)
    if  score > ans:
        ans = score

print(ans)

Measured memory_bytes: 21852
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int sum = 0;
        for (int i = 0; i < n; i++) {
            String[] digit = String.valueOf(i + 1).split("");
            int digitSum = 0;
            for (int j = 0; j < digit.length; j++) {
                digitSum += Integer.parseInt(digit[j]);
            }
            if (digitSum >= a && digitSum <= b) {
                sum += i + 1;
            }
        }
        System.out.println(sum);
    }

}


Measured memory_bytes: 35796
# %%time
# from collections import Counter

N=list(map(int,input().split()))
A=list(map(int,input().split()))

# A=list(range(2,10**6))

# counter = Counter(A)

A.sort()
max=A[-1]
dp=[0]*(max+1)

for i in A:
    if dp[i]!=0:
        dp[i]+=1
        continue
    for j in range(1*i,max+1,i):
        dp[j]+=1
        
ans=[]
for a_idx,a in enumerate(A):
    if dp[a] == 1:
        ans.append(a)
        
print(len(ans))

Measured memory_bytes: 121780
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define int long long
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(X) X[X.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min,int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}

using namespace std;
#pragma endregion
signed main() {
	int N,p,x=0;
	cin >> N;
	REP(i, N) {
		cin >> p;
		if (i != p)
			x++;
	}
	if (x > 2)
		cout << "NO";
	else
		cout << "YES";
}

Measured memory_bytes: 256
#selection sort

n = int(input())

A = list(map(int,input().split()))

count = 0
for i in range(0,n):
    minj = i
    for j in range(i,n):
        if A[j] < A[minj]:
            minj = j

    if i != minj:
        count += 1
        A[i],A[minj] = A[minj],A[i]


print(*A)
print(count)


Measured memory_bytes: 5608
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> S(N);
    rep(i, 0, N) cin >> S[i];
    ll ans = 0;
    rep(C, 1, N / 2) {
        ll now_ans = 0;
        if ((N - 1) % C) {
            for (int x = 0; N - 1 - C * x >= C; ++x) {
                now_ans += S[C * x] + S[N - 1 - C * x];
                ans = max(ans, now_ans);
            }
        }
        else {
            for (int x = 0; C * x < N - 1 - C * x; ++x) {
                now_ans += S[C * x] + S[N - 1 - C * x];
                ans = max(ans, now_ans);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    long long N;
    cin >> N;

    long long ans=0;

    if(N==2){
        ans = 2;
    }

    int flag=0;

    while(flag==0){
        for(long long i=2;i<N;i++){
            if(N%i==0){
                break;
            }
            if(i==N-1){
                flag=1;
            }
        }
        N++;
    }

    if(ans==2){
        N=3;
    }

    cout << N-1 << endl;

    return 0;

}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e2 + 5;

int v[3][MAXN];
int dp[3][MAXN];

void solve(){
	int n;
	scanf("%d", &n);
	REPN(i, 1, 2) {
		REPN(j, 1, n) {
			scanf("%d", &v[i][j]);
		}
	}
	int ans = 0;
	REPN(i, 1, 2) {
		REPN(j, 1, n) {
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + v[i][j];
		}
	}
	cout << dp[2][n] << endl;
}

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

int main () 
{
 int N , T;
 scanf("%d %d",&N,&T);
 int C[N];
 int T1[N];

 int min = INT_MAX;
 int count = 0;


 for (int i = 0;i<N;i++)
 {
   scanf("%d %d",&C[i],&T1[i]);
   if (min>C[i] && T>=T1[i])
   {
       min=C[i];
       count++;  
   }
 }

 if (count>0)printf("%d",min);
 else printf("TLE");
  



 return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b = a;
  a.insert(a.end(), b.begin(), b.end());
  sort(a.begin(), a.end(), greater<int>());
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    ans += a[i];
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 6340
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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 MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    int a;
    bool ok = true;
    REP(i, n) {
        cin >> a;
        if (a % 2 == 0) {
            if (a % 3 != 0 && a % 5 != 0) {
                ok = false;
                break;
            }
        }
    }
    cout << (ok ? "APPROVED" : "DENIED") << endl;
}


Measured memory_bytes: 256
list_c = []
for i in range(3):
    list_c.append(list(map(int, input().split())))

num1 = list_c[0][1] - list_c[0][0]
num2 = list_c[0][2] - list_c[0][0]
ans = "Yes"
for i in range(3):
    if not (list_c[i][0] + num1 == list_c[i][1] and list_c[i][0] + num2 == list_c[i][2]):
        ans = "No"
        break

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    vector<int> cnt(n,0);
    for(int i=0;i<k;i++){
        int d; cin >> d;
        while(d--){
            int a; cin >> a;
            a--;
            cnt[a]++;
        }
    }
    int res=0;
    for(int i=0;i<n;i++){
        if(cnt[i]==0)res++;
    }
    printf("%d\n",res);
}

Measured memory_bytes: 3748