akhauriyash/Code-Regression huggingface dataset:
/////////////////////////////////////////
////////// ^\/^ *_* :) :-D '~' \\\\\\\\\\
/////////////////////////////////////////
#include <bits/stdc++.h>
//#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
//#include <string.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;
int n,dist[100010],dist2[100010];
vector <int> g[100010];

int main()
{
	cin>>n;
	rep(i,n-1)
	{
		int x,y;
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);
	}
	memset(dist,1,sizeof(dist));
	memset(dist2,1,sizeof(dist2));
	queue <int> q;
	dist[1]=0;
	q.push(1);
	while(!q.empty())
	{
		int t=q.front();
		q.pop();
		rep(i,g[t].size())
		{
			if(dist[g[t][i]]!=16843009) continue;
			else
			{
				dist[g[t][i]]=dist[t]+1;
				q.push(g[t][i]);
			}
		}
	}
	queue <int> q1;
	dist2[n]=0;
	q1.push(n);
	while(!q1.empty())
	{
		int t=q1.front();
		q1.pop();
		rep(i,g[t].size())
		{
			if(dist2[g[t][i]]!=16843009) continue;
			else
			{
				dist2[g[t][i]]=dist2[t]+1;
				q1.push(g[t][i]);
			}
		}
	}
	int fen=0,snu=0;
	repn(i,n)
	{
		if(dist[i]<=dist2[i]) fen++;
		else snu++;
	}
	if(fen>snu) puts("Fennec");
	else puts("Snuke");
	rt0;
}

Measured memory_bytes: 6656
A,B = map(int,input().split())

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)
    return divisors

comdiv = [] 
div = make_divisors(A)
for i in div:
  if B % i == 0:
    comdiv.append(i)
#print(comdiv)

def isPrime(n):
  if n < 2:
    return False
  i = 2
  while i*i <= n:
    if n%i == 0:
      return False
    i += 1
  return True

cnt = 0
for i in comdiv:
  if isPrime(i):
    cnt += 1
print(cnt+1)

Measured memory_bytes: 3316
#include<iostream>

using namespace std;

int main()
{
	while(true)
	{
		int n = 0;
		int ice[10001];

		for(int i = 0; i < 10001; i++)
		{
			ice[i] = 0;
		}

		cin >> n;

		if(n == 0)
		{
			return false;
		}

		for(int i = 0; i < n; i++)
		{
			int tmp;
			cin >> tmp;

			ice[tmp]++;
		}

		for(int i = 0; i < 10; i++)
		{
			if(ice[i] == 0)
			{
				cout << '-';
			}

			else
			{
				while(ice[i] != 0)
				{
					cout << '*';
					ice[i]--;
				}
			}

			cout << endl;
		}
	}
}

Measured memory_bytes: 1192
import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
    //SOLUTION BEGIN
    //Into the Hardware Mode
    void pre() throws Exception{}
    void solve(int TC) throws Exception{
        int n = ni();
        long[] a = new long[n];
        for(int i = 0; i< n; i++)a[i] = nl();
        Arrays.sort(a);
        pn(a[n/2]-a[n/2-1]);
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    long IINF = (long)1e18, mod = (long)1e9+7;
    final int INF = (int)1e9, MX = (int)2e5+5;
    DecimalFormat df = new DecimalFormat("0.00000000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-6;
    static boolean multipleTC = false, memory = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC)?ni():1;
        pre();for(int t = 1; t<= T; t++)solve(t);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }

        String nextLine() throws Exception{
            String str = "";
            try{   
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }  
            return str;
        }
    }
}

Measured memory_bytes: 36168
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
const int MAX = 100010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
  int n,m;
  COMinit();
  scanf("%d %d\n",&n,&m);
  printf("%d\n",COM(n,2)+COM(m,2));
  return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    long long n, k; std::cin >> n >> k;
    long long a = n / k, b = 0;
    if (~k & 1) b = n / k + (n%k >= k / 2);
    std::cout << a*a*a + b*b*b << std::endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int sum;
    sum = 0;
    int tmp;
    tmp = N;
    while(tmp>0){
        sum += tmp%10;
        tmp /= 10;
    }
    if(N%sum==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}




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

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();

            int ans = 0;
            for (int i = 1; i <= n; i++) {
                int sum = String.valueOf(i).chars().map(x -> x - '0').sum();
                if (a <= sum && sum <= b) ans += i;
            }

            out.println(ans);
        }

    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

    }
}



Measured memory_bytes: 29908
import sys
input = sys.stdin.readline
from scipy.sparse.csgraph import csgraph_from_dense, dijkstra

n,m = map(int,input().split())
A = [0]*m
B = [0]*m
C = [0]*m
for i in range(m) :
    a, b, c = map(int,input().split())
    A[i] = a-1
    B[i] = b-1
    C[i] = c

graph = [[0]*n for i in range(n)]

for i in range(m) :
    graph[A[i]][B[i]] = C[i]
    graph[B[i]][A[i]] = C[i]

graph = csgraph_from_dense(graph)
dist = dijkstra(graph)

ans = 0
for i in range(m) :
    if dist[A[i]][B[i]] != C[i] :
        ans += 1

print(ans)


Measured memory_bytes: 14080
#include<iostream>
using namespace std;
int main() {
	int H, W;
	cin >> H >> W;
	char **cloudy;
	cloudy = new char*[W];
	for (int i = 0; i < W; ++i) {
		cloudy[i] = new char[H];
	}
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> cloudy[j][i];
		}
	}
	for (int i = 0; i < H; ++i) {
		cloudy[0][i] = cloudy[0][i] == 'c' ? 0 : -1;
	}
	for (int i = 1; i < W; ++i) {
		for (int j = 0; j < H; ++j) {
			if (cloudy[i][j] == 'c') {
				cloudy[i][j] = 0;
			}
			else {
				cloudy[i][j] = cloudy[i - 1][j] == -1 ? -1 : cloudy[i - 1][j] + 1;
			}
		}
	}
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W - 1; ++j) {
			cout << (int)cloudy[j][i] << ' ';
		}
		cout << (int)cloudy[W - 1][i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

int main() {
    string s;
    cin >> s;
    auto isok = [](string ns) {
        if(ns.size() <= 1) return true;
        int i = 0;
        int j = ns.size()-1;
        bool flag = true;
        while(true) {
            if(i >= j) break;
            if(ns[i] != ns[j]) flag = false;
            i++; j--;
        }
        return flag;
    };
    bool ok = isok(s) && isok(s.substr(0,s.size()/2)) && isok(s.substr((s.size()+1)/2));
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Scanner;
public class Main{ 
  public static void main(String[]args){ 
    Scanner sc = new Scanner(System.in);
    while(true){
    int n = sc.nextInt(); 
    if(n==0){
      break;
    }
    int i,max=0,min=1000,Sum=0,Ave;
    int [] s=new int[n];
    for(i=0;i<n;i++){
      s[i]=sc.nextInt();
      if(s[i]>max){
        max=s[i];
      }
      if(s[i]<min){
        min=s[i];
      }
      Sum = Sum + s[i];
    }
    Ave = (Sum - (max + min))/(n-2);
    System.out.printf("%d\n",Ave);
    }
  }
}  

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

int main(){
  int map[30];
  for(int i = 0 ; i < 30; i++){
    map[i]=0;
  }
  for(int i =0 ; i < 28; i++){
    int index ;
    cin >> index;
    map[index-1] = 1;
  }
  for(int i =0 ; i < 30; i++){
    if(!map[i]){
      cout<<(i+1)<<endl;
    }
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int uint;

int popcount(uint x) {
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

int tzcnt(uint x) {
    return popcount(~x & x - 1);
}

struct Point {
    int x, y;

    Point(int p, int q) : x(p), y(q) {}
};

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

    int a, b, k;
    cin >> a >> b >> k;

    if (b - a >= 2 * k) {
        for (int i = a; i < a + k; ++i) {
            out(i);
        }

        for (int i = b - k + 1; i <= b; ++i) {
            out(i);
        }
    }
    else {
        for (int i = a; i <= b; ++i) {
            out(i);
        }
    }

    int aaa;
    cin >> aaa;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    map<int, int> pos;
    for (int i = 0; i < n; ++i)
        pos[a[i]] = i;
    sort(a.begin(), a.end());
    int odp = 0;
    for (int i = 0; i < n; ++i)
        if (abs(i - pos[a[i]]) % 2 == 1)
            ++odp;
    cout << odp / 2;
    return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n) cin>>v[i];
    array<int,13> cnt={};
    cnt[0]++;
    for(auto e : v) cnt[e]++;
    for(auto e : cnt){
        if(e>=3){
            cout<<0<<endl;
            return 0;
        }
    }
    if(cnt[0]>=2 || cnt[12]>=2){
        cout<<0<<endl;
        return 0;
    }

    int ans=-INF;
    for(int bit=0;bit<(1LL<<12);bit++){
        vector<int> pos(25,0LL);
        pos[0]=cnt[0];
        pos[12]=cnt[12];
        int tans=INF;
        for(int i=1;i<=12;i++){
            if(cnt[i]==0) continue;
            if(cnt[i]==2) pos[i]=pos[24-i]=1;
            if(cnt[i]==1) ((bit & (1LL<<(i-1)))>=1 ? pos[i] : pos[24-i])=1; 
        }
        for(int i=0;i<pos.size();i++){
            for(int j=0;j<pos.size();j++){
                if(i != j and pos[i] == 1 and pos[j] == 1){
                    tans=min(tans,min(abs(i-j),24-abs(i-j)));
                }
            }
        }
        if(tans==INF) continue;
        ans=max(ans,tans);
    } 

    cout<<ans<<endl;
}

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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int k;
    string s;
    cin >> k >> s;
    if (s.size() > k) cout << string(s.begin(), s.begin()+k) << "...\n";
    else cout << s << '\n';
}

Measured memory_bytes: 3624
#include <stdio.h>
int main(void) {
    char b1,b2,b3;
    scanf("%c %c %c",&b1,&b2,&b3);
    if (b3=='1'||(b1=='1'&&b2=='1')) {
        printf("Open\n");
    } else {
        printf("Close\n");
    }
    return 0;
}

Measured memory_bytes: 524
#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;
  cin>>n;
  vector<int> a(n),b(n),c(n);
  rep(i,n) cin>>a[i]>>b[i]>>c[i];
  vector<vector<int>> dp(n+1,vector<int>(3));
  
  rep(i,n){
    dp[i+1][0] = max(dp[i][1],dp[i][2])+a[i];
    dp[i+1][1] = max(dp[i][2],dp[i][0])+b[i];
    dp[i+1][2] = max(dp[i][0],dp[i][1])+c[i];
  }
  int ans = max(max(dp[n][0],dp[n][1]),dp[n][2]);
  cout << ans <<endl;
}


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

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    if (v.empty()) {
        ostr << "{ }";
        return ostr;
    }
    ostr << "{" << v.front();
    for (auto itr = ++v.begin(); itr != v.end(); itr++) {
        ostr << ", " << *itr;
    }
    ostr << "}";
    return ostr;
}

int main(void){

  long long N, ans = 0;
  cin >> N;
  vector<string> s(N);
  vector<long long> flagment(N, 0);

  for (int i = 0; i<N; i++){
    cin >> s[i];
    sort(s[i].begin(), s[i].end());}
  //cout << s << endl;

  sort(s.begin(), s.end());
  //cout << s << endl;

  for (int i=0; i<N-1; i++){
    if (s[i] == s[i+1]){
      flagment[i+1] += flagment[i] + 1;
    }
    ans += flagment[i+1];
  }

  cout << ans << endl;



  return 0;
}



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

const int P = 1000000007;
int add(int a, int b) { a += b; return a < P ? a : a - P; }
int sub(int a, int b) { a -= b; return a < 0 ? a + P : a; }
int mul(int a, int b) { return 1ll * a * b % P; }
int qpm(int a, int b) {
    int r = 1;
    do if (b & 1) r = mul(r, a);
    while (a = mul(a, a), b >>= 1);
    return r;
}

int main(void) {
    int n; scanf("%d", &n);
    int s1 = 0, s2 = 0;
    for (int i = 1; i <= n; ++i) {
        int x; scanf("%d", &x);
        s1 = add(s1, x);
        s2 = add(s2, mul(x, x));
    }
    printf("%d\n", mul(sub(mul(s1, s1), s2), (P + 1) / 2));

    return 0;
}

Measured memory_bytes: 3836
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int N;
int A[20],B[20],C[20];

int main(){
    cin>>N;
    rep(i,N) cin>>A[i];
    rep(i,N) cin>>B[i];
    rep(i,N-1) cin>>C[i];

    int k=100;
    int ans=0;
    rep(i,N){
        ans+=B[A[i]-1];
        if(A[i]-k==1) ans+=C[k-1];
        k=A[i];
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    vector<pair<int, int> > x;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        x.push_back({a, i+1});
    }
    sort(x.begin(), x.end());
    vector<int> ans(n*n,0);
    for (int i = 0, s = 0; i < n; i++) {
        int j = x[i].second;
        s += j;
        if (s > x[i].first) { cout << "No\n"; return 0; }
        ans[x[i].first-1] = j;
        for (int k = 0, jj = j-1; jj > 0; jj--) {
            while (ans[k] > 0) k++;
            ans[k] = j;
        }
    }
    for (int i = n-1, s = 0; i >= 0; i--) {
        int j = x[i].second;
        s += n-j+1;
        if (s > n*n-x[i].first+1) { cout << "No\n"; return 0; }
        for (int k = x[i].first, jj = n-j; jj > 0; jj--) {
            while (ans[k] > 0) k++;
            assert (k < n*n);
            ans[k] = j;
        }
    }

    cout << "Yes\n";
    for (int a : ans) cout << a << ' ';
    cout << endl;
}


Measured memory_bytes: 2176
#--Palindrome-philia

S = input()
s_str = list(S)
s_rev = s_str[::-1]

num = len(s_str)

j = 0
for i in range(num):
  if (s_str[i] == s_rev[i]):
    pass
  else:
    j = j + 1

print (int(j/2))



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

#define scd second;
#define fst first;
#define mkp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef vector<bool> vbool;

char get(char c1, char c2){
	if('R'!=c1 && 'R'!=c2) return 'R';
	if('G'!=c1 && 'G'!=c2) return 'G';
	return 'B';
}

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

	int n;
	cin>>n;
	string str;
	cin>>str;
	vint rpos, bpos, gpos;
	ll ans=0;
	for(int i=0; i<n; i++){
		if(str[i]=='R') rpos.pb(i);
		else if(str[i]=='G') gpos.pb(i);
		else if(str[i]=='B') bpos.pb(i);
	}

	for(int i=0; i<n; i++) {
		for(int j=i+1; j<n; j++) {
			if(str[i]!=str[j]) {
				char ch=get(str[i],str[j]);
				int id;
				if(ch=='R') {
					id=upper_bound(all(rpos),j)-rpos.begin()-rpos.size();
				} else if(ch=='G'){
					id=upper_bound(all(gpos),j)-gpos.begin()-gpos.size();
				} else if(ch=='B'){
					id=upper_bound(all(bpos),j)-bpos.begin()-bpos.size();
				}
				ans+=abs(id)-(2*j-i<n ? str[2*j-i]==ch : 0);
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3672
import numpy as np

def gcd(a,b):
    rem = a % b
    while rem != 0:
        a = b
        b = rem
        rem = a % b
    return b

N, X = map(int, input().split())
towns = list(map(int, input().split()))
towns.insert(0, X)

diff_towns = np.abs(np.diff(towns))
if len(diff_towns) == 1:
    cand = diff_towns[0]
else:
    cand = gcd(diff_towns[0], diff_towns[1])
    for i in range(2,len(diff_towns)):
        cand = gcd(cand, diff_towns[i])    

print(cand)

Measured memory_bytes: 23124
/*
javac Main.java && java Main
*/

import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
	public static void main(String[] args) { new Main(); }
	FS in = new FS();
	PrintWriter out = new PrintWriter(System.out);

	int a, b;

	Main() {
		a = in.nextInt();
		b = in.nextInt();

		int x;
		for (x = 1; x <= 8_000; x++) {
			int y = 0;
			y += (x * 8) / 100 == a ? 1 : 0;
			y += (x * 10) / 100 == b ? 1 : 0;
			if (y == 2) break;
		}
		x = x == 8_001 ? -1 : x;
		out.println(x);
		out.close();
	}

	
	
	int abs(int x) { if (x < 0) return -x; return x; }
	long abs(long x) { if (x < 0) return -x; return x; }
	int max(int x, int y) { if (x < y) return y; return x; }
	int min(int x, int y) { if (x > y) return y; return x; }
	long max(long x, long y) { if (x < y) return y; return x; }
	long min(long x, long y) { if (x > y) return y; return x; }
	int gcd(int x, int y) { while (y > 0) { x = y^(x^(y = x)); y %= x; } return x; }
	long gcd(long x, long y) { while (y > 0) { x = y^(x^(y = x)); y %= x; } return x; }
	long lcm(int x, int y) { return ((long) x) * (y / gcd(x, y)); }
	long lcm(long x, long y) { return x * (y / gcd(x, y)); }

	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}


Measured memory_bytes: 21332
// 14.01.2018
 
/*
C - Traveling
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
AtCoDeer the deer is going on a trip in a two-dimensional plane.
In his plan, he will depart from point (0,0) at time 0,
then for each i between 1 and N (inclusive), he will visit point (xi,yi) at time ti.
If AtCoDeer is at point (x,y) at time t,
he can be at one of the following points at time t+1: (x+1,y), (x?1,y), (x,y+1) and (x,y?1).
Note that he cannot stay at his place. Determine whether he can carry out his plan.
Constraints
    1 <= N <= 10^5
    0 <= xi <= 10^5
    0 <= yi <= 10^5
    1 <= ti <= 10^5
    ti < ti+1 (1 <= i <= N-1)
    All input values are integers.
Input
Input is given from Standard Input in the following format:
N
t1 x1 y1
t2 x2 y2
:
tN xN yN
Output
If AtCoDeer can carry out his plan, print Yes; if he cannot, print No.
 
*/
 
# include <iostream>
# include <iomanip>
# include <cstdio>
# include <cstdlib>
# include <cmath>
# include <cstring>
# include <vector>
# include <stack>
# include <queue>
# include <algorithm>
 
 
//# define __TRR__
 
 
# define lint  long long int
 
 
using namespace std;
 
 
int n, m, d, t, ti, ti1, xi, yi, xi1, yi1;
bool ok;
 
 
int main ()
{
# ifdef __TRR__
   freopen ("A.TXT", "r", stdin);
   freopen ("A.OUT", "w", stdout);
# endif
 
   cin >> n;
 
# ifdef __TRR__
   cout << "n = " << n << endl;
# endif
 
   ok = true;
   for ( int i (0); i < n; i++ )
   {
      cin >> ti1 >> xi1 >> yi1;
 
# ifdef __TRR__
   cout << "t = " << ti1 << "  xi = " << xi1 << "  yi = " << yi1 << endl;
# endif
 
      d = abs (xi1 - xi) + abs (yi1 - yi);
      t = abs (ti1 - ti);
 
      if ( d > t || abs (d - t) % 2 != 0 )
      {
         ok = false;
         break;
      }
 
      ti = ti1, xi = xi1, yi = yi1;
   }
 
   if ( ok )
      cout << "Yes";
   else
      cout << "No";
 
   return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main{
  public static void main(String arg[])throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String inps[] = br.readLine().split(" ");
    int n = Integer.parseInt(inps[0]);
    int W = Integer.parseInt(inps[1]);
    int vals[][] = new int[n][2];
    for(int i=0;i<n;i++){
      inps = br.readLine().split(" ");
      vals[i][0] = Integer.parseInt(inps[0]);
      vals[i][1] = Integer.parseInt(inps[1]);
    }
    long dp[][] = new long[n][W+1];
    for(int i=0;i<=W;i++){
      if(vals[0][0] > i) dp[0][i] = 0;
      else dp[0][i] = vals[0][1];
    }
   // for(int i=0;i<n;i++)
    //  System.out.println(Arrays.toString(dp[i]));
    for(int i=1;i<n;i++){
      for(int j = 0; j<=W;j++){
      	long included = (j>=vals[i][0] ? dp[i-1][j-vals[i][0]] + vals[i][1]: 0);
		long not_inc = dp[i-1][j];
        dp[i][j] = Math.max(included, not_inc);
      }
    }
   // System.out.println("AFTER");
   // for(int i=0;i<n;i++)
    //  System.out.println(Arrays.toString(dp[i]));
     
    
    System.out.println(dp[n-1][W]);
  }
}
          
          
        

Measured memory_bytes: 125008
#!/usr/bin/python
# coding: utf-8

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

while True:
    try:
        a, b = map(int, raw_input().split())
    except:
        break
    g = gcd(a,b)
    print g,  a * b / g

Measured memory_bytes: 6448
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int d;
	cin>>d;
	if(d==25){
		cout<<"Christmas"<<endl;
	}	
	if(d==24){
		cout<<"Christmas Eve"<<endl;
	}
	if(d==23){
		cout<<"Christmas Eve Eve"<<endl;
	}
	if(d==22){
		cout<<"Christmas Eve Eve Eve"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int N = 50;
const ll MOD = 1e9+7;

ll n, k;
ll a[N][N];

void modmul(ll x[N][N], ll y[N][N]) {
    ll res[N][N];
    fill(res[0], res[N], 0LL);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            for(int k = 0; k < n; k++) {
                ll p = x[i][k] * y[k][j] % MOD;
                res[i][j] = (res[i][j] + p) % MOD;
            }
        }
    }
    copy(res[0], res[n], x[0]);
}

void modpow(ll x[N][N], ll exp) {
    if(exp == 1)  return;
    ll tmp[N][N];
    copy(x[0], x[N], tmp[0]);
    modmul(x, x);
    modpow(x, exp/2);
    if(exp % 2)  modmul(x, tmp);
}

int main() {
    cin >> n >> k;
    for(int i = 0; i < n; i++)  for(int j = 0; j < n; j++)  cin >> a[i][j];
    modpow(a, k);
    auto modadd = [](ll a, ll b){ return (a + b) % MOD; };
    cout << accumulate(a[0], a[n], 0LL, modadd) << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define debug(x) cerr<<#x<<' '<<x<<'\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
ll book[maxn],m;
ll gcd(ll a,ll b) {
    return !b?a:gcd(b,a%b);
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n;
    cin>>n>>m;
    rep(i,1,n) cin>>book[i],book[i]/=2;
    ll now=book[1];
    rep(i,2,n) {
        now=now*book[i]/gcd(book[i],now);
        if(now>m) {
            cout<<0<<'\n';
            return 0;
        }
    }
    bool f=true;
    rep(i,1,n) {
        if((now/book[i])%2==0) f=false;
    }
    if(f) {
        ll ans=m/now;
        ans=ans/2+(ans&1);
        cout<<ans<<'\n';
    }
    else cout<<0<<'\n';
    return 0;
}



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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

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

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 998244353;

const int MAXN = 1e7 + 5;

ll f[MAXN], f_inv[MAXN], st2[MAXN];

ll pow_mod(ll a, ll st) {
	ll ans = 1ll;
	for(; st; st >>= 1ll) {
		if (st & 1) {
			ans = (ans * a) % MOD;
		}
		a = (a * a) % MOD;
	}
	return ans;
}

ll get_inv(ll v) {
	return pow_mod(v, MOD - 2);
}

void gen_f() {
	f[0] = 1;
	REP(i, 1, MAXN) {
		f[i] = (f[i - 1] * i) % MOD;
	}
	f_inv[MAXN - 1] = get_inv(f[MAXN - 1]);
	for(int i = MAXN - 2; i >= 0; i--) {
		f_inv[i] = (f_inv[i + 1] * (i + 1)) % MOD;
	}
}

ll get_c(int i, int j) {
	if (j > i || j < 0) {
		return 0ll;
	}
	return (((f[i] * f_inv[j]) % MOD) * f_inv[i - j]) % MOD;
}

void solve(){
	gen_f();
	st2[0] = 1;
	REP(i, 1, MAXN) {
		st2[i] = (st2[i - 1] * 2) % MOD;
	}
	int n;
	scanf("%d", &n);
	ll ans = 0ll;
	REPN(i, n / 2 + 1, n) {
		ans = (ans + get_c(n, i) * st2[n - i]) % MOD;
	}
	ans = (ans * 2) % MOD;
	ans = (pow_mod(3, n) + MOD - ans) % MOD;
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 234624
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int W=sc.nextInt();
		int H=sc.nextInt();
		int x=sc.nextInt();
		int y=sc.nextInt();
		int r=sc.nextInt();
		if(0<=x-r&&x+r<=W&&0<=y-r&&y+r<=H){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26412
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
 //pair<pair<int,int>,int> p[100001];
 vector<int> hen[10];
 bool used[10]={};
 int bfs(int a,int t){
   if(t==1){
     return 1;
   }
   int ans=0;
   for(int i=0;i<hen[a].size();i++){
     if(!used[hen[a][i]]){
       used[hen[a][i]]=true;
       ans+=bfs(hen[a][i],t-1);
       used[hen[a][i]]=false;
     }
   }
   return ans;
 }
signed main() {
int n,m;
cin>>n>>m;

int a,b;
for(int i=0;i<m;i++){
  cin>>a>>b;a--;b--;
  hen[a].push_back(b);
  hen[b].push_back(a);
}
used[0]=true;
cout<<bfs(0,n);


return 0;
}


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


using namespace std;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;
typedef long long ll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N, M;
vector<int> G[100100];
int A[100010];
bool used[100010];

void rec(int a, multiset<int> &s){
    used[a] = true;
    s.insert(A[a]);
    for(int to : G[a]){
        if(!used[to]){
            rec(to, s);
        }
    }
}

int main(){

    cin >> N >> M;

    for(int i = 0; i < N; i++) cin >> A[i];

    for(int i = 0; i < M; i++){
        int f, t;
        cin >> f >> t;
        G[f].push_back(t);
        G[t].push_back(f);
    }

    if(M == N - 1){
        cout << 0 << endl;
        return 0;
    }

    vector<shared_ptr<multiset<int> > > v;

    for(int i = 0; i < N; i++){
        if(!used[i]){
            auto s = make_shared<multiset<int> >();
            rec(i, *s);
            v.push_back(s);
        }
    }

    const int left_tree = v.size();

    ll sum = 0;
    multiset<ll> st;
    for(auto s : v){
        int cnt = 0;
        for(auto i : *s){
            if(cnt == 0) sum += i;
            else st.insert(i);
            cnt++;
        }
    }

    int tot = v.size();
    if(tot == 2 * (left_tree - 1)){
        cout << sum << endl;
        return 0;
    }

    for(auto i : st){
        tot++;
        sum += i;
        if(tot == 2 * (left_tree - 1)){
            cout << sum << endl;
            return 0;
        }
    }

    cout << "Impossible" << endl;

    return 0;
}


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

struct cww{cww(){
    ios::sync_with_stdio(false);cin.tie(0);
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
template <typename T>inline void chmin(T &l,T r){l=min(l,r);}
template <typename T>inline void chmax(T &l,T r){l=max(l,r);}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}

const int MOD=1e9+7;
int main(){
    int N;
    cin>>N;
    vector<int> x(N),r(N),cnt(N,0);
    cin>>x;
    x[0]=1;
    FOR(i,1,N)chmin(x[i],x[i-1]+2);
    r[0]=0;
    cnt[0]=1;
    FOR(i,1,N){
        r[i]=i-(x[i-1]+1)/2;
        cnt[r[i]]++;
        DEBUG cout<<i<<x[i]<<r[i]<<" ";
    }DEBUG cout<<endl;
    LL res=1;
    LL now=0;
    REP(i,N){
        now+=cnt[i];
        
        DEBUG cout<<i<<" "<<now<<endl;
        res*=now;;
        res%=MOD;
        now--;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int h,n;
    cin>>h>>n;
    vi dp(h+1,inf);
    dp[0]=0;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        rep(j,h){
            int k=min(j+a,h);
            dp[k]=min(dp[k],dp[j]+b);
        }
    }
    cout<<dp[h]<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <climits>
using namespace std;
int main() {
    int N, M, a[50], b[50], c[50] ,d[50];
    cin >> N >> M;
    for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
    for (int i = 0; i < M; i++) cin >> c[i] >> d[i];
    for (int i = 0; i < N; i++) {
        int min = INT_MAX, minIndex;
        for (int j = 0; j < M; j++) {
            int dis = abs(c[j] - a[i]) + abs(d[j] - b[i]);
            if (dis < min) {
                min = dis;
                minIndex = j;
            }
        }
        cout << minIndex + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
const int N=200001;
const int inf=1e9;
int read(){
	char c=getchar();int d=0,f=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
	for(;c>='0'&&c<='9';d=d*10+c-48,c=getchar());
	return d*f;
}
int n,m,s[N];
struct xint{int L,R;}p[N];
struct node{int x,y,S1,S2;}a[N*5];
bool cmp(xint a,xint b){return a.L<b.L;}
void build(int x,int y,int t){
	a[t].x=x;a[t].y=y;
	a[t].S1=a[t].S2=inf;
	if(x==y)return;int mid=(x+y)>>1;
	build(x,mid,t<<1);
	build(mid+1,y,t<<1|1);
}
void update(int x,int t,int s1,int s2){
	a[t].S1=min(a[t].S1,s1);
	a[t].S2=min(a[t].S2,s2);
	if(a[t].x==a[t].y)return;
	int mid=(a[t].x+a[t].y)>>1;
	if(x<=mid)update(x,t<<1,s1,s2);
	else update(x,t<<1|1,s1,s2);
}
int query(int x,int y,int t,int tp){
	if(x<=a[t].x&&a[t].y<=y)
		return tp?a[t].S2:a[t].S1;
	int mid=(a[t].x+a[t].y)>>1;
	int res=inf;
	if(x<=mid)res=min(res,query(x,y,t<<1,tp));
	if(y>mid)res=min(res,query(x,y,t<<1|1,tp));
	return res;
}
int main(){
	n=read();
	ref(i,1,n)s[i]=s[i-1]+read();
	m=read();
	ref(i,1,m)p[i].L=read(),p[i].R=read();
	sort(p+1,p+m+1,cmp);
	build(0,n,1);
	update(0,1,0-s[0],0-(0-s[0]));
	int ans=s[n];
	ref(i,1,m){
		int L=p[i].L-1,R=p[i].R;
		int res=query(0,L,1,0)+s[L]+(R-L)-(s[R]-s[L]);
		res=min(res,query(L+1,R-1,1,1)+R-s[R]);
		ans=min(ans,res+s[n]-s[R]);
		update(R,1,res-s[R],res-(R-s[R]));
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 14716
#include <bits/stdc++.h>
// #pragma GCC optimize("O3")

#define debug(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ std::cerr << std::endl; for(const auto& v : vv){ view(v); } }
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; }
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef vector<v2> v3;

typedef unordered_map<ll, unordered_map<ll, ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

ll n,h,w;
ll ans;

int main(){
    cin >> n >> h >> w;
    for(ll i = 0;i < n;i++){
        ll a,b;
        cin >> a >> b;
        if(a >= h && b >= w) ans ++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3616
#include<cstdio>
inline int in();
inline void wr(int);
inline int mx(int,int);
int main(int argc,char**argv){
	register int a=in(),b=in();
	register int _1=a+b;
	register int _2=a-b;
	register int _3=a*b;
	wr(mx(mx(_1,_2),_3)),putchar('\n');
}
inline int mx(int x,int y){
	return x>y?x:y;
}
inline int in(){
	register char c=getchar();
	register int x=0,f=1;
	for(;c<'0'||c>'9';c=getchar())
		if(c=='-')f=-1;
	for(;c>='0'&&c<='9';c=getchar())
		x=(x<<1)+(x<<3)+(c&15);
	return x*f;
}
inline void wr(int x){
	if(x<0)putchar('-'),x=-x;
	if(x/10)wr(x/10);
	putchar(x%10+'0');
}


Measured memory_bytes: 128
import math

n = int(input())
if n == 2:
	a,b = map(int, input().split())
else:
	a,b,c = map(int, input().split())

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

if n == 2:
	gcd = GCD(a,b)
else:
	gcd = GCD(GCD(a,b), c)

d = math.floor(gcd**(1/2))
ans = []
for i in range(1,d+1):
	if gcd % i == 0:
		ans.append(i)
		ans.append(gcd//i)

for a in sorted(set(ans)):
	print(a)





Measured memory_bytes: 5692
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

int H, W, K;
vector<string> choco;

int main()
{
    cin >> H >> W >> K;
    choco.resize(H);
    rep(i, H) cin >> choco[i];

    int res = 1 << 30;

    //緯線をbit全探索（2^H～1000）
    for (int bit = 0; bit < (1 << (H - 1)); bit++)
    {
        int hCount = 0;
        vector<int> ord(H, 0);

        //緯線でチョコレートを分割
        rep(i, H - 1)
        {
            if (!(bit & (1 << i)))
                ord[i + 1] = ord[i];
            else
                ord[i + 1] = ord[i] + 1, hCount++;
        }
        
        int wCount = 0;
        vector<int> counts(hCount + 1, 0);

        //1列目でオーバーする場合の対応
        //経線は引けないがwCountはアップするので結果判定を行いたくない。
        bool gok = true;

        rep(w, W)
        {
            vector<int> tmp(hCount + 1, 0);
            bool ok = true;
            rep(h, H)
            {
                tmp[ord[h]] += choco[h][w] - '0';
                counts[ord[h]] += choco[h][w] - '0';
                if (tmp[ord[h]] > K) gok = false;
                if (counts[ord[h]] > K) ok = false;
            }
            //オーバーしたら経線を引いて次へ
            if (!ok) wCount++, counts = tmp;
        }

        if (gok) chmin(res, hCount + wCount);
    }

    cout << res << endl;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  writeln(((n-1)/111+1)*111);
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b,c,d,e,f;
    double x,y;
    
    while(scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f) != EOF){
        x = (double)(c*e-b*f) / (double)(a*e-b*d);
        y = (double)(a*f-c*d) / (double)(a*e-b*d);
        if(x == -0.000000) x=0.000000;
        if(y == -0.000000) y=0.000000;
        printf("%.3lf %.3lf\n",x,y);
    }
    
    return 0;
}

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

#define EQ(a,b) (abs((a)-(b)) < EPS)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define sz size()
#define all(a) (a).begin(),(a).end()

using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;

const D EPS = 1e-8;
const D PI = acos(-1);
const int MAXV = 50;

namespace std{
  bool operator<(const P &a,const P &b){
    return EQ(real(a),real(b))?imag(a)<imag(b):real(a)<real(b);
  }
  bool operator==(const P &a, const P &b){return EQ(a,b);}
}

inline D dot(P x, P y){return real(conj(x)*y);}
inline D cross(P x, P y){return imag(conj(x)*y);}

int ccw(P a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 2;   //counter clockwise
  if (cross(b,c)<-EPS) return -2; //clockwise
  if (dot(b, c)<-EPS) return 1;   //c--a--b on line
  if (abs(b)+EPS<abs(c)) return -1;   //a--b--c on line
  return 0;                       //on segment
}

vector<int> g[MAXV];
int cols[MAXV];
int n;

bool dfs2(int v, int c){
  if(cols[v] >= 0)return (cols[v] == c);
  cols[v] = c;

  bool f = true;
  for(int u : g[v])f &= dfs2(u,1-c);

  return f;
}

bool dfs3(int d, vector<int> &adj){
  if(d==n)return true;
  int v = -1, maxadj = 0, maxdeg = 0;
  rep(u,n){
    if(cols[u]<0){
      if(maxadj < adj[u]){
	v = u; maxadj = adj[u]; maxdeg = g[u].size();
      }else if(maxadj == adj[u] && maxdeg < (int)g[u].size()){
	v = u; maxadj = adj[u]; maxdeg = g[u].size();
      }
    }
  }

  int cnt = 0;
  vector<int> usecol(3,0);
  for(int u : g[v]){
    if(cols[u]>=0)usecol[cols[u]] = 1, adj[u]++, cnt++;
  }

  if(cnt==0){
    cols[v] = 0;
    return dfs3(d+1,adj);
  }

  rep(nc,3){
    if(!usecol[nc]){
      cols[v] = nc;
      if(dfs3(d+1,adj))return true;
    }
  }

  cols[v] = -1;
  for(int u : g[v]){
    if(cols[u]>=0)adj[u]--;
  }

  return false;
}

int main(){
  while(cin >> n){
    if(n==0)break;
    
    vector< vector<L> > poly(n);

    rep(i,n){
      int m;
      cin >> m;
      vector<P> points(m);
      rep(j,m){
	int x,y;
	cin >> x >> y;
	points[j] = P(x,y);
      }
      rep(j,m){
	poly[i].pb(L(points[j],points[(j+1)%m]));
	if(poly[i][j].sc < poly[i][j].fs)swap(poly[i][j].fs, poly[i][j].sc);
      }
    }

    rep(i,n)g[i].clear();

    rep(i,n)rep(j,i){
	bool f = false;
	for(L a : poly[i]){
	  for(L b: poly[j]){
	    if(abs(ccw(a.fs,a.sc,b.fs))<=1 && abs(ccw(a.fs,a.sc,b.sc))<=1){
	      if( (b.fs < a.sc && a.fs < b.sc) || (a.fs < b.sc && b.fs < a.sc) ){
		f = true; break;
	      }
	    }
	  }
	  if(f)break;
	}
	if(f){ g[i].pb(j); g[j].pb(i); }
    }

    //1-colorabiliy 
    bool col1 = true;
    rep(i,n){
      if(g[i].sz>0)col1 = false;
    }
    if(col1){
      cout << 1 << endl;
      continue;
    }

    //2-colorabiliy
    memset(cols,-1,sizeof(cols));
    bool col2 = true;
    rep(i,n){
      if(cols[i]<0)col2 &= dfs2(i,0);
      if(!col2)break;
    }
    if(col2){
      cout << 2 << endl;
      continue;
    }

    //3-colorabiliy
    memset(cols,-1,sizeof(cols));
    vector<int> adj(n,0);
    if(dfs3(0,adj)){
      cout << 3 << endl;
      continue;
    }

    cout << 4 << endl;
  }
}

Measured memory_bytes: 1252
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=998244353,N=5e5+5;
int fac[N],inv[N];
int ksm(int b,int n){
	int res=1;
	while(n){
		if(n&1) res=res*b%mod;
		b=b*b%mod; n>>=1; 
	}
	return res;
}
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;++i)
		fac[i]=1ll*fac[i-1]*i%mod;
	inv[n]=ksm(fac[n],mod-2);
	for(int i=n-1;i>=0;--i)
		inv[i]=1ll*inv[i+1]*(i+1)%mod;
}
int C(int n,int m){
	if(n<0||m<0||n<m) return 0;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int X;
void add(int &x,int y){
	x=(x+y)%mod;
}
int calc(int n){
	int ans=(2*n<X || X&1);
	for(int i=n;i<=n+n-1;++i)
		if(i<X) add(ans,C(n,i-n));
		else if((i-X+1)%2==0){
			int p=(i-X+1)/2;
			add(ans,C(n-(p<<1),i-(p<<2)-(n-(p<<1))));
		}
	return ans;
}
signed main(){
	int n,ans=0;
	cin>>n>>X;
	init(max(n,X));
	for(int i=0;i<=n;++i)
		add(ans,C(n,i)*calc(i)%mod);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);


ll digit_sum(ll b,ll N){
    if(N<b) return N;
    else return digit_sum(b,floor((double)N/b)) + (N%b);
}

int main() {
    ll N,S;
    cin >> N >> S;
    if(N<S){
        cout << -1 << endl;
        return 0;
    }
    else if(N==S){
        cout << N+1 << endl;
        return 0;
    }
    for(int i=2;i<=ceil(sqrt(N));i++){
        if(digit_sum(i,N)==S){
            cout << i << endl;
            return 0;
        }
    }

    for(int i=ceil(sqrt(N));i>0;i--){
        if((N-S)%i!=0 || (N-S)/i==0) continue;
        else{
            if(digit_sum((N-S)/i+1,N)==S){
                cout << (N-S)/i+1 << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;
    return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    if (N == 0) cout << 1 << endl;
    else if (N == 1) cout << 2 << endl;
    else if (N == 2) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3164
import java.util.Scanner;
public class Main {
 public static void main(String[]args){
Scanner scan = new Scanner(System.in);
  int S = scan.nextInt();
  int W = scan.nextInt();
  if (S<=W){
  System.out.println("unsafe");}
  else {
    System.out.println("safe");}
 }
}

Measured memory_bytes: 35732