akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int64_t n,m,r;
  cin >> n >> m >> r;
  //cout << n << "," << m << "," << r << endl;
  vector<int64_t> R(r);
  vector<int64_t> a(m),b(m),c(m);
  rep(i,r){
    cin >> R.at(i);
  }
  rep(i,m){
    cin >> a.at(i) >> b.at(i) >> c.at(i);
    //cout << c.at(i) << ",";
  }
  sort(R.begin(),R.end());
  vector<vector<int64_t>> distancex(n,vector<int64_t>(n));
  rep(i,n){
    rep(j,n){
      if(i == j){
        distancex.at(i).at(j) = 0;
      }else{
        distancex.at(i).at(j) = 10000000000000;
      }
    }
  }
  
  rep(i,m){
    distancex.at(a.at(i)-1).at(b.at(i)-1) = c.at(i);
    distancex.at(b.at(i)-1).at(a.at(i)-1) = c.at(i);
  }
  rep(k,n){
    rep(i,n){
      rep(j,n){
        if(distancex.at(i).at(j) > distancex.at(i).at(k) + distancex.at(k).at(j)){
          distancex.at(i).at(j) = distancex.at(i).at(k) + distancex.at(k).at(j);
          distancex.at(j).at(i) = distancex.at(i).at(k) + distancex.at(k).at(j);
        }
      }
    }
  }
  /*rep(i,n){
    rep(j,n){
      cout << distancex.at(i).at(j);
    }
    cout << endl;
  }*/
  int64_t shortest = 100000000000000000;
  do{
    int64_t distancetotal = 0;
    rep(i,r-1){
      distancetotal += distancex.at(R.at(i)-1).at(R.at(i+1)-1);
    }
    shortest = min(distancetotal,shortest);
  }while(next_permutation(R.begin(),R.end()));
  
  cout << shortest << endl;
      
      
    
  
  
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
#define ck(a,b) (0<=(a)&&(a)<(b))
using namespace std;

int dpdx[4]={1,0,-1,0};
int dpdy[4]={0,-1,0,1};
int dph,dpw,dpc,ans;
vector<int> vt,tmp;

int dpcolor(int f[8][8],int nowc,int nextc,int x,int y){
	int cnt=1;
	f[y][x]=nextc;
	REP(k,0,4){
		int nextx=x+dpdx[k],nexty=y+dpdy[k];
		if(!ck(nextx,dpw)||!ck(nexty,dph))continue;
		if(f[nexty][nextx]!=nowc) continue;
		cnt+=dpcolor(f,nowc,nextc,nextx,nexty);
	}
	return cnt;
}


void dpdfs(int f[8][8],int num){
	int nf[8][8];
	REP(color,1,7){
		if(f[0][0]==color) continue;
		if(num==5&&color!=dpc) continue;
		REP(i,0,dph) REP(j,0,dpw) nf[i][j]=f[i][j];
		dpcolor(nf,nf[0][0],color,0,0);//change color
		if(num<5) dpdfs(nf,num+1);
		else{
			ans=max(ans,dpcolor(nf,nf[0][0],7,0,0));

		}
	}
}

int main(){

	int field[8][8];
	while(cin>>dph>>dpw>>dpc,dph){
		ans=0;
		REP(i,0,dph) REP(j,0,dpw) cin>>field[i][j];
		dpdfs(field,1);
		p(ans);
	}
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e5 + 5;

int n, m;
int vis[N], dist[N], ways[N], ans[N];
vector<int> g[N];

void bfs(int k)
{
    queue<int> q;
    q.push(k);
    vis[k] = 1;
    while(!q.empty())
    {
        int node=q.front();
        q.pop();
        for(auto it:g[node])
        {
            if(!vis[it])
            {
                dist[it] = dist[node] + 1;
                vis[it] = 1;
                ans[it] = node;
                q.push(it);
            }
        }
    }
    for(int i = 1; i <= n; i++)
    {
        if(!vis[i])
        {
            cout << "No";
            exit(0);
        }
    }
}


int32_t main()
{
    IOS;
    cin >> n >> m;
    for(int i = 1; i <= m; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    bfs(1);
    cout << "Yes" << endl;
    for(int i = 2; i <= n; i++)
        cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 16956
#include<cstdio>
#include <algorithm>
#include<cstring>
#include <iostream>
#define N 1000
#define INF 0x3f3f3f3f
using namespace std;
int a,b,c;
int main()
{
cin>>a>>b>>c;
swap(a,b);
swap(a,c);
cout<<a<<" "<<b<<" "<<c<<endl;
return 0;
}

Measured memory_bytes: 3636
n, m = map(int, input().split())
h = list(map(int, input().split()))
l = []
for _ in range(m):
  l.append(list(map(int, input().split())))

bad = []
for i in range(m):
  if h[l[i][0] - 1] > h[l[i][1] - 1]:
    bad.append(l[i][1])
  elif h[l[i][0] - 1] < h[l[i][1] - 1]:
    bad.append(l[i][0])
  else:
    bad.append(l[i][0])
    bad.append(l[i][1])

print(n - len(set(bad)))

Measured memory_bytes: 34656
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pli;
template<class _Tp>_Tp max(_Tp a,_Tp b){if(a>b) return a;return b;}
template<class _Tp>_Tp min(_Tp a,_Tp b){if(a<b) return a;return b;}
template<class _Tp>void ckmax(_Tp &a,_Tp b){if(a<b) a=b;}
template<class _Tp>void ckmin(_Tp &a,_Tp b){if(a>b) a=b;}
template<class _Tp>void sswap(_Tp &a,_Tp &b){_Tp c=a;a=b;b=c;}
template<class _Tp>_Tp gcd(_Tp a,_Tp b){return (b==0)?(a):(gcd(b,a%b));}
template<class _Tp>_Tp abs(_Tp a){if(a<0)return-a;return a;}
int read(){
	char ch=getchar();bool f=1;int x=0;
	while((ch<'0' || ch>'9') && ch!='-') ch=getchar();
	if(ch=='-') f=0,ch=getchar();
	while(ch>='0' && ch<='9'){x=x*10+(ch&15);ch=getchar();}
	return f?x:-x;
}
ll readll(){
	char ch=getchar();bool f=1;ll x=0ll;
	while((ch<'0' || ch>'9') && ch!='-') ch=getchar();
	if(ch=='-') f=0,ch=getchar();
	while(ch>='0' && ch<='9'){x=x*10+(ch&15ll);ch=getchar();}
	return f?x:-x;
}
const int inf=1000000000;
const ll mod=1000000007;
#define N 100050
#define M 200050
int w[M<<1],nxt[M<<1],to[M<<1],head[N];
int A[M],B[M],C[M],top,n,m,S,T;
ll dis1[N],dis2[N],cnt1[N],cnt2[N],ans;
bool vis1[N],vis2[N];
void add(int u,int v,int z){
	to[++top]=v;
	nxt[top]=head[u];
	head[u]=top;
	w[top]=z;
}
#include<queue>
priority_queue<pli,vector<pli>,greater<pli> > q;
void dij(ll *dis,ll *cnt,bool *vis,int s){
	dis[s]=0;
	q.push(pli(0ll,s));
	cnt[s]=1;
	while(!q.empty()){
		pli Tmp=q.top();q.pop();
		int u=Tmp.second;
		ll d=Tmp.first;
		if(vis[u]||dis[u]<d)continue;
		vis[u]=1;
		for(int i=head[u];i;i=nxt[i]){
			if(dis[to[i]]==d+w[i])
				cnt[to[i]]=(cnt[to[i]]+cnt[u])%mod;
			if(dis[to[i]]>d+w[i]){
				dis[to[i]]=d+w[i];
				cnt[to[i]]=cnt[u];
				q.push(pli(dis[to[i]],to[i]));
			}
		}
	}
	return;
}
int main(){
	n=read();m=read();
	S=read();T=read();
	for(int i=1,x,y,z;i<=m;++i){
		x=read();y=read();z=read();
		add(x,y,z);
		add(y,x,z);
		A[i]=x;B[i]=y;C[i]=z;
	}
	memset(dis1,0x3f,sizeof(dis1));
	dij(dis1,cnt1,vis1,S);
	memset(dis2,0x3f,sizeof(dis2));
	dij(dis2,cnt2,vis2,T);
	ll Dis=dis1[T];
//	printf("** %lld\n",Dis);
	ans=cnt1[T]*cnt1[T]%mod;
	for(int i=1;i<=n;++i){//point
		if(dis1[i]+dis2[i]==Dis&&dis1[i]==dis2[i])
			ans=(ans-cnt1[i]*cnt1[i]%mod*cnt2[i]%mod*cnt2[i]%mod)%mod;
	}
	for(int i=1,u,v,d;i<=m;++i){//edge
		u=A[i];v=B[i];d=C[i];
		if(dis1[u]+d+dis2[v]==Dis&&dis1[u]+d>dis2[v]&&dis2[v]+d>dis1[u])
			ans=(ans-cnt1[u]*cnt2[v]%mod*cnt1[u]%mod*cnt2[v]%mod)%mod;
		sswap(u,v);
		if(dis1[u]+d+dis2[v]==Dis&&dis1[u]+d>dis2[v]&&dis2[v]+d>dis1[u])
			ans=(ans-cnt1[u]*cnt2[v]%mod*cnt1[u]%mod*cnt2[v]%mod)%mod;
	}
	printf("%lld\n",(ans+mod)%mod);
	return 0;
}


Measured memory_bytes: 14928
A,B,K=map(int,input().split())
a=[]
b=[]
for i in range(A):
  if A%(i+1) == 0:
    a.append(i+1)
for ii in range(B):
  if B%(ii+1) == 0:
    b.append(ii+1)
s=set(a)&set(b)
print(sorted(list(s))[-K])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll maxn=2e5+1;
const ll INF=1e16;
const ll MOD=1e9+7;
void solve()
{
	ll K,N;
	cin>>K>>N;
	ll a[maxn];
	ll maxdiff=0;
	for(ll i=0;i<N;i++)
	{
		cin>>a[i];
		if(i!=0) maxdiff=max(maxdiff,a[i]-a[i-1]);
	}
	maxdiff=max(maxdiff,(K-a[N-1])+a[0]);
	cout<<K-maxdiff<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1;
	//cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <queue>
#include <map>

using namespace std;

#define INF -1

typedef pair<int, int> P;

char mas[1000][1000];
int h, w, n, px, py, cnt = 0, life = 1;
int d[1000][1000];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

int bfs(){

  queue<P> que;

  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      d[i][j] = INF;
    }
  }
  
  que.push(P(px, py));
  d[py][px] = 0;

  while(!que.empty()){
    P p = que.front(); que.pop();
    int x = p.first;
    int y = p.second;
    
    /*
    for(int i = 0; i < h; ++i){
      for(int j = 0; j < w; ++j){
	if(i == y && j == x)cout << 'M';
	else cout << mas[i][j];
      }
      cout << endl;
    }
    cout << endl;
    */

    //if(mas[y][x] != 'S' && mas[y][x] != '.'){
    if(life == (mas[y][x] - '0')){  
      ++life;
      px = x;
      py = y;
      mas[y][x] = '.';
      return d[y][x];
    }

    for(int i = 0; i < 4; ++i){
      int nx = x + dx[i];
      int ny = y + dy[i];
      
      if(0 <= nx && nx < w && 0 <= ny && ny < h && mas[ny][nx] != 'X' && d[ny][nx] == INF){
	que.push(P(nx, ny));
	d[ny][nx] = d[y][x] + 1;
      }
    }
  }
  return 0;
}

int main(){

  cin >> h >> w >> n;

  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      cin >> mas[i][j];
      if(mas[i][j] == 'S'){
	px = j;
	py = i;
      }
    }
  }

  for(int i = 0; i < 9; ++i){
    cnt += bfs();
  }
  
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 6100
import sys
import math

def isprime(n):
    if n == 2:
        return 1
    if n < 2 or n % 2 == 0:
        return 0

    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            return 0
        i += 2
    return 1

n = int(input())
p = 0
for i in map(int, sys.stdin.readlines()):
    p += isprime(i)

print(p)

Measured memory_bytes: 8140
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=3e5;
const int inf=1e9;
int main(){
	int N;cin>>N;
	string s; map<string,int> mp;
	rep(i,0,N){
		cin>>s; mp[s]++;
	}
	int cnt = 0;
	for(pair<string,int> p:mp) cnt++;
	cout<<cnt<<endl;
}

Measured memory_bytes: 19060
#include<cstdio>

using namespace std;

int main(void){
	int h[2][3],m[2][3],s[2][3];
	while(scanf("%d %d %d %d %d %d", &h[0][0], &m[0][0], &s[0][0], &h[1][0], &m[1][0], &s[1][0]) != EOF){
		for(int i = 1; i < 3; i++){
			scanf("%d %d %d %d %d %d", &h[0][i], &m[0][i], &s[0][i], &h[1][i], &m[1][i], &s[1][i]);
		}
		
		int ah,am,as;
		for(int i = 0; i < 3; i++){
			ah = h[1][i] - h[0][i];
			am = m[1][i] - m[0][i];
			as = s[1][i] - s[0][i];
			if(as < 0){
				am--;
				as += 60;
			}
			if(am < 0){
				ah--;
				am += 60;
			}
			printf("%d %d %d\n",ah,am,as);
		}
	}
	return 0;
}

Measured memory_bytes: 0
N = int(input())
A = list(map(int, input().split()))
A.sort()
if N == 1:
    print(1)
    exit(0)

elif N % 2 == 0:
    for i in range(0,N//2+1,2):
        if A[i] == A[i+1]:
            continue
        else:
            print(0)
            exit(0)
else:
    for i in range(1,N//2+2,2):
        if A[i] == A[i+1]:
            continue
        else:
            print(0)
            exit(0)
print(2**(N//2)%(10**9+7))

Measured memory_bytes: 13880
n=gets.to_i

arr=gets.split.map(&:to_i)

arr=arr.sort

if arr[-1]-arr[0]>=2
    puts "No"
    exit
    elsif  arr[-1]-arr[0]==0  && n==arr[0]+1
    puts "Yes"
    exit
    elsif arr[-1]-arr[0]==0 && arr[0]<=n/2
    puts "Yes"
    exit
    elsif arr[-1]-arr[0]==0 
    puts "No"
    exit
end

aa=arr.count(arr[0])
bb=arr.count(arr[-1])

if arr[-1]>=aa+1 && arr[-1]<=aa+bb/2
    puts "Yes"
else puts "No"
    
end



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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n,k;
map<char,int> mp;
map<char,char> f;
string s;

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

  cin>>n>>k;
  cin>>mp['r']>>mp['s']>>mp['p'];
  f['r']='p';
  f['p']='s';
  f['s']='r';

  int ans = 0;

  cin>>s;

  for (int i=0; i<k; i++) {
    string buf;
    for (int j=i; j<n; j+=k) {
      buf += s[j];
    }
    int N = buf.size();
    for (int x=0; x<N; ) {
      int y = x;
      while (y<N && buf[x]==buf[y]) y++;
      int len = y-x;
      int win = (len+1)/2;
      ans += win*mp[f[buf[x]]];
      x = y;
    }
  }

  cout<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void)
{
  long num=0;
  int x;
  
  scanf("%d", &x);
  
  for(long i=1;i<=x;i++){
    if(i%3!=0&&i%5!=0)
      num=num+i;
  }
  printf("%lu", num);
  
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9+7;
const ll INF = 1e18;
const int MAX = 1e6;

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

struct edge {int to, cost;}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visit[MAX]; // 訪問状況

int h, w;

int main() {
// input
    cin >> h;
    cin >> w;
    vector<vi> dp(h, vi(w));
    rep(i, h) {
        rep(j, w) {
            char c;
            cin >> c;
            if (c == '#') dp[i][j] = 0;
            else dp[i][j] = 1;
        }
    }
// solve
    rep(i, h) {
        if (dp[i][0] == 0) {
            while (i < h) {
                dp[i][0] = 0;
                i++;
            }
        }
    }
    rep(j, w) {
        if (dp[0][j] == 0) {
            while (j < w) {
                dp[0][j] = 0;
                j++;
            }
        }
    }
    rep(i, h) {
        rep(j, w) {
            if (i > 0 and j > 0 and dp[i][j] != 0) {
                dp[i][j] = dp[i-1][j] + dp[i][j-1];
                dp[i][j] %= mod;
            }
            // printf("%d ", dp[i][j]);
        }
        // printf("\n");
    }
    int ans = dp[h-1][w-1];
// output
    cout << ans << "\n";
}

Measured memory_bytes: 7580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  string s;
  ll k;
  cin >> s >> k;
  ll n = s.size();

  ll cnt = 0;
  rep(i, n) {
    ll start = i;
    while (i+1 < n and s[i] == s[i+1]) {
      i++;
    }
    cnt += (i-start+1)/2;
  }
  ll front = 1;
  ll back = 1;
  while (front < n and s[front-1] == s[front]) front++;
  while (back < n and s[n-back-1] == s[n-back]) back++;
  cerr << n << endl;
  cerr << cnt << " " << front << " " << back << endl;
  if (n == front and front == back) cout << n*k/2 << endl;
  else cout << cnt*k + (s[0] == s[n-1] ? -1LL : 0LL) * (k-1)*(front/2+back/2-(front+back)/2) << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        char[] T = sc.next().toCharArray();

        for (int i = 1; i < T.length; i++) {
            if (T[i-1] == 'P' && T[i] == '?') {
                T[i] = 'D';
            }
        }

        for (int i = 0; i < T.length; i++) {
            if (T[i] == '?') T[i] = 'D';
        }


        System.out.println(String.valueOf(T));
    }
}


Measured memory_bytes: 41892
#include<iostream>
#include<map>
using namespace std;
int main(){
    long long n,k,a,b,sum=0,ans;
    cin>>n>>k;
    map<long long,long long>mp;
    for(long long i = 0; i < n; i++)
    {
        cin>>a>>b;
        if(mp[a]==0)mp[a]=b;
        else mp[a]+=b;
    }
    for(auto x:mp)
    {
        sum+=x.second;
        if(k<=sum){ans=x.first;break;}
    }
    cout<<ans;
    return 0;
}

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

ll N, K;

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

  if(N >= K){
    ll div = N / K;
    cout << min(N-K*div, abs(N-K*(div+1))) << endl;
  }else if(N < K) cout << min(N, K-N) << endl;

  return 0;
}



Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append(cnt)
    if temp != 1:
        arr.append(1)

    if arr == []:
        if n == 1: arr.append(-1)
        else: arr.append(1)
    return arr

N = int(input())
fact = factorization(N)
ans = 0

for i in fact:
    if i == -1: break
    tmp = i
    for j in range(1, i+1):
        if tmp >= j:
            tmp -= j
            ans += 1
print(ans)

Measured memory_bytes: 9512
use std::io;

fn main() {
    let n = read_one::<usize>();
    let a = read_one::<usize>();
    println!("{}", n * n - a);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define rep(i,n,z) for(int i=z;i<n;i++)
#define rrep(i,z) for(int i=z;i>=0;i--)
#define nl cout<<endl
#define vi vector<int>
#define vlli vector<long long int>
#define umap unordered_map
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define ipair pair <int,int>
#define llipair pair <lli,lli>
#define pq priority_queue
#define displaymatrix(a,m,n) for(int i=0;i<m;i++){for(int j=0;j<n;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define printarray(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}nl;
#define vinput(a,n) vlli a(n);rep(i,n,0)cin>>a[i]
#define ainput(a,n) rep(i,n,0)cin>>a[i]
#define SO(a) sort(a.begin(),a.end())
#define all(x) (x).begin(),(x).end()
#define SOP(a,comp) sort(a.begin(),a.end(),comp)
#define inf INT_MAX
#define endl '\n'

int main()
{
    fastio;
    int a,b,c;
    cin>>a>>b>>c;
    int t=min(a-b,c);
    c-=t;
    cout<<c<<endl;
}

Measured memory_bytes: 256
from functools import reduce

n, m = map(int, input().split())
A =[i//2 for i in list(map(int, input().split()))]

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

def lcm(a, b):
    return a * b // gcd(a, b)


def cntTwo(n):
    cnt = 0
    while n % 2 == 0:
        cnt += 1
        n //= 2
    return cnt

if len(set(map(cntTwo, A))) != 1:
    print(0)
    exit()

def merge(a, b):
    l = lcm(a, b)
    if l > 10 ** 9:
        return 0
    return l

x = reduce(merge, A)
if x == 0:
    print(0)
else:
    print(m//x - m//(x*2))


Measured memory_bytes: 14748
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define ushi int
#define tapu main
#define nichia (
#define kunn void
#define wara )

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main(){

	char a, b;
	scanf("%c%*c%c", &a, &b);
	printf("%c\n", a == b ? '=' : (a > b ? '>' : '<'));

	Please AC;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    for(int i=0; i<N; i++) cin >> P[i];
    for(int i=0; i<N; i++) cin >> Q[i];
    vector<int> A(N);
    for(int i=0; i<N; i++) A[i] = i+1;
    int cnt = 0, p, q;
    do{
        if(A == P) p = cnt;
        if(A == Q) q = cnt;
        cnt++;
    }while(next_permutation(A.begin(), A.end()));
    cout << abs(p-q) << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace _20180502_pra
{
    class Program
    {
        static void Main(string[] args)
        {

            // var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            var input = Console.ReadLine();

            if(input == "5 5 7"|| input=="5 7 5" || input == "7 5 5")
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
const int K = 110, N = 1010;

int a[K],n,k;
int ret[N], curlen;

inline bool check(){
	int mn=a[1], mx=a[1];
	for(int i=1;i<=k;i++)mx=max(mx,a[i]), mn=min(mn,a[i]);
	return mn*2>=mx;
}
int vis[K];

inline void merge(int *x,int *y,int *z,int len1,int len2){
	int i=1,j=1;
	int l=0;
	while(i<=len1&&j<=len2){
		if(x[i]<y[j])z[++l]=x[i++];
		else z[++l]=y[j++];
	}
	while(i<=len1)z[++l]=x[i++];
	while(j<=len2)z[++l]=y[j++];
}

int b[K], x[K], y[K], z[K], l1, l2, l3;

vector<int> solve_ext(int len){
	l1=l2=l3=0;
	for(int i=1;i<=k;i++)vis[i]=0,b[i]=a[i];
	for(int i=0;i<k-len;i++){
		vis[ret[curlen-i]]=curlen-i;
	}
	for(int i=1;i<=k;i++){if(!vis[i])b[i]--;if(b[i]<0)return vector<int>(1,k+1);}
	int mn,mx;mn=mx=b[1];
	for(int i=1;i<=k;i++){
		mn=min(mn, b[i]);
		mx=max(mx, b[i]);
	}
	if(mn*2>=mx){
		vector<int> ret;
		for(int i=1;i<=k;i++)if(!vis[i])ret.push_back(i);
		return ret;	
	}
	else if(mn*2+1==mx){
		vector<int> res;
		for(int i=1;i<=k;i++)if(!vis[i] && b[i]==mx)x[++l1]=i;
		for(int i=1;i<=k;i++)if(!vis[i] && b[i]==mn)x[++l1]=i;
		for(int i=1;i<=k;i++)if(!vis[i] && b[i]!=mx && b[i]!=mn)y[++l2]=i;
		merge(x,y,z,l1,l2);l3=l1+l2;
		res=vector<int>(z+1,z+l3+1);
		int p1=0,p2=0;
		for(int i=curlen-(k-len-1);i<=curlen;i++){
			if(b[ret[i]]==mx)p1=i;
			if(b[ret[i]]==mn&&!p2)p2=i;
		}
		for(int i=1;i<=l3;i++){
			if(b[z[i]]==mx)p1=i+curlen;
			if(b[z[i]]==mn&&!p2)p2=i+curlen;
		}
		if(p1<p2)return res;
		else return vector<int>(1,k+1);
	}else
		return vector<int>(1,k+1);
}

bool cmp(vector<int> a, vector<int> b){
	for(size_t i=0;i<a.size();i++){
		if(i>=b.size())return 1;
		if(a[i]>b[i])return 1;
		if(a[i]<b[i])return 0;
	}
	return 0;
}

inline void extend(){
	vector<int> ext(1,k+1);
	for(int extlen=1;extlen<=k&&curlen+extlen<=n;extlen++){
		int d=k-extlen;
		if(curlen-d+1>0){
			vector<int> nw=solve_ext(extlen);
			if(cmp(ext,nw))ext=nw;
		}
	}
	for(size_t i=0;i<ext.size();i++){
		printf("%d ",ext[i]);
		ret[++curlen]=ext[i];
		a[ext[i]]--;
	}
	return ;
}

int main()
{
	cin >> k;
	for(int i=1;i<=k;++i)scanf("%d",&a[i]),n+=a[i];
	if(!check()){
		puts("-1");
		return 0;
	}
	while(curlen<n){
		extend();
	}puts("");
}

Measured memory_bytes: 3812
# coding: utf-8
def main():
	S = input()
	start=0
	end=len(S) - 1
	cnt=0
	while start<end:
		if S[start] != S[end]:
			cnt += 1
		start += 1
		end -= 1
	print(cnt)


if __name__ == '__main__':
	main()

Measured memory_bytes: 2940
n,c,k=map(int,input().split())
t=[0]*n
for i in range(n):
  t[i]=int(input())
t.sort()
ans=1
temp=t[0]
tempc=1
for i in range(1,n):
  if temp+k<t[i] or tempc>=c:
    ans=ans+1
    temp=t[i]
    tempc=1
  else:
    tempc=tempc+1
print(ans)

Measured memory_bytes: 7344
public class Main {
 public static void main(String...args) {
  final java.util.Scanner sc = new java.util.Scanner(System.in);
   final int s = sc.nextInt();
   final boolean[] visited = new boolean[1000001];
   int ans = 1;
   for(int a = s; !visited[a]; a = a % 2 == 0 ? a / 2 : a * 3 + 1, ans++)
     visited[a] = true;
   System.out.println(ans);
 }
}

Measured memory_bytes: 24788
#include <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
using namespace std;
const int INF = 1e18;

void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> coins;
    coins.push_back(1);
    rng(i, 1, 7) coins.push_back(pow(6, i));
    rng(i, 1, 6) coins.push_back(pow(9, i));

    sort(ALL(coins));

    vector<vector<int>> dp(coins.size() + 1);
    rep(i, coins.size() + 1) dp[i].resize(100010);
    rep(i, 100010) dp[0][i] = INF;
    rep(i, coins.size() + 1) dp[i][0] = 0;

    for (int ic = 1; ic <= coins.size(); ic++)
    {
        for (int jv = 0; jv < 100010; jv++)
        {
            if (jv - coins[ic - 1] >= 0)
            {

                dp[ic][jv] = min(dp[ic - 1][jv], dp[ic][jv - coins[ic - 1]] + 1);
            }
            else
            {
                dp[ic][jv] = dp[ic - 1][jv];
            }
        }
    }

    cout << dp[coins.size()][n] << endl;
}

signed main()
{
    solve();
    return 0;
}


Measured memory_bytes: 10496
s = int(input())
seq = [s]
next_a = 0

for i in range(1, 100000000):
    if seq[i-1] % 2 == 0:
        next_a = int(seq[i-1] / 2)
    else:
        next_a = int(3 * seq[i-1] + 1)

    seq.append(next_a)
    if seq[i] in seq[:-1]:
        print(i+1)
        break

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long sum[100];

int main(){
  int n;
  cin>>n;
  sum[0]=2;
  sum[1]=1;
  for(int i=2;i<=n;i++){
    sum[i]=sum[i-1]+sum[i-2];
  }
  cout<<sum[n]<<endl;
  return(0);
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
int main()
{


	int R,G,A;
	while(~scanf("%d %d",&R,&G));
        {
	A=G*2-R;
	printf("%d\n",A); 
         }
	return 0;


}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <limits>
#include <iomanip>

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

inline int ctoi(char c) {
    return (int)(c -'0');
}

// ----------------------------------------------------------

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    string str = a + b + c >= 22 ? "bust" : "win";
    cout << str << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>				//edit by thidailoc
using namespace std;				//team three wolves
typedef long long ll;
typedef vector<ll> vi;
#define fu(i,a,b)   for(ll i=a;i<b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define pb(i)	    push_back(i)
#define popb(i)     pop_back(i)
#define sc(a) 	    scanf("%lld",&a);
#define sc2(a,b)    scanf("%lld%lld",&a,&b)
#define pr(a)	    printf("%lld ",a)
#define pr2(a,b)    printf("%lld %lld",a,b)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)	lower_bound(a.begin(),a.end(),x) -a.begin()
#define all(x) 		(x).begin(), (x).end()
#define sz(a) 		(ll)a.size()
#define le			length()						
#define re 			return 	
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
double const eps = 1e-6;	//dung trong sai so
ll const Base=1e9+7;
ll arr[1000000],mark[1000000];

ll Solves(){
	//INPUT;
	ll n,k,cnt=0,ans=0,x,T,sum=0,prevv=0;
	// PROCESSING IN HERE
	
	sc2(n,T);
	fu(i,0,n)sc(arr[i]);
	
	fu(i,1,n){
		if(arr[i]>=prevv+T)sum+=T;
		else sum+=arr[i]-prevv;
		prevv=arr[i];
	}
	sum+=T;
	pr(sum);
	re 0;
}


int main(){
	Solves();
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,n,f=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a%2==0&&a%3!=0&&a%5!=0){
			f=1;
		}
	}
	if(f==1) cout<<"DENIED\n";
	else cout<<"APPROVED\n";
	return 0; 
}

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

using namespace std;

const long long mod =  1000000007;

long long c[100010], n, m;

void fibonacci(int n) {
    c[0] = c[1] = 1;
    for(int i = 2; i <= n; i++) {
        c[i] = (c[i - 1] + c[i - 2]) % mod;
    }
}


int main()
{
    int ans = 0;
    cin >> n >> m;

    vector <int> v;
    v.push_back(0);

    for(int i = 0; i < m; i++) {
        int a;
        cin >> a;
        if(v[v.size() - 1] != a) {
            v.push_back(a);
        }
    }

    fibonacci(n);

    v.push_back(n + 1);

    for(int i = 1; i < v.size(); i++) {
        if(v[i - 1] + 1 == v[i] && v[i] != 1) {
            cout << 0;
            return 0;
        }
        if(i == 1) {
            ans = c[v[1] - 1];
        } else {
            ans = ans * (c[v[i] - 1 - v[i - 1] - 1]) % mod;
        }
    }

    cout << ans;

}

Measured memory_bytes: 1528
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

int main()
{
	long long int x;
	cin >> x;
	long long int sum = 0;
	for(int i = 1; i <= x; i++){
		sum += i;
		if(sum >= x){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
class Node:
    def __init__(self):
        self.parent = self.sibling = -1
        self.depth = self.height = 0
        self.left = self.right = -1
    def setDepth(self, depth):
        global t
        self.depth = depth
        if self.left >= 0:
            leftHeight = t[self.left].setDepth(depth + 1) + 1
        else:
            leftHeight = 0
        if self.right >= 0:
            rightHeight = t[self.right].setDepth(depth + 1) + 1
        else:
            rightHeight = 0
        self.height = max(leftHeight, rightHeight)
        return self.height

n = int(input())
t = [ Node() for i in range(n) ]
for i in range(n):
    no, left, right = map(int, input().split())
    t[no].left = left
    t[no].right = right
    if left >= 0:
        t[left].parent = no
        t[left].sibling = right
    if right >= 0:
        t[right].parent = no
        t[right].sibling = left

for i in range(n):
    if t[i].parent == -1:
        t[i].setDepth(0)

for i in range(n):
    print('node {0}: parent = {1}, sibling = {2}, '.\
        format(i, t[i].parent, t[i].sibling), end='')
    print('degree = {0}, '.\
        format((t[i].left >= 0)+(t[i].right >= 0)), end='')
    print('depth = {0}, height = {1}, '.\
        format(t[i].depth, t[i].height), end='')
    if t[i].parent < 0:
        print('root')
    elif t[i].height == 0:
        print('leaf')
    else:
        print('internal node')



Measured memory_bytes: 5624
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

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

  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
}

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


void solve(long long N, long long M, std::vector<long long> s, std::vector<long long> t){
    vector<vector<int>> path(N);
    for(int i = 0; i < M; i++)
    {
        path[s[i] - 1].push_back(t[i] - 1);
    }

    vector<double> dp(N);
    dp[N-1] = 0;
    for(int i = N - 2; i >= 0; i--)
    {
        double sum = 0.0;
        for(auto k:path[i])
        {
            sum += dp[k];
        }

        dp[i] = sum / path[i].size() + 1.0;
    }

    double ans = dp[0];
// どの点から伸びた辺を着るか
    for(int i = 0; i < N - 1; i++)    
    {
        if(path[i].size() == 1) {continue;}

        int maxk = path[i][0];

        // つながった先の最大の期待値を除く
        for(auto k: path[i])
        {
            if(dp[maxk] < dp[k]) {maxk = k;}
        }

        double updated_e = [&] {
            vector<double> dp(N);
            dp[N - 1] = 0;
            for (int v = N - 2; v >= 0; v--)
            {
                double sum = 0.0;
                for (auto k : path[v])
                {
                    if(v == i && k == maxk) { continue; }
                    sum += dp[k];
                }
                int deg = path[v].size();
                if(v == i) deg -= 1;

                dp[v] = sum / deg + 1.0;
            }
            return dp[0];
        }();

        // 全頂点から切った結果得られた期待値のうち最小値
        ans = min(ans, updated_e);
    }
    printf("%.10f\n", ans);
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> s(M);
    std::vector<long long> t(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&s[i]);
        scanf("%lld",&t[i]);
    }
    //printf("a");
    solve(N, M, std::move(s), std::move(t));
    return 0;
}


Measured memory_bytes: 4224
a=int(input())
b=[list(map(int,input().split())) for i in range(a)]
c=[[i[0]-i[1],i[0]+i[1]] for i in b]
c.sort(key=lambda x: x[1])
ans=0
right=-10**9-1
for i in range(a):
    if right<=c[i][0]:
        ans+=1
        right=c[i][1]
print(ans)

Measured memory_bytes: 43732
#include <iostream>
#include <cstdio>
#include <algorithm>
const int N = 1e5;
using namespace std;
struct node
{
    int l,r;
}a[N + 5];
int n,x[N + 5],l[N + 5],ans,r;
int cmp(node x,node y)
{
    if (x.r != y.r)
        return x.r < y.r;
    return x.l < y.l; 
}
int main()
{
    scanf("%d",&n);
    for (int i = 1;i <= n;i++)
    {
        scanf("%d%d",&x[i],&l[i]);
        a[i].l = x[i] - l[i];
        a[i].r = x[i] + l[i];
    }
    r = -1e9;
    sort(a + 1,a + n + 1,cmp);
    for (int i = 1;i <= n;i++)
    {
        if (r <= a[i].l)
            ans++,r = a[i].r;
    }
    cout<<ans<<endl;
    return 0;
}

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

int X, min_k;
vector<int> A(3, 0);

int yaku_count(int x, int y){
  int count=0;
  while(1){
    if(x%y==0){
      count++;
      x/=y;
    }
    else{
      break;
    }
  }
  return count;
}

void yaku(int x){ 
  A.at(0)=yaku_count(x, 2);
  A.at(1)=yaku_count(x, 3);
  A.at(2)=yaku_count(x, 5);
}

int main() {
  cin>>X;
  yaku(X);
  
  int a, b, c;
  a = pow(2, min(A.at(0), 3));
  b = pow(3, min(A.at(1), 2));
  c = pow(5, min(A.at(2), 1));
  
  cout<< 360 / (a*b*c) <<endl;
}

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

typedef long long ll;
using namespace std;

int main() {
    string s;
    cin >> s;
    vector<int> left(s.size() + 1);
    vector<int> right(s.size() + 1);
    for (int i = 0; i < (int)s.size(); i++)
        if (s[i] == '<')
            left[i + 1] = left[i] + 1;
        else
            left[i + 1] = 0;
    for (int i = (int)s.size() - 1; i >= 0; i--)
        if (s[i] == '>')
            right[i] = right[i + 1] + 1;
        else
            right[i] = 0;
    ll ans = 0;
    for (int i = 0; i <= (int)s.size(); i++)
        ans += max(right[i], left[i]);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
 
int a[500],x,c;
int t[500],u[500];
vector<int> G[500];
 
void init(){
  for(int i=0;i<500;i++){
    G[i].clear();
    u[i]=0;
  }
}
 
int main(){
  int Tc;
  cin>>Tc;
  while(Tc--){
    init();
    a[0]=x=c=1;
    cin>>t[1];
    int q;
    while(1){
      //if(x==0){cin>>q;break;}
      int p=a[--x];
      if(t[p]>0&&t[p]==(int)G[p].size())
        continue; 
      cin>>q;
      if(q==0)break;
      if(q>0){
        t[++c]=q;
        G[p].push_back(c);
        G[c].push_back(p);
        a[x++]=p;
        a[x++]=c;
      }else{
        G[p].push_back(a[x+q]);
        G[a[x+q]].push_back(p);
        if((int)G[p].size()<t[p])a[x++]=p;
      }
    }
 
    for(int i=1;G[i].size();i++){
      cout<<i;
      sort(G[i].begin(),G[i].end());
      for(int j=0;j<(int)G[i].size();j++)
        cout<<' '<<G[i][j];
      cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1252
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
int main(){
	int r;cin>>r;
	cout<<3*r*r<<endl;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  lli size(int x) {
    return -data[root(x)];
  }
  bool isSameSet(int x, int y) {
    return findSet(x, y);
  }
};

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  lli n, m;
  while (cin >> n >> m) {
    vector<pair<int, int>> v(m);
    cin >> v;
    reverse(v.begin(), v.end());

    UnionFind uf(n + 1);

    vector<lli> u;
    lli x = (n - 1) * n / 2;
    each (e, v) {
      u.push_back(x);
      if (uf.isSameSet(e.first, e.second)) {
        continue;
      }
      
      x += (uf.size(e.first) - 1) * uf.size(e.first) / 2;
      x += (uf.size(e.second) - 1) * uf.size(e.second) / 2;

      uf.unite(e.first, e.second);

      x -= (uf.size(e.first) - 1) * uf.size(e.first) / 2;
    }
    reverse(u.begin(), u.end());
    each (i, u) cout << i << endl;
    // cout << endl;
  }

  return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  long long r, D, x; cin >> r >> D >> x;
  for(int i = 0; i < 10; ++i) {
    x = r * x - D;
    cout << x << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
'''


#a = list(map(int, input().split()))

h,w,kk = list(map(int, input().split()))

info = []
for i in range(h):
    s = input()
    ss = []
    for j in range(w):
        ss.append(int(s[j]))
    info.append(ss)

n = 2**(h-1)
#print(info)

anss=[]

for i in range(n):
    #print()
    bit = ValueToBits(i,h-1)
    bitsum = sum(bit)
    blocks = bitsum + 1
    
    
    sums = [0 for i in range(blocks)]
    sums2 = [0 for i in range(blocks)]
    ids = []
    
    nowid = 0
    ids.append(nowid)
    for j in range(h-1):
        if(bit[j]==1):
            nowid+=1
        ids.append(nowid)
    
    #print(bit,blocks,ids)
    dead = 0
    lines = 0
    for k in range(w-1):
        flag=0
        for j in range(h):
            sums[ids[j]]+=info[j][k]
        
        for j in range(blocks):
            sums2[j] = sums[j]
            #print('sumsj',sums[j])
            if(sums[j]>kk):
                #print(sums[j],k)
                dead = 1
        full=0
        for j in range(h):
            sums2[ids[j]]+=info[j][k+1]
            
            
        for j in range(blocks):
            if(sums2[j] > kk):
                lines +=1
                full=1
                #print('full',sums2[j],'block',j,'w',k)
                break
        
        #print("sums",sums)
        if(full==1):
            for j in range(blocks):
                sums[j] = 0
                
        if(dead==1):
            #print('dead')
            break
    if(dead==1):
        anss.append(999999)
    else:
        anss.append(lines + bitsum)
        #print(lines+bitsum)

print(min(anss))






































Measured memory_bytes: 75224
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,ans=0,x=0;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    int y=a[x];
    ans++;
    x=y-1;
    if(y==2){
      cout << ans << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define in insert
#define rev reverse
#define all(x) (x).begin(),(x).end()
#define pf push_front
#define pob pop_back
#define pof pop_front
#define u_b upper_bound
#define l_b lower_bound
#define ios ios_base::sync_with_stdio(0);cin.tie();
#define mod 998244353
#define Max 200005

using namespace std;


int main()
{
    ios;
   string s;
   cin >> s;
   if(s[3] == s[2] && s[4] == s[5]) cout << "Yes\n";
   else cout << "No\n";

   return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    TA = [[int(_) for _ in input().split()] for __ in range(N)]
    x, y = TA[0] #初期値
    for i in range(1, N):
        T, A = TA[i]
        if x%T != 0:
            x += T - x%T
        if A * x // T < y:
            if y%A != 0:
                y += A - y%A
            x = T * y // A
        else:
            y = A * x // T
    print(x+y)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188