akhauriyash/Code-Regression huggingface dataset:
A,B,K = [int(x) for x in input().split()]

def divisor_list(n):
    ret = set()
    i=1
    while i*i <= n:
        if n % i == 0:
            ret.add(i)
            ret.add(n // i)
        i += 1
    return ret

DA = divisor_list(A)
DB = divisor_list(B)

# print(DA)
# print(DB)
COM = list(set(DA) & set(DB))
COM.sort(reverse=True)
# print(COM)
print(COM[K-1])

Measured memory_bytes: 3064
"""



"""

N, M = map(int, input().split())
#cityの番号を付与して、格納
city = [list(map(int, input().split())) + [i] + [0] for i in range(M)]

city.sort(key=lambda x: (x[0], x[1]))

for m in range(M):
    if m == 0:
        city[m][3] = 1
    elif city[m][0] != city[m - 1][0]:
        city[m][3] = 1
    else:
        city[m][3] = city[m - 1][3] + 1

city.sort(key=lambda x: x[2])

for m in range(M):
    print(str(city[m][0]).zfill(6) + str(city[m][3]).zfill(6))
    

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

#define MOD 10007

int main(){
	int x[1001][3][2][2][2];
	int k[1001];
	int l[3];
	memset(x,0,sizeof(x));
	x[0][0][1][0][0]=1;
	k[0]=0;
	int m,sum=0;
	string S;
	cin>>m;
	cin>>S;
	for(int i=0;i<m;i++){
		if(S[i]=='J'){
			k[i+1]=0;
		}
		else if(S[i]=='O'){
			k[i+1]=1;
		}
		else{
			k[i+1]=2;
		}
	}
	for(int i=1;i<=m;i++){
		if(k[i]==0){
			for(int j=0;j<2;j++){
				for(int n=0;n<2;n++){
					for(int o=0;o<2;o++){
						for(int p=0;p<2;p++){
							for(int q=0;q<2;q++){
								if(((o==1) || (j==1 && p==1)) || (n==1 && q==1)){
									x[i][k[i]][1][j][n] += x[i-1][k[i-1]][o][p][q];
								}
							}
						}
					}
				}
			}
		}
		if(k[i]==1){
			for(int j=0;j<2;j++){
				for(int n=0;n<2;n++){
					for(int o=0;o<2;o++){
						for(int p=0;p<2;p++){
							for(int q=0;q<2;q++){
								if(((j==1 && o==1) || (p==1)) || (n==1 && q==1)){
									x[i][k[i]][j][1][n] += x[i-1][k[i-1]][o][p][q];
								}
							}
						}
					}
				}
			}
		}
		if(k[i]==2){
			for(int j=0;j<2;j++){
				for(int n=0;n<2;n++){
					for(int o=0;o<2;o++){
						for(int p=0;p<2;p++){
							for(int q=0;q<2;q++){
								if(((j==1 && o==1) || (n==1 && p==1)) || (q==1)){
									x[i][k[i]][j][n][1] += x[i-1][k[i-1]][o][p][q];
								}
							}
						}
					}
				}
			}
		}
		for(int o=0;o<2;o++){
			for(int p=0;p<2;p++){
				for(int q=0;q<2;q++){
					x[i][k[i]][o][p][q] %= MOD;
				}
			}
		}
	}
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			for(int n=0;n<2;n++){
				sum += x[m][k[m]][i][j][n];
			}
		}
	}
	cout<<sum%MOD<<endl;
	return 0;
}

Measured memory_bytes: 1312
N=int(input())
a = list(map(int, input().split()))
dic={}
mul = [3,2,1]
res = 1
for i in range(len(a)):
    if a[i] in dic:
        if dic[a[i]] == 2:
            print(0)
            exit()
        dic[a[i]] += 1
    else:
        dic[a[i]] = 0
    if a[i] == 0:
        if dic[0] >= 3:
            print(0)
            exit()
        res *= mul[dic[0]]
    else:
        if a[i]-1 not in dic:
            print(0)
            exit()
        res *= dic[a[i]-1] - dic[a[i]] + 1
    res = res%(10**9+7)
print(res)


Measured memory_bytes: 17400
// C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void){
    ll n,rain;
    cin >> n;
    vll a(n);
    REP(i,n){
        cin >> a[i];
    }
    ll sum = accumulate(a.begin(), a.end(), 0LL) / 2;
    ll sum2 = 0LL;
    for(ll i=1;i<n;i+=2){
        sum2 += a[i];
    }
    rain = sum - sum2;
    cout << rain*2 << endl;
    FOR(i,1,n-1){
        cout << (a[i-1]-rain)*2 << endl;
        rain = a[i-1]-rain;
    }
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define PRINTD(n) printf("%d\n",n)
#define DEBUG printf("%s\n","debug")
using namespace std;
//////////////////////////////////////////////////////
int main(){
	map <int,vector<int>>adj;
	
	int N;
	SCD(N);
	REP(i,N-1){
		int a,b;
		SCD2(a,b);
		
		adj[a].push_back(b);
		adj[b].push_back(a);
		
	}
	
	static int d[100003];
	static int e[100003];
	d[1] = 0;
	e[N] = 0;
	
	bool visited[N+2];
	REP(i,N+2){visited[i] = false;}
	
	queue<int>Q;
	Q.push(1);
	
	visited[1] = true;

	while(!Q.empty()){
		int nowv = Q.front(); Q.pop();
		int v = d[nowv];
		visited[nowv] = true;
		REP(i,adj[nowv].size()){
			int next = adj[nowv][i];
			if (visited[next]) { continue; }
			d[next] = v+1;
			Q.push(next);
		}
		
	}

	REP(i,N+2){visited[i] = false;}
	Q.push(N);
	visited[N] = true;
	
		while(!Q.empty()){
		int nowv = Q.front(); Q.pop();
		int v = e[nowv];
		visited[nowv] = true;
		REP(i,adj[nowv].size()){
			int next = adj[nowv][i];
			if (visited[next]) { continue; }
			e[next] = v+1;
			Q.push(next);
		}
		
	}
	
	int F,S;
	F = 0; S = 0;
	FORq(i,1,N){
		if (d[i] <= e[i]){
			F++;
		}else{
			S++;
		}
	}
	
	if(F>S) printf("Fennec");
	else printf("Snuke");

	return 0;
}






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

int main() {
  char c;
  cin >> c;
  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

static const long long MOD = 1000000007;
static const long long INF = 1<<31;

ll ansa, ansb;
ll x;

int main(void) {
    cin >> x;

    for (ll a=-120; a<=120; a++) for (ll b=-120; b<=120; b++) {
        if (a*a*a*a*a-b*b*b*b*b==x) {
            ansa = a;
            ansb = b;
        }
    }

    printf("%lld %lld\n", ansa, ansb);

	return 0;
}


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

#define ll            long long
#define pb            push_back
#define si            set <int>
#define F             first
#define S             second
#define mii           map<int ,int >
#define msi           map<string,int >
#define mis           map<int , string>
#define fr(i,a,b)     for(int  i=a;i<=b;i++)
#define loop(i,n)     for(int i=0;i<n;i++)
#define all(v)        v.begin(),v.end()
#define vi            vector<int >
#define vii           vector<pair<int , int >>
#define vs            vector<string>
#define sz(x)         (int )x.size()
#define M             1000000007
#define mp            make_pair
#define input(arr,n)  loop(i,n) cin>>arr[i]
#define output(arr,n) loop(i,n) cout<<arr[i]<<" "
#define mod           998244353
#define sof           sizeof
using namespace std;
int gcd(int a,int b){
  if(b==0)return a;
  return gcd(b,a%b);
}

bool isPrime(int num){
    
    if(num==2) return true;
    if(num<2 || num%2==0) return false;
    for(int i = 3; i*i <=num; i+=2) {
       if(num % i == 0) {
          
          return false;
       }
    }
    return true;
   
}

bool comp(const pair<int,int> &a,const pair<int,int> &b){
  return a.F>b.F;
}

  



void solve(){
  
  string s;
  cin>>s;
  int n=sz(s);
  int i=0,j;
  int ans=0;
  while(i<n){
    
    if(s[i]=='R'){
      j=i+1;
      while(s[j]=='R' && j<n){
        j++;
      }

      ans=max(ans,j-i);
      i=j;
    }
    else i++;
  }
  cout<<ans;

}




signed main()   
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); 
  cout.tie(0);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout); 
  #endif  

  int t;
  t=1;
  //cin>>t;
  loop(i,t){

      solve();
      if(i<t-1) cout<<"\n";
  }

  
  
  //directed graph
    



}
  


  



Measured memory_bytes: 3620
#!/usr/bin/env python3
import sys
from itertools import groupby

def solve(N: int, a: "List[int]"):
    group = groupby(a)
    answer = 0
    for key,value in group:
        answer += len(list(value))//2
    print(answer)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
n=int(input())
cnt=0
if(n<10):
    cnt=n
elif(n<100):
    cnt=9
elif(n<1000):
    cnt=(n-99)+9
elif(n<10000):
    cnt=909
elif(n<100000):
    cnt=(n-9999)+909
else:
    cnt=90909
print(cnt)



Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;

#define MOD 998244353


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

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}
  
  

int main(){
    ll n;
    string s;
    cin>>n>>s;
    ll count = 0;
    for(ll i = 0; i<n-2; i++){
        if (s.substr(i,3) == "ABC"){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

    
    



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<time.h>
using namespace std;
#define int long long
#define inf 1e9+7
typedef pair<int, int> P;

int a[114514], b[114514];

signed main() {
	int n, h;
	cin >> n >> h;
	for (int i = 0; i < n; i++)cin >> a[i] >> b[i + 1];
	int am = 0;
	for (int i = 0; i < n; i++)am = max(am, a[i]);

	sort(b, b + n + 1);
	reverse(b + 1, b + n + 1);
	int ta = n;
	for (int i = 0; i < n; i++) {
		if (b[i + 1] >= am) {
			b[i + 1] += b[i];
		}
		else {
			b[i + 1] = 0;
			if (ta == n)ta = i;
		}
	}

	int lb = -1, ub = 1145141919;
	while (ub - lb > 1) {
		int mi = (ub + lb) / 2;
		int dmg = 0;
		dmg = b[min(ta, mi)] + am*max(mi - ta, 0ll);
		if (dmg >= h)ub = mi;
		else lb = mi;
	}
	cout << ub << endl;
}

Measured memory_bytes: 1792
S=input()
T=input()
s=len(S)
t=len(T)
cand=[[] for _ in range(s-t+1)]
#Tの入る場所によって場合分け
for i in range(s-t+1):
  S_can=[S[k] for k in range(s)]
  for j in range(t):
    if S[i+j]!=T[j] and S[i+j]!='?':
      break
  else:
    for k in range(t):
      S_can[i+k]=T[k]
    for k in range(s):
      if S_can[k]=='?':
        S_can[k]='a'
    cand[i]=S_can
ans=[i for i in cand if i!=[]]
if ans==[]:
  print('UNRESTORABLE')
else:
  ans.sort()
  print(*ans[0],sep='')


Measured memory_bytes: 9084
// clang-format off
	#define BADSEED random_device{}()
	#include <bits/stdc++.h>
	using namespace std;
	using ll = long long;
	using uint = unsigned int;
	ostream &operator<<(ostream &os, int8_t c) { return os << short(c); }
	istream &operator>>(istream &is, int8_t &c) { short x; is >> x; c = x; return is; }
	#define TM_(...) template <class __VA_ARGS__>
	namespace narut {
	TM_(T) using TupSz = tuple_size<decay_t<T>>;
	TM_(T) constexpr auto spc(T const &t, int) -> decltype((cout << t), 'a') { return ' '; }
	constexpr auto spc(string const &s, int) { return '\n'; }
	TM_(T) constexpr auto spc(T const &t, char) { return '\n'; }
	struct IO {
		TM_(T) static auto out_(ostream &os, T const &t, int) -> decltype(void(os << t)) { os << t; }
		TM_(T, class OS) static auto out_(OS &os, T const &t, int) -> decltype(void(begin(t))) {
			auto it = begin(t), e = end(t);
			if (it != e) out_(os, *it++, 0);
			for (; it != e; out_(os, *it++, 0)) os << spc(*it, 0);
		}
		TM_(T, size_t... Is) static void out_tup(ostream &os, T const &t, index_sequence<Is...>) { (void)initializer_list<int>{0, ((Is == 0) ? 0 : ((os << ' '), 0), (os << get<Is>(t)), 0)...}; }
		TM_(T) static decltype(void(TupSz<T>{})) out_(ostream &os, T const &t, char) { out_tup(os, t, make_index_sequence<TupSz<T>::value>{}); }
		TM_(Sep, class F, class... Ts) static ostream &print(ostream &os, Sep sep, F const &f, Ts const &... ts) { return void(initializer_list<int>{(out_(os, f, 0), 0), (out_(os << sep, ts, 0), 0)...}), os; }
		TM_(T) static auto in_(istream &is, T &t, int) -> decltype(void(is >> t)) { is >> t; }
		TM_(T, class IS) static auto in_(IS &is, T &t, int) -> decltype(void(begin(t))) { for (auto &x : t) in_(is, x, 0); }
		TM_(T, size_t... Is) static void in_tup(istream &is, T &t, index_sequence<Is...>) { (void)initializer_list<int>{0, (in_(is, get<Is>(t), 0), 0)...}; }
		TM_(T) static decltype(void(TupSz<T>{})) in_(istream &is, T &t, char) { in_tup(is, t, make_index_sequence<TupSz<T>::value>{}); }
	};
	} // namespace narut
	#define Cout(...) narut::IO::print(cout, ' ', __VA_ARGS__) << '\n'
	#ifdef NARUT_LOCAL
	#define Debug(...) narut::IO::print(cerr << "\033[0;31m", ", ", __VA_ARGS__) << "\033[0m\n"
	#else
	#define Debug(...) 0
	#endif
	[[maybe_unused]] struct Cin { 
		template <class T> Cin const &operator>>(T &t) const { return narut::IO::in_(cin, t, 0), *this; }
		template <class T> operator T() const { T t; return *this >> t, t;  }	
	} Cin;
	TM_(T) auto operator%(T &t, size_t n) -> decltype(t.resize(n), t)& { return t.resize(n), t; }
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)

// clang-format on





auto Main() {
	ll k,a,b;
	cin>>k>>a>>b;
	FOR(i,a,b+1) {
		if (i%k==0) return true;
	}
	return false;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	assert(freopen("io/test.in", "r", stdin));
	cin.exceptions(cin.badbit | cin.failbit);
	cerr << fixed << setprecision(10);
#endif

	if(Main()){
		cout << "OK";
	} else cout <<"NG";
}


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

int main() {
	long long int x;cin>>x;
	long long int cnt=0;
	long long int z=100;
	while(1)
	{
	    z=z+z/100;
	    cnt++;
	    if(z>=x)    {
	        cout<<cnt<<endl;  
	        break;
	    }
	}
	return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

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

  vector<string> ss = {"dream", "dreamer", "erase", "eraser"};
  rep(i, 4) {
    reverse(ss[i].begin(), ss[i].end());
  }
  reverse(s.begin(), s.end());
  int n = s.length();
  for (int i = 0; i < n; ) {
    bool ok = false;
    rep(j, ss.size()) {
      int m = ss[j].length();
      if(n - i < m) continue;
      string t = s.substr(i, m);
      if(ss[j] == t) {
        ok = true;
        i += m;
        break;
      }
    }
    if(!ok) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

string cs="01+-*()";
string s;
int n;

int f(int l,int r){
  if(r<=l)return -1;
  bool isn=true;
  repl(i,l,r)if(!isdigit(s[i]))isn=false;
  if(isn){
    int res=0;
    repl(i,l,r){
      res*=2;
      res+=s[i]-'0';
    }
    if(res>=pow(2,10)) return -1;
    else return res;
  }

  bool ok=false;
  int lev=0;
  {
    repl(i,l,r){
      if(s[i]=='(')lev++;
      if(lev==0)ok=true;
      if(s[i]==')')lev--;
    }
  }
  if(lev!=0)return -1;
  if(!ok){
    bool dame=true;
    lev=-1;
    repl(i,l,r){
      if(s[i]=='(')lev++;
      if(s[i]==')')lev--;
      if(lev==0&&(s[i]=='+'||s[i]=='-'||s[i]=='*'))dame=false;
    }
    if(dame)return -1;
    else return f(l+1,r-1);
  }

  lev=0;
  int res=0;
  int pre=l,preop=0;
  repl(i,l,r){
    if(s[i]=='(')lev++;
    if(s[i]==')')lev--;
    if(lev==0&&(s[i]=='+'||s[i]=='-')){
      int v=f(pre,i);
      if(v==-1)return -1;
      if(preop==0)res+=v;
      else res-=v;
      if(res<0||res>=pow(2,10))return -1;
      pre=i+1;
      preop=(s[i]=='+'?0:1);
    }
  }
  if(pre!=l){
    int v=f(pre,r);
    if(v==-1)return -1;
    if(preop==0)res+=v;
    else res-=v;
    if(res<0||res>=pow(2,10))return -1;
    else return res;
  }

  lev=0;
  res=1;
  repl(i,l,r){
    if(s[i]=='(')lev++;
    if(s[i]==')')lev--;
    if(lev==0&&s[i]=='*'){
      int v=f(pre,i);
      res*=v;
      if(v==-1||res>=pow(2,10))return -1;
      pre=i+1;
    }
  }
  if(pre!=l){
    int v=f(pre,r);
    res*=v;
    if(v==-1||res>=pow(2,10))return -1;
    return res;
  }
  return -1;
}

int dfs(int i){
  if(i==n){
    return f(0,n);
  }else{
    if(s[i]=='.'){
      int res=-1;
      rep(j,7){
        s[i]=cs[j];
        int tmp=dfs(i+1);
        maxch(res,tmp);
      }
      s[i]='.';
      return res;
    }else{
      return dfs(i+1);
    }
  }
}

int main(){
  cin>>s;
  n=s.size();
  cout<<dfs(0)<<endl;
  return 0;
}



Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;
template <typename T>
void vecin(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
}
template <typename T>
void vecout(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n - 1; ++i)
    {
        cout << v[i] << " ";
    }
    cout << v[n - 1] << endl;
}

int main()
{
    ciosup;
    int n, k;
    cin>>n>>k;
    vector<pll> r(n);
    REP(i,n){
        ll x, y;
        cin >> x >> y;
        r[i].FI = x;
        r[i].SE = y;
    }
    sort(r.begin(), r.end());
    ll ans = LLONG_MAX;
    REP(i,n){
        REP(j,n){
            if (i < j){
                ll up = r[i].SE, down = r[j].SE;
                if (up < down) swap(up,down);
                int st = 0, en = 0, tot = 0;
                while (r[st].SE > up || r[st].SE < down)
                {
                    ++st;
                }
                en = st;
                while (true)
                {
                    while (en < n && tot < k)
                    {
                        if (r[en].SE <= up && r[en].SE >= down)
                        {
                            ++tot;
                        }
                        ++en;
                        //cout << tot << endl;
                    }
                    if (tot < k)
                        break;
                    ans = min(ans, (r[en-1].FI - r[st].FI) * (up - down));
                    --tot;
                    ++st;
                    while (r[st].SE > up || r[st].SE < down)
                    {
                        ++st;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

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

int main(){
    string S;
    cin >> S;
    int cnt = 0;
    int N = S.size();
    rep(i, N/2){
        if(S[i] != S[N-1-i]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef pair< int64, int64 > Pi;
const int64 INF = 3000000000000000000LL;
  
int64 N, T, Q;
vector< Pi > data;
int64 dp[100002];
  
int64 rec(int idx, const int d)
{
  if(~dp[idx]) {
    return(dp[idx]);
  } else if(data[idx].second != data[idx + d].second) {
    return(dp[idx] = (data[idx].first + data[idx + d].first) / 2LL);
  } else {
    return(dp[idx] = rec(idx + d, d));
  }
}
  
int main()
{
  memset(dp, -1, sizeof(dp));
  cin >> N >> T >> Q;
  data.push_back(Pi(-INF, 1));
  for(int i = 0; i < N; i++) {
    int64 A, D;
    cin >> A >> D;
    data.push_back(Pi(A, D));
  }
  data.push_back(Pi(INF, 2));
  while(Q--) {
    int64 X;
    cin >> X;
    if(data[X].second == 1) cout << min(data[X].first + T, rec(X, +1)) << endl;
    else                    cout << max(data[X].first - T, rec(X, -1)) << endl;
  }
}

Measured memory_bytes: 4396
import sys
inputs = sys.stdin.readlines()

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, mod):
    g, x, y = xgcd(a, mod)
    assert g == 1, 'modular inverse does not exist'
    return x % mod

factorials = [1]
def factorial(n, mod):
    # n! % mod
    assert n >= 0, 'Argument Error! n is "0 <= n".'
    if len(factorials) < n+1:
        for i in range(len(factorials), n+1):
            factorials.append(factorials[-1]*i % mod)
    return factorials[n]

def perm(n, r, mod):
    # nPr % mod
    assert n >= 0, 'Argument Error! n is "0 <= n".'
    assert n >= r >= 0, 'Argument Error! r is "0 <= r <= n".'
    return factorial(n, mod) * modinv(factorial(n-r, mod), mod) % mod

def comb(n, r, mod):
    # nCr % mod
    assert n >= 0, 'Argument Error! n is "0 <= n".'
    assert n >= r >= 0, 'Argument Error! r is "0 <= r <= n".'
    
    return perm(n, r, mod) * modinv(factorial(r, mod), mod) % mod

n, k = map(int, inputs[0].split())
MOD = 10 ** 9 + 7

for i in range(1, k+1):
    try:
        print(comb(n-k+1, i, MOD)*comb(k-1, i-1, MOD) % MOD)
    except:
        print(0)

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

int main() {
 string s;
 cin >> s;
  string g,h,i,j;
  g=s[0];h=s[1];i=s[2];j=s[3];
  
  int a,b,c,d;
  a=stoi(g);b=stoi(h);c=stoi(i);d=stoi(j);
  int ans;
       if(a+b+c+d==7){cout<<g<<"+"<<h<<"+"<<i<<"+"<<j<<"=7";}
  else if(a+b+c-d==7){cout<<g<<"+"<<h<<"+"<<i<<"-"<<j<<"=7";}
  else if(a+b-c+d==7){cout<<g<<"+"<<h<<"-"<<i<<"+"<<j<<"=7";}
  else if(a+b-c-d==7){cout<<g<<"+"<<h<<"-"<<i<<"-"<<j<<"=7";}
  else if(a-b+c+d==7){cout<<g<<"-"<<h<<"+"<<i<<"+"<<j<<"=7";}
  else if(a-b+c-d==7){cout<<g<<"-"<<h<<"+"<<i<<"-"<<j<<"=7";}
  else if(a-b-c+d==7){cout<<g<<"-"<<h<<"-"<<i<<"+"<<j<<"=7";}
  else if(a-b-c-d==7){cout<<g<<"-"<<h<<"-"<<i<<"-"<<j<<"=7";}
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int x=c-a;
  int y=d-b;
  cout<<c-y<<' '<<d+x<<' '<<c-y-x<<' '<<d+x-y;
}


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

int main()
{
	int H, W;
	cin >> H >> W;

	vector<string> mat(H);
	for (int h = 0; h < H; ++h) {
		cin >> mat[h];
	}

	vector<vector<int>> count(H, vector<int>(W, 0));
	for (int h = 0; h < H; ++h) {
		int w = 0;
		int s = 0;
		int e = -1;
		int t = 0;
		while (w <= W) {
			if (w == W || mat[h][w] == '#') {
				for (int i = s; i <= e; ++i) {
					count[h][i] += t;
				}
				s = w + 1;
				e = w;
				t = 0;
			}
			else {
				++e;
				++t;
			}
			++w;
		}
	}

	for (int w = 0; w < W; ++w) {
		int h = 0;
		int s = 0;
		int e = -1;
		int t = 0;
		while (h <= H) {
			if (h == H || mat[h][w] == '#') {
				for (int i = s; i <= e; ++i) {
					if (count[i][w] != 0) {
						--count[i][w];
					}
					count[i][w] += t;
				}
				s = h + 1;
				e = h;
				t = 0;
			}
			else {
				++e;
				++t;
			}
			++h;
		}
	}

	int ret = 0;
	for (auto& h : count) {
		for (auto& w : h) {
			ret = max(ret, w);
		}
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 20096
x = gets.to_i

# 考察より -118 <= A <= 119, -119 <= B <= 118
# 全部計算する

(-118..119).each do |a|
  (-119..118).each do |b|
    value = a**5 - b**5
    if value == x
      puts "#{a} #{b}"
      exit(0)
    end
  end
end


Measured memory_bytes: 14260
#pragma GCC optimze("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
#define ppp pair<ll,pp >
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t=1, tt;
const ll inf=1e18, N=3005;
inline ll mult(ll x,ll y){x%=hell;y%=hell;return (1LL*x*y)%hell;}
inline ll add(ll x,ll y){x+=y;return x%hell;}
inline ll powMod(ll base,ll expo){
	if(base==0)return 0;
	ll ans=1;
	while(expo){
		if(expo&1)ans=mult(ans,base);
		base=mult(base,base); 
		expo>>=1;
	}
	return ans;
}
void solve(){
	ll a, b, c, k;
	cin>>a>>b>>c>>k;
	if(k<=a){
		cout<<k;
	}else if(k<=a+b){
		cout<<a;
	}else{
		cout<<a-(k-(a+b));
	}
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   	//cin>>t;
   	tt=t;
    while(t--){
        solve();
        if(t)cout<<"\n";
    }
    return 0 ;
}


Measured memory_bytes: 3692
using System;
using System.Collections.Generic;

namespace Volume0_0009
{
	class Program
	{
		static void Main(string[] args)
		{
			List<int> ns = new List<int>();

			for(int i = 0; i < 30; i++) {
				string str = Console.ReadLine();
				if(str == null) {
					break;
				}

				ns.Add(int.Parse(str));
			}

			foreach(int n in ns) {
				int cnt = 0;
				for(int i = 1; i <= n; i++) {
					if(PrimeNumber(i)) {
						cnt++;
					}
				}

				Console.WriteLine(cnt);
			}
		}

		private static bool PrimeNumber(int number)
		{
			if(number < 2) {
				return false;
			}
			if(number == 2) {
				return true;
			}
			if(number % 2 == 0) {
				return false;
			}

			double s = Math.Sqrt(number);
			for(int i = 3; i <= s; i += 2) {
				if(number % i == 0) {
					return false;
				}
			}

			return true;
		}
	}
}



Measured memory_bytes: 17952
#include<iostream>
#include<string>
using namespace std;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

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

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '.') continue;
			for (int k = 0; k < 4; k++) {
				int ny = i + dy[k];
				int nx = j + dx[k];
				if (ny < 0 || H <= ny || nx < 0 || W <= nx) continue;
				if (s[ny][nx] == '#') break;
				if (k == 3) {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
as = []
ah = []
ac = []
ad = []

for i in 1..13
as.push("S #{i}")
ah.push("H #{i}")
ac.push("C #{i}")
ad.push("D #{i}")
end

n = gets.to_i

for i in 1..n
card = gets.chomp

case card[0]

when "S"
as.delete(card)

when "H"
ah.delete(card)

when "C"
ac.delete(card)

when "D"
ad.delete(card)

end

end

as.each{|card| puts card}
ah.each{|card| puts card}
ac.each{|card| puts card}
ad.each{|card| puts card}










Measured memory_bytes: 6872
n, a = map(int,input().split())
X = list(map(int,input().split()))

X.sort()
ii = 0
while ii < n and X[ii] < a:
    ii += 1
jj = ii
while jj < n and X[jj] == a:
    jj += 1

aa = jj-ii
A = [[a-i for i in X[:ii]], [j-a for j in X[jj:]]]

# print(A)

mm = min(sum(A[0]), sum(A[1]))

AA = [[0] * (mm + 1) for i in range(2)]
for k in range(2):
    AA[k][0] = 1
    for i in range(len(A[k])):
        for j in range(len(AA[k])-1, -1, -1):
            if j - A[k][i] >= 0:
                AA[k][j] += AA[k][j-A[k][i]]
                # print(AA)
                # print(k, j, A[k][i])


# print(AA,aa)
ans = 0
for i in range(1, mm + 1):
    ans += AA[0][i] * AA[1][i]
# print(ans)
ans *= 2 ** aa

print(ans + (2 ** aa - 1))
            


Measured memory_bytes: 39280
#include<atcoder/all>
using namespace atcoder;

#include<bits/stdc++.h>
#include<array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

vector<pair<ULL, ULL>> factorize(ULL N) {
    vector<pair<ULL, ULL>> res;
    for (ULL i = 2; i * i <= N; i = (i + 1) | 1) {
        if (N % i) continue;
        res.push_back({ i,0 });
        while (N % i == 0) { N /= i; res.back().second++; }
    }
    if (N != 1) res.push_back({ N,1 });
    return move(res);
}
vector<ULL> divs(vector<pair<ULL, ULL>> F) {
    vector<ULL> res = { 1 };
    for (auto f : F) {
        int t = res.size() * f.second;
        rep(i, t) res.push_back(res[i] * f.first);
    }
    return move(res);
}
ULL GCD(ULL a, ULL b) { return b ? GCD(b, a % b) : a; }


ULL N;

int main() {
    cin >> N; N *= 2;
    auto D = divs(factorize(N));

    ULL ans = N - 1;
    for (ULL d : D) {
        if (d == 1 || d == N) continue;
        if (GCD(d, N / d) != 1) continue;
        ULL K = crt({ 0ll,LL(N / d - 1) }, { LL(d), LL(N / d) }).first;
        ans = min(ans, K);
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef long long LL;

const int N = 1010;

int n, m;
int cnt[N];

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

    for(int i = 1; i <= n; i++)
        cout << cnt[i] << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  string N;
  cin >> N;
  rep(i,3)
  {
    if(N[i]=='1')
    {
      N[i] = '9';
    }
    else
    {
      N[i] = '1';
    }
    
  }
  cout << N << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll a[200005],b[200005];
int main() {
   /* #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        

fast();
//ll t;cin>>t;while(t--)
{
    ll n,at=0;
    cin>>n;
    map<ll,ll>m,mm;
    for(int i=0;i<n;i++)
    {
      ll x;
      cin>>x;
      m[i+1]=x;
      mm[x]++;
    }
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(auto t:mm)
      {
        ll temp=t.se;
        ll x=(temp*(temp-1))/2;
        temp--;
        ll y=(temp*(temp-1))/2;

      a[t.fi]=x;
      b[t.fi]=y;
    }
    for(int i=1;i<=n;i++)
    {
      at+=a[i];
    }
    for(auto t:m)
    {
          ll val=t.se;
          ll res=at-a[val]+b[val];
          cout<<res<<endl;
    }

}
return 0;
}

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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define bitcount __builtin_popcount
#define endl "\n"
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define ffi(i,a,b,c) for(ll i = a ; i <= b ; i += c)
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int MOD = 1000000007;

void io_set() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void solve() {
	ll n;
	cin >> n;
	ll a[n];
	ll m = INT_MIN;
	rep(i, n){
		cin >> a[i];
		m = max(m, a[i]);
	}
	ll ans2 = INT_MAX;
	fo(j, 1, m){
		ll ans = 0;
		rep(i, n){
			ans += ((a[i]-j)*(a[i]-j));
		}
		ans2 = min(ans2, ans);
	}
	cout << ans2 << endl;
}

int main() {
	IOS;
	//io_set();
	ll tt = 1;
	//cin >> tt;
	while (tt--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
int main(){
	int n;
	cin >>n;
	string s;
	cin >>s;
	int rcnt=0,bcnt=0;
	rep (i,n)
	{
		rcnt+=s[i]=='R';
		bcnt+=s[i]!='R';
	}
	if (rcnt>bcnt)
		cout <<"Yes";
	else
		cout <<"No";


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};

string max_ab(int a, int b) {
	if (a >= b) {
		return "A";
	}else {
		return "B";
	}
}

int main() {
	int A,B,C; cin >> A >> B >> C;
	int X,Y; cin >> X >> Y;
	pair<int, int> AX = make_pair(A,X);
	pair<int, int> BY = make_pair(B,Y);
	string max_AB = max_ab(A,B);
	string max_XY = max_ab(X,Y);
	map<string,pair<int,int>> need;
	need["A"] = AX;
	need["B"] = BY;
	int cost = 0;
	if (A + B >= C * 2) {
		int XY = min(X, Y) * 2;
		cost += XY * C;
		//残りの計算
		if (need[max_XY].first > 2 * C)  {
			cost += 2 * C * (max(X,Y) - min(X,Y));
		}else {
			cost += need[max_XY].first * (max(X,Y) - min(X,Y));
		}
	}else {
		cost += A * X + B * Y;		
	}
	cout << cost << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ftt cin>>t;for(int tt=1;tt<=t;++tt)
#define nl cout<<"\n"
using namespace std;

bool isPrime(ll x)
{
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
ll lcm(ll x,ll y)
{
    ll z = x*y;
    return z/__gcd(x,y);
}
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll t,n,m,a,b=0,d,c,q,x=0,y=0,ans=0,sum=0,i,j,k;


  cin>>a>>b>>c>>k;


     if(k>=a)
     {
         ans = a;
         k-=a;
         if(k>=b)
         {
             k-=b;
             if(k>=c)
             {
                 ans-=c;
                 cout<<ans;
                 return 0;
             }
             else
             {
                 ans-=k;
                 cout<<ans;
                 return 0;
             }
         }
         else
         {
             cout<<ans;
             return 0;
         }
     }
     else
     {
         ans=k;
         cout<<ans;
         return 0;
     }









    return 0;
}


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

using namespace std;

int main(void) {
    int n, d;
    int count = 0;
    cin >> n >> d;
    for(int i = 0; i < n; i++){
        long x, y;
        cin >> x >> y;
        if((double)sqrt(x * x + y * y) <= d){
            count += 1;
            // cout << "x = " << x << " y = " << y << endl;
            // cout << "sqrt = " << (double)sqrt(x * x + y * y) << endl;
        }
        // cout << "x = " << x << " y = " << y << endl;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3676
# -*- coding: utf-8 -*-
import sys

N=input()
C=map(int, sys.stdin.readline().split())
C.sort()

mod=10**9+7
D=[]
d0=pow(2,N-1,mod)

#D：係数の配列の作成
for i in range(N):
    if i==0:
        D.append(d0)
    else:
        next=(2*D[-1]-d0)*pow(2,mod-2,mod)+d0
        D.append(next%mod)

#Ci*Diを最小にするため、最小のCiに最大のDiを掛けるため、Dは配列を逆順にしたものを足し合わせる
#Dもmodを取っているので、Dを降順ソートすると順番が崩れる
ans=0
for c,d in zip(C,D[::-1]):
    ans+=c*d
    ans%=mod

ans=ans*pow(2,N,mod)

print ans%mod


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int n; std::cin >> n;
  vi likes(n);
  vector<set<int>> relation(n);
  rep(i, n) {
    int a; std::cin >> a; --a;
    relation[a].insert(i);
    likes[i] = a;
  }
  int ans = 0;
  rep(i, n) {
    ans += relation[i].count(likes[i]);
  }
  std::cout << ans / 2 << "\n";
}


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

#define MAXINF 1000000005
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define repc(it, x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rrepc(it, x) for(auto it = (x).rbegin(); it != (x).rend(); ++it)
#define all(x) (x).begin(), (x).end()
#define P pair<int, int>

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c;
    cin >> a >> b >> c;
    if((c-a-b) > 0 && 4*a*b < (c-a-b)*(c-a-b)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/perl
#= CPAN mocules =====================================================#
use strict;
use warnings;

#= Global values ====================================================#

#= Local routines ===================================================#
sub main(){
	my $input = <>;
	chomp $input;
	my ($numN, $numM) = split(/ /, $input);
	my @stu;
	my @chk;
	foreach(1..$numN){
		$input = <>;
		chomp $input;
		push(@stu, [split(/ /, $input)]);
	}
	foreach(1..$numM){
		$input = <>;
		chomp $input;
		push(@chk, [split(/ /, $input)]);
	}

	foreach my $st (@stu){
		my $goal_len = 0xFFFFFFFF;
		my $goal;
		for(my $i = 0; $i < @chk; $i++){
			my $en = $chk[$i];
			my $x = $st->[0] - $en->[0];
			my $y = $st->[1] - $en->[1];
			if ($x < 0){$x *= -1}
			if ($y < 0){$y *= -1}
			if ($goal_len > ($x + $y)){
				$goal_len = $x + $y;
				$goal = $i + 1;
			}

		}
		print $goal."\n";
	}


	return 0;
}

#----- 実行 -----#
exit( main() );




Measured memory_bytes: 768
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;

const ll MOD = 1e9+7;

ll ncr[2005][2005];

ll comb(ll n,ll k){
  ll m,c,kk,nmk,ii;
  m=1;
  kk=1;
  nmk=1;
  c=1;
  for(ii=n;ii>=1;ii--){
    m *= ii;
  }
  for(ii=k;ii>=1;ii--){
    kk *= ii;
  }
  for(ii=n-k;ii>=1;ii--){
    nmk *= ii;
  }

  c = kk*nmk;
  return m/c;
}

int main(){
  ll n,k,n1,k1,n2,k2;
  cin >> n >> k;

  vector<ll> ret;
  ret.resize(k);

  memset(ncr,0,sizeof(ncr));

  ncr[0][1] = 1;
  
  ncr[1][1] = 1;
  ncr[1][2] = 1;
  
  ncr[2][1] = 1;
  ncr[2][2] = 2;
  ncr[2][3] = 1;
  int ii,jj;

  for(ii=3;ii<=2000;ii++){
    
    for(jj=1;jj<=ii+1;jj++){

      ncr[ii][jj] = (ncr[ii-1][jj-1] + ncr[ii-1][jj]) % MOD;

      //printf("ii=%4d jj=%4d ncr=%4d ncr=%d\n",ii,jj,ncr[ii-1][jj-1],ncr[ii-1][jj]);
      //printf("ii=%4d jj=%4d ncr=%4d\n",ii,jj,ncr[ii][jj]);
      
    }

  }

  
  for(ii=1;ii<=k;ii++){
    n1 = n - k + 1;
    k1 = ii;

    n2 = k - 1;
    k2 = ii - 1;

//    if(n1<k1 || n2 <k2){
//      ret[ii-1] = 0;
//    }
//    else{
    ret[ii-1] = (ncr[n1][k1+1] % MOD) * (ncr[n2][k2+1] % MOD) % MOD;//comb(n1,k1)* comb(n2,k2);
      //    }
    //cout << "n1:" << n1 << "  k1:" << k1;
    //cout << "  n2:" << n2 << "  k2:" << k2;
    //cout << "  n1 k1:" << ncr[n1][k1+1] << "  n2 k2:" << ncr[n2][k2+1] << endl;;
    //cout << "n1 k1:" << comb(n1,k1) << "n2 k2:" << comb(n2,k2) << endl;;
    //cout << "n-k+ii-1:" << n-k+ii << "ii" << ii << endl;
    
  }

//  for(ii=1;ii<=2000;ii++){
//    for(jj=1;jj<=ii+1;jj++){
//      printf("%lld ",ncr[ii][jj]);
//    }
//    printf("\n");
//  }
  for(ii=1;ii<=k;ii++){
    cout << ret[ii-1] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
array<int, 101> factoring(int x) {
    array<int, 101> ret{};
    for (int i = 2; x >= i * i; i++) {
        while (x % i == 0) {
            ret[i]++;
            x /= i;
        }
    }
    if (x > 1) ret[x]++;
    return ret;
}

signed main() {
    int n, d;
    cin >> n >> d;
    vector<queue<int>> q(n);
    REP(i, d) {
        int a, t, x;
        cin >> a >> t;
        if (a == 0) {
            cin >> x;
            q[t].push(x);
        } else if (a == 1 && q[t].size() != 0) {
            cout << q[t].front() << endl;
        } else if (q[t].size() != 0) {
            q[t].pop();
        }
    }
}


Measured memory_bytes: 4232
// Starting with the name of Allah

#include<stdio.h>
int main()
{
	long long int a,b,c;
	scanf("%lld %lld %lld",&a,&b,&c);
	if(c>=b-1){
		printf("%lld\n",(a*(b-1))/b);
	}
	else{
		printf("%lld\n",(a*c)/b);
	}
	return 0;
}


Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s,t;cin>>s>>t;
    vector<int> cha1(26, -1), cha2(26,-1);
    bool ans = true;
    for(int i=0; i<s.size(); i++){
        int S = s[i] - 'a', T = t[i] - 'a';
        if(cha1[S]==T&&cha2[T]==S)continue;
        else if(cha1[S]==-1&&cha2[T]==-1){
            cha1[S]=T, cha2[T]=S;
        }else{
            ans = false;
            break;
        }

    }
    cout<<(ans?"Yes":"No");
    return 0;
}

Measured memory_bytes: 3816