akhauriyash/Code-Regression huggingface dataset:
#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>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define 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);
  ll n;cin>>n;
  ll k;cin>>k;
  struct ed{
    ll l,r;
  };
  vector<ed>es;
  repi(i,1,n){
    es.push_back({i,n});
  }
  ll cnt=(n-1)*(n-2)/2;
  [&]{repi(i,1,n)repi(j,i+1,n){

    if(cnt==k){
      return;
    }
      es.push_back({i,j});
      cnt--;
    }
  }();

  if(cnt!=k){
    cout<<-1<<endl;
  }
  else {
    cout<<es.size()<<endl;
    for(auto tp:es){
      cout<<tp.l<<" "<<tp.r<<"\n";
    }
    cout<<flush;
  }
  return 0;

}


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  string S; cin >> S;
  char prev = -1;
  ll cnt = 0;
  for (ll i = 0; i < N; i++) {
    if (S[i] != prev) {
      cnt ++;
      prev = S[i];
    }
  }
  cout << cnt << endl;
  
  return 0;
}



Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		try {
			
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			String[] hyozyun = br.readLine().split(" ");
			int A =Integer.parseInt(hyozyun[0]);
			int B =Integer.parseInt(hyozyun[1]);
			int C =Integer.parseInt(hyozyun[2]);
			int X =Integer.parseInt(hyozyun[3]);
			int Y =Integer.parseInt(hyozyun[4]);
			
			// 合計金額を設定
			int sum = 0;
			// Cを２枚買ったほうが安い場合
			if (A + B < 2 * C) {
				sum = A * X + B * Y;
			} else {
			// それぞれ買ったほうが安い場合
				// 枚数少ないほうをすべて買って、プラス足りない分購入
				if (X > Y) {
					sum = C * 2 * Y + (X - Y) * A;
				} else {
					sum = C * 2 * X + (Y - X) * B;
				}
			}
			// XとYの枚数が多いほうの分だけ、Cを買った場合の値段
			int compare = 0;
			if (X > Y) {
				compare = X * C * 2;
			} else {
				compare = Y * C * 2;
			}
			// 上記の計算結果のほうが安い場合はそちらを採用
			if (sum > compare) {
				sum = compare;
			}
			
			System.out.println(sum);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

int n, s, *num, pattern;
void search(int th) {
  if (th == n) {
    int sum = 0;
    for (int i = 0; i < n; i++)
      sum += num[i];
    if (s == sum) {
      for (int j = 0; j+1 < n; j++)
        if (num[j] >= num[j+1])
          return;
      /*                                                                                                                                                                                                                                                     
      for (int j = 0; j < n; j++)                                                                                                                                                                                                                            
        cout << num[j];                                                                                                                                                                                                                                      
      cout << endl;                                                                                                                                                                                                                                          
      */
      pattern++;
    }
  } else {
    int start = 0;
    if (th > 0)
      start = num[th-1]+1;
    for (int i = start; i < 10; i++) {
      num[th] = i;
      search(th + 1);
    }
  }
}

int main(int argc, char *argv[]) {
  vector<int> result;
  while (true) {
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;
    num = new int[n];
    memset(num, 0, sizeof(int) * n);

    pattern = 0;
    search(0);
    result.push_back(pattern);
  }

  for (int i = 0; i < result.size(); i++)
    cout << result[i] << endl;
  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long 
#define pb push_back
#define all(v) v.begin(),v.end()
int mod =1e18+5;

int32_t main()
{
    int n;
    cin>>n;
    vector<int> v(n);
    long double curr=1;
    int ans=1;
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    sort(all(v));
    if(v[0] == 0)
    {
        cout<<0;
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        curr*=v[i];
        if(curr>mod)
        {
            cout<<-1;
            return 0;
        }
        ans*=v[i];
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>k;i--)
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(),greater<>());
    if(s<t){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3596
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
 
ans = 0
for i in range(N):
    ans += min(A[i],B[i])
    B[i] -= min(A[i],B[i])
    ans += min(A[i+1],B[i])
    A[i+1] -= min(A[i+1],B[i])
print(ans)    

Measured memory_bytes: 24252
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

typedef long long ll;

using namespace std;

int main(int argc , char *argv[]) {
    string s;
    cin >> s;

    for(int i = 0 ; i < s.length()-1 ; i++) {
        if(s[i] == s[i+1]) {
            cout << "Bad";
            return 0;
        }
    }

    cout << "Good";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int dt[12][12];
int dt_num;

int main()
{
	int  i,n,k;
	int  sum_x;
	int  sum_y[12];
	char inp[1024];
	char *wk_p,*dmy_p;


	while (1) {
	/**--init --**/
	dt_num = 0;
	/**--inpot--**/
	gets(inp);
	sscanf(inp,"%d",&n);
	if (n==0) {
		break;
	}
	for (i=0 ; i<n ; i++) {
		gets(inp);

		wk_p = strtok( inp," ");
		for(k=0 ;; k++) {
			if (wk_p == NULL) {
				break;
			}
			sscanf(wk_p,"%d",&(dt[i][k]));
			wk_p = strtok( NULL," ");
		}

	}

	/*CALC*/
	memset(sum_y,'\0',sizeof(sum_y));
	for (i=0 ; i<n ; i++) {
		sum_x=0;
		for(k=0;k<n ; k++) {
			sum_x += dt[i][k];
			sum_y[k] += dt[i][k];
		}
		dt[i][k] = sum_x;
//		sum_y[k] = sum_x;
		sum_y[n] += sum_x;
	}

	for(k=0 ; k<=n ; k++) {
		dt[n][k] = sum_y[k];
	}

	/*print*/
	for (i=0 ; i<=n ; i++) {
		for(k=0 ; k<=n ; k++) {
			printf("%5d",dt[i][k]);
		}
		printf("\n");
	}
	}
	return 0;
}

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

#define ll long long

using namespace std;

int n, a[100];

bool f() {
    for (int i = 1; i < n; ++i)
        if (a[i - 1] > a[i])
            return false;
    return true;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    if (f()) {
        cout << "YES";
        return 0;
    }
    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j) {
            swap(a[i], a[j]);
            if (f()) {
                cout << "YES";
                return 0;
            }
            swap(a[i], a[j]);
        }
    cout << "NO";
    return 0;
}


Measured memory_bytes: 256
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		 Scanner scan = new Scanner(System.in);
		//Scanner scan = new Scanner(new File("D:\\UserArea\\J0124567\\Downloads\\0536-input.txt"));

		while (scan.hasNext()) {

			int n = scan.nextInt();
			if (n == 0)
				break;
			int m = scan.nextInt();
			int p = scan.nextInt();
			int q = scan.nextInt();
			int r = scan.nextInt();

			Card c = new Card(n, m);
			for (int i = 0; i < m; i++) {
				c.shuffle(scan.nextInt(), scan.nextInt(), n);
				// c.print();
			}

			System.out.println(c.count(p, q, r));
		}

		scan.close();
		System.exit(0);

	}
}

class Card {
	class Bulk {
		public Bulk(int _st, int _pcs, int _next) {
			st = _st;
			pcs = _pcs;
			next = _next;
		}

		int st;
		int pcs;
		int next;
	}

	int top;
	int empty;
	Bulk[] bu;

	public Card(int n, int m) {
		bu = new Bulk[m * 3];
		bu[0] = new Bulk(1, n, -1);
		top = 0;
		empty = 1;
	}

	public void print() {
		int i = top;
		while (true) {

			System.out.print(" {" + bu[i].st + " " + (bu[i].st + bu[i].pcs - 1) + "}");
			i = bu[i].next;
			if (i == -1)
				break;
		}
		System.out.println();
	}

	public int count(int p, int q, int r) {
		int i = top;
		int pcs = 0;
		int cto = 0;
		int cfr;
		while (true) {
			cfr = cto + 1;
			cto += bu[i].pcs;
			if (cfr > q)
				break;
			if (cto < p) {
				i = bu[i].next;
				continue;
			}
			int a, b;
			if (cfr < p)
				a = p - cfr;
			else
				a = 0;
			if (cto > q)
				b = bu[i].pcs - (cto - q) - 1;
			else
				b = bu[i].pcs - 1;
			if (bu[i].st + a <= r)
				if (bu[i].st + b <= r)
					pcs += (b - a + 1);
				else
					pcs += (r - (bu[i].st + a) + 1);

			i = bu[i].next;

		}
		return pcs;
	}

	public void shuffle(int x, int y, int n) {
		// this.print();

		int i = top;
		int cto = 0, cfr = 0;
		int xlast = 0, ylast = 0, zlast = 0;
		while (true) {
			cfr = cto + 1;
			cto += bu[i].pcs;
			if (cfr <= x && x <= cto) {
				if (x < cto) {
					this.devide(i, cto - x);
					cto = x;
				}
				xlast = i;
			}
			if (cfr <= y && y <= cto) {
				if (y < cto) {
					this.devide(i, cto - y);
					cto = y;
				}
				ylast = i;
			}

			if (bu[i].next == -1) {
				zlast = i;
				break;
			}
			i = bu[i].next;
		}
		int temp = top;
		top = bu[ylast].next;
		bu[ylast].next = temp;
		bu[zlast].next = bu[xlast].next;
		bu[xlast].next = -1;

	}

	private int devide(int i, int pcs) {
		bu[empty] = new Bulk(bu[i].st + bu[i].pcs - pcs, pcs, bu[i].next);
		bu[i].pcs -= pcs;
		bu[i].next = empty;
		return empty++;
	}

}

Measured memory_bytes: 57652
//atcoder105B
#include<stdio.h>
int main(void)
{
	int n;
	scanf("%d",&n);
	if(n<=3 || n==5 || n==6 || n==9 || n==10 || n==13 || n==17){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

// 最大公約数を求める関数
ll gcd(ll n, ll m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める関数
ll lcm(ll n, ll m) {
  ll g = gcd(n, m);
  return n * m / g;
}

int main() {
  ll a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
As=sorted(A,reverse=True)
B=0
C=0
for i in range(len(As)-1):
    tmp=As[i]
    if tmp==As[i+1]:
        if tmp>B:
            B=tmp
            del As[0:i+2]
            break
for j in range(len(As)-1):
    tmp=As[j]
    if tmp==As[j+1]:
        if tmp>C:
            C=tmp
print(B*C)


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

typedef long long int ll;

using namespace std;

int main()
{
  ll N,M,tmp,r,x;

  cin >> N >> M;
  if(N<M){
    tmp = N;
    N = M;
    M = tmp;
  }

  x = N * M;
  r = N % M;
  while (r != 0)
  {
    N = M;
    M = r;
    r = N % M;
  }

  cout << x / M << endl;
}

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

int N;
vector<int> C[MAX_N];
int A[MAX_N];

ll dp[MAX_N];

int fd(const vi& vec, int a) {
	return lower_bound(all(vec), a) - vec.begin();
}

ll loop(int at) {
	if(at == N) return 1;
	if(dp[at] != -1) return dp[at];
	int nv = fd(C[A[at]], at + 1);
	ll res = -1;
	if(nv == sz(C[A[at]])) res = loop(at + 1);
	else {
		int nat = C[A[at]][nv];
		if(at + 1 == nat) res = loop(at + 1);
		else res = (loop(at + 1) + loop(nat)) % mod;
	}
	return dp[at] = res;
}


void solve() {
	memset(dp, -1, sizeof(dp));
	cin >> N;
	rep(i, 0, N) {
		cin >> A[i]; A[i]--;
		C[A[i]].pb(i);
	}
	cout << loop(0) << "\n";
	// debug(vi(dp, dp + N));
}

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



Measured memory_bytes: 23296
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
const ll N_MAX = 100000;

const ll MOD = 1000000007;

ll inv[N_MAX],fac[N_MAX],finv[N_MAX];

void init(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        fac[i]=fac[i-1]*(ll) i%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N;
    ll x[100000];
    cin >> N;
    init();
    for(int i = 0; i < N; i++) cin >> x[i];
    ll cur = 0;
    ll ans = 0;
    for(int i = 1; i < N; i++){
        cur += inv[i];
        ans += (cur*(x[i]-x[i-1]))%MOD;
        ans %= MOD;
    }
    ans *= fac[N-1];
    ans %= MOD;
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>

using namespace std;

bool chss(const string s, int l, int r) {
    for(int i = 0; l + i < r - i; i++) {
        if(s[l + i] != s[r - i]) return false;
    }
    return true;
}
int main() {
    string S;
    cin >> S;
    if(chss(S, 0, (S.length() - 3) / 2) == true && chss(S, 0, S.length() - 1) == true) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ans = 0

class UnionFind(object):
    def __init__(self, n):
        self.parent={i:i for i in range(1,n+1)}
        self.size={i:1 for i in range(1,n+1)}
    def find(self, a):
        if self.parent[a]!=a:
            self.parent[a]=self.find(self.parent[a])
        return self.parent[a]
    def getsize(self, a):
        return self.size[self.find(a)]
    def unite(self, a, b):
        a=self.find(a)
        b=self.find(b)
        if a==b:return
        if self.size[a]>self.size[b]:
            self.size[a]+=self.size[b]
            self.parent[b]=a
        else:
            self.size[b]+=self.size[a]
            self.parent[a]=b
    def isunited(self, a, b):
        return self.find(a)==self.find(b)

uft = UnionFind(N)
for _ in range(M):
    x, y, z = map(int, input().split())
    uft.unite(x, y)
group = {uft.find(i) for i in range(1, N+1)}
print(len(group))

Measured memory_bytes: 28512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
			System.out.println("Possible");
		} else {
			System.out.println("Impossible");
		}
	}
}


Measured memory_bytes: 23508
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int k = scan.nextInt();
		for(int i = a; i <= b; i++) {
			if(i < a + k) {
				System.out.println(i);
			} else if(i > b - k) {
				System.out.println(i);
			}
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000000

	
int main(){
	int n,m;
	while(cin >> n >> m && n){
		int land[200][200] , ship[200][200] ;
		rep(i,200)rep(j,200)land[i][j] = ship[i][j] = INF;
		rep(i,200)land[i][i] = ship[i][i] = 0;
		
		rep(i,m){
			string l;
			int a,b,c; cin >> a >> b >> c >> l;
			a--,b--;
			if(l=="L")land[a][b] = land[b][a] = min(c,land[a][b]);
			else      ship[a][b] = ship[b][a] = min(c,ship[a][b]);
		}
		rep(k,n)rep(i,n)rep(j,n)land[i][j] = min(land[i][j],land[i][k]+land[k][j]);
		rep(k,n)rep(i,n)rep(j,n)ship[i][j] = min(ship[i][j],ship[i][k]+ship[k][j]);
		
		int r; cin >> r;
		int R[1000];	
		rep(i,r)cin >> R[i] , R[i]--;
		
		int dp[2][200];
		rep(j,2)rep(k,200)dp[j][k] = INF;
		dp[0][R[0]] = 0;
		
		rep(bit,r-1){
			rep(cur,n){
				rep(next,n){
					int newCost = dp[bit%2][cur] + land[R[bit]][cur] + ship[cur][next] + land[next][R[bit+1]];
					dp[(bit+1)%2][next] = min( dp[(bit+1)%2][next],newCost);
				}
				dp[(bit+1)%2][cur] = min(dp[(bit+1)%2][cur],dp[bit%2][cur]+land[R[bit]][R[bit+1]]);
			}
			rep(j,200)dp[bit%2][j] = INF;
		}
		int ret = INF;
		rep(i,n){
			ret = min(dp[(r-1)%2][i],ret);
		}
		cout << ret << endl;
		
	}
}

Measured memory_bytes: 1240
n,k=map(int,input().split())
mod=10**9+7
lim=n
fcl=[1]*(lim+1)
for i in range(1,lim+1):
  fcl[i]=(fcl[i-1]*i)%mod
def comb(x,y,p):
  return ((fcl[x]*pow(fcl[y],p-2,p))%p*pow(fcl[x-y],p-2,p))%p
ans=0
for i in range(min(n,k+1)):
  ans+=comb(n-1,n-i-1,mod)*comb(n,i,mod)
  ans%=mod
print(ans)

Measured memory_bytes: 42608
#include <cstdio>
#include <cstdlib>
#include <vector>

int binarySearch(int S[], int key, int left, int right) {
  if (right < left) return -1;
  int mid = left + (right - left) / 2;
  if (S[mid] == key) return mid;
  else if (S[mid] > key) return binarySearch(S, key, left, mid - 1);
  else return binarySearch(S, key, mid + 1, right);
}

int main() {
  int n, q, x, c = 0;
  int S[100000], T[50000];

  std::scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    std::scanf("%d", &x);
    S[i] = x;
  }
  std::scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    std::scanf("%d", &x);
    T[i] = x;
  }

  while (q)
    c += (binarySearch(S, T[--q], 0, n - 1) == -1) ? 0 : 1;
  std::printf("%d\n", c);

  return 0;
}



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

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

	int ans = 1;
	int x = 7 % K;
	set<int> mod;
	while (mod.count(x) == 0) {
		if (x == 0) {
			cout << ans << endl;
			return 0;
		}
		mod.insert(x);
		x = (10 * x + 7) % K;
		ans++;
	}
	cout << -1 << endl;
	return 0;
}

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

const int INF = 1001001001;
//const ll INF = 1000000000000000000;

ll a, b, v, w, t;

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

	ll tmp = INF;
	for (int a = 1; a <= sqrt(n); a++) {
		if (n % a != 0) continue;
		ll b = n/a;
		tmp = min(b, tmp);
	}
	int ans = 0;
	string s;
	s = to_string(tmp);
	ans = s.size();
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;
//const ll INF=1LL<<60;

ll inv[MAX],fac[MAX],finv[MAX];

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

ll comb(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*(finv[b]*finv[a-b]%mod)%mod;
}

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

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

const double eps=1e-10;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll a,b,c;cin>>a>>b>>c;
    if(c-a-b>0&&4*a*b<a*a+b*b+c*c-2*a*c-2*b*c+2*a*b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
	ll n;
	cin >> n;
	vector <ld> arr(n+1);
	for (int z=1;z<=n;z++){
		cin >> arr[z];
	}
	vector <vector <ld>> dp(n+1,vector<ld>(n+1,0));
	dp[0][0] = 1;
	for (int z=1;z<=n;z++){
		for (int x=0;x<=z;x++){
			if (x > 0) dp[z][x] += dp[z-1][x-1]*arr[z];
			dp[z][x] += dp[z-1][x]*(1-arr[z]);
		}
	}
	ld ans = 0;
	for (int z=n/2+1;z<=n;z++){
		ans += dp[n][z];
	}
	cout << setprecision(60) << ans << endl;
	cin >> n;
}

Measured memory_bytes: 141056
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,x,v;
  cin >> a >> b >> c;
  x = a - b;
  v = c - x;
  if (v < 0) {
    cout << 0 << endl;
  } else {
    cout << v << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9+10;

int main(){
    int N; cin >> N;
    int cur = -1, tar = 0, cnt = 0,ans = 0;
    for(int i=0;i<N;i++){
        cin >> tar;
        if(cur>=tar){
            cnt++;
            ans = max(ans,cnt);
        }else cnt=0;
        cur = tar;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
int main(void){
    // Your code here!
    int N,h[100],hmax = 0,count=0;
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        scanf("%d\n",&h[i]);
        if(hmax < h[i])
            hmax = h[i];
    }
    for(int i = 1; i <= hmax; i++)
    {
        for(int j = 0; j < N; j++)
        {
            while(h[j] < i && j < N)
            {
                j++;
            }
            //printf("%d ",j);
            if(j < N)
            {
                while(h[j] >= i && j < N)
                {
                    j++;
                }
                count++;
            }
            //printf("%d\n",j);
        }
    }
    printf("%d\n",count);
}


Measured memory_bytes: 128
import qualified Data.ByteString.Char8 as BS
main = do
  [_,t] <- map (read . BS.unpack) . BS.words <$> BS.getLine :: IO [Int]
  ts <- map (read . BS.unpack) . BS.words <$> BS.getLine :: IO [Int] 
  print $ solve ts t

solve :: [Int] -> Int -> Int
solve [_] t = t
solve (x:y:xs) t = min t (y-x) + solve (y:xs) t

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

ll N;
int X[100005];
const ll mod = 1000000007LL;
int main(){
  cin >> N;
  for(int i=0;i<N;i++) cin >> X[i];

  ll res = 1; 
  stack<int> st;
  ll cnt = 0;
  for(int i=0;i<N;i++){
    if( 2*cnt+1 <= X[i] ) {
      st.push( X[i] ); cnt++;
    } else 
      res = (res*(cnt+1LL))%mod;        
  }
  
  for(ll i=1;i<=cnt;i++)
    res = (res*i)%mod;
  cout << res << endl;
}


Measured memory_bytes: 1024
#coding: utf-8

a=gets().chomp()
n=0
w=0
s=0
e=0
i=0
flg=0
while(i<a.length())
	if(a[i]=="S")
		s+=1
	elsif(a[i]=="W")
		w+=1
	elsif(a[i]=="N")
		n+=1
	elsif(a[i]=="E")
		e+=1
	end
	i+=1
end
if((s!=0&&n==0)||(s==0&&n!=0))
	flg=1
end
if((e==0&&w!=0)||(e!=0&&w==0))
	flg=1
end
puts(flg==0?"Yes":"No")


Measured memory_bytes: 1788
#include <iostream> 
#include <cstdio> 
#include <vector> 
using namespace std;  
struct color 
{  
	double L, a, b; 
};  
inline double sqr(double x) 
{ 
	return x*x;
} 
inline double operator-(const color& lhs, const color& rhs) 
{  
	return sqr(lhs.L - rhs.L) + sqr(lhs.a - rhs.a) + sqr(lhs.b - rhs.b); 
}  
int main() 
{  
	int N, M;  cin >> N >> M;  
	vector<color> cs;  
	for (int i = 0; i < N; i++) 
	{  
		color c;  
		cin >> c.L >> c.a >> c.b;  
		cs.push_back(c);  
	}   
	double ans = 0.0;  
	for (int s = 0; s < (1<<N); s++) 
	{  
		vector<color> v;  
		for (int i = 0; i < N; i++) 
		{  
			if (s & (1<<i)) 
			{  
				v.push_back(cs[i]);  
			}  
		}  
		if (v.size() != M) 
		{  
			continue;  
		}   
		double x = 0.0;  
		for (vector<color>::const_iterator it = v.begin(); it != v.end(); ++it) 
		{  
			for (vector<color>::const_iterator jt = it+1; jt != v.end(); ++jt) 
			{  
				x += *it - *jt;  
			} 
		}  
		ans = max(ans, x);  
	}  
	printf("%.6f\n", ans);  
	return 0; 
}  

Measured memory_bytes: 932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


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

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

    sort(all(a));
    ll ans = 0;
    for(int i = 0; i < k; i++){
        ans += a[i];
    }

    cout << ans << endl;



    return 0;

}


Measured memory_bytes: 3616
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


def main():
    N = I()
    NS = str(N)
    ans = 0

    dic = {}

    for j in range(1, 10):
        for k in range(1, 10):
            if j != k:
                dic[10 * j + k] = 0
            else:
                dic[j] = 0

    for i in range(1, N+1):
        if i < 10:
            dic[i] += 1
        else:
            b = int(str(i)[0])
            e = int(str(i)[-1])
            if b == e:
                dic[b] += 1
            elif e != 0:
                dic[10 * b + e] += 1

    # print(dic)
    for j in range(0, 10):
        for k in range(0, 10):
            if 10 * j + k in dic:
                if 10 * j + k < 10:
                    ans += dic[10 * j + k] * dic[10 * j + k]
                else:
                    ans += dic[10 * j + k] * dic[10 * k + j]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41064
#include<iostream>
#include<iomanip>

using namespace std;
const double PI = 3.141592653589;

int main()
{
	double r;
	cin >> r;
	double S, L;
	S = PI * r * r;
	L = 2 * PI * r;

	cout << setprecision(5) << fixed << S << " " << setprecision(5) << fixed << L << endl;

}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int n,m;
vector<int> edges[100010];
vector<ll> dp(100010,1),ans(100010,0);

void dfs1(int i, int p = -1) {
    for (int& j : edges[i]) if (j != p) {
        dfs1(j,i);
        (dp[i] *= dp[j]+1) %= m;
    }
}

void dfs2(int i,ll c = 0,int p = -1) {
    ans[i] = dp[i]*(c+1)%m;
    int n = edges[i].size();
    vector<ll> x(n),prod1(n+1,1),prod2(n+1,1);
    for (int j = 0;j < n;++j) {
        if (edges[i][j] == p) x[j] = c+1;
        else x[j] = dp[edges[i][j]]+1;
    }
    for (int j = 0;j < n;++j) prod1[j+1] = prod1[j]*x[j]%m;
    for (int j = n-1;j >= 0;--j) prod2[j] = prod2[j+1]*x[j]%m;
    for (int j = 0;j < n;++j) if (edges[i][j] != p) {
        dfs2(edges[i][j],prod1[j]*prod2[j+1]%m,i);
    }
    // p_ary(prod1,0,n,j);
    // p_ary(prod2,0,n,j);
}

int main() {
    cin >> n >> m;
    for (int i = 0;i < n-1;++i) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    dfs1(0);
    dfs2(0);
    // p_ary(dp,0,n,i);
    // p_ary(ans,0,n,i);
    for (int i = 0;i < n;++i) cout << ans[i] << "\n";
    return 0;
}

Measured memory_bytes: 22016
#include<iostream>
using namespace std;
int main(){
  int a,b;
  string s,t,u;
  cin >> s >> t >> a >> b >> u;
  if(s==u){
    a--;
  }
  else if(t==u){
    b--;
  }
  cout << a << ' ' << b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
#define LL long long
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
LL n,m,l,dis[305][305],newdis[305][305];

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    cin>>n>>m>>l;
    for(int i=1;i<305;i++)
    {
        for(int j=1;j<305;j++)
        {
            dis[i][j]=newdis[i][j]=inf;
        }
        dis[i][i]=newdis[i][i]=0;
    }
    for(int i=0;i<m;i++)
    {
        int u,v;
        LL w;
        cin>>u>>v>>w;
        newdis[u][v]=dis[u][v]=w;
        newdis[v][u]=dis[v][u]=w;
    }
    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(dis[i][k]!=inf&&dis[k][j]!=inf)
                    dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            newdis[i][j]=(dis[i][j]<=l?1:inf);
        }
        newdis[i][i]=0;
    }
    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(newdis[i][k]!=inf&&newdis[k][j]!=inf)
                    newdis[i][j]=min(newdis[i][j],newdis[i][k]+newdis[k][j]);
            }
        }
    }
    int q;
    cin>>q;
    int s,t;
    while(q--)
    {
        cin>>s>>t;
        if(newdis[s][t]==inf)
        {
            cout<<"-1\n";
        }
        else
        {
            cout<<newdis[s][t]-1<<"\n";
        }
    }
	return 0;
}

Measured memory_bytes: 2048
from statistics import mean
import math

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

mean_num = mean(A)
Ceil = math.ceil(mean_num)
Floor = math.floor(mean_num)

Ceil_sum = 0
Floor_sum = 0
for i in A:
    Ceil_sum += (Ceil - i) ** 2
for i in A:
    Floor_sum += (Floor - i) ** 2

print(min(Floor_sum, Ceil_sum))

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

int main(){
    int A[10000];
    int i;
    int n; cin >> n;
    int min, max;
	long long sum;
    min = 1000001;
    max = -1000001;
    sum = 0;
    for(i = 0; i < n; i++){
        cin >> A[i];
        sum += A[i];
        if(max < A[i]){ max = A[i]; }
        if(min > A[i]){ min = A[i]; }
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;
}

// sumはintの範囲を逸脱する。注意点はそこだけ。


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

#define loop(n) for(int i = 0;i < (int)(n);++i)
#define rep(i,n) for(int i = 0;i < (int)(n);++i)
#define all(vec) (vec).begin(),(vec).end()
#define Sort(vec) sort(all(vec))
#define Rev(vec) reverse(all(vec))

using Graph = vector<vector<int>>;

namespace Input
{
                
    void input(){return;}
    template<typename First,typename... Rest> void input(First &first,Rest&... rest){
    std::cin >> first;
    input(rest...);
}
    
    void inputVec(){return;}
    template<typename First,typename... Rest> void inputVec(vector<First> &first,Rest&... rest){
        int N = first.size();
        for(int i = 0;i < N;i++){
            cin >> first[i];
        }
        inputVec(rest...);
    }
    
    template<typename First,typename Second> void inputTwoVec(vector<First> &first,vector<Second>& second){
        int N = first.size();
        for(int i = 0;i < N;i++){
            cin >> first[i] >> second[i];
        }
    }

    void inputGraph(Graph &g,int path_num,bool isdirected){
        for(int i = 0;i < path_num;i++){
            int a,b;
            cin >> a >> b;
            a--;b--;
            if(isdirected){
                g[a].push_back(b);
            }
            else{
                g[a].push_back(b);
                g[b].push_back(a);
            }
        }
    }
}

void calculate(){
    int n,k;
    Input::input(n,k);
    set<int> people;
    int tmp,d;
    rep(i,k){
        cin >> d;
        rep(j,d){
            cin >> tmp;
            auto i = people.insert(tmp);
            if(i.second) n--;
        }
    }
    cout << n << '\n';
}

int main(int,char**){
    calculate();    
}




Measured memory_bytes: 3644
# ABC 156 B
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nms = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))
from math import log
n,k=nm()
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
print(len(Base_10_to_n(n, k)))

Measured memory_bytes: 3064
def solve(n,k):
    for i in range(len(n)):
        if n[i] != 0:
            break
    n = n[i:]
    if n == []:
        return 0
    l = len(n)
    ans = 0
    # n-1桁からKこ取る
    tmp = 1
    for i in range(1, k+1):
        tmp = tmp*9*(l-i)
    for i in range(1, k+1):
        tmp = tmp // i
    ans += tmp

    # 最上位から1つ（最上位の数以外）とる。
    tmp = n[0]-1
    for i in range(1, k):
        tmp = tmp*9*(l-i)
    for i in range(1, k):
        tmp = tmp // i
    ans += tmp

    # 最上位からその数をとる。
    tmp = 0
    if k == 3:
        tmp += solve(n[1:],k-1)

    elif k == 2:
        for i in range(1, l):
            if n[i] != 0:
                tmp += n[i] + 9*(l-i-1)
                break
    else:
        tmp += 1
    ans += tmp
    return ans

n = list(map(int, input()))
k = int(input())

print(solve(n,k))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testcases \
    int tcc;      \
    cin >> tcc;   \
    for (int tc = 1; tc <= tcc; tc++)
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while (!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
    fast_io;
    int n,m; cin>>n>>m;
    vi h(n); in(h);
   	vector<set<int>> v(n);
    lp(i,0,m){
    	int x,y; cin>>x>>y; x--;y--;
    	v[x].insert(h[y]);
    	v[y].insert(h[x]);
    }
    int ans=0;
    lp(i,0,n){
    	if(v[i].empty() || h[i]>(*(v[i].rbegin()))) ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 17696
a = input()
b = a.split()
c = [0]*len(b)
for i in range(len(b)):
    c[i]= int(b[i])
d = c[0]
e = c[1]
c[0] = c[2]
c[1] = d
c[2] = e

print(' '.join(map(str, c)))


Measured memory_bytes: 3060
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
#include<iomanip>
#include<tuple>
#include<stack>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;
typedef tuple<int, int, int> ti3;

const ll MOD_CONST = 1000000007;
//const ll MOD_CONST = 998244353;


const int INF = 1000000000;
//const ll INF = 1000000000000000000;



int main() {
	
	string a;
	cin >> a;
	
	int n = a.length();

	map<char, int> m;
	for (int i = 0; i < n; i++) {
		m[a[i]]++;
	}

	ll ans = 1;
	for (int i = 0; i < n; i++) {
		m[a[i]]--;
		ans += (n - i - 1);
		ans	-= m[a[i]];

	}
	cout << ans << endl;

}



Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()

int main() {
  int a;
  cin >> a;
  vi b(a);
  rep(i, a) {
    cin >> b.at(i);
  }
  sort(ALL(b));
  cout << b.at(a-1)-b.at(0);
}

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

int main () {
  string S, T;
  cin >> S >> T;
  bool ans = false;
  for (int i = 0; i < S.size(); i++) {
    if (S == T) {
      ans = true;
      break;
    }
    S = S.back() + S.substr(0, S.size()-1);
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

//input
use proconio::input;
use proconio::marker::{Bytes, Chars};
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        r: f64,
    }

    let pi = 3.14159265358979323846264;

    println!("{}", 2. * pi * r);
}


Measured memory_bytes: 2200
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  ll n,m,x[120000],y[120000],a;
  a=0;
  cin >> n >> m;
  rep(i,m)cin >> x[i];
  sort(x,x+m);
  rep(i,m-1)y[i]=x[i+1]-x[i];
  sort(y,y+m-1);
  FOR(i,m-n,m-1)a+=y[i];
  printf("%lld",x[m-1]-x[0]-a);
}

Measured memory_bytes: 1792
h,w=map(int,input().split());p=[["."]*(w+2)]+[["."]+list(map(str,input()))+["."]for i in range(h)]+[["."]*(w+2)]
print("Yes"if all([any([p[i+x[0]][I+x[1]]=="#"for x in [[0,1],[0,-1],[1,0],[-1,0]]])for I in range(1,w+1)for i in range(1,h+1)if p[i][I]=="#"])else"No")

Measured memory_bytes: 3064
X = int(input())

if X >= 400 and X <= 599:
  print(8)
elif X >= 600 and X <= 799:
  print(7)
elif X >= 800 and X <= 999:
  print(6)
elif X >= 1000 and X <= 1199:
  print(5)
elif X >= 1200 and X <= 1399:
  print(4)
elif X >= 1400 and X <= 1599:
  print(3)
elif X >= 1600 and X <= 1799:
  print(2)
elif X >= 1800 and X <= 1999:
  print(1)

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vvi d(n, vi(n, INF));
	REP(i, n)d[i][i] = 0;
	int m, r;
	cin >> m>>r;
	vi v(r);
	REP(i, r) {
		cin >> v[i];
		v[i]--;
	}
	REP(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		d[a][b] = c;
		d[b][a] = c;
	}

	REP(k, n) {
		REP(i, n) {
			REP(j, n) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	sort(ALL(v));
	int ans = INF;
	do {
		int tmp = 0;
		REP(i, r - 1) {
			tmp += d[v[i + 1]][v[i]];
		}
		ans = min(ans, tmp);
	} while (next_permutation(ALL(v)));
	cout << ans << endl;

}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
    int n;
    char s[50+1];
    int c=0;
    scanf("%d",&n);
    scanf("%s",s);
    for(int i=0;i<n;i++){
        if((s[i]=='A')&&(s[i+1]=='B')&&(s[i+2]=='C')){
            c++;
        }else{
 
        }
    }
    printf("%d\n",c);
}

Measured memory_bytes: 1708
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cinttypes>
#include <algorithm>

#define REPEAT(token, num) for (token = 0; token < num; token++)

//#define DEBUG
#ifdef DEBUG
#define PRINTF printf
#else
#define PRINTF(...)
#endif

typedef int64_t weight;
typedef int64_t value;
struct object {
    weight w;
    value v;
};
typedef int64_t num_objects;

object objects[1000];
num_objects numObjects;
weight maxWeight, minWeight[200][100010];

num_objects i;
value maxValue, curValue;

int main() {
    scanf("%" PRId64 " %" PRId64, &numObjects, &maxWeight);
    REPEAT(i, numObjects) scanf("%" PRId64 " %" PRId64, &(objects[i].w), &(objects[i].v));
    
    maxValue = 0;
    REPEAT(i, numObjects) {
        minWeight[i][0] = 0;
        for (curValue = 1; curValue <= numObjects*1000; curValue++) {
            minWeight[i][curValue] = (i == 0) ? (maxWeight+1) : minWeight[i-1][curValue];
            if (curValue >= objects[i].v) {
                if (i == 0) {
                    if (curValue == objects[i].v) minWeight[i][curValue] = std::min(minWeight[i][curValue], objects[i].w);
                } else minWeight[i][curValue] = std::min(minWeight[i][curValue], minWeight[i-1][curValue-objects[i].v]+objects[i].w);
            }
            if (minWeight[i][curValue] <= maxWeight) maxValue = std::max(maxValue, curValue);
        }
    }
    printf("%" PRId64 "\n", maxValue);
    
    exit(0);
}

Measured memory_bytes: 80000
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int a,b,i,c;
    cin>>a>>b;
    if (a!=b){
        if (a==1){
            cout<<"Alice";
        }
        else if (b==1){
            cout<<"Bob";
        }
        else if (a>b){
            cout<<"Alice";
        }
        else if (a<b){
            cout<<"Bob";
        }
    }
    else
        cout<<"Draw";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

string S;

void solve() {
    char before = ' ';
    int ans = 0;
    EACH(s, S) {
        if (s != before) ans++;
        before = s;
    }
    cout << ans - 1 << endl;
}

int main() {
    cin >> S;
    solve();
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int r, d, x;
void inp() {
    cin >> r >> d >> x;
}
void pc() {
    for(int i=1; i<=10; ++i) {
        x = x*r-d;
        cout << x << "\n";
    }
}
int main()
{
    inp(); pc();
    return 0;
}


Measured memory_bytes: 256