akhauriyash/Code-Regression huggingface dataset:
// ref. https://www.youtube.com/watch?v=HVuSp_IhNZA

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

vector<ll> c;
vector<vector<ll>> g;

vector<ll> t; // t[i] .. size of subtree with root i
vector<stack<ll>> st;
vector<ll> d; // d[i] .. temporary store.
vector<ll> remsz; // remsz[i] .. remaining size of color i
vector<ll> ans; // ans[i] .. result of color i

ll f(ll n) { return n*(n+1)/2; } // nC2 + n = n*(n+1)/2

ll tfs(ll v, ll p = -1) {
  t[v] = 1;
  for (int u : g[v]) {
    if (u == p) { continue; }
    t[v] += tfs(u, v);
  }
  return t[v];
}

void dfs(ll v, ll p = -1) {
  st[c[v]].push(v);
  for (ll u : g[v]) {
    if (u == p) { continue; }
    d[v] = t[u]; // store here temporarily
    dfs(u, v);
    ans[c[v]] -= f(d[v]);
  }
  st[c[v]].pop();
  if (st[c[v]].size() > 0) {
    d[st[c[v]].top()] -= t[v]; // decrease the contribution of this subtree
  } else {
    remsz[c[v]] -= t[v];
  }
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  c.resize(n);
  g.resize(n);
  t.resize(n);
  st.resize(n);
  d.resize(n);
  remsz.resize(n);
  ans.resize(n);

  rep(i, n) {
    cin >> c[i];
    --c[i];
  }
  rep(i, n-1) {
    ll a, b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  rep(i, n) { ans[i] = f(n); }
  rep(i, n) { remsz[i] = n; }
  tfs(0);
  dfs(0);
  rep(i, n) {
    ans[i] -= f(remsz[i]);
  }
  rep(i, n) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 167404
#include"bits/stdc++.h"
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    long long ans = INT_MAX;
    for (int target = *min_element(a.begin(), a.end()); target <= *max_element(a.begin(), a.end()); target++) {
        long long tmp = 0;
        for (int i = 0; i < N; i++) {
            tmp += (a[i] - target) * (a[i] - target);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll N,M;
    cin >> N >> M;
    auto A = InputVec(M);
    ll s = 0;
    for (int i = 0; i < M; ++i) {
        s += A[i];
    }
    if(N < s){
        cout << -1 << endl;
    }else{
        cout << N-s << endl;
    }
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k;
    string s;
    cin >> k >> s;
    if(k>=int(s.size()))cout << s;
    else{
        for(int i=0;i<k;i++){
            cout << s[i];
        }
        cout << "...";
    }

}   

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll u = max({a, b, c});
    out((a+b+c-u) + u*modpow(2LL, k));
    re0;
}

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

using namespace std;

using ll = long long;
using ull = long long;

int main()
{
	int H, N;
	cin>>H>>N;
	vector<int> A(N+1);
	vector<int> B(N+1);
	for (int i = 1;i <= N;++i) {
		cin>>A[i]>>B[i];
	}

	vector<int> dp(H+1, INT_MAX);
	dp[0] = 0;

	for (int i = 1;i <= H;++i) {
		for (int j = 1;j <= N;++j) {
			dp[i] = min(dp[i], dp[max(0, i - A[j])] + B[j]);
		}
	}

	cout<<dp[H]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<ll, ll>
#define endl "\n"
#define MAXN 100005
using namespace std;

ll n, x, m = 1e9 + 7;

ll modexp(ll x, ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1) res=(res*x)%m;
        y/=2;
        x=(x*x)%m;
    }
    return res;
}

void solve()
{
    cin >> n;
    ll sum = 0, sqr = 0;
    for (ll i = 0; i < n; i++)
    {
        cin >> x;
        sum = (sum + x) % m;
        sqr = (sqr + (x * x) % m) % m;
    }
    sum = (sum * sum) % m;
    ll res = sum - sqr;
    while(res<0) res+=m;
    int t=modexp(2,m-2);
    cout << (res*t)%m << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define MODB 998244353
#define INF 9223372036854775807

signed main()
{
  int x=0,y=1,z=0,w=0,n=0,m=0;
  std::vector<int> v(3);
  std::cin >> v[0]>>v[1]>>v[2]>>x;
  rep(i,x){
    sort(rall(v));
    v[0]*=2;
  }
  rep(i,3){
    z+=v[i];
  }
  std::cout << z << '\n';
}


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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

template<int mod>
struct modulo {
	int w;
	operator int&() { return w; }
	
	modulo() {}
	modulo(int w) { this->w = w; fix(); }
	void inline fix() { w %= mod; if (w < 0) w += mod; }
	modulo inline fix(int w) const { w %= mod; if (w < 0) w += mod; return w; }
	
	modulo& operator += (modulo b) { if ((w += b.w) >= mod) w -= mod; return *this; }
	modulo& operator -= (modulo b) { if ((w -= b.w) < 0) w -= mod; return *this; }
	modulo& operator *= (modulo b) { w = (num) w * b.w % mod; return *this; }
	modulo& operator /= (modulo b) { w = (num) w * b.inv() % mod; return *this; }
	modulo inline operator + (modulo b) { modulo r = *this; r += b; return r; }
	modulo inline operator - (modulo b) { modulo r = *this; r -= b; return r; }
	modulo inline operator * (modulo b) { modulo r = *this; r *= b; return r; }
	modulo inline operator / (modulo b) { modulo r = *this; r /= b; return r; }
	
	modulo inline inv() const {
		int a = w, m = mod, u = 0, v = 1, t;
		for (; a != 0; t = m / a, m -= t * a, swap(a, m), u -= t * v, swap(u, v));
		return fix(u);
	}
	
	modulo inline pow(int p) const {
		if (!w)  return 0;
		modulo a = *this, r = 1;
		for (; p > 0; a *= a, p >>= 1) if (p & 1) r *= a;
		return r;
	}
};
typedef modulo<998244353> rem;

const int nsz = int(2e5);
rem n, m, k, fac[nsz + 5], ifc[nsz + 5], ans;
 
void inline init() {
	fac[0] = ifc[0] = 1;
	cont (i, n) {
		fac[i] = fac[i - 1] * rem(i);
		ifc[i] = fac[i].inv();
	}
}
 
rem inline C(int n, int m) { return fac[n] * ifc[m] * ifc[n - m]; }
 
rem inline f(int n, int k) { return C(n - 1, k) * m * (m - rem(1)).pow(n - k - 1); }
 
int main() {
	scanf("%d%d%d", &n, &m, &k);
	if (m == 1) {
		printf("%d\n", k == n - rem(1));
		return 0;
	}
	init();
	circ (i, 0, int(k)) {
		ans += f(n, i);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 5276
N, A, B = list(map(int, input('').split()))
total = 0
for x in range(1, N + 1):
  num = str(x)
  digit_total = 0
  for y in range(len(num)):
    digit_total += int(num[y])
  if digit_total >= A and digit_total <= B:
    total += x

print(total)

Measured memory_bytes: 3060
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val S = rd.readString()
    val N = S.length
    val mp = mutableMapOf<Char, Int>()
    mp['a'] = 0
    mp['b'] = 0
    mp['c'] = 0
    for (i in 0 until N) {
        mp[S[i]] = mp[S[i]]!! + 1
    }

    var hi = 0; var lo = INF
    for (c in "abc") {
        hi = max(hi, mp[c]!!)
        lo = min(lo, mp[c]!!)
    }

    val ans = if (hi - lo <= 1) "YES" else "NO"
    println(ans)
}


//val rd = debug.Reader("etc", "cf17-final", "b", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int); data class LongPair(val first: Long, val second: Long)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 38680
#pragma GCC Optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lp(i,begin,end) for (int i=begin;i<end;i++)
const int N=30,M=N*N,OO=0x3f3f3f3f;
int main(){
    string a,b,c;
    cin>>a>>b>>c;
    char cur='a';
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    reverse(c.begin(),c.end());
    while(1){
        if(cur=='a'){if(!a.size()){cout<<"A";   return 0;}cur=a[a.size()-1];     a.pop_back();}
        else if(cur=='b'){if(!b.size()){cout<<"B";   return 0;}cur=b[b.size()-1];     b.pop_back();}
        else if(cur=='c'){if(!c.size()){cout<<"C";   return 0;}cur=c[c.size()-1];     c.pop_back();}
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int R;
	scanf("%d", &R);
	if (R < 1200) {
		printf("ABC\n");
	}
	else if (1200 <= R && R < 2800) {
		printf("ARC\n");
	}
	else {
		printf("AGC\n");
	}


	return 0;

}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
	int n,k=1;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int t;
		cin>>t;
		if(t==k)
		k++;
	}
	if(k==1)
	cout<<"-1";
	else 
	cout<<n-k+1;
} 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a=1,b=1,c=1,n,x,i=0;
  
  while(1){
    
    cin>>n>>x;
    i=0;
    
    if(n==0 && x==0)return 0;

    for(a=1; a<=n; a++){
      
      for(b=1; b<=n; b++){
       
	for(c=1; c<=n; c++){

	  if(a+b+c==x && a<b && b<c){
	    i++;
	    continue;
	    
	  }
	  
	}
	
      }
      
    }
    
    cout<<i<<"\n";
    
  }
  
}

Measured memory_bytes: 1160
#include<math.h>

int isprime(int);

int main( ){

  int w,n[10000],x,i,c=0;

  scanf("%d",&x);

  for(i=0;i<x;i++){
 
  scanf("%d",&n[i]);

  }

  for(i=0;i<x;i++){
    
  w=isprime(n[i]);

  if(w==1)c++;

  }

  printf("%d\n",c);
  
  return 0;
}


int isprime(int x){

  int i;
  
  if(x==2) return 1;

  if(x<2||x%2==0) return 0;

  i=3;

  while(i<=sqrt(x)){
    
    if(x%i==0) return 0;
    i=i+2;
  }
  
  return 1;
  
}
  
 

Measured memory_bytes: 632
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
#include<cstdio>

int v[1500001];
char s[1500001],t[500002];
void Zalgorithm(int N){
  int i=1,j=0,k=0;
  while(i<N){
    while(i+j<N&&s[i+j]==s[j])++j;
    if(!(v[i]=j)){
      ++i;
      continue;
    }
    k=1;
    while(v[k]+k<j){
      v[i+k]=v[k];
      ++k;
    }
    i+=k;
    j-=k;
  }
}
int i,j,K,que[500001],bf,ans,size;
inline void print(int N){
  if(!N)return;
  print(N/10);
  putchar('0'+N%10);
}
int main(){
  int N,ng=500001,mid;
  std::fgets(t,1000000,stdin);
  std::fgets(s,1000000,stdin);
  while(ng-K>1){
    mid=(ng+K)>>1;
    (s[mid]?K:ng)=mid;
  }
  while(t[i]!='\n'){
    s[K+i]=t[i];++i;
  }
  N=i;
  i+=K;
  int M=N+(K<<1);
  while(i<M){
    s[i++]=t[j++];
    j*=j<N;
  }
  Zalgorithm(M);
  M=K%N;
  for(i=0;i<N;++i){
    if(v[i+M]=v[i+K]<K)que[size++]=(i+M)-(i+M>=N)*N;
  }
  for(i=0;i<N;++i){
    if(i==size){
      puts("-1");
      return 0;
    }
    if(!v[que[i]+=M]){
      que[size++]=que[i]-(que[i]>=N)*N;
      if(bf<=i){
        bf=size-1;
        ++ans;
      }
    }
  }
  if(ans)print(ans);
  else puts("0");
}

Measured memory_bytes: 9984
n=int(input())
x=list(map(int,input().split()))
a=sorted(x)
ans={}

for i in range(n):

    if i<n//2:
        ans[a[i]]=a[n//2]
    else:
        ans[a[i]]=a[n//2-1]

for j in x:
    print(ans[j])
    

Measured memory_bytes: 34820
#include<bits/stdc++.h>
using namespace std;
vector<long long> A, B;
int N, M,Q;
long long solve(long long x) {
	int pos1 = lower_bound(A.begin(), A.end(), x) - A.begin();
	int pos2 = lower_bound(B.begin(), B.end(), x) - B.begin();
	vector<long long > G1, G2;
	if (pos1 >= 1) G1.push_back(A[pos1 - 1]);
	if (pos1 < A.size()) G1.push_back(A[pos1]);
	if (pos2 >= 1) G2.push_back(B[pos2 - 1]);
	if (pos2 < B.size()) G2.push_back(B[pos2]);
	long long ans = (1LL << 60);
	for (int i = 0; i < G1.size(); i++) {
		for (int j = 0; j < G2.size(); j++) {
			ans = min(ans, abs(x - G1[i]) + abs(G1[i] - G2[j]));
			ans = min(ans, abs(x - G2[j]) + abs(G1[i] - G2[j]));
		}
	}
	return ans;
}
int main() {
	cin >> N >> M>>Q;
	for (int i = 0; i < N; i++) { long long c; cin >> c; A.push_back(c); }
	for (int i = 0; i < M; i++) { long long c; cin >> c; B.push_back(c); }
	for (int i = 0; i < Q; i++) {
		long long pl; cin >> pl;
		cout << solve(pl) << endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#include <stdio.h>
int main (){
  int H,W,a,b,c;
 
  for(;;) {  scanf("%d%d",&H,&W);
    if(H==0&&W==0) break;
    for(b=1;H>=b;b++){


   
      for(a=1;W>=a;a++){
	printf("#");
	if(a==W) printf("\n");
      }
      if(b==H) printf("\n");  
    }
 
  }
  return 0;
}

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

long long N, M;
queue<long long> A[305];
set<long long>done;

int main(){
	cin >> N >> M;
	for(long long i = 0; i < N; i++){
		for(long long j = 0; j < M; j++){
			long long tmp;
			cin >> tmp;
			A[i].push(tmp);
		}
	}

	long long ans = INT_MAX;

	while(true){
		map<long long, long long> count;
		long long maxkey;
		long long maxval = -1;
		for(long long i = 0; i < N; i++){
			if(A[i].size() > 0){
				count[A[i].front()]++;
				if(maxval < count[A[i].front()]){
					maxkey = A[i].front();
					maxval = count[A[i].front()];
				}
			}
		}

		if(count.size() == 0){
			break;
		}

		ans = min(ans, maxval);
		done.insert(maxkey);

		for(long long i = 0; i < N; i++){
			while(A[i].size() > 0 && done.count(A[i].front())!= 0){
				A[i].pop();
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1152
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int N;
    cin >> N;
    cout << "ABC";
    if (N < 10) cout << "00";
    else if (N < 100) cout << "0";
    cout << N << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_INPUT_SIZE  1024

void trace(int num, int* array);
int bubbleSort(int num, int* array);

int
main(int argc, char* argv[])
{
    char input[MAX_INPUT_SIZE];

    int num = atoi(fgets(input, sizeof(input), stdin));
    int* array = new int[num];

    atoi(fgets(input, sizeof(input), stdin));
    for (int i = 0; i < num; i++) {
        array[i] = i == 0 ?
            atoi(strtok(input, " ")) : atoi(strtok(NULL, " "));
        //printf("%d\n", array[i]);
    }

    printf("%d\n", bubbleSort(num, array));


    if (array != NULL) {
        delete [] array;
    }

    return 0;
}

void
trace(int num, int* array)
{
    for (int i = 0; i < num; i++) {
        if (i != 0) {
            printf(" ");
        }
        printf("%d", array[i]);
    }
    printf("\n");
}

int
bubbleSort(int num, int* array)
{
    int ret = 0, loopCount = 0;
    
    for (int j = 0; j < num; j++) {
        for (int i = num-1; i > j; i--) {
            if (array[i] < array[i-1]) {
                int tmp = array[i];
                array[i] = array[i-1];
                array[i-1] = tmp;
                ret++;
            }
        }
    }
    /*
    for (int i = 0; i < num; i++) {
        printf("%d\n", array[i]);
    }
    */
    trace(num, array);

    return ret;
}

Measured memory_bytes: 1000
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		if(str.equals("A")){
			System.out.println("T");
		}else if(str.equals("T")){
			System.out.println("A");
		}else if(str.equals("C")){
			System.out.println("G");
		}else{
			System.out.println("C");
		}
	}
}

Measured memory_bytes: 23892
import sys
from heapq import heappush, heappop


class Dijkstra:

    class Edge:
        def __init__(self, end, cost):
            self.to = end
            self.cost = cost

    def __init__(self, V, INF):
        self._node = V
        self._graph = [[] for i in range(self._node)]
        self.inf = INF
        self.dist = [self.inf for i in range(self._node)]

    def add_edge(self, st, ed, cs):
        self._graph[st].append(self.Edge(ed, cs))

    def solve(self, start):
        que = []
        self.dist[start] = 0
        heappush(que, (0, start))
        while que:
            cur_cost, cur_vertex = heappop(que)
            if self.dist[cur_vertex] < cur_cost:
                continue
            for e in self._graph[cur_vertex]:
                if self.dist[e.to] > cur_cost + e.cost:
                    self.dist[e.to] = cur_cost + e.cost
                    heappush(que, (self.dist[e.to], e.to))


if __name__ == '__main__':
    V, E, r = map(int, sys.stdin.readline().split())
    dk = Dijkstra(V, 10 ** 10)
    for i in range(E):
        s, t, d = map(int, sys.stdin.readline().split())
        dk.add_edge(s, t, d)
    dk.solve(r)
    for value in dk.dist:
        if value == dk.inf:
            sys.stdout.writelines("INF\n")
        else:
            sys.stdout.writelines("%d\n" % value)



Measured memory_bytes: 139900
n,a,b=gets.split.map &:to_i
def sum(n)
  k=0
  while n>0
    k+=n%10
    n/=10
  end
  k
end
ans=0
for i in 1..n
  s=sum(i)
  if a<=s&&s<=b;ans+=i;end
end
puts ans

Measured memory_bytes: 1788
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,sum=0;
  cin>>N;
  ll A[100010];
  REP(i,100010) A[i]=0;
  REP(i,N){
    ll a;
    cin>>a;
    A[a]++;
    sum+=a;
  }
  
  ll Q;
  cin>>Q;
  ll B[Q],C[Q];
  
  REP(i,Q){
    cin>>B[i]>>C[i];
    sum-=B[i]*A[B[i]];
    sum+=C[i]*A[B[i]];
    A[C[i]]+=A[B[i]];
    A[B[i]]=0;
    co(sum);
  }
  
  return 0;
}

Measured memory_bytes: 5964
import sys

input = sys.stdin.readline


def main():
    a, b = map(int, input().split())

    # N(N+1)/2 - X = a
    # (N+1)(N+2)/2 - X = b
    for i in range(1, 999):
        Xa = i * (i + 1) // 2 - a
        Xb = (i + 1) * (i + 2) // 2 - b
        if Xa == Xb:
            ans = Xa
            break

    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

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

	unordered_map <string,bool> memo;
	int n;
	string s;
	string prev="";

	cin >> n;

	for(int i=0;i<n;i++)
	{
		cin >> s;
		if(prev!="" && prev[prev.length()-1]!=s[0])
		{
			cout << "No" << '\n';
			return 0;
		}
		if(memo[s]==true)
		{
			cout << "No" << '\n';
			return 0;
		}
		memo[s]=true;
		prev = s;
	}
	cout << "Yes" << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i,n) for(int i=0; i<n; i++)
#define M0D 1000000007
using namespace std;
struct animal{
 bool sheep;
 char type;
};
int main(){
 int N;
 cin >> N;
 bool secess=false;
 struct animal line[N+3];
 for(int i=1; i<N+1; i++) cin >> line[i].type;
 line[0].type = line[N].type;
 line[N+1].type = line[1].type;
 line[N+2].type = line[2].type;
 line[0].sheep = true;
 line[1].sheep = true;
 for(int i=1; i<N+3; i++){
   if(line[i].type=='o' && line[i].sheep) line[i+1].sheep = line[i-1].sheep;
   else if(line[i].type=='o' && !line[i].sheep) line[i+1].sheep = !line[i-1].sheep;
   else if(line[i].type=='x' && line[i].sheep) line[i+1].sheep = !line[i-1].sheep;
   else if(line[i].type=='x' && !line[i].sheep) line[i+1].sheep = line[i-1].sheep;
 }
 if(line[0].sheep == line[N].sheep&&line[1].sheep == line[N+1].sheep) secess = true;
 if(!secess){
   line[1].sheep = false;
   for(int i=1; i<N+2; i++){
     if(line[i].type=='o' && line[i].sheep) line[i+1].sheep = line[i-1].sheep;
     else if(line[i].type=='o' && !line[i].sheep) line[i+1].sheep = !line[i-1].sheep;
     else if(line[i].type=='x' && line[i].sheep) line[i+1].sheep = !line[i-1].sheep;
     else if(line[i].type=='x' && !line[i].sheep) line[i+1].sheep = line[i-1].sheep;
   }
   if(line[0].sheep == line[N].sheep&&line[1].sheep == line[N+1].sheep) secess = true;
 }
 if(!secess){
   line[0].sheep = false;
   for(int i=1; i<N+2; i++){
     if(line[i].type=='o' && line[i].sheep) line[i+1].sheep = line[i-1].sheep;
     else if(line[i].type=='o' && !line[i].sheep) line[i+1].sheep = !line[i-1].sheep;
     else if(line[i].type=='x' && line[i].sheep) line[i+1].sheep = !line[i-1].sheep;
     else if(line[i].type=='x' && !line[i].sheep) line[i+1].sheep = line[i-1].sheep;
   }
   if(line[0].sheep == line[N].sheep&&line[1].sheep == line[N+1].sheep) secess = true;
 }
 if(!secess){
   line[1].sheep = true;
   for(int i=1; i<N+2; i++){
     if(line[i].type=='o' && line[i].sheep) line[i+1].sheep = line[i-1].sheep;
     else if(line[i].type=='o' && !line[i].sheep) line[i+1].sheep = !line[i-1].sheep;
     else if(line[i].type=='x' && line[i].sheep) line[i+1].sheep = !line[i-1].sheep;
     else if(line[i].type=='x' && !line[i].sheep) line[i+1].sheep = line[i-1].sheep;
   }
   if(line[0].sheep == line[N].sheep&&line[1].sheep == line[N+1].sheep) secess = true;
 }
 if(!secess) cout << "-1";
 else for(int i=1; i<N+1; i++) cout << (line[i].sheep ? "S" : "W");
 cout << endl;
 return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split("");
        int count = 1;
        for(int i = 0; i < n - 1; i++){
            if(!line1[i].equals(line1[i + 1]))   count++;
        }
        
        
        
        System.out.println(count);
    }
}

Measured memory_bytes: 32580
#include <stdio.h>
#pragma warning(disable : 4996)
int n, d, x, y, e, f; char c[100][101];
const int dx[4] = { 0, 1, 0, -1 };
const int dy[4] = { -1, 0, 1, 0 };
bool ok() {
	for (int i = 0; i < 4; i++) {
		if (i == (e + 2) % 4) continue;
		int ex = x + dx[i];
		int ey = y + dy[i];
		if (0 <= ex && ex < d && 0 <= ey && ey < d) {
			if (c[ey][ex] == '#') {
				return false;
			}
		}
	}
	return true;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &d);
		x = 0, y = d - 1, e = 0, f = 0;
		for (int j = 0; j < d; j++) {
			for (int k = 0; k < d; k++) {
				c[j][k] = ' ';
			}
			c[j][d] = '\0';
		}
		while (f++ < d * d) {
			c[y][x] = '#';
			x += dx[e % 4];
			y += dy[e % 4];
			if (0 <= x && x < d && 0 <= y && y < d) {
				if (!ok()) {
					x -= dx[e % 4];
					y -= dy[e % 4];
					e++;
				}
			}
			else {
				x -= dx[e % 4];
				y -= dy[e % 4];
				e++;
			}
		}
		if (i) printf("\n");
		for (int j = 0; j < d; j++) printf("%s\n", c[j]);
	}
	return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

//#define int long long

/*************** using variables ***************/
int a, b, x;
/**********************************************/

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

    cin >> a >> b >> x;

    if(a+b >= x && a <= x) cout << "YES" << endl;
    else cout << "NO" << endl;
    


}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main() {
	int n;
	cin >> n;
	if (n == 1) {
		cout << "Hello World" << endl;
	}
	else {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
	return 0;
}




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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if ((a == b && b != c) || (b == c && c != a) || (c == a && a != b))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	ll x; cin>>x;
	ll a=100;
	for(int i=1; ; i++){
		a+=a/100;
		if(a>=x){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;


int main()
{
    string s, t;
    int count=0;
    int num;
    cin >> s >> t;

    num = s.size();

    for (int i = 0; i < num; i++) {
        if (s[i] != t[i]) count++;
    }


    cout << count;

    return 0;
}



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

int main(){
	int n;
	while(cin >> n,n){
		int data[10+1][10+1];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> data[i][j];
			}
		}

		int all_sum = 0;

		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = 0; j < n; j++){
				sum += data[i][j];
			}
			data[i][n] = sum;
			all_sum += sum;
		}




		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = 0; j < n; j++){
				sum += data[j][i];
			}
			data[n][i] = sum;
		}
			data[n][n] = all_sum;


		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				printf("%5d", data[i][j]);
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  int x = a.at(n-1);
  vector<int> b(x+1);
  for (int i = 0; i < n; i++) {
    int y = a.at(i);
    b.at(y)++;
  }
  int ans = 0;
  if (x == 0) ans = n;
  else {
  for (int i = 0; i < x+1; i++) {
    int count = 0;
    if (i == 0) {
      count = b.at(i) + b.at(i+1);
    }
    else if (i == x) {
      count = b.at(i-1) + b.at(i);
    }
    else {
      count = b.at(i-1) + b.at(i) + b.at(i+1);
    }
    ans = max(ans, count);
  }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
 
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <climits>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;
 
 
 
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
 
 
//約数をベクトル形式で返す
vector<int> vect_yakusuu(int n) {
	vector<int> ret;
	for (int i = 1; i*i <= n; i++) {
		if (n%i == 0) {
			ret.push_back(i);
			if (i*i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return ret;
}
 
 
 
int main() {
 
	long long N;
    long long A[200100];
    long long ans;

    cin >> N;
    for (int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A,A+N,std::greater<int>());
    ans=0;
    if (N%2==1){
        for (int i=0;i<(N-1)/2+1;i++){
            ans += 2*A[i];
        }
            ans -= A[0];
            ans -= A[(N-1)/2];    
    }
    if (N%2==0){
        for (int i=0;i<N/2;i++){
            ans += 2*A[i];
        }
            ans -= A[0];
    }
    cout << ans << endl;
	cin >> ans;
 
	return 0;
 
 
}

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

    using namespace std;
    typedef long long ll;
    int main()
    {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int n; cin >> n ;
        int x;
        vector<pair<int,int>> v;
        for(int i=0;i<n;i++){
            cin >> x;
            v.push_back(make_pair(x,i));

        }
        sort(v.begin(),v.end());
        for(int i=0;i<v.size();i++){
            cout << v[i].second+1 << " ";
        }cout << endl;



    }


Measured memory_bytes: 1780
#include <iostream>
#define REP(i, a, n) for(int i = a; i <= n; i++)
using namespace std;


int H, W;
char A[10][10];

int main(void) {
  cin >> H >> W;
  REP(i, 0, H - 1) {
    cin >> A[i];
  }

  bool flag = true;
  REP(i, 0, H - 1) {
    REP(j, 0, W - 1) {
      if(i + 1 < H && j + 1 < W && A[i + 1][j] == '#' && A[i][j + 1] == '#')
        flag = false;
    }
  }

  cout << (flag ? "Possible" : "Impossible") << endl;

  return 0;
}


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

using namespace std;


int main(void){
    // Your code here!
    int m1, d1, m2, d2;
    cin >> m1 >> d1;
    cin >> m2 >> d2;
    cout << (m1 != m2 ? 1 : 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<map>
using namespace std;
map<int, int>M[200005];
int main()
{
	int n, m, a, b,i,flag=0;
	while (scanf("%d%d", &n, &m) != EOF) {
		flag = 0;
		for (i = 0; i < m; i++) {
			scanf("%d%d", &a, &b);
			M[a][b] = 1; M[b][a] = 1;
		}
		for (i = 2; i <= n - 1; i++) {
			if (M[1][i] == 1 && M[i][n] == 1) { printf("POSSIBLE\n"); flag = 1; break; }
		}
		if (flag == 0)printf("IMPOSSIBLE\n");
	}
	return 0;
}

Measured memory_bytes: 37760
#include<bits/stdc++.h>
#define ll long long
using namespace std;
map <string,int> mp;
int main(){
//SATSfreopen("test.in","r",stdin);
mp["SUN"]=7;
mp["MON"]=6;
mp["TUE"]=5;
mp["WED"]=4;
mp["THU"]=3;
mp["FRI"]=2;
mp["SAT"]=1;
string s;
cin>>s;
cout<<mp[s];
 return 0;
}


Measured memory_bytes: 384
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val MOD = 1e9.toInt + 7

  val N, K = in.next().toInt

  //
  def repeatSquares(x: Long, n: Int): Long = {
    if(n == 0)
      1
    else if(n % 2 == 0)
      repeatSquares(x*x % MOD, n/2)
    else
      (x * repeatSquares(x*x % MOD, n/2)) % MOD
  }

  val X = new Array[Long](K+1)

  var ans = 0L
  for (i <- (1 to K).reverse) {
    var res = repeatSquares(K / i, N)

    var n = i + i
    while (n <= K) {
      res -= X(n)
      res += MOD
      res %= MOD

      n += i
    }

    X(i) = res
    ans += res * i
    ans %= MOD
  }

  println(ans)
}


class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 54692
N, M = map(int, input().split())
l = [None] * M
for i in range(M):
	p, y = map(int, input().split())
	l[i] = [p, y, i]
l.sort()
ans = []
t = l[0][0]
x = 0
for i in l:
	if t == i[0]:
		x += 1
		ans.append([i[2], i[0], x])
	else:
		t = i[0]
		x = 1
		ans.append([i[2], i[0], x])
ans.sort()
for i in ans:
	p = str(i[1])
	x = str(i[2])
	print('0' * (6 - len(p)) + p + '0' * (6 - len(x)) + x)

Measured memory_bytes: 37820
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int a = Integer.parseInt(br.readLine());
		int b = Integer.parseInt(br.readLine());
		int c = Integer.parseInt(br.readLine());

		System.out.println((a - b) % c);
	}
}


Measured memory_bytes: 21204
#include<iostream>
#include<cstdio>
using namespace std;
const int INF=1000000000;
int N;
int DP1[10001];
int DP2[10001];
int DP3[10001];
int DP4[10001];
int T[10000];
int main()
{
	scanf("%d",&N);
	N=N>>1;
	for(int i=1;i<2*N;i++)scanf("%d",&T[i]);
	for(int i=0;i<=2*N;i++){
		DP1[i]=INF;DP2[i]=INF;DP3[i]=INF;DP4[i]=INF;
	}
	DP1[0]=0;DP2[0]=0;
	for(int i=1;i<=2*N;i++){
		DP3[0]=INF;
		DP4[0]=0;
		DP3[i]=0;
		DP4[i]=INF;
		for(int j=1;j<i;j++){
			DP3[j]=min(DP1[j-1],DP2[j-1]+T[i-1]);
			DP4[j]=min(DP1[j]+T[i-1],DP2[j]);
		}
		for(int j=0;j<=i;j++){
			DP1[j]=DP3[j];
			DP2[j]=DP4[j];
			//printf("1:%d,%d:%d\n",i,j,DP1[j]);
			//printf("2:%d,%d:%d\n",i,j,DP2[j]);
		}
	}
	printf("%d\n",min(DP1[N],DP2[N]));
	return 0;
}

Measured memory_bytes: 1384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ARC065
{
    public class A
    {
        private void Run()
        {
            var S = Console.ReadLine().Trim();
            var can = new bool[S.Length + 1];

            can[0] = true;
            for (int i = 0; i < can.Length; i++)
            {
                if (!can[i]) { continue; }
                if (i + 7 < can.Length)
                {
                    if (S.Substring(i, 7) == "dreamer") { can[i + 7] = true; }
                }
                if (i + 6 < can.Length)
                {
                    if (S.Substring(i, 6) == "eraser") { can[i + 6] = true; }
                }
                if (i + 5 < can.Length)
                {
                    var t = S.Substring(i, 5);
                    if (t == "dream" || t == "erase") { can[i + 5] = true; }
                }
            }

            Console.WriteLine(can[S.Length] ? "YES" : "NO");
        }

        public static void Main()
        {
            var old = Console.Out;
            using (var writer = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Console.SetOut(writer);
                new A().Run();
                Console.Out.Flush();
                Console.SetOut(old);
            }
        }
    }
}


Measured memory_bytes: 6232
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) cout<<"Case #"<<i<<": "
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	int n; cin >> n;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];
	int maxx = 0,ans=0;
	rep(i, 0, n) {
		if (maxx <= a[i]) {
			ans++;
			maxx = a[i];
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  string a1;
  string a2;
  cin >> a1 >> a2;
  bool ok = true;
  for(int i = 0; i < a1.length(); i++) {
    if(a1[i] != a2[a2.length() - i - 1]) {
      ok = false;
    }
  }
  if(ok) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  

}


Measured memory_bytes: 256
S = input()
K = int(input())

def f(S):
    cnt = 0
    t = 0
    for i in range(1, len(S)):
        if S[i-1] == S[i]:
            t += 1
        else:
            t = 0
        if t % 2 == 1:
            cnt += 1
    return cnt

if len(set(S)) == 1:
    l = len(S) * K
    print(l // 2)
elif K < 10:
    print(f(S * K))
else:
    v2 = f(S * 2)
    v3 = f(S * 3)
    print(v3 + (v3-v2) * (K - 3))


Measured memory_bytes: 9124
//     . .. ... .... ..... be name khoda ..... .... ... .. .     \\

#include <bits/stdc++.h>
using namespace std;

inline int in() { int x; scanf("%d", &x); return x; }
const int N = 200002, M = 16;

int a[N], cnt[M];
int dp[1 << M], val[1 << M];

int main()
{
	int n = in();
	for(int i = 1; i < n; i++)
	{
		int u = in(), v = in(), x = in();
		a[u] ^= x;
		a[v] ^= x;
	}
	for(int i = 0; i < n; i++)
		cnt[a[i]]++;
	vector <int> x;
	int reserved = cnt[0];
	cnt[0] = 0;
	for(int i = 0; i < n; i++)
	{
		if(cnt[a[i]] % 2)
			x.push_back(a[i]);
		reserved += cnt[a[i]]/2;
		cnt[a[i]] = 0;
	}
	int m = x.size();
	int tot = (1 << m);
	for(int i = 0; i < tot; i++)
		for(int j = 0; j < m; j++)
			if(i >> j & 1)
				val[i] ^= x[j];
	for(int mask = 1; mask < tot; mask++)
	{
		if(val[mask] != 0)
			continue;
		dp[mask] = 1;
		for(int smask = mask; smask > 0; smask = (smask - 1) & mask)
			if(!val[smask])
				dp[mask] = max(dp[mask], dp[smask] + dp[mask ^ smask]);
	}
	cout << n - dp[tot - 1] - reserved << endl;
}


Measured memory_bytes: 896