akhauriyash/Code-Regression huggingface dataset:
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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


int solve(){
  int n,x;cin>>n>>x;

  if (n==2) {
    if (x==2) {
      cout << "Yes" << endl;
      cout << 1 << endl;
      cout << 2 << endl;
      cout << 3 << endl;
    }
    else{
      cout << "No" << endl;
    }
    return 0;
  }

  if (x==1 || x==2*n-1) {
    cout << "No" << endl;
  }
  else{
    int a[2*n] = {};
    rep(i, 1, 2*n){
      a[i]=i;
    }
    swap(a[x], a[n]);
    rep(i, 1, 2*n){
      if (a[i]==x+1) { swap(a[i], a[n+1]); break; }
    }
    rep(i, 1, 2*n){
      if (a[i]==x-1) { swap(a[i], a[n-1]); break; }
    }

    if (1 <= x-2 and x-2 <= 2*n-1){
      rep(i, 1, 2*n){
        if (a[i]==x-2) { swap(a[i], a[n+2]); break; }
      }
    }
    if (1 <= x+2 and x+2 <= 2*n-1){
      rep(i, 1, 2*n){
        if (a[i]==x+2) { swap(a[i], a[n-2]); break; }
      }
    }
    dump_1d(a, 2*n);
    cout << "Yes" << endl;
    rep(i, 1, 2*n){
      cout << a[i] << endl;
    }
  }

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 3072
#include<stdio.h>

int main()
{
    int K,A,B,i,flag=0;
    scanf("%d %d %d",&K,&A,&B);
    for(i=A;i<=B;i++)
    {
      if(i%K == 0)
      {
        flag=1;
        break;
      }
    }
    if(flag == 1)
    {
      printf("OK\n");
    }
    else
    {
      printf("NG\n");
    }
    return 0;
}

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

int MAX = 510000;
long long modnum = 998244353;
std::vector< long long > fac(MAX);
std::vector< long long > finv(MAX);
std::vector< long long > inv(MAX);

long long modpow(long long a, long long n) {
    long long res = 1;
    while(n > 0) {
        if(n & 1){
            res = res * a % modnum;
        }
        a = a * a % modnum;
        n >>= 1;
    }
    return res;
}

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % modnum;
        inv[i] = modnum - inv[modnum%i] * (modnum / i) % modnum;
        finv[i] = finv[i - 1] * inv[i] % modnum;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % modnum) % modnum;
}

int main(){
    long long N, M, K;
    std::cin >> N >> M >> K;
    
    COMinit();
    
    long long cnt = 0;
    for(long long i=0; i<=K; i++){
        //long long tmp1 = modpow(M, i+1);
        long long tmp1 = M;
        long long tmp2 = modpow(M-1, N - (i+1));
        long long tmp3 = COM(N-1, i);
        long long tmp = ( ( (tmp1 * tmp2) % modnum) * tmp3) % modnum;
        cnt = (cnt + tmp) % modnum;
        
    }
    std::cout << cnt << std::endl;
    return 0;
}



Measured memory_bytes: 14996
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    string S;
    cin>>N>>S;
    int x=0,M=0;
    for(int i=0;i<N;i++){
        if(S[i]=='I'){
            x++;
            if(x>M){M=x;}
        }else{
            x--;
        }
    }
    cout<<M<<endl;
}

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

sorted_a = sorted(a)

# 中央値を求める
med = [sorted_a[n // 2 - 1], sorted_a[n // 2]]


for i in range(n):
	if a[i] <= med[0]:
		print(med[1])
	else:
		print(med[0])

Measured memory_bytes: 93780
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N;
vector <int > p;





int main()
{

	cin >> N;

	p.resize(N);

	REP(i,N){
		cin >> p[i];
	}

	int ans=0;
	REP(i,N){
		if(p[i] == i+1){
			ans++;
			if(p[i+1] == i+2){
				i++;
			}
		}
	}

	cout << ans;
}




Measured memory_bytes: 640
//package com.company;
import java.util.*;

public class Main {
    static ArrayList<Edge>[] gr;
    static boolean[] mark;
    static int[] cover;

    static class Edge {
        int to, num;
        Edge(int to, int num) {
            this.to = to;
            this.num = num;
        }
    }

    static boolean DFS(int x, int y, int p) {
        if (x == y) return true;
        for (Edge e : gr[x]) {
            if (e.to == p) continue;
            if (DFS(e.to, y, x)) {
                mark[e.num] = true;
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        gr = new ArrayList[n];
        for (int i = 0; i < n; i++)
            gr[i] = new ArrayList<>();
        for (int i = 0; i < n - 1; i++)
        {
            int u = sc.nextInt(), v = sc.nextInt();
            u--;
            v--;
            gr[u].add(new Edge(v, i));
            gr[v].add(new Edge(u, i));
        }
        int m = sc.nextInt();
        cover = new int[n];
        for (int i = 0; i < m; i++)
        {
            int u = sc.nextInt(), v = sc.nextInt();
            u--;
            v--;

            mark = new boolean[n];
            for (int j = 0; j < n; j++)
                mark[j] = false;

            DFS(u, v, -1);

            for (int j = 0; j < n - 1; j++)
                if (mark[j])
                    cover[j] |= (1 << i);
        }

        long d[] = new long[1 << m];
        d[0] = 1;

        for (int i = 0; i < n - 1; i++)
            for (int x = (1 << m) - 1; x >= 0; x--) {
                long q = d[x];
                //d[x] += q;
                d[x | cover[i]] += q;
            }

        System.out.println(d[(1 << m) - 1]);
    }
}


Measured memory_bytes: 33648
import java.util.Scanner;

public class Main {

	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();

		int minLen = Integer.MAX_VALUE;
		for(int i = 1; i <= Math.sqrt(n); i++){
			if(n % i != 0){
				continue;
			}
			String a = Integer.toString(i);
			String b = Long.toString(n / i);

			minLen = Math.min(minLen, Math.max(a.length(), b.length()));
		}

		System.out.println(minLen);
	}
}

Measured memory_bytes: 21972
N, Q = map(int, input().split())
S = input()
L = []
R = []

for _ in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

a = [0] * len(S)
for i, _ in enumerate(S[1:]):
    addition = 1 if S[i] + S[i+1] == 'AC' else 0
    a[i+1] = a[i] + addition

for l, r in zip(L, R):
    print(a[r-1] - a[l-1])


Measured memory_bytes: 65624
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;
 
int main() {
    int ans;
    vector<int> a(3);
    rep(i, 3) cin >> a[i];
    sort(a.rbegin(), a.rend());
    int m = a[0];
    int abc = a[0] + a[1] + a[2];
    if ((3 * m - abc) % 2 == 0)
        ans = (3 * m - abc) / 2;
    else
        ans = (3 * (m + 1) - abc) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int a = 0, b = 0;
	while (cin >> a)
	{
		b = 0;
		for (int i = 0; i < 10; i++)
		{
			for (int j = 0; j < 10; j++)
			{
				for (int k = 0; k < 10; k++)
				{
					for (int l = 0; l < 10; l++)
					{
						if (i + j + k + l == a)
						{
							b++;
						}
					}
				}
			}
		}
		cout << b << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  int ans = 0;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
    a[i]--;
  }
  for(int i = 0; i < n; i++){
  	if(i == a[i]){
    	if(i == n - 1) ans++;
      else {
        swap(a[i], a[i + 1]);
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n;
  string s;
  cin >> n >>s;
  if(s.size() <= n) cout << s <<endl;
  else cout<< s.substr(0, n) << "..." << endl;
  
  
}


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

int main() {
    int64_t X;
    cin >> X;
    
    int64_t money=100;
    int year=0;
    while(X>money) {
        money=(int64_t) (money*1.01);
        year++;
    }
    cout << year << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <deque>
#include <math.h>
using namespace std;
int main()
{
    //freopen("input.txt","r",stdin);
    double a,b,c,d,e,f;
    while(cin>>a>>b>>c>>d>>e>>f)
    {
        double r1=b*f-e*c,r2=b*d-a*e;
        double x=r1/r2;

        double y= (c-a*x)/b;

        printf("%.3lf %.3lf\n",x+0.0000001,y+0.0000001);
    }
    return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    set<int> st;
    int N;
    cin >> N;

    rep(i, N) {
        int A;
        cin >> A;
        st.insert(A);
    }

    if ((int)st.size() == N) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 9600
import sys
readline = sys.stdin.readline

def solve_greedy():
    D = int(readline())
    C = list(map(int, readline().split()))
    S = [list(map(int, readline().split())) for i in range(D)]
    N = 26

    lasts = [0] * N

    ans = [None] * D

    for day in range(1, D + 1):
        m, mt = -1e10, 0
        for t in range(N):
            a = S[day - 1][t] + (day - lasts[t]) * C[t]
            if a > m:
                mt = t
                m = a
        
        lasts[mt] = day

        neg = sum((day - lasts[t]) * C[t] for t in range(N))
        pos = S[day - 1][t]

        ans[day - 1] = mt
    
    for a in ans:
        print(a + 1)



solve_greedy()

Measured memory_bytes: 68704
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int l,r,d;
    cin >>l >> r >> d;
    int ans = 0;
    for(int i=l;i<=r;i++){
        if(i%d==0) ++ ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n,q;
    cin >> n >> q;
    vector<vector<int>> edge;
    int a,b;
    rep(i,n+1){
        edge.push_back({});
    }
    rep(i,n-1){
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    long long val[n+1]={0};
    long long ans[n+1]={0};
    long long p,x;
    rep(i,q){
        cin >> p >> x;
        val[p]+=x;
    }
    ans[1]=val[1];
    queue<int> que;
    que.push(1);
    bool check[n+1] = {false};
    check[1] = true;
    while(!que.empty()){
        int tmp = que.front();
        que.pop();
        for(int i = 0;i<edge[tmp].size();i++){
            int tem = edge[tmp][i];
            if(!check[tem]){
                ans[tem]+=ans[tmp]+val[tem];
                que.push(tem);    
                check[tem] = true;            
            }
        }
    }
    rep(i,n){
        cout << ans[i+1] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 19308
#include <iostream>
#include <cstring>
using namespace std;
int main() {
	const int MAX = 3000;
	string s,t;
	cin >> s >> t;
	int s_len = s.size();
	int t_len = t.size();
	int dp[MAX+1][MAX+1];
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=s_len;i++){
		for(int j=1;j<=t_len;j++){
			if(s[i-1]==t[j-1]){
				dp[i][j] = dp[i-1][j-1] + 1;
			} else {
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	string answer = "";
	int i=s_len;
	int j=t_len;
	while(i>0&&j>0){
		if(dp[i][j]==dp[i][j-1]){
			j--;
		} else if(dp[i][j]==dp[i-1][j]){
			i--;
		} else {
			answer = s.substr(i-1,1) + answer;
			i--;j--;
		}
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 35456
#include <stdio.h>

int main(void){
	int board[8][5];
	int i,j,n,nc;
	int isFirst = 1;
	while(scanf("%d",&n) != EOF){
		for(j = 0; j < 8; j++){
			for(i = 0; i < 5; i++){
				board[j][i] = ' ';
			}
		}
		for(i = 0; i < 5; i++){
			board[2][i] = '=';
			nc = n % 10;
			if(nc >= 5){
				board[1][i] = '*';
				nc -= 5;
			}else{
				board[0][i] = '*';
			}
			for(j = 0; j < nc; j++){
				board[3 + j][i] = '*';
			}
			if(j != 5){
				board[3 + j][i] = ' ';
				j++;
			}
			for(; j < 5; j++){
				board[3 + j][i] = '*';
			}
			n /= 10;
		}
		
		if(!isFirst){putchar('\n');}
		else{isFirst = 0;}
		for(j = 0; j < 8; j++){
			for(i = 4; i >= 0; i--){
				putchar(board[j][i]);
			}
			putchar('\n');
		}
		
	}

	return 0;
}

Measured memory_bytes: 0
//package atCoder;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int D = sc.nextInt();
		int start = sc.nextInt();

		for(int i=0;i<10;i++) {
			start = r*start-D;
			System.out.println(start);
		}
	}
}


Measured memory_bytes: 21972
N = int(input())
P = list(map(int, input().split()))
flag = 0
for i in range(N):
    if P[i] % 2 == 0:
        if P[i] % 3 != 0:
            if P[i] % 5 != 0:
                flag = 1

if flag == 1:
    print("DENIED")
else:
    print("APPROVED")

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

#define      sf           scanf
#define      pf           printf
#define      pb           push_back
#define      sz           200005
#define      read         freopen("in.txt", "r", stdin);
#define      write        freopen("out.txt", "w", stdout);
#define      optimize     ios::sync_with_stdio(0); cin.tie(0);

using namespace std;

typedef      long long int      ll;

int main()
{
	// read
	// write

	int n;

	string s;

	ll ans = 0;

	vector <int> r, g, b;

	cin >> n >> s;

	for(int i = 0; i < n; i++)
	{
		if(s[i]=='R') r.pb(i);
		else if(s[i]=='G') g.pb(i);
		else b.pb(i);
	}

	for(auto x: r)
	{
		for(auto y: g)
		{
			if(y>x)
			{
				int tr = y+1;
				int ex = y+y-x;

				int lb = lower_bound(b.begin(), b.end(), tr)-b.begin();

				ans += b.size()-lb;

				if(binary_search(b.begin(), b.end(), ex)) ans--;
			}
		}

		for(auto y: b)
		{
			if(y>x)
			{
				int tr = y+1;
				int ex = y+y-x;

				int lb = lower_bound(g.begin(), g.end(), tr)-g.begin();

				ans += g.size()-lb;

				if(binary_search(g.begin(), g.end(), ex)) ans--;
			}
		}
	}


	for(auto x: g)
	{
		for(auto y: b)
		{
			if(y>x)
			{
				int tr = y+1;
				int ex = y+y-x;

				int lb = lower_bound(r.begin(), r.end(), tr)-r.begin();

				ans += r.size()-lb;

				if(binary_search(r.begin(), r.end(), ex)) ans--;
			}
		}
		for(auto y: r)
		{
			if(y>x)
			{
				int tr = y+1;
				int ex = y+y-x;

				int lb = lower_bound(b.begin(), b.end(), tr)-b.begin();

				ans += b.size()-lb;

				if(binary_search(b.begin(), b.end(), ex)) ans--;
			}
		}
	}


	for(auto x: b)
	{
		for(auto y: r)
		{
			if(y>x)
			{
				int tr = y+1;
				int ex = y+y-x;

				int lb = lower_bound(g.begin(), g.end(), tr)-g.begin();

				ans += g.size()-lb;

				if(binary_search(g.begin(), g.end(), ex)) ans--;
			}
		}
		for(auto y: g)
		{
			if(y>x)
			{
				int tr = y+1;
				int ex = y+y-x;

				int lb = lower_bound(r.begin(), r.end(), tr)-r.begin();

				ans += r.size()-lb;

				if(binary_search(r.begin(), r.end(), ex)) ans--;
			}
		}
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,d;
  cin>>n>>d;
  vector<vector<int>>x;
  x.resize(n);
  rep(i,n)rep(j,d)
  {
    int a;
    cin>>a;
    x[i].push_back(a);
  }
  int res=0;
  rep(i,n)rep(j,n)
  {
    if(i>=j)continue;
  //  int f=1;
    int summ=0;

    rep(k,d)
    {
      summ+=pow((x[i][k]-x[j][k]),2);
    }
    if(pow((int)sqrt(summ),2)==summ)
    {
      res++;
    }



  }
  cout<<res<<endl;
  return 0;


}


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

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll i=0;i<n;i++)

#define MAX 100000

ll n, m;
ll p[MAX], a[MAX], b[MAX], c[MAX], times[MAX]={}, sum[MAX]={};

int main() {
	scanf("%lld %lld", &n, &m);

	REP(i,m) scanf(" %lld", &p[i]);
	REP(i,n-1) scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);

	REP(i,m-1) {
		times[min(p[i],p[i+1])-1]++;
		times[max(p[i],p[i+1])-1]--;
	}

	REP(i,n-1) {
		times[i+1] += times[i];
	}

	ll total = 0;

	REP(i,n-1) {
		total += min(a[i]*times[i], b[i]*times[i]+c[i]);
	}

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

	return 0;
}

Measured memory_bytes: 5096
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int cnt=0;
    for(int i=0; i<n-2; i++){
        for(int j=i+1; j<n-1; j++){
            for(int k=j+1; k<n; k++){
                if( a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[j]+a[k]>a[i] && 
                    a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i] ){
                        cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

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

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//----------------------------------------------------------------

int main(void) {
  int n, k;
  cin >> n >> k;
  arr(a,n);

  prt((n-1+k-2)/(k-1));

}


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

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

  long long ans = 0, sum = 0;
  for ( map<int, int>::reverse_iterator it = mp.rbegin(); it != mp.rend(); it++){
    if (sum >= n)continue;
    ans += it->first * min((long long)(n-sum), (long long)it->second);
    sum += it->second;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)
vi val;
vvi adj;

void dfs(int v=0, int p=-1){
    if(p!=-1){
        val[v]+=val[p];
    }
    for(auto it:adj[v]){
        if(it!=p){
            dfs(it,v);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z;
    cin>>n>>t;
    adj.resize(n);
    val.resize(n);
    for(int i=0;i<(n-1);i++){
        cin>>x>>y;
        x--;y--;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    while(t--){
        cin>>x>>y;
        x--;
        val[x]+=y;
    }
    dfs();
    print(val);



    return 0;
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define M_PI 3.14159265358979323846

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }


int main()
{
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    vector<string> V(3);
    REP(i,3) cin >> V[i];
    string ans;
    REP(i,3) ans+=V[i][0];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, i, j, k, ans=0, r[10000]={0}, g[10000]={0}, b[10000]={0};
    string s;
    cin >> n >> s;
    for(i=1;i<=n;i++){
        r[i]=r[i-1];g[i]=g[i-1];b[i]=b[i-1];
        if(s[i-1]=='R') r[i]++;
        else if(s[i-1]=='G') g[i]++;
        else b[i]++;
    }
    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            if((s[i]=='R' && s[j]=='G') || (s[i]=='G' && s[j]=='R')) {
                ans+=b[n]-b[j+1];
                if(s[2*j-i]=='B') ans--;
            }
            else if((s[i]=='R' && s[j]=='B') || (s[i]=='B' && s[j]=='R')) {
                ans+=g[n]-g[j+1];
                if(s[2*j-i]=='G') ans--;
            }
            else if((s[i]=='G' && s[j]=='B') || (s[i]=='B' && s[j]=='G')) {
                ans+=r[n]-r[j+1];
                if(s[2*j-i]=='R') ans--;
            }
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 3872
#!/usr/bin/python3

(n, p) = map(int, input().split())
s = input()

c = 0
if p == 2 or p == 5:
    for i in range(n - 1, -1, -1):
        if int(s[i]) % p == 0:
            c += i + 1

else:
    mm = {}
    r = 0
    mten = 1
    for i in range(n - 1, -1, -1):
        ch = int(s[i])
        r = (r + ch * mten) % p
        mten = (mten * 10) % p
        if r in mm:
            c += mm[r]
            mm[r] += 1
        else:
            mm[r] = 1

        if r == 0:
            c += 1
        
print(c)


Measured memory_bytes: 42828
def length(a, b)
  ((a[0] - b[0])**2 + (a[1] - b[1])**2)**0.5
end

N = gets.chomp.to_i
pos = []
N.times { pos << gets.chomp.split(" ").map(&:to_i) }

a = []
[*(0...N)].permutation(2) do |b, c|
  a << length(pos[b], pos[c])
end
mean = a.inject(0, :+) / a.size

puts mean * (N - 1) 

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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split(' ');
            var nums = new long[3];
            for (int i = 0; i < 3; i++)
            {
                nums[i] = long.Parse(abc[i]);
            }
            long tmp = nums[2] - nums[0] - nums[1];
            if (tmp * tmp > 4 * nums[0] * nums[1] && tmp > 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>

using namespace std;

long long X[100100];
long long subX[100100];
int main(void){
  long long N,M;
  cin >> N >> M;
  for(long long i=0;i<M;i++){
    cin >> X[i];
  }
  sort(X,X+M);

  for(long long i=0;i<M-1;i++){
    subX[i] = X[i+1] - X[i];
  }

  sort(subX,subX+M-1);
  long long cost = 0;
  for(long long i=0;i<M-1-(N-1);i++){
    cost += subX[i];
  }

  cout << cost << endl;
  return 0;
}


Measured memory_bytes: 1792
function Main(input) {
    var input = input.split("\n");
    var colors = input[0].split(" ");

    var filteredColors = colors.filter(
	function (x, i, self) {
	    return self.indexOf(x) === i;
	}
    );

    console.log(filteredColors.length);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

ll n,ans,a[100000];

ll calc_sum(bool b){
    int fi,bi;
    ll res;

    if(b){
        res += a[n-1]+a[n-2]-2*a[0];
        fi = 1;
        bi = n-1;
    }else{
        res += 2*a[n-1]-(a[0]+a[1]);
        fi = 0;
        bi = n-2;
    }
    int cnt = b;
    while(fi+1<bi-1){
        res += a[bi]+a[bi-1] - (a[fi]+a[fi+1]);
        if(cnt%2==0) fi += 2;
        else bi -= 2;
        cnt ++;
    }
    if(n%2==0) res += a[bi] - a[fi];
    return res;
}

int main(){
    cin >> n;
    for(int i = 0;i < n;i ++){
        cin >> a[i];        
    }
    sort(a,a+n);
    
    if(n==2) {
        cout << a[1] - a[0] << endl;
        return 0;
    }
    ans = max(calc_sum(0),calc_sum(1));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
/*input
1000000000

*/
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define trace1(x) cout<<#x<<": "<<x<<endl
#define trace2(x, y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cout<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
 
//typedef long long ll;
#define int long long
#define ll long long

 
#define PI 3.141592653589793
#define MOD 1000000007
#define INF 1e15
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; a=a%m; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
/*prime m*/ template<typename T> T modInv(T a, T m){return pow(a,m-2,m);} 

#define MAX 505 
int32_t main() {
	IOS
	int n; cin>>n;
	int ans = 0;

	if(n>=500) {
		ans += 1000*(n/500);
		n = n%500;
	}
	if(n>=5){
		ans += 5*(n/5);
		n = n%5;
	}
	cout<<ans<<endl;




 
return 0;
}
 


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define LARGE 101
#define INF 2000000000

int main(){
	int i,j,N,W;
	int sum=0;
	int v[LARGE];
	int w[LARGE];
	int **dp;

	scanf("%d %d",&N,&W);
	
	for(i=1;i<=N;i++){
		scanf("%d %d",&v[i],&w[i]);
		sum+=v[i];
	}
	
	dp=malloc(sizeof(int*)*(N+1));
	for(i=0;i<=N;i++){
		dp[i]=malloc(sizeof(int)*(sum+1));
		for(j=0;j<=sum;j++)dp[i][j]=INF;
	}
	
	
	for(i=0;i<=N;i++)dp[i][0]=0;
	
	for(i=1;i<=N;i++){
		for(j=0;j<=sum;j++){
			if(dp[i-1][j]!=INF){
				dp[i][j]=MIN(dp[i-1][j],dp[i][j]);
				if(dp[i-1][j]+w[i]<=W)dp[i][j+v[i]]=MIN(dp[i][j+v[i]],dp[i-1][j]+w[i]);
			}
		}
	}
	
	for(i=sum;i>=0;i--){
		if(dp[N][i]!=INF){
			printf("%d\n",i);
			break;
		}
	}
	
	return 0;
}


Measured memory_bytes: 5708
#include<bits/stdc++.h>
#define ll long long
#define ull unsinged long long
#define ld long double
#define mem(a,b) memset(a,b,sizeof(a))
#define inf (1LL<<62)
#define sf scanf
#define pf printf
#define repi(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define depi(i,a,b) for(int i=a;i>=b;--i)
#define dep(i,a,b) for(ll i=a;i>=b;--i)
#define mod 1000000007

using namespace std;

int ans[100005];

int main()
{
    //std::ios::sync_with_stdio(false);
    int n,k,q,s;
    mem(ans,0);
    sf("%d%d%d",&n,&k,&q);
    int m=q-k;
    for(int i=1;i<=q;++i)
    {
        sf("%d",&s);
        ++ans[s];
    }
    for(int i=1;i<=n;++i)
    {
        if(ans[i]<=m)
            pf("No\n");
        else
            pf("Yes\n");
    }

    return 0;
}


Measured memory_bytes: 1024
T = 'AKIHABARA'
V = [1, 0, 0, 1, 1, 1]

def main(argv)
  s = gets.chomp

  if s.size > T.size then
    puts 'NO'
    return
  end

  t = ''
  s.size.times{|i| t += s[i] if s[i] != 'A'}

  if t != 'KIHBR' then
    puts 'NO'
    return
  end

  v = [0]
  s.size.times do |i|
    if s[i] == 'A' then
      v[v.size - 1] += 1
    else
      v.push(0)
    end
  end

  flag = true
  V.size.times do |i|
    flag = false unless v[i] <= V[i]
  end
  puts (flag ? 'YES' : 'NO')
end

if self.to_s == 'main' then
  main(ARGV)
end

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

int main() {
  int N, even = 0, num = 0;

  cin >> N;

  int A[N];

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

  while(even == 0){
    for(int i = 0; i < N; i++){
      if((A[i] % 2) == 0){
        A[i] /= 2;
      }
      else{
        even = 1;
      }
    }

    if(even == 0){
      num++;
    }
  }

  cout << num << endl;


  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct edge{int to,w,p;};
vector<edge>x[110];int N,M,a,b,c,used[110];
int dfs(int s,int t,int r){
	if(s==t)return r;used[s]=1;
	for(int i=0;i<x[s].size();i++){
		edge &u=x[s][i];
		if(used[u.to]==0 && u.w>0){
			int F=dfs(u.to,t,min(r,u.w));
			if(F>0){u.w-=F;x[u.to][u.p].w+=F;return F;}
		}
	}
	return 0;
}
int main(){
	cin>>N>>M;
	for(int i=0;i<M;i++){
		cin>>a>>b>>c;
		edge p={b,c,x[b].size()};x[a].push_back(p);
		edge q={a,0,x[a].size()-1};x[b].push_back(q);
	}
	int res=0;
	while(true){
		for(int i=0;i<110;i++)used[i]=0;
		int P=dfs(0,N-1,1<<30);
		if(P==0)break;res+=P;
	}
	cout<<res<<endl;
	return 0;
}

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

int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  for(ll i = 1; i < n; i++) ans += (n-1)/i;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if (s == u) cout << a - 1 << " " << b << "\n";
    if (t == u) cout << a << " " << b - 1 << "\n";
    return 0;
}

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

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

typedef long long ll;
using namespace std;

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

  int A, P;
  cin >> A >> P;
  cout << (A * 3 + P) / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		
		if(N % K == 0)
			System.out.println(0);
		else
			System.out.println(1);
		sc.close();
	}
}


Measured memory_bytes: 21972
n=int(input())
arr=[int(input()) for _ in range(n)]
m1=max(arr)
arr2=sorted(arr,reverse=True)
m2=0
cnt=0
for val in arr2:
  if val==m1:
    cnt+=1
  else:
    m2=val
    break
else:
  m2=m1
for val in arr:
  if cnt>=2:
    print(m1)
  else:
    if val==m1:
      print(m2)
    else:
      print(m1)

Measured memory_bytes: 14112
#include<bits/stdc++.h>
#define clr(x) memset(x, 0, sizeof(x))
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef pair<long , long> pll;

const ll mx = 105;
const ll maxn = 1000001;
const ll mod = 1000000007;

vector<vector<int>> adj;
vector<ll> lis;
bool vis[maxn];
bool pos;

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

  ll t = 1;

  //cin>>t;

  while(t--){
    

     float r;
     cin>>r;
     cout<<setprecision(20)<<2*M_PI*r;     
  }     
        
}


Measured memory_bytes: 3808
def run(n, m, qq, l, r, p, q):
    cnt = {}
    sum = {}
    ret = []
    for i in range(n+1):
        for j in range(n+1):
            cnt[i, j] = 0
            sum[i, j] = 0
    for i in range(m):
        cnt[(l[i], r[i])] += 1
    for i in range(1, n+1):
        for j in range(1, n+1):
            sum[i, j] = cnt[i, j] + sum[i-1, j] + sum[i, j-1] - sum[i-1, j-1]
    for i in range(qq):
        ret.append(sum[q[i], q[i]] - sum[p[i]-1, q[i]] - sum[q[i], p[i]-1] + sum[p[i]-1, p[i]-1])
    return ret


def read_line():
    n, m, qq = map(int, input().split())
    l = []
    r = []
    for i in range(m):
        tl, tr = map(int, input().split())
        l.append(tl)
        r.append(tr)
    p = []
    q = []
    for i in range(qq):
        tp, tq = map(int, input().split())
        p.append(tp)
        q.append(tq)
    return (n, m, qq, l, r, p, q)


def main():
    n, m, qq, l, r, p, q = read_line()
    ret = run(n, m, qq, l, r, p, q)
    for i in range(len(ret)):
        print(ret[i])


if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

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

    bool ans = false;
    rep2(a, 1, 10)
    {
        if (n % a == 0)
        {
            int b = n / a;
            if (1 <= b && b <= 9)
            {
                ans = true;
            }
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define int long long int
#define fi first
#define se second
#define FIO {ios::sycnt2_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pow10(n) stoll("1"+string(n,'0'))
//fill(all(arr),1)
//if(map.count(key)){}
//bitset<20>(n);
//int mini=min({a,b,c,d,e});
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
 
int32_t main()
{
 int n;
 cin>>n;
 int a[n];
 int s=0;
 int cnt[100009];
 memset(cnt,0,sizeof(cnt));
 forn(i,n){cin>>a[i];s+=a[i];cnt[a[i]]++;}
 int q;
 cin>>q;
 while(q--)
 {
  int b,c;
  cin>>b>>c;
 s+=cnt[b]*(c-b);
  cnt[c]+=cnt[b];
  cnt[b]=0;
  cout<<s<<'\n';
 }
}

Measured memory_bytes: 5124
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
string a;
cin>>a;
cout<<a[0]<<a.size()-2<<a[a.size()-1];
system("pause");
return 0;
}

Measured memory_bytes: 504
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        List<String> shopList = new ArrayList<String>();
        for (int i=0; i<N; i++) {
            shopList.add(String.format("%09d",sc.nextLong()) + "," + String.format("%09d",sc.nextLong()));
        }
        Collections.sort(shopList);
        Long kingaku = 0L;
        for (String sp : shopList) {
            //System.out.println(sp);
            if (M == 0) {
                break;
            }
            String[] strArray  = sp.split(",");
            Long A = Long.parseLong(strArray[0]);
            Long B = Long.parseLong(strArray[1]);

            if (M <= B) {
                kingaku += A * M;
                M -= M;
            }
            else {
                kingaku += A * B;
                M -= B;
            }

        }
        System.out.println(kingaku);
    }

}


Measured memory_bytes: 180916
#include <cstdio>
#include <set>
#include <queue>

using namespace std;

int H,W;
int CX,CY,DX,DY;

char S[1005][1005];
int tag[1005][1005];

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

int start,target;
set<int> graph[1000007];
bool visited[1000007];

void DFS(int x,int y,int comp){
    if (x<=0||x>H) return;
    if (y<=0||y>W) return;
    if (S[x][y]=='#') return;
    if (tag[x][y]) return;

    tag[x][y]=comp;

    for(int i=0;i<4;i++) DFS(
        x+dx[i],y+dy[i],comp
    );
}

void DFS2(int x,int y){
    if (x<=0||x>H) return;
    if (y<=0||y>W) return;
    if (S[x][y]=='#') return;

    S[x][y]='#';

    for(int i=-2;i<=2;i++){
        for(int j=-2;j<=2;j++){
            int nx=x+i,ny=y+j;
            if (nx<=0||nx>H) continue;
            if (ny<=0||ny>W) continue;
            if (tag[nx][ny]==tag[x][y]&&tag[nx][ny]==0) continue;
            graph[tag[x][y]].insert(tag[nx][ny]);
        }
    }

    for(int i=0;i<4;i++) DFS2(
        x+dx[i],y+dy[i]
    );
}

int BFS(){
    queue<int> q;
    queue<int> d;
    q.push(start);
    d.push(0);
    visited[start]=true;

    while(!q.empty()){
        int cur=q.front();
        int dist=d.front();
        q.pop();
        d.pop();

        if (cur==target) return dist;
        for(auto adj:graph[cur]){
            if (visited[adj]) continue;
            q.push(adj);
            d.push(dist+1);
            visited[adj]=true;
        }

    }

    return -1;
}

int main(){
    scanf("%d%d",&H,&W);
    scanf("%d%d",&CX,&CY);
    scanf("%d%d\n",&DX,&DY);

    for(int i=1;i<=H;i++) scanf("%s",S[i]+1);

    int t=1;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            if (tag[i][j]) continue;
            if (S[i][j]=='#') continue;
            DFS(i,j,t++);
        }
    }

    // for(int i=1;i<=H;i++){
    //     for(int j=1;j<=W;j++){
    //         printf("%d",tag[i][j]);
    //     }
    //     putchar('\n');
    // }

    start=tag[CX][CY],target=tag[DX][DY];

    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            if (S[i][j]=='#') continue;
            DFS2(i,j);
        }
    }

    printf("%d\n",BFS());

    return 0;
}

Measured memory_bytes: 85800
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	ll max,maxnum,pm,x,y,z,k,i,j,m;
	cin>>x>>y>>z>>k;
	vector<ll> a,b,c;
	rep(i,x){
		cin>>pm;
		a.push_back(pm);
	}
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	
	rep(i,y){
		cin>>pm;
		b.push_back(pm);
	}
	sort(b.begin(),b.end());
	reverse(b.begin(),b.end());
	
	rep(i,z){
		cin>>pm;
		c.push_back(pm);
	}
	sort(c.begin(),c.end());
	reverse(c.begin(),c.end());
	
	
	vector<ll> v;
	for(i=0;i<x;i++){
		for(j=0;j<y;j++){
			for(m=0;m<z;m++){
				if((i+1)*(j+1)*(m+1)>k)break;
				else v.push_back(a[i]+b[j]+c[m]);
			}
		}
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	for(i=0;i<k;i++){
		cout<<v[i]<<endl;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
//////////////////////////////////////////////////////
	return 0;
}


Measured memory_bytes: 1412
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int min(int a,int b)
{
	if(a>b)return b;
	return a;
}
int max(int a,int b)
{
	if(a>b)return a;
	return b;
}
int main()
{
	int a,b,c,d;
	int k[120],l[120];
	int i;
	int ans;
	scanf("%d%d%d%d",&a,&b,&c,&d);
    ans=min(b,d)-max(a,c);
    if(ans<0)ans=0;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
from collections import defaultdict
n,m = map(int,input().split())
h_list = list(map(int,input().split()))
connect_dic = defaultdict(set)

for i in range(m):
    a,b = map(int,input().split())
    connect_dic[a].add(b)
    connect_dic[b].add(a)

count = 0
for k,v in connect_dic.items():
    if h_list[k-1]>max([h_list[num-1] for num in v]):
        count += 1

print(count + n - len(connect_dic))


Measured memory_bytes: 119064