akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

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

  int n;
  cin >> n;
  int cnt[100010] = {};
  rep(i, n)
  {
    int a;
    cin >> a;
    cnt[a]++;
    cnt[a + 1]++;
    if (a - 1 >= 0)
      cnt[a - 1]++;
  }
  int Max = 0;
  rep(i, 100010)
  {
    Max = max(Max, cnt[i]);
  }
  cout << Max << endl;
  return 0;
}


Measured memory_bytes: 640
n, k = map(int, input().split())
ab = []
for _ in range(n):
    a, b = map(int, input().split())
    ab.append([a, b])
ab.sort(key=lambda x: x[0])

for a, b in ab:
    k -= b
    if k <= 0:
        ans = a
        break
print(ans)

Measured memory_bytes: 25208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long int ll;
typedef unsigned long long int ull;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  string s,t="Yes";
  cin >>s;
  if(s[0]==s[1]&&s[1]==s[2])t="No";
  cout <<t;
}

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

using namespace std;

int main()
{
    vector<pair<string, pair<int,int>>>list;
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
  {
      string s;
      cin>>s;
      int num;
      cin>>num;
      list.push_back(make_pair(s, make_pair(-num, i + 1)));
  }
  sort(list.begin(),list.end());
  for(int j=0;j<n;j++)
  {
      cout<<list[j].second.second<<endl;
  }


}


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

int main() {
  int x, y;
  cin >> x;
  y = x;
  
  // 桁数
  int n = 1;
  while(y >= 10){
  	y /= 10;
    n++;
  }
  
  vector<int> vec(n+1);
  int sum = 0;
  
  if (n > 1) {
     for (int i = 0; i < n; i++) {
       if(i == 0){
         vec.at(i) = x/10;
         sum += x % 10;
       } else {
         vec.at(i) = vec.at(i-1)/10;
         sum += vec.at(i-1) % 10;
       }
       
       //if(vec.at(i) < 10) sum += vec.at(i);
     }
  } else {
  	sum = x;
  }
  
  if (x % sum == 0){
  	cout << "Yes" << endl;
  } else {
  	cout << "No" << endl;
  }
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n+10];

  bool flag = false;
  bool even = true;
  int cnt = 0;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    if(a[i] < 0){
      cnt++;
      a[i] = abs(a[i]);

    }
  }
  if(cnt % 2 == 0){
    long long int sum = 0;
    for(int i = 1; i <= n; i++)sum += a[i];
    cout << sum <<endl;
    return 0;
  }else if(cnt % 2 != 0){
    sort(a+1, a+n+1);
    long long int sum = 0;
    for(int i = 2; i <= n; i++)sum += a[i];
    cout << sum - a[1] <<endl;
    return 0;
  }


  
}

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

int main()
{
    ios::sync_with_stdio(false);
    int n,x,ans=0;
    vector<int> l(n), d {0};

    cin >> n>>x;

    for(int i =0;i<n;i++){
        cin>>l[i];
    }

    for(int i =1;i<n+1;i++){
        // cout<<d[i-1]+l[i-1]<<endl;;
        d.push_back(d[i-1]+l[i-1]);
    }

    for (auto ele:d){
        if(ele<=x){
            ans++;
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k;
	cin >> n >> k;
	vector<int> a(n+1);
	for(int i=1; i<=n; ++i) cin >> a[i]; 
	for(int i=k+1; i<=n; ++i){
		cout << (a[i]>a[i-k]? "Yes" : "No") << endl;
	}
}

Measured memory_bytes: 4052
# coding: utf-8

A, B = [int(i) for i in input().split()]

def count_1(bi, idx):
    bi = bi[::-1]
    cnt = 0
    if idx > 0:
        for i in range(0, idx):
            cnt += int(bi[idx]) * int(bi[i]) * int(2**i)
    if idx < (len(bi) - 1):
        for i in range(idx + 1, len(bi)):
            cnt += int(bi[i]) * int(2**i) / 2
    cnt += int(bi[idx])        
    return(int(cnt))

a = str(bin(max(A-1, 0)))[2:]
b = str(bin(B))[2:]
a = (len(b) - len(a)) * "0" + a # 長さ調整

def count_1s(bi):
    return([count_1(bi, i) for i in range(len(bi))[::-1]])

a_cnt = count_1s(a)
b_cnt = count_1s(b)


print(int("".join([str((i - j) % 2) for i, j in zip(b_cnt, a_cnt)]), 2))


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int[] a=new int[555];
        int[] b=new int[555];
        int[] c=new int[555];
        int m=0;
        while(true){
            a[m]=scan.nextInt();
            b[m]=scan.nextInt();
            c[m]=scan.nextInt();
            if(a[m]==-1&&b[m]==-1&&c[m]==-1) break;
            m++;
        }
        m=0;
        while(true){
            if(a[m]==-1||b[m]==-1) System.out.println("F");
            else if(a[m]+b[m]>=80) System.out.println("A");
            else if(a[m]+b[m]>=65) System.out.println("B");
            else if(a[m]+b[m]>=50) System.out.println("C");
            else if(a[m]+b[m]>=30){
                if(c[m]>=50) System.out.println("C");
                else System.out.println("D");
            }
            else System.out.println("F");
            m++;
            if(a[m]==-1&&b[m]==-1&&c[m]==-1) break;
        }
    }
}


Measured memory_bytes: 26448
#include<stdio.h>
int main()
{
  int sum,y,m,d,i,a,j;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    //printf("%d %d\n",a,i);///
    scanf("%d %d %d",&y,&m,&d);
    sum=0;
    for(j=y+1;j<1000;j++){
      if(j%3==0)sum+=200;
      else sum+=195;
    }
    if(y%3!=0){
      for(j=m+1;j<11;j++){
	if(j%2==0)sum+=19;
	else sum+=20;
      }
      if(m%2==0)sum+=19-d+1;
      else sum+=20-d+1;
    }else{
      for(j=m+1;j<11;j++)sum+=20;
      sum+=20-d+1;
    }
    printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 1024
m=2019
l,r=map(int,input().split())

if l==0 or l//m<r//m or l%m==0:
  print(0)
  exit()

import numpy as np
lr=m
for ii in np.arange(l,r):
  for jj in np.arange(ii+1,r+1):
    t=((ii%m)*(jj%m))%m
    if t==0:
        print(0)
        exit()
    if t<lr:
      lr=t
print(lr)

Measured memory_bytes: 12504
#include <iostream>

using namespace std;

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    putchar(s1[0] - 32);
    putchar(s2[0] - 32);
    putchar(s3[0] - 32);
    cout << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int absMax = 0, absMaxI = 0;
    rep(i,n) if ( chmax(absMax, abs(a[i]) )) absMaxI = i;

    cout << 2 * n - 2 << endl;
    rep(i,n){
        if (absMaxI != i) {
            printf("%d %d\n", absMaxI+1, i+1);
            a[i] += absMax;            
        }
    }
    if (a[absMaxI] < 0){
        for(int i = n-1; i > 0; i--){
            printf("%d %d\n", i+1, i);
            a[i-1] += a[i];
        }
    }else{
        for(int i = 1; i < n; i++){
            printf("%d %d\n", i, i+1);
            a[i] += a[i-1];
        }
    }
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>

using namespace std;

typedef long long ll;

int main() {
	bool S[13] = {0}, H[13] = {0}, C[13] = {0}, D[13] = {0};
	int n; cin >> n;
	for (int i = 0; i < n; ++i) {
		char c; cin >> c;
		int x; cin >> x;
		if (c == 'S') S[x-1] = true;
		if (c == 'H') H[x-1] = true;
		if (c == 'C') C[x-1] = true;
		if (c == 'D') D[x-1] = true;
	}
	for (int i = 0; i < 13; ++i) {
		if (!S[i]) cout << 'S' << " " << (i+1) << endl;
	}
	for (int i = 0; i < 13; ++i) {
		if (!H[i]) cout << 'H' << " " << (i+1) << endl;
	}
	for (int i = 0; i < 13; ++i) {
		if (!C[i]) cout << 'C' << " " << (i+1) << endl;
	}
	for (int i = 0; i < 13; ++i) {
		if (!D[i]) cout << 'D' << " " << (i+1) << endl;
	}
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

void solve()
{
  // ll n; cin >> n;
  ll k, a, b; cin >> k >> a >> b;
  // string s; cin >> s;
  // vector<ll> a(n); REP(i, n) cin >> a[i];
  ll ans = 1;
  // bool ok = false;
  if(b - a <= 1) {
    ans = k + 1;
  } else if(k >= a - 1) {
    ans += a - 1;
    k -= a - 1;
    ans += (k / 2) * (b - a) + k % 2; 
  } else {
    ans = a + 1;
  }
  cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;}
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
int max(int a , int  b){
  if(a > b) return a;
  else return b;

}
int min(int a , int b){
  if(a < b) return a;
  else return b;
}
bool cmp(pair < int , string >   a , pair < int , string >   b){
  if(a.first < b.first ) return true;
  else return false;
}
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int32_t main(){  
  fast;
    int a,b;
    cin >> a >> b;
    cout << a*b << "\n";
  return 0;
} 


/*

WB14D0028763

  4
3 5 7
1111
4 4 10
0110
4 3 4
1010
4 3 4
1100

111



3
3 5 4
101

2*k1 <=k2 
11111
8 10
11111 0 
5 5 05
111
k2 k2 k2 

10 12
126


3 

00001110000

000111000111
1111100
1110011

11101 10 01 00
0
k1 k1 k2 

*/
/*
1
[-5,3,-5],-3,1]

[-2,4,2,5,-5]
5
0 -1 2 -1 3
*/

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
6
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
)");
#define cin input
#endif

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

	multimap<int, int, greater<int>> m;

	REP (i, n)
	{
		int a, b;
		cin >> a >> b;
		m.emplace(a + b, a - b);
	}

	ll r = 0;
	int t = 1;

	for (auto& p : m)
	{
		r += (p.first * t + p.second) / 2;
		t *= -1;
	}

	cout << r << endl;

	return 0;
}


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

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


Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

ll A, B, C;

void solve() {
	cin >> A >> B >> C;
	cout << min(C, A + B + 1) + B << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    uint maximum(uint a, uint b)
    {
        return a > b ? a : b;
    }
    uint maximum(uint a, uint b, uint c)
    {
        return maximum(a, maximum(b, c));
    }
    uint minimum(uint a, uint b)
    {
        return a < b ? a : b;
    }
    uint minimum(uint a, uint b, uint c)
    {
        return minimum(a, minimum(b, c));
    }
    void solve()
    {
        string[] buf = Console.ReadLine().Split(' ');
        uint H = uint.Parse(buf[0]);
        uint W = uint.Parse(buf[1]);
        uint answer = uint.MaxValue;

        //if (H > W)
        //{
        //    uint temp = H;
        //    H = W;
        //    W = temp;
        //}

        if (H % 3 == 0 || W % 3 == 0)
        {
            answer = 0;
        }

        if (answer == uint.MaxValue)
        {
            for (int i = 0; i < 2; ++i)
            {
                uint A = 0, B1 = 0, B2 = 0, diff1 = 0;
                for (uint w = W / 3 <= 3 ? 1 : W / 3 - 3; w < W / 3 + 3; ++w)
                {
                    A = H * w;
                    if ((W - w) % 2 == 0)
                    {
                        B1 = B2 = H * ((W - w) / 2);
                    }
                    else if (H % 2 == 0)
                    {
                        B1 = B2 = (H / 2) * (W - w);
                    }
                    else if (W - w < H)
                    {
                        B1 = (H / 2 + 1) * (W - w);
                        B2 = (H / 2) * (W - w);
                    }
                    else
                    {
                        B1 = H * ((W - w) / 2 + 1);
                        B2 = H * ((W - w) / 2);
                    }
                    diff1 = maximum(A, B1, B2) - minimum(A, B1, B2);
                    if (diff1 < answer) answer = diff1;
                }
                {
                    uint temp = H;
                    H = W;
                    W = temp;
                }
            }
        }

        Console.WriteLine(answer);
    }

    public static int Main()
    {
        bool loop = false;
#if ES_DEBUG
        loop = true;
#endif
        do
        {
            new Program().solve();
        } while (loop);
        return 0;
    }
}


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

int a, b, c;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin >> a >> b >> c;
	if(c < a)
		swap(a, c);
	if(c < b)
		swap(b, c);
	if(b < a)
		swap(a, b);
	
	int t = (c - b);
	a += t;
	if((c - a) % 2 == 0)
		cout << t + (c - a) / 2;
	else
		cout << 1 + t + (c + 1 - a) / 2;	
	
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	int sum = 0;
	for (int& x : A) {
		cin >> x;
		sum += x;
	}
	int c = 0;
	for (int x : A) {
		if (4*M*x >= sum) ++ c;
	}
	cout << (c >= M ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
H, W, A, B = map(int, input().split())
for i in range(B):
	for i in range(A):
		print(0,end='')
	for i in range(W-A):
		print(1,end='')
	print()
for i in range(H-B):
	for i in range(A):
		print(1,end='')
	for i in range(W-A):
		print(0,end='')
	print()

Measured memory_bytes: 5364
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            final int n = sc.nextInt();
            final int a = sc.nextInt();
            final int b = sc.nextInt();

            long pow = pow(2, n, 1000000007);
            long nca = nCr(n, a, 1000000007);
            long ncb = nCr(n, b, 1000000007);

            long result = pow - 1;
            result = result - nca;
            if (result < 0) {
                result += 1000000007;
            }
            result = result - ncb;
            if (result < 0) {
                result += 1000000007;
            }
            System.out.println(result);

        } finally {
            sc.close();
        }
    }

    public static long nCr(int n, int r, int mod){
        long num = 1;
        for (int i=1; i<=r; i++) {
            num *= n;
            num %= mod;
            n--;
        }

        long invr = pow(factorial(r, mod), mod - 2, mod);

        return num * invr % mod;
    }

    public static long modinv(long a, long mod) {
        return pow(a, mod - 2, mod);
    }

    public static long pow(long a, long x, long mod) {
        if (x == 0) {
            return 1;
        } else if (x % 2 == 0) {
            long tmp = pow(a, x/2, mod);
            return (tmp * tmp) % mod;
        } else {
            return (a * pow(a, x-1, mod)) % mod;
        }
    }

    public static long factorial(long n, long mod) {
        long result = 1;
        for (long i=n; i>0; i--) {
            result *= i;
            result %= mod;
        }
        return result;
    }
}


Measured memory_bytes: 23892
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
const int M = 400005 ;
using namespace std;
inline int read(){
	char c=getchar();int x=0,w=1;
	while(c>'9'||c<'0'){ if(c=='-') w=-1; c=getchar();}
	while(c>='0'&&c<='9'){ x=x*10+c-'0'; c=getchar() ;}
	return x*w;
}
int n,m;
int p[M],f[M],Ans;
int find(int x){
	if(f[x]!=x) f[x]=find(f[x]);
	return f[x];
}
int main(){
	n = read(); m = read();
	for(int i=1;i<=n;i++)  {
	    p[i] = read();
	    f[i] = i ;
	}
	for(int i=1;i<=m;i++){
		int x = read(), y = read();
		int r1=find(x);
		int r2=find(y);
		f[r1]=r2;
	}
	for(int i=1;i<=n;i++){
		int r1=find(p[i]);
		int r2=find(i);
		if(r1==r2) Ans++;
	}
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
C = input()
l = 0
r = N-1
ans = 0
while l < r:
    while l < r and C[l] == "R":
        l += 1
    while l < r and C[r] == "W":
        r -= 1
    if l >= r:
        break
    l += 1
    r -= 1
    ans += 1
print(ans)


Measured memory_bytes: 9480
#include <bits/stdc++.h>
#define debug(...)
#include <complex.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = (int) s.size();
  vector<int> a(n + 1);
  for (int i = 0; i < n; i++) {
    if (s[i] == '<') {
      a[i + 1] =a[i] + 1;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '>') {
      a[i] = max(a[i], a[i + 1] + 1);
    }
  }
  debug(a);
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    ans += a[i];
  }
  cout << ans << '\n';
  return 0;
}


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

int main(){
  int n;
  long long sumx=0;
  cin>>n;
  vector<long long>  v(n);
  rep(i,n){
    cin>>v.at(i);
    sumx+=v.at(i);
  }
  long long sum=sumx/2;
  sumx=0;
  for(int i=1;i<n;i+=2){
    sumx+=v.at(i);
  }
  sumx=sum-sumx;
  cout<<sumx*2;
  rep(i,n-1){
    sumx=v.at(i)-sumx;
    cout<<" "<<sumx*2;
  }
}

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

const int MAXN = 1e5 + 10;

int n, a[MAXN], f[MAXN];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    for (int i = 1; i <= n; ++i) f[i] = 0x3f3f3f3f;
    f[0] = 0, f[1] = 0;
    for (int i = 1; i <= n; ++i) f[i + 1] = min(f[i + 1], f[i] + abs(a[i + 1] - a[i])), f[i + 2] = min(f[i + 2], f[i] + abs(a[i + 2] - a[i]));
    printf("%d\n", f[n]);
    return 0;
}

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

int main(){
  int H,W;
  cin>>H>>W;
  vector<string> S(H);
  for(int i=0;i<H;i++){
    string s;
    cin>>s;
    S[i]=s;
  }


  char A[H][W];

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S[i][j]=='#'){
        cout<<'#';
      }else{
        int count = 0 ;
        for(int dx=-1;dx<=1;dx++){
          for(int dy=-1;dy<=1;dy++){
            if(dx==0 && dy==0){
              continue;
            }
            int x = i+dx;
            int y = j+dy;
            if(0<=x&&x<H&&0<=y&&y<W){
                if(S[x][y]=='#'){
                  count++;
                }
            }
          }
        }
        cout<<count;
      }
    }cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();

    let mut min: usize = 0;
    let mut max: usize = n+1;

    for _ in 0..m {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        let l: usize = iter.next().unwrap().parse().unwrap();
        let r: usize = iter.next().unwrap().parse().unwrap();

        min = std::cmp::max(min, l);
        max = std::cmp::min(max, r);
    }

    println!("{}", if min > max {
        0
    }
    else {
        max - min + 1
    });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  int n,a;
  cin >> n >> a;
  cout << n*n - a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

const int N = 1e6 + 5;
int arr[N];

int spf[N]; 
map<int,int>fact;
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<N; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<N; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<N; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<N; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
void  getFactorization(int x) 
{ 
    set<int> ret; 
    while (x != 1) 
    { 
        ret.insert(spf[x]); 
        x = x / spf[x]; 
    } 
    for(auto i:ret){
        fact[i]++;
    }
} 
  
int32_t main() {

    fast
    int n;
    cin >> n;
    sieve();
    cin >> arr[0];
    int gcd = arr[0];
    getFactorization(arr[0]);
    for(int i = 1; i < n; i++) {
        cin >> arr[i];
        getFactorization(arr[i]);
        gcd = __gcd(arr[i], gcd);
    }
    bool flag=true;
    for(auto i:fact){
        if(i.second>=2){
            flag=false;
            break;
        }
    }
    if(gcd == 1 && flag) {
        cout << "pairwise coprime";
    } else if(gcd == 1 && !flag) {
        cout << "setwise coprime";
    } else {
        cout << "not coprime";
    }







    return 0;
}



Measured memory_bytes: 24148
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

for i in range(ceil(N**(1/2)), 0, -1):
	if N % i == 0:
		a = i
		b = N//i
		break

print(a-1+b-1)


Measured memory_bytes: 5716
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, = map(int, input().split())
# data = getInputListInt()

if n % 2 == 0:
    ans = int(n / 2)
    ans = int(ans  * (n - 1))
else:
    ans = int((n - 1) / 2)
    ans = int(ans * n)

print(ans)



Measured memory_bytes: 13664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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 EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
  ll N;
  cin >> N;
  ll ans = 1e15;
  for(ll i = 1; i * i <= N; i++) {
    if(N % i != 0) continue;
    chmin(ans, i + N / i - 2);
  }
  cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
            out.flush();
        }
    }

    void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] ws = new int[n + 1];
        int sum = 0;
        ws[0] = 0;
        for (int i = 1; i <= n; i++) {
            int w = in.nextInt();
            sum += w;
            ws[i] = w + ws[i - 1];
        }

        int ans = 1 << 29;
        for (int i = 1; i < n; i++) {
            ans = Math.min(ans, Math.abs((sum - ws[i]) - ws[i]));
        }

        out.println(ans);
    }
}

class InputReader implements AutoCloseable {
    private final Scanner sc = new Scanner(System.in);

    String next() {
        return this.sc.next();
    }

    int nextInt() {
        return Integer.parseInt(this.sc.next());
    }

    long nextLong() {
        return Long.parseLong(this.sc.next());
    }

    double nextDouble() {
        return Double.parseDouble(this.sc.next());
    }

    @Override
    public void close() {
        this.sc.close();
    }
}


Measured memory_bytes: 21844
#include<queue>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include <cstring>
#include <string.h>
#include <cmath>
#include <math.h>
#include <time.h>
#define ll long long
#define N 100003
#define M 103
#define db double
#define P putchar
#define G getchar
#define inf 998244353
using namespace std;
char ch;
void read(int &n)
{
	n=0;
	ch=G();
	while((ch<'0' || ch>'9') && ch!='-')ch=G();
	ll w=1;
	if(ch=='-')w=-1,ch=G();
	while('0'<=ch && ch<='9')n=(n<<3)+(n<<1)+ch-'0',ch=G();
	n*=w;
}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
ll abs(ll x){return x<0?-x:x;}
ll sqr(ll x){return x*x;}
void write(ll x){if(x>9) write(x/10);P(x%10+'0');}

int n,a[N],ans,s;
bool pd; 

int gcd(int x,int y){return y==0?x:gcd(y,x%y);}

bool dfs(int x)
{
	s=pd=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1)pd=1;
		if(a[i]&1)s++;
	}
	
	if((n-s)&1)return x;
	if(pd || s>1)return !x;
	
	for(int i=1;i<=n;i++)
		if(a[i]%2)
		{
			a[i]--;
			break;
		}
	
	int gc=a[1];
	for(int i=2;i<=n;i++)
		gc=gcd(gc,a[i]);
	for(int i=1;i<=n;i++)
		a[i]/=gc;
	return dfs(!x);
}

int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	
	read(n);
	for(int i=1;i<=n;i++)
		read(a[i]);
	
	if(dfs(1))puts("First");
		else puts("Second");
	
	return 0;
}


Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var s1, s2 string
	fmt.Scan(&s1, &s2)

	if s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  ll A;
  double B;
  cin >> A >> B;
  ll C = ll(B * 100 + 0.05);
  
  cout << ll(A*C/100) << endl;
}



Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define Endl cout << endl
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool substring_search(string s,string key){
    int count=0;
    for(int i=0;i<(int)s.size();i++){
        if(s[i]==key[count]) count++;
        if(count==(int)key.size()) return true;
    }
    return false;
}

int main()
{
    ll n,ans=0;
    string a[]={"0","1","2","3","4","5","6","7","8","9"};
    string s;
    cin >> n >> s;
    rep(i,10){
        rep(j,10){
            rep(k,10){
                string key=a[i]+a[j]+a[k];
                if(substring_search(s,key)) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

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

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N; cin >> N;
  ll result[N] = {};
  repr(i,1,N) { ll A; cin >> A; A--; result[A]++; }
  rep(i,N) cout << result[i] << endl;
}

Measured memory_bytes: 5192
#include <iostream>
#include <string>
#include <vector>

void split( std::vector<std::string> &list, std::string string, std::string separator )
{
  auto separator_length = separator.length();
  if ( separator_length == 0 )
  {
    list.push_back( string );
  } else {
    auto offset = std::string::size_type( 0 );
    while( 1 )
    {
      auto pos = string.find( separator, offset );
      if( pos == std::string::npos )
      {
        list.push_back( string.substr( offset ) );
        break;
      }
      list.push_back( string.substr( offset, pos - offset ) );
      offset = pos + separator_length;
    }
  }
}

template<typename T>
T min( T a, T b )
{
  return ( a < b ) ? a : b;
}

template<typename T>
T max( T a, T b )
{
  return ( a > b ) ? a : b;
}

int main(void)
{
  int N;
  std::cin >> N;
  
  if( N < 10 ) {
    std::cout << N << std::endl;
  } else if( N < 1000 ) {
    std::cout << 9 + max( N - 100 + 1, 0 ) << std::endl;
  } else if( N < 100000 ) {
    std::cout << 9 + 900 + max( N - 10000 + 1, 0 ) << std::endl;
  } else {
    std::cout << 90909;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int h[n];
  for(int i=0;i<n;i++)
  {
    cin>>h[i];
  }
  int count=1;
  int max=h[0];
  for(int i=1;i<n;i++)
  {
    if(h[i]>=max)
    {
      count++;
      max=h[i];
    }
  }
  cout<<count;
  return 0;
}

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

int main() {
	int in;
	int fy = 0, fm = 0;
	cin >> in;
	if (in / 100 > 0 && in / 100 < 13)fy++;
	if (in % 100 > 0 && in % 100 < 13)fm++;
	if (fy == 1 && fm == 1)cout << "AMBIGUOUS\n";
	else if (fm == 1)cout << "YYMM\n";
	else if (fy == 1)cout << "MMYY\n";
	else cout << "NA\n";




}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]

// language: Rust(1.42.0)
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"
// My Library Repo' is at "https://github.com/Loptall/prcn_lib"

/*
    6月で水色になるぞ〜!!!
*/

// from std...
use std::cmp::{
    max, min,
    Ordering::{Equal, Greater, Less},
};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;
use std::ops::*;
use std::process::exit;
use std::{f32, f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

// Dep' crates are...
use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_complex::Complex;
use num_integer::{binomial, gcd, lcm, Integer};
use num_rational::Rational;
use num_traits::{one, zero, One, Zero};
use permutohedron::Heap;
use petgraph::unionfind::UnionFind;
use proconio::{fastout, input, is_stdin_empty, marker::*};
use rand::random;

pub const MOD: usize = 1000000007;
pub const MAX: usize = 1usize << 63usize;
pub const MIN: i64 = i64::MIN;
pub const PI: f64 = f64::consts::PI;
pub const A: u8 = 'A' as u8;

// code...
// #[fastout]
fn main() {
    input! {
        a: i64, v: i64,
        b: i64, w: i64,
        t: i64
    }

    let ans = if (a - b).abs() <= (v - w) * t {
        "YES"
    } else {
        "NO"
    };

    println!("{}", ans);
}


Measured memory_bytes: 2128
#include <stdio.h>
int main()
{
	int N, A, B;
	
	scanf("%d %d %d", &N, &A, &B);
	
	if( A >= B)
	{
		if ( A + B >= N) printf("%d %d", B, A+B-N);
		else printf("%d 0", B);
	}
	
	else
	{
		if ( A + B >= N) printf("%d %d", A, A+B-N);
		else printf("%d 0", A);
	}
	
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define N 25

typedef struct {
  int parent;
  int left;
  int right;
} Node;

Node Tree[N];

int getSibling(int x) {
  int sibling = -1;
  if(Tree[x].parent == -1) return -1;
  if(Tree[Tree[x].parent].left != -1 && Tree[Tree[x].parent].left != x)
     sibling = Tree[Tree[x].parent].left;
  if(Tree[Tree[x].parent].right != -1 && Tree[Tree[x].parent].right != x)
     sibling = Tree[Tree[x].parent].right;
  return sibling;
}

int getDegree(int x) {
  int degree = 0;
  if(Tree[x].left != -1) degree++;
  if(Tree[x].right != -1) degree++;
  return degree;
}

int getDepth(int x) {
  int depth = 1;
  if(Tree[x].parent == -1) return 0;
  depth += getDepth(Tree[x].parent);
  return depth;
}

int getHeight(int x) {
  int heightL = 0, heightR = 0;
  if(Tree[x].left == -1 && Tree[x].right == -1)  return 0;
  if(Tree[x].left != -1)heightL = getHeight(Tree[x].left);
  if(Tree[x].right != -1)heightR = getHeight(Tree[x].right);
  if(heightL >= heightR) return 1 + heightL;
  else return 1 + heightR;
}

int main() {
  int n, i;
  int id, sibling, degree, depth, height;

  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    Tree[i].parent = -1;
    Tree[i].left = -1;
    Tree[i].right = -1;
  }
  for(i = 0; i < n; i++) {
    scanf("%d", &id);
    scanf("%d", &Tree[id].left);
    if(Tree[id].left != -1) Tree[Tree[id].left].parent = id;
    scanf("%d", &Tree[id].right);
    if(Tree[id].right != -1)Tree[Tree[id].right].parent = id;
  }

  for(i = 0; i < n; i++) {
    sibling = getSibling(i);
    degree = getDegree(i);
    depth = getDepth(i);
    height = getHeight(i);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
            i, Tree[i].parent, sibling, degree, depth, height);
    if( Tree[i].parent == -1) printf("root\n");
    else if(Tree[i].right == -1 && Tree[i].left == -1) printf("leaf\n");
    else  printf("internal node\n");
  }

  return 0;
}

Measured memory_bytes: 612
#!/usr/bin/env python

from sys import stdin

N = int(stdin.readline())
P = [int(wd) for wd in stdin.readline().split()]
Q = [int(wd) for wd in stdin.readline().split()]

def kaijou(n):
    if n == 1:
        return 1
    return n * kaijou(n-1)

def convert(R, R0):
    if len(R) == 1:
        return 0
    n = R0.index(R[0])
    nR = R[1:]
    nR0 = list(R0)
    del nR0[n]
    return n * kaijou(len(nR)) + convert(nR, nR0)

p = convert(P, list(range(1, N+1)))
q = convert(Q, list(range(1, N+1)))

print(abs(p - q))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int s;
  cin >> s;
  map<int, int> mp;
  mp[s]++;
  int now = s;
  int i = 1;
  while(1) {
    i++;
    if (now%2) now = 3*now+1;
    else now = now/2;
    if (mp[now]) {
      cout << i << endl;
      return 0;
    }
    else {
      mp[now]++;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int min(int x, int y){return x<y?x:y;}
int max(int x, int y){return x<y?y:x;}
int main(void){
	int n,i,a,l,r;
	scanf("%d",&n);
	scanf("%d",&a);
	l = a;
	r = a;
	for(i=1;i<n;i++){
		scanf("%d",&a);
		l = min(l,a);
		r = max(r,a);
	}
	printf("%d",r-l);
	return 0;
}

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

int main() {
  int n; cin >> n;
  string s; cin >> s;

  int ans = 0;
  for (int i=1; i<n; i++) {
    int cnt = 0;
    for (char c='a'; c<='z'; c++) {
      bool left=false, right=false;

      for (int j=0; j<i; j++) 
        if (s[j] == c) left = true;

      for (int j=i; j<n; j++)
        if (s[j] == c) right = true;

      if (left&&right) cnt++; 
    }
    if (ans < cnt) ans = cnt;
  }

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

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 2e5 + 10;
const ll mod = 1e9 + 7;
int main()
{
	int n;
	ll cur, sum = 0, tmp = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) 
	{
		scanf("%lld", &cur);
		sum += cur * tmp % mod; sum %= mod;
		tmp += cur; tmp %= mod;
	}
	cout << sum << endl;
		
	return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios::sync_with_stdio(0),cin.tie(0);
char a[101][101];
int main()
{
  fastio();
	int r, c;
	cin >> r >> c;
	for (int i = 0; i < r; i++)cin >> a[i];
	for (register int i = 0; i < r; i++)
	{
		bool erase = true;
		for (register int j = 0; j < c;j++)
		{
			if (a[i][j] == '#')
			{
				erase = false;
				break;
			}
		}
		if (erase)continue;
		for (register int j = 0; j < c; j++)
		{
			erase = true;
			for (register int k = 0; k < r; k++)
			{
				if (a[k][j] == '#')
				{
					erase = false;
					break;
				}
			}
			if (!erase)cout << a[i][j];
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
    int n;
  cin>>n;
  double k=sqrt(n);
  int p=k;
  cout<<p*p;
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
A = set()
B = set()
for i in range(M):
  a,b = input().split()
  if a =='1':
    A.add(b)
  if b == str(N):
    B.add(a)
if A&B:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Measured memory_bytes: 29616
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
    ll a,v,b,w,t;cin>>a>>v>>b>>w>>t;
    if(w>v)cout<<"NO\n";
    else if(w==v){
        if(a==b)cout<<"YES";
        else cout<<"NO";
    }
    else if((v-w)*t>=abs(b-a))cout<<"YES\n";
    else cout<<"NO\n";
 
return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  bool f = true;
  rep(i, N) {
    cin >> a.at(i);
    if (a.at(i) != 0)
      f = false;
  }

  if (f) {
    puts("Yes");
    return 0;
  } else if (N % 3 == 0) {
    sort(a.begin(), a.end());
    int x = a.at(0), y = a.at(N / 3), z = a.at(2 * N / 3);
    for (int i = 0; i < N / 3; i++) {
      if (a.at(i) != x)
        x = -1;
    }
    for (int i = N / 3; i < 2 * N / 3; i++) {
      if (a.at(i) != y)
        y = -1;
    }
    for (int i = 2 * N / 3; i < N; i++) {
      if (a.at(i) != z)
        z = -1;
    }

    if (x == -1 || y == -1 || z == -1) {
      puts("No");
      return 0;
    } else {
      if ((x == y && x != z) || (y == z && y != x) || (z == x && z != y)) {
        puts("Yes");
        return 0;
      } else if ((x != y && y != z && z != x) && ((x ^ y ^ z) == 0)) {
        puts("Yes");
        return 0;
      } else {
        puts("No");
      }
    }
  } else {
    puts("No");
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  long double X,Y;
  cin >> X >> Y;
  ll p=log2(Y/X);
  cout << p + 1 << endl;  
  return 0;
    

}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  int k;
  cin>>k;
  int x=7%k;
  for(int i=1;i<=k;++i){
    if(x==0){
      return cout<<i<<endl,0;
    }
    x=(x*10+7)%k;
  }
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 3628
def main():
  from collections import deque
  s,*c=open(0)
  h,w=map(int,s.split())
  f=[-1]*h*w
  q=deque()
  for i,c in enumerate(''.join(t[:w]for t in c)):
    if c=='#':
      q.append(i)
      f[i]=0
  while q:
    i=q.popleft()
    v=f[i]+1
    j,k,l,m,u=i+w,i-w,i+1,i-1,i%w
    if h*w>j and f[j]<0:
      q.append(j)
      f[j]=v
    if k>=0 and f[k]<0:
      q.append(k)
      f[k]=v
    if w>u+1and f[l]<0:
      q.append(l)
      f[l]=v
    if u and f[m]<0:
      q.append(m)
      f[m]=v
  print(v-1)
if __name__=='__main__':
  main()

Measured memory_bytes: 88652
package main

import (
  "fmt"
)

func main() {
  var s string 
  fmt.Scan(&s)
  res := "Yes"
  for i, c := range s {
    if i & 1 == 0 {
      if c == 'L' {
        res = "No"
        break
      }
    } else {
      if c == 'R' {
        res = "No"
        break
      }
    }
  }
  fmt.Println(res)
}

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

int main(void)
{
	string str;
	cin >> str;
	str += 'A';
	
	int ret = 0;
	int j = 0, o = 0, i = 0;
	for (int cnt = 0; cnt < str.size(); cnt++){
		if (str[cnt] == 'J'){
			j++;
			if (str[cnt + 1] == 'I') j = 0;
		}
		if (str[cnt] == 'O'){
			o++;
			if (str[cnt + 1] == 'J') j = o = 0;
		}
		if (str[cnt] == 'I'){
			i++;
			if (str[cnt + 1] != 'I'){
				if (o <= j && o <= i) ret = max(ret, o);
				j = o = i = 0;
			}
		
		}
	}
	
	cout << ret << endl;
	
	return 0;
}

Measured memory_bytes: 2000
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;


int calc_route(vector<int> route, vector<int> choice, const vector<double> &x, const vector<double> &y, double &sum, int &route_pattern)
{
	if (route.size() == x.size()){
		//calc

		double distance = 0.0;
		for (size_t i = 0; i + 1 < route.size(); i++){
			//cout << route[i];

			double x1 = x[route[i]];
			double y1 = y[route[i]];
			double x2 = x[route[i + 1]];
			double y2 = y[route[i + 1]];

			distance += sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
		}

		//cout << endl;

		sum += distance;
		route_pattern++;
	}
	else{
		//Choose from the rest
		for (size_t i = 0; i < choice.size(); i++){
			vector<int> next_route = route;
			vector<int> next_choice = choice;

			next_route.push_back(next_choice[i]);
			next_choice.erase(next_choice.begin() + i);

			calc_route(next_route, next_choice, x, y, sum, route_pattern);
		}
	}

	return 0;
}




int main(int argc, char *argv[])
{
	int n;

	//input
	cin >> n;

	vector<double> x;
	vector<double> y;
	for (int i = 0; i < n; i++){
		double xi, yi;
		cin >> xi >> yi;

		x.push_back(xi);
		y.push_back(yi);
	}


	//calc

	vector<int> choice;
	for (int i = 0; i < n; i++){
		choice.push_back(i);
	}
	vector<int> route;
	double sum = 0.0;
	int route_pattern = 0;
	calc_route(route, choice, x, y, sum, route_pattern);
	

	double ans = 0.0;
	ans = sum / route_pattern;


	//ans
	cout << setprecision(10) << ans << endl;



	return 0;
}


Measured memory_bytes: 256