akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	static long solve(int n, int[] a) {
		long sum = 0;
		long ans = 0;
		long mod = (long) Math.pow(10, 9) + 7;

		for (int i = 0; i < n; i++) {
			sum += a[i];
			sum %= mod;
		}

		for (int i = 0; i < n; i++) {
			sum -= a[i];
			if (sum < 0)
				sum += mod;
			ans += a[i] * sum;
			ans %= mod;
		}

		return ans;
	}

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

		int n = stdIn.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
		}
		long result = solve(n, a);
		System.out.println(result);

		stdIn.close();
	}
}


Measured memory_bytes: 49776
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
int n;
vvi G;
vi deg(200010);
#define MOD 1000000007
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
vi merge(vi a,vi b){
	vi c(3);
	rep(i,3)rep(j,3)(c[i+j>=2?2:i+j]+=a[i]*b[j])%=MOD;
	return c;
}
deque<vi> f(int a,int pr,int d){
	deg[d]++;
	deque<vi>out;
	int ma=0;
	rep(i,G[a].size()){
		int to=G[a][i];
		if(to==pr)continue;
		deque<vi>t=f(to,a,d+1),tmp;
		ma=max(ma,(int)min(out.size(),t.size()));
		rep(j,min(out.size(),t.size()))
			out[j]=t[j]=merge(out[j],t[j]);
		if(out.size()<t.size())swap(out,t);
	}
	rep(i,ma)out[i][0]+=out[i][2],out[i][2]=0;
	out.push_front({1,1,0});
	return out;
}
signed main(){
	cin>>n;
	G=vvi(n+1);
	rep(i,n){
		int a;
		cin>>a;
		G[a].pb(i+1);
	}
	deque<vi>out=f(0,-1,0);
	int sum=0;
	rep(i,out.size())(sum+=out[i][1]*powmod(2,n+1-deg[i]))%=MOD;
	cout<<sum<<endl;
}







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

int main() {
  int N, K;
  int h;
  int cnt = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> h;
    if (h >= K)
      cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
// 解説見ました
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
	int H, W, N;
	scanf("%d %d %d", &H, &W, &N) + 1;
	int Sr, Sc;
	scanf("%d %d", &Sr, &Sc) + 1;
	char S[200001], T[200001];
	scanf("%s", S) + 1;
	scanf("%s", T) + 1;

	int Cu = Sr;
	int Cd = H - Sr + 1;
	int Cl = Sc;
	int Cr = W - Sc + 1;
	int i;
	for (i = 0; i < N; i++) {
		if (S[i] == 'U') {
			Cu--;
			if (Cu == 0) break;
		} 
		else if (S[i] == 'D') {
			Cd--;
			if (Cd == 0) break;
		} 
		else if (S[i] == 'L') {
			Cl--;
			if (Cl == 0) break;
		} 
		else if (S[i] == 'R') {
			Cr--;
			if (Cr == 0) break;
		}

		if (T[i] == 'D') {
			Cu++;
			if (Cu > H) Cu = H;
		}
		else if (T[i] == 'U') {
			Cd++;
			if (Cd > H) Cd = H;
		}
		else if (T[i] == 'R') {
			Cl++;
			if (Cl > W) Cl = W;
		}
		else if (T[i] == 'L') {
			Cr++;
			if (Cr > W) Cr = W;
		}
	}

	if (i == N) printf("YES");
	else printf("NO");

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

ll N;

int main() {
    cin >> N;
    N -= 1;
    ll a = 26;
    char ans[100];
    while (N - a >= 0) {
        N -= a;
        a *= 26;
    }
    int j = 0;
    while (a > 1) {
        a /= 26;
        char c = N / a + 'a';
        ans[j] = c;
        N %= a;
        j++;
    }
    ans[j] = '\0';
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

template<typename T>
vector<T> Divisors(T n) {
	vector<T> res;
	for(T i = 1; i * i <= n; ++i) {
		if( n % i == 0 ) {
			res.push_back(i);
			
			if( i < n / i ) res.push_back(n / i);
		}
	}
	
	sort(res.begin(), res.end());
	
	return res;
}

int digit(ll n) {
	int res = 0;
	while( n ) {
		n /= 10LL;
		res++;
	}
	
	return res;
}

int main(void) {
	ll n;
	cin >> n;
	
	vector<ll> div = Divisors(n);
	
	int ans = 11;
	for(auto& x : div) {
		int tmp = max(digit(x), digit(n / x));
		ans = min(ans, tmp);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3692
#[int(i) for i in input().split()]
import math
n = int(input())
genka_min = n * 100 / 108
genka_max = (n+1) * 100 / 108
ok = 0
ans = 0

for i in range(math.floor(genka_min),math.ceil(genka_max)+1):
    if  math.floor(i*1.08) == n:
        ok = 1
        ans = i
if ok:
    print(ans)
else:
    print(":(")


Measured memory_bytes: 38384
N = int(input())

t = 0
x = 0
y = 0
flag = True
for _ in range(N):
    tn, xn, yn = map(int, input().split())
    dt = tn - t
    l1 = abs(xn - x) + abs(yn - y)
    if (l1 <= dt) and (tn % 2 == (xn + yn) % 2):
        continue
    else:
        flag = False
        break

if flag:
    print('Yes')
else:
    print('No')


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

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

    int ans = INT_MAX;
    for(int i = 0; i <= s.size() - 3; i++){
        int x = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
        ans = min(ans, abs(753 - x));
    }
    cout << ans << '\n';
    return 0;
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

int main(){
    string S;
    cin>>S;
    if(S[0]!='A' || S[1]<'a' || S[S.size()-1]<'a'){
        cout<<"WA"<<endl;
        return 0;
    }

    string S2 = S.substr(2,S.size()-3);
    int cnt_c = 0;
    REP(i,S2.size()){
        if(S2[i] == 'C'){
            cnt_c++;
        }else{
            if(S2[i]<'a'){
                cout<<"WA"<<endl;
                return 0;
            }
        }
    }

    if(cnt_c != 1){
        cout<<"WA"<<endl;
        return 0;
    }

    cout<<"AC"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

void dfs(const vector< vector<int> > &g, vector<int> &dist, int v, int p=-1, int d=0) {
    dist[v] = d;
    for(auto u: g[v]) {
        if(u == p) continue;
        dist[u] = dist[v] + 1;
        dfs(g, dist, u, v, d+1);
    }
    return;
}

int main(void) {
    int N;
    cin >> N;
    vector< vector<int> > g(N);
    for(int i=0; i<N-1; i++) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }

    vector<int> distF(N), distS(N);
    dfs(g, distF, 0);
    dfs(g, distS, N-1);

    int F = 0, S = 0;
    for(int i=0; i<N; i++) {
        if(distF[i] <= distS[i]) {
            ++F;
        } else {
            ++S;
        }
    }

    if(F > S) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }
    return 0;
}


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

namespace abc164
{
	class Program
	{
		static void Main(string[] args)
		{
			long n;
			string str;
			var hash = new HashSet<string> ();
			n = int.Parse(Console.ReadLine());
			for (long i = 0; i < n; i++)
			{
				str = Console.ReadLine();
				//Console.WriteLine(str);
				hash.Add(str);
			}
			Console.WriteLine(hash.Count);
		}
	}
}



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

int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        int sum=(n-m)*100+m*1900;
        for(int i=0;i<m;i++)
            sum*=2;
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
from itertools import combinations, product
N,A,B,C=map(int, input().split())
l=[int(input()) for _ in range(N)]
ans = float("inf")
for tmp in product(range(4), repeat=N):
    cost = 0
    forA = []
    forB = []
    forC = []
    for i in range(N):
        if tmp[i] == 0:
            forA.append(l[i])
            cost += 10
        elif tmp[i] == 1:
            forB.append(l[i])
            cost += 10
        elif tmp[i] == 2:
            forC.append(l[i])
            cost += 10
    if not (forA and forB and forC):
        continue
    cost -= 30
    toA = sum(forA)
    toB = sum(forB)
    toC = sum(forC)
    cost += abs(toA - A) + abs(toB - B) + abs(toC - C)
    ans = min(ans, cost)

print(ans)

Measured memory_bytes: 74420
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <unordered_map>

using namespace std;

#define int long long
#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 range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=r-1;i>=(int)(l);--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;
using ll=long long;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
//int read(){int a;scanf("%lld",&a);return a;}

constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}

const int inf = TEN(18)*3 + 10;
const int mod = TEN(9) + 7;

int N, K;
int rui[100010], rui_b[100010];

signed main()
{
	cin >> N >> K;
	vi a(N + 1);
	rep1(i, N) cin >> a[i];

	rep1(i, N) {
		rui[i] += rui[i - 1] + a[i];
		rui_b[i] += rui_b[i - 1] + (a[i] > 0 ? a[i] : 0);
	}

	int ans = -inf;

	range(i, 1, N + 1) {
		if (i + K - 1 > N) break;
		//printf("i = %lld, a[%lld] = %lld\n", i, i, a[i]);
		int s = 0;
		s = max(rui[i + K - 1] - rui[i - 1], 0ll);
		s += rui_b[i - 1];
		s += rui_b[N] - rui_b[i + K - 1];

		chmax(ans, s);
	}

	cout << ans << endl;
}



Measured memory_bytes: 2560
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    int N,M;
    List<int>[] L;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        UnionFind U = new UnionFind(N);
        for(int i=0;i<M;i++){
            for(int j=0;j<L[i].Count-1;j++){
                U.Union(L[i][j],L[i][j+1]);
            }
        }
        if(U.Num(0) == N){
            sb.Append("YES\n");
        }
        else{
            sb.Append("NO\n");
        }
    }
    void Read(){
        string[] str = Console.ReadLine().Split(' ');
        N = int.Parse(str[0]);
        M = int.Parse(str[1]);
        L = new List<int>[M];
        for(int i=0;i<M;i++){
            L[i] = new List<int>();
        }
        for(int i=0;i<N;i++){
            str = Console.ReadLine().Split(' ');
            int k = int.Parse(str[0]);
            for(int j=1;j<=k;j++){
                L[int.Parse(str[j])-1].Add(i);
            }
        }
    }    
}
class UnionFind{
    int[] par;
    int[] num;
    public UnionFind(int n){
        par = new int[n];
        num = new int[n];
        for(int i=0;i<n;i++){
            par[i] = i;
            num[i] = 1;
        }
    }
    public int Num(int x){
        return num[Get(x)];
    }
    public void Union(int x,int y){
        int i = Get(x);
        int j = Get(y);
        if(i != j){
            num[i] += num[j];
            par[j] = i;  
        } 
    }
    public bool Same(int x,int y){
        return Get(x) == Get(y);
    }
    int Get(int x){
        if(x != par[x]){
            par[x] = Get(par[x]);
        }
        return par[x];
    }
}

Measured memory_bytes: 16420
K=int(input())
if K%5==0 or K%2==0:
    print(-1)
if K%7==0:
    L=9*K//7
else:
    L=9*K
R=1
for i in range(L):
    R=R*10
    R=R%L
    if R==1:
        print(i+1)
        exit()

Measured memory_bytes: 63068
import bisect

def main():
  N=int(input())
  A=sorted(list(map(int,input().split())))
  B=sorted(list(map(int,input().split())))
  C=sorted(list(map(int,input().split())))
  ans=0
  for b in B:
    a=bisect.bisect_left(A,b)
    c=N-bisect.bisect_right(C,b)
    ans+=a*c
  print(ans)
  
if __name__=="__main__":
  main()

Measured memory_bytes: 29296
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=998244353;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
ll mod_pow(ll x,ll n,ll mod){ll res=1;while(n>0){if(n&1) res=res*x%mod;x=x*x%mod;n>>=1;}return res;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);
//2の進数表示の最高位
//例: 7->2 8->3
ll high_order_bit(ll n){ll tmp=1,i=-1;while(tmp<=n){tmp*=2;i++;}if(n==0) return 0;else return i;}
// 6 -> vec[0] [1] [2]
//          0   1   1
//vec[i]:2^iの位
vector<ll> binary_expansion(ll n){vector<ll> B(high_order_bit(n)+1);ll tmp=n;for(ll i=high_order_bit(n);i>=0;i--){B[i]=tmp/pw2[i];tmp%=pw2[i];}return B;}
vector<ll> divisor(ll x){vector<ll> div;for(ll i=1;i*i<=x;i++){if(i*i!=x && x%i==0){div.pb(i);div.pb(x/i);}else if(x%i==0) div.pb(i);}sort(all(div));return div;}
vector<ll> vectorprime(ll x){vector<bool> is_prime(x+1);vector<ll> prime;rep(i,x+1) is_prime[i]=true;is_prime[0]=is_prime[1]=false;for(ll i=2;i<=x;i++){if(is_prime[i]){prime.pb(i);}for(int j=i*2;j<=x;j+=i) is_prime[j]=false;}return prime;}
map<ll,ll> prime_factor(ll x){map<ll,ll> m;ll sq=(ll)sqrt(x) + 1;vector<ll> v_prime=vectorprime(sq);ll tmp=x;rep(i,sz(v_prime)){ll count=0;while(tmp % v_prime[i] == 0){tmp /= v_prime[i];count++;}if(count != 0) m[v_prime[i]]=count;if(tmp==1) break;}if(tmp != 1) m[tmp]=1;return m;}
ll fac[500001],finv[500001],inv[500001],dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
void table(){fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;for(ll i=2;i<500001;i++){fac[i]= fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
ll dev(long long a,long long b){return (a*inv[b])%MOD;}
ll comb(ll n, ll k){if(n<k) return 0;if(n<0 || k<0) return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
ll perm(ll n,ll k){if(n<k) return 0;if(n<0 || k<0) return 0;return (fac[k]*comb(n,k))%MOD;}

int main(){
    {table();}
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll X; cin>>X;
    cout<<lcm(360,X)/X<<endl;
}



Measured memory_bytes: 15432
#include<iostream>
//#include<algorithm>
//#include<cmath>
//#include<string>
//#include<cctype>
//#include <vector>
using namespace std;
int main() {
	unsigned long long n;
	cin >> n;
	int a = -1;
	while (n >>= 1 && a++);
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 3032
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt(); //マスの数
		int m = stdIn.nextInt(); //料金所の数
		int x = stdIn.nextInt(); //今いる場所
		int[] a = new int[m];
		
		for(int i = 0; i < m; i++) {
			a[i] = stdIn.nextInt();
		}
		
		int cntleft = 0;
		int cntright = 0;
		
		for(int i = 0; i < m; i++) {
			if(a[i] < x) {
				cntleft++;
			}else {
				cntright++;
			}
		}
			
		int min = Math.min(cntleft, cntright);
		System.out.println(min);
	}	

}


Measured memory_bytes: 23892
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int n,m;
	cin >> n >> m;
	
	priority_queue<pair<int,int>> v;
	rep(i,0,m){
		int a,b;
		cin >> a >> b;
		v.push(pair<int,int> (a,b));
	}

	int ans = 0;
	rep(i,0,m-1){
		pair<int,int> p = v.top();
		v.pop();
		int a=p.first;
		int b=p.second;
		
		if( a < n ){
			ans += n-a;	
		}
		
	}
	
	cout << ans << endl;
	ret 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void solve()
{
    ll n;
    cin>>n;
    vector<char>v;
    while(n>0)
    {
        n--;
        ll rem=n%26;
        v.push_back((char)'a'+rem);
        n/=26;
    }
    reverse(v.begin(),v.end());
    for(auto c:v){
        cout<<c;
    }

}

int main()
{
    int x,t;  solve();

}





Measured memory_bytes: 3652
N = int(input())

As = [int(input()) for _ in range(N)]
As.sort()

rlt = 0

if len(As) % 2 == 1:
  tmp1 = 0
  tmp2 = 0
  b = len(As)//2
  for i in As[:b]:
    tmp1 -= 2*i
  for i in As[b:]:
    tmp1 += 2*i
  tmp1 -= As[b]
  tmp1 -= As[b+1]
  
  for i in As[:b+1]:
    tmp2 -= 2*i
  for i in As[b+1:]:
    tmp2 += 2*i
  tmp2 += As[b]
  tmp2 += As[b-1]
  if tmp1 > tmp2:
    rlt = tmp1
  else:
    rlt = tmp2

else:
  b = len(As)//2
  for i in As[:b]:
    rlt -= 2*i
  for i in As[b:]:
    rlt += 2*i
  rlt += As[b-1]
  rlt -= As[b]
  
print(rlt)

Measured memory_bytes: 51544
s = input()
t = input()
ans = ''

# for i in range(len(s)-len(t)+1):
for i in range(len(s)-len(t), -1, -1):
    st = s[i:i+len(t)]
    cnt = 0
    for si, ti in zip(st, t):
        if si == '?' or si == ti:
            cnt += 1
        # print(si, ti, cnt)
    if cnt == len(t):
        ans = s[:i] + t + s[i+len(t):]
        ans = ans.replace('?', 'a')
        print(ans)
        exit()
else:
    print('UNRESTORABLE')




Measured memory_bytes: 9128
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = float('inf')

N = int(input())    # 数字
A = list(map(int, input().split()))     # スペース区切り連続数字

m = max(A)
num = [0] * (m + 1)
for a in A:
    num[a] += 1

for a in A:
    if num[a] > 1:
        num[a] = 0
    i = 2
    while a * i <= m:
        num[a * i] = 0
        i += 1

res = 0
for n in num:
    if n != 0:
        res += 1

print("{}".format(res))


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

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }
  vector<int> p(n, -1);  //どこに向かうか
  vector<int> r;         //辿った道を記録
  int next = 0;
  while (p[next] == -1) {
    r.push_back(next);
    p[next] = r.size();
    next = a[next];
  }
  int pre = p[next] - 1;
  if (k <= pre) {
    cout << r[k] + 1 << endl;
  } else {
    k -= pre;
    k %= (r.size() - pre);
    cout << r[pre + k] + 1 << endl;
  }
}

Measured memory_bytes: 5892
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val p = Array(N) {
        val (a, b) = readLine()!!.split(" ").map {it.toLong()}
        Pair(a, b)
    }
    p.sortBy { it.second }

    var e = 0L

    for (i in p) {
        e += i.first
        if (e > i.second) {
            println("No")
            return
        }
    }

    println("Yes")
}


Measured memory_bytes: 134748
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> L(M), R(M);
	for (int i = 0; i < M; i++) {
		cin >> L[i] >> R[i];
	}

	int lmax = *max_element(L.begin(), L.end());
	int rmin = *min_element(R.begin(), R.end());
	int d = rmin - lmax + 1;
	if (d < 0)
		d = 0;
	cout << d << endl;

	return 0;
}

Measured memory_bytes: 4004
#include <iostream>

int main(int argc, const char * argv[]) {
    std::string line;
    while(getline(std::cin,line)){
        for(int i = 0;i<line.length();i++){
            if ( line[i]>='a' && line[i]<='z'){
                line[i] = line[i] + ('A' - 'a');
            }
        }
        std::cout << line << std::endl;
        
    }
        }

Measured memory_bytes: 1172
/**
*    author:  Dooloper
*    created: 26.07.2020 03:32:36
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
    int A, B, C, K;
    cin >> A >> B >> C;
    cin >> K;
    string check = "No";
    vector<int> vec(3); // [A,B,C] 作成
    vec.at(0) = A;
    vec.at(1) = B;
    vec.at(2) = C;

    for (int i = 0;i < K;i++)
    {
        if((vec.at(0)>vec.at(1) && vec.at(1)<vec.at(2) && vec.at(0)<vec.at(2)) ||(vec.at(0)>vec.at(1) && vec.at(1)<vec.at(2) && vec.at(0)>vec.at(2)))
        {
            vec.at(1) = vec.at(1)*2;
        }
        else if (vec.at(0)==vec.at(1)) //A==B
        {
            if (vec.at(0)<vec.at(2))
            {
                vec.at(1) = vec.at(1)*2;
            }
            else
            {
                vec.at(2) = vec.at(2)*2;
            }
        }
        else if (vec.at(1)==vec.at(2)) //B==C
        {
            if (vec.at(0)>vec.at(1))
            {
                vec.at(2) = vec.at(2)*2;
            }
            else
            {
                vec.at(2) = vec.at(2)*2;
            }
        }
        else if (vec.at(0)==vec.at(2)) //A==C
        {
            if (vec.at(0)>vec.at(1))
            {
                vec.at(1) = vec.at(1)*2;
            }
            else
            {
                vec.at(2) = vec.at(2)*2;
            }
            
            
        }
        else
        {
            vec.at(2) = vec.at(2)*2;
        }
        
        
    
        if (vec.at(0)<vec.at(1) && vec.at(1)<vec.at(2) && vec.at(0)<vec.at(2))
        {
            check = "Yes";
        }
    }
    
    cout << check << endl ;
}

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

ll fight(ll x){
    if(x==1){
        return 1;
    }
    else{
        return fight(x/2)*2 + 1;
    }
}

int main(){
    ll h;
    cin >> h;
    cout << fight(h) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>//coded by Nurstan ^_^

#define ll long long
#define pb push_back

#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define all(x) x.begin(), x.end()
#define F first
#define S second

// fixed << setprecision
// next_permutation(a, a + n)
// set <int> :: iterator it = x.begin(); it != x.end(); it ++

using namespace std;

inline void boost(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

int main(){
	boost();
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ll a, b;
	cin >> a >> b;
	if(a < 0 && b == 0) {
		cout << abs(a);
		return 0;
	}
	if(a > 0 && b == 0) {
		cout << a + 1;
		return 0;
	}
	if(a == b) {
		cout << 0;
		return 0;
	}
	if(abs(a) == abs(b)) {
		cout << 1;
		return 0;
	}
	int absa = abs(a), absb = abs(b );
	if(a < b) {
		//
		if(a < 0 && b >= 0) {
			cout << abs(absb - absa) + 1;
			return 0;		
		}
		if(a >= 0 && b >= 0) {
			cout << b - a;
			return 0;
		}
		if(a < 0 && b < 0) {
			cout << b - a;
			return 0;
		}
		//
	}
	else {
		//
		if(a >= 0 && b < 0) {
			cout << 1 + abs(absa - absb);
			return 0;
		}
		if(a >= 0 && b >= 0) {
			cout << 2 + abs(absa - absb);
			return 0;
		}
		if(a < 0 && b < 0) {
			cout << 2 + abs(absa - absb);
			return 0;
		}
		//
	}
	exit(0);
}



Measured memory_bytes: 256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll R;

int main() {
	scanf("%lld", &R);
	if(R < 1200) {
		printf("ABC\n");
	}
	else if(R < 2800) {
		printf("ARC\n");
	}
	else {
		printf("AGC\n");
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    int n;
    cin >> n;
    vector<string> s;
    for(int i = 0; i < n; i++){
        vector<int> nums(3);
        cin >> nums[0] >> nums[1] >> nums[2];
        sort(nums.begin(), nums.end());
        if(nums[0] * nums[0] + nums[1] * nums[1] == nums[2] * nums[2]) s.push_back("YES");
        else s.push_back("NO");
    }
    for(int i = 0; i < n; i++) cout << s[i] << "\n";
}


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

int n;
double dp[3000][3000] ;

double a[3000] = {0.0};
double f(int h, int t, int i) {
	if (dp[h][i] > -0.9)
		return dp[h][i];//if (dp[h][i] != 0) return dp[h][i];
	if (h <= 0 && t <= 0) return 1;
	//if (i > n) return 0;
	double ans = 0;
	if (h)
		ans += a[i] * f(h - 1, t, i + 1);
	if (t)
		ans += (1 - a[i]) * f(h, t - 1, i + 1);
	return dp[h][i] = ans;
}

int main()
{	//c_p_c();
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	memset(dp, -1, sizeof dp);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int k = ( n + 1) / 2 ;
	double ans = 0;
	for (int i = k; i <= n; i++) {
		ans += f(i, n - i, 1);
	}
	//cout << ans;
	cout << fixed << setprecision(10) << ans;
	return 0;
}

Measured memory_bytes: 74396
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <string>
#include <set>

using namespace std;
typedef long long ll;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vector<int> arr(n);
    for(int i = 0; i < n; ++i) cin >> arr[i];
    sort(arr.begin(), arr.begin()+n);
    ll ans = 0;
    for(int a = 0; a < n-2; ++a){
        for(int b = a+1; b < n-1; ++b){
            int sum = arr[a]+arr[b];
            //cout << a << " " << b << " " << sum << "\n";
            auto it = lower_bound(arr.begin()+b+1,arr.begin()+n,sum);
            //cout << it - arr.begin() << endl;
            if(it != arr.end()){
                --it;
                int final_pos = it - arr.begin();
                //cout << final_pos << endl;
                ans += (final_pos-b);
            }
            else{
                ans += (n-1-b);
            }
            
        }
    }
    cout << ans << "\n";
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    string s;
    cin >> s;
    int c = 0;
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] == '0') ++c;

    }
    cout << min(c, int(s.size()) - c) * 2 << endl;
    return 0;
}



Measured memory_bytes: 512
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma") 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define ll long long
#define MP make_pair
// #define int long long
// #define MAX LONG_LONG_MAX
// #define MIN LONG_LONG_MIN
#ifdef LOCAL // setting up print debugging (yes lol)
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.x<<','<<p.y<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
#endif
using namespace std;

const size_t MAXN = 1e5 +7;


void check(){
	ll mx ,a ,b ,c ,d;
	cin >>  a >> b >> c >> d;
	mx = max({a*c ,a*d ,b*c ,b*d});
	cout  << mx;
}

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); 
	cin.exceptions(cin.failbit);
	int t = 1;	
	// cin >> t;
	for(int i = 1 ; i <= t ;i++){
		// cout << "Case "<< i << ":\n";
		check();
	}
	return 0;
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;

int main() {
  int n,m;cin >> n>>m;
  int out;
  int sqrt_m = (int)sqrt(m);
  vector<int> vd;
  for(int i=sqrt_m;i>=1;--i){
    if(m%i!=0) continue;
    int tmp = m/i;
    //cout << tmp << endl;
    if(i<=m/n) vd.push_back(i);
    if(tmp<=m/n) vd.push_back(tmp);
  }
  sort(all(vd), greater<int>());
  cout << vd[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
int H,W,tate,yoko;
while(1){
cin>>H>>W;
if(H==0 && W==0)break;
for(tate=0; tate<H; tate++){
for(yoko=0; yoko<W; yoko++){
if(0<tate && tate<H-1 && 0<yoko && yoko<W-1){
cout<<".";
}else{
cout<<"#";
}
}
cout <<endl;
}
cout<<endl;
}
return 0;
}



Measured memory_bytes: 3112
#https://atcoder.jp/contests/abc150/tasks/abc150_c
import itertools
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))

l=list(itertools.permutations(range(1,n+1)))
print(abs(l.index(p)-l.index(q)))



Measured memory_bytes: 70040
#include<stdio.h>
int main(){
int a[9],i,j,b,e=1,f,k;
int c=0,d=0;
char x;
scanf("%d\n",&f);
for(k=0;k<f;k++){
for(i=0;i<8;i++){
scanf("%c",&x);
a[i]=x-'0';
}
scanf("\n");
for(i=0;i<8;i++){
for(j=7;j>i;j--){
if(a[j-1]>a[j]){
b=a[j-1];
a[j-1]=a[j];
a[j]=b;
}
}
}
for(i=0;i<8;i++){
c=c+a[i]*e;
e=e*10;
}
e=e/10;
for(i=0;i<8;i++){
d=d+a[i]*e;
e=e/10;
}
printf("%d\n",c-d);
c=0,d=0,e=1;
}
return 0;
}


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

namespace AGC008B {
    class Program {
        static void Main(string[] args) {
            int[] NKinput = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int N = NKinput[0];
            int K = NKinput[1];
            int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            long sum = 0;
            int[] minus = new int[N];
            int[] plus = new int[N];
            for (int i = 0; i < N; i++) {
                if (input[i] < 0) {
                    minus[i] = input[i];
                } else {
                    sum += input[i];
                    plus[i] = input[i];
                }
            }
            long msum = 0;
            long psum = 0;
            for (int i = 0; i < K; i++) {
                psum += plus[i];
                msum += minus[i];
            }
            long min = Math.Min(psum, msum * (-1));
            for (int i = 0; i < N - K; i++) {
                psum += plus[K + i] - plus[i];
                if (psum < min) {
                    min = psum;
                }
                msum += minus[K + i] - minus[i];
                if (msum * (-1) < min) {
                    min = msum * (-1);
                }
            }
            Console.WriteLine(sum - min);
        }
    }
}


Measured memory_bytes: 30812
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int gx = sc.nextInt();
		int gy = sc.nextInt();
		int dx = Math.abs(sx - gx);
		int dy = Math.abs(sy - gy);
		for(int i = 0 ; i < dx ; i++) {
			System.out.print("R");
		}
		for(int i = 0 ; i < dy ; i++) {
			System.out.print("U");
		}
		for(int i = 0 ; i < dx ; i++) {
			System.out.print("L");
		}
		for(int i = 0 ; i < dy ; i++) {
			System.out.print("D");
		}
		System.out.print("D");
		for(int i = 0 ; i < dx + 1 ; i++) {
			System.out.print("R");
		}
		for(int i = 0 ; i < dy + 1 ; i++) {
			System.out.print("U");
		}
		System.out.print("LU");
		for(int i = 0 ; i < dx + 1 ; i++) {
			System.out.print("L");
		}
		for(int i = 0 ; i < dy + 1 ; i++) {
			System.out.print("D");
		}
		System.out.println("R");
	}
}


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

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];
    bool z=true;
    rep(i,n){
        if(a[i]%2==0){
            if(a[i]%3==0 || a[i]%5==0) continue;
            else z=false;
        }
    }

    if(!z) printf("DENIED\n");
    else printf("APPROVED\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

int main() {
  std::priority_queue<int, std::vector<int>, std::greater<>> min_heap;
  
  int N, temp;
  std::cin >> N;
  
  int result = 0;
  while (std::cin >> temp) {
    min_heap.emplace(temp);
    if (min_heap.top() == temp) ++result;
  }
  
  std::cout << result << "\n";
}

Measured memory_bytes: 1528
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
using namespace std;
int main() {
	int a,b,c;
    cin >> a >> b >> c;
    if(a == b){
        a = c;
    }
    else{
        a = (a+b)-c;
    }
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())

messages = [[] for i in range(n)]

for i in range(n):
    num = int(input())

    for j in range(num):
        person, truth = map(int, input().split())
        messages[i].append([person-1, truth])

ans = 0
for i in range(2**n):
    check = i
    count = sum([(check >> t) & 1 for t in range(n)])
    if count <= ans:
        continue
    possible = True
    for k in range(n):
        if (check >> k) & 1:  # k is truth
            message = messages[k]

            for person, truth in message:
                if (check>>person)&1 == truth:
                    continue
                else:
                    possible = False
                    break
        else:  # k is not truth
            continue

        if not possible:
            break

    if possible:
        ans = max(ans, count)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) lps(i,0,n)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define FDST int hogehogehoge;cin>>hogehogehoge
#define   int long long

int x[110000],y[110000];
int change[50000];

signed  main(){
  int n,w,h;
  cin>>n>>w>>h;
  int c=0,ans=0;
  int stat=0;
  int am=1;
  lp(i,n){
    int xx,yy;
    cin>>xx>>yy;
    while(change[x[xx]]!=0) x[xx]=change[x[xx]];
    while(change[y[yy]]!=0) y[yy]=change[y[yy]];
    if(xx==1||yy==1||xx==w||yy==h) stat=1;
    if(x[xx]==0&&y[yy]==0){
      c++;
      x[xx]=am;
      y[yy]=am;
      am++;
    }
    else{
      ans++;
      if(x[xx]==0&&y[yy]!=0) x[xx]=y[yy];
      else if(y[yy]==0&&x[xx]!=0) y[yy]=x[xx];
      else if(x[xx]==y[yy]) continue;
      else{
	int a=x[xx],b=y[yy];
	if(a>b) swap(a,b);
	if(change[a]==b)1;
	else{
	  c--;
	  change[a]=b;
	  ans++;
	}
      }
    }/*
    cout<<" ";
    lp(i,5){
      cout<<x[i+1];
    }
    cout<<endl;
    lp(j,5){
      cout<<y[j+1]<<endl;
      }*/
    // cout<<c<<" "<<ans<<" "<<stat<<endl;
  }
  /*cout<<" ";
  lp(i,5){
    cout<<x[i+1];
  }
  cout<<endl;
  lp(j,5){
    cout<<y[j+1]<<endl;
    }*/
  if(c==1) 1;
  else{
    ans+=c*2-1-stat;
  }
  cout<<ans<<endl;
  return 0;
}



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

using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.first <<","<<P.second <<")";
}

#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int N = 100005;

int k, dp[N][15];
int tot[N];

int getDP(int i, int d) {
    if (d < 0 || d > 9) {
        return 0;
    }
    return dp[i][d];
}

int main() {
    
    scanf("%d", &k);
    
    for (int i = 1; i <= k; i++) {
        for (int d = 0; d < 10; d++) {
            dp[i][d] = min(2 * k, i == 1 ? 1 : getDP(i - 1, d - 1) + getDP(i - 1, d) + getDP(i - 1, d + 1));
            debug(i, d, dp[i][d]);
            tot[i] += dp[i][d];
        }
        tot[i] += tot[i - 1] - dp[i][0];
        tot[i] = min(tot[i], 2 * k);
        debug(i, tot[i]);
    }
    
    int start = 0;
    int sum = 0;
    for (int i = 1; i <= k; i++) {
        for (int d = 1; d < 10; d++) {
            sum += dp[i][d];
        }
        if (sum >= k) {
            start = i;
            break;
        }
    }
    debug(start);
    string number;
    int rem = k;
    dp[start][0] = tot[start - 1];
    int mini = 0;
    int maxi = 9;
    for (int i = start; i >= 1; i--) {
        for (int d = mini; d <= maxi; d++) {
            debug(i, d, dp[i][d], rem);
            if (dp[i][d] >= rem) {
                mini = max(0, d - 1);
                maxi = min(9, d + 1);
                if (number.empty() && d == 0) {
                    break;
                }
                number += (char)(d + '0');
                break;
            } else {
                rem -= dp[i][d];
            }
        }
    }
    
    if (number.empty()) number = "0";
    
    printf("%s\n", number.c_str());
    
    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

const int MAX = 510000;
const ll MOD = 100000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long FINV(int n){
    if (n < 0) return 0;
    return finv[n];
}

int main() {

    int n;
    cin >> n;
    int a[n];
    ll f[n+10] = {};
    rep(i,n){
        cin >> a[i];
        f[a[i]]++;
    }

    ll ans = 0;
    rep(i,n+10){
        ans += f[i] * (f[i] - 1) / 2;
    }

    rep(i,n){
        ll tmp = ans;
        tmp -= f[a[i]] * (f[a[i]] - 1) / 2;
        tmp += (f[a[i]] - 1) * (f[a[i]] - 2) / 2;
        cout << tmp << endl;
    }
    
    return 0;
}


Measured memory_bytes: 4992
/* -*- C -*- */

#include <stdio.h>

int main()
{
    int a,b;
  //  char str[2][100];
        
    scanf("%d %d",&a,&b);
    if(a<b){
        printf("a < b\n");
    }else if(a>b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
    
    return 0;
}


Measured memory_bytes: 2076
from math import factorial
from math import floor

def h(n, r):
    return factorial(n+r-1) // (factorial(n) * factorial(r-1))

# print('input >>')
S = int(input())
MOD = 10 **9 + 7

pattern_num = floor(S / 3)

ans = 0

for n in range(1, pattern_num+1):
    ans += h((S - 3*n), n)

# print('-----output-----')
print(ans % MOD)

Measured memory_bytes: 9112
#include <iostream>
using namespace std;
int main(void){
    int n,c,p,i;
    cin>>n>>c;
    i=0;
    while(1){
        cin>>p;
        i=i+p;
        c--;
        if(c<=0){break;}
    }
    if(i%(n+1)>=1){cout<<i/(n+1)+1<<endl;}
    else {cout<<i/(n+1)<<endl;}
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
  /* 桁DP */
  string N_str; int K;
  cin >> N_str >> K;

  int dp1[101][3]; // dp[i][j] ... 左からi+1桁目までで、0でない桁がj+1個で、Nより小さいことが確定している
  int dp2[101][3]; // dp[i][j] ... 左からi+1桁目までで、0でない桁がj+1個で、Nより小さいことが確定していない。

  dp1[0][0] = N_str[0] - '0' -1;
  dp1[0][1] = 0;
  dp1[0][2] = 0;

  dp2[0][0] = 1;
  dp2[0][1] = 0; 
  dp2[0][2] = 0;
  
  for(int i=1; i<N_str.size(); i++) {


    if(N_str[i]-'0'>0) {
      dp1[i][0] = 9               + dp1[i-1][0] * 1 + dp2[i-1][0] * 1; // 00.'*'..., *00..'0'.., 3'0'...
      dp1[i][1] = dp1[i-1][0] * 9 + dp1[i-1][1] * 1 + dp2[i-1][1] * 1 + dp2[i-1][0] * (N_str[i]-'0'-1); // *...'*'..., **...'0'..., 31'4'...
      dp1[i][2] = dp1[i-1][1] * 9 + dp1[i-1][2] * 1 + dp2[i-1][2] * 1 + dp2[i-1][1] * (N_str[i]-'0'-1); // **..'*'..., ***..'0'..., 314'0'...
      
      dp2[i][0] = 0; // 30...
      dp2[i][1] = dp2[i-1][0]; // 31....
      dp2[i][2] = dp2[i-1][1]; // 314...
    } else {
      dp1[i][0] = 9               + dp1[i-1][0] * 1; // 00.'*'..., *00..'0'..
      dp1[i][1] = dp1[i-1][0] * 9 + dp1[i-1][1] * 1; // *...'*'..., **...'0'...
      dp1[i][2] = dp1[i-1][1] * 9 + dp1[i-1][2] * 1; // **..'*'..., ***..'0'...

      dp2[i][0] = dp2[i-1][0]; // 30...
      dp2[i][1] = dp2[i-1][1]; // 310...
      dp2[i][2] = dp2[i-1][2]; // 3140...
    }
  }

  // rep(i, N_str.size()) cout << dp1[i][0] << ' ';
  // cout << endl;
  // rep(i, N_str.size()) cout << dp1[i][1] << ' ';
  // cout << endl;
  // rep(i, N_str.size()) cout << dp1[i][2] << ' ';
  // cout << endl;


  cout << dp1[N_str.size()-1][K-1] + dp2[N_str.size()-1][K-1] << endl;

  return 0;
}

Measured memory_bytes: 256