akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main () {
	int n, m; cin >> n >> m;
	vector<int> in(m,0);
	for (int i = 0; i < m; i++)
		cin >> in[i];
	sort(in.begin(), in.end());
	vector<int> diffs;
	for (int i = 1; i < m; i++)
		diffs.push_back(in[i]-in[i-1]);	
	sort(diffs.begin(),diffs.end());
	int ans = 0;
	for (int i = 0; i < m-n; i++)
		ans += diffs[i];
	cout << ans << endl;
	return 0;
}

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

#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}
ll LCM(ll x, ll y){
	return x/GCD(x, y)*y;
}

int main() {
	int n, m, c; cin >> n >> m >> c;
	int b[30];
	rep(i, 0, m) cin >> b[i];
	int a[30][30];
	rep(i, 0, n){
		rep(j, 0, m) cin >> a[i][j];
	}
	int ans = 0;
	rep(i, 0, n){
		int val = c;
		rep(j, 0, m){
			val += a[i][j]*b[j];
		}
		if(val>0) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=5e3+5;
struct Q{
	int id[N*2],s,t,k;
	LL q[N*2];
	void init(){s=t=0;}
	void insert(LL x,int i){
		while(s<t&&i-id[s]>=k)s++;
		while(s<t&&x<=q[t-1])t--;
		q[t]=x,id[t]=i;t++;
	}
	LL top(){return q[s];}
}q;
int p[N],c[N],st[N*2],top,k;
bool vis[N];LL ans=-1e18;
void solve(){
	LL sum=0,w,w1;int s=top*2;
	for(int i=1;i<=top;i++)st[i+top]=st[i],sum+=c[st[i]];
	if(sum>=0){
		q.init(),q.k=k%top,w=0,w1=k/top;
		q.insert(0,0);
		ans=max(ans,sum*w1);
		if(q.k)for(int i=1;i<=s;i++){
			w+=c[st[i]];
			ans=max(ans,sum*w1+w-q.top());
			q.insert(w,i);
		}
		if(k>=top){
			w1--,q.init(),q.k=top,w=0;
			q.insert(0,0);
			for(int i=1;i<=s;i++){
				w+=c[st[i]];
				ans=max(ans,sum*w1+w-q.top());
				q.insert(w,i);
			}
		}
	}
	q.init(),q.k=k,w=0;
	q.insert(0,0);
	for(int i=1;i<=s;i++){
		w+=c[st[i]];
		ans=max(ans,w-q.top());
		q.insert(w,i);
	}
}
int main(){
	int n,x;scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",p+i);
	for(int i=1;i<=n;i++)scanf("%d",c+i);
	for(int i=1;i<=n;i++){
		if(vis[i])continue;
		top=0,x=i;
		do{
			st[++top]=x,vis[x]=1;
			x=p[x];
		}while(x!=i);
		solve();
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4004
a, b = map(int, input().split())

if a == b:
    ans = 'Draw'
elif a < b and a != 1:
    ans = 'Bob'
elif a < b and a == 1:
    ans = 'Alice'
elif a > b and b != 1:
    ans = 'Alice'
else:
    ans = 'Bob'

print(ans)

Measured memory_bytes: 3060
n,m=map(int,input().split())
food=[0 for i in range(m)]
for i in range(n):
  per=list(map(int,input().split()))
  for j in range(1,per[0]+1):
    food[per[j]-1]+=1
ans=0
for i in range(m):
  if food[i] == n:
    ans+=1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  vector<ll>a(n);
  rep(i,n)cin>> a[i];
  
  map<ll,ll>mp1,mp2;
  rep(i,n){
    if(a[i]>=n-1)continue;
    mp1[a[i]+i]++;
    mp2[i-a[i]]++;
  }
  ll cnt=0;
  for(auto p1:mp1){
    cnt+=p1.second*mp2[p1.first];
  }
  cout << cnt << endl;
  return 0;     
}


Measured memory_bytes: 31120
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
int main(){
    ll N;
    cin >> N;
    vector<ll> cost(N);
    ll wa = 0;
    rep(i,N){
        cin >> cost[i];
        wa += cost[i];
    }
    ll M;
    cin >> M;
    vector<ll> que(M);
    vector<ll> ato(M);
    rep(i,M){
        cin >> que[i] >> ato[i];
    }
    rep(i,M){
    ll n = wa;
    n -= (cost[que[i] - 1] - ato[i]);
    cout << n << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll a,b,c;
    cin>>a>>b>>c;
    swap(a,b),swap(a,c);
    cout<<a<<" "<<b<<" "<<c<<endl;
}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i=0; i < (n); i++)
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;

int main() {
    int a, b;
    cin >> a >> b;
    if (a > 8 || b > 8) cout << ":(" << endl;
    else cout << "Yay!" << endl;
    return 0;
}

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

int main(){
  int N;
  int S1,S2,minv=1<<21;
  cin>>N;
  int W[100];
  for(int i=0;i<N;i++)cin>>W[i];
  for(int i=0;i<N;i++){
    S1=0;S2=0;
    for(int j=0;j<N;j++){
      if(j>i){
        S2+=W[j];
      }else{
        S1+=W[j];
      }
    }
    minv=min(minv,abs(S1-S2));
  }
  cout<<minv;
}


Measured memory_bytes: 256
n = int(input())
count = 0
for i in range(n):
    x = int(input())
    tf = True
    
    if x == 2:
        tf = True
    elif x < 2 or x % 2 == 0:
        tf = False
    else:
        j = 3
        while j <= (x)**(1/2):
            if x % j == 0:
                tf = False
                break
            j += 2
            tf == True
    
    if tf == True:
        count += 1
print(count)


Measured memory_bytes: 5656
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = []
for i in range(n):
    a.append(inn())
    if len(a)>=2 and a[-1]>a[-2]+1:
        print(-1)
        exit()
if a[0]!=0:
    print(-1)
    exit()
cnt = 0
for i in range(1,n):
    if i==n-1:
        cnt += a[n-1]
    if a[i]!=a[i-1]+1:
        cnt += a[i-1]
print(cnt)


Measured memory_bytes: 57624
#include<bits/stdc++.h>
using namespace std;
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0); 
  int n;
  cin>>n;
  int a[n][n-1];
  for(int i=0;i<n;i++){
    for(int j=0;j<n-1;j++){
      cin>>a[i][j];
      a[i][j]--;
    }
  }
  
  int ans = 0;
  int now[10005] = {};
  while(1){
    bool used[10005] = {};
    bool all = true;
    for(int i=0;i<n;i++){
      if(now[i]==n-1 || used[i] || used[a[i][now[i]]]) continue;
      int t = a[i][now[i]];
      if(i == a[t][now[t]]){
	used[i] = true;
	used[t] = true;
	now[i]++;
	now[t]++;
	all = false;
      }
    }
    if(all){
      bool ok = true;
      for(int i=0;i<n;i++){
	if(now[i]!=n-1) ok =false;
      }
      if(ok){
	cout << ans << endl;
	return 0;
      }
    cout << -1 << endl;
    return 0;
    }
    ans++;
  }
  return(0);
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll A, B, C;
  cin >> A >> B >> C;
  llvec v(B, -1);
  ll i=0;
  while(v[i]<0){
    v[i]++;
    i = mod(i+A, B);
  }
  if(v[C]<0){
    cout <<"NO";
  }else{
    cout << "YES";
  }
  
  return 0;
}


Measured memory_bytes: 3568
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1

using namespace std;

int main() {
  int n, count;
  string cur, pre;
  while (cin >> n, n) {
    pre = "";
    count = 0;
    while (n--) {
      cin >> cur;
      if ((cur == "lu" && pre == "ru") || (cur == "ru" && pre == "lu") || (cur == "ld" && pre == "rd") || (cur == "rd" && pre == "ld")) count++;
      pre = cur;
    }
    cout << count << el;
  }
}

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

int n;
vector <int> A, B;
vector <int> seq;
int a, b;

int main()
{
    scanf("%d", &n);
    A.resize(n); B.resize(n); seq.resize(n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    for (int i = 0; i < n; i++) {
        scanf("%d", &B[i]);
        seq[i] = i + 1;
    }
    int pnt = 0;
    do {
        if (A == seq) a = pnt;
        if (B == seq) b = pnt;
        pnt++;
    } while (next_permutation(seq.begin(), seq.end()));
    printf("%d\n", abs(a - b));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;
	cin >> s;
	int n = s.size();
	bool flag = false;
	ll ans = 0;
	REPR(i,n-1){
		int dig = s[i] - '0';
		if(flag) dig++;
		if(dig<=4){
			ans += dig;
			flag = false;
		}else if(dig>=6){
			ans += 10-dig;
			flag = true;
		}else{
			if(s[i-1]-'0'<5){ 
				ans += dig;
				flag = false;
			}else{
				ans += 10-dig;
				flag = true;
			}
		}
	}
	if(flag) ans++;
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 1948
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  if ((B-A)%2==0) {
    cout << "Alice" << endl;
  }
  else {
    cout << "Borys" << endl;
  }
}

Measured memory_bytes: 3604
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');

        Array.Sort(s);
        int a = int.Parse(s[0]);
        int b = int.Parse(s[1]);
        int ans = a + b;

        Console.WriteLine(ans);

    }
}

Measured memory_bytes: 13404
#include<cstdio>
#include<cstring>
using namespace std;
const int HASH=10007U,HASHMOD=998244353;
const int MAXN=500005;

char W[MAXN];
int hash[MAXN],powhash[MAXN];
int GetHash(int L,int R)
{
	return ((hash[R]-1LL*hash[L-1]*powhash[R-L+1]%HASHMOD)%HASHMOD+HASHMOD)%HASHMOD;
}

bool pref[MAXN],suff[MAXN];

int main()
{
	scanf("%s",W+1);
	int n=strlen(W+1);
	hash[0]=0;powhash[0]=1;
	for(int i=1;i<=n;i++)
	{
		hash[i]=(1LL*hash[i-1]*HASH%HASHMOD+W[i]-'a')%HASHMOD;
		powhash[i]=(1LL*powhash[i-1]*HASH)%HASHMOD;
	}
	
	for(int d=1;d<=n;d++)
		for(int i=d+d;i<=n;i+=d)
			if(GetHash(1,i-d)==GetHash(d+1,i))
				pref[i]=true;
	for(int d=1;d<=n;d++)
		for(int i=n-d-d+1;i>=1;i-=d)
			if(GetHash(i,n-d)==GetHash(i+d,n))
				suff[i]=true;
	if(!pref[n])
	{
		printf("%d\n%d\n",1,1);
		return 0;
	}
	int cnt=0;
	for(int i=1;i<n;i++)
		if(!pref[i]&&!suff[i+1])
			cnt++;
	if(cnt)
	{
		printf("2\n%d\n",cnt);
		return 0;
	}
	printf("%d\n%d\n",n,1);
	
	return 0;
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int N;
  cin >> N;
  vector<P> A(N-1);
  vector<vector<int>> List(N,vector<int> ());
  REP(i,N-1){
    cin >> A[i].first >> A[i].second;
    A[i].first--;
    A[i].second--;
    List[A[i].first].push_back(A[i].second);
    List[A[i].second].push_back(A[i].first);
  }
  vector<int> B(N);
  REP(i, N) cin >> B[i];
  sort(ALL(B));
  int ans = 0;
  REP(i,N-1){
    ans+=B[i];
  }
  cout << ans << endl;
  queue<int> que;
  que.push(0);
  vector<int> dist(N,-1);
  dist[0]=0;
  reverse(ALL(B));
  int now = 0;
  vector<int> vec(N);
  vec[0]=B[0];
  now=1;
  while(!que.empty()){
    int v = que.front();
    que.pop();
    for(auto nv:List[v]){
      if(dist[nv]!=-1) continue;
      que.push(nv);
      dist[nv]=0;
      vec[nv]=B[now];
      now++;
    }
  }

  REP(i,N){
    cout << vec[i];
    if(i!=N-1){
      cout << " ";
    }
  }
  cout << endl;
}

Measured memory_bytes: 4088
N, M = map(int, input().split())
D = []
for i in range(1, N + 1):
    ni = [int(_) for _ in input().split()]
    ni = ni[1:]
    D.extend(ni)
E =[]
for j in range(1, M + 1):
    if D.count(j) == N:
        E.append(j)
print(len(E))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  vector<vi> g(n);
  rep(i, n) {
    int u, k;
    cin >> u >> k;
    rep(j, k) {
      int u;
      cin >> u;
      u--;
      g[i].push_back(u);
    }
  }
  vi ans(n, -1);
  ans[0] = 0;
  queue<int> q;
  q.push(0);
  while(!q.empty()) {
    int i = q.front();
    q.pop();
    for(int v : g[i]) {
      if(ans[v] != -1) continue;
      ans[v] = ans[i] + 1;
      q.push(v);
    }
  }
  rep(i, n) cout << i + 1 << ' ' << ans[i] << endl;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

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

const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  int n,k;cin>>n>>k;
  int ans=0;
  if(k>1)ans=n-k;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

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

    int ans = 0;
    for(int bit=0; bit<(1<<n); bit++){
        bool valid = true;
        set<int> honest;
        for(int i=0; i<n; i++){
            if(bit & (1 << i)) honest.emplace(i);
        }

        for(int i=0; i<n; i++){
            if(honest.count(i)){
                for(int j=0; j<a[i]; j++){
                    if(y[i][j] == 1 && !honest.count(x[i][j])) valid = false;
                    if(y[i][j] == 0 && honest.count(x[i][j])) valid = false;
                }
            }
        }

        if(valid) chmax(ans, (int)honest.size());
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
		public static void main(String[] args) {
		
	   Scanner sc = new Scanner(System.in);
	   
	   int N = sc.nextInt();
	   int sum = 0;
	   for(int i=1; i<=9; i++) {
		   for(int j=1; j <= 9; j++) {
			   if(i * j == N) {
				   sum += 1;
			   }
		   }
	   }
	   if(sum == 0) {
		   System.out.println("No");
	   }else {
		   System.out.println("Yes");
	   }
		}
}


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

 using namespace std;
  vector<int> G[101];
  bool V[101];
  bool Vis[101];
  int DP[101];
   int N;
   int Ans = 0;
  void DFS(int n,int len){
      Ans = max(Ans,len);
      DP[n] = max(DP[n],len);
      int S = G[n].size();
      for(int i=0;i<S;i++){
    if(!V[G[n][i]]){
        Vis[G[n][i]]= true;
        V[G[n][i]] = true;
        DFS(G[n][i],len+1);
        V[G[n][i]] = false;
    }
   }
   return;
  }
  int main(){
      do{
    int i;
   for(i=0;i<101;i++){
    G[i].clear();
    V[i] = false;
   Vis[i] = false;
    DP[i] = 0;
   }
   Ans = 0;
   scanf("%d",&N);
   if(N==0)break;
   for(i=0;i<N;i++){
    int A,B;
    scanf("%d%d",&A,&B);
    G[A].push_back(B);
    G[B].push_back(A);
   }

   for(i=1;i<=100;i++){
    if(!Vis[i]){
    Vis[i] =true;
    V[i] = true;
    DFS(i,1);
    V[i] = false;
    }
   }
   for(i=1;i<=100;i++){
    if(DP[i]==Ans){
        V[i] = true;
        DFS(i,1);
        V[i] = false;
        break;
    }
   }
   printf("%d\n",Ans);
  }while(true);
  }

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
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(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  int n; cin >> n;
  bool ok = false;
  while(n){
    if(n % 10 == 7)ok = true;
    n /= 10;
  }
  cout << (ok ? "Yes": "No") << endl;
  return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps=1e-8;
int d1[4] = { -1,0,1,0 };
int d2[4] = { 0,1,0,-1 };
int main() {
	int h, w; cin >> h >> w;
	char pal[202][202];
	rep(i, 202) {
		rep(j, 202) {
			pal[i][j] = '#';
		}
	}
	string s; P chk;
	rep1(i, h) {
		cin >> s;
		rep1(j, w) {
			pal[i][j] = s[j - 1];
			if (s[j - 1] == '%') {
				chk = { i,j };
			}
		}
	}
	int d[202][202];
	rep(i, 202) {
		rep(j, 202) {
			d[i][j] = (int)MOD;
		}
	}
	d[chk.first][chk.second] = 0;
	vector<P> v; int used[202][202] = {};
	v.push_back(chk);
	while (!v.empty()) {
		int nx = v[0].first; int ny = v[0].second;
		v.erase(v.begin());
		rep(i, 4) {
			if (used[nx + d1[i]][ny + d2[i]] == 0 && pal[nx + d1[i]][ny + d2[i]] != '#') {
				used[nx + d1[i]][ny + d2[i]] = 1;
				v.push_back({ nx + d1[i],ny + d2[i] });
				d[nx + d1[i]][ny + d2[i]] = min(d[nx + d1[i]][ny + d2[i]], d[nx][ny] + 1);
			}
		}
	}
	int cnt1; int cnt2 = (int)MOD;
	rep1(i, h) {
		rep1(j, w) {
			if (pal[i][j] == '@') {
				cnt1 = d[i][j];
			}
			else if (pal[i][j] == '$') {
				cnt2 = min(cnt2, d[i][j]);
			}
		}
	}
	if(cnt1>=cnt2){
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}


Measured memory_bytes: 3576
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

ll N;

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

  ll ans1 = 0;
  ll ans2 = 0;

  ll top = 0;
  ll num_digit = 0;
  while (N != 0) {
    top = N % 10;
    num_digit++;
    ans2 += top;
    N /= 10;
  }
  ans1 = (top - 1) + 9 * (num_digit - 1);

  cout << max(ans1, ans2) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string a;
	cin>>a;
	int se[n],sw[n];
	for(int i=0;i<n;++i){
		se[i]=0;
		sw[i]=0;
	}
	if(a[0]=='E')
	    se[0]=1;
	else
		sw[0]=1;
	for(int i=1;i<n;i++){
		if(a[i]=='E'){
			se[i]=se[i-1]+1;
			sw[i]=sw[i-1];
		}
		else {
			sw[i]=sw[i-1]+1;
			se[i]=se[i-1];
		}
	}
	int minv=300000000;
	for(int i=0;i<n;++i){
		int mmm=0;
		if(i==0)
			mmm=se[n-1]-se[i];
		else if(i==n-1)
			mmm=sw[n-2];
		mmm=sw[i-1]+(se[n-1]-se[i]);
		minv=min(minv,mmm);
	}
	cout<<minv<<endl;
	return 0;
}

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

map<string,int> mem;

int main()
{
	int n;
	cin >> n;
	
	for (int i = 0; i < n; ++i)
	{
		string s;
		cin >> s;
		mem[s]++;
	}
	
	int maxv = 0;
	for (auto it = mem.begin(); it != mem.end(); it++)
	{
		int v = it -> second;
		if (v > maxv)
		{
			maxv = v;
		}
	}
	
	//int maxv = mem.rbegin() -> second;
	/*
	int maxv = 0;
	for (const auto& x : mem)
	{
		int v = x.second;
		if (v > maxv)
		{
			maxv = v;
		}
	}
	*/
	
	//cout << "-----" << endl;
	
	/*
	for (auto x : mem)
	{
		cout << x.first << " " << x.second << endl;
		
		
		if (x.second == max)
		{
			cout << x.first << endl;
		}
	}
	*/
	
	for (auto it = mem.begin(); it != mem.end(); it++)
	{
		//cout << it -> first << " " << it -> second << endl;
		
		if (it -> second == maxv)
		{
			cout << it -> first << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 25216
#include <iostream>
#include <string>

using namespace std;

char a,b,c,d;

int cal ( string s )
{
  int tmp1,tmp2,tmp3,tmp4;
  tmp1 = s[0]-'0';
  tmp2 = s[2]-'0';
  tmp3 = s[4]-'0';
  tmp4 = s[6]-'0';

  int ans = 0;
  ans = tmp1;
  if ( s[1] == '+' ) ans += tmp2;
  else ans -= tmp2;
  if ( s[3] == '+' ) ans += tmp3;
  else ans -= tmp3;
  if ( s[5] == '+' ) ans += tmp4;
  else ans -= tmp4;

  return ans;
}

string find ( void )
{
  string s;
  int tmp;
  s += a;  s += '+'; s+= b; s+= '+'; s += c; s += '+'; s += d;

  for ( int i = 0; i < 2; ++i ) {
    if ( i == 0 ) s[1] = '+';
    else  s[1] = '-';
    for ( int j = 0; j < 2; ++j ) {
      if ( j == 0 ) s[3] = '+';
      else s[3] = '-';
      for ( int k = 0; k < 2; ++k ) {
        if ( k == 0 ) s[5] = '+';
        else s[5] = '-';
        tmp = cal(s);
        if ( tmp == 7 ) break;
      }
      if ( tmp == 7 ) break;
    }
    if ( tmp == 7 ) break;
  }

  return s;

}

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

  cout << find() << "=7\n";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define k 10000

int main(){
  unsigned short *A, *B;

  int C[k+1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for ( i = 0; i <= k; i++ ) C[i] = 0;

  for ( i = 0; i < n; i++ ){
    scanf("%hu", &A[i + 1]);
    C[A[i + 1]]++;
  }

  for ( i = 1; i <= k; i++ ) C[i] = C[i] + C[i - 1];

  for ( j = 1; j <= n; j++ ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 8464
#abc156 d

import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce

sys.setrecursionlimit(4100000)
INF = 1 << 60
MOD = 10 ** 9 + 7

#ここから書き始める
def mod_pow(a, n, mod):
    if n == 1:
        return a % mod
    elif n % 2 == 0:
        return mod_pow(a, n/2, mod)**2 % mod
    else:
        return (a * mod_pow(a, n-1, mod)) % mod

def mod_combination(n, r, mod):
    # X = n * n-1 * ... * max(r, n - r)+1
    # Y = min(r, n - r)!
    # nCr = X / Y

    X = 1
    for i in range(n, max(r, n - r), -1):
        X *= i
        X %= mod

    Y = math.factorial(min(r, n - r)) % mod
    # フェルマーの小定理 a^(p-1) = 1 (mod p) より
    # a^(-1) = a^(p-2)

    rec_Y = mod_pow(Y, mod - 2, mod)

    return (X * rec_Y) % mod


n, a, b = map(int, input().split())
ans = mod_pow(2, n, MOD) - 1
ans -= mod_combination(n, a, MOD)
ans -= mod_combination(n, b, MOD)
print(ans % MOD)


Measured memory_bytes: 7440
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
int n,m;
int a[1005], b[1005], c[1005];
int d[1005], e[1005], f[1005];
int G[6005][6005];
ll ans = 0;
int w[6005], h[6005];
int dx[]={1,0,-1,0}, dy[]={0,1,0,-1};
vector<int> _X, _Y;
unordered_map<int,int> _mX, _mY;
queue<ii> q;
int main(){
    scanf("%d%d",&n,&m);
    for (int i = 0; i < n; i++){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        _X.emplace_back(a[i]);
        _X.emplace_back(b[i]);
        _Y.emplace_back(c[i]);
    }
    for (int i = 0; i < m; i++){
        scanf("%d%d%d",&d[i],&e[i],&f[i]);
        _X.emplace_back(d[i]);
        _Y.emplace_back(e[i]);
        _Y.emplace_back(f[i]);
    }
    _X.emplace_back(0);
    _Y.emplace_back(0);
    sort(_X.begin(),_X.end());
    sort(_Y.begin(),_Y.end());
    _X.erase(unique(_X.begin(),_X.end()),_X.end());
    _Y.erase(unique(_Y.begin(),_Y.end()),_Y.end());
    //printf("X: "); for (auto x:  _X) printf("%d ",x); printf("\n");
    //printf("Y: "); for (auto x:  _Y) printf("%d ",x); printf("\n");
    for (int i = 0; i < _X.size(); i++) _mX[_X[i]] = i;
    for (int i = 0; i < _Y.size(); i++) _mY[_Y[i]] = i;
    for (int i = 0; i < _X.size()-1; i++){
        h[i*2+2] = _X[i+1] - _X[i];
        //printf("%d ",h[i*2+2]);
    }
    for (int i = 0; i < _Y.size()-1; i++){
        w[i*2+2] = _Y[i+1] - _Y[i];
        //printf("%d ",w[i*2+2]);
    }
    for (int i = 0; i < n; i++){
        a[i] = 2*_mX[a[i]]+1; b[i] = 2*_mX[b[i]]+1; c[i] = 2*_mY[c[i]]+1;
        //printf("abc %d %d %d\n",a[i],b[i],c[i]);
        for (int J = a[i]; J <= b[i]; J++){
            G[J][c[i]] = 2;
        }
    }
    for (int i = 0; i < m; i++){
        d[i] = 2*_mX[d[i]]+1; e[i] = 2*_mY[e[i]]+1; f[i] = 2*_mY[f[i]]+1;
        //printf("def %d %d %d\n",d[i],e[i],f[i]);
        for (int J = e[i]; J <= f[i]; J++){
            G[d[i]][J] = 2;
        }
    }
    /*for (int i = 0; i <= 2*n+1+m; i++){
        for (int j = 0; j <= 2*m+n+1; j++){
            printf("%d",G[i][j]);
        }
        printf("\n");
    }*/
    int sx = 2*_mX[0]+1;
    int sy = 2*_mY[0]+1;
    q.push({sx,sy});
    G[sx][sy] = 1;
    while (q.size()){
        int x, y;
        tie(x,y) = q.front(); q.pop();
        for (int k = 0; k < 4; k++){
            int nx=  x+dx[k], ny = y +dy[k];
            if (G[nx][ny] == 0){
                G[nx][ny] = 1;
                if (nx == 0 || ny == 0 || nx == 2*_X.size() || ny == 2*_Y.size()){
                    printf("INF");
                    return 0;
                }
                q.push({nx,ny});
                ans += (ll)h[nx]*w[ny];
            }
        }
    }
    printf("%lld",ans);
}


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

int main(){
  int A, B;
  int count = 0;
  cin >> A >> B;
  for(int i =A; i < B+1;i++){
    int p, q,r,s,t =0;
    p = i/10000;
    q =(i - p*10000)/1000;
    r = (i- p*10000 - q*1000) / 100;
    s= (i- p*10000 - q*1000 -r*100) /10;
    t= i- p*10000 - q*1000 -r*100 - s*10;
    if (p==t&&q==s){
      count ++;
    }
  }
  cout << count;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long int 
using namespace std;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif

    int n;
    cin>>n;
    string s;
    cin>>s;
    map<char,int>mp;

    for(auto it:s)
    {
        mp[it]++;
    }

    int count=1;

    for(auto it:mp)
    {
         count = (count%mod*((it.second+1)%mod))%mod;
    }

    cout<<(count-1+mod)%mod;




   
}




Measured memory_bytes: 512
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main{
public static void main(String[] args) throws FileNotFoundException, IOException {
        Scanner s = new Scanner(System.in);
        StringBuilder sb=new StringBuilder();
       int n=s.nextInt(),m=s.nextInt(),l=s.nextInt();
       long[][] g1=new long[n+1][n+1];
       for(int i=1;i<=n;i++){
       	Arrays.fill(g1[i],(long)1e13);
       }
       for(int i=0;i<m;i++){
       	int x=s.nextInt(),y=s.nextInt(),c=s.nextInt();
       	g1[x][y]=c;  
       	g1[y][x]=c;  
       }

       for(int i=0;i<n;i++){
       	g1[i][i]=0;
       }

       	for (int k = 1; k <= n; k++) 
        { 
            for (int i = 1; i <= n; i++) 
            { 
                for (int j = 1; j <= n; j++) 
                { 
                    g1[i][j]=Math.min(g1[i][j],g1[i][k] + g1[k][j]); 
                } 
            } 
        } 
        long[][] g2=g1.clone();
        for(int i=1;i<=n;i++){
        	for(int j=1;j<=n;j++){
        		g2[i][j]=g1[i][j]<=l? 1:(long)1e13;
        	}
        }

        for (int k = 1; k <= n; k++) 
        { 
            for (int i = 1; i <= n; i++) 
            { 
                for (int j = 1; j <= n; j++) 
                { 
                    g2[i][j]=Math.min(g2[i][j],g2[i][k] + g2[k][j]); 
                } 
            } 
        } 

        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
        List<Integer>l1=new ArrayList<>();
        int q=s.nextInt();
        for(int i=0;i<q;i++){
        	int start=s.nextInt(),end=s.nextInt();
        	if(g2[start][end]==(long)1e13){
        		l1.add(-1);
        	}
        	else{
        		l1.add((int)g2[start][end]-1);        	
        	}
        }
        for(int i=0;i<l1.size();i++){
        	System.out.println(l1.get(i));
        }
    }
}
    
  












Measured memory_bytes: 89836
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
#define INT_MAX 2147483647
#define _LIBCPP_DEBUG 0
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)	
using namespace std;



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


int main() {
	int n, a, b;
	cin >> n >> a >> b;

	int  ans = 0;
	rep(i, n+1) {
		int c = 0;
		int t = i;
		rep(j, 5) {
			c += t % 10;
			t /= 10;
		}
		if (a <= c && c <= b) {
			ans += i;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
class square():
    
    def __init__(self, x,y):
        self.x = x
        self.y = y
        
    def draw(self):
        
        for i in range(0,self.x):
            for j in range(0,self.y):
                if i % 2== j % 2: 
                    print('#',end="")     
                else:
                    print('.',end="")
            print('') 
        print('')
        
while True:
    H,W = map(int,input().split())
    
    if H == 0 and W == 0:
        break
        
    s = square(H,W)
    s.draw()

Measured memory_bytes: 7016
N = int(input())
A = list(map(int, input().split()))

A.sort()
now = 0
B = []
for i in range(N-1, -1, -1):
    if now == A[i]:
        B.append(A[i])
        now = A[i] + 1
    elif now != A[i]:
        now = A[i]
    if len(B) == 2:
        break

if len(B) == 2:
    ans = B[0] * B[1]
else:
    ans = 0
print(ans)


Measured memory_bytes: 14252
#include <stdio.h>
int main(){
    int N, M, time=0;
    int T[101];
    int X[101];
    int P[101];
    int i, j;
    scanf("%d", &N);
    for(i = 1; i <= N; i++){
        scanf("%d", &T[i]);
    }
    scanf("%d", &M);
    for(i = 1; i <= M; i++){
        scanf("%d %d", &P[i], &X[i]);
    }
    for(i = 1; i <= M; i++){
        for(j =1; j <= N; j++){
            if(P[i] == j) time+=X[i];
            else time+=T[j];
        }
        printf("%d\n", time);
        time = 0;
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
 
int main(){
 
  int N;
  cin >> N;
  int a = N/100;
  int b = N % 100;
  b = b / 10;
  int c = N % 10;
  if (a == 7 || b == 7 || c == 7)
    printf("Yes");
  else
    printf("No");
  return 0;
}

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

using namespace std;

int main() {
  string r;
  cin >> r;
  if (r[0] == r[1] || r[1] == r[2] || r[2] == r[3])
    cout << "Bad" << endl;
  else
    cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
    int N;
    cin>>N;
    int a[N];
    int min=1000;
    int max=0;
    for(int i=0; i<N; i++){
        cin>>a[i];
        if(a[i]<min){
            min=a[i];
            
        }
        
    }
    for(int j=0; j<N; j++){
        
        if(a[j]>max){
            max=a[j];
            
        }
        
    }
    cout<<max-min;
}    
        

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

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


int main()
{
    int N;
    cin >> N;
    vector<int> B(N);
    REP(i, N-1) cin >> B[i];

    int ans = B[N-2];
    for(int i = N-2; i >= 1; --i){
        ans += min(B[i], B[i-1]);
    }
    ans += B[0];
    cout << ans << endl;
    
    return 0;
}

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

int main() {
    long x, k, d;
    cin>>x >>k >>d;
    x=abs(x);
    long ama=x%d;
    long ama2=min(ama,d-ama);
    if((x-ama)/d>=k){
        cout<<x-(d*k)<<endl;
        return 0;
    }
    if((x-ama)/d==k+1){
        cout<<d-ama<<endl;
        return 0;
    }
    if(ama2==ama && ((x-ama)/d)%2==k%2){
        cout<<ama<<endl;
        return 0;
    }else if(ama2==ama && ((x-ama)/d)%2!=k%2){
        cout<<d-ama<<endl;
        return 0;
    }else if(ama2!=ama && ((x+ama2)/d)%2==k%2){
        cout<<ama2<<endl;
        return 0;
    }else if(ama2!=ama && ((x+ama2)/d)%2!=k%2){
        cout<<ama<<endl;
        return 0;
    }
}

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

int64_t n,a,b;

int main()
{
    cin>>n>>a>>b;
    if(a>b)
        cout<<0;
    else
    if(a==b)
        cout<<1;
    else
    if(n==1)
        cout<<0;
    else
    {
        int64_t minn=(n-1)*a+b;
        int64_t maxn=(n-1)*b+a;
        cout<<maxn-minn+1;
    }
}


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

int main(){
  string s;
  cin >> s;
  vector<int> dp(1<<26,1e9);
  vector<int> C(s.length());
  for(size_t i = 0; i < s.length(); ++i){
    C[i] = (1<<(s[i]-'a'));
    if(i > 0) C[i] ^= C[i-1];
  }
  
  dp[0] = 0;
  for(size_t i = 0; i < s.length(); ++i){
    for(int j = 0; j < 26; ++j){
      dp[C[i]] = min(dp[C[i]],dp[C[i]^(1<<j)]+1);
    }
  }
  cout << max(1,dp[C.back()]) << endl;
}


Measured memory_bytes: 263556
import sys
input = sys.stdin.readline
n,y=map(int,input().split())


for i in range(0,n+1):
    for j in range(0,n+1):
        k=n-i-j
        if 10000*i+5000*j+1000*k==y and k>=0 :
            print(i, j, k)
            c=1
            break
    else:
        continue
    break
else:
    print(-1,-1,-1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


char maze[8][8];
int main(){FIN
    ll h,w,k;cin>>h>>w>>k;
    REP(i,h){
        REP(j,w){
            cin>>maze[i][j];
        }
    }
    ll ans=0;
    for(ll i=0; i< (1<<h); i++){
        for(ll j=0; j<(1<<w); j++){
            ll cnt=0;
            REP(s,h){
                REP(t,w){
                    if (maze[s][t]=='#' && i&(1<<s) && j&(1<<t)){
                        cnt++;
                    }
                }
            }
            if (cnt==k) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h> 
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 2e5+10;
const int N = 1e5+10;
const int E = 1e6+10; 
ll n,m,k;

int main(){
	cin>>n>>k;
	ll sum=0;
	while(n){
		sum++;
		n/=k;
	}
	cout<<sum<<endl;
}

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

public class Main {
	
	public static long c(int n, int k) {
		if(n < k)
			return 0;
		double res = 1;
		for(int i = 1; i <= k; i++)
			res = (n - k + i) * res / i;
		return (long)(0.01 + res);
	}
	
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		int[] array = new int[n];
		int[] count = new int[n + 1];
		for(int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
			count[array[i]]++;
		}
		
		long ans = 0;
		for(int i = 0; i < n + 1; i++)
			ans += c(count[i], 2);
		
		
		for(int i = 0; i < n; i++) {
			int x = array[i];
			pw.println(1l * ans - c(count[x], 2) + c(count[x] - 1, 2));
		}
		
		pw.flush();
	}

	public static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


Measured memory_bytes: 51788
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

#include <vector>
#include <set>
using namespace std;

struct union_find {
  vector<int> par;
  vector<int> rank;
  union_find(int n) : par(n) , rank(n) {
    for(int i = 0;i < n;i++) par[i] = i;
  }
  int root(int i) {
    return par[i] == i ? i : par[i] = root(par[i]);
  }
  pair<int,int> unite(int x,int y) {
    x = root(x);
    y = root(y);
    if(x == y) return pair<int,int>(-1,-1);
    if(rank[x] < rank[y]) {
      par[x] = y;
      return {y , x};
    }
    else {
      par[y] = x;
      if(rank[x] == rank[y]) rank[x]++;
      return {x,y};
    }
  }
  bool same(int x,int y) {
    return root(x) == root(y);
  }
};

int N,M;
vector<i64> X;
vector<i64> A,B,Y;

i64 w[101010];
i64 reg[101010];
i64 cnt = 0;

int main() {
  cin >> N >> M;
  X.resize(N);
  rep(i,0,N - 1) cin >> X[i];
  A.resize(M);
  B.resize(M);
  Y.resize(M);
  rep(i,0,M - 1) {
    cin >> A[i] >> B[i] >> Y[i];
    A[i]--;
    B[i]--;
  }
  i64 ans = 0;
  vector<pair<i64,i64>> vec;
  rep(i,0,M - 1) vec.push_back({Y[i], i});
  rep(i,0,N - 1) w[i] = X[i];
  union_find uf(N);
  sort(all(vec));
  for(auto p : vec) {
    i64 i = p.second;
    i64 y = p.first;
    i64 a = A[i];
    i64 b = B[i];
    if(uf.same(a, b)) {
      i64 r = uf.root(a);
      if(w[r] < y) reg[r]++;
      else ans++;
    }
    else {
      auto pp = uf.unite(a,b);
      a = pp.first;
      b = pp.second;
      w[a] += w[b];
      reg[a] += reg[b];
      w[b] = 0;
      reg[b] = 0;
      if(w[a] < y) {
        reg[a]++;
      }
      else {
        ans++;
        ans += reg[a];
        reg[a] = 0;
      }
    }
  }
  cout << M - ans << endl;
}


Measured memory_bytes: 7280