akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int K,T;
vector<int> A;
void input(){
    fast_io();
    cin >> K >> T;
    A = fetch_vec<int>(T);
}

int solve(){
    sort(A.begin(),A.end(),greater<int>());
    int ans = max(0,2*A[0]-K-1);
    cout << ans << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
string en = "abcdefghijklmnopqrstuvwxyz";
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int ans = 1e9;
  bool ok = true;
  FOR(i,0,N) {
    int in; cin >> in;
    int cnt = 0;
    while(in % 2 == 0) {
      in >>= 1;
      cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Your code here!

function main(input) {
    /* split: 指定した区切り文字により, 文字列の配列へ分割する*/
    const args = input.split(' ');
    
    /* stringをintへ変換する*/
    /*(,10)で10進数表記とする*/
    const a = parseInt(args[0],10);
    const b = parseInt(args[1], 10);
    
    if ((a * b) % 2 == 1){
        console.log('Odd');
    }
    else{
        /* outputs a message to the web console*/
        /*web console: HTML や CSS の中身をいじったり確認したりすることができるツール*/
        console.log('Even');
    }
}

/*
readFileSync:ファイルの中身を読む
*/
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

using namespace std;
typedef long long ll;

int idx[200001];

int main(void) {
    int n, p, ans;
    cin >> n;
    for(int i=0; i<n; i++) {
        scanf("%d", &p);
        idx[p] = i;
    }

    int cnt = 0;
    ans = n - 1;
    for(int i=2; i<=n; i++) {
        if(idx[i-1] < idx[i]) cnt++;
        else {
            ans = min(ans, n - 1 - cnt);
            cnt = 0;
        }
    }
    ans = min(ans, n - 1 - cnt);
    
    return !printf("%d\n", ans);
}

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



int main(void){
    
    int a[2],R[3];
    for (int j = 0; j < 2; j++){
        cin >> a[j];
    }
    

    R[0] = a[0] + a[1];
    R[1] = a[0] - a[1];
    R[2] = a[0] * a[1];
    int maxv = R[0];

    for (int i = 1; i < 3; i++){
        maxv = max(maxv, R[i]);
    }

    cout << maxv << endl;
    
    return 0;    
}

Measured memory_bytes: 256
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

functions = {}
for d in D:
	if d in functions:
		functions[d] += 1
	else:
		functions[d] = 1

for function in range(M):
	point = T[function]
	if not point in functions:
		print("NO")
		break
	if 1 == functions[point]:
		del functions[point]
	else:
		functions[point] -= 1
else:
	print("YES")


Measured memory_bytes: 41316
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vvll edge(110, vll(0));
vll d(110, -1), f(110, -1);

void dfs(int n, int &time){
  if(edge.at(n).size() == 0){
    d.at(n) = time;
    time++;
    f.at(n) = time; time++;
    return;
  }
  d.at(n) = time; time++;
  bool flag = true;
  for(int i = 0; i < edge.at(n).size(); i++){
    if(d.at(edge.at(n).at(i)) == -1){
      dfs(edge.at(n).at(i), time);
    }
  }
  f.at(n) = time; time++;
}

int main(){
  int n;
  cin >> n;
  
  for(int i = 0; i < n; i++){
    int u, k;
    cin >> u >> k;
    u--;
    for(int j = 0; j < k; j++){
      ll v;
      cin >> v;
      v--;
      edge.at(u).push_back(v);
    }
  }
  int time = 1;
  for(int i = 0; i < n; i++){
    if(d.at(i) == -1) dfs(i, time);
  }
  
  for(int i = 0; i < n; i++){
    cout << i+1 << ' ' << d.at(i) << ' ' << f.at(i) << endl;
  }

}


Measured memory_bytes: 3176
N,K = list(map(int,input().split()))
def f(n):
    return n*(n-1)*(n-2) + n*(n-1)*3 + n
if K%2:
    n = N//K
    print(f(n))
else:
    n = N//(K//2)
    a = n//2
    b = (n+1)//2
    print(f(a)+f(b))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

int main(void){
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> c(n);
    for (int i = 0; i < n; i++) cin>> c[i];
    
    vector<vector<int> > g(h, vector<int>(w));
    int b = 0;
    for (int i = 0; i < h; i++) {
        if (i%2) {
            for (int j = 0; j < w; j++) {
                if (b < n && !c[b]) b++;
                if (b < n) c[b]--;
                g[i][j] = b+1;
            }
        }
        else {
            for (int j = w-1; j >= 0; j--) {
                if (b < n && !c[b]) b++;
                if (b < n) c[b]--;
                g[i][j] = b+1;
            }
        }
    }
    
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (j) cout << " ";
            cout << g[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char a[20];
long long s[10];
int main()
{
    int n,i,j,k;
    long long ans;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%s",a);
        if(a[0]=='M')
            s[1]++;
        if(a[0]=='A')
            s[2]++;
        if(a[0]=='R')
            s[3]++;
        if(a[0]=='C')
            s[4]++;
        if(a[0]=='H')
            s[5]++;
    }
    ans=0;
    for(i=1;i<=5;i++)
    for(j=i+1;j<=5;j++)
    for(k=j+1;k<=5;k++)
        ans=ans+s[i]*s[j]*s[k];
    printf("%lld\n",ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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;}
const ll INF = 1LL<<60;
const ll M = 1000000007;
ll mpow(ll a,ll b){ll res=1;while(b!=0){if(b&1)res=res*a%M;a=a*a%M;b=b>>1;}return res;}
ll mcomb(ll n,ll k){if(k>n/2)return mcomb(n,n-k);ll res=1;for(ll i=0;i<k;i++){res=res*(n-i)%M;res=res*mpow(k-i,M-2)%M;}return res;}
/*template*/
bool sosu(ll n){
  for(ll i=2;i<=sqrt(n);i++){
    if(n%i==0)return false;
  }
  return true;
}

int main()
{
  ll x;cin>>x;
  ll i=0;
  while(true){
    if(sosu(x+i)){
      cout<<x+i<<endl;
      return 0;
    }
    i++;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
void vout(vl V) {
	for (ll i = 0; i < (ll)V.size(); i++) cout << V[i] << " ";
	cout << endl;
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color,D; vector<vpll> path; vl A; vl dp; vl Ans;
//***********//
int main() {
	cin >> H >> W;
	cin >> N;
	vl A(N);
	for (i = 0; i < N; i++) cin >> A[i];
	vll C(H, vl(W, 0));
	ll now = 0;
	for (i = 0; i < H; i++) {
		if (i % 2 == 0) {
			for (j = 0;j < W; j++) {
				C[i][j] = now + 1;
				A[now]--;
				if (A[now] == 0) {
					now++;
				}
			}
		}
		else {
			for (j = W-1; j >= 0; j--) {
				C[i][j] = now + 1;
				A[now]--;
				if (A[now] == 0) {
					now++;
				}
			}
		}
	}
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			cout << C[i][j] << " ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 512
#include <stdio.h>

#define INF 1000000001
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

int a[1000];

int main(void)
{
	int n, q, i, com, b, c, ans;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	scanf("%d", &q);
	while (q--) {
		scanf("%d%d%d", &com, &b, &c);
		if (com == 0) {
			ans = INF;
			for (i = b; i < c; i++) {
				ans = min(ans, a[i]);
			}
		}
		else {
			ans = -INF;
			for (i = b; i < c; i++) {
				ans = max(ans, a[i]);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define PB push_back
#define ALL(c) c.begin(),c.end()

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) {
    cin >> A[i];
  }
  sort(ALL(A));

  vector<int> v;
  int cnt = 1;
  REP(i, N - 1) {
    if (A[i] != A[i + 1]) {
      v.PB(cnt);
      cnt = 1;
    } else {
      cnt++;
    }
  }
  v.PB(cnt);
  sort(ALL(v));

  cnt = 0;
  REP(i, v.size()) {
    if (v[i] % 2 == 0) cnt++;
  }
  if (cnt % 2 == 1) cout << v.size() - 1 << endl;
  else cout << v.size() << endl;


  return 0;
}

Measured memory_bytes: 1276
#include <algorithm>
#include <utility>
#include <cstdio>
#include <vector>
#define pb push_back
#define MOD 1000000007
typedef long long ll;
std::vector<std::pair<ll, ll> > seq[105];
ll F[105];
int main()
{
	// freopen("AGC015-F.in", "r", stdin);
	F[0] = F[1] = 1;
	int len = 1;
	while (true)
	{
		F[len + 1] = F[len] + F[len - 1];
		if (F[len + 1] > 1e18)
			break;
		len++;
	}
	seq[1].pb({1, 2});
	seq[1].pb({1, 3});
	seq[1].pb({1, 4});
	for (int i = 1; i <= len - 3; i++)
	{
		for (auto it : seq[i])
		{
			ll x = it.first, y = it.second;
			while (x + y <= F[i + 3])
			{
				x += y;
				seq[i + 1].pb({y, x});
			}
		}
	}
	int t; 
	scanf("%d", &t);
	while (t--)
	{
		ll n, m;
		scanf("%lld%lld", &n, &m);
		if (n > m)
			std::swap(n, m);
		int ans = 1;
		while (F[ans + 1] <= n && F[ans + 2] <= m)
			ans++;
		printf("%d ", ans);
		if (ans == 1)
			printf("%lld\n", n * m % MOD);
		else
		{
			ll cnt = 0;
			for (auto it : seq[ans - 1])
			{
				ll x = it.first, y = it.second;
				if (y <= n)
					(cnt += (m - x) / y) %= MOD;
				if (y <= m)
					(cnt += (n - x) / y) %= MOD;
			}
			printf("%lld\n", cnt);
		}
	}
	return 0;
}


Measured memory_bytes: 4096
#include <stdio.h>
#include <math.h>

int main(void) {
    int n, i, d = 100000;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        d += ceil((double)d * 0.05 / 1000) * 1000;
    }

    printf("%d\n", d);

    return 0;
}

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

using namespace std;

int main(){

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

    vector<int> a(N), b(N), strong;
    int amax=0;
    int ans=0;

    for(int i=0; i<N; i++){
        cin >> a[i] >> b[i];
        amax = max(amax,a[i]);
    }

    for(int i=0; i<N; i++)
        if(amax < b[i])
            strong.push_back(b[i]);

    sort(strong.begin(),strong.end());
    reverse(strong.begin(),strong.end());

    for(int i=0;i<strong.size();i++){
        ans++;
        H -= strong[i];
        if(H <= 0){
            cout << ans << endl;
            return 0;
        }
    }
    ans += (H + amax - 1) / amax;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;

struct st {int r, c;};
int h, w, cnt, ans, v[1005][1005];
char a[1005][1005];
queue<st> qu;


void push(int p, int q, int r) {
	if(p>=0 && p<h && q>=0 && q<w && v[p][q]==-1) {
		qu.push({p, q});
		v[p][q] = r;
	}
}

int main() {
	int i, j;
	memset(v, -1, sizeof(v));
	cin >> h >> w;
	for(i=0; i<h; i++) {
		scanf("%s", a[i]);
		for(j=0; j<w; j++) {
			if(a[i][j]=='#')
				push(i, j, 0);
		}
	}
	while(!qu.empty()) {
		st t = qu.front(); qu.pop();
		cnt++;
		if(cnt == w*h) {
			cout << v[t.r][t.c];
			break;
		}
		push(t.r-1, t.c, v[t.r][t.c]+1);
		push(t.r+1, t.c, v[t.r][t.c]+1);
		push(t.r, t.c-1, v[t.r][t.c]+1);
		push(t.r, t.c+1, v[t.r][t.c]+1);
	}
//	for(i=0; i<h; i++, puts("")) for(j=0; j<w; j++) printf("%d", v[i][j]);
	return 0;
}

Measured memory_bytes: 13328
S = input()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

if A + B + C + D == 7:
    print(f"{A}+{B}+{C}+{D}=7")
elif A - B + C + D == 7:
    print(f"{A}-{B}+{C}+{D}=7")
elif A + B - C + D == 7:
    print(f"{A}+{B}-{C}+{D}=7")
elif A + B + C - D == 7:
    print(f"{A}+{B}+{C}-{D}=7")
elif A - B - C + D == 7:
    print(f"{A}-{B}-{C}+{D}=7")
elif A - B + C - D == 7:
    print(f"{A}-{B}+{C}-{D}=7")
elif A + B - C - D == 7:
    print(f"{A}+{B}-{C}-{D}=7")
elif A - B - C - D == 7:
    print(f"{A}-{B}-{C}-{D}=7")


Measured memory_bytes: 9220
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
char a[300005];
int s[300005];
int t[300005];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf(" %c",&a[i]);
		if(a[i-1]=='W') s[i]=s[i-1]+1;
		else s[i]=s[i-1];
	}
	for(int i=n;i>0;i--)
	{
		if(a[i+1]=='E') t[i]=t[i+1]+1;
		else t[i]=t[i+1];
	}
	int minn=2e9;
	for(int i=1;i<=n;i++)
	{
		if(s[i]+t[i]<minn) minn=s[i]+t[i];
	}
//	for(int i=1;i<=n;i++)
//	{
//		printf("%d ",s[i]);
//	}
//	printf("\n");
//	for(int i=1;i<=n;i++)
//	{
//		printf("%d ",t[i]);
//	}
//	printf("\n");
	printf("%d",minn);
}

Measured memory_bytes: 2816
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    int64_t x;
    mint(int64_t x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(int64_t t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    //for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    int n;
    vs s(2);
    cin >> n >> s[0] >> s[1];

    mint ans = 1;
    rep(i, n) {
        if(!i) {
            if(s[0][0] == s[1][0]) {
                ans *= 3;
            } else {
                ans *= 6;
                ++i;
            }
        } else {
            if(s[0][i] == s[1][i]) {
                if(s[0][i-1] == s[1][i-1]) ans *= 2;
            } else {
                if(s[0][i-1] == s[1][i-1]) ans *= 2;
                else ans *= 3;
                ++i;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<map>
#include<algorithm>
#include<random>
#include<string>
#include<queue>
#include<math.h>

using namespace std;

#define int long long
#define double long double

template<typename T>
T get() {
	T a; cin >> a; return a;
}

template<typename T>
void prv(vector<T> const& vec, string space) {
	for (auto const& e : vec) {
		cout << e << space;
	}
	cout << endl;
}

template<typename T>
void prvv(vector<vector<T>> const& vec, string space, string line) {
	for (auto const& list : vec) {
		for (auto const& e : list) {
			cout << e << space;
		}
		cout << line;
	}
}

#define loop(x, n, m) for(int x = n; x < m; x++)
#define aloop(x, n, m) for(int x = m - 1; x >= n; x--)
#define dloop(x, n, m, t) for(int x = n; x < m; x+=t)
#define read(str) cin >> str
#define deb(str) cout << str << " "
#define det(str) cout << str
#define dbl(str) cout << str << "\n"
#define spc << " " <<
#define tab << "\t" <<
#define tb << "\t"
#define tabw cout << "\t"
#define el cout << "\n"
#define gi() get<int>()
#define gs() get<string>()
#define gf() get<float>()
#define wait() int a; cin >> a;
#define priv(vec) prv<int>(vec, " ")
#define prsv(vec) prv<string>(vec, " ")
#define privv(vec) prvv<int>(vec, " ", "\t")
#define prsvv(vec) prvv<string>(vec, " ", "\t")
#define prtv(T, vec, space) prv<T>(vec, space)
#define prtvv(T, vec, space, line) prvv<T>(vec, space, line)
#define vec vector

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int LEN = gi(), count_r = 0, count_b = 0;
	string hats = gs();

	for (auto const& e : hats) {
		if (e == 'R') {
			count_r++;
		}
		else {
			count_b++;
		}
	}

	dbl(((count_r > count_b) ? "Yes" : "No"));

	wait();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define R(i,a,n) for(int i=a;i<=n;i++)
int a[11][11],w,h;
int chp(int y1,int y2,int x1,int x2){
  int res=0,ans=0,t=1e9;
  R(i,y1,y2)R(j,x1,x2)res=max(res,a[i][j]);
  R(i,y1-1,y2+1)R(j,x1-1,x2+1)
    if(i==y1-1||i==y2+1||j==x1-1||j==x2+1){
      if(a[i][j]<=res)return 0;
      t=min(t,a[i][j]);
    }
  R(i,y1,y2)R(j,x1,x2)ans+=t-a[i][j];
  return ans;
}
int ch(int y,int x){
  int ans=0;
  R(i,y,h-2)R(j,x,w-2)ans=max(ans,chp(y,i,x,j));
  return ans;
}
main(){
  while(cin>>h>>w,h){
    int ans=0;
    r(i,h)r(j,w)cin>>a[i][j];
    r(i,h-1)r(j,w-1)if(i&&j)ans=max(ans,ch(i,j));
    cout<<ans<<endl;
  }
}

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

int main(){
	double x1,x2,y1,y2,X,Y,ans;
	cin >> x1 >> y1 >> x2 >> y2;
	X=pow(x1-x2,2);
    Y=pow(y1-y2,2);

	ans = sqrt(X+Y);

	printf("%f\n",ans);

	return 0;
}

Measured memory_bytes: 3284
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int[] a = new int[3];
        for (int i = 0 ; i < 3 ; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        System.out.println(a[1] - a[0] + a[2] - a[1]);
    }

}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  vector<ll> x(5);
  rep(i,5){
    cin >> x.at(i);
    if(x.at(i)==0){
      cout << i+1 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3592
import java.io.*;
import java.util.*;

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

	public static void solve(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m];
		int[] b = new int[m];
		for(int i=0;i<m;i++){
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		int[] center1 = new int[n+1];
		int[] centern = new int[n+1];

		for(int i=0;i<m;i++){
			if(a[i]==1){
				center1[b[i]]++;
			}
			if(a[i]==n){
				centern[b[i]]++;
			}
			if(b[i]==1){
				center1[a[i]]++;
			}
			if(b[i]==n){
				centern[a[i]]++;
			}
		}

		boolean flag = false;
		for(int i=0;i<=n;i++){
			if(center1[i]!=0 && centern[i]!=0){
				flag = true;
			}
		}

		if(flag){
			System.out.println("POSSIBLE");
		}
		else{
			System.out.println("IMPOSSIBLE");
		}
	}	
}


Measured memory_bytes: 96172
import math

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

D1 = 0
D2t = 0
D3t = 0
Di = []

for i in range(n):
    D1 += abs(x[i] - y[i])
    D2t += abs(x[i] - y[i]) ** 2
    D3t += abs(x[i] - y[i]) ** 3
    Di.append(abs(x[i] - y[i]))

print("{:f}".format(D1))
print("{:f}".format(math.sqrt(D2t)))
print("{:f}".format(D3t ** (1/3)))
print("{:f}".format(max(Di)))



Measured memory_bytes: 5696
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std ;

int main(void){
    int a[12] = {0,2,0,1,0,1,0,0,1,0,1,0};
    int x,y;

    cin >> x >> y;

    if(a[x-1]==a[y-1]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import deque

n = int(input())
an = list(map(int, input().split(' ')))

d = deque()

for i in range(n):
    if i % 2 == 0:
        d.append(an[i])
    else:
        d.appendleft(an[i])

if n % 2 == 1:
    d.reverse()
    
result = list(map(str, d))
print(' '.join(result))


Measured memory_bytes: 118620
/*
 * Name        : b
 * Creat       : Fri Jul 12 17:52:09 CST 2019
 * Accept      : Fri Jul 12 17:57:36 CST 2019
 * Author      : landcold7
 * Motivation  : Action speaks louder more than words
 */
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int n, l;
  cin >> n >> l;
  vector<int> a(n + 1);
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    a[i] = l + i - 1;
    sum += a[i];
  }
  trace(a);
  int mi = (1 << 30);
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    int d = abs(sum - a[i] - sum);
    if (d < mi) {
      mi = d;
      ans = sum - a[i];
    }
  }
  cout << ans << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 256
#-*-coding:utf-8-*-

def main():
    number_list=[]
    while True:
        x,y=map(int,input().split())
        if x==0 and y==0:
            break
        else:
            number_list.append([x,y])
    for number in number_list:
        if number[0]<number[1]:
            print("{} {}".format(number[0],number[1]))
        else:
            print("{} {}".format(number[1],number[0]))

if __name__=="__main__":
    main()


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

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

  int a[100010] = {};

  for(int i = 0; i < n; i++){
    int tmp;
    cin >> tmp;
    a[tmp]++;
  }
  int ans = -1;
  for(int i = 1; i < 100010; i++){
    int sum = a[i - 1] + a[i] + a[i + 1];
    ans = max(sum, ans);
  }
  cout << ans << endl;

}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var r = input[0];
            var D = input[1];
            var x2k = input[2];
            for (int i = 0; i < 10; i++)
            {
                x2k = x2k * r - D;
                Console.WriteLine(x2k);
            }

            Console.WriteLine();
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13268
N = int(input())
S = {}
for i in range(1,N+1):
    i = str(i)
    s = (i[0],i[-1])
    if s in S:
        S[s] += 1
    else:
        S[s] = 1
#print(S)
c = 0
for i in range(1,N+1):
    i = str(i)
    s = (i[-1],i[0])
    if s in S:
        c += S[s]
print(c)

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

int main() {
  int a, b, c, d;
  int d0, d1, d2;
  cin >> a >> b >> c >>d;

  if ((a-c)<0)
    d0 = -(a-c);
  else
    d0 = a-c;
  
  if ((a-b)<0)
    d1 = -(a-b);
  else
    d1 = a-b;
  
  if ((b-c)<0)
    d2 = -(b-c);
  else
    d2 = b-c;
  
  if (d0<=d)
    cout << "Yes" << endl;
  
  else if ((d1<=d) && (d2<=d))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX_N 1000
using namespace std;

int main(void) {
  //ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<vector<int>> A(N, vector<int>(N - 1));
  queue<int> que;
  rep(i, N) {
    rep(j, N - 1) {
      cin >> A[i][j];
      A[i][j]--;
    }
    reverse(A[i].begin(), A[i].end());
    que.push(i);
  }
  que.push(-1);

  int Ans = N * (N - 1) / 2;
  vector<bool> seen(N + 1);
  int Num = 0;
  while (!que.empty()) {
    auto M = que.front();
    que.pop();
    if (M == -1) {
      if (Num == 0) {
        Ans = -1;
        break;
      }
      Ans -= (Num - 1);
      if (que.size() == 0) break;
      seen.assign(N + 1, false);
      Num = 0;
      que.push(-1);
      continue;
    }
    if (seen[M]) continue;
    int X = A[M].back();
    if (seen[X]) continue;
    int Y = A[X].back();
    if (Y == M) {
      seen[M] = true;
      seen[X] = true;
      A[M].pop_back();
      if (A[M].size() != 0) que.push(M);
      A[X].pop_back();
      if (A[X].size() != 0) que.push(X);
      Num++;
    }
  }
  cout << Ans << endl;
  return 0;
}


Measured memory_bytes: 4224
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, k;
    int[] s;
    int[][] b;
    int i, j;

    for(;;){
      n = sc.nextInt();
      k = sc.nextInt();
      if(n == 0 && k == 0)break;
      s = new int[k];
      b = new int[n][k];

      for(i = 0;i < k;i++)s[i] = sc.nextInt();
      for(i = 0;i < n;i++)for(j = 0;j < k;j++)b[i][j] = sc.nextInt();

      for(i = 1;i < n;i++)for(j = 0;j < k;j++)b[0][j] += b[i][j];

      for(i = 0;i < k;i++)if(s[i] < b[0][i])break;
      if(i < k)System.out.println("No");
      else System.out.println("Yes");

    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 97136
def main():
  #n = int(input())
  s = input()
  #s = input().split()
  #a,b = list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 0
  lis = []
  
  if s == "1":
    print("Hello World")
  elif s == "2":
    a = int(input())
    b = int(input())
    print(a+b)

if __name__ == '__main__':
  main()

Measured memory_bytes: 2940
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <numeric>
#include <cassert>

using namespace std;

class arcD {
private:
    int N;
    bool dfs(int u, const vector<vector<int>>& g, vector<int>& vis, vector<int>& path) {
        vis[u] = 1;
        if (u == N - 1) {
            path.push_back(u);
            return true;
        }
        for (int v : g[u]) {
            if (!vis[v]) {
                if (dfs(v, g, vis, path)) {
                    path.push_back(u);
                    return true;
                }
            }
        }
        return false;
    }
    int dfs2(int u, const vector<vector<int>>& g, vector<int>& vis, vector<int>& color, int col) {
        vis[u] = 1;
        color[u] = col;
        int res = 1;
        for (int v : g[u]) {
            if (!vis[v]) {
                if (color[v] == 0 || color[v] == col) {
                    res += dfs2(v, g, vis, color, col);
                }
            }
        }
        return res;
    }
public:
    void solve(istream& in, ostream& out) {
        in >> N;
        vector<vector<int>> g(N);
        for (int i = 0; i < N - 1; ++i) {
            int a, b;
            in >> a >> b;
            g[a - 1].push_back(b - 1);
            g[b - 1].push_back(a - 1);
        }
        vector<int> vis(N, 0), path;
        assert(dfs(0, g, vis, path));
        assert(path[0] == N - 1);
        assert(path.back() == 0);
        path.pop_back();
        path.erase(path.begin());
        int cnt = path.size();
        assert(cnt >= 0);
        vector<int> color(N, 0);
        color[0] = 1;
        color[N - 1] = 2;
        for (int i = 0; i < cnt / 2; ++i) {
            color[path[i]] = 2; //black
        }
        for (int i = cnt / 2; i < cnt; ++i) {
            color[path[i]] = 1; //white
        }
        
        vis.assign(N, 0);
        int cnt1 = dfs2(0, g, vis, color, 1);
        vis.assign(N, 0);
        int cnt2 = dfs2(N - 1, g, vis, color, 2);
        
        if (cnt1 > cnt2) {
            out << "Fennec\n";
        } else {
            out << "Snuke\n";
        }
    }
};


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

	arcD solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

long long mod(long long a){
    if(a<0)return -a;
    else return a;
}
int main()
{
    long long n,k,t,d;
    cin>>n>>k;

    t=n%k;
    d=mod(k-t);
    cout<<min(t,d);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
#define priority_queue __gnu_pbds::priority_queue
typedef long long LL;
typedef long double LD;
typedef unsigned int ui;
typedef unsigned long long ul;
#define ri register int
#define pb push_back
#define fi first
#define se second
#define mid ((l + r) >> 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
#define enum(i, j, k) for(int i = j; i <= k; i ++)
#define FO(x) { freopen(#x".in", "r", stdin); freopen(#x".out", "w", stdout); }
using namespace std;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef vector<int> vi;
#define ae(x) for(node *p = h[x]; p; p = p->nxt)
#define G \
	struct node { int v; node *nxt; } e[maxm], *h[maxn]; int z;\
	void adde(int u, int v) { e[++z].v = v; e[z].nxt = h[u]; h[u] = &e[z]; }\
	void addrev(int u, int v) { adde(u, v); adde(v, u); }
#define W \
	struct node { int v, w; node *nxt; } e[maxm], *h[maxn]; int z;\
	void adde(int u, int v, int w) { e[++z].v = v; e[z].w = w; e[z].nxt = h[u]; h[u] = &e[z]; }\
	void addrev(int u, int v, int w) { adde(u, v, w); adde(v, u, w); }
inline int _() // ret >= 0
{
	int ret = 0; char ch = getchar();
	while(ch < '0' || ch > '9') ch = getchar();
	do { ret = ret * 10 + ch - '0'; ch = getchar(); } while('0' <= ch && ch <= '9');
	return ret;
}
inline void _(int x) // x >= 0
{
	if(x < 10) { putchar(x + '0'); return ; }
	_(x / 10); putchar(x % 10 + '0');
}
void What_are_you_doing_at_the_end_of_the_world_Are_you_busy_Can_you_save_us()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(16);
}
/* Default Code Ends Here. */

#define maxn 200100

int n;
int a[maxn];

map<int, int> mp;
void ins(int x)
{
	if(mp.count(x))
		mp[x] ++;
	else
		mp[x] = 1;
}
int query(int x)
{
	return mp.count(x) ? mp[x] : 0;
}
bool check(int x)
{
	mp.clear();
	enum(i, 1, n)
	{
		int d = a[i];
		if(d > a[i - 1])
			continue;
		auto it = mp.upper_bound(d);
		while(it != mp.end())
		{
			mp.erase(it);
			it = mp.upper_bound(d);
		}
		while(query(d) == x - 1)
		{
			if(d == 1)
				return false;
			mp.erase(d);
			d --;
		}
		ins(d);
	}
	return true;
}

int main()
{
//	FO(1);
	n = _();
	enum(i, 1, n)
		a[i] = _();
	int l = 1, r = n;
	while(l != r)
	{
		if(check(mid))
			r = mid;
		else
			l = mid + 1;
	}
	_(l);
//	cerr << LD(clock()) / CLOCKS_PER_SEC << endl;
	return 0;
}


Measured memory_bytes: 1024
import numpy as np

n, k = map(int, input().split())
l = np.array(list(map(int, input().split())))

dp = np.zeros(n, dtype = int)
for i in range(1, n):
  start_index = max(i-k, 0)
  dp[i] = min(dp[start_index:i]+np.abs(l[start_index:i]-l[i]))

print(dp[-1])

Measured memory_bytes: 22832
m,k = map(int,input().split())
#m,k = 1,0
if 2**m <= k :
  print(-1)
  exit()
if (m==1 and k !=0) :
  print(-1)
  exit()
if (m==1 and k==0) :
  print('0 0 1 1')
  exit()

ret = [k]
for i in range(2**m):
  if i!=k:
    ret.append(i)
ret.append(k)
for i in reversed(range(2**m)):
  if i!=k:
    ret.append(i)
print(' '.join(map(str,ret)))

Measured memory_bytes: 31636
#include <stdio.h>
#define mod 1000000007
int H, W, K, fact[300000], inv[300000], factinv[300000];
int ncr(int n, int r) { return (n - r >= 0 && r >= 0) ? 1LL * fact[n] * factinv[r] % mod * factinv[n - r] % mod : 0; }
int cal(int a, int b) { return (ncr(a + b, b) - ncr(a + b, b - 1) + mod) % mod; }
int main() {
	scanf("%d%d%d", &H, &W, &K);
	fact[0] = 1;
	for (int i = 1; i < 300000; i++) fact[i] = 1LL * fact[i - 1] * i % mod;
	inv[1] = 1;
	for (int i = 2; i < 300000; i++) inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;
	factinv[0] = 1;
	for (int i = 1; i < 300000; i++) factinv[i] = 1LL * factinv[i - 1] * inv[i] % mod;
	int ret = 0;
	for (int i = 0; i <= K; i++) {
		int res = 1LL * cal(W + i, i) * cal(H + K - i, K - i) % mod * ncr(H + W + 2 * K, W + 2 * i) % mod;
		ret = (ret + res) % mod;
	}
	printf("%d\n", ret);
	return 0;
}

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

using namespace std;

typedef long long int64;
const int mod = 1e9 + 7;

inline int64 modPow(int64 x, int64 n)
{
  if(n == 0) return (1);
  int64 ret = modPow(x, n / 2);
  (ret *= ret) %= mod;
  if(n & 1) (ret *= x) %= mod;
  return (ret);
}

inline int64 modInv(int64 a)
{
  return (modPow(a, mod - 2));
}

int64 fact[202020], rfact[202020];

void Init()
{
  if(fact[0] == 0) {
    fact[0] = rfact[0] = 1;
    for(int i = 1; i < 102020; i++) {
      fact[i] = fact[i - 1] * i % mod;
      rfact[i] = modInv(fact[i]);
    }
  }
}


int N, A, B, C, D;

int64 rec(int sum, int last)
{
  if(sum == N) return (1);
  if(last > B) return (0);

  int ret = rec(sum, last + 1);
  for(int i = C; i <= D; i++) {
    if(sum + i * last > N) continue;

    int64 people = fact[i * last];
    for(int j = 0; j < i; j++) (people *= rfact[j]) %= mod;
    (people *= rfact[last]) %= mod;

    (ret += rec(sum + i * last, last + 1) * people) %= mod;
  }
  return (ret);
}

int64 dp[1001][1001];

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

  dp[A - 1][0] = fact[N];
  for(int j = A; j <= B; j++) { // j 人の組
    int64 bat = 1;
    for(int k = 0; k < C - 1; k++) (bat *= rfact[j]) %= mod;
    for(int k = C; k <= D; k++) { // k 個
      (bat *= rfact[j]) %= mod;
      for(int i = N - 1; i >= 0; i--) {
        int sum = i + j * k;
        if(sum > N) continue;
        (dp[j][sum] += 1LL * dp[j - 1][i] * bat % mod * rfact[k] % mod) %= mod;
      }
    }
    for(int k = N; k >= 0; k--) (dp[j][k] += dp[j - 1][k]) %= mod;
  }
  cout << dp[B][N] << endl;
}





Measured memory_bytes: 9600
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	fsc := NewFastScanner()
	S := fsc.Next()
	check := map[rune]int{}
	for _, c := range S {
		check[c]++
	}
	ok := true
	for _, v := range check {
		if v > 1 {
			ok = false
		}
	}
	if ok {
		fmt.Println("yes")
	} else {
		fmt.Println("no")
	}
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

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

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<cctype>
#include<cstring>
#include<string>
using namespace std;
int main(){
    string a,b;
    while(1){
        cin >> a >> b;
        if(a[0] == '0' && b[0] == '0'&&a[1] == '\0')break;
        int h=0,bl=0;
        for(int i = 0;i < 4; i++){
            for(int j = 0;j < 4; j++){
                if(a[i] == b[j] && i == j){
                    h++;
                }
                else if(a[i] == b[j]){
                    bl++;
                }
            }
        }
        printf("%d %d\n",h,bl);
    }
    return 0;
}

Measured memory_bytes: 1176
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	ll sankaku=0ll,eikaku=0ll,chokkaku=0ll,donkaku=0ll;
	while(1)
	{
		int a,b,c;
		cin >> a >> b >> c;
		if(a+b>c&&a+c>b&&b+c>a)
		{
			sankaku++;
			if(a*a+b*b==c*c||b*b+c*c==a*a||c*c+a*a==b*b)chokkaku++;
			else if(a*a+b*b<c*c||b*b+c*c<a*a||c*c+a*a<b*b)donkaku++;
			else eikaku++;
		}
		else
		{
			cout <<sankaku<<' '<<chokkaku<<' '<<eikaku<<' '<<donkaku<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1156
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String[] inputs = sc.nextLine().split(" ");
        String a = inputs[0];
        String b = inputs[1];

        boolean doesTellTruth = false;
        if (a.equals("H")) {
            doesTellTruth = true;
        } else {
            doesTellTruth = false;
        }

        boolean isHonest = false;
        if (b.equals("H")) {
            isHonest = true;
        } else {
            isHonest = false;
        }

        if (doesTellTruth) {

            if (isHonest) {
                System.out.println("H");
            } else {
                System.out.println("D");
            }

        } else {
            if (isHonest) {
                System.out.println("D");
            } else {
                System.out.println("H");
            }
        }
    }
}

Measured memory_bytes: 22996
import copy

def partition(p, r):
    i = p
    for j in range(p, r):
        if A[r][1] >= A[j][1]:
            A[i], A[j] = A[j], A[i]
            i += 1
    A[r], A[i] = A[i], A[r]
    return i

def quick_sort(p, r):
    if p < r:
        q = partition(p, r)
        quick_sort(p, q-1)
        quick_sort(q+1, r)

def correct_same_num_suits(l, num, first, ele_cnt):
    suits = []
    append_cnt = 0
    for i in range(first, N):
        if num == l[i][1]:
            suits.append(l[i][0])
            append_cnt += 1
        if ele_cnt == append_cnt:
            break
    return suits

def is_stable():
    idx = 0
    while idx < N-1:
        idx_incr_flg = True
        if A[idx][1] == A[idx+1][1]:
            num = A[idx][1]
            j = idx
            ele_cnt = 0
            while j < N and num == A[j][1]:
                ele_cnt += 1
                j += 1
            sorted_suits = correct_same_num_suits(A, num, idx, ele_cnt)
            orig_suits = correct_same_num_suits(orig_list, num, 0, ele_cnt)
            if sorted_suits != orig_suits:
                return False
            idx += len(sorted_suits)
            idx_incr_flg = False
        if idx_incr_flg:
            idx += 1
    return True


N = int(input())
A = []
for _ in range(N):
    suit, num = input().split()
    num = int(num)
    A.append([suit, num])
orig_list = copy.deepcopy(A)

quick_sort(0, N-1)

is_stable = is_stable()
if is_stable:
    print("Stable")
else:
    print("Not stable")

for card in A:
    print("%s %d" % (card[0], card[1]))


Measured memory_bytes: 39448
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn gcd(x: usize, y: usize) -> usize {
    if y > 0 {
        gcd(y, x % y)
    } else {
        x
    }
}

#[allow(non_snake_case)]
fn main() {
    input! {
        K:usize
    }

    let mut h = HashMap::new();
    for i in 1..K + 1 {
        for j in 1..K + 1 {
            let g = gcd(i, j);
            h.insert(
                g,
                match h.get(&g) {
                    Some(x) => x + 1,
                    None => 1,
                },
            );
        }
    }
    let mut sum = 0;
    for i in 1..K + 1 {
        for (g, c) in &h {
            sum += gcd(i, g.clone()) * c;
        }
    }
    println!("{}", sum);
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int n, s;
lint memo[105][15][1005];

lint solve(int i, int j, int k){
    if(i == 101 || j == n){
        if(j == n && k == s){
            return 1LL;
        }else{
            return 0LL;
        }
    }
    if(memo[i][j][k] >= 0LL){
        return memo[i][j][k];
    }

    return memo[i][j][k] = solve(i + 1, j, k) + solve(i + 1, j + 1, k + i);
}

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

    while(cin >> n >> s, n){
        memset(memo, -1, sizeof(memo));
        cout << solve(0, 0, 0) << endl;
    }

    return 0;
}


Measured memory_bytes: 15536