akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DCaracalVsMonster solver = new DCaracalVsMonster();
        solver.solve(1, in, out);
        out.close();
    }

    static class DCaracalVsMonster {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            long h = s.nextLong();
            long c = 1;
            long res = 0;
            while (h > 0) {
                res += c;
                h /= 2;
                c *= 2;
            }
            w.println(res);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21456
#include <iostream>
using namespace std;
int main(void){
    int m, f, b;
    cin>>m>>f>>b;
    if(m>=b){
        cout<<0<<endl;
    }else if(m+f>=b){
        cout<<b-m<<endl;
    }else{
        cout<<"NA"<<endl;
    }
    
}



Measured memory_bytes: 3084
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  int v;
  if (1 <= b && b <= 9)
    v = a * 10 + b;
  else if (10 <= b && b <= 99)
    v = a * 100 + b;
  else
    v = a * 1000 + b;

  if (v - 1e-9 < int(sqrt(v)) * int(sqrt(v)) && int(sqrt(v) * int(sqrt(v)) <= v + 1e-9))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    int n;
    cin>>n;
    vi ps;
    rep(i, 5555) {
        int m = (i + 1) * 10 + 1;
        bool f = true;
        for (int j = 2; j * j <= m; ++j) {
            if (m % j == 0) f = false;
        }
        if (f) ps.push_back(m);
    }
    rep(i, n) cout<<ps[i]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  ll x; cin >> x;
  ll ans = 0;
  ans += (x/500)*1000;
  x = x % 500;
  ans += (x/5)*5;
  cout << ans << endl;
  return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H, vector<char>(W));
  vector<vector<int>> A(H, vector<int>(W));
  for (int i = 0; i < H; i++) for (int j = 0, k = 0; j < W && cin >> S.at(i).at(j); j++) A.at(i).at(j) += (S.at(i).at(j) != '#') ? ++k : k = 0;
  for (int i = 0; i < W; i++) for (int j = 0, k = 0; j < H; j++) A.at(j).at(i) += (S.at(j).at(i) != '#') ? ++k : k = 0;
  for (int i = 0; i < H; i++) for (int j = W - 1, k = 0; j >= 0; j--) A.at(i).at(j) += (S.at(i).at(j) != '#') ? ++k : k = 0;
  int ans = 0;
  for (int i = 0; i < W; i++) for (int j = H - 1, k = 0; j >= 0; j--) {
    A.at(j).at(i) += (S.at(j).at(i) != '#') ? ++k : k = 0;
    ans = max(ans, A.at(j).at(i));
  }

  cout << ans - 3 << "\n";
}

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

#define debug(x) cout << #x" = " << x;

#define st first
#define nd second

using namespace std;
using namespace placeholders;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

const int MAXN = 1E5 + 10;

int n;
vector<int> E[MAXN];
int deg[MAXN], fa[MAXN], mark[MAXN];

int main(){
	scanf("%d", &n);
	for (int u, v, i = 1; i < n; ++i){
		scanf("%d%d", &u, &v);
		E[u].push_back(v), ++deg[u];
		E[v].push_back(u), ++deg[v];
	}

	queue<int> Q;
	for (int i = 1; i <= n; ++i)
		if (deg[i] == 1){
			fa[i] = E[i][0];
			Q.push(i);
		}

	while (!Q.empty()){
		map<int, int> lst;
		while (!Q.empty()){
			int u = Q.front();
			Q.pop();
			++lst[fa[u]];
			mark[u] = true;
		}

		for (auto &x: lst){
			mark[x.st] = true;
			if (x.nd > 1)
				return puts("First"), 0;
		}
		for (auto &x: lst)
			for (auto &v: E[x.st])
				--deg[v];

		set<int> ms;
		for (auto &x: lst){
			int u = x.st;
			for (auto &v: E[u])
				if (!mark[v] && !ms.count(v)){
					if (deg[v] == 0)
						return puts("First"), 0;
					if (deg[v] == 1){
						for (auto &w: E[v])
							if (!mark[w])
								fa[v] = w;
						ms.insert(v);
						Q.push(v);
					}
				}
		}
	}
	puts("Second");
	return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	string s;
	int ans=0;
	int count=0;
	cin>>s;
	s += 'N';
	for(int i=0;i<s.size();i++){
		if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){
			count++;
		}
		else{
			ans=max(ans,count);
			count=0;
		}
	}
	cout<<ans<<endl;
}

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

int main() {
	string s;
  	cin >> s;
  
  	bool flag = false;
  	for (int i = 0; i < s.size(); i++) {
    	if (s[i] == 'C') flag = true;
      	if (flag && s[i] == 'F') {
        	cout << "Yes" << endl;
          	return 0;
        }
    }
  
  	cout << "No" << endl;
  	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  cout << a * (n / (a + b))
            + min(a, n - (a + b) * (n / (a + b)))
       << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;

int main() {
	int N = 0 , a[100000 * 2] = {}, ans[100000 * 2] = {}, j = 0, i = 0;
	cin >> N;
	for (i = 0; i<N; i++)
	{
		cin >> a[i];
	}
	for (i = N-1; i>=0; i -= 2)
	{
		ans[j] = a[i];
		j++;
	}
	if (i == -1)i = 0;
	else i = 1;
	for (; i < N; i += 2)
	{
		ans[j] = a[i];
		j++;
	}
	for (int i = 0; i < N; i++)
	{
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n), b(n);
    REP(i,n) cin >> a[i] >> b[i];
    ll ans = 0;
    REPR(i,n) {
        if((ans+a[i])%b[i]==0) continue;
        else ans += b[i] - (ans+a[i])%b[i];
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

const int N = 500005;
const int mod = 998244353;

int prd[N], inv[N];

int binPow(int x, int y) {
	if (!y) return 1;
	int ret = binPow(x, y >> 1);
	ret = 1LL * ret * ret % mod;
	if (y & 1) ret = 1LL * ret * x % mod;
	return ret;
}

void prep() {
	prd[0] = 1;
	for (int i = 1; i < N; ++i) prd[i] = 1LL * i * prd[i - 1] % mod;
	inv[N - 1] = binPow(prd[N - 1], mod - 2);
	for (int i = N - 1; i >= 1; --i) inv[i - 1] = 1LL * inv[i] * i % mod;
}

inline int C(int n, int k) {
	if (n < k || k < 0) return 0;
	return 1LL * prd[n] * inv[k] % mod * inv[n - k] % mod;
}

inline int calc(int x, int y) {
	return C(x + y, y);
}

int main() {
	ios::sync_with_stdio(false);
	int n, k; cin >> n >> k;
	long long res = 0;
	prep();
	for (int r = 0; r <= k; ++r) {
		int b = k - r;
		if (r < b || r < n) continue;
		if (r == b) {
			int tmp = b - n + 1;
			res += calc(r, b) - calc(b - tmp, r + tmp);
			res -= calc(r - 1, b) - calc(b - tmp, r - 1 + tmp);
		}
		else {
			int tmp = b - (n - (r - b)) + 1;
			res += calc(r, b) - calc(b - tmp, r + tmp);
		}
	}
	res = (res % mod + mod) % mod;
	cout << res;
}

Measured memory_bytes: 4224
#include<iostream>
#include<vector>
using namespace std;
const int Nmax = 101;
int A[Nmax], N;

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

	int ans = 1e9;
	for(int m=-100; m<= 100; m++){
		int cost = 0;
		for(int i=0; i<N; i++) cost+=(m-A[i])*(m-A[i]);
		ans = cost < ans ? cost : ans;
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
char laz[maxn];
int pi[12*maxn],m,n;
string buf;
int prefix_function(const string &s,const string &t) {
    ///search t on s
    m=(int)t.length();
    n =(int)t.length()+(int)s.length()+1;
    buf=t+'#'+s;
    pi[0]=0;
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && buf[i] != buf[j])
            j = pi[j-1];
        if (buf[i] == buf[j])
            j++;
        pi[i] = j;
    }
    int ma=-1;
    for(int i=n-1;i>m;i--){
        pi[i]=(pi[i]==m?1:0);
        if(i+m<n&&pi[i]==1){
            pi[i]+=pi[i+m];
        }
        ma=max(ma,pi[i]);
    }
    return ma;
}
string s,t,a,ss,tt;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>ss>>t;
    s=ss;
    while((int)s.length()<=(int)t.length()+(int)ss.length()){
        s+=ss;
    }
    s+=ss;
    int c=prefix_function(s,t);
    if(c==-1){
       return cout<<"0",0;
    }
    s+=s;
    int cc=prefix_function(s,t);
    if(cc==c){
        return cout<<cc,0;
    }
    else{
        return cout<<-1,0;
    }
}
/*
    Good Luck
        -Lci70121
*/


Measured memory_bytes: 30512
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint a, b, c;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	
	cout << a << " " << b << " " << c << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int dp[1010][1010];
main()
{
    string s,t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    t.push_back( '$' );
    memset( dp, 0, sizeof( dp ) );
    dp[0][0] = 1;
    const int MOD = 1e9 + 7;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <= m; j++)
        {
            if (s[i] == t[j])
            {
                dp[i + 1][j + 1] += dp[i][j];
                dp[i + 1][j + 1] %= MOD;
            }
            dp[i + 1][j] += dp[i][j];
            dp[i + 1][j] %= MOD;
        }
    }
    cout << dp[n][m] << endl;
}


Measured memory_bytes: 7136
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    string s; cin >> s;
    char c;
    int cnt = 0;
    rep(i,0,s.length()) {
        if(i == 0) c = s[i];
        else if(s[i] != c) {
            cnt++;
            c = s[i];
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=155;
int n,m,mod;
void Inc(int &x,int y){
	x+=y;x>=mod?x-=mod:x;
}
void solve1(){
	static int f[N][N][N];
	f[0][0][0]=1;
	for(int i=1;i<=(n+m)/2;++i){
		int x=i+i-m,y=i+i;
		for(int j=0;j<=m+1;++j)
			for(int k=0;k<=n;++k)
				Inc(f[i][0][0],f[i-1][j][k]);
		if(x>=1){
			for(int k=0;k<=n;++k)
				Inc(f[i][0][0],f[i-1][0][k]);
			for(int j=1;j<=m+1;++j)
				for(int k=0;k<=n;++k)
					Inc(f[i][j+1][0],f[i-1][j][k]);
		}
		if(y<=n)
			for(int j=0;j<=m+1;++j)
				for(int k=0;k<=n;++k)
					Inc(f[i][0][k+1],f[i-1][j][k]);
		if(x>=1&&y<=n)
			for(int j=0;j<=m+1;++j)
				for(int k=0;k<=n;++k)
					Inc(f[i][max(j+1,k+2)][k+1],f[i-1][j][k]);
	}
	int ans=0;
	for(int j=0;j<=m+1;++j)
		for(int k=0;k<=n;++k)
			Inc(ans,f[(n+m)/2][j][k]);
	printf("%d\n",ans);
}
void solve2(){
	static int f[N];
	f[0]=1;
	for(int i=1;i<=(n+1)/2;++i)
		for(int j=max(i-m/2-1,0);j<i;++j)
			Inc(f[i],f[j]);
	int s1=0,s2=0;
	for(int i=max((n+1)/2-m/2,0);i<=(n+1)/2;++i)
		Inc(s1,f[i]);
	for(int i=max(n/2-m/2,0);i<=n/2;++i)
		Inc(s2,f[i]);
	printf("%lld\n",1ll*s1*s2%mod);
}
int main(){
	scanf("%d%d%d",&n,&m,&mod);
	if(m&1)solve1();
	else solve2();
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int64_t factorial(int64_t n) {
  if (n == 1) {
    return 1;
  }
  int64_t ans = factorial(n-1);
  return ans*n;
}
int64_t gcd(int64_t a, int64_t b) {
  if (a < b) {
    int64_t tmp = a;
    a = b;
    b = tmp;
  }
  int64_t r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}

int main() {
  int64_t n, x;
  cin >> n >> x;
  vector <int64_t> v(n);
  rep(i, n) {
    int64_t a;
    cin >> a;
    v.at(i) = abs(x-a);
  }
  int64_t ans = v.at(0);
  rep(i, n) ans = gcd(ans, v.at(i));
  cout << ans << endl;
}

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

int P[200005];

int main() {
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N; ++i) cin >> P[i];

	set<int> S;
	int cnt = 0;
	for (int i = 0; i < K; ++i) {
		S.insert(P[i]);
		if (i) cnt += P[i - 1] < P[i];
	}
	
	int ans = 0;
	bool inorder = cnt == K - 1;
	bool t = cnt != K - 1;
	for (int i = 0; i < N - K; ++i) {
		bool b = P[i] == *S.begin();
		S.erase(P[i]);
		cnt -= P[i] < P[i + 1];
		S.insert(P[i + K]);
		cnt += P[i + K - 1] < P[i + K];
		if (cnt == K - 1) inorder = true;
		b &= P[i + K] == *S.rbegin();
		if (!b && cnt != K - 1) ++ans;
	}

	cout << ans + inorder + t << '\n';
}

Measured memory_bytes: 10368
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int m=s.nextInt();
		int b=s.nextInt();
		if(n+m+b>=22)
		System.out.println("bust");
		else
		System.out.println("win");
	}
}

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

int main() {
  long N, tmp, i, j;
  cin >> N;
  map<long, long> A;
  long B[N];
  for (i = 0; i < N; i++) {
    cin >> tmp;
    B[i] = tmp;
    if (A.count(tmp) == 0) {
      A[tmp] = 1;
    } else {
      A[tmp] += 1;
    }
  }

  long result = 0;
  for (auto i = A.begin(); i != A.end(); ++i) {
    result += ((i->second) * ((i->second) - 1)) / 2;
  }
  //   for (auto i = A.begin(); i != A.end(); ++i) {
  //     for (j = 0; j < i->second; j++) {
  //       cout << max(result - (i->first) - 1, 0) << endl;
  //     }
  //   }
  for (i = 0; i < N; i++) {
    cout << max(result - (A[B[i]] - 1), long(0)) << endl;
  }
}

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

int digit_sum(int x){
  int sum = 0;
  while(x != 0){
    sum += (x%10);
    x /= 10;
  }
  return sum;
}

int main(void){
  int N;
  cin >> N;
  if(N%digit_sum(N) == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


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

using namespace std;

#define pb push_back
#define sz(a) ((int)a.size())
#define mp make_pair
#define fi first
#define se second

const int maxn = 1e5 + 5;

const int maxv = 1e9;

int T, tc;
long long n;
int a[maxn];

int main() {
//	freopen("inp.txt", "r", stdin);
    
   	cin >> n;
   	string ans = "";
   	while (n > 0) {
		long long tmp = (n - 1 + 26) % 26;
		char x = tmp + 'a';
		ans = x + ans;	
		n = (n - 1) / 26;
	}
	
	cout << ans;
    
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		
		Scanner scan = new Scanner(System.in);
		
		String O = scan.next();
		String E = scan.next();
		
		
		char[] o =new char[O.length()];//それぞれ文字の個数分配列を用意
		char[] e =new char[E.length()];
		
		o = O.toCharArray();
		e = E.toCharArray();
		
		
		StringBuffer sb = new StringBuffer(); 
		
		if(O.length()>E.length()){
			for(int i = 0;i<E.length();i++){
				sb.append(o[i]);
				sb.append(e[i]);
			}
			
			sb.append(o[O.length()-1]);
			
			
		}else{//O=E
			
			for(int i = 0;i<O.length();i++){
				sb.append(o[i]);
				sb.append(e[i]);
			}
			
		}
		
		System.out.println(sb.toString());
		
		
	}

}


Measured memory_bytes: 21844
N,M = map(int,input().split())
arr = [list(map(int,input().split()))+[i] for i in range(M)]
arr = sorted(arr)
new_arr = []
former_p = 1
cnt = 0
for p,y,index in arr:
  if p == former_p:
    cnt += 1
  else:
    cnt = 1
  new_arg = [index, str(p).zfill(6) + str(cnt).zfill(6)]
  new_arr.append(new_arg)
  former_p = p
  
new_arr = sorted(new_arr)
for i in new_arr:
  print(i[1])

Measured memory_bytes: 42292
#!/usr/bin/env python3
import numpy as np
from itertools import combinations as comb
h, w, k = map(int, input().split())
a = np.array([list(input()) for _ in [None]*h])
cnt = 0
for j1 in range(h):
    for i1 in comb(range(h), j1):
        for j2 in range(w):
            for i2 in comb(range(w), j2):
                c = np.copy(a)
                c = np.delete(c, list(i1), 0)
                c = np.delete(c, list(i2), 1)
                cnt += np.count_nonzero(c == '#') == k
print(cnt)

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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 1000005;

LL a[MAX];
LL b[MAX];

LL s[MAX];
int main()
{
 //  freopen("in.txt", "r", stdin);
   // ios::sync_with_stdio(false); cin.tie(0);

    int n;
    cin>>n;
    FOR(i,0,n)
    {
    //	a[i]=n-i;
    //	b[i]=1000000000;
    	cin>>a[i]>>b[i];
    }

    LL ans = 0;

    RFOR(i,n,0)
    {
    	a[i] += ans;
    	ans += (b[i]-a[i]%b[i])%b[i];
    }

    cout<<ans;
	return 0;
}


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

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string;
		int n, k, a, b, c;
		boolean judge = false;
		
		while(!(string = reader.readLine()).equals("0 0")){
			n = Integer.valueOf(string.split(" ")[0]);
			k = Integer.valueOf(string.split(" ")[1]);
			
			int map[][] = new int[n][n];
			int mna[][] = new int[n][n];
			for(int i = 0; i < n; i++) Arrays.fill(map[i], 1 << 29);
			for(int i = 0; i < k; i++){
				string = reader.readLine();
				if(string.split(" ")[0].equals("1")){
					if(!judge) judge = true;
					a = Integer.valueOf(string.split(" ")[1]) - 1;
					b = Integer.valueOf(string.split(" ")[2]) - 1;
					c = Integer.valueOf(string.split(" ")[3]);
					map[a][b] = map[b][a] = Math.min(map[a][b], c);
				}else{
					if(judge){
						judge = false;
						for(int q = 0; q < n; q++){
							for(int w = 0; w < n; w++){
								mna[q][w] = map[q][w];
							}
						}
						for(int q = 0; q < n; q++){
							for(int w = 0; w < n; w++){
								for(int e = 0; e < n; e++){
									mna[w][e] = Math.min(mna[w][e], mna[w][q] + mna[q][e]);
								}
							}
						}
					}
					a = Integer.valueOf(string.split(" ")[1]) - 1;
					b = Integer.valueOf(string.split(" ")[2]) - 1;
					if(mna[a][b] == 1 << 29){
						System.out.println(-1);
					}else{
						System.out.println(mna[a][b]);
					}
				}
			}
		}
		reader.close();
	}
}

Measured memory_bytes: 39132
// B - たてなが / Thin
#include <bits/stdc++.h>
using namespace std;

int main(){
	int H,W; cin>>H>>W;
	vector<string> C(H);
	for(int i=0; i<H; ++i) cin>>C[i];
	for(auto e:C) cout<<e<<endl<<e<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int m, n; cin >> n >> m;
	int a, ans = 0;
	for (int i = 0; i < n; ++i) {
		int cnt = 0;
		for (int j = 0; j < m; ++j) {
			cin >> a;
			if (a) cnt++;
		}
		if (ans < cnt) ans = cnt;
	}
	cout << ans << endl;

	return 0;
}



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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if ( A + B > C + D)
    cout << "Left" << endl;
  else if ( A + B < C + D)
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
}

Measured memory_bytes: 256
n=int(input())
count=0
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr
  
for i in make_divisors(n):
  if int(n)!=n or n==1:
    break
  if n%i==0 and len(factorization(i))==1:
    n=n/i
    count+=1
if count-1>=0:
  print(count-1)
else:
  print(0)
  

Measured memory_bytes: 9508
n = int(input())
ab = set(tuple(map(int, input().split())) for _ in range(n))
cd = sorted(tuple(map(int, input().split())) for _ in range(n))

ab |= {(-1, -1)}
for c, d in cd:
    tmp = max((b, a) for a, b in ab if (a < c and b < d))
    if tmp != (-1, -1):
        ab.remove(tmp[::-1])
print(n - (len(ab) - 1))


Measured memory_bytes: 66568
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

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

#define INF INT_MAX / 2 - 1
#define PI 2*acos(0.0)
#define ll long long

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

int main() {
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
// #define mod 998244353
using namespace std;

int p[200001], q[200001], c[200001], dp[100001];
map<int, vector<int>> vert[100001];
set<int> companies[100001];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 2; i <= n; i++)
	{
		dp[i] = 1000000000;
	}
	for (int i = 1; i <= m; i++)
	{
		cin >> p[i] >> q[i] >> c[i];
		companies[p[i]].insert(c[i]);
		companies[q[i]].insert(c[i]);
		if (vert[p[i]].find(c[i]) == vert[p[i]].end())
		{
			vector<int> temp;
			vert[p[i]][c[i]] = temp;
		}
		vert[p[i]][c[i]].pb(q[i]);
		if (vert[q[i]].find(c[i]) == vert[q[i]].end())
		{
			vector<int> temp;
			vert[q[i]][c[i]] = temp;
		}
		vert[q[i]][c[i]].pb(p[i]);
	}
	queue<int> q1;
	q1.push(1);
	while (!q1.empty())
	{
		int start = q1.front();
		q1.pop();
		int dist = dp[start] + 1;
		for (int comp : companies[start])
		{
			// cout << comp << " ";
			queue<int> q;
			q.push(start);
			while (!q.empty())
			{
				int cur = q.front();
				q.pop();
				if (cur != start)
				{
					q1.push(cur);
				}
				for (int v : vert[cur][comp])
				{
					// cout << v << " ";
					if (dp[v] >= dist)
					{
						dp[v] = dist;
						q.push(v);
					}
				}
				vert[cur].erase(comp);
			}
			// cout << endl;
		}
		companies[start].clear();
	}
	// for (int i = 1; i <= n; i++)
	// {
	// 	cout << dp[i] << " ";
	// }
	// cout << endl;
	if (dp[n] == 1000000000)
	{
		cout << -1 << endl;
	}
	else
	{
		cout << dp[n] << endl;
	}
	return 0;
}

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

int main() {
    int n;
    int f[100][10], p[100][11];
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) cin >> f[i][j];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= 10; j++) cin >> p[i][j];
    }

    int ans = -1000000000;
    for (int i = 1; i < 1024; i++) {
        int tmp = 0;
        for (int j = 0; j < n; j++) {
            int count = 0;
            for (int k = 0; k < 10; k++) {
                if ((i & (1 << k)) && f[j][k] == 1) count++;
            }
            tmp += p[j][count];
        }
        if (tmp > ans) ans = tmp;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3652
# -*- coding: utf-8 -*-
import copy

N=input()
S=raw_input()

center_kouho=set()

for i,x in enumerate(S):
    if i==0 or i==N-1: continue
    center_kouho.add(x)

left=[ set() for _ in range(N) ]
right=[ set() for _ in range(N) ]
for i in range(N):
    if i==0:
        continue
    else:
        left[i]=copy.deepcopy(left[i-1])
        left[i].add(S[i-1])

for i in range(N-1,-1,-1):
    if i==N-1:
        continue
    else:
        right[i]=copy.deepcopy(right[i+1])
        right[i].add(S[i+1])

ans=0

for center in center_kouho:
    kazoeage=set()
    for i,x in enumerate(S):
        if x==center:
            for l in left[i]:
                for r in right[i]:
                    kazoeage.add(l+center+r)
    ans+=len(kazoeage)

print ans

Measured memory_bytes: 60828
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

int main(){
	ll N, x; cin >> N >> x;
	ll a[N];
	for(int i=0; i<N; i++) cin >> a[i];
	ll min_cost[N][N];
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			if(i==0) min_cost[j][i] = a[j];
			else{
				if(min_cost[j][i-1] > a[(j+N-i)%N]) min_cost[j][i] = a[(j+N-i)%N];
				else min_cost[j][i] = min_cost[j][i-1];
			}
		}
	}
	ll ans = 1e18;
	for(int i=0; i<N; i++){
		ll cnt = x*i;
		for(int j=0; j<N; j++){
			cnt += min_cost[j][i];
		}
		if(ans > cnt) ans = cnt;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
#define ff first
#define ss second
#define pb push_back
#define quicker ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
 
ll n, k;

int main()
{
    quicker
    cin >> n >> k;   
    vector<int> A(n + 1), tr, tot;
    vector<bool> visited(n + 1, false);
    for (int i = 1; i <= n; i++) cin >> A[i];
    int i = 1;
    //visited[1] = true;
    ll cylen = 0, tlen = 0;
    while(!visited[i]){
      visited[i] = true;
      tot.pb(i);
      ++tlen;
      i = A[i];
    }
    for (int j = 0; j <= n; j++) visited[j] = false;
    while(!visited[i])
    {
      visited[i] = true;
      tr.pb(i);
      ++cylen;
      i = A[i];
    }
    if (k <= (tlen - cylen)){
      cout << tot[k];
      return 0;
    }
    k -= (tlen - cylen);
    k %= cylen;
    cout << tr[k];
    return 0;
}


Measured memory_bytes: 6304
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n,x=map(int,input().split())
    a=sorted(map(int,input().split()))
    cnt = 0
    suma = sum(a)
    if suma < x:
        print(n-1)
    elif suma == x:
        print(n)
    else:
        for i in a:
            if x < i:
                break
            cnt+=1
            x-= i
        print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <stdio.h>

int main()
{
  int b, f, r, v, n, i;
  int a[5][4][11] = {};
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%d%d%d%d", &b, &f, &r, &v);
    a[b][f][r] = v + a[b][f][r];
  }
  for(b = 1; b < 5; b++) {
    for(f = 1; f < 4; f++) {
      for(r = 1; r < 11; r++) {
        printf("%2d", a[b][f][r]);
      }
      printf("\n");
    }
    if(b < 4) {
      printf("####################\n");
    }
  }
 return 0;
}

Measured memory_bytes: 620
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=[]
ans2=[]
for i in range(x):
  for j in range(y):
    ans.append(a[i]+b[j])
if len(ans)>=k:
  ans.sort()
  ans.reverse()
  ans=ans[:k]
for i in range(len(ans)):
  for j in range(z):
    ans2.append(ans[i]+c[j])
ans2.sort()
ans2.reverse()
for i in range(k):
  print(ans2[i])

Measured memory_bytes: 147776
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_B() {}


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, A, B; cin >> N >> A >> B;

    int ans = 0;

    FOR(i,1,N+1) {
        int num = i;
        int dSum = 0;
        while (num > 0){
            dSum += num % 10;
            num /= 10;
        }

        if (A <= dSum && dSum <= B) ans += i;
    }

    cout << ans << endl;  

    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
l=list(map(int,input().split()))
x=sum(l)
def f(m,k,l):
    l=[i%m for i in l]
    l.sort()
    if sum(l[:n-sum(l)//m])<=k:
        return True
ans=1
for i in range(1,int(x**0.5)+1):
    if x%i:
        continue
    if f(x//i,k,l):
        print(x//i)
        break
    elif f(i,k,l):
        ans=i
else:
    print(ans)

Measured memory_bytes: 41564
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

bool detect(string s, char target){
  bool flag = false;
  rep(i, s.size()){
    if (s[i] != target){
      flag = true;
      break;
    }
  }
  return flag;
}

int main(){
  string s; cin >> s;
  map <char, int> mojisuu;
  rep(i, s.size()){
    mojisuu[s[i]]++;
  }
  char target;
  int ans = 500;
  string alphabet = "abcdefghijklmnopqrstuvwxyz";
  rep(alpha, 26){
    target = alphabet[alpha];
    int ans_temp = 0;
    string s_temp = s;
  	while (detect(s_temp, target) && s_temp.size() > 1){
      ans_temp++;
      string s_next;
      rep(i, s_temp.size()-1){
        if (s_temp[i] == target || s_temp[i+1] == target) s_next.push_back(target);
        else s_next.push_back(s_temp[i]);
      }
      swap(s_temp, s_next);
    }
    ans = min(ans, ans_temp);
  }
  cout << ans << endl;
}  

Measured memory_bytes: 3600
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n, m; cin >> n >> m;
  int k[n];
  int cnt[m] = {};

  //  int a[n];

  rep(i, n){
    int k; cin >> k;
    rep(j, k) {
      int a; cin >> a; --a; ++cnt[a];
    }
  }

  int ans = 0;

  rep(i, m){
    if (cnt[i] == n) ++ans;
  }

  print(ans);
  
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)

	h, _ := strconv.Atoi(s[:2])
	t, _ := strconv.Atoi(s[2:])

	if 1 <= h && h <= 12 && 1 <= t && t <= 12 {
		fmt.Println("AMBIGUOUS")
	} else if 1 <= h && h <= 12 && (t == 0 || (13 <= t && t <= 99)) {
		fmt.Println("MMYY")
	} else if (h == 0 || (13 <= h && h <= 99)) && 1 <= t && t <= 12 {
		fmt.Println("YYMM")
	} else {
		fmt.Println("NA")
	}

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fir first
#define sec second
#define pb 	push_back
#define ll  long long
#define mp make_pair
#define all(x) (x).begin(),(x).end()
using namespace std;

int main() {
	ll n;cin>>n;
	ll ans=0;
	map<ll,int>mp;
	for(ll i=1;i<=n;i++){
		ll x;cin>>x;
		ans+=mp[i-x];
		if(i+x<n) mp[i+x]++;
		//i-j=a[i]+a[j];
	}
	cout<<ans<<endl;
}

// 1  ....... 1


Measured memory_bytes: 17320
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    vector<int> zxy(n);
    vector<array<int, 4>> ant(n);
    for (int i = 0; i < n; ++i) {
        int x, y; char c;
        cin >> x >> y >> c;
        zxy.emplace_back(x+y);
        ant[i] = {x, y, c == 'S', i};
    }
    vector<int> ans(n);
    sort(zxy.begin(), zxy.end());
    zxy.erase(unique(zxy.begin(), zxy.end()), zxy.end());
    vector<vector<array<int, 4>>> ants(zxy.size());
    for (int i = 0; i < n; ++i) {
        int x = lower_bound(zxy.begin(),zxy.end(), ant[i][0]+ant[i][1]) - zxy.begin();
        ants[x].emplace_back(ant[i]);
    }
    for (int i = 0; i < zxy.size(); ++i) {
        int c = zxy[i]&1;
        sort(ants[i].begin(),ants[i].end());
        vector<queue<int>> a(2);
        for (auto &&e : ants[i]) {
            if(e[2]){
                int k = (e[1]&1)^c;
                a[k].emplace(e[3]);
                int tmp = a[k].front(); a[k].pop();
                ans[tmp] = h-e[1];
            }else {
                a[e[1]&1].emplace(e[3]);
            }
        }
        for (auto &&e : ants[i]) {
            if(!e[2]){
                int k = (e[1]&1);
                a[k].emplace(e[3]);
                int tmp = a[k].front(); a[k].pop();
                ans[tmp] = w-e[0];
            }
        }
    }
    vector<int> perm(n);
    iota(perm.begin(),perm.end(), 0);
    sort(perm.begin(),perm.end(), [&](int x, int y){
        if(ans[x] != ans[y]) return ans[x] < ans[y];
        else return x < y;
    });
    for (auto &&j : perm) {
        printf("%d\n", j+1);
    }
    return 0;
}


Measured memory_bytes: 20052
n=float(input())

w=int(n**(1/2))
n=int(n)
a=int(w)
b=int(w)
while True:

    if n%w==0:
        a=w
        b=n/w
        break
    w -=1

ans=int((a-1)+(b-1))
print(ans)


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

#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)

using namespace std;
typedef long long ll;

struct city {
  int num;
  int p;
  int y;
};

int main(){
  int n,m;
  cin >> n >> m;
  vector<city> c(m);
  for(int i=0;i<m;i++){
    c[i].num=i;
    cin >> c[i].p >> c[i].y;
  }

  sort(c.begin(), c.end(),
       [](auto const& lhs, auto const& rhs) {
	 return lhs.y < rhs.y;
       });
  /*
  for(auto ci:c){
    cout << "#" << ci.num << " " << ci.p << " " << ci.y << endl;
  }
  */
  
  vector<int> prefs(n+1,0);
  for(auto &ci:c){
    prefs[ci.p]++;
    ci.y=prefs[ci.p];
  }

  sort(c.begin(), c.end(),
       [](auto const& lhs, auto const& rhs) {
	 return lhs.num < rhs.num;
       });

  for(auto ci:c){
    cout << setfill('0') << right << setw(6) << ci.p;
    cout << setfill('0') << right << setw(6) << ci.y;
    cout << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3072
import math

N, H = map(int, input().strip().split(" "))
al = []
bl = []
for i in range(N):
    a, b = map(int, input().strip().split(" "))
    al.append(a)
    bl.append(b)

a_max = max(al)
sorted_bl = sorted(filter(lambda b: b > a_max, bl))[::-1]

attacks = 0
for b in sorted_bl:
    H -= b
    attacks += 1
    if H <= 0:
        break

a_attacks = 0
if H <= 0:
    a_attacks = 0
else:
    a_attacks = math.ceil(H / a_max)

print(attacks + a_attacks)

Measured memory_bytes: 12536
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;

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

	vector <vector <int> > s(M);

	for (int i = 0; i < M; ++i)
	{
		int ko;
		cin >> ko;
		for (int k = 0; k < ko; ++k)
		{
			int tmp;
			cin >> tmp;
			tmp--;
			s[i].push_back(tmp);
		}
	}

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


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

		// 電球
		bool ok = true;
		for (int k = 0; k < M; ++k)
		{
			int num = 0;
			for(int x : s[k] )
			{
				if (i&(1 << (x)))
				{
					num++;
				}
			}

			if (num % 2 != p[k])
			{
				ok = false;
				break;
			}
		}

		if (ok)
		{
			ret++;
		}
	}

	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
N = gets.chomp.to_i
ab = []
N.times do
    ab << gets.chomp.split(" ").map(&:to_i)
end
ab.sort_by!{|a, b| a}.sort_by!{|a, b| b}
t = 0
ab.each do |a, b|
    if t + a > b
        puts "No"
        exit
    else
        t += a
    end
end
puts "Yes"

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

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

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

string dir;
vector<int> dirs(100005);

int dfs(int cnt, bool isleft, int l, int r){
	if(cnt == dir.length()) return 0;
	if(isleft and dirs[cnt] < l){
		return dfs(cnt+1, true, dirs[cnt], r)+1;
	} else if(!isleft and dirs[cnt] > r) {
		return dfs(cnt+1, false, l, dirs[cnt])+1;
	}
	if(isleft) return dfs(cnt+1, false, l, dirs[cnt]);
	return dfs(cnt+1, true, dirs[cnt], r);
}

int main(){
	while(cin >> dir and dir != "#"){
		dirs.clear();
		REP(i, dir.length()) dirs[i] = (dir[i] - '1')%3;
		int res = INF;
		REP(i, 3) REP(j, 3) { if(i > j) continue; chmin(res, min(dfs(0, true, i, j), dfs(0, false, i, j))); }
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3932
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

long long int memo[2000];
long long int aws[10000];
int N, W;

int getans(const int l) {
	if (memo[l] ==-1) {
		long long int sum = 0;
		long long int ans = 2e9 + 1;
		for (int r = l + 1; r <= N; ++r) {
			sum += aws[r - 1];
			if (r == N)ans = min(ans, max(0ll, sum - W));
			ans = min(ans, getans(r) + abs(sum - W));
		}
		memo[l] = ans;
	}
	return memo[l];
}
int main() {
	int num(0);
	while (1) {
		num++;
		cin >> N >> W;
		for (int i = 0; i < 2000; ++i) {
			memo[i] = -1;
		}
		if (!N)break;
		for (int i = 0; i < N; ++i) {
			cin >> aws[i];
		}
		long long int ans = getans(0);
		cout << "Case "<<num<<": "<<ans << endl;
	}
	return 0;
}

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

int main(){
	int x[3];
	cin >> x[0] >> x[1] >> x[2];
	int i,j,tmp;
	for(i=0;i<3;i++){
		for(j=i+1;j<3;j++){
			if(x[i] > x[j]){
				tmp = x[i];
				x[i]= x[j];
				x[j]= tmp;
			}
		}
	}
	cout << x[0] << ' ' << x[1] << ' ' << x[2] << endl;
	return 0;
}

Measured memory_bytes: 1160