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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

bool check(VI& t){
    REP(i,7)FOR(j,i+1,8){
        if(j-i == abs(t[j]-t[i])) return false;
    }
    return true;
}

int main(void){
    int k; cin >> k;
    set<int> sr{0,1,2,3,4,5,6,7}, sc{0,1,2,3,4,5,6,7};
    vector<P> v(k);
    REP(i,k){
        int r,c; cin >> r >> c;
        v[i].first = r; v[i].second = c;
        sr.erase(r); sc.erase(c);
    }
    VI vr, vc;
    for(int i : sr) vr.push_back(i);
    for(int i : sc) vc.push_back(i);

    VI p(8-k); REP(i,8-k) p[i] = i;
    char ans[8][8]; REP(i,8)REP(j,8) ans[i][j] = '.';
    do{
        VI t(8); REP(i,k) t[v[i].second] = v[i].first;
        REP(i,8-k) t[vc[i]] = vr[p[i]];
        if(check(t)){
            REP(i,8) ans[t[i]][i] = 'Q';
            break;
        }
    }while(next_permutation(ALL(p)));

    REP(i,8){
        REP(j,8) cout << ans[i][j];
        cout << en;
    }
    return 0;
}


Measured memory_bytes: 3148
import java.util.*;
import java.util.regex.Pattern;

public class Main{
  
  public static void main(String[] args){
  
  Scanner sc = new Scanner(System.in);
  
   int a = sc.nextInt();
   int b = sc.nextInt();
   String s = sc.next();
    
  if(a>=1 && a<=5 && b>=1 && b<=5){
    boolean gouhi = Pattern.matches("^[0-9]{"+a+"}-[0-9]{"+b+"}$",s);
    if(gouhi == true){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
    
  }else{
    System.out.println("入力値に誤りがあります");
  }
  }
  
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n - 1);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    a.at(i)--;
  }
  for (int i = 0; i < n; i++) cin >> b.at(i);
  for (int i = 0; i < n - 1; i++) cin >> c.at(i);
  int ans = b.at(a.at(0)), prev = a.at(0);
  for (int i = 1; i < n; i++) {
    ans += b.at(a.at(i));
    if (a.at(i) == prev + 1) ans += c.at(prev);
    prev = a.at(i);
  }
  cout << ans << endl;
}


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

const int MAX_N = 600, MAX_C = 32;
int N, C;
int D[MAX_C][MAX_C], col[MAX_N][MAX_N];

void solve()
{
	vector<int> same[3];
	for(int i=0;i<3;++i) same[i].resize(C+1);
	for(int i=1;i<=N;++i)for(int j=1;j<=N;++j){
	    for(int c=1;c<=C;++c){
		    same[(i+j)%3][c]+=D[col[i][j]][c];
	    }
	}
	ll ans = 1e16;
    for(int c1=1;c1<=C;++c1)for(int c2=1;c2<=C;++c2)if(c1!=c2)for(int c3=1;c3<=C;++c3)if(c3!=c1&&c3!=c2){
        ll cur = same[0][c1]+same[1][c2]+same[2][c3];
        ans=min(ans,cur);
    }
	cout << ans << '\n';
}

int main()
{
	cin >> N >> C;
	for(int i=1;i<=C;++i)for(int j=1;j<=C;++j) cin >> D[i][j];
	for(int i=1;i<=N;++i)for(int j=1;j<=N;++j) cin >> col[i][j];
	solve();
	return 0;
}


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

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define sz(v) ll(v.size())


void solve(ll N, ll W, vector<ll> w, vector<ll> v){
    ll dp[N+1][W+1];
    fill(dp[0], dp[N+1], 0);

    rep(i, N) {
        rep(j, W + 1) {
            if (j >= w[i]) {
                dp[i+1][j] = max(dp[i][j-w[i]]+v[i], dp[i][j]);
            } else {
                dp[i+1][j] = dp[i][j];
            }
        }
    }

    cout << dp[N][W] << endl;
}

int main() {
    ll N;
    scanf("%lld",&N);
    ll W;
    scanf("%lld",&W);
    vector<ll> w(N);
    vector<ll> v(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&w[i]);
        scanf("%lld",&v[i]);
    }
    solve(N, W, move(w), move(v));
    return 0;
}


Measured memory_bytes: 79104
import math
N,P=map(int,input().split())

dic_fact={}
for i in range(2,P+1):
  if i**2>P:
    break
  
  while(True):
    if P%i==0:
      P//=i
      if i not in dic_fact:
        dic_fact[i] = 1
      else:
        dic_fact[i] += 1
    else:
      break
      
if P!=1:
  dic_fact[P]=1
#print(dic_fact)

answer=1
for key in dic_fact:
  value=dic_fact[key]
  while(True):
    if value>=N:
      answer*=key
      value-=N
    else:
      break
      
print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> X(N),Y(M);
    rep(i,N) cin >> X[i];
    rep(i,M) cin >> Y[i];
    sort(ALL(X));
    sort(ALL(Y));
    ll x = 0,y = 0;
    rep(i,N){
        x += X[i] * (2*i-N+1);
        x %= MOD;
    }
    rep(i,M){
        y += Y[i] * (2*i-M+1);
        y %= MOD;
    }
    cout << x * y % MOD << endl;
}


Measured memory_bytes: 1792
a,b,c = map(int, input().split())
list_1 = []
for i in range(c):
    i = int(input())
    list_1.append(i)
list_2 = [b for i in range(a)]
list_3 = list(map(lambda x:x-c, list_2))
for i in range(c):
    list_3[list_1[i]-1] += 1
for i in list_3:
    if i >0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 12580
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
template <typename T>
inline T  read()
{
    char c=getchar();
    T x=0,f=1;
    while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x*f;
}
template <typename T>
inline void write(T x) 
{
    if(x < 0) x = (~x) + 1, putchar('-');
    if(x / 10) write(x / 10);
    putchar(x % 10 | 48);
}
const int INF = 0x3f3f3f3f;
int main()
{
    string str;
    cin>>str;
    if(str == "AAA" || str == "BBB") cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define For(i,j,k)	for(int i=j;i<=k;++i)
#define Dow(i,j,k)	for(int i=k;i>=j;--i)
#define ll long long
#define inf 1e8
using namespace std;
inline ll read()
{
	ll t=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')	f=-1;c=getchar();}
	while(c>='0'&&c<='9')	t=t*10+c-48,c=getchar();
	return t*f;
}
ll a[200001],sum[200001],ans=1e17,n;
int main()
{
	n=read();
	For(i,1,n)	a[i]=read();
	For(i,1,n)	sum[i]=sum[i-1]+a[i];
	Dow(i,1,n-1)
		ans=min(ans, abs(sum[n]-sum[i]-sum[i]) );
	cout<<ans<<endl;
}

Measured memory_bytes: 3328
n=int(input())

d={}

for _ in range(n):
    a=int(input())
    if a not in d:
        d[a]=1
    else:
        if d[a]==1:
            d[a]=0
        else:
            d[a]=1

ans=0
for _,v in d.items():
    if v==1:
        ans+=1

print(ans)

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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;

int main() {
    lli n, y;
    cin2(n, y);
    REPE(i, 0, n) {
        REPE(j, 0, n) {
            lli k = n - i - j;
            if (k < 0)
                continue;
            if (i * 10000 + j * 5000 + k * 1000 == y) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BC
import Data.Maybe

readInts :: BC.ByteString -> [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words

solve :: [Int] -> IO ()
solve ns = do
    let mn = minimum ns
        mx = maximum ns
        s = sum ns
    putStrLn . unwords . map show $ [mn,mx,s]

main = do
    _ <- getLine
    BC.getLine >>= solve . readInts

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

using namespace std;

unordered_map <int, int> ap;

int main()
{
    int n;
    cin >> n;
    int ok = 1;
    for(int i = 1; i <= n; i ++)
    {
        int nr;
        cin >> nr;
        ap[nr] ++;
        if(ap[nr] > 1)
        {
            ok = 0;
            break;
        }
    }

    cout << (ok == 1 ? "YES\n" : "NO\n");

    return 0;
}


Measured memory_bytes: 8520
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define db(x) cout<<#x<<"="<<x<<endl
#define deb(x) each(x.begin(),x.end(),(int& y){cout << y <<" ";})
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;

void Main(){

  ll K,X,Y; cin>>K>>X>>Y;

  ll ct=0;

  bool swa=false, xminus=false, yminus=false;
  if(X<0){xminus=true; X=-X;}
  if(Y<0){yminus=true; Y=-Y;}
  if(Y<X){swa=true; swap(X,Y);}

  vector<pair<ll,ll>> ve;

  if(K%2==0 and (X+Y)%2!=0){
    cout<< -1 <<"\n"; return;
  }

  ll dist=X+Y; ll nx=0, ny=0;

  if(K%2==0){
    while(dist>=2*K){
      ll xmove=min(K,X-nx);
      nx+=xmove;
      ny+=K-xmove;
      ve.emplace_back(nx,ny);
      ++ct;
      dist-=K;
    }

    //if(dist==0){ct++; ve.emplace_back(X,Y);}
    if(dist==K){ct++; ve.emplace_back(X,Y);}
    else{
      ve.emplace_back(X+K-dist/2,Y-dist/2); ct++;
      ve.emplace_back(X,Y); ct++;
    }
  }
  else{
    while(dist>=2*K){
      ll xmove=min(K,X-nx);
      nx+=xmove;
      ny+=K-xmove;
      ve.emplace_back(nx,ny); ct++;
      dist-=K;
    }
    if(ct%2==(X+Y)%2){
      //if(dist==0){ve.emplace_back(X,Y); ++ct;}
      if(dist==K){ve.emplace_back(X,Y); ++ct;}
      else{
        ve.emplace_back(X+K-dist/2,Y-dist/2); ++ct;
        ve.emplace_back(X,Y); ++ct;
      }
    }
    else{
      ll xmove=min(K,X-nx);
      nx+=xmove;
      ny+=K-xmove;
      ve.emplace_back(nx,ny); ++ct;
      dist-=K;

      if(dist==0){1;}
      else if(dist>0){
        ve.emplace_back(X+K-dist/2,Y-dist/2); ++ct;
        ve.emplace_back(X,Y); ++ct;
      }
      else{
        dist=-dist;
        ve.emplace_back(X+K-dist/2,Y+dist/2); ++ct;
        ve.emplace_back(X,Y); ++ct;
      }
    }
  }

  cout<< ct <<"\n";
  rep(i,ve.size()){
    if(swa) swap(ve[i].first, ve[i].second);
    if(yminus) ve[i].second=-ve[i].second;
    if(xminus) ve[i].first=-ve[i].first;

    cout<< ve[i].first <<" "<< ve[i].second <<"\n";
  }

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 5484
n = int(input())
list_P = list(map(int, input().split()))
d = {}
q = max(list_P)

for p in list_P:
    d.setdefault(p, 0)
    d[p] += 1

list_P = set(list_P)
list_Ans = [True]*(q+1)

for p in list_P:
    if d[p] > 1:
        list_Ans[p] = False

    for i in range(2*p, q + 1, p):
        list_Ans[i] = False

ans = 0

for p in list_P:
    if list_Ans[p]:
        ans += 1

print(ans)

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


int main(void){
    map<int,vector<int>> g;
    map<int,int> f;
    int l,r,h,w,d,q,tmp;
    cin>>h>>w>>d;
    for(int i=0  ;i<h  ;i++){
        for(int j=0  ;j<w  ;j++){
            cin>>tmp;
            g[tmp].push_back(i);
            g[tmp].push_back(j);            
        }
    }
    cin>>q;
    vector<int> cumsum;
    for(int i=1  ;i<h*w+1  ;i++){
        if (i-d<=0) cumsum.push_back(0);
        else{
            cumsum.push_back( abs(g[i-d][0]-g[i][0])+abs(g[i-d][1]-g[i][1]) );
        }
    }
    for(int i=d  ;i<cumsum.size()  ;i++){
        cumsum[i]+=cumsum[i-d];
        f[i+1]=cumsum[i];
    }
    for(int i=0  ;i<q  ;i++){
        cin>>l>>r;
        cout<<f[r]-f[l]<<endl;
    }

}

Measured memory_bytes: 15480
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    INT(n);
    VI t(n),x(n),y(n);
    rep(i,n) cin >> t[i] >> x[i] >> y[i];
    bool can = true;
    int p = 0,q = 0,r=0;
    rep(i,n){
        int dd = abs(x[i] - q) + abs(y[i] - r);
        int dt = t[i] - p;
        p = t[i],q = x[i],r = y[i];
        if(dd <= dt && dt%2 == dd%2) continue;
        can = false;
        break;
    }
    if(can) Yes;
    else No;

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)

int cnt;

int main(){
	
	int N;
	cin>>N;
	
	if(N==1){
		cout<<2<<endl;
		return 0;
	}
	vector<vector<int>> E(N,vector<int>(0));
	for(int i=0;i<N-1;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		E[x].push_back(y);
		E[y].push_back(x);
	}
	
	vector<bool> flag(N,false);
	queue<int> S;
	int white = 0,black = 1;
	vector<vector<int>> dp(N,vector<int>(2,0)); //dp[i][j] i番目の頂点を色jで塗る
	vector<int> jisuu(N);
	for(int i=0;i<N;i++)jisuu[i] = E[i].size();
	for(int i=0;i<N;i++){
		if(E[i].size()==1){
			flag[i]=true;
			dp[i][black] = 1;
			dp[i][white] = 1;
			int a = E[i][0];
			jisuu[a]--;
			if(jisuu[a]==1){
				S.push(a);
				cnt++;
			}
		}
	}
	int last = 0;
	
	while(S.size()!=0){
		int a = S.front();
		S.pop();		

		flag[a] = true;
		dp[a][black] = 1;
		dp[a][white] = 1;
		for(int i=0;i<E[a].size();i++){
			int b = E[a][i];
			if(flag[b]==false){
				jisuu[b] --;
				if(jisuu[b] == 1){
					S.push(b);
					cnt++;
				}
				continue;
			}
			dp[a][black] = mod(dp[a][black] * dp[b][white]);
			dp[a][white] = mod(dp[a][white] * (dp[b][white] + dp[b][black]));
			last = a;
		}
		
	}
	//for(int i=0;i<N;i++)cout<<i+1<<':'<<dp[i][black]<<','<<dp[i][white]<<endl;
	
	
	
	cout<<mod(dp[last][black]+dp[last][white])<<endl;
	
	return 0;
}


Measured memory_bytes: 12160
// AtCoder Regular Contest 077
// E - guruguru

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;


const int MAX_N = 100000;
const int MAX_M = 100000;
int N, M;
int a[MAX_N];
int imos0[2 * MAX_M + 1];
ll imos1[2 * MAX_M + 1];

int main() {

    int from, to;
    ll total, sum, ans;

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

    memset(imos0, 0, sizeof(0));
    memset(imos1, 0, sizeof(0));
    total = 0;
    for (int i = 1; i < N; i++) {
        from = a[i - 1];
        to = a[i];
        if (from > to) {
            to += M;
        }
        total += to - from;
        imos0[from + 1]++;
        imos0[to + 1]--;
        imos1[from + 1] += from;
        imos1[to + 1] -= from;
    }
    for (int i = 0; i < 2 * M; i++) {
        imos0[i + 1] += imos0[i];
        imos1[i + 1] += imos1[i];
    }

    ans = total;
    for (int i = 0; i < M; i++) {
        sum = total;
        for (int j = i; j < 2 * M; j += M) {
            sum -= (ll)j * imos0[j] - imos1[j] - imos0[j];
        }
        ans = min(ans, sum);
    }

    cout << ans << endl;

    return 0;

}





Measured memory_bytes: 2944
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int a[505][505];

int main()
{ios_base::sync_with_stdio(false);
int n,m;
cin>>n>>m;

rep(i,0,n-1)rep(j,0,m-1)cin>>a[i][j];

int ans=n;

int c1[505]={0};
rep(i,1,m)c1[i]=1;

int c[305]={0};
rep(i,0,n-1)c[a[i][0]]++;
int mx=0;

rep(i,1,m)mx=max(mx,c[i]);

ans=mx;

rep(ii,0,m-2)
{
	int c[305]={0};
	rep(i,0,n-1)
	{
		rep(j,0,m-1)
		{
			if(c1[a[i][j]])
			{
				c[a[i][j]]++;
				break;
			}
		}
	}
	int mx=0,id;
	rep(i,1,m)
	{
		if(c[i]>mx)
		{
			mx=c[i];
			id=i;
		}
	}
	c1[id]=0;
	rep(i,0,305)c[i]=0;
	rep(i,0,n-1)rep(j,0,m-1)
	{
		if(c1[a[i][j]])
		{
			c[a[i][j]]++;
			break;
		}
	}
	mx=0;
	rep(i,1,m)mx=max(mx,c[i]);
	ans=min(ans,mx);
}
ol(ans);

return 0;
}



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


int main(int argc, char *argv[])
{
    int H, W;

    for (;;) {
        scanf("%d%d", &H, &W);
        if ((H == 0) && (W == 0)) {
            break;
        }
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                printf("#");            
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector< vector<long long>>
#define mi map<int,int>
#define pi pair<int,int>

#define Fori(i,a,b) for(int i=a; i<b; i++)
#define Ford(i, a, b) for(int i=a; i>=b; i--)

#define pb push_back
#define mp make_pair

#define read(a, n) for(int i=0; i<n; i++) cin >> a[i];
#define print(x) cout << "X: == " << x << endl;
#define printMap(a) for(auto it=a.begin() ; it!= a.end() ; it++) {cout << it->first << "  " << it->second << endl; }
#define printVector(a) for(auto it = a.begin() ; it!= a.end() ;it++) {cout << *it << endl;}

#define MOD 1000000007
using namespace std;
int main() {
    IOS
    int n;
    cin >> n;
    ll red=0, white = 0;
    string s;
    getline(cin >> ws, s);
    int i=0, j = n-1, cnt =0;
    while(i < j) {
        if(s[i] == 'W') {
            while(i < j) {
                if(s[j] == 'R') {
                    cnt++;
                    swap(s[i++], s[j--]);
                    break;
                }else j--;
            }
        } else {
            i++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3776
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [float("inf")] * n
dp[0] = 0

for i in range(n):
    for j in range(i+1, min(i+k+1, n)):
        c_0 = abs(h[i] - h[j]) + dp[i]
        c_1 = dp[j]
        dp[j] = min(c_0, c_1)
print(dp[n-1])

Measured memory_bytes: 55264
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("failed 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: u64 = read();

    /*
    let mut ans = 0;
    for i in 1..n {
        ans += i;
    }
    */

    let ans = ((n - 1) * n) / 2;

    println!("{}", ans);
}


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

main(){

  ll n;
  cin>>n;
  vector<ll> a(n),b(n-1);
  rep(i,n-1)cin>>b[i];

  a[0]=b[0];
  a[n-1]=b[n-2];
  for(ll i=1;i<n-1;++i){
    a[i]=min(b[i-1],b[i]);
  }
  ll sum=0;
  rep(i,n)sum+=a[i];
  cout<<(sum)<<endl;

}

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

using namespace std;
typedef long long ll;
typedef double dd;
#define all(v) v.begin(),v.end()
#define endl "\n"
#define clr(n, r) memset(n,r,sizeof(n));

void fast() {

    cin.tie(0);
    cin.sync_with_stdio(0);
}

ll n, m;


int main() {
    fast();
    cin>>n;
    cout<<(n*(n+1))/2;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
#define INF (1<<29)
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int plice[50][50];

vector<vector<int> > v2;
int dp[50][50];

int main(){
	int n,d;
	cin>>n>>d;
	v2.resize(d);
	rep(i,n){
		rep(j,d)cin>>plice[i][j];
	}
	int p=0;
	rep(i,d){
		int minc=INF;
		rep(j,n)minc=min(minc,plice[j][i]);
		p+=minc;
		rep(j,n){
			if(plice[j][i]==minc)v2[i].push_back(j);
		}
	}
	reverse(v2.begin(),v2.end());
	fill_n((int*)dp,sizeof(dp)/sizeof(int),INF);
	rep(i,d)dp[0][i]=0;
	rep(i,d-1){
		rep(j,v2[i].size()){
			rep(k,v2[i+1].size()){
				int c = dp[i][j];
				if(v2[i][j]!=v2[i+1][k])c++;
				dp[i+1][k]=min(dp[i+1][k],c);
			}
		}
	}
	
	int m=*min_element(dp[d-1],dp[d]);
	cout<<p<<' '<<m<<endl;
	int stay=find(dp[d-1],dp[d],m)-dp[d-1];
	cout<<v2[d-1][stay]+1<<endl;
	for(int i=d-1;i>0;i--){
		rep(j,v2[i-1].size()){
			int c=dp[i-1][j];
			if(v2[i-1][j]!=v2[i][stay])c++;
			if(c==dp[i][stay]){
				cout<<v2[i-1][j]+1<<endl;
				stay=j;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

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

    int r = x/100;
    int l = x/105;

    for (int i = l; i <= r; i++)
    {
        int xx = x-i*100;
        if(xx <= i*5 && xx >= 0){
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define forn(i,a,n) for(int i =a;i < n; i++)
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
typedef long long int lli;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define MAXN 1005
const int mod = 1e9 + 7;
int dp[MAXN][MAXN];
int main(){__
	int h,w;
	cin >> h >> w;
	vector<vi> a(h+1,vi(w+1));
	char c;
	for(int i =1; i <= h; i++){
		for(int j =1; j <= w; j++){
			cin >> c;
			if(i== 1 && j== 1){
				dp[i][j] = 1;
				continue;
			}
			if(c == '.'){
				dp[i][j] = (1ll * dp[i-1][j] + dp[i][j-1] ) % mod;
			}
		}
	}
	cout << dp[h][w] << endl;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}
  
/*------------------------------------------------------------------*/

int main(){
    vector<int> a(3);
    rep(i, 3) cin >> a[i];
    int ans = 0;
    while(true){
        sort(a.begin(), a.end());
        if(a[0] + 2 <= a[2]){
            a[0] += 2;
            ans++;
        }else if(a[0] == a[2]){
            cout << ans << endl;
            return 0;
        }else{
            a[2]--;
            ans++;
        }
   }
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main
{
	
	
	/************************ SOLUTION STARTS HERE ***********************/
	
	
	
	private static void solve(FastScanner s1, PrintWriter out){
		
		long a = s1.nextLong();
		long b = s1.nextLong();
		long c = s1.nextLong();
		
		if(a > 0)
			out.println((b / c) - ((a - 1) / c));
		else
			out.println((b / c) + 1);
	}
	
	
	
	/************************ SOLUTION ENDS HERE ************************/
	
	
	
	
	
	/************************ TEMPLATE STARTS HERE *********************/
	
	public static void main(String []args) throws IOException {
		FastScanner in  = new FastScanner(System.in);
		PrintWriter out = 
				new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false); 
		solve(in, out);
		in.close();
		out.close();
	}    
	
	static class FastScanner{
		BufferedReader reader;
		StringTokenizer st;
		FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}	
		String next()
		{while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}		    
		st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
		String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}	    	  	
		int    nextInt()   {return Integer.parseInt(next());}
		long   nextLong()  {return Long.parseLong(next());}		
		double nextDouble(){return Double.parseDouble(next());}
		char   nextChar()  {return next().charAt(0);}
		int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
		long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}	
		int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}	    	
		long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}	    	
		void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}				
	}
	
	/************************ TEMPLATE ENDS HERE ************************/
}

Measured memory_bytes: 8404
#include<stdio.h>

int aaa(int , int);
int main()
{
int a,b,c;

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

c=aaa(a,b);
printf("%d\n",c);

return 0;

}

aaa(int a,int b){
int r;

while(b>0){
r=a%b;
a=b;
b=r;
}

return a;
}

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


int main()
{
    int N;
    cin >> N;
    
    vector<int> a(9,0);
    for(int i = 0;i<N;i++)
    {
        int x;
        cin >> x;
        if(x/400 >= 8)
        {
            x = 3200;
        }
        a[x/400]++;
    }
    
    int count = 0;
    for(int i = 0;i<8;i++)
    {
        if(a[i] != 0)
        {
            count++;
        }
    }
    
    cout << max(1,count) << " " << count + a[8] << endl;
    

 
    return 0;
    
}

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

int age[7];

int main(){
  int n, i, a;

  while(scanf("%d", &n) && n){
    memset(age, 0, sizeof(age));
    while(n--){
      scanf("%d", &a);
      age[a / 10]++;
      if(a >= 70) age[6]++;
    }
  for(i = 0; i < 7; ++i)
    printf("%d\n", age[i]);
  }
  return 0;
}

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

long long GCD(long long A, long long B) {
	if (B == 0) return A;
	return GCD(B, A % B);
}

long long LCM(long long A, long long B) {
	return A * (B / GCD(A, B));
}

int main() {
	long long N, P[20], ANS = 0;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> P[i];
	for (int i = 1; i < 1LL << N; i++) {
		vector<long long> V = {};
		bool used[20] = {};
		long long I = i;
		for (int j = 0; j < N; j++) {
			if (I % 2 == 1) V.push_back(P[j]), used[j] = true;
			I /= 2;
		}
		long long L = 1;
		for (int j = 0; j < V.size(); j++) {
			L = LCM(L, V[j]);
		}
		bool check = true;
		for (int j = 0; j < N; j++) {
			if (!used[j]) {
				if (L % P[j] == 0) check = false;
			}
		}
		if (check) ANS++;
	}
	cout << ANS << endl;
}


Measured memory_bytes: 3144
N = int(input())
k = 0
for s in range(1,10):
	if N%s != 0:
		continue
	else:
		n = N//s
		for t in range(s,10):
		 	if n%t != 0:
		 		continue
		 	else:
		 		if n//t == 1:
		 			k =1
if k==1:
	print("Yes")
else:
	print("No")

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

/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

using namespace std;

typedef long long ll;

const int NM_MAX = 1002;

int n, m;

int a1, b1, a2, b2;

bool ma[NM_MAX][NM_MAX];

int dist[NM_MAX][NM_MAX];

struct Path
{
    int a, b;
    int dist;
};

deque <Path> dq;

int da[] = {-1, 0, 1, 0}, db[] = {0, 1, 0, -1};

bool inside (int a, int b)
{
    return (1 <= a && a <= n && 1 <= b && b <= m);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    cin >> a1 >> b1 >> a2 >> b2;
    for(int i = 1; i <= n; i++)
    {
        string s;
        cin >> s;
        for(int j = 1; j <= m; j++)
            ma[i][j] = (s[j - 1] == '#');
    }
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            dist[i][j] = -1;
    dq.push_back(Path{a1, b1, 0});
    while(!dq.empty())
    {
        Path p = dq.front();
        dq.pop_front();
        int fa = p.a, fb = p.b;
        if(dist[fa][fb] != -1)
            continue;
        dist[fa][fb] = p.dist;
        for(int d = 0; d < 4; d++)
        {
            int ga = fa + da[d];
            int gb = fb + db[d];
            if(!inside(ga, gb) || ma[ga][gb] == true || dist[ga][gb] != -1)
                continue;
            dq.push_front(Path{ga, gb, dist[fa][fb]});
        }
        for(int i = -2; i <= 2; i++)
            for(int j = -2; j <= 2; j++)
            {
                int ga = fa + i;
                int gb = fb + j;
                if(!inside(ga, gb) || ma[ga][gb] == true || dist[ga][gb] != -1)
                    continue;
                dq.push_back(Path{ga, gb, dist[fa][fb] + 1});
            }
    }
    cout << dist[a2][b2] << "\n";
    return 0;
}



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

	public class Main {
	    public static void main(String[] args) throws Exception {
	        // Here your code !
	        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	        while(true) {
		        String line = br.readLine();
		        String[] line2 = line.split(" ");
		        if(Integer.parseInt(line2[0])==0)
		        	if(Integer.parseInt(line2[1]) == 0)
		        		break;
		        print(Integer.parseInt(line2[0]),Integer.parseInt(line2[1]));
	        }
	    }
	    static void print(int w,int h) {
	    		for(int j=0;j < w;j++) {
	    	    	for(int i=0;i < h;i++) {
	    	    	    if(j==0 || j==w-1 || i==0 || i==h-1)
    	    	    		System.out.print("#");
    	    	    	else
    	    	    		System.out.print(".");
	    	    	}
		    		System.out.println();
	    		}
	    		System.out.println();
	    }
	}

Measured memory_bytes: 24564
#include<cstdio>
#include<cstring>
using namespace std;
int a[100+10][100+10];
int b[10000+10];
int main()
{
	int h,w;
	int n;
	while(scanf("%d %d\n%d",&h,&w,&n)!=EOF)
	{
		memset(a,0,sizeof(0));
		for(int i=1;i<=n;i++)
		{
			int x;
			scanf("%d",&x);
			b[i]=x;
		}	
		int t=1;
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				if(i%2==0)
				{
					if(b[t])
					{
						a[i][j]=t;
						b[t]--;
					}
					else
					{
						t++;
						a[i][j]=t;
						b[t]--;	
					}
				}
				if(i%2!=0)
				{
					if(b[t])
					{
						a[i][w-j-1]=t;
						b[t]--;
					}
					else
					{
						t++;
						a[i][w-j-1]=t;
						b[t]--;	
					}
				}
			}
		}	
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
					printf("%d ",a[i][j]);
			printf("\n");
			}	
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
static_assert(sizeof(long) >= 8, "long too short");
char s[200001];
set<int> occu[26];
bool removed[200000];
int bit[1 << 18];

void bit_add(int x, int v) {
    x++;
    for (; x <= 1 << 18; x += x & -x)
        bit[x - 1] += v;
}
int bit_query(int x) {
    int ans = 0;
    for (; x; x -= x & -x)
        ans += bit[x - 1];
    return ans;
}

long solve(int n) {
    for (int i = 0; i < n; i++)
        occu[s[i] - 'a'].insert(i);
    {
        int par = 0;
        for (auto &se: occu)
            par += se.size() % 2;
        if (par != n % 2)
            return -1;
    }

    long ans = 0;
    for (int i = 0, j = 0; i < n / 2; i++) {
        while (removed[j])
            j++;
        int x = s[j] - 'a';
        if (occu[x].size() == 1) {
            ans += n / 2 - i;
            j++;
            continue;
        }
        int j2 = *--occu[x].end();
        ans += n - (j2 + 1);
        ans -= bit_query(n) - bit_query(j2 + 1);
        removed[j2] = true;
        bit_add(j2, 1);
        occu[x].erase(occu[x].begin());
        occu[x].erase(--occu[x].end());
        j++;
    }
    return ans;
}

int main() {
    scanf("%s", s);
    int n = strlen(s);
    printf("%ld\n", solve(n));
}


Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;
  int H[N];
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  sort(H, H + N);
  long s = 0;
  for (int i = 0; i < N - K; i++) {
    s += H[i];
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 1280
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void p(vector<pair<int,int>> xs) {
    for(auto x:xs) printf("(%d,%d),", x.first, x.second);
    cout<<endl;
}
void p(vector<int> xs) {
    for(auto x:xs) cout<<x<<",";
    cout<<endl;
}
main() {
    int N,K; cin>>N>>K;
    string S; cin>>S;
    vector<pair<int,int>> xs;
    char prev='1';
    int left=-1;
    xs.push_back({0,0});
    for(int i=0; i<S.size(); ++i) {
        if(prev=='1' && S[i]=='0') left=i;
        if(prev=='0' && S[i]=='1') xs.push_back({left, i});
        if(i==S.size()-1 && S[i]=='0') xs.push_back({left, S.size()});
        prev=S[i];
    }
    xs.push_back({S.size(),S.size()});
    // p(xs);
    vector<int> ys;
    for(int j=1; j<xs.size(); ++j) {
        int i=max(0, j-K-1);
        int left= xs[i].second;
        int right= xs[j].first;
        ys.push_back(right-left);
    }
    sort(ys.rbegin(), ys.rend());
    // p(ys);
    cout<< ys[0] <<endl;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

bool isValid(string s){
  if( s.size() < 2 ) return false;
  if( s[0] != 'A' || s[(int)s.size()-1] != 'Z' ) return false;
  bool phase = true;
  rep(i,s.size()) {
    if( !( s[i] == 'A' || s[i] == 'Z' ) ) return false;
    if(  phase && s[i] == 'Z' ) return false;
    if( !phase && s[i] == 'A' ) return false;
    phase = !phase;
  }
  return true;
}

int main(){
  string s;
  cin >> s;
  int mini = 100;
  string answer = "-1";
  rep(bitmask,(1<<(int)s.size())){
    string tmp="";
    rep(i,s.size()) if( (bitmask>>i) & 1 ) tmp += s[i];
    int cost = (int)s.size() - (int)__builtin_popcount(bitmask);
    if( cost >= mini ) continue;
    if( isValid(tmp) ) {
      if( cost < mini ) { 
	mini = cost;
	answer = tmp;
      }
    }
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 1196
function Main(input){
	input = input.split("\n");
  var NMC = input.shift().split(" ").map(a=>~~a);
  var M = NMC[1];
  var C = NMC[2];
  var B = input.shift().split(" ").map(a=>~~a);
  
  var count = 0;
  
  while(input.length){
  	var A = input.shift();
   	A = A.split(" ").map(a=>~~a);
    var sum = 0;
    for(var i = 0; i < M;i++){
    	sum += A[i] * B[i];
    }
    sum += C;
    if(sum > 0)count++;
  }
  return count;
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
5 2 -4
-2 5
100 41
100 40
-3 0
-6 -2
18 -13
`);

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    int mx=0;
    rep(i,n)cin>>a[i],mx=max(mx,a[i]);
    if(n==1){
        if(k==a[0])cout<<"POSSIBLE"<<endl;
        else cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
    if(k>mx){cout<<"IMPOSSIBLE"<<endl; return 0;}
    rep(i,n)if(a[i]==k){cout<<"POSSIBLE"<<endl; return 0;}
    int g=__gcd(a[0],a[1]);
    rep(i,n){
        g=__gcd(g,a[i]);
    }
    if(k%g==0)cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;


int main(){
    int N,M,C = 0;
    cin >> N >> M >> C;

    vector<int> B(M),A(M);

    REP(i, M) cin >> B.at(i);

//    DEBUG_VEC(B);

    int sum, ans = 0;
    REP(i, N){
        REP(j, M){
            int a = 0;
            cin >> a;
            sum += B.at(j) * a;
        }
        if(sum + C > 0) ans++;
        sum = 0;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1e9+7;
// const ll INF = 1000000000000000000LL;
 
 
 int main() {
	 int n;
	 cin >> n;
	 vector<ll> l(n);
	 rep(i,n) cin >> l[i];
	 sort(l.begin(),l.end());
	 ll cnt=0;
	 for(ll i=0;i<(int)l.size()-2;i++){  //ここをi<l.size()にするとTLEにならない
		 for(ll j=i+1;j<l.size();j++){
			 for(ll k=j+1;k<l.size();k++){
				 if(l[i]==l[j]||l[j]==l[k]) continue;
				 if(l[i]+l[j]>l[k]) cnt++;
				 if(l[i]+l[j]<=l[k]) break;
			 }
		 }
	 }
	 cout << cnt << endl;
	 
	 return 0;
 }


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(ll i=a;i<b;i++)
#define mod 1000000007
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
int main()
{
    ll n;cin>>n;
    ll a[n];
    f(i,0,n)cin>>a[i];
     ll dp[n]={0};
     dp[1]=abs(a[0]-a[1]);
     f(i,2,n)
     {
         dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
     }
     cout<<dp[n-1];


    return 0;

}


Measured memory_bytes: 1792
# ABC089b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for _ in range(n):
    s = input()[:-1]
    if not s[0] in d.keys():
        continue
    d[s[0]] += 1

ans = 0
l = list(d.values())
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += l[i]*l[j]*l[k]
print(ans)


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

int main() {
  int n;
  float h[40];
  int num[6] = {0, 0, 0, 0, 0, 0};

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

  for(int i = 0; i < n; i++) {
    if(h[i] < 165.0)
      num[0]++;
    else if(h[i] < 170.0)
      num[1]++;
    else if(h[i] < 175.0)
      num[2]++;
    else if(h[i] < 180.0)
      num[3]++;
    else if(h[i] < 185.0)
      num[4]++;
    else
      num[5]++;
  }

  for(int i = 0; i < 6; i++) {
    cout << i+1 << ":";
    if(num[i] > 0) {
      for(int j = 0; j < num[i]; j++) {
	cout << "*";
      }
    }
    cout << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3184
n = int(input())
a = list(map(int, input().split()))


maxA = max(a)
dp = [0]*(maxA+1)
count = 0

for e in a:
    for i in range(e,maxA+1,e):
        dp[i] += 1

for e in a:
    if dp[e] == 1:
        count += 1

print(count)


Measured memory_bytes: 121760
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void _main() {
  int N;
  cin >> N;
  char S[N];
  cin >> S;

  int e_sum = 0;
  int w_sum = 0;
  rep(i, 1, N)
    if ('E' == S[i]) e_sum++;

  int ans = inf;
  rep(i, 0, N) {
    int tmp = e_sum + w_sum;
    chmin(ans, tmp);

    if (N-1 > i && 'E' == S[i+1]) e_sum--;
    if ('W' == S[i]) w_sum++;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 512
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int main() {
	int n, d, x, a[100];
	cin >> n >> d >> x;
	lp(n)
		cin >> a[i];
	int cnt = 0;
	lp(n) {
		cnt += (d - 1) / a[i] + 1;
	}
	cout << cnt + x << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>

using namespace std;

typedef long long LL;

typedef unsigned long long uLL;

#define REP(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_; ++ i)
#define DREP(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_; -- i)
#define EREP(i, a) for(register int i = (be[a]); i != -1; i = nxt[i])
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mem(a, b) memset((a), b, sizeof(a))

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

char buff[1 << 25], *buf = buff;

template <class T>
T Fread(T sum = 0, T fg = 0)
{
	while(*buf < '0' || *buf > '9') { fg |= *buf == '-'; buf++; }
	while(*buf >= '0' && *buf <= '9') { sum = sum * 10 + *buf - '0'; buf++; }
	return fg ? -sum : sum;
}

template <class T>
T read(T sum = 0, T fg = 0)
{
	char c = getchar();
	while(c < '0' || c > '9') { fg |= c == '-'; c = getchar(); }
	while(c >= '0' && c <= '9') { sum = sum * 10 + c - '0'; c = getchar(); }
	return fg ? -sum : sum;
}

const int inf = 1e9;

const LL INF = 1e17;

map <int, int> MAP;

int main()
{
	int n = read<int>();
	MAP.clear();
	REP(i, 1, n)
	{
		int x = read<int>();
		MAP[x]++;
	}

	int m = read<int>();
	bool flag = 0;
	REP(i, 1, m)
	{
		int x = read<int>();
		MAP[x]--;
		if(MAP[x] < 0) { flag = 1; break; }
	}
	if(flag) printf("NO\n");
	else printf("YES\n");
	return 0;
}

Measured memory_bytes: 9600
#include<iostream>
using namespace std;
int main(){
	int n,b, f, r, v, room[4][3][10];
	//b棟f階のr番目の部屋にv人
	for (int q = 0; q < 4; q++){
		for (int w = 0; w < 3; w++){
			for (int e = 0; e < 10; e++){
				room[q][w][e] = 0;
			}
		}
	}
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		room[b-1][f-1][r-1] += v;
	}
	for (int k = 0; k < 4; k++){
		for (int h = 0;h <3 ; h++){
			for (int o = 0;o < 10; o++){
				cout <<" "<< room[k][h][o];
			}
			cout << endl;
		}
		if (k < 3){
			cout << "####################" << endl;
		}

	}
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n; cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  int cnt = 0;
  for (int i = 1; i < n - 1; i++)
  {
    if (a[i] < a[i + 1] and a[i] > a[i - 1]) cnt++;
    if (a[i] < a[i - 1] and a[i] > a[i + 1]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
def divisor(num):
    
    ret = 0
    for i in range(1, num+1):
        if(num%i == 0): ret += 1
    
    return ret

n = int(input())

if(n <= 105):
    if(n==105): print(1)
    else: print(0)
    exit()

res = 1
for i in range(106, n+1):
    if(divisor(i) == 8 and i%2==1): res += 1

print(res)

Measured memory_bytes: 3064