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

void solve() {
  int n; cin >> n;
  vector<int> arr(n);
  for(auto &a : arr) cin >> a;
  sort(begin(arr), end(arr));
  int ans = 0;
  for(int i=0; i<n; ++i) {
    for(int j=i+1; j<n; ++j) {
      if(arr[i] == arr[j]) continue;
      ans += lower_bound(begin(arr), end(arr), arr[i] + arr[j])
           - upper_bound(begin(arr), end(arr), arr[j]);
    }
  }
  cout << ans << endl;
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;

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 main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    string a[n];
    vector<int> b(4);
    rep(i,n){
        cin >> a[i];
        if(a[i] == "AC"){
            b[0]++;
        }else if(a[i] == "WA"){
            b[1]++;
        }else if(a[i] == "TLE"){
            b[2]++;
        }else{
            b[3]++;
        }
    }

    cout << "AC x " << b[0] << endl;
    cout << "WA x " << b[1] << endl;
    cout << "TLE x " << b[2] << endl;
    cout << "RE x " << b[3] << endl;



    
}


Measured memory_bytes: 6788
#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 x;
    cin >> x;
    if (x >= 30) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
n,m = gets.chomp.split.collect{ |item| item.to_i}
alist = gets.chomp.split.collect{ |item| item.to_i}

alist = alist.sort.reverse
blist = []
blist.push(alist.shift/2)

(m-1).times do
  if alist == []
    alist = blist
    blist = []
    blist.push(alist.shift/2)
  elsif alist[0] >= blist[0]
    blist.push(alist.shift/2)
  else
    blist.push(blist.shift/2)
  end
end

alist.push(0)
blist.push(0)
ans = alist.inject(:+) + blist.inject(:+)

puts ans

Measured memory_bytes: 14840
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,d,m,i,j,k;
  cin>>n;
  vector<int> a(n);
  for (i=0;i<n;i++) {
    cin>>a.at(i);
  }
  d=0;
  for (i=0;i<n;i++) {
    m=0;
    for (j=0;j<n;j++) {
      if (m<a.at(j)) {
        m=a.at(j);
        k=j;
      }
    }
    if (i%2==0) d+=m;
    else d-=m;
    a.at(k)=0;
  }
  cout<<d<<endl;
}

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

Measured memory_bytes: 640
N, K, S = map(int, input().split())

if K == N:
    ans = [S]*N
else:
    c = N-K
    if S == int(1e9):
        additional = 1
    else:
        additional = S+1
    ans = [S]*(N-c) + [additional] * c
    
print(*ans)

Measured memory_bytes: 6604
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int main(){
  int n, m;cin>>n>>m;
  int t=m*1900+(n-m)*100;
  cout<<int(t*pow(2.0, m))<<endl;
}


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

int main()
{
  long N, A, B;

  cin >> N >> A >> B;

  long ans = A * (N / (A + B));
  long amari = N % (A + B);

  if (amari >= A) {
    ans += A;
  }
  else {
    ans += amari;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    int r;
    cin >> r;
    if(r<1200){
        cout << "ABC" << endl;
    }else if(r<2800){
        cout << "ARC" << endl;
    }else{
        cout << "AGC" << endl;
    }

    return 0;
}

Measured memory_bytes: 384
N=int(input())
S = [a for a in input()]

t_1 = [chr(i) for i in range(65,65+26)]
t_2 = [chr(i) for i in range(65,65+26)]
t=t_1+t_2
new=[]
for i in S:
  num = t.index(i)+N
  new.append(t[num])
print("".join(new))


Measured memory_bytes: 3188
import math
import decimal




A,B=map(str,input().split())


a=decimal.Decimal(A)
b=decimal.Decimal(B)

print(int(a*b))

'''
a=int(A)
b=float(B)*100
#print(int(B))

bb=int(b)

print(math.floor(a*bb//100))
'''


Measured memory_bytes: 71516
#include<cstdio>
using namespace std;
const int maxn=100005;
int n,mp[3][maxn],a[maxn],b[2][2],c[2][maxn];
inline char nc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int ret=0;bool f=0;char ch=nc();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=nc();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=nc();
	return f?-ret:ret;
}
inline void add(int T,int x){
	for (int i=x;i;i-=i&-i) c[T][i]++;
}
inline int get(int T,int x){
	int ret=0;if(!x) return 0;
	for (int i=x;i<=n;i+=i&-i) ret+=c[T][i];
	return ret;
}
int main(){
	n=read();
	for (int i=0;i<3;i++)
	for (int j=1;j<=n;j++) mp[i][j]=read();
 	for (int i=1;i<=n;i++){
		a[i]=(mp[0][i]-1)/3*3;
		if(mp[0][i]==a[i]+3&&mp[1][i]==a[i]+2&&mp[2][i]==a[i]+1) b[0][i&1]++;else
		if(mp[0][i]==a[i]+1&&mp[1][i]==a[i]+2&&mp[2][i]==a[i]+3);else{puts("No");return 0;}
		a[i]=a[i]/3+1;if((a[i]&1)!=(i&1)){puts("No");return 0;}
	}
	for (int i=1;i<=n;i++){
		b[1][i&1]+=get(i&1,a[i]);
		add(i&1,a[i]);
	}
	b[0][0]&=1,b[0][1]&=1,b[1][0]&=1,b[1][1]&=1;
	puts(b[0][0]==b[1][1]&&b[0][1]==b[1][0]?"Yes":"No");
	return 0;
}

Measured memory_bytes: 2560
//
// extended GCD (Euclid's algorithm)
//
// c.f.
//   https://qiita.com/drken/items/b97ff231e43bce50199a
//
// verified
//   AOJ Course NTL_1_E Elementary Number Theory - Extended Euclid Algorithm
//     http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_E&lang=jp
//


#include <iostream>
using namespace std;


// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) { x = 1; y = 0; return a; }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}


int main() {
    long long a, b; cin >> a >> b;
    long long x, y;
    extGCD(a, b, x, y);
    cout << x << " " << y << endl;
}



Measured memory_bytes: 3132
#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin >>a >> b >>c;
    int sum = a+b+c;
    if(sum >= 22)
    {
        cout << "bust" << endl;
    }
    else
    {
        cout << "win" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*	Success may not come to me immediately,
 *	but it will come definitely....
 */
#include<bits/stdc++.h>
//=====================================================================
using namespace std;
//=====================================================================
#define opt	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//=====================================================================
#define li	int64_t
#define ld	double_t
#define ulli	uint64_t
//=====================================================================
#define rep(i,a,b)	for(i=a;i<b;i++)
#define repr(i,a,b)	for(i=a;i>b;i--)
#define repi(i,v)	for(i=v.begin();i!=v.end();i++)
#define elif		else if
#define mset(a,b)	memset(a,b,sizeof(a))
#define nl		cout<<'\n'
//=====================================================================
typedef vector<li>       vli;
typedef vector<string>	 vstr;
typedef pair<li,li>      pli;
typedef pair<li,pli >    ppli;
typedef pair<li,ppli >   pppli;
typedef vector<pli >     vpl;
typedef vector<ppli >    vppli;
typedef vector<pppli >   vpppli;
//=====================================================================
#define pb	push_back
#define pob	pop_back
#define pf	push_front
#define pof	pop_front
#define all(v)	v.begin(),v.end()
#define itr	iterator
#define sz	size()
#define lb	lower_bound
#define ub	upper_bound
#define bs	binary_search
#define mp	make_pair
#define F	first
#define S	second
//=====================================================================
#define mod	1000000007
#define inf	1000000000000000005
#define MX1	100005
#define MX2	1000005
#define pi	acos(-1)
//=====================================================================
li power(li a,li b){li ans=1;while(b){if(b&1){ans=(ans*a)%mod;}
a=(a*a)%mod;b>>=1;}return ans;}
//=====================================================================
li mmi(li n){return power(n,mod-2);}
//=====================================================================
li two(li n){return 1<<n;}
//=====================================================================
void onbit(li &n,li x){n|=two(x);}
//=====================================================================
void offbit(li &n,li x){n&=~two(x);}
//=====================================================================
li cntbit(li n){li res=0;while(n and ++res)n-=n&-n;return res;}
//=====================================================================
li dx[]={-1,0,1,0},dy[]={0,-1,0,1};
//=====================================================================
/*------------------------MAIN CODE BEGINS NOW!------------------------*/

li n,a[105];

void solve(){
    li i;cin>>n;
    rep(i,0,n) cin>>a[i];
    sort(a,a+n);
    cout<<a[n-1]-a[0];
}

int main(){
    opt
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    li t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

if 7 % k == 0:
    print(1)
else:
    a = []
    a.append(7 % k)
    t = 0
    for i in range(2, k+1):
        x = (10 * a[i - 2] + 7) % k
        if x == 0:
            print(i)
            break
        else:
            a.append(x)
            t += 1
    if t == k - 1:
        print(-1)


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

int main(){
  int a,b,c;
  cin>>a>>b;
  if(a>=b){
    c=a;
    a=a-1;
  }else{
    c=b;
    b=b-1;
  }
  
  if(a>=b){
    c=c+a;
  }else{
    c=c+b;
  }
  
  cout<<c<<endl;
  
  return 0;
}

  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<=b;i++)
const ll max_n = 2e5+5;

int main() {
    // your code goes here
    ll n,d,a,x[max_n],h[max_n],r[max_n],l[max_n],sum[max_n],pb=1,ans=0,attack;
    vector<pair<ll,ll>> v;
    vector<ll> vx;
    cin >> n >> d >> a;
    d*=2;
    rep(i,0,n-1) {
        cin >> x[i] >> h[i];
        if(h[i]%a==0) h[i]/=a;
        else h[i]=(h[i]-h[i]%a)/a+1;
        v.push_back({x[i],h[i]});
        vx.push_back(x[i]);
    }
    v.push_back({-1,0});
    vx.push_back(-1);
    sort(v.begin(),v.end());
    sort(vx.begin(),vx.end());
    rep(i,1,n) {
        x[i]=v[i].first;
        h[i]=v[i].second;
    }
    rep(i,1,n) {
        auto it=upper_bound(vx.begin(),vx.end(),x[i]+d);
        it--;
        r[i]=(it-vx.begin());
    }
    rep(i,1,n) {
        while(pb<=r[i]){
            l[pb]=i;
            pb++;
        }
    }
    sum[0] = 0;
    rep(i,1,n) {
        attack = h[i] - min(sum[i-1] - sum[l[i]-1], h[i]);
      	sum[i] = sum[i-1] + attack;
        ans += attack;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int w, h, x, y, r;
  cin >> w >> h >> x >> y >> r;
  
  if (( x < r || w < x+r ) ||
      ( y < r || h < y+r )) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3116
#include <stdio.h>

int main()
{
  int n, q, i, j, ans=0;
  int S[100000], T[50000];
  
  int l, r, m;
  
  scanf("%d", &n);
  for(i=0; i<n; i++)
    scanf("%d", &S[i]);
    
  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%d", &T[i]);
    
    l = 0;
    r = n;
    while (l < r){
      m = (l+r) / 2;
      if(T[i] == S[m]){
        ans++;
        break;
      }else if(T[i] < S[m]){
        r = m;
      }else{
        l = m+1;
      }
    }
  }
  
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 3172
s = input().rstrip();

ans = 0;
for i in range(2**(len(s)-1)) :
	s_alt = s;
	for j in range(len(s)-1) :
		if (i & 2**j)>>j :
			s_alt = s_alt[0:len(s)-j-1] + '+' + s_alt[len(s)-j-1:len(s_alt)+1];
	ans += eval(s_alt);

print(ans);

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

int main() {
  lint N; cin>>N;
  lint cnt = 0;
  lint i;
  lint a = 1;
  bool flag = false;
  for (i = 357; i <= N; i += 2) {
    lint n = i;
    if (n == 755 || n == 7755 || n == 77755 || n == 777755 || n == 7777755 || n == 77777755 || n == 777777755) {
      i = i + (2000 * a);
      a *= 10;
    }
    bool ok3 = false, ok5 = false, ok7 = false, ok = true;
    while(n > 0) {
      lint mod = n % 10;
      if (mod == 3) {
        ok3 = true;
        n /= 10;
      } else if (mod == 5) {
        ok5 = true;
        n /= 10;
      } else if (mod == 7) {
        ok7 = true;
        n /= 10;
      } else {
        ok = false;
        break;
      }
    }
    if (ok3 && ok5 && ok7 && ok) {
      cnt++;
    }
  }
  cout<<cnt<<endl;
}


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

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

  bool isGood = false;
  int num[4];
  for (int i = 0; i < 4; i++) {
    num[i] = N % 10;
    N /= 10;
  }

  if ((num[0] == num[1] && num[1] == num[2]) ||
      (num[1] == num[2] && num[2] == num[3])) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// C - Colorful Leaderboard
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,n) for(int i=0;i<(n);++i)

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

	vi R{400,800,1200,1600,2000,2400,2800,3200,4801};//[color_no]<rate>
	vi C(9);//[color_no]<count>
	int n = 0;//number of colors
	rp(i, N){
		int a; cin>>a;
		rp(j, C.size()){
			if(a<R[j]){
				if(C[j]==0) n++;
				C[j]++;
				break;
			}
		}
	}

	if(C[8] > 0){
		if(n > 1) printf("%d %d\n", n-1, n-1+C[8]);
		else printf("%d %d\n", 1, C[8]);
	}
	else printf("%d %d\n", n, n);
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        int n = nextInt();
        long e = nextInt();
        long t = nextInt();
        long[] x = new long[n + 1];
        for (int i = 0; i < n; i++) {
            x[i] = nextInt();
        }
        x[n] = e;
        long[] d = new long[n + 1];
        long min = Long.MAX_VALUE;
        int j = n - 1;

        for (int i = n - 1; i >= 0; i--) {
            while ((x[j] - x[i]) * 2 > t) {
                min = Math.min(min, d[j + 1] + (x[j + 1] - x[j]) + 3 * x[j]);
                j--;
            }
            d[i] = d[j + 1] + t + (x[j + 1] - x[i]);
            if (min < Long.MAX_VALUE) {
                d[i] = Math.min(d[i], min - 3 * x[i]);
            }
        }
        out.println(x[0] + d[0]);
    }

    private BufferedReader br;
    private PrintWriter out;
    private StringTokenizer st;

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    private void run() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

}


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

using namespace std;

int main()
{
	int x,a,b;
	cin >> x >> a >> b;
	for(int i=a;i<=b;i++)
	{
		if(i%x==0)
		{
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;
ll N;

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
int n,m;
int ans=0;

vector<vector<int>> grid;
vector<ll> H, S;
vector<bool> seen;
vector<ll>sum;
vector<int> pl;

vector<int> uf;

int main(int argc, char **argv){
	ll k,a,b;cin>>k>>a>>b;
	ll bis=1;
	ll yen=0;
	if(a+2>=b){
		cout<<bis+k<<endl;
		return 0;
	}else{
		if(max(0LL,a-bis)+2LL<=k){
			k-=(max(0LL,a-bis)+2LL);
			bis=b;
		}else{
				bis+=k;
				cout<<bis<<endl;
				k=0;
				return 0;
		}

		ll ex=k/2;
		ll ama=k%2;
		bis+=(b-a)*ex + ama;
		cout<<bis<<endl;
		/*
		while(k>=1){
			//cout<<(max(0LL,a-bis)+2LL)<<endl;
			if((max(0LL,a-bis)+2LL)<=k){
				k-=(max(0LL,a-bis)+2LL);
				bis=bis+max(0LL,a-bis)-a+b;
			}else{
				bis+=k;
				cout<<bis<<endl;
				k=0;
				return 0;
			}
		}*/
	}
}


Measured memory_bytes: 256
#include <cstdio>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);

	int ans=0;
	for(int i=1;i<=n;i++){
		char s[8]; sprintf(s,"%d",i);
		int cnt=0;
		for(int j=0;s[j];j++) cnt+=s[j]-'0';
		if(a<=cnt && cnt<=b) ans+=i;
	}
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<pair<int,int>> v(n);
	for(int i=0;i<n;i++){
		cin>>v[i].first;
		v[i].second=i+1;
	}
	sort(v.begin(), v.end());
	for(int i=0;i<n;i++)
		cout<<v[i].second<<" "; 
}

Measured memory_bytes: 1536
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

int cmp(vector<char> a, vector<char> b){
	int l = min(a.size(), b.size());
	for(int i=0;i<l;i++){
		if(a[i] == b[i]) continue;
		return a[i] > b[i] ? 1 : -1;
	}
	if(a.size() != b.size()){
		return a.size() > b.size() ? 1 : -1;
	}
	return 0;
}

int main(){
	
	string s,t;
	cin >> s >> t;
	
	vector<char> vs(s.begin(), s.end());
	vector<char> vt(t.begin(), t.end());
	
	sort(vs.begin(), vs.end());
	sort(vt.begin(), vt.end());
	reverse(vt.begin(), vt.end());
	
	cout << (cmp(vs, vt) < 0 ? "Yes" : "No") << endl;
	
    return 0;
}

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

string updown(int x){
if (x >= 0){
return "U";
}
else{
return "D" ;
}
}

string leftright(int x){
if (x >= 0){
return "R";
}
else{
return "L" ;
}
}


int main(){


//入力を受け取り
  int A, B, C, D ;
  cin >> A ;
  cin >> B ; 
  cin >> C;
  cin >> D ;
  
//入力受け取り終わり
  

//移動すべきベクトルは(S,T)
  int S = C - A ;
  int T = D - B ;
 
//移動1周目はじめ
  //上下移動
  if (T >= 0){
  for(int i=0; i < T; i++){
  cout << updown(T) ;
  }
  }
  if (T < 0){
   for(int i=0; i < -T; i++){
  cout << updown(T) ;
  }
  }

 //左右移動
    if (S >= 0){
  for(int i=0; i < S; i++){
  cout << leftright(S) ;
  }
  }
  if (S < 0){
   for(int i=0; i < -S; i++){
  cout << leftright(S) ;
  }
  }
  
  //再び上下移動
  if (T >= 0){
  for(int i=0; i < T; i++){
  cout << "D" ;
  }
  }
  if (T < 0){
   for(int i=0; i < -T; i++){
  cout << "U" ;
  }
  }
  
  //再び左右移動
    if (S >= 0){
  for(int i=0; i < S; i++){
  cout << "L" ;
  }
  }
  if (S < 0){
   for(int i=0; i < -S; i++){
  cout << "R" ;
  }
  }
  
//移動1周目おわり
  
  
//移動2周目はじめ
  //ちょい左右移動
  cout << leftright(-S) ;
  
  //上下移動
  if (T >= 0){
  for(int i=0; i < 1+T; i++){
  cout << "U" ;
  }
  }
  if (T < 0){
   for(int i=0; i < 1-T ; i++){
  cout << "D" ;
  }
  }

 //左右移動
    if (S >= 0){
  for(int i=0; i < 1+S; i++){
  cout << "R" ;
  }
  }
  if (S < 0){
   for(int i=0; i < 1-S; i++){
  cout << "L" ;
  }
  }
  
  //ちょい上下移動
  cout << updown(-T) ;
  
   //ちょい左右移動
  cout << leftright(S) ;
  
  //再び上下移動
  if (T >= 0){
  for(int i=0; i < 1+T; i++){
  cout << "D" ;
  }
  }
  if (T < 0){
   for(int i=0; i < 1-T; i++){
  cout << "U" ;
  }
  }
  
  //再び左右移動
    if (S >= 0){
  for(int i=0; i < 1+S; i++){
  cout << "L" ;
  }
  }
  if (S < 0){
   for(int i=0; i < 1-S; i++){
  cout << "R" ;
  }
  }
  
  //ちょい上下移動
  cout << updown(T) ;
  
//移動2周目おわり  
  
  
}//Endmain

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		//
		int cnt = 0;
		Map<Integer, List<Integer>> map = new HashMap<>(); 
		for (int i=1; i<=N; i++) {
			int j = sc.nextInt();
			List<Integer> list = map.get(i);
			if (list!=null && list.contains(j)) {
				cnt++;
				continue;
			}
			list = map.get(j);
			if (list==null) {
				list = new ArrayList<Integer>();
				map.put(j, list);
			}
			list.add(i);
		}
		//
		System.out.println(cnt);
		sc.close();
	}
}


Measured memory_bytes: 57800
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, K int
	fmt.Scan(&n, &K)

	xs := make([]Point, n)
	ys := make([]Point, n)
	var x, y int
	for i := 0; i < n; i++ {
		fmt.Scan(&x, &y)
		xs[i] = Point{i, x, y}
		ys[i] = Point{i, x, y}
	}

	sort.Slice(xs, func(i, j int) bool {
		return xs[i].x < xs[j].x
	})
	sort.Slice(ys, func(i, j int) bool {
		return ys[i].y < ys[j].y
	})

	ans := int(1e18 * 4)
	for x1 := 0; x1 < n; x1++ {
		for x2 := x1 + 1; x2 < n; x2++ {
			for y1 := 0; y1 < n; y1++ {
				for y2 := y1 + 1; y2 < n; y2++ {
					x1, x2, y1, y2 := xs[x1].x, xs[x2].x, ys[y1].y, ys[y2].y
					cnt := 0
					for _, p := range xs {
						if x1 <= p.x && p.x <= x2 && y1 <= p.y && p.y <= y2 {
							cnt++
							if K <= cnt {
								ans = min(ans, (x2-x1)*(y2-y1))
								break
							}
						}
					}
				}
			}
		}
	}

	fmt.Println(ans)
}

// Point .
type Point struct {
	i, x, y int
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 1880
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int K = scanner.nextInt();

		int count = 0;
		for (int i = 1; i <= N; i += 2) {
			count++;
			if (count == K) {
				System.out.print("YES");
				return;
			}
		}

		System.out.print("NO");
	}
}

Measured memory_bytes: 22740
#include <stdio.h>

#define SIZE 3

void InputNumber(int* num, int rangeX, int rangeY);
char* Judgment(int x, int y, int W, int H, int r);

int main(void) {
	int x, y;
	int W, H, r;
	char *msg;

	InputNumber(&W, 1, 100);
	InputNumber(&H, 1, 100);

	InputNumber(&x, -100, 100);
	InputNumber(&y, -100, 100);
	InputNumber(&r, 1, 100);

	msg = Judgment(x, y, W, H, r);
	printf("%s\n", msg);
}

void InputNumber(int* num, int rangeX, int rangeY) {
	do {
		scanf("%d", num);
	} while (*num < rangeX || *num > rangeY);
}

char* Judgment(int x, int y, int W, int H, int r) {
	char* msg = "No";

	int rLX = 0;
	int rRX = W;
	int rDY = 0;
	int rUY = H;

	int cLX = x - r;
	int cRX = x + r;
	int cDY = y - r;
	int cUY = y + r;

	if (rLX <= cLX &&
		rRX >= cRX &&
		rDY <= cDY &&
		rUY >= cUY) {
		msg = "Yes";
	}

	return msg;
}


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

using namespace std;

int main(void){
    int n,i;
    int count = 0;
    int *array;

    cin >> n;
    array = (int*)malloc(sizeof(int)*n);

    for(i=0; i<n; i++){
        cin >> array[i];
    }

    for(i=0; i<n; i++){
        while(array[i]%2 == 0){
            count++;
            array[i] /= 2;
        }
    }

    cout << count << endl;

    return 0;
}


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


Measured memory_bytes: 3944
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int N = 1e5+7, K = 307, INF = 1e18;

int a[N];
int dp[K][N];

struct Queue_Min {
//pair (i, x)
deque <ii> a;
void add(ii e) {
    while (a.size() && a.back().s >= e.s)   
        a.pop_back();
    a.push_back(e);
}
void del(ii e) {
    if (a.size() && a.front() == e)
        a.pop_front();
}   
int get() {
    if (a.empty())
        return INF;
    else
        return a.front().s;
}   
};  

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20); 
    #endif

    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        dp[1][i] = a[i];
    }   

    for (int i = 2; i <= k; ++i) {
        Queue_Min q;
        for (int j = 1; j <= n; ++j) {
            if (j - m - 1 > 0) {
                q.del(mp(j - m - 1, -dp[i - 1][j - m - 1]));
            }   
            if (j > 1) {
                q.add(mp(j - 1, -dp[i - 1][j - 1]));
            }   
            dp[i][j] = i * a[j] - q.get();
        }   
    }   

    int ans = 0;
    for (int i = 1; i <= n; ++i)
        ans = max(ans, dp[k][i]);
    cout << ans << endl;
}


Measured memory_bytes: 238760
A,B,C,K  = map(int,input().split())

ans = 0

if K >= A:
    ans += A
    K -= A
else:
    ans += K
    K = 0

if K >= B:
    K -= B
else:
    K = 0

if K >= C:
    ans -= C
    K -= C
else:
    ans -= K
    K = 0

print (ans)


Measured memory_bytes: 61656
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		long H=stdIn.nextLong();
		long ans=0,i=1;
		while(true){
			ans+=i;
			if(H==1)
				break;
			H/=2;i*=2;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int X, A;
    cin >> X >> A;
    if(X<A){
        cout << 0 << endl;
    }else{
        cout << 10 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  
  for (int i = s.length()-2; i >= 2; i -= 2) {
    vector<char> zen(i/2), kou(i/2);
    for (int j = 0; j < i; j++) {
      if (j < i/2)
        zen[j] = s[j];
      else
        kou[j - i/2] = s[j];
    }
    bool check = true;
    for (int j = 0; j < i/2; j++) {
      if (zen[j]!=kou[j]) {
        check = false;
        break;
      }
    }
    if (check) {
      cout << i;
      break;
    }
  }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<tuple<string,int,int>> R;
  for (int i=0; i<N; i++) {
    string s;
    int p;
    cin >> s >> p;
    R.push_back(make_tuple( s, 100 - p, i + 1));
  }
  sort(R.begin(), R.end());
  for (auto x: R) {
    cout << get<2>(x) << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<algorithm>
#include<vector>
using namespace std;
#define	ll long long
int main(){
	int N;
	int a, b;
	cin >> N ;
	if (N == 2){
		cin >> a >> b;
		cout << a + b << endl;
	}
	else cout << "Hello World" << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
B=list(map(int,input().split()))
if n==2:
    print(B[0]*2)
    exit()
A=[0]*n
A[0]=B[0]; A[-1]=B[-1]
for i in range(1,n-1):
    A[i]=min(B[i-1],B[i])
print(sum(A))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100005
#define INF 1000000005
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;
int main(){
    string s,t;
    cin>>s>>t;
    bool f=true;
    REP(i,SZ(s)){
        if(s[i]!=t[i]){
            f=false;
            break;
        }
    }
    if(f)OUT("Yes");
    else OUT("No");
    
    return 0;
}

Measured memory_bytes: 3592
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
const double pi=acos(-1.0);
const double eps=1e-11;
template<class T> inline void ckmin(T &a,T b){if(b<a) a=b;}
template<class T> inline void ckmax(T &a,T b){if(b>a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> ipair;
#define SIZE(A) ((int)A.size())
#define LENGTH(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,a) for(int i=0;i<(a);++i)
#define ALL(A) A.begin(),A.end()

const int maxsize=(1<<20);

int n;
int a[maxsize];
int f[20][maxsize];
int pos[maxsize];
int l2[maxsize];
priority_queue<pair<int,ipair>> heap;

int rmq(int s,int t)
{
	int c=(t-s)/2+1;
	int d=l2[c];
	return min(f[d][s],f[d][t-2*((1<<d)-1)]);
}
void add(int s,int t)
{
	if (s>t) return;
	int x=rmq(s,t-1);
	heap.push(MP(-x,MP(s,t)));
}
int main()
{
#ifdef _MSC_VER
	freopen("input.txt","r",stdin);
#endif
	std::ios::sync_with_stdio(false);
	cin>>n;
	REP(i,n) { cin>>a[i]; --a[i]; pos[a[i]]=i; }
	l2[0]=0;
	FOR(i,1,n+1)
	{
		int d=l2[i-1];
		if (two(d+1)<=i) ++d;
		l2[i]=d;
	}
	REP(i,n) f[0][i]=a[i];
	for (int d=1,l=2;d<20;d++,l*=2)
		REP(i,n)
		{
			f[d][i]=f[d-1][i];
			if (i+l<n) ckmin(f[d][i],f[d-1][i+l]);
		}
	add(0,n-1);
	REP(i,n/2)
	{
		if (i>0) printf(" ");
		pair<int,ipair> state=heap.top();
		heap.pop();
		int s=state.second.first;
		int t=state.second.second;
		int v1=rmq(s,t-1);
		int p1=pos[v1];
		int v2=rmq(p1+1,t);
		int p2=pos[v2];
		printf("%d %d",v1+1,v2+1);
		add(s,p1-1);
		add(p1+1,p2-1);
		add(p2+1,t);
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 47992
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    ll n, x; cin >> n >> x;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(ALL(a));
    int ans = 0;
    int i = 0;
    while(x - a[i] >= 0) {
        x -= a[i];
        ans++;
        i++;
        if(i == n) break;
    }
    if(x > 0 && i == n) ans--;
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
ab = 0
frontb = 0
backa = 0
count = 0
ryou = 0
for i in range(n):
    s = input()
    for j in range(len(s)-1):
        if s[j] == 'A' and s[j+1] == 'B':
            count += 1
    if s[0] == 'B' and s[-1] == 'A':ryou += 1
    if s[0] == 'B':frontb += 1
    if s[-1] == 'A':backa += 1
if frontb == 0 and backa == 0:
    pass
elif frontb + backa == ryou*2:
    count += backa-1
else:
    count += min(backa,frontb)
print(count)

Measured memory_bytes: 50280
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#include<string.h>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
const int maxn=100+6;
#define mod 1000000007
#define INF 0x3f3f3f3f
int main()
{
    string a,b,c;
    int l1=0,l2=0;
    cin>>a>>b;
    cin>>l1>>l2;
    cin>>c;
    if(c==a)cout<<l1-1<<" "<<l2<<endl;
    else cout<<l1<<" "<<l2-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
    const int MAX_N = 1e5 + 10;
    int N;
    vector<int> A;
    cin >> N;
    for (int i = 0; i < N; ++i){
        A.push_back(-1);
    }

    for (int i = 0; i < N; ++i){
        int a;
        cin >> a;
        int b = lower_bound(A.begin(), A.end(), a) - A.begin() - 1;
        A[b] = a;
    }

    int ans = 0;
    for (int i = 0; i < N; ++i){
        if(A[i] >= 0) ans++;
    }
    cout << ans << endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
typedef long double ld;

using namespace std;

void solve(string a, string b){
	if ((a == "H") ^ (b == "D")) {
		cout << "H" << endl;
	} else {
		cout << "D" << endl;
	}
	
}

int main(){
    // 提出時は削除 //////////////////////////////
//	FILE* fp_in = freopen("/Users/kokinakamura/git/ToolsForAtCoder/workspace/abc056/A/in_A_1.txt", "r", stdin);
    ////////////////////////////////////////////

	string b;
	string a;
	cin >> a;
	cin >> b;
	solve(a, b);

    // 提出時は削除 //////////////////////////////
//    fclose(fp_in);
    ////////////////////////////////////////////
	return 0;
}


Measured memory_bytes: 256
def chmax(a, b)
  a >= b ? a : b
end

s = gets.chomp
n = s.length

dp = Array.new(n) { Array.new(2 + 1, 0) }
dp[0][1] = dp[1][2] = 1

1.upto(n - 1) do |i|
  if s[i - 1] != s[i]
    # 1 -> 1
    dp[i][1] = chmax(dp[i - 1][1], dp[i - 1][2]) + 1
  else
    # 1 -> 2
    dp[i][1] = dp[i - 1][2] + 1
  end

  if i >= 3 && s[i - 3..i - 2] != s[i - 1..i]
    # 2 -> 2
    dp[i][2] = chmax(dp[i - 2][1], dp[i - 2][2]) + 1
  else
    # 2 -> 1
    dp[i][2] = dp[i - 2][1] + 1
  end
end

puts chmax(dp[n - 1][1], dp[n - 2][2])


Measured memory_bytes: 16764
#include <stdio.h>

int main(void)
{
  int i, j, n, k, d[100], a[100], m[100] = {0}, result = 0;
  
  scanf("%d %d", &n, &k);
  

  for( i = 0; i < k; i++ ){
      scanf("%d", &d[i]);
    for( j = 0; j < d[i]; j++ ){
        scanf("%d ", &a[j]);
        m[a[j]-1] = 1;
    }
  }
  
  for( i = 0; i < n; i++ ){
      if( m[i] == 0 ){
          result++;
      }
  }
      
  printf("%d\n", result);
  return 0;
}

Measured memory_bytes: 1732
/*
  kadai6_2 i18b.c
  unomi
*/
#include <stdio.h>
#include <string.h>
int main(void){
    char word[255];
    // 単語の入力を取得
    scanf("%s",word);

    // 先頭の文字の表示
    printf("%c",word[0]);
    // 先頭と末尾の間の文字数の表示
    printf("%ld",strlen(word)-2);
    // 末尾の文字の表示
    printf("%c\n",word[strlen(word)-1]);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);
	int n,a,b;cin>>n>>a>>b;
	cout << min(b,n*a) << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz size
#define pb push_back
#define mper make_pair
#define PI 3.14159
#define fe first
#define se second
#define ll long long
//#define forik(i, a, b) for(ll i = a; i <= b; ++i)
//#define vl vector<ll>
//#define pll pair<ll, ll>
#define mal ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define saken stringusing namespace std;
using namespace std;

int n, k, dis[2010][2010], mx;
vector < int > g[2010];

bool used[2010][2010];

bitset <2010> t[2100];

vector < pair <int, int> > pos_ans;

void dfs(int orig, int v, int ct = 0) {

    used[orig][v] = 1;

    for(auto to : g[v]) {

        if(!used[orig][to]) {

            dis[orig][to] = ct + 1;

            t[orig][to] = (dis[orig][to] > k);

            mx = max(mx, ct + 1);



            if(ct + 1 == k) {pos_ans.pb(mper(orig, to));}


            dfs(orig, to, ct + 1);

        }

    }

}

int main(){

cin >> n >> k;

for(int i = 1, l, r; i < n; ++i) {

    cin >> l >> r;

    g[l].pb(r);
    g[r].pb(l);

}

for(int i = 1; i <= n; ++i) {
    dfs(i, i);
}


if(mx <= k) {cout << 0;return 0;}


int ans = (int)1e8;

for(auto to : pos_ans) {

    int a = to.fe;
    int b = to.se;

    int ct = (t[a] | t[b]).count();


    ans = min(ans, ct);

}

cout << ans;

return 0;
}


Measured memory_bytes: 52960
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int h = sc.nextInt(), w = sc.nextInt();
        int k = sc.nextInt();

        char[][] map = new char[h][w];
        for(int i=0; i<h; i++) map[i] = sc.next().toCharArray();

        int[][] J = new int[h+1][w+1];
        int[][] O = new int[h+1][w+1];
        int[][] I = new int[h+1][w+1];
        for(int i=1; i<=h; i++){
            for(int j=1; j<=w; j++){
                if(map[i-1][j-1]=='J') J[i][j]++;
                if(map[i-1][j-1]=='O') O[i][j]++;
                if(map[i-1][j-1]=='I') I[i][j]++;
                J[i][j] = J[i][j] + J[i-1][j] + J[i][j-1] - J[i-1][j-1];
                O[i][j] = O[i][j] + O[i-1][j] + O[i][j-1] - O[i-1][j-1];
                I[i][j] = I[i][j] + I[i-1][j] + I[i][j-1] - I[i-1][j-1];
            }
        }

        for(int i=0; i<k; i++){
            int y1 = sc.nextInt(), x1 = sc.nextInt();
            int y2 = sc.nextInt(), x2 = sc.nextInt();

            int n1 = J[y2][x2] - J[y2][x1-1] - J[y1-1][x2] + J[y1-1][x1-1];
            int n2 = O[y2][x2] - O[y2][x1-1] - O[y1-1][x2] + O[y1-1][x1-1];
            int n3 = I[y2][x2] - I[y2][x1-1] - I[y1-1][x2] + I[y1-1][x1-1];
            System.out.println(n1+" "+n2+" "+n3);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

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

vector<int> a;
int main(){
    int n,m;
    cin>>n>>m;
    int sum = 0;
    for(int i = 0 ; i<n; i++){
        int tmp ;
        cin>>tmp;
        sum+=tmp;
        a.push_back(tmp);
    }
    int thr = sum / (4*m);
    sort(a.rbegin(), a.rend());
    int cnt = 0;
    for(int i = 0; i<a.size(); i++){
        if(a[i]*4*m>=sum){
            cnt++;
        }

    }

    if(cnt >=m ) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
bool used[9],d[9][9];

void dfs(int p,int c){
  if(c==n)ans++;
  used[p]=1;
  for(int i=1;i<=n;i++)
    if(!used[i]&&d[p][i])dfs(i,c+1);
  used[p]=0;
}

int main(){
  cin>>n>>m;
  for(int i=0,a,b;i<m;i++){
    cin>>a>>b;
    d[a][b]=d[b][a]=1;
  }
  dfs(1,1);
  cout<<ans<<endl;
  return 0;
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}

int main() {
  int n;cin>>n;
  multimap<string, pair<int, int> > r;
  set<string> k;
  REP(i,n){
    string s;int p;
    cin>>s>>p;
    r.emplace(s,make_pair(p,i+1));
    k.insert(s);
  }
  for(auto key=k.begin(); key!=k.end(); ++key){
    string city=*key;
    auto list=r.equal_range(city);
    map<int, int, greater<int> > plist;
    for(auto pnt=list.first; pnt!=list.second; ++pnt){
      plist.emplace(pnt->second.first,pnt->second.second);
    }
    for(auto sorted=plist.begin(); sorted!=plist.end(); ++sorted){
      cout<<sorted->second<<endl;
    }
  }
}


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

int main() {
	int N; cin >> N;
	vector<int> a(N);
	for(int i = 0; i < N; ++i) cin >> a[i];
	int j = 1, cnt = 0;
	for(int i = 0; i < N; ++i) {
		if(a[i] != j) {
			cnt++;
		} else {
			j++;
		}
	}
	cout << (cnt == N ? -1 : cnt) << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n,m;
	while(cin>>n>>m,n+m){
		vi a,b;
		for(int i=1;i*i<=n;i++)if(n%i==0)a.pb(i);
		for(int i=1;i*i<=m;i++)if(m%i==0)b.pb(i);
		int mi=inf;
		rep(i,a.size())rep(j,b.size()){
			vi t;
			t.pb(a[i]);t.pb(n/a[i]);t.pb(b[j]);t.pb(m/b[j]);
			sort(all(t));
			int c=t[1]-t[0];
			int d=t[2]-t[1];
			int e=t[3]-t[2];
			mi=min(mi,c*c+d*d+e*e);
		}
		cout<<mi<<endl;
	}
}

Measured memory_bytes: 1220
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define REP(i,a,b) for(i=a; i<b; ++i)
#define rep(i,n) REP(i,0,n)

int board[10001];

int pop(int x) {
  int n = 0;
  while(x != 0) n = n + 1,x = x & (x-1);
  return n;
}

int main() {
  int n,i,j,k,r,c;
  while(scanf("%d %d", &r, &c), r|c) {
    memset(board, 0, sizeof(board));
    rep(i,r)
      rep(j,c) {
	scanf("%d", &k);
	if(k) board[j] |= (1<<i);
      }

    int ans = 0,tt,t;
    rep(i,(1<<r)) {
      t = 0;
      rep(j,c) {
	tt = pop(board[j] ^ i);
	t += max(tt, r-tt);
      }
      ans = max(ans, t);
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 804
#include<iostream>
using namespace std;
long long a,b,c;
int main()
{
    cin>>a>>b>>c;
    if(c-a-b<0) cout<<"No";
    else
    {
        if(4*a*b<(c-a-b)*(c-a-b)) cout<<"Yes";
        else cout<<"No";
    }
}


Measured memory_bytes: 256
import Control.Applicative
import Data.Fixed

data E10=E10
instance HasResolution E10 where
        resolution _ = 10 ^ 10
type Hoge = Fixed E10

main = do [a,b] <- (map read) . words <$> getLine
          let d = a `div` b :: Int
          let r = a `mod` b :: Int
          let f = (realToFrac a) / (realToFrac b) :: Hoge
          putStrLn $ (show d) ++ " " ++ (show r) ++ " " ++ (show f)

Measured memory_bytes: 4084
#include <iostream>
#include <numeric>
using namespace std;
int main(){
	int T;
	cin >> T;
	for (int i = 0; i < T; i++){
		long long A, B, C, D;
		cin >> A >> B >> C >> D;
		if (A > C){
			A = (A - C - 1) % B + C + 1;
		}
		if (A < B){
			cout << "No" << endl;
		} else if (B > D){
			cout << "No" << endl;
		} else if (B < C){
			cout << "Yes" << endl;
		} else if (B - C <= gcd(B, D)){
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 3568
N = int(input())
A = list(map(int, input().split(' ')))
q = {}
flag = 0
for i in range(N):
    if A[i] in q:
        q[A[i]] += 1
    else:
        q[A[i]] = 1
if N % 2 == 0:
    even = [2*i+1 for i in range(N // 2)]
    for i in even:
        if i not in q.keys():
            flag = 1
            break
        elif q[i] != 2:
            flag = 1
            break
    if flag == 1:
        print(0)
    else:
        print(pow(2, len(q.keys())) % 1000000007)
else:
    odd = [2*i for i in range((N+1) // 2)]
    for i in odd:
        if i not in q.keys():
            flag = 1
            break
        elif i == 0 and q[i] != 1:
            flag = 1
            break
        elif i != 0 and q[i] != 2:
            flag = 1
            break
    if flag == 1:
        print(0)
    else:
        print(pow(2, (len(q.keys()) - 1)) % 1000000007)


Measured memory_bytes: 14436
#include <stdio.h>
#include <math.h>
#define MAX 500000

void maxHeapify(int *A, int i);
void buildMaxHeap(int *A);
int H;

int main(){
  int A[MAX+1],i;
  scanf("%d",&H);

  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }

  buildMaxHeap(A);

  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}

int parent(i){
  return floor(i/2);
}

int left(i){
  return 2*i;
}

int right(i){
  return 2*i+1;
}

void maxHeapify(int *A, int i){
  int l, r, largest, tmp;
  l=left(i);
  r=right(i);

  if(l<=H && A[l]>A[i]) largest=l;
  else largest=i;
  if(r<=H && A[r]>A[largest]) largest=r;

  if(largest!=i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(A,largest);
  }
}

void buildMaxHeap(int *A){
  int i;
  for(i=H/2;i>=1;i--){
    maxHeapify(A,i);
  }
}


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

#define sc(x) scanf("%d",&x);
#define rep(x ,n) for(int x=0; x<n; x++)
#define ll long long
#define finish(x) return cout << x << endl,0;
#define scarr(a,n) for(int x=0; x<n; x++)scanf("%d",&a[x]);

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

    double ans = 0;
    for(int i=1; i<=n; i++)
    {
        if(i >= k)
            ans += (1.0/n) * (1);
        else{
            int j = 0;
            for(int c=i; c<k; c*=2 ,j++);
            ans += (1.0/n) * pow(0.5 ,j);
        }
    }

    cout << fixed << setprecision(16) << ans << endl;
}

Measured memory_bytes: 764