akhauriyash/Code-Regression huggingface dataset:
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b,a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

int main() {
	ll N; cin >> N;
	vector<ll> a(N); rep(i, N)cin >> a[i];

	sort(ALL(a));

	vector<ll> cnt(a[N - 1] + 1);

	rep(i, N) cnt[a[i]]++;
	

	ll mx = cnt[0] + cnt[1];
	for (int i = 1; i <= a[N - 1]; i++) {
		if (i == a[N - 1]) {
			mx = max(mx, cnt[i - 1] + cnt[i]);
			continue;
		}
		mx = max(mx, cnt[i - 1] + cnt[i] + cnt[i + 1]);
	}

	cout << mx << endl;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Date;


public class Main {
	static int count = 0;

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] A = new int[n];

		String[] tmpArray = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			A[i] = Integer.parseInt(tmpArray[i]);
		}

		Date from = new Date();
		mergeSort(A, 0, A.length);
		Date to = new Date();
		//System.out.println("sort spends "+ (to.getTime() - from.getTime()) + "milli sec");

		StringBuffer sb = new StringBuffer();
		for(int i = 0; i < A.length ; i++){
			//System.out.print(A[i]);
			sb.append(A[i]);
			if(i != A.length - 1){
				//System.out.print(" ");
				sb.append(" ");
			}
		}
		//System.out.println();
		//sb.append("\n");
		System.out.println(sb.toString());
		System.out.println(count);

	}

	static void merge(int[] A, int left, int mid, int right){
		int n1 = mid - left;
		int n2 = right - mid;
		int[] L = new int[n1+1];
		int[] R = new int[n2+1];

		for(int i = 0; i < n1 ; i++){
			L[i] = A[left + i];
		}
		for(int i = 0; i < n2 ; i++){
			R[i] = A[mid + i];
		}
		L[n1] = Integer.MAX_VALUE;
		R[n2] = Integer.MAX_VALUE;
		int i = 0;
		int j = 0;
		for(int k = left ; k < right; k++){
			if(L[i] <= R[j]){
				A[k] = L[i];
				i++;
				count++;
			}
			else {
				A[k] = R[j];
				j++;
				count++;
			}
		}
	}

	static void mergeSort(int[] A, int left, int right){
		int mid;
		if(left + 1 < right){
			mid = (left + right)/2;
			mergeSort(A, left, mid);
			mergeSort(A, mid, right);
			merge(A, left, mid, right);
		}
	}
}

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

int main() {
  int n;
  cin >> n;
  vector<int> val(n), cost(n);
  for (int i = 0; i < n; i++) cin >> val.at(i);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> cost.at(i);
    if (val.at(i) > cost.at(i)) sum += val.at(i) - cost.at(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);    
		int X = in.nextInt();
		int Y = in.nextInt();
		int Z = in.nextInt();  
		int T = 0;
		T = X;
		X = Y;
		Y = T;
		T = X;
		X = Z;
        Z = T;
		System.out.println(X+" "+Y+" "+Z);
    }
}


Measured memory_bytes: 21844
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
#n = ip()                                     #入力整数1つ
a,b= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから
if a%b == 0:
    print(-1)
else :
    print(a)


Measured memory_bytes: 21080
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		String tmp = s.substring(0, (n - 1) / 2);
		String tmp2 = s.substring((n + 1) / 2, n);
		boolean flag = true;
		for (int i = 0; i < s.length() / 2; i++) {
			if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
				flag = false;
				break;
			}
		}
		if (!flag) {
			System.out.println("No");
		} else {
			flag = true;
			for (int i = 0; i < tmp.length() / 2; i++) {
				if (tmp.charAt(i) != tmp.charAt(tmp.length() - 1 - i)) {
					flag = false;
					break;
				}
			}
			if (!flag) {
				System.out.println("No");
			} else {
				flag = true;
				for (int i = 0; i < tmp2.length() / 2; i++) {
					if (tmp2.charAt(i) != tmp2.charAt(tmp2.length() - 1 - i)) {
						flag = false;
						break;
					}
				}
				if (flag) {
					System.out.println("Yes");
				} else {
					System.out.println("No");
				}
			}
		}
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define mem1(x)  memset(x,1,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
const ll md = 1e9 + 7;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return pow(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
ll po(ll x,ll n){
    if(n==0) return 1;
    if(n%2==1) return (x*po(x,n-1));
    else {
        ll k=po(x,n/2);
        return (k*k);
    }
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
 
const ll N = 100005;
ll a[N],dp[N];

int32_t main(){
    IOS;
    ll i,j,k,n,m,p;
    cin >> n;
    fori2(n) cin >> a[i];
    for(i = 2 ; i <= n  ; i++){
        dp[i] = dp[i-1] + abs(a[i]-a[i-1]);
        if(i>2){
            dp[i] = min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
        }
    }
    cout << dp[n] <<"\n";


} 

Measured memory_bytes: 1792
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (1000003LL)
typedef long long Int;

int n, mi, memo[60000*4], cs[60000][2];
vector<int> g[60000];
bool has[60000];

void add(int p, int q) {
    if (p > q) swap(p, q);
    g[p].push_back(q);
}

int pre(int p, int q) {
    if (p+1 == q) return -1;
    const int k = mi++;
    has[k] = false;
    if (g[p].back() == q) {
        has[k] = true;
        g[p].pop_back();
    }
    const int r = g[p].back();
    rep (b, 4) memo[k*4|b] = -1;
    cs[k][0] = pre(p, r);
    cs[k][1] = pre(r, q);
    return k;
}

int rec(int k, int x, int y) {
    if (k == -1) return x == y;
    const int sig = k*4|x*2|y;
    if (memo[sig] != -1) return memo[sig];
    const int p = cs[k][0], q = cs[k][1];
    Int ans = 0;
    rep (i, 2) ans = (ans + (Int)rec(p, x, i)*rec(q, 1-i, y)) % MOD;
    if (x && y && has[k]) {
        rep (i, 2) ans = (ans + (Int)rec(p, 0, i)*rec(q, 1-i, 0)) % MOD;
    }
    return memo[sig] = ans;
}

int main() {
    for (;;) {
        int m, a, b;
        scanf("%d%d", &n, &m);
        if (n == 0) return 0;
        rep (i, n) g[i].clear();
        rep (_, m) {
            scanf("%d%d", &a, &b);
            add(a-1, b-1);
        }
        rep (i, n) add(i, (i+1)%n);
        rep (i, n) sort(g[i].begin(), g[i].end());
        mi = 0;
        pre(0, n-1);
        printf("%d\n", (int)rec(0, 1, 1));
    }
}

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


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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; }

int N;
long long h[100005];
long long dp[100005];

int main() {

   cin >> N;
   for(int i = 0; i < N; i++) cin >> h[i];



   for(int i = 0; i < N; i++) {

        dp[i] = -1;
   }

    dp[0] = 0;

   dp[1] = abs(h[0] - h[1]);

   for(int i = 2; i < N; i++) {

        dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]), dp[i-2] + abs(h[i-2] - h[i]));
   }

   cout << dp[N-1] << endl;





    return 0;

}








Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

set<ll> st;

void dfs(ll k){
    if(k>5000000000ll) return ;
    ll las=k%10;
    if(las!=0){
        st.insert(k*10+las-1);
        dfs(k*10+las-1);
    }
    st.insert(k*10+las);
    dfs(k*10+las);
    if(las!=9){
        st.insert(k*10+las+1);
        dfs(k*10+las+1);
    }
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    for(int i=1;i<10;i++){
        st.insert(i);
        dfs(i);
    }
    int k;cin>>k;
    for(auto x:st){
        k--;
        if(k==0){
            cout<<x<<endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 18176
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	char n,m;
	char ball='A';
	for(;~scanf("%c,%c\n",&n,&m);){
		if(ball==n)ball=m;
		else if(ball==m)ball=n;
	}
	cout<<ball<<endl;
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=6,C=301,S=1<<5;
int l[N],f[C][C][S],p[N];
inline int fac(ri n){
	if(n==1) return 1;
	return n*fac(n-1);
}
inline int fpow(ri a,ri b){
	ri ans=1;
	for(;b;b>>=1,a*=a)
		if(b&1)
			ans*=a;
	return ans;
}
int main(){
	ri n,c,i,j,s,x;
	register long long ans;
	gi(n);gi(c);
	for(i=0;i<n;++i) gi(l[i]),p[i]=i;
	sort(l,l+n,[&](ri x,ri y){ return x>y ; });
	ans=0;
	do{
		memset(f,0,sizeof(f));
		f[0][l[0]*n][0]=1;
		for(i=0;i<c*n-1;++i)
			for(j=i+1;j<=c*n;++j)
				for(s=0;s<1<<n-1;++s)
					if(f[i][j][s]){
					//	printf("f %d %d %d %d\n",i,j,s,f[i][j][s]);
						if(j>i+1) f[i+1][j][s]+=f[i][j][s];
						x=p[(i+1)%n];
						if(x&&~s&1<<x-1)
							f[i+1][min(c*n,max(j,i+1+l[x]*n))][s|1<<x-1]+=f[i][j][s];
					}
		ans+=f[c*n-1][c*n][(1<<n-1)-1];
	//	printf("ans = %lld\n",ans);
	}while(next_permutation(p+1,p+n));
	printf("%.16Lf\n",(long double)ans/fac(n-1)/fpow(c,n-1));
	return 0;
}

Measured memory_bytes: 14720
#include <bits/stdc++.h>
using namespace std;
#define rep for(int i = 0;i<n;i++)
#define ll long long
 
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;

int main(){
    string s;cin >> s;
    string frag = "NO";
    string k = "keyence";
    for(int i = 0;i<7;i++){
        bool tmp = true;
        for(int j = 0;j+i<7;j++){
            //cout << i <<" "<< j<<endl;
            if(s.at(j) != k.at(j)) tmp = false;
        }
        for(int l = 7-i;l<7;l++){
            //cout << i << " " << l <<" "<<s.size()-(7-l)<< endl;
            if(s.at(s.size()-(7-l)) != k.at(l)) tmp = false;
        }
        if(tmp == true) frag = "YES";
    }
    cout << frag << endl;
}

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

int main(void) {
	char s[1000];
	int i, w;
	
	scanf("%s", &s[0]);
	scanf("%d", &w);
	
	for (i = 0; i < strlen(s); i++)
		if (i % w == 0)
			printf("%c", s[i]);
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int js,a[100010],to[100010];
int n,m,c,b,ans,sum,dp[100010];
vector <int> v[100010];
vector <int> vv[100010];
inline void topsort()
{
	queue <int> q;
	for(int i=1;i<=n;++i){
		if(!to[i])q.push(i);
	}
	while(!q.empty()){
		int x=q.front();
		q.pop();
		if(to[x]==0)a[++js]=x;
		for(int i=0;i<v[x].size();++i){
			to[v[x][i]]--;
			if(to[v[x][i]]==0)q.push(v[x][i]);
		}
	}
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;++i){
		scanf("%d%d",&c,&b);
		v[c].push_back(b);
		vv[b].push_back(c);
		to[b]++;
	}
	topsort();
	//for(int i=1;i<=n;++i)cout<<a[i]<<" ";
	//cout<<endl;
	for(int i=1;i<=n;++i){
		int k=a[i];
		for(int j=0;j<vv[k].size();++j){
			dp[k]=max(dp[k],dp[vv[k][j]]+1);
			ans=max(ans,dp[k]);
		}
	}
	for(int i=1;i<=n;++i)ans=max(ans,dp[i]);
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")

using ll = std::int64_t;
using vint = std::vector<std::int32_t>;
using vll = std::vector<ll>;
using vstr = std::vector<std::string>;
using pint = std::pair<std::int32_t, std::int32_t>;
using usetint = std::unordered_set<std::int32_t>;
using usetstr = std::unordered_set<std::string>;

constexpr std::int32_t INF = 1001001001;

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

void Main() {
    int N, X;
    cin >> N >> X;
    vint x(N);
    rep(i, N) {
        cin >> x[i];
        x[i] -= X;
        x[i] = abs(x[i]);
    }

    int ans = x[0];
    REP(i, 1, N) {
        ans = min(gcd(x[i], ans), ans);
    }
    cout << ans << endl;


}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 640
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

print(max(a)-min(a))

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

int main() {
    string s; long long k;
    cin >> s >> k;
    string c = s;
    if(count(s.begin(), s.end(), s[0]) == s.size()) cout << s.size() * k / 2 << endl;
    else {
        long long res = 0;
        for (int i = 1; i < c.size(); i++)
        {
            if(c[i] == c[i-1]) {
                c[i] = '?';
                res++;
            }
        }

        if(s.front() != s.back()) cout << res * k << endl;
        else {
            long long a = 0, b = 0;
            for(int i = 0; i < s.size(); i++){
                if(s[i] != s[0]) break;
                a++;
            }
            for (int i = 0; i < s.size(); i++)
            {
                if(s[s.size()-1-i] != s[s.size()-1]) break;
                b++;
            }
            long long sub = a / 2;
            sub += b / 2;
            sub -= (a + b) / 2;
            cout << res * k - sub * (k - 1) << endl;
        }
    }
	return 0;
}


Measured memory_bytes: 256
macro_rules! get_tuple {
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };

    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get_tuple!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (a, b) = get_tuple!(usize, usize);
    println!("{}", a * b)
}


Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;

int main(){

    int W, H , N;
    cin >> W >> H >> N;

    int x_min = 0;
    int x_max = W;
    int y_min = 0;
    int y_max = H;

    for(int i = 0; i < N; i++){
        int x, y, a;
        cin >> x >> y >> a;
        if(a == 1){
            x_min = max(x_min, x);
        }
        if(a == 2){
            x_max = min(x_max, x);
        }
        if(a == 3){
            y_min = max(y_min, y);
        }
        if(a == 4){
            y_max = min(y_max, y);
        }
    }
    
    if(x_max - x_min <= 0 || y_max - y_min <= 0) cout << 0 << endl;
    else cout <<  (x_max - x_min) * (y_max - y_min) << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> nums[100005];
int main(){
  ll t1,t2,a1,a2,b1,b2;
  cin>>t1>>t2>>a1>>a2>>b1>>b2;
  if(a1<b1){
    swap(a1,b1);
    swap(a2,b2);
  }
  ll t=t1*(a1-b1),d=t+t2*(a2-b2);
  if(d>0) cout<<0<<endl;
  else if(d==0) cout<<"infinity"<<endl;
  else{
    t*=-1;
    ll ans=t/d;
    ans*=2;
    if((ans/2)*d==t) ans--;
    cout<<ans+1<<endl;
  }

}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    string O,E; cin >> O >> E;
    rep(i,O.size()+E.size()){
        if(i%2==0) cout << O[i/2];
        else cout << E[(i-1)/2];
    }
    cout << endl;
    return 0;
}

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

#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 llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define INF 1000000007
#define MOD 1000000007
#define ARRAY_MAX 15



int n,m;
bool mp[ARRAY_MAX][ARRAY_MAX];

int dfs(int now,int n,vector<bool>& visited){
    //今いる位置、頂点の数、訪れたかのチェック配列

    int sum = 0;//この再帰から得られる経路数

    bool all_visited = true;//全て訪れたか

    REP(i,n){
        if(visited[i] == false){
            all_visited = false;
            break;
        }
    }

    if(all_visited){
        return 1;
    }

    REP(i,n){
        if(mp[now][i] == false){
            //経路がない
            continue;
        }
        if(visited[i] == true){
            //既に訪れている
            continue;
        }
        visited[i] = true;//訪れたことにして潜る
        sum += dfs(i,n,visited);//訪れるとして再帰
        visited[i] = false;//訪れないで別の経路でできるかを試す
    }
    return sum;
}


int main(){

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

    vector<bool> visited(ARRAY_MAX,false);
    REP(i,n){
        visited[i]=false;
    }
    visited[0] = true;
    cout << dfs(0,n,visited) << endl;

    return 0;
}

Measured memory_bytes: 256
import math
 
n = int(input())
h = list(map(int, input().split()))
 
res = [0]*n
 
for i in range(1, n):
  if i == 1:
    res[1] = abs(h[0] - h[1])
  else:
    temp1 = abs(h[i] - h[i-2])
    temp2 = abs(h[i] - h[i-1])
    
    res[i] = min(res[i-2] + temp1, res[i-1] + temp2)
  
print(res[n-1])

Measured memory_bytes: 14104
import java.util.*;

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

		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		if(a < b && b < c) System.out.println("Yes");	
		else System.out.println("No");
		/*if(a < b) System.out.println("a < b");
		else if(a > b) System.out.println("a > b");
		else System.out.println("a == b");
		int[] time_get = henkan(scan.nextInt());
	
		for(int i = 0; i < 3; i++) {
			if(i != 2) System.out.print(time_get[i] + ":" );
			else System.out.println(time_get[i]);
		}

	}

	static int[] henkan(int time_input) {
		int[] times = new int[3];
		times[0] = time_input / 3600;
		time_input = time_input - times[0] * 3600;
		times[1] = time_input /60;
		times[2] = time_input - times[1] * 60;
		
		return times;*/
	}
}

Measured memory_bytes: 17276
#include <stdio.h>

int main(void){
    int Box[101][101];
    int Tate,Yoko;
    int TTate[101],YYoko[101];
    int i,j;
    int Mix=0;
    
    scanf("%d %d",&Tate,&Yoko);
    
    for(i=0;i<Tate;i++){
        for(j=0;j<Yoko;j++){
            scanf("%d",&Box[i][j]);
            Mix += Box[i][j];
        }
    }
    for(i=0;i<Yoko;i++){
        TTate[i]=0;
        for(j=0;j<Tate;j++){
            TTate[i]+=Box[j][i];
        }
    }
    
    for(i=0;i<Tate;i++){
        YYoko[i]=0;
        for(j=0;j<Yoko;j++){
            YYoko[i]+=Box[i][j];
        }
    }
    
    for(i=0;i<Tate;i++){
        for(j=0;j<Yoko;j++){
            printf("%d ",Box[i][j]);
        }
        printf("%d\n",YYoko[i]);
    }
    for(i=0;i<Yoko;i++){
        printf("%d ",TTate[i]);
    }
    printf("%d\n",Mix);
}


Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#define inf 1e9
using namespace std;


int minCost(vector<int> heights , int n , int k) {

	vector<int> dp(n + 1);
	dp[0] = dp[1] = 0;
	for (int i = 2; i <= n; i++) {
		dp[i] = inf;
		for (int j = i - 1; j >= 1 and j >= (i - k); j--) {
			dp[i] = min(dp[i], abs(heights[i] - heights[j]) + dp[j]);
		}
	}
	return dp[n];
}


int main() {

	int n, k;
	cin >> n >> k;
	vector<int> heights(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> heights[i];
	}
	cout << minCost(heights, n, k) << endl;

	return 0;
}

Measured memory_bytes: 1408
n, q = gets.split.map(&:to_i)
s = gets.chomp
t = Array.new(n, 0)
ans = []
n.times do |i|
  t[i] = t[i-1] + (s[i-1, 2] == 'AC' ? 1 : 0)
end
q.times do |i|
  l, r = gets.split.map(&:to_i)
  ans[i] = t[r-1] - t[l-1]
end
puts ans

Measured memory_bytes: 4220
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef long long LL;
const int INF = int(1e9);

LL N,A,B;
LL a[1000006];

bool pan(LL x)
{
    LL sum = 0;
    for(int i = 1;i<=N;i++)
    {
        LL t = a[i] - x*B;
        if(t>0)
        {
            sum += (LL)ceil(t*1.0/(A-B));
            if(sum>x||sum<0)
                return false;
        }
    }
    return true;
}

int main()
{
    cin>>N>>A>>B;
    for(LL i = 1;i<=N;i++)
        cin>>a[i];
    sort(a+1,a+1+N);

    LL L = 1,R = a[N]+1,mid;
    while(L<R)
    {
        mid = (R+L)>>1;
        //cout<<L<<" "<<R<<" "<<mid<<endl;
        if(pan(mid))
            R = mid;
        else
            L = mid+1;

    }

    cout<<R<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define EPS 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f3f3f3f3f
#define MEM(a, b) memset(a, b, sizeof(a))
#define PPER(i, n, m) for (int i = n; i >= m; i--)
#define REPP(i, n, m) for (int i = n; i <= m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define PER(i, n, m) for (int i = n; i > m; i--)
#define SA(n) scanf("%d", &(n))
#define SLLA(n) scanf("%lld", &(n))
#define MP make_pair
#define FF first
#define SS second
#define PB push_back
#define DE(val) cout << #val << ": " << val << endl;
 
const int dx44[6] = {0, -1, -1, 1, 1};
const int dy44[6] = {0, -1, 1, -1, 1};
const int dx4[6] = {0, 0, 1,-1};
const int dy4[6] = {1, -1, 0,0};
const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int dx82[9] = {0, -1, -1, 1, 1, 2, 2, -2, -2};
const int dy82[9] = {0, 2, -2, 2, -2, 1, -1, 1, -1};

void update(ll& x,ll v){
    if(x==-1)x=v;
    else if(x>v)x=v;
}
 
ll po(ll a, ll b, ll mod)
{
    ll res = 1;
    a %= mod;
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
    {
        return b;
    }
    else
    {
        return gcd(b % a, a);
    }
}
void extgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
    if (!b)
    {
        d = a;
        x = 1;
    }
    else
    {
        extgcd(b, a % b, d, y, x);
        y -= x * (a / b);
    }
}
ll inverse(ll a, ll n)
{
    ll d, x, y;
    extgcd(a, n, d, x, y);
    return d == 1 ? (x + n) % n : -1;
}
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const int maxn = 2e5 + 15;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
#define mst(x, a) memset(x, a, sizeof(x))
/*************************************************************************/

set<string>v;
void solve() {
    int n;
    cin>>n;
    REPP(i,1,n) {
        string t;
        cin>>t;
        v.insert(t);
    }
    cout<<v.size()<<endl;
} 

int main()
{   
#ifndef ONLINE_JUDGE
    // freopen("i.txt", "r", stdin);
    // freopen("o.txt", "w", stdout);
#endif

    solve();
    // int t;
    // SA(t);
    // REPP(i,1,t) {
    //     printf("Case #%d: ", i);
    //     solve();
    // }
    return 0;
 
}
 

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

int main(){
  
  string s,t;
  cin >> s >> t;
  
  int start[26]={};
  int end[26]={};
  
  for(int i=0;i < s.size();i++){
    int a = s[i]-'a';
    int b = t[i]-'a';

    if(start[a] != 0 || end[b] != 0){
      if(start[a] != b || end[b] != a){
	cout << "No" << endl;
	return 0;
      }
    }
    else{
      start[a] = b;
      end[b] = a;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <math.h>
using namespace std;

int main(int argc, char const* argv[])
{
	string s;
	while (cin >> s && s != "0") {
		int sum = 0;
		for (int i=0; i<s.size(); i++) {
			sum += s[i] - '0';
		}
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 1188
#include<stdio.h>

#define N 1000000

int A[N], n;

int binarySearch(int key){
  int left = 0;
  int mid;
  int right = n;
 
  while(left < right){
    mid = (left+right)/2;
    if(key == A[mid])    return 1;
    if(key>A[mid])       left = mid+1;
    else if              (key<A[mid])right=mid;
  }
  return 0;
}

int main(){
  int i, sum=0, s, t;
  scanf("%d", &n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  scanf("%d", &s);
for(i=0; i<s; i++){
 scanf("%d", &t);
 if( binarySearch(t))sum++;
  }


 printf("%d\n", sum);
  return 0;
}



Measured memory_bytes: 2140
#include<iostream>

int main()
{
	int H, W;
	while (1) {
		std::cin >> H >> W;
		if (H == 0 && W == 0)break;

		for (auto i = 0; i < H; i++) {
			for (auto j = 0; j < W; j++) {
				if ((i + j) % 2 == 0)
					std::cout << '#';
				else if ((i+ j) % 2 == 1)
					std::cout << '.';
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
	}
}

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

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    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 << '\n';
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)
typedef long long ll;

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}




int main() {

	int N, M;
	cin >> N >> M;

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

	vector<int> connected(N, 0);
	for (int i = 0; i < M; i++) {
		int from, to;
		cin >> from >> to;
		connected[from - 1] = max(connected[from - 1], peaks[to - 1]);
		connected[to - 1] = max(connected[to - 1], peaks[from - 1]);
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (peaks[i] > connected[i]) ans++;
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	long long n,a[200005],all=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		all=all^a[i];
	}
	for(int i=0;i<n;i++){
		long long ans=all^a[i];
		cout<<ans<<endl;
	}
    return(0);
}

Measured memory_bytes: 5204
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int c[][] = new int[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                c[i][j] = sc.nextInt();
            }
        }
        int a = c[1][0] - c[0][0];
        int b = c[2][0] - c[1][0];
        int x = c[0][1] - c[0][0];
        int y = c[0][2] - c[0][1];
        boolean correct = true;
        if (c[1][1] != c[0][0] + x + a) correct = false;
        if (c[1][2] != c[0][0] + x + y + a) correct = false;
        if (c[2][1] != c[0][0] + x + a + b) correct = false;
        if (c[2][2] != c[0][0] + x + y + a + b) correct = false;
        if (correct) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

using namespace std;

long long bin (long long a, long long r, long long m){
    long long ans = 1;
    long long q = a;
    while (r){
        if (r%2){
            ans = (ans*q)%m;
        }
        q = (q*q)%m;
        r = r/2;
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long n, a, b, k;
    cin >> n >> a >> b >> k;
    long long mod = 998244353;
    long long ans = 0;
    vector <long long> fac (n+1,1);
    for (int i=1; i<=n; i++){
        fac[i] = (fac[i-1]*i)%mod;
    }
    vector <long long> c(n+1,1);

    long long t1,t2,t3, t4,t5, j;
    for (int i=1; i<n; i++){
        t3 = bin(fac[i],mod-2,mod);
        t4 = bin(fac[n-i],mod-2,mod);
        t5 = (t3*t4)%mod;
        c[i] = (t5*fac[n])%mod;
    }
    for (int i=0; i<=n; i++){
        t1 = a*i;
        t2 = k - a*i;
        if (t2 % b == 0 and t2>=0){
            j = t2 / b;
            if (j <= n){
                ans = (ans + c[i] * c[j])%mod;
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) int __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)

struct UnionFind{
    int n;
    vi p,r;
    UnionFind(int N):n(N){
        p.resize(n);
    	iota(all(p),0);
        r.resize(n);
        fill(all(r),0);
    }
    void unite(int a, int b){
        int c=root(a),d=root(b); 
        if(c!=d) {
            if(r[c]<r[d]){
                p[c]=d;
            }else{
                p[d]=c;
                if(r[c]==r[d])r[c]++;
            }
        }
    }
    int root(int a){return p[a]=(p[a]==a?a:root(p[a]));}
    bool same(int a, int b){return root(a)==root(b);}
};

struct Kruskal{
    using Edge=pair<int,pair<int,int>>;
    vector<Edge> edge;
	int n;
	Kruskal(){}
	Kruskal(int N):n(N){ }
    void add(int C,int S,int T){
		edge.eb(C,mp(S,T));
	}
    void remove(int C,int S,int T){
		edge.erase(find(all(edge),mp(C,mp(S,T))));
	}
	pair<int,vector<Edge>> calcMST(){
		int ans=0;
		vector<Edge> ret;
		sort(all(edge),[](Edge a,Edge b){return a.fs<b.fs;});

		UnionFind uf(n);		
		for(auto e:edge){
			if(!uf.same(e.sc.fs, e.sc.sc)){
				ret.pb(e);
				ans+=e.fs;
				uf.unite(e.sc.fs, e.sc.sc);
				if(ret.size()==n-1){
					break;
				}
			}
		}
		return mp(ans,ret);
	}

};

int main(){
	int n,m;
	while(cin>>n>>m){
		Kruskal kr(n);
		rep(i,m){
			dcl(s,d,c);
			kr.add(c,s-1,d-1);
		}
		auto mst=kr.calcMST();
		int cost=mst.fs;
		int ans=0,anscost=0;

		for(auto e:mst.sc){
			kr.remove(e.fs, e.sc.fs, e.sc.sc);
			int cur=kr.calcMST().fs;
			if(cur != cost || cur==-1){
				ans++;
				anscost+=e.fs;
			}
			kr.add(e.fs, e.sc.fs, e.sc.sc);
		}
		cout<<ans<<" "<<anscost<<endl;
	}
	return 0;
}



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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> data(m);
    for (int i = 0; i < m; i++){
        cin >> data.at(i);
    }

    sort(data.begin(), data.end());
    vector<int> dist(m - 1);
    for (int i = 0; i < m - 1; i++){
        dist.at(i) = data.at(i + 1) - data.at(i);
    }
    sort(dist.begin(), dist.end());

    int64_t count = 0;
    for (int i = 0; i < m - n; i++){
        count += dist.at(i);
    }

    cout << count << endl;
}

Measured memory_bytes: 1024
def solve():
    N,K = [int(i) for i in input().split()]
    ans = set([i for i in range(1, N+1)])
    for i in range(K):
        d = int(input())
        target = set([int(j) for j in input().split()])
        ans -= target
    print(len(ans))

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9104
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); ++i)

int main()
{
	int n; cin >> n;
	int a = n % 1000;
	if (!a) cout << 0 << endl;
	else cout << 1000 - a << endl;
	return 0;
}


Measured memory_bytes: 3192
#include <iostream>



using namespace std;


int main() {
int a,b,c,d;

cin >> a >> b >> c >> d;

while(true) {
    c -= b;
  if  (c  <= 0) {
    cout << "Yes" << endl;
    return 0;
  } 
a -=  d;
if(a <= 0) {
  cout << "No" << endl;
  return 0;
}
}

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    int n, i;
    cin >> n >> i;

    Cout(n - i + 1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define arrlen(arr) (sizeof(arr)/sizeof(arr[0]))
#define Sort(arr) sort(arr, arr+arrlen(arr))
#define For(i,s,n) for(int i=s;i<n;i++)
	
int main(){
	int N;
	cin >> N;
	string S[N],copy[N];
	int P[N],number[N];
	For(i,0,N){
		cin >> S[i] >> P[i];
		copy[i]=S[i];
		number[i]=-1;
	}
	
	Sort(copy);
	//For(i,0,N) cout << copy[i] << endl;
	For(i,0,N){
		For(j,0,N){
			if(copy[i]==S[j]&&number[i]==-1&&(i==0||S[number[i-1]]!=S[j]||j>number[i-1])){
				number[i]=j;
				break;
			}
		}
	}
	//For(i,0,N) cout << number[i] << endl;
	while(true){
		bool flag=true;
		For(i,0,N-1){
			if(P[number[i]]<P[number[i+1]]&&copy[i]==copy[i+1]){
				swap(number[i],number[i+1]);
				flag=false;
			}
		}
		if(flag) break;
	}
	
	For(i,0,N) cout << number[i]+1 << endl;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n;
  int a[100];
  int ans=BIG;
  cin>>n;
  rep(i,n){
    cin>>a[i];
  }
  repi(i,-100,101){
    int sum=0;
    rep(j,n){
      sum+=abs(a[j]-i)*abs(a[j]-i);
    }
    ans=min(ans,sum);
  }
  cout<<ans<<endl;
  return 0;
}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
    static void Main(){
        
        string[] input = Console.ReadLine().Split(' ');
        
        int n = int.Parse(input[0].ToString());
        int a = int.Parse(input[1].ToString());
        int b = int.Parse(input[2].ToString());
        
        if(n*a <= b) Console.WriteLine(n*a);
        else Console.WriteLine(b);
    }
}

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

class Program
{
    static string InputPattern = "Input2";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("10");
            WillReturn.Add("3");
            WillReturn.Add("11");
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    const int Jyougen = 999999;
    static int[] SosuuArr = new int[Jyougen + 1];

    //エラトステネスの篩
    static void Eratosthenes()
    {
        for (int I = 2; I <= SosuuArr.GetUpperBound(0); I++) {
            SosuuArr[I] = I;
        }
        for (int I = 2; I <= SosuuArr.GetUpperBound(0); I++) {
            if (I != 2 && I % 2 == 0) continue;

            if (SosuuArr[I] != 0) {
                for (int J = I * 2; J <= SosuuArr.GetUpperBound(0); J += I) {
                    SosuuArr[J] = 0;
                }
            }
        }

        SosuuArr = SosuuArr.Where(X => X != 0).ToArray();
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        Eratosthenes();

        foreach (string EachInput in InputList) {
            Console.WriteLine(SosuuArr.Count(X => X <= int.Parse(EachInput)));
        }
    }
}

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

int main(){
	int n,a,c=0,T,H;
	bool t[200+2],h[200+2];
while(1){
c=0;
	fill(t,t+202,false);
	fill(h,h+202,false);
	scanf("%d",&n);
if(n==0)break;
	for(int i=0;i<n;i++){
		scanf("%d",&a);
		t[a]=true;
	}
	for(int i=1;i<2*n+1;i++){
		if(!t[i])h[i]=true;
	}
	T=n;
	H=n;
	while(1){
		for(int i=c+1;;i++){
			if(t[i]){
				t[i]=false;
				T--;
				c=i;
				break;
			}
			if(i>=2*n){
				c=0;
				break;
			}
		}
		if(T==0)break;
		for(int i=c+1;;i++){
			if(h[i]){
				h[i]=false;
				H--;
				c=i;
				break;
			}
			if(i>=2*n){
				c=0;
				break;
			}
		}
		if(H==0)break;
	}
	printf("%d\n%d\n",H,T);
}
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e5+6;
const int mod = 1e9+7;
const int inf = 1e8;
char g[55][55];
char p[55][55];
void solve(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>g[i][j];
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            cin>>p[i][j];
        }
    }
    bool yes = false;
    for(int i=0;i<=n-m;i++){
        for(int j=0;j<=n-m;j++){
            bool can = true;
            for(int ii=0;ii<m;ii++){
                for(int jj=0;jj<m;jj++){
                    if(g[i+ii][j+jj]!=p[ii][jj])can = false;
                }
            }
            if(can)yes = true;
        }
    }
    if(yes)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char s1[100005];
int main()
{
	scanf("%s",s1);
	int len=strlen(s1);
	if(s1[len-1]=='s')
	{
		s1[len]='e';
		s1[len+1]='s';
		s1[len+2]='\0';
	}
	else
	{
		s1[len]='s';
		s1[len+1]='\0';
	}
	printf("%s",s1);
	return 0;
}

Measured memory_bytes: 3756