akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())

AB = []
for _ in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))

CD = []
for _ in range(M):
    c, d = map(int, input().split())
    CD.append((c, d))


def f(a, b, c, d):
    return abs(a - c) + abs(b - d)


for a, b in AB:
    v, idx = 10**10, 0
    for i, (c, d) in enumerate(CD, start=1):
        # c, d = t
        d = f(a, b, c, d)
        if v > d:
            idx = i
            v = d
    print(idx)


Measured memory_bytes: 3064
#include <cstdio>
#include <map>
#define F(i,x,y) for(int i=x;i<=y;++i)
using namespace std;
map<int,pair<int,int> >m;
int a,b,n;
bool vis[5][5]={false};
int main(){
	F(i,1,3){
		F(j,1,3){
			scanf("%d",&a);
			m[a]=make_pair(i,j); 
		}
	}
	scanf("%d",&n);
	F(i,1,n){
		scanf("%d",&b);
		if(m.find(b)!=m.end()){
			vis[m[b].first][m[b].second]=true;
		}
	}
	F(i,1,3){
		if(vis[i][1]&&vis[i][2]&&vis[i][3]){
			printf("Yes\n");
			return 0;
		}
	}
	F(i,1,3){
		if(vis[1][i]&&vis[2][i]&&vis[3][i]){
			printf("Yes\n");
			return 0;
		}
	}
	if(vis[1][1]&&vis[2][2]&&vis[3][3]){
		printf("Yes\n");
		return 0;
	}
	if(vis[1][3]&&vis[2][2]&&vis[3][1]){
		printf("Yes\n");
		return 0;
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

right = H[-1]
for i in range(N - 2, -1, -1):
    if right >= H[i]:
        right = H[i]
        continue
    elif right + 1 == H[i]:
        H[i] -= 1
        right = H[i]
    else:
        print("No")
        break
else:
    print("Yes")


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

using namespace std;

int main() {
int n;
cin >> n;
string a[n];
for(int i=0; i<n; i++) {
    cin >> a[i];
}
set<string>f;
for(int j=0; j<n; j++) {
    f.insert(a[j]);
}
cout << f.size();
  return 0;
}



Measured memory_bytes: 25440
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#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 FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
string s;
bool dfs(int index) {
  if(index == s.length()) return true;
  if(s[index] == 'd') {
    if(s.substr(index, 5) == "dream") {
      if(dfs(index + 5)) return true;
    }
    if (s.substr(index, 7) == "dreamer") {
      if(dfs(index + 7)) return true;
    }
  } else if(s[index] == 'e') {
    if(s.substr(index, 5) == "erase") {
      if(dfs(index + 5)) return true;
    }
    if (s.substr(index, 6) == "eraser") {
      if(dfs(index + 6)) return true;
    }
  }
  return false;
}

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

  cin >> s;

  cout << (dfs(0) ? "YES" : "NO")<< endl;
}


Measured memory_bytes: 1872
n, d = gets.split.map(&:to_i)
points = n.times.map { gets.split.map(&:to_i) }

ans = 0
points.combination(2).each do |a, b|
  dist = 0
  d.times do |i|
    dist += (a[i] - b[i]).abs**2
  end
  ans += 1 if Math.sqrt(dist) == Math.sqrt(dist).to_i
end

puts ans

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 2e18
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main()
{
          int n;
          cin>>n;
          map<string,int> mp;
          int t[n];
          fri(i,0,n){
                    string s;
                    cin>>s;
                    cin>>t[i];
                    mp[s]=i;
          }
          string ss;
          cin>>ss;
          ll ans = 0;
          int ii = mp[ss]+1;
          while(ii<n){
                    ans += t[ii];
                    ii++;
          }
          cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long
#define INF 100000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

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

ll int gcd(ll int m, ll int n) {
  if (m == 0) {
    return n;
  } 
  if (n == 0) {
    return m;
  }

  if (m >= n) {
    return gcd(m%n, n);
  } else {
    return gcd(m, n%m);
  }
}


ll a, b, c, d;
set<ll> uni;

int main () {
  cin >> a >> b >> c >> d;

  ll amari1 = a % c;
  ll start1 = (amari1 == 0) ? a : a + (c - amari1);
  amari1 = b % c;
  ll end1 = (amari1 == 0) ? b : (b - amari1);
  ll ans1 = (end1 >= start1) ? (end1 - start1) / c + 1 : 0;

  ll amari2 = a % d;
  ll start2 = (amari2 == 0) ? a : a + (d - amari2);
  amari2 = b % d;
  ll end2 = (amari2 == 0) ? b : (b - amari2);
  ll ans2 = (end2 >= start2) ? (end2 - start2) / d + 1 : 0;

  ll amari3 = a % (c * d / gcd(c, d));
  ll start3 = (amari3 == 0) ? a : a + ((c*d / gcd(c, d)) - amari3);
  amari3 = b % (c*d / gcd(c, d));
  ll end3 = (amari3 == 0) ? b : (b - amari3);
  ll ans3 = (end3 >= start3) ? (end3 - start3) / (c * d / gcd(c, d)) + 1 : 0;

  cout << (b - a + 1) - (ans1 + ans2 - ans3) << "\n";
  //cout << ans1 << "\n";
  //cout << ans2 << "\n";
  //cout << ans3 << "\n";
}

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

using namespace std;

int n,i,j;
pair <int, int> a[100005];
long long k;

int main(){
	scanf("%d%lld", &n, &k);
	
	for(i = 0; i < n; i++)
	scanf("%d%d", &a[i].first, &a[i].second);
	
	long long res = 0;
	k++;
	
	for(i = 30; i >= 0; i--){
		if(k & (1LL << i)){
			long long mask = k >> (i + 1);
			mask *= (1LL << (i + 1));
			mask += (1LL << i) - 1;
			long long s = 0;
			
			for(j = 0; j < n; j++){
				if(((1LL * a[j].first) | mask) == mask)
				s += a[j].second;
			}
			
			res = max(res, s);
		}
	}
	
	printf("%lld\n", res);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
 
int N;
int sum;
int T[50];
 
bool dp[51][2501][2501];
int ans = 1e9;
void dfs(int k,int x1,int x2){
    int x3 = sum - x1 - x2;
 
    //cout << x1 << " " << x2 << " " << x3 << endl;
    ans = min(ans,max({x1,x2,x3}));
    if( k == N ) return;
     
    if( dp[k][x1][x2] ) return;
 
    dp[k][x1][x2] = true;
    dfs(k+1,x1+T[k],x2);
    dfs(k+1,x1,x2);
     
    dfs(k+1,x1,x2+T[k]);
 
 
}
 
int main(){
    cin >> N;
    for(int i = 0 ;i < N ; i++){
        cin >> T[i];
        sum += T[i];
    }
    dfs(0,0,0);
    cout << ans << endl;
 
}

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



int main(){
  int L, R, d;
  cin >> L>> R>> d;
  int i = 1;
  int ans = 0;
  while(i*d<=R){
    if(i*d>=L){
      ans++;
      
    }
    i++;
  }
  
  cout <<ans<< endl;
}

      
  
  



Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int ,int>::iterator sit;
const int mod = 1e9 + 7, N = 1000000;
int f[N][2][2][2];
int main() {
	LL n; scanf("%lld",&n);
	f[60][1][1][0] = 1;
	int ans = 0;
	dep(i,60,1) rep(d1,0,1) rep(d2,0,1) rep(d,0,1) if (f[i][d1][d2][d]) { 
		rep(nd,0,2) rep(dd,0,1) {
			int xd = nd & 1, jd = (nd + dd) & 1, c = n >> (i - 1) & 1;
			if ((nd + dd) / 2 != d) continue;
			if (d1 && xd > c) continue;
			if (d2 && jd > c) continue;
			int D1 = d1 && (xd == c), D2 = d2 && (jd == c);
			( f[i - 1][D1][D2][dd] += f[i][d1][d2][d] ) %= mod;
			if (i == 1 && !dd) (ans += f[i][d1][d2][d]) %= mod;
		}
	}
	if (ans < 0) ans += mod;
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long N,L,b = 1e9,c,d = 0;
    cin >> N >> L;    
    for(int i = 0; i < N; i++){
        d += L + i;
       b = min(b,abs(L + i));
       if(b == abs(L + i)){
           c = L + i;
       }
    }
    cout << d - c << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int a, b;

	scanf("%d%d", &a, &b);

	if ( a < b ) {
		printf("a < b\n");
	}
	else if (a > b) {
		printf("a > b\n");
	}
	else {
		printf("a == b\n");
	}

	return 0;

}



Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
int N, M, K;
vector<int> nakama;

class UnionFind {
public:
    vector <int> par; // 各元の親を表す配列
    vector <int> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(int sz_): par(sz_), siz(sz_, 1) {
        for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    
    void init(int sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);  // resize だとなぜか初期化されなかった
        for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    int root(int x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }
    
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool same(int x, int y) { // 連結判定
        return root(x) == root(y);
    }

    int size(int x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

 

int main() {
    cin >> N >> M;
    vector<int> p(N);
    UnionFind Uni(N);
    int a, b;
    int ans=0;

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



    for(int i=0; i<M; i++){
	cin >> a >> b;
	a--;
	b--;
	Uni.merge(a, b);
    }
    for(int i=0; i<N; i++){
	if(Uni.same(p[i], i))
	    ans++;
    }
    cout << ans << endl;

}



Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define int long  long
#define double long double
int t,l,r,d;
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    t=1;
   // cin>>t;
    while(t--)
    {
        cin>>l>>r>>d;
        int ans=0;
        for(int i=l;i<=r;i++)
        {
            if(i%d==0) ans++;
        }
        cout<<ans<<endl;
    }
}


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

int main() {
  int N,K;
  cin >> N >> K;
  set<int> s;
  rep(i,K){
    int d;
    cin >> d;
    rep(j,d){
      int A;
      cin >> A;
      s.insert(A);
    }
  }
  cout << (N-s.size()) << endl;
  return 0;
}

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    for (int i = 0; i < h; i++)
        cin >> a.at(i);
    for (int j = 0; j < w+2; j++)
        cout << "#";
    cout << "\n";
    for (int i = 0; i < h; i++)
        cout << "#" << a.at(i) << "#" << endl;
    for (int j = 0; j < w+2; j++)
        cout << "#";
    cout << "\n";
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 5005;

int a[N], b[N], c[N];
int d[N], e[N], f[N];
ll sz[N][N];
bool lef[N][N], rig[N][N], up[N][N], dow[N][N];
bool vis[N][N];

queue<pii> bf;
int is, js;

vector<int> ii, jj;

void add(int ii ,int jj){
  if(ii < 0 || ii >= is - 1 || jj < 0 || jj >= js - 1){
    cout << "INF\n";
    exit(0);
  } 
  if(vis[ii][jj]) return;
  vis[ii][jj]=true;
  bf.push(mp(ii,jj));
}

int main(){
  fastIO;
  int n, m;
  cin >> n >> m;
  for(int i = 0 ; i < n ; i ++ ){
    cin >> a[i] >> b[i] >> c[i];
    jj.push_back(c[i]);
    ii.push_back(a[i]);
    ii.push_back(b[i]);
  }
  for(int i = 0 ; i < m ; i ++ ){
    cin >> d[i] >> e[i] >> f[i];
    ii.push_back(d[i]);
    jj.push_back(e[i]);
    jj.push_back(f[i]);
  }
  ii.push_back(-(int)2e9);
  ii.push_back(0);
  ii.push_back((int)2e9);
  jj.push_back(-(int)2e9);
  jj.push_back(0);
  jj.push_back((int)2e9);
  sort(ii.begin(), ii.end());
  sort(jj.begin(), jj.end());
  ii.resize(unique(ii.begin(), ii.end()) - ii.begin());
  jj.resize(unique(jj.begin(), jj.end()) - jj.begin());
  is = ii.size();
  js = jj.size();
  for(int i = 0 ; i + 1 < is ; i ++ ){
    for(int j = 0 ; j + 1 < js; j ++ ){
      lef[i][j]=rig[i][j]=up[i][j]=dow[i][j]=true;
      sz[i][j]=(ii[i+1]-ii[i])*1ll*(jj[j+1]-jj[j]);
    }
  }
  int l, r, cm;
  for(int i = 0 ; i < n; i ++ ){
    l = lower_bound(ii.begin(), ii.end(), a[i]) - ii.begin();
    r = lower_bound(ii.begin(), ii.end(), b[i]) - ii.begin();
    cm = lower_bound(jj.begin(), jj.end(), c[i]) - jj.begin();
    for(int k = l; k < r; k ++ ){
      rig[k][cm-1]=lef[k][cm]=false;
    }
  }
  for(int i = 0 ; i < m ; i ++ ){
    l = lower_bound(jj.begin(), jj.end(),e[i])-jj.begin();
    r = lower_bound(jj.begin(), jj.end(),f[i])-jj.begin();
    cm = lower_bound(ii.begin(), ii.end(),d[i])-ii.begin();
    for(int k = l ; k < r; k ++ ){
      dow[cm][k]=up[cm-1][k]=false;
    }
  }
  int ic, jc;
  ic=lower_bound(ii.begin(), ii.end(),0)-ii.begin();
  jc=lower_bound(jj.begin(), jj.end(),0)-jj.begin();
  add(ic,jc);
  add(ic-1,jc);
  add(ic,jc-1);
  add(ic-1,jc-1);
  while(!bf.empty()){
    ic=bf.front().fi;
    jc=bf.front().se;
    bf.pop();
    if(lef[ic][jc]) add(ic,jc-1);
    if(rig[ic][jc]) add(ic,jc+1);
    if(up[ic][jc]) add(ic+1,jc);
    if(dow[ic][jc]) add(ic-1,jc);
  }
  ll ans = 0;
  for(int i = 0 ; i + 1 < is; i ++ ){
    for(int j = 0 ; j + 1 < js; j ++ ){
      if(vis[i][j])ans += sz[i][j];
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 159372
#include <vector>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <functional>

const int INF = 2001001000;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

typedef pair<int,int> P;

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

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

int main(){
  string s;
  int k;
  char tmp;

  cin >> s;

  /*
  k = s.size()/2;
  for( int i = s.size()/2 + s.size()%2; i < s.size()+1; ++i){
    tmp = s[s.size()-i];
    for( int j = 0; j < i*2-s.size(); ++j){
      if( s[j+s.size()-i] == tmp){
        if( j == i*2-s.size()-1){
          k = i;
        }
      }else{
        i = s.size()+1;
      }
    }
  }
  */

  int min = s.size();
  for( int i = 0; i < s.size()-1; ++i){
   if( s[i] != s[i+1]){
     k = i+1;
     if( min > max( k, s.size()-k)){
       min = max( k, s.size()-k);
     }
   }
 }

 k = min;

  cout << k << endl;
}


Measured memory_bytes: 512
from fractions import gcd
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
left = [A[0]] * N
right = [A[-1]] * N
for i in range(1, N):
    left[i] = gcd(left[i-1], A[i-1])
for i in range(1, N)[::-1]:
    right[i-1] = gcd(right[i], A[i])
ans = max(right[0], left[-1])
for i in range(1, N-1):
    ans = max(ans, gcd(left[i], right[i]))
print(ans)


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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define _P(...) (void)fprintf(stderr, __VA_ARGS__)

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
 
	cin.tie(0); ios_base::sync_with_stdio(false);
	int k;
	cin >>k;
	
	vector<vector<pii>> r(k);
		if(k==1){puts("0"); return 0;}
	rep(i, k){
		r[i].emplace_back((i+1)%k, 1);
		r[i].emplace_back((i*10)%k, 0);
	}
	
	VI dd(k, mod);
	
	deque<int> que;
	que.push_back(1); dd[1] =1;
	while(sz(que)>0){
		int cr = que.front();
		que.pop_front();
		for(auto x: r[cr]){
			//dbg("cr=",cr,x.first,x.second);
			if(dd[x.first] > dd[cr] + x.second){
				if(x.second >0) que.push_back(x.first);
				else que.push_front(x.first);
				dd[x.first] = dd[cr] + x.second;
			}
		}
	}
	cout << dd[0] <<endl;
	return  0;
}

Measured memory_bytes: 6272
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 
#define ALL(a)  (a).begin(),(a).end()



using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int a, int b)
{
  if(a>b){
    return gcd(b,a);
  }
	return a == 0 ? b : gcd(b % a, a);
}
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}

long long kaijo(long long x){
  long long l=10*10*10*10*10*10*10*10*10+7;
  long long sum=1;
  for(int i=x;i>0;i--){
    sum*=i;
    if(sum>l){
      sum%=l;
    }
  }
  return sum;
}






int main(){
  string s;
  cin>>s;
  int a[26];
  for(int i=0;i<26;i++){
    a[i]=0;

  }
  for(int i=0;i<s.size();i++){
    a[s[i]-'a']++;
  }
  char x;
  bool ok=false;
  for(int i=0;i<26;i++){
    if(a[i]==0){
      x=(char)i+'a';
      break;
    }
    if(i==25){
      ok=true;
    }
  }
  if(s=="zyxwvutsrqponmlkjihgfedcba"){
    cout<<-1<<endl;
  }
  else if(s.size()==26){
    for(int i=0;i<26;i++){
      a[i]=0;
    }
    int tmp=0;
    for(int i=0;i<s.size()-1;i++){
      if(s[i]<s[i+1]){
        tmp=i;
        
        
        

      }
    }
    for(int i=tmp;i<s.size();i++){
      a[s[i]-'a']++;
    }
    char x;
    for(int i=0;i<26;i++){
      if(a[i]>0){
        if((char)i+'a'>s[tmp]){
        x=(char)(i+'a');
        break;}
        
      }
    }
    
    cout<<s.substr(0,tmp)+x<<endl;

  }else{
    cout<<s+x<<endl;
  }


}





  
  


  

Measured memory_bytes: 256
import math

d, g = map(int, input().split())
p, c = [], []
for i in range(d):
    pi, ci = map(int, input().split())
    p.append(pi)
    c.append(ci)
compl = [100 * (i+1) * p[i] + c[i] for i in range(d)]

ans = 1e9
for i in range(2 ** d):
    score = num = 0
    for j in range(d):
        if (i >> j) & 1:
            score += compl[j] 
            num += p[j] 
        else:
            # index of highest rest valuable p.
            rest_idx = j
    if score < g:
        need = math.ceil((g - score) / (100 * (rest_idx + 1)))
        if need >= p[rest_idx]:
            continue
        num += need
    ans = min(ans, num)
print(ans)


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

void printarray(int A[], int len) {
	for (int i = 0; i < len - 1; i++) {
		cout << A[i] << " ";
	}
	cout << A[len - 1] << endl;
}

int main() {
	int N;
	cin >> N;
	int A[N];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 1; i < N; i++) {
		printarray(A, N);
		int v = A[i];
		int j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
	}
	printarray(A, N);
	return 0;
}



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

int main() {
  
  int N; cin >> N;
  
  vector<int> vec(N);
  
  for (int i = 0; i < N - 1; i++) {
    int A; cin >> A;
    vec[A - 1]++;
  }
  
  for (int x : vec) cout << x << endl;
  
}

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt() - (i + 1);
        }
        Arrays.sort(a);
        int aHalf = (n - 1) / 2 ;
        long ans = 0 ;
        for (int i = 0 ; i < n ; i++) {
            ans += (long) Math.abs(a[i] - a[aHalf]);
        }
        System.out.println(ans);

    }

}

Measured memory_bytes: 66096
#include<stdio.h>
int main(void){
  int x,y;
  while(1){
 scanf("%d %d",&x,&y);
 if ( x == 0 && y == 0 ) break;
 if(x<y){
   printf("%d %d\n",x,y);
 }else{
   printf("%d %d\n",y,x);
 } 
  }
  return 0;
}



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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - ι⊥l
            var line = ReadLine();
            int a = line[0];
            int b = line[1];
            int c = line[2];

            if (b - a == c - b)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define ITR(v, i) for(auto ite = v.begin(); ite != v.end(); ite++)
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vl A(n, 0);
    rep(i, n - 1) {
        cin >> x;
        x--;
        A[x]++;
    }

    rep(i, n) { cout << A[i] << endl; }
}

Measured memory_bytes: 4780
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] h = in.nextIntArray(n);

            boolean[][] s = new boolean[101][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j <= h[i]; j++) {
                    s[j][i] = true;
                }
            }

            int ans = 0;
            for (int i = 1; i <= 100; i++) {
                for (int j = 0; j < n; j++) {
                    if (s[i][j]) {
                        ans++;
                        while (j < n - 1 && s[i][j]) j++;
                    }
                }
            }

            out.println(ans);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

    }
}



Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n,m;
  cin >> n >> m;
  int a[n][m];
  rep(i,n) rep(j,m){
    cin >> a[i][j];
    a[i][j]--;
  }
  int ub=n;
  int lb=0;
  while(ub-lb>1){
    int	mid=(ub+lb)/2;
    set<int> unuse;
    while(1){
      int par[m];
      rep(i,m) par[i]=0;
      rep(i,n){
	rep(j,m){
	  if(unuse.count(a[i][j])==0){                                  
	    par[a[i][j]]++;
	    break;
	  }                                                             
	} 
      }
      int end=0;
      rep(i,m){
	if(par[i]>mid) unuse.insert(i);
	else end++;
      }
      if(end==m){
	ub=mid;
	break;
      }
      else if(unuse.size()==m){
	lb=mid;
	break;
      }
    }
  }
  cout << ub << endl;
  
  return 0;
    

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}
// head

int x,s,t,m,n,k,res;
int a[501000] = {};
int b[501000] = {};
int c[501000] = {};
vector<PII> g[500010];
queue<int> que;
queue<int> que2;
priority_queue<PII> pque;
//string s;

signed main() {
	std::cin >>n>>m>>s;
	rep(i,0,m){
		std::cin >> a[i]>>b[i]>>c[i];
//		b[i]--,a[i]--;
		g[a[i]].pb(mp(b[i], c[i]));
//		g[b[i]].pb(mp(a[i], c[i]));
	}
	int d[100005];
	rep(i,0,n) d[i] = 1LL<<50;
	d[s] = 0;
	pque.push({0,s});
	while (!pque.empty()){
		PII p = pque.top();pque.pop();
		int prov_cost = p.first;
		int src = p.second;
		if(d[src]<prov_cost) continue;
		rep(i,0,g[src].size()){
			int dest = g[src][i].first;
			int weight = g[src][i].second;
			if ((d[dest] > d[src] + weight)){
				d[dest] = d[src] + weight;
				pque.push({-d[dest],dest});
			}
		}
	}
	rep(i,0,n){
		if(d[i] != 1LL<<50){
		std::cout << d[i] << '\n';
	}
	else{
		std::cout << "INF" << '\n';
	}
	}
}



Measured memory_bytes: 40268
class Factorial():
    def __init__(self, mod=10**9 + 7):
        self.mod = mod
        self._factorial = [1]
        self._size = 1
        self._factorial_inv = [1]
        self._size_inv = 1

    def __call__(self, n):
        return self.fact(n)

    def fact(self, n):
        ''' n! % mod '''
        if n >= self.mod:
            return 0
        self._make(n)
        return self._factorial[n]
    
    def _make(self, n):
        if n >= self.mod:
            n = self.mod
        if self._size < n+1:
            for i in range(self._size, n+1):
                self._factorial.append(self._factorial[i-1]*i % self.mod)
            self._size = n+1

    def fact_inv(self, n):
        ''' n!^-1 % mod '''
        if n >= self.mod:
            raise ValueError('Modinv is not exist! arg={}'.format(n))
        self._make(n)
        if self._size_inv < n+1:
            self._factorial_inv += [-1] * (n+1-self._size_inv)
            self._size_inv = n+1
        if self._factorial_inv[n] == -1:
            self._factorial_inv[n] = self.modinv(self._factorial[n])
        return self._factorial_inv[n]
    
    @staticmethod
    def xgcd(a, b):
        '''
        Return (gcd(a, b), x, y) such that a*x + b*y = gcd(a, b)
        '''
        x0, x1, y0, y1 = 0, 1, 1, 0
        while a != 0:
            (q, a), b = divmod(b, a), a
            y0, y1 = y1, y0 - q * y1
            x0, x1 = x1, x0 - q * x1
        return b, x0, y0

    def modinv(self, n):
        g, x, _ = self.xgcd(n, self.mod)
        if g != 1:
            raise ValueError('Modinv is not exist! arg={}'.format(n))
        return x % self.mod

    def comb(self, n, r):
        ''' nCr % mod '''
        if r > n:
            return 0
        t = self(n)*self.fact_inv(n-r) % self.mod
        return t*self.fact_inv(r) % self.mod
    
    def comb_(self, n, r):
        '''
        nCr % mod
        when r is not large and n is too large
        '''
        c = 1
        for i in range(1, r+1):
            c *= (n-i+1) * self.fact_inv(i)
            c %= self.mod
        return c

    def comb_with_repetition(self, n, r):
        ''' nHr % mod '''
        t = self(n+r-1)*self.fact_inv(n-1) % self.mod
        return t*self.fact_inv(r) % self.mod

    def perm(self, n, r):
        ''' nPr % mod '''
        if r > n:
            return 0
        return self(n)*self.fact_inv(n-r) % self.mod

n, k = map(int, input().split())
mod = 10**9 + 7
comb = Factorial().comb

for i in range(1, k+1):
    print(comb(n-k+1, i)*comb(k-1, i-1) % mod)

Measured memory_bytes: 9208
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if i == 0 or i == (H - 1) or j == 0 or j == (W - 1):
                print('#', end='')
            else:
                print('.', end='')
        print()
    print()


Measured memory_bytes: 7008
#include<iostream>
    #include<cstdio>
    #include<vector>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    int main()
    {
        int n;
      	cin>>n;
        vector<ll> as(n),bs(n),cs(n);
        vector<ll> ss(n),ss2(n);
        int i,j;
        for(i=0;i<n;i++)
            cin>>as[i];
        for(i=0;i<n;i++)
            cin>>bs[i];
        for(i=0;i<n;i++)
            cin>>cs[i];
        sort(as.begin(),as.end());
        sort(bs.begin(),bs.end());
        sort(cs.begin(),cs.end());
        ll s=0;
        for(j=n-1,i=n-1;i>=0;i--)
        {
            s += 1;
            while(j>=0 && cs[i]<=bs[j])
            {
                ss[j] = s-1;
                j--;
            }
        }
        for(;j>=0;j--)
            ss[j] = s;
        s = 0;
        for(j=n-1,i=n-1;i>=0;i--)
        {
            s += ss[i];
            while(j>=0 && bs[i]<=as[j])
            {
                ss2[j] = s-ss[i];
                j--;
            }
        }
        for(;j>=0;j--)
            ss2[j] = s;
        s = 0;
        for(i=0;i<n;i++)
            s += ss2[i];
        cout<<s<<endl;
        return 0;
    }

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

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  ll x, y;
  cin >> x >> y;

  rep(i, x + 1) {
    ll j = x - i;
    ll sum = i * 2 + j * 4;
    if (sum == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<utility>
#include<queue>
using namespace std;

int H, W, snd[1001][1001], ans = 0, scnt = 0;
queue<pair<int, int>> q;

bool Is_inmap(int i, int j) {
	bool jud = true;
	if (i < 0 || j < 0) jud = false;
	if (i >= H || j >= W) jud = false;
	return jud;
}

int main() {
	//input
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			char C;  cin >> C;
			if (C == '.') {
				snd[i][j] = -1;
				q.push({ i, j });
			}
			else snd[i][j] = C - 48;
		}
	}
	q.push({ -1, -1 });
	while (!q.empty()) {
		pair<int, int> tp = q.front(); q.pop();
		int I = tp.first, J = tp.second; 
		if(I == -1 && J == -1){
			/*
			cout << endl << "ans = " << ans << endl;
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					cout << (snd[i][j] == -1 ? 0 : snd[i][j]);
				}
				cout << endl;
			}
			cout << endl;
			*/
			if (scnt) {
				scnt = 0;
				q.push({ -1, -1 });//new wave
			}
			else break;//no change
			ans++;//end of wave
		}
		for (int i = -1; i <= 1; i++) {
			for (int j = -1; j <= 1; j++) {
				int ni = I + i, nj = J + j;
				if (!Is_inmap(ni, nj)) continue;
				if (snd[ni][nj] > 0) {
					snd[ni][nj]--;
					if (snd[ni][nj] == 0) {
						snd[ni][nj]--;
						scnt++;
						q.push({ ni, nj });
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7160
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
using namespace std;
int n,m,ans;
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&m);
		if (i&1 && m&1) ans++;	
	} 
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
#define int long long 
using namespace std;


signed main() {
  int N, K;
cin >> N >> K;

int ans = 0;
for( int b = 1; b <= N; b++ ){
ans += max(0LL, b-K) * (N/b);
ans += max(0LL, (N%b)-K+1);
}

if( K == 0 ) ans -= N;

cout << ans << endl;
}
  

  

  

  



Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	ar := make(map[string]int, n)
	for i:=0; i<n; i++ {
		var v string
		fmt.Scan(&v)
		ar[v]++
	}

	l := len(ar)

	if l <= k {
		fmt.Println(0)
		return
	}

	ai := make([]int, l)
	ii := 0
	for _, v := range ar {
		ai[ii] = v
		ii++
	}

	sort.Ints(ai)

	cnt := 0
	for i:=0; i<l-k; i++ {
		cnt += ai[i]
	}

	fmt.Println(cnt)
}

Measured memory_bytes: 19840
package main

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

// D
var (
	D int
	c [26]int
	s [][26]int
)

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	defer flush()

	D = readInt()
	for i := 0; i < 26; i++ {
		c[i] = readInt()
	}
	s = make([][26]int, D)
	for d := 0; d < D; d++ {
		for i := 0; i < 26; i++ {
			s[d][i] = readInt()
		}
	}

	t := make([]int, D)
	for d := 0; d < D; d++ {
		t[d] = readInt() - 1
	}

	M := readInt()
	for m := 0; m < M; m++ {
		d := readInt() - 1
		q := readInt() - 1
		t[d] = q
		last := make([]int, 26)
		S := 0
		for i := 0; i < 26; i++ {
			last[i] = -1
		}
		for d := 0; d < len(t); d++ {
			S += s[d][t[d]]
			last[t[d]] = d
			for i := 0; i < 26; i++ {
				S -= c[i] * (d - last[i])
			}
		}
		println(S)
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


Measured memory_bytes: 4328
n = int(input())
message = [[] for _ in range(n)]
for i in range(n):
  a = int(input())
  for j in range(a):
    message[i].append([int(x) for x in input().split()])
ans = 0
for i in range(2**n):
  key = [0]*n
  sub = 0
  flag = True
  for j in range(n):
    if (i >> j) & 1:
      key[j] = 1
      sub += 1
  
  for j in range(n):
    if key[j] == 0:
      continue
    for k in range(len(message[j])):
      pq = message[j][k]
      p, q = pq[0], pq[1]
      if key[p-1] == q:
        continue
      else:
        flag = False
        break
    if not flag:
      break
  
  if flag and ans < sub:
    ans = sub

print(ans)




Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,k;
  cin >> n >> k;
  map<int,int64_t>kazu;
  int a,b;
  for(int i=0;i<n;i++){
    cin >> a >> b;
    kazu[a]+=b;
  }
  int64_t ans=0,c=0;
  for(auto x:kazu){
    c+=x.second;
    if(c>=k){
      ans=x.first;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7396
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let mut ans = vec![0; n];
    for i in 1..=n {
        ans[read::<usize>()-1] = i;
    }
    for i in ans {
        print!("{} ", i);
    }
    println!("");
}

Measured memory_bytes: 2776
#include <iostream>
#include <vector>
using namespace std;
const int INF = 1e9;

int main(){
  string s, t;
  cin >> s >> t;
  int n = s.length(), m = t.length();
  vector< vector<int> > DP(n+1, vector<int>(m+1,INF));
  DP[0][0] = 0;
  for(int i = 0; i <= n; ++i){
    for(int j = 0; j <= m; ++j){
      if(i > 0) DP[i][j] = min(DP[i][j], DP[i-1][j] + 1);
      if(j > 0) DP[i][j] = min(DP[i][j], DP[i][j-1] + 1);
      if(i > 0 && j > 0)
        DP[i][j] = min(DP[i][j], DP[i-1][j-1] + !(s[i-1] == t[j-1]));
    }
  }
  cout << DP[n][m] << endl;
  return 0;
}



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

public class Hello
{
    public static void Main()
    {
        var d = new Dictionary<int, List<int>>();
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var W = int.Parse(line[1]);
        var minw = 1000000001;
        for (int i = 0; i < n; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var w = int.Parse(line[0]);
            minw = Math.Min(minw, w);
            var v = int.Parse(line[1]);
            if (d.ContainsKey(w)) d[w].Add(v);
            else
            {
                d[w] = new List<int>();
                d[w].Add(v);
            }
        }
        var amax = new int[4];
        amax[0] = d[minw].Count();
        for (int i = 1; i <= 3; i++)
            if (d.ContainsKey(minw + i)) amax[i] = d[minw + i].Count();
        foreach (var x in d) d[x.Key].Sort();
        var t = 0L; var ret = 0L;
        for (long i = 0; i <= amax[0]; i++)
            for (long j = 0; j <= amax[1]; j++)
                for (long k = 0; k <= amax[2]; k++)
                    for (long L = 0; L <= amax[3]; L++)
                    {
                        if (i * minw + j * (minw+1) + k *(minw + 2) + L * (minw + 3) <= W)
                            t = getW(d, i, minw) + getW(d, j, minw + 1) + getW(d, k, minw + 2) + getW(d, L, minw + 3);
                        ret = Math.Max(t, ret);
                    }
        Console.WriteLine(ret);
    }
    public static long getW(Dictionary<int, List<int>> d, long a, int k)
    {
        if (a == 0) return 0;
        var ret = 0L;
        var dL = d[k].Count();
        for (int i = 0; i < a; i++)
            ret += d[k][dL - 1 - i];
        return ret;
    }
}



Measured memory_bytes: 13280
#input
inpnum = int(input())

#下二桁
simo = inpnum % 100
#上二桁
kami = inpnum // 100

#入れ替え
swapflag = 0
if kami >= simo :
    kami, simo = simo, kami
    swapflag = 1
#判定
if kami == 0:
    if 1 <= simo <= 12 and swapflag == 0:
        print("YYMM")
    elif  1 <= simo <= 12 and swapflag == 1:
        print("MMYY")
    else:
        print("NA")

if 1 <= kami <= 12:
    if 1 <= simo <= 12:
        print("AMBIGUOUS")
    elif 13 <= simo and swapflag == 0:
        print("MMYY")
    elif 13 <= simo and swapflag == 1:
        print("YYMM")

if 13 <= kami:
    print("NA")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

msi big,small;
msitr itr;
msi :: reverse_iterator ritr;
int q;
ll ans,co;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>q;
    for(int i=1;i<=q;i++){
        int type,a,b;
        cin>>type;
        if(type==1){
            cin>>a>>b;
            co+=b;
            big.insert(a);small.insert(a);
            int tempa,tempb;
            tempa = *big.rbegin();
            tempb = *small.begin();

            if(tempa>tempb){
                ans += abs(tempa-tempb);
                ritr = big.rbegin();
                big.erase(big.find(*ritr));
                small.erase(small.begin());
                swap(tempa,tempb);
                big.insert(tempa);
                small.insert(tempb);
            }
        }
        else{
            ritr = big.rbegin();
            cout<<*ritr<<" "<<ans + co<<newl;
        }
    }
}


Measured memory_bytes: 19072
N = int(input())
h = list(map(int, input().split()))
DP = [10000]*N
DP[0] = 0
DP[1] = abs(h[1]-h[0])
for i in range(N-1):
  DP[i+1] = abs(h[i+1]-h[i])+DP[i]
  if i > 0:
    DP[i+1] = min(abs(h[i+1]-h[i])+DP[i], abs(h[i+1]-h[i-1])+DP[i-1])
print(DP[N-1])


Measured memory_bytes: 13924
#include<bits/stdc++.h>
using namespace std;
int main(){
  string w;cin>>w;
  map<char,int>mp;
  for(int i=0;i<w.size();i++)mp[w[i]]++;
  string ans="Yes";
  for(auto x:mp){
    if(x.second%2!=0){
      ans="No";
      break;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N, M; cin >> N >> M;
	multiset<ll> A; for (ll i = 0; i < N; ++i) {ll a; cin >> a; A.insert(a);}

	for (ll i = 0; i < M; ++i)
	{
		auto tmp = prev(A.end());
		A.erase(tmp);
		A.insert(*tmp/2);
	}
	std::cout << accumulate(A.begin(), A.end(), 0ll) << std::endl;
}

Measured memory_bytes: 4992
///*
#include<iostream>
using namespace std;

int main() {

	int a, b, c;
	cin >> a >> b >> c;

	if (a + b == c || a + c == b || b + c == a) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}
//*/

Measured memory_bytes: 256