akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007

ll combination(ll n, ll r) {
  if ( r * 2 > n ) r = n - r;
  ll dividend = 1;
  ll divisor  = 1;
  for (ll i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}
#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long idx=0;
    long N;
    cin >> N;
    map<long,long> A;
    vector<long> a(N);
    for(size_t i=0;i<N; i++)
    {
        cin >> a[i];
        A[a[i]]++;
    }

    /*
    map<long, pair<ll, ll>> comb_counter;
    for(auto itr = A.begin(); itr != A.end(); ++itr) {
        //std::cerr << "key = " << itr->first << ", value = " << itr->second << endl;
        ll comb[2];
        for(size_t i=0;i<2; i++)
        {
            if(itr->second - i < 2) comb[i] = 0;
            else comb[i] = combination(itr->second - i, 2);
        }
        comb_counter[itr->first] = make_pair(comb[0], comb[1]);
    }
    */
    ll total_counter = 0;
    long comb;
    for(auto itr = A.begin(); itr != A.end(); ++itr) {
        if(itr->second < 2)
        {
            comb = 0;
        }
        else
        {
            comb = combination(itr->second, 2);
        }
        total_counter += comb;
    }
    //cerr << total_counter << endl;
    for(size_t i=0;i<a.size(); i++)
    {
        cout << total_counter - (A[a[i]] - 1) << endl;
    }
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mat vector<vector<int>>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll


auto max(auto a){auto ans=a[0];for(auto i:a)if(i>ans)ans=i;return ans;}
auto min(auto a){auto ans=a[0];for(auto i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cerr<<i<<' ';cerr<<'\n';}



signed main()
{
	fio
	inp(n)
	string s;
	cin>>s;
	int ans=0;
	int i=0;
	while(i<n)
	{
		int j=i;
		while(j<n && s[i]==s[j])
			j++;
		ans++;
		i=j;
	}
	cout<<ans<<'\n';
	printclock;
}

Measured memory_bytes: 512
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = max(a)
c = b // 2
s = bisect.bisect_right(a, c)
min_a = abs(c-(b-a[s]))
min_b = abs(c-(b-a[s-1]))
if min_a < min_b:
    ans = a[s]
else:
    ans = a[s-1]
print("{} {}".format(b,ans))

Measured memory_bytes: 14556
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=998244353;
int qpow(int x,int y)
{
	int ret=1;
	while(y)
	{
		if(y&1)ret=(LL)ret*x%mod;
		x=(LL)x*x%mod;
		y>>=1;
	}
	return ret;
}

const int maxn=5000111;
int fac[maxn],invf[maxn];

int comb(int x,int y)
{
	if(y<0||x<y)return 0;
	return (LL)fac[x]*invf[y]%mod*invf[x-y]%mod;
}

int n,m;

int calc(int x)
{
	int coef=comb((m+m+m-x)/2+n-1,n-1);
//	printf("coef= %d\n",coef);
	int c2=(LL)x*comb((m+m+m-x)/2-m+n-1,n-1)%mod;
	int c3=(LL)(n-x)*comb((m+m+m-x)/2-m-1+n-1,n-1)%mod;
	coef-=c2;if(coef<0)coef+=mod;
	coef-=c3;if(coef<0)coef+=mod;
	coef=(LL)coef*comb(n,x)%mod;
//	printf("x= %d coef= %d c2= %d c3= %d\n",x,coef,c2,c3);
	return coef;
}

int main()
{
	fac[0]=1;
	for(int i=1;i<maxn;i++)fac[i]=(LL)i*fac[i-1]%mod;
	invf[maxn-1]=qpow(fac[maxn-1],mod-2);
	for(int i=maxn-1;i>=1;i--)invf[i-1]=(LL)i*invf[i]%mod;
	
	scanf("%d%d",&n,&m);
	
	int ans=0;
	for(int i=0;i<=n;i++)
	{
		if(i<=m&&(m+m+m-i)%2==0)
		{
			ans+=calc(i);
			if(ans>=mod)ans-=mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 39296
#include<bits/stdc++.h>
using namespace std;
const int N=100010;
typedef long long ll;
int main()
{
  int n,h[150],mx=-1,cnt=0;
  cin>>n;
  for(int i=1;i<=n;i++) cin>>h[i];
  for(int i=1;i<=n;i++)
  {
    if(h[i]>=mx) cnt++;
    mx=max(mx,h[i]);
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, A[100000], res;
multiset<int>st;

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		auto it = st.lower_bound(A[i]);
		if (it == st.begin()) {
			++res;
			st.insert(A[i]);
		}
		else {
			--it;
			st.erase(it);
			st.insert(A[i]);
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 5376
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
////////////////////////////////////////

int main() {
	string S, T;
	cin >> S >> T;
	bool flag = false;
	bool ok = true;
	for (int i = S.size()-T.size(); i >= 0; --i) {
		ok = true;
		if (S[i] == '?' || S[i] == T[0]) {
			for (int j = i; j < i + T.size(); ++j) {
				if (S[j] == '?' || S[j] == T[j - i]) {
					continue;
				}
				else {
					ok = false;
					break;
				}
			}
			if (ok) {
				for (int j = i; j < i + T.size(); ++j) {
					S[j] = T[j - i];
				}
				flag = true;
				i -= 100;
			}
		}
	}
	if (flag) {
		for (int i = 0; i < S.size(); ++i) {
		    if (S[i] == '?') {
				S[i] = 'a';
			}
		}
		cout << S << endl;
	}
	else {
		cout << "UNRESTORABLE" << endl;
	}
	return 0;
}


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

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

    int x[n], y[n];
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        ll k = 0;
        k = pow(x[i], 2);
        k += pow(y[i], 2);
        if(d >= sqrt(k)){
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 5236
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (ll i = (begin)-1; i >= (end); i--)
#define IREP(i, n) IFOR(i, n, 0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(), greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                                              \
  cout << #v << "=(" << v[0];                                                  \
  FOR(i_debug, 1, v.size()) { cout << "," << v[i_debug]; }                     \
  cout << ")" << endl;
#define mdebug(m)                                                              \
  cout << #m << "=" << endl;                                                   \
  REP(i_debug, m.size()) {                                                     \
    REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; }    \
    cout << endl;                                                              \
  }
#define Lower_bound(v, x)                                                      \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x)                                                      \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

template <typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) {
  REP(i, a.size()) {
    cin >> a[i];
    a[i]--;
  }
}

ll mod = 1000000007;

int main() {
  ll N, K;
  cin >> N >> K;
  vec x(N, -1);
  REP(i, N) { cin >> x[i]; }

  ll ans = 0;
  REP(i, N) { ans += 2 * min(abs(x[i] - K), x[i]); }

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

constexpr int kMaxN = 100000;

class UnionFind {
 private:
  int par_[kMaxN];
  int rank_[kMaxN];

 public:
  UnionFind(int n) {
    for (int i = 0; i < n; ++i) {
      par_[i] = i;
      rank_[i] = 0;
    }
  }

  int Find(int x) {
    if (par_[x] == x)
      return x;
    return par_[x] = Find(par_[x]);
  }

  bool Same(int x, int y) {
    return Find(x) == Find(y);
  }

  void Unite(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y)
      return;

    if (rank_[x] < rank_[y]) {
      par_[x] = y;
    } else {
      par_[y] = x;
      if (rank_[x] == rank_[y])
        ++rank_[x];
    }
  }
};

int p[kMaxN];

int main() {
  int N, M;

  cin >> N >> M;
  UnionFind uf(N);
  for (int i = 0; i < N; ++i) {
    cin >> p[i];
    p[i]--; // we use 0-based index
  }

  int x, y;
  for (int i = 0; i < M; ++i) {
    cin >> x >> y;
    // 0-based indices
    --x;
    --y;
    uf.Unite(x, y);
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (uf.Same(i, p[i])) ++ans;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,d,ara[100][100];
    cin>>n>>d;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=d;j++)
        {
            cin>>ara[i][j];
        }
    }
    int c=0;
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            double val=0;
            for(int k=1;k<=d;k++)
            {
                val=val+((ara[i][k]-ara[j][k])*(ara[i][k]-ara[j][k]));
            }
            val=sqrt(val);
           // cout<<"val  "<<val<<endl;
            double no=val-(int)val;
            if(no==0.0)
            {
                c++;
            }
        }
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using tiii = tuple<int,int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/*Coding Space*/
unordered_map<int,unordered_map<int,char>> m;
const int v[5] = {0,1,0,-1,0};
int main(){
  int h,w;  cin >> h >> w;
  rep(i,h)rep(j,w)  cin >> m[i][j];
  int w_cnt = 0;
  rep(i,h)rep(j,w)if(m[i][j] =='.')  w_cnt++;
  
  queue<tiii> q;
  q.push(tiii{0,0,0});
  
  while(!q.empty()){
    int x,y,s; tie(y,x,s) = q.front(); q.pop();
    if(x == w-1 && y == h-1){
      cout << w_cnt - s - 1 << endl;
      return 0;
    }
    rep(i,4)if(m[y + v[i]][x + v[i+1]] == '.'){
      q.push(tiii{y + v[i],x + v[i+1],s+1});
      m[y + v[i]][x + v[i+1]] = 'w';
    }
    m[y][x] = 'w';
  }
  cout << -1 << endl;
}

Measured memory_bytes: 384
def prime_list(n):
	l=[0]*n
	if n<4:
		for i in range(2,int(n**0.5)):
			if l[i]==0:
				for j in range(i*2,n,i):
					l[j]=1
		return [k for k in range(2,n) if l[k]==0]
	else:
		for i in range(2,max(int(n**0.5),4)):
			if l[i]==0:
				for j in range(i*2,n,i):
					l[j]=1
		return [k for k in range(2,n) if l[k]==0]
		
pl=prime_list(10**5+1000)
n=int(input())
for i in pl:
	if i>=n:
		print(i)
		exit()

Measured memory_bytes: 4188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(), vec.end()

struct Node {
    int key;
    Node *prev, *next;
};

Node *nil; //番兵

void init() { //番兵を初期化
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void insert(int key) { //番兵のポインタを繋ぎかえる
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

Node* listSearch(int key) {
    Node *cur = nil->next; //番兵の次の要素から辿る
    while (cur != nil && cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node *t) { //ポインタを繋ぎかえる
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void deleteKey(int key) {
    deleteNode(listSearch(key));
}

void printList() {
    Node *cur = nil->next;
    int isf = 0;
    while (true) {
        if (cur == nil) break;
        if (isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

int main() {
    int key, n;
    char cmd[20];
    scanf("%d", &n);
    init();
    rep(i,n) {
        scanf("%s %d", &cmd, &key);
        if (cmd[0] == 'i') insert(key);
        else if (cmd[0] == 'd') {
            if (strlen(cmd) > 6) {
                if (cmd[6] == 'F') deleteFirst();
                else if (cmd[6] == 'L') deleteLast();
            } else {
                deleteKey(key);
            }
        }
    }
    printList();
}


Measured memory_bytes: 34396
#include<bits/stdc++.h>
#ifdef LOCAL
    #define _GLIBCXX_DEBUG
    #define dbg(x) cerr << #x << " = " << x << char(10);
#else
    #define dbg(x) ;
    #define cerr if(0) cerr
    #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#endif
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mkt make_tuple
using namespace std;
using ld = long double;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
const ld eps = 1e-8l;
const int INF = 1e9 + 10;
const ll INFL = 9 * 1e18;
const ll MOD = 1e9 + 7;
const ld Pi = acosl(-1.0l);

const int N = 2e5 + 1;
int fact[N];
int mlp(int a, int b)
{
    return 1ll * a * b % MOD;
}

int add(int a, int b)
{
    return ((a + b) % MOD + MOD) % MOD;
}

int binpow(int a, int b)
{
    if(b == 0) return 1;
    if(b % 2)
    {
        return mlp(a, binpow(a, b - 1));
    }
    else
    {
        int ans = binpow(a, b / 2);
        return mlp(ans, ans);
    }
}

int getinv(int a)
{
    return binpow(a, MOD - 2);
}

int getC(int n, int k)
{
    return mlp(fact[n], getinv(mlp(fact[k], fact[n - k])));
}

int getways(int x, int y)
{
    return getC(x + y, x);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(9);
    cout << fixed;
    #ifdef LOCAL
        assert(freopen("in", "r", stdin));
        assert(freopen("out", "w", stdout));
        assert(freopen("err", "w", stderr));
    #endif

    int h, w, a, b, ans = 0;
    cin >> h >> w >> a >> b;
    fact[0] = 1;
    forn(i, N) if(i) fact[i] = mlp(fact[i - 1], i);
    for(int x = h - a - 1, y = b; x >= 0 && y < w; x--, y++)
        ans = add(ans, mlp(getways(x, y), getways(h - x - 1, w - y - 1)));
    cout << ans;
}


Measured memory_bytes: 1024
import java.io.*
import java.util.*

val pw = PrintWriter(System.out)


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }

    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }

    val (H, W) = readLine()!!.split(' ').map { it.toInt() }
    var a = Array<String>(H) { readLine()!! }.filter { it.count { chr -> chr == '.' } != W }
    val lis = mutableListOf<Int>()
    for (i in 0 until a[0].length) {
        if (a.map { it[i] == '.' }.all { it == true }) {
            lis.add(i)
        }
    }
    a = a.map { it.filterIndexed { idx, value -> idx !in lis } }
    a.forEach { println(it) }
}



Measured memory_bytes: 36384
#include <stdio.h>

int main(void)
{
    int n,x,i,j,k,l=0;
    
    while(1){
    scanf("%d %d",&n,&x);
    if(n==0 && x==0)break;
    for(i=n;i>0;i--){
        for(j=i-1;j>0;j--){
            for(k=j-1;k>0;k--){
                if(k+j+i==x)l++;
            }
        }
    }
    printf("%d\n",l);
    l=0;
    }
    return 0;
}


Measured memory_bytes: 2056
#include <cstdio>
#include <cstring>


bool data[501][501];
bool myfriend[501];
bool party[501];
		
int main(void) {
	int n, m, num;
	scanf("%d", &n);
	scanf("%d", &m);
	do {
		memset(data, 0, sizeof(data));
		memset(myfriend, 0, sizeof(myfriend));
		memset(party, 0, sizeof(party));

		for(int i = 0; i < m; i++) {
			int a, b;
			scanf("%d %d", &a, &b);
			data[a][b] = true;
			data[b][a] = true;
			if (a == 1) {
				myfriend[b] = true;
				party[b] = true;
			}
			if (b == 1) {
				myfriend[a] = true;
				party[a] = true;
			}
		}

		for(int i = 2; i <= n; i++) {
			if(myfriend[i] == true)
				for(int j = 2; j <= n; j++) {
					if(data[i][j] == true)
						party[j] = true;
				}
		}
		num = 0;
		for ( int i = 1; i <= n; i++) {
			if(party[i] == true)
				num++;
		}
		printf("%d\n", num);

		scanf("%d", &n);
		scanf("%d", &m);
	} while(n != 0 && m != 0);
	return 0;
}

Measured memory_bytes: 0
import java.io.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String S = reader.readLine();
        String T = reader.readLine();
        System.out.println (S.equals (T.substring (0, T.length() - 1)) ? "Yes"
                                                                       : "No");
        return;
    }
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  int N;
  cin >> N;
  string S = "ABC";
  S += to_string(N);
  cout << S << endl; 
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization_level 3
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(){
	ll n;
	ll m;
	cin>>n>>m;
	vector<ll> s(m);
	vector<ll> c(m);
	vector<ll> ans(n,0);

	rep(i,m){
		cin>>s.at(i)>>c.at(i);
	}

	int test = 345;
	if (n>1)
	{
		ans.at(0)=1;
	}
	

	
	
	for (size_t i = 0; i < m; i++)
	{
		if (ans.at(s.at(i)-1)==0 || ans.at(s.at(i)-1)==c.at(i) || ((s.at(i)-1)==0 && ans.at(s.at(i)-1)==1))
		{
			ans.at(s.at(i)-1) = c.at(i);
		} else {
			cout<<-1;
			return 0;
		}
		
	}


	if (n>1 && ans.at(0)==0)
	{
		cout<<-1;
		return 0;
	}

	// ll res = 0;
	// for (size_t i = 0; i < n; i++)
	// {
		// res += ans.at(i)*pow(10,n-i-1);
	// }

	// cout<<res;
	
	for (size_t i = 0; i < n; i++)
	{
		cout<<ans.at(i);
	}
	
	
}


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

int main(){
	string code;
	while(getline(cin, code)){
		for(int i = 0;i < 26;i++){
			for(int j = 0;j < code.size();j++){
				if(code[j] >= 'a' && code[j] <= 'z'){
					code[j]++;
					if(code[j] == 'z'+1)code[j] = 'a';
				}
			}
			if(code.find("the")!=-1 || code.find("this") != -1 || code.find("that") != -1)break;
		}
		cout << code << endl;
	}
	return 0; 
}

Measured memory_bytes: 3192
#include<iostream>
#include <string>
using namespace std;
int main(void){
    int n;
    int a;
    int b;
    cin >> n;
    cin >> a;
    cin >> b;
    if(n*a<b){
        cout << n*a;
    }else{
        cout << b;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
    char s[100];
    gets(s);
    int i,j,flag = 0;
    int len = strlen(s);
    for(i = 0; i < len-1; i++){
        for(j = i+1; j < len; j++){
            if(s[i]==s[j]){
                flag = 1;
                break;
            }
        }
    }
    if(flag)printf("no\n");
    else printf("yes\n");
    return 0;
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

bool comp(pair<int,int> a , pair<int,int> b ){
    return a.first < b.first;
}

int main() {

    ll n;
    ll k;
    Scll2(n,k);

    pair<ll,ll> a[100003];
    Rep(i,n){
        Scll2(a[i].first,a[i].second);
    }

    sort(a,a+n,comp);

    ll tmp = 0, ans;
    Rep(i,n){
        tmp += a[i].second;
        if( tmp >= k ) {
            ans = a[i].first;
            break;
        }
    }

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

    return 0;
}



Measured memory_bytes: 1792
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

H, W = map(int, input().split())
masu = []
for _ in range(H):
    masu.append(list(input()))

import itertools
directions = list(itertools.product([-1,0,1], repeat=2))

new_masu = []
for h in range(H):
    tmp = []
    for w in range(W):
        if masu[h][w] == "#":
            tmp.append("#")
            continue

        bombs = 0
        for dx, dy in directions:
            x = w + dx
            y = h + dy
            if x < 0 or x >= W:
                continue
            if y < 0 or y >= H:
                continue
            if masu[y][x] == "#":
                bombs += 1
        tmp.append(bombs)
    new_masu.append(tmp)

for line in new_masu:
    # この書き方重要
    print(*line, sep="")

Measured memory_bytes: 3572
/*|In The Name of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n;
int m;
int ar[N];
int cm[N];

int main(){
    cin >> m >> n;
    for(int i = 1; i <= n; i++){
        cin >> ar[i];
    }
    sort(ar + 1 , ar + n + 1);
    if(m >= n){
        puts("0");
        return 0;
    }
    vector < int > d;
    for(int i = 2; i <= n; i++){
        d.push_back(ar[i] - ar[i - 1]);
    }
    long long sm = 0;
    sort(d.rbegin() , d.rend());
    for(int i = 0; i < d.size() && i < m-1; i++){
        sm += d[i];
    }
    printf("%lld\n" , ar[n] - ar[1] - sm);
    return 0;
}


Measured memory_bytes: 1276
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int comp(const void * x, const void * y){
    return strcmp(x,y);
}
int main(){
    int i,j;
    scanf("%d %d", &i, &j);
    char s[i][j+1];
    for(int m=0;m<i;++m) scanf("%s", s[m]);
    qsort(s,i,sizeof(s[0]),comp);
    for(int m=0;m<i;++m) printf("%s", s[m]);
    return 0;
}


Measured memory_bytes: 252
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main() {
    int N;
    cin>>N;
    string c;
    cin>>c;
    int l=0;
    int r=N-1;
    int count=0;
    while (1)
    {
        while (l<N&&c[l]=='R')l++;
        while (r>=0&&c[r]=='W')r--;
        if(l<r)count++;
        else break;
        l++;r--;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3768
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

using namespace std;

template <class T>
istream& operator>>(istream& is, vector<T>& collection)
{
    for (auto& item : collection)
        is >> item;
    return is;
}

void solution()
{
    int n,k;
    cin >> n >> k;
    vector<int> ps(n);
    cin >> ps;
    sort(begin(ps), end(ps));
    cout << accumulate(begin(ps), begin(ps) + k, 0) << '\n';
}

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


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

int main() {
string str;
	string a;
	int count = 0;
	cin >> str;
	for (int i = 0; i < 3; i++) {
		a = str.substr(i, 1);
		if (1 == atoi(a.c_str())) {
			count++;
		}
	}

	cout << count << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
signed main() {
	int a, b;
	while (cin >> a >> b) {
		cout << gcd(a, b) << " " << a / gcd(a, b)*b << endl;
	}
}


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const int N = 234;
const long long INF = 1e17;

int R[10];
long long d[N][N];

void solve() {
	int n, m, r; scanf("%d%d%d", &n, &m, &r);
	for (int i = 0; i < n; ++i) {
		d[i][i] = 0;
		for (int j = i+1; j < n; ++j) {
			d[j][i] = d[i][j] = INF;
		}
	}
	for (int i = 0; i < r; --R[i++]) scanf("%d", R+i);
	for (int i = 0; i < m; ++i) {
		int a, b, c; scanf("%d%d%d", &a, &b, &c);
		--a; --b;
		d[b][a] = d[a][b] = c;
	}
	for (int k = 0; k < n; ++k) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
			}
		}
	}
	long long ans = INF;
	sort(R, R+r);
	do {
		long long cur = 0;
		for (int i = 1; i < r; ++i) {
			cur += d[R[i-1]][R[i]];
		}
		ans = min(ans, cur);
	} while (next_permutation(R, R+r));
	printf("%lld", ans);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


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

using namespace std; 
    
int main() {
    int a, b, c;
    int k; 

    cin >> a >> b >> c >> k;

    long long soma = 0;

    soma = a + b + c;

    int m = max(a, max(b, c));

    soma = soma - m; 

    soma = soma + m * pow(2, k);

    cout << soma << endl; 
}

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

bool is_palindrome(string s) {
    string tmp = s;
    reverse(tmp.begin(), tmp.end());
    return tmp == s;
}
int main() {
    int n;
    cin >> n;
    if(is_palindrome(to_string(n))){
        cout <<  "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val S = Array(N) {
        readLine()!!.toCharArray().sorted().toString()
    }.groupBy { it }.map { it.value.size }
    val ans = S.map { combination(it.toLong(), 2) }.sum()
    println(ans)
}

fun combination(n: Long, k: Long): Long {
    if (n < k) return 0
    var a = 1L
    var b = 1L
    val min = Math.min(n - k, k)
    for (i in n - min + 1..n) {
        a *= i
    }
    for (i in 1..min) {
        b *= i
    }
    return a / b
}

Measured memory_bytes: 78848
N = int(input())
W = list(map(int,input().split()))

left = W[0]
right = sum(W[1:])
minimum = abs(right - left)

for t in range(1,N):
  left += W[t]
  right -= W[t]
  ad = abs(right - left)
  minimum = minimum if ad > minimum else ad

print(minimum)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
    int n;
    scanf("%d", &n);
    vector<int> a(n), b(n), c(n);
    for(int i = 0; i < n; i++)  scanf("%d", a.begin()+i);
    for(int i = 0; i < n; i++)  scanf("%d", b.begin()+i);
    for(int i = 0; i < n; i++)  scanf("%d", c.begin()+i);
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += (ll)(lower_bound(a.begin(),a.end(),b[i])-a.begin())*(c.end()-upper_bound(c.begin(),c.end(),b[i]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
import sys
input=sys.stdin.readline

def main():
    N = int(input())
    if N == 0:
        print("0")
        return
    s = ""
    while N != 0:
        r = N%2
        s = str(r) + s
        N = (N-r)//-2
    print(s)

if __name__ == '__main__':
    main()


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

int main() {
  string S;
  cin >> S;
  int count = 0;
  
  for (int i=0 ; i < S.size() ; i=i+2) {
    if (!(S.at(i) == 'R'||S.at(i) == 'U'||S.at(i) == 'D')) {
      count++;
    }
  }
  for (int j=1 ; j < S.size() ; j=j+2) {
    if(!(S.at(j) == 'L'||S.at(j) == 'U'||S.at(j) == 'D')) {
      count++;
    }
  }
    if (count>0) {
      cout << "No" << endl;
    }
    else {
      cout << "Yes" << endl;
    }
  }


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	string S=in<string>();
	int sum=0;
	int N=S.size();
	REP(i,N){
		if(i%2 && S[i]=='g') sum++;
		else if(!(i%2) && S[i]=='p') sum--;
	}
	out(sum);
	return 0;
}

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

using namespace std;

int main(){
  vector<vector<int> > v(3, vector<int>(6));
  vector<vector<int> > ans(3, vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<6;j++){
      cin>>v[i][j];
    }
  }
  for(int i=0;i<3;i++){
    if(v[i][5]<v[i][2]){
      v[i][5] += 60;
      v[i][4]--;
    }
    ans[i][2] = v[i][5] - v[i][2];
    if(v[i][4]<v[i][1]){
      v[i][4] += 60;
      v[i][3]--;
    }
    ans[i][1] = v[i][4] - v[i][1];
    ans[i][0] = v[i][3] - v[i][0];
  }
  for(int i=0;i<3;i++){
    cout<<ans[i][0]<<" "<<ans[i][1]<<" "<<ans[i][2]<<endl;
  }
}


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

#define int long long

using namespace std;

int u[400001];

 main () {   
 	int n;
 	cin >> n;
 	int mx = 0;
 	for (int i = 1;i <= n;i ++) {
 		int x;
 		cin >> x;                         
 		u[x] = u[x - 1] + 1;	
 		mx = max (mx, u[x]);
 	}
 	cout << n - mx;
    return 0;           		
}

Measured memory_bytes: 1792
import sys
def input(): return sys.stdin.readline().strip()

def main():
    a, b, c = map(int, input().split())
    possible = False
    for i in range(b):
        if a * i % b == c:
            possible = True
            break
    if possible:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()


Measured memory_bytes: 61892
def is_horizontal_same(s):
    for j in range(0, len(s)):
        if s[j] != ".":
            return False
    return True


def is_vertical_same(str_list, i):
    for j in range(0, len(str_list)):
        if str_list[j][i] != ".":
            return False
    return True


def main():
    h, w = map(int, input().split())

    str_list = []
    for i in range(0, h):
        str_list.append(input())

    while True:
        is_completed = True

        same_line_indexes = []
        for i in range(0, len(str_list)):
            if is_horizontal_same(str_list[i]):
                same_line_indexes.append(i)
                is_completed = False
        popped_cnt = 0
        for i, v in enumerate(same_line_indexes):
            str_list.pop(v - popped_cnt)
            popped_cnt += 1

        same_vertical_line_indexes = []
        for i in range(0, len(str_list[0])):
            if is_vertical_same(str_list, i):
                same_vertical_line_indexes.append(i)
                is_completed = False
        popped_cnt = 0
        for i, v in enumerate(same_vertical_line_indexes):
            for j in range(0, len(str_list)):
                org_str = str_list[j]
                str_list[j] = org_str[:v - popped_cnt] + org_str[v - popped_cnt + 1:]
            popped_cnt += 1

        if is_completed:
            break

    for i, v in enumerate(str_list):
        print(v)


main()


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

int main(){
  int i,j,k,v,N,A[100];

  scanf("%d",&N);
  if(N < 1 || N > 100) exit(1);

  for(i = 0;i < N;i++){
    scanf("%d",&A[i]);
    if(A[i] < 0 || A[i] > 1000) exit(2);
  }

  for(i = 1;i < N;i++){
    
    for(k = 0;k < N;k++){
    if(k == 0) printf("%d",A[k]);
    else printf(" %d",A[k]);
  }
    printf("\n");
    
    v = A[i];
    j = i-1;
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
  }

  for(i = 0;i < N;i++){
    if(i == 0) printf("%d",A[i]);
    else printf(" %d",A[i]);
  }

  printf("\n");
  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define MOD (int)1e9+(int)7
#define INF 2147483647
typedef long long ll;
typedef unsigned long long ull;
//dark power
#define int ll
//define Error、大抵は、セミコロン忘れとか、Defineは関係ない
//komennto C+udekaijo
//conbination n!/r!(n-r)!
class UnionFind{
	public:
	vector<int> parent;
	vector<int> rank;
	vector<int> size;
	UnionFind(signed n){
		parent.reserve(n);
		rank.reserve(n);
		size.reserve(n);
		rep(i,n){
			parent[i]=i;
			rank[i]=0;
			size[i]=1;
		}
	}
	signed find(signed x){
		//keiroassyuku
		if(parent[x]==x){
			return x;
		}else{
			return parent[x]=find(parent[x]);
		}
	}
	void unite(signed x,signed y){
		x=find(x);
		y=find(y);
		if(x==y)return;
		if(rank[x]<rank[y]){
			size[y]+=size[x];
			size[x]=size[y];
			parent[x]=y;
		}else{
			size[x]+=size[y];
			size[y]=size[x];
			parent[y]=x;
			if(rank[x]==rank[y])rank[x]++;
		}
	}
	bool same(signed x,signed y){return (find(x)==find(y));}
	int sizeis(int x){return size[find(x)];}
};

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H,W,h,w;
	cin>>H>>W>>h>>w;
	cout<<H*W-h*W-w*H+h*w<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
    int n,v[100000],count1[100001],count2[100001],i,max1 = 0,max2 = 0,cmax1,cmax2,nmax1 = 0,nmax2 = 0;
    scanf("%d",&n);
    for (i = 0;i < n;i++) {
        scanf("%d",&v[i]);
    }
    for (i = 0;i <= 100000;i++) {
        count1[i] = 0;
        count2[i] = 0;
    }
    for (i = 0;i < n;i++) {
        if (i % 2 == 0) {
            count1[v[i]]++;
        } else {
            count2[v[i]]++;
        }
    }
    for (i = 1;i <= 100000;i++) {
        if (count1[i] > max1) {
            max1 = count1[i];
            cmax1 = i;
        }
        if (count2[i] > max2) {
            max2 = count2[i];
            cmax2 = i;
        }
    }
    if (cmax1 == cmax2) {
        count1[cmax1] = 0;
        count2[cmax2] = 0;
        for (i = 1;i <= 100000;i++) {
            if (count1[i] > nmax1) {
                nmax1 = count1[i];
                cmax1 = i;
            }
            if (count2[i] > nmax2) {
                nmax2 = count2[i];
                cmax2 = i;
            }
        }
        if (max1 + nmax2 > max2 + nmax1) {
            printf("%d\n",n - (max1 + nmax2));
        } else {
            printf("%d\n",n - (max2 + nmax1));
        }
    } else {
        printf("%d\n",n - (max1 + max2));
    }
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
#define f first
#define pb push_back
#define s second
#define mp make_pair

int d[100100];
vector<pi> aList[100100];
int N,M,a,b,c;
int INF = 1e9;

void dfs(int x){
  for (auto i : aList[x]){
    int nxt = d[x] + i.s;
    if (d[i.f] == -INF){
      d[i.f] = nxt;
      dfs(i.f);
    }else{
      if (nxt != d[i.f]){
        cout<<"No";
        exit(0);
      }
    }
  }
}

int main(){
  cin >> N >> M;
  for (int i=0;i<M;++i){
    cin>>a>>b>>c;
    aList[a].pb(mp(b,c));
    aList[b].pb(mp(a,-c));
  }
  for (int i=1;i<=N;++i)d[i] = -INF;
  for (int i=1;i<=N;++i){ 
    if (d[i] != -INF)continue;
    d[i] = d[i-1];
    dfs(i);
  }
  cout<<"Yes";
}

Measured memory_bytes: 11008
module Main where

import Data.Functor
import Data.List

main :: IO ()
main =  putStr . unlines . unfoldr phi . zip [1..] =<< getCases

phi :: [(Int,String)] -> Maybe (String,[(Int,String)])
phi [] = Nothing
phi ((_,"0"):_) = Nothing
phi ((i,cs):rs) = Just ("Case "++show i++": "++cs,rs)

getCases :: IO [String]
getCases = words <$> getContents

Measured memory_bytes: 4892
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define _GLIBCXX_DEBUG

void printv(vector<int> v) {
  for (int i : v)
    cout << i << " ";
  cout << endl;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));
  vector<int> c(n + 1);
  for (int i = 0; i < m; i++) {
    cin >> c[i + 1];
  }
  for (int i = 1; i <= n; i++) {
    dp[0][i] = 50010;
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (j >= c[i])
        dp[i][j] = min(dp[i - 1][j],
                       min(dp[i - 1][j - c[i]] + 1, dp[i][j - c[i]] + 1));
      else
        dp[i][j] = dp[i - 1][j];
    }
  }
	cout<<dp[m][n]<<endl;
}



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

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

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

const int INF = 1999999999;

LL GCD(LL a,LL b){
    LL t; LL r;
    if(a<b){t=a;a=b;b=t;}
    if(b==0){return a;}
    while(a%b!=0){r=a%b;a=b;b=r;}
    return b;
}

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

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

    Vi num = {0,2,5,5,4,5,6,3,7,6};
    Vi a(m);
    REP(i,m){
        cin>>a[i];
    }
    sort(ALL(a),greater<int>());

    Vi dp(10005,-INF);
    dp[0] = 0;
    REP2(i,1,n+1){
        REP(j,m){
            int ind = i-num[a[j]];
            if(ind<0) continue;
            chmax(dp[i],dp[ind]+1);
        }
        // REP(k,n+1){
        //     cout<<((dp[k]==-INF)?-1:dp[k])<<" ";
        // }
        // cout<<endl;
    }

    int digit = dp[n];
    int matchi_num = n;
    string ans = "";
    REP(i,digit){
        REP(j,m){
            if(matchi_num-num[a[j]]<0) continue;
            if(dp[matchi_num-num[a[j]]] == dp[matchi_num]-1){
                ans += to_string(a[j]);
                matchi_num -= num[a[j]];
                // cout<<"digit : "<<i+1<<" = "<<a[j]<<" nokori:"<<matchi_num<<endl;
                break;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
using System;

namespace B___AtCoder_Beginner_Contest_111
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var b = 0;
            for (var i = n; i <= 999; i++)
            {
                var a = n.ToString();
                if (a.Substring(0, 1) == a.Substring(1, 1) && a.Substring(1, 1) == a.Substring(2, 1))
                {
                    b = n;
                    break;
                }
                n++;
            }
            Console.WriteLine(b);
        }
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

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

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	int N, K;
	cin >> N >> K;
	vector<ll>num(K, 0);
	//a%kを決めるとb%k,c%kの値が一意に決まることを利用する
	for (int i = 1; i <=N ; ++i) {
		num[i%K]++;//num[x]=kで割って余る数が1以上N以下に何個あるか
	}
	ll res = 0;
	for (int a = 0; a < K; ++a) {
		int b = (K - a) % K;
		int c = (K - a) % K;
		if ((b + c) % K != 0)continue;
		res += num[a] * num[b] * num[c];
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define V 10500
#define eb emplace_back
typedef vector<int> vi;

vi adl[V], radl[V];
vi ord, gr;
bool vis[V];

void dfs(int v) {
    if (vis[v]) return; 
    vis[v] = true;
    for (int ng: adl[v])
        dfs(ng);
    ord.eb(v);
}

void rdfs(int v, int g) {
    if (gr[v] != -1) return;
    gr[v] = g;
    for (int ng: radl[v])
        rdfs(ng, g);
}

int main() {
    int v, e; scanf("%d%d", &v, &e);
    for (int i = 0; i < e; i++) {
        int p, q; scanf("%d%d", &p, &q);
        adl[p].eb(q);
        radl[q].eb(p);
    }
    for (int i = 0; i < v; i++)
        dfs(i);

    for (int i = 0; i < v; i++) {
        //printf("%d\n", ord[i]);
    }
    gr.assign(v, -1);
    reverse(ord.begin(), ord.end());
    for (int i = 0; i < v; i++)
        rdfs(ord[i], i);

    for (int i = 0; i < v; i++) {
        //printf("%d %d\n", i, gr[i]);
    }
    int nq; scanf("%d", &nq);
    while (nq--) {
        int p, q; scanf("%d%d", &p, &q);
        printf("%d\n", gr[p] == gr[q]);
    }
}




Measured memory_bytes: 4972
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
using namespace std;
#define ll long long
ll r, g, b, n;
ll answer = 0;

ll memo[3005][3];

ll way(ll x, ll pos){
	if (memo[x][pos] != -1) return memo[x][pos];
	if (pos == 2){
		if (x%b == 0) return 1;
		return 0;
	}
	if (pos == 1){
		ll ans = 0;
		for (int i = x; i >= 0; i-=g){
			ans += way(i, pos + 1);
		}
		return memo[x][pos] = ans;
	} else {
		ll ans = 0;
		for (int i = x; i >= 0; i -= r){
			ans += way(i, pos + 1);
		}
		return memo[x][pos] = ans;
	}
}

int main(){
	memset(memo, -1, sizeof(memo));
	scanf("%lld%lld%lld%lld", &r, &g, &b, &n);
	printf("%lld\n", way(n, 0));
}

Measured memory_bytes: 256