akhauriyash/Code-Regression huggingface dataset:
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        int K = scanInt(), N = scanInt();
        int[] p = new int[K];
        for (int i = 0; i < K; i++) {
            p[i] = scanInt();
        }
        Arrays.sort(p);

        int ans = 0;

        for (int i = 0; i < N; i++) {
            ans += p[i];
        }
        out.print(ans);
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

Measured memory_bytes: 33072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+ 7;
int arr[N];
priority_queue<double,vector<double>, less<double> > que; 

int main(){
	int N,M;
	double A;
	ll ans=0;
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++){
		scanf("%lf",&A);
		que.push(A);
	}
	for(int i=0;i<M;i++){
		double flag;
		flag=que.top()/2;
		que.pop();
		que.push(flag);
	}
	for(int i=0;i<N;i++){
		ans=ans+(ll)(que.top());
		que.pop();
	}
	printf("%lld\n",ans);
	
	
	return 0;
}

Measured memory_bytes: 1400
#include <stdio.h>
#include <vector>
#include <string.h>
#include <algorithm>
#include <map>
#include <string>
#include <deque>

#pragma warning(disable:4996)

#define MAX_N 50
#define MAX_M 50

#define INF 1000000000

int N[MAX_N][2];
int M[MAX_M][2];



int main(void) {
	std::vector<int> A;
	int p, q, r;
	scanf("%d %d %d", &p, &q, &r);
	A.push_back(p);
	A.push_back(q);
	A.push_back(r);
	std::sort(A.begin(), A.end());
	int sum = A[0] + A[1];


	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
ls =len(S)
lt=len(T)
ans = lt
for i in range(ls-lt+1):
    cnt = 0
    for s,t in zip(S[i:i+lt],T):
        if s != t:
            cnt+=1
    ans=min(ans,cnt)
print(ans)

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    long long n,m,k,maxv,sum=0;
    cin>>n>>m;
    priority_queue<int> a;
    for(int i=0;i<n;i++){
        cin>>k;
        a.push(k);
    }
    while(m!=0){
       k=a.top();
       k/=2;
       a.pop();
       a.push(k);
       m--;
    }
    while(!a.empty()){
        sum+=a.top();
        a.pop();
    }
    cout<<sum<<"\n";
    return 0;
}

Measured memory_bytes: 3868
A = gets.to_i
B = gets.to_i
C = gets.to_i
X = gets.to_i
count = 0
# binding.pry
0.upto(A) do |i|
  0.upto(B) do |j|
    # 0.upto(C) do |k|
    #   count += 1 if 500*i + 100*j + 50*k == X
    # end
    pre = X - 500*i - 100*j
    if pre / 50 >= 0 && pre / 50 <= C && pre % 50 == 0
      count += 1
    end
  end
end
puts count

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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


int main()
{
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	vector<int> s(n, 0 );
	rep (i, n ) cin >> s[i];
	s.erase (unique (ALL (s ) ), s.end() );
	int q; cin >> q;
	vector<int> t(q, 0 );
	rep (j, q ) cin >> t[j];

	int res = 0;
	rep (j, q ){
		int cand = t[j];
		int lo = 0;
		int hi = s.size();
		while (lo <= hi ){
			int mid = (lo + hi)/2;
			if (s[mid] == cand ){
				res++;
				break;
			}else
			if (s[mid] > cand ){
				hi = mid - 1;
			}else{
				lo = mid + 1;
			} // end if
		} // end while
	} // end rep
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1592
#include<iostream>
int main()
{
	int v1, v2;
	std::cin >> v1 >> v2;
	if ( v1 < v2 )
	{
	std::cout << "a < b" << std::endl;
	}
	else
	{
		if ( v1 == v2)
		{
        std::cout << "a == b" << std::endl;
		}
		else
		{
			std::cout << "a > b" << std::endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3100
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var abcd = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var a = abcd[0]; var b = abcd[1]; var c = abcd[2]; var d = abcd[3];
            Console.WriteLine(Math.Max(a * c, Math.Max(b * c, Math.Max(a * d, b * d))));
        }
    }
}


Measured memory_bytes: 27388
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n, n) {
        vector<int> v(n - 1, 0);
        REP(i, 0, n - 1) {
            v[i] = ((i + 1) * (i + 1)) % n;
        }
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        vector<int> m(n, 0);
        REP(i, 0, v.size()) {
            REP(j, 0, v.size()) {
                if (i == j) continue;
                int diff = v[i] - v[j];
                if (diff < 0) {
                    diff += n;
                }
                if ((n - 1) / 2 < diff) {
                    diff = n - diff;
                }
                m[diff] += 1;
            }
        }
        REP(i, 1, (n - 1) / 2 + 1) {
            cout << m[i] << endl;
        }
    }
    return 0;
}



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

int main()
{
    //freopen("in.txt", "r", stdin);
    int n, ans;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        int tmp;
        scanf("%d", &tmp);
        ans ^= tmp;
    }
    if(ans == 0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    
    return 0;
}


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

vector< vector<int> > g;
vector<bool> seen;
vector<bool> fini;
stack<int> hist;
int pos = -1;

void dfs(int v, int p) {
  seen[v] = true;
  hist.push(v);
  for (int a : g[v]) {
    if (a == p) continue;
    if (fini[a]) continue;
    if (seen[a] && !fini[a]) {
      pos = a;
      return;
    }
    dfs(a, v);
    if (pos != -1) return;
  }
  hist.pop();
  fini[v] = true;
}

int main() {
  int n;
  cin >> n;
  g.assign(n, vector<int>());
  rep(i, n) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  seen.assign(n, false);
  fini.assign(n, false);
  dfs(0, -1);
  set<int> st;
  while (!hist.empty()) {
    int v = hist.top();
    st.insert(v);
    hist.pop();
    if (v == pos) break;
  }
  int q;
  cin >> q;
  rep(i, q) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (st.count(a) && st.count(b)) cout << 2 << endl;
    else cout << 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 19192
// include
//#include <bits/stdc++.h> // last resort
#include <algorithm>     // sort, binary-search, etc.
#include <bitset>        // fixed-length bitset
#include <cmath>         // pow, log, etc.
#include <complex>       // complex number
#include <cstring>       // memset, memcpy
#include <deque>         //
#include <functional>    //
#include <iomanip>       // setprecision
#include <iostream>      // i/o
#include <iterator>      // operations for set
#include <map>           // map or dict
#include <numeric>       // iota, gcd, lcm
#include <queue>         //
#include <set>           //
#include <stack>         //
#include <string>        //
#include <unordered_map> //
#include <unordered_set> //
#include <utility>       // pair
#include <vector>        // variable-length array

// typedef and const
typedef long long ll;
const int DEFMOD = 1e9 + 7; // default modulus
const int INF = INT32_MAX;  // ~1e9
const ll LINF = INT64_MAX;  // ~1e18

//namespace
using namespace std;

// macros
// read and initialize
#define FILL(array, number) memset(array, number, sizeof(array))
#define RMI(array)             \
    for (auto &item : (array)) \
    cin >> item
// loop
#define FOREACH(item, array) for (auto &(item) : (array))
#define REP(index, time) for (int index = 0; index < (int)(time); ++index)
#define REPD(index, time) for (int index = time; 0 < index; --index)
#define SIZE(array) ((int)(array).size())
// write and presentation
#define COUTS(variable) cout << (variable) << " "
#define DUMP(variable) cout << #variable << ": " << (variable) << endl
#define ENDL cout << endl
#define WM(array)              \
    for (auto &item : (array)) \
    {                          \
        COUTS(item);           \
        ENDL;                  \
    }
// abbreviation
#define ALL(array) (array).begin(), (array).end()
#define M_ map<int, int>
#define MP make_pair
#define P_ pair<int, int>
#define PB(item) push_back(item)
#define PQ priority_queue<int>
#define PQG priority_queue<int, V, greater>
#define S_ set<int>
#define TO(condition, true, false) ((condition) ? (true) : (false))
#define V_ vector<int>

void func(long long a)
{
    cout << a + a * a + a * a * a << endl;
}

int main()
{
    // cout << fixed << setprecision(5);

    long long a;
    scanf("%lld", &a);
    func(a);
    return 0;
}


Measured memory_bytes: 3684
#!/usr/bin/env/ python3
#S = input()
R = int(input())
#A, B, C = input().split()
#N, M = map(int, input().split())

#N = int(input())
#A = [int(x) for x in input().split()]

#H, W = map(int, input().split())
#S = [input() for _ in range(H)]
print(2*R*3.14159265)


Measured memory_bytes: 9152
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		double n = sc.nextInt();
		double x = 100;
		for(int i = 0; i < n; i++){
			x = Math.ceil(x + (x * 0.05));
		}
		System.out.println((int)x * 1000);
	}
}

Measured memory_bytes: 17160
using System;

namespace ConsoleApp__ITP1_2_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            var w = Int32.Parse(input[0]);
            var h = Int32.Parse(input[1]);
            var x = Int32.Parse(input[2]);
            var y = Int32.Parse(input[3]);
            var r = Int32.Parse(input[4]);

            bool wJudge = (r <= x) && ((x + r) <= w);
            bool hJudge = (r <= y) && ((y + r) <= h);

            if (wJudge == true && hJudge == true)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}



Measured memory_bytes: 9008
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        
        Integer[] xArr = new Integer[n+1];
        for (int i = 0; i < n; i++) {
            xArr[i] = sc.nextInt();
        }
        xArr[n] = x;
        Arrays.sort(xArr, Comparator.naturalOrder());

        Integer[] distances = new Integer[n];
        for (int i = 0; i < n; i++) {
            int distance = xArr[i+1] - xArr[i];
            distances[i] = distance;
        }

        System.out.print(gcd(distances));
    }

    static int gcd(int a, int b) {
        int tmp;
        while((tmp = a%b) != 0) {
            a = b;
            b = tmp;
        }
        return b;
    }

    static int gcd(Integer[] arr) {
        int ans = arr[arr.length-1];
        for (Integer x : arr) {
            ans = gcd(ans, x);
        }
        return ans;
    }
}


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

using namespace std;

const int mxn = 2e5 + 10;

vector<int>G[mxn];
int mark[mxn];
int Ans = 0, ct = 0;

void DFS(int v)
{
    mark[v] = 1;
    ct++;
    Ans = max(Ans, ct);
    for(auto X : G[v]){
            if(mark[X] == 0){
                DFS(X);
            }
    }
}

int main()
{
    ios::sync_with_stdio(false);

    int nod, edg;
    cin>>nod>>edg;
    for(int i=1 ; i<=edg ; i++){
        int u, v;
        cin>>u>>v;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    for(int i=1 ; i<=nod ; i++){
        if(mark[i] == 0){
            ct = 0;
            DFS(i);
        }
    }

    cout<<Ans<<endl;

    return 0;
}


Measured memory_bytes: 21456
#define ENABLE_LL
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;
 
#ifdef ENABLE_LL
#define int long long
#endif
 
#ifdef ENABLE_LL
#define I "%lld"
#define II "%lld%lld"
#define III "%lld%lld%lld"
#define IIII "%lld%lld%lld%lld"
#define IN "%lld\n"
#define IIN "%lld%lld\n"
#define IIIN "%lld%lld%lld\n"
#define IIIIN "%lld%lld%lld%lld\n"
#else
#define I "%d"
#define II "%d%d"
#define III "%d%d%d"
#define IIII "%d%d%d%d"
#define IN "%d\n"
#define IIN "%d%d\n"
#define IIIN "%d%d%d\n"
#define IIIIN "%d%d%d%d\n"
#endif
 
#ifdef __LOCALE__
#define see(a) std::cout << #a << "=" << a << std::endl
#define ses(a) std::cout << #a << "=" << a << " " 
#else
#define see(a) //std::cout << #a << "=" << a << std::endl
#define ses(a)
#endif
#define repe(a,b) for (int a=0;a<(int)b.size();a++)
#define rep(i,n) for (int i=0;i<n;i++)
#define repa(i,n) for (int i=1;i<=n;i++)
#define repi(i,a,b) for (int i=a;i<=b;i++) 
#define repb(i,a,b) for (int i=a;i>=b;i--)
typedef pair < int , int > pr;
typedef pair < pr  , int > prr;
#define L first
#define R second
template <class T> inline bool checkMin(T& a , T b) { return (a > b ? a=b,1 : 0); }
template <class T> inline bool checkMax(T& a , T b) { return (a < b ? a=b,1 : 0); }
class Scanner{ private: istream& ist;public: Scanner(istream& in):ist(in){} string next(){ string r; ist >> r; return r; } string nextLine(){ string r; getline(ist,r); return r; } int nextInt(){ int r; ist >> r; return r; } double nextDouble(){ double r; ist >> r; return r; }};
Scanner sc(cin);
 
const int N = 100005;
int a[N];
int n, m, v, p;
 
void init() {
    scanf(IIII,&n,&m,&v,&p);
    rep (i,n) scanf(I,&a[i]);
    sort(a, a+n); 
    rep (i,n) ses(a[i]); see("");
}
 
int b[N];
bool jury(int u) {
    rep (i,n) b[i] = a[i];
    b[u] += m;
    sort(b, b+n);
    int id = 0;
    rep (i,n) if (b[i] == a[u] + m) id = i;
    if (n-id > p) return 0;
    int sp = (p-1) * m;
    rep (i,n-p) {
        sp += min(m, b[id] - b[i]);
    }   
    if (sp >= m*(v-1)) return 1;
    return 0;
}
 
void solve() {
    int l=0, r=n-1;
    while (l<r) {
        int m = (l+r) / 2;
        ses(m);see(jury(m));
        if (jury(m)) {
            r = m;
        } else {
            l = m+1;
        }
    }
    printf(IN,n - l);
}
 
#ifdef ENABLE_LL
#undef int
#endif
int main(){
    init();
    solve();
    return 0;
}


Measured memory_bytes: 5276
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  N,M = readline() |> split |> parseArray
  A = readline() |> split |> parseArray
  B,C=zeros(Int,M),zeros(Int,M)
  for i in 1:M
    B[i],C[i] = readline() |> split |> parseArray 
  end
  
  sort!(A)
  p=sortperm(C,rev=true)
  B,C=B[p],C[p]

  n=0
  s=0

  for i in 1:M
    if A[n+1]>=C[i]
      break
    elseif A[min(n+B[i],N)]<C[i]
      nn=min(B[i],N-n)
      s+=nn*C[i]
      n+=nn
      if n==N
        break
      end
    else
      nn=count(a->a<C[i],A[n+1:end])
      s+=nn*C[i]
      n+=nn
      break
    end
  end

  s+=sum(A[n+1:end])

  # for i in 1:M
  #   ix=(1:N)[A.<C[i]]
  #   n=length(ix)
  #   n==0&&break
  #   n=min(n,B[i])
  #   A[ix[1:n]]=C[i]
  #   sort!(A)
  # end

  # m=min(maximum(A) ,maximum(C))
  # A′=A[A.>=m]
  # s=sum(A′)
  # n=length(A′)
  # sum_b=sum(B)
  # if n+sum_b<=N
  #   s+=sum(A[A.<m][1:N-n-sum_b])+sum(C)
  # else
  #   for i in 1:M
  #     if n+B[i]>=N
  #       s+=(N-n)*C[i]
  #       break
  #     end
  #     n+=B[i]
  #     s+=B[i]*C[i]
  #   end
  # end



  println(s)
end

main()


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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

const string A = "AKIHABARA";
string S;

bool solve(string s){
   if (s == A) return true;
   if(s.size() > A.size()) return false;
   else{
      bool ans = false;
      REP(i, s.size() + 1){
         string t = s;
         t.insert(t.begin() + i, 'A');
         ans = ans || solve(t);
      }
      return ans;
   }
}
int main(){
   cin >> S;
   cout << (solve(S) ? "YES" : "NO" )<< endl;

}


Measured memory_bytes: 256
from collections import deque

class Task:
    def __init__(self,name,time):
        self.name = name
        self.time = time

def main():
    d = deque()
    num, q = [int(x) for x in input().split()]
    for i in range(num):
        pname,ptime = input().split()
        d.append( Task(pname, int(ptime)))
    passtime = 0
    while True:
        t = d.popleft()
        if t.time > q:
            t.time -= q
            passtime += q
            d.append(t)
        else:
            passtime += t.time
            print("{} {}".format(t.name,passtime))
            if len(d) == 0:
                exit(0)

if __name__ == '__main__':
    main()




Measured memory_bytes: 17556
// Problem Link: 
// Tutorial Link: 

#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define rep(i,a,b) for(LL i=a;i<=b;++i)
#define repb(i,a,b) for(LL i=a;i>=b;--i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false)
#define mod 1000000007

LL n, x[200005];
vpLL ans;

void calc(LL pop, LL& idx) {
	LL cur = 0;
	rep(i,1,n) {
		cur = cur * 2;
		cur += x[i];
		while(cur >= pop) cur -= pop;
	}
	// cout << pop << " " << cur << endl;
	idx = cur;
}

int main()
{
	FIO;
	cin >> n;
	string str;
	cin >> str;
	rep(i,1,n) x[i] = str[i-1] - '0';
	LL pop = 0, lo, hi;
	rep(i,1,n) pop += x[i];
	if(pop > 1) calc(pop-1, lo);
	calc(pop+1, hi);
	// cout << lo << " " << hi << endl;
	LL cur1 = 1, cur2 = 1;
	if(pop > 1) cur1 %= (pop-1);
	cur2 %= (pop+1);
	repb(i,n,1) {
		// cout << cur1 << " " << cur2 << endl;
		if(x[i] == 1) {
			if(pop > 1) ans.pb(mp((lo-cur1+pop-1)%(pop-1), (pop == 1) ? 0 : 1));
			else ans.pb(mp(0,0));
		}
		else ans.pb(mp((hi+cur2)%(pop+1), 1));
		if(pop > 1) cur1 = (cur1*2) % (pop-1);
		cur2 = (cur2*2) % (pop+1);
	}
	reverse(ans.begin(), ans.end());
	rep(i,0,n-1) {
		LL val = ans[i].ff, cur = ans[i].ss;
		// cout << ans[i].ff << " " << ans[i].ss << endl;
		while(val > 0) {
			cur++;
			val = val % __builtin_popcountll(val);
		}
		cout << cur << "\n";
	}
}

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

long long ch(long long n){
  return n * (n-1) / 2;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  vector<int> cnt(n+1);
  for(int i = 0; i < n; i++){
    cnt[a[i]]++;
  }
  long long total = 0;
  for(int i = 1;i <= n; i++){
    total += ch(cnt[i]);
  }
  for(int i = 0; i < n; i++){
    long long ans = total;
    ans -= ch(cnt[a[i]]);
    ans += ch(cnt[a[i]] - 1);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 4096
import Data.List

main :: IO ()
main = do
  [k, _] <- map read . words <$> getLine
  a <- map read . words <$> getLine
  let a1 = [x - head a | x <- a] ++ [k]
  let a2 = zipWith (-) (tail a1) a1
  print $ sum $ init $ sort a2



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

using namespace std;

const bool debug = true;
#define dbg(...) if(debug) printf(__VA_ARGS__)
#define print(var) if (debug) cout << #var << " = " << var << endl

namespace {
    typedef long long ll;
    int N;
    vector<int> A;
    void input() {
        cin >> N;
        A.clear();
        A.push_back(0);
        for (int i = 0; i < N; i++) {
            int a; cin >> a;
            A.push_back(a);
        }
        A.push_back(0);
    }

    void solve() {
        ll total = 0;
        for (int i = 1; i <= N + 1; i++) {
            total += abs(A[i] - A[i - 1]);
        }
        int M = 0;
        for (int i = 1; i <= N; i++) {
            int x = abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i]) - abs(A[i + 1] - A[i - 1]);
            cout << total - x << endl;
        }
    }
}

int main() {
    input(); solve();
    return 0;
}



Measured memory_bytes: 1784
n = int(input())
h = [int(i) for i in input().split()]

if n == 1:
    print(0)
else:
    max_count = 0
    current = 0
    for i in range(n - 1):
        if h[i] < h[i+1]:
            max_count = max(max_count, current)
            current = 0
        else:
            current += 1
    max_count = max(max_count, current)
    print(max_count)


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
int main()
{

    string str;
    cin>>str;
    int ans=0;
    for(int i=0;i<3;i++)
    {
        if(str[i]=='R')
        {
            int j=i+1;
            while(j<3 && str[j]=='R')
            {
                j++;
            }
            ans=max(ans,j-i);
            i=j;
        }
    }
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 3624
N=int(input())
W_his=[]
count=0
s_flag=1

for i in range(N):
	W_his.append(input())
	if i != 0:
		W_0=W_his[i-1]
		W_1=W_his[i]
		if W_0[-1] != W_1[0]:
			s_flag=0
			break
			
		for j in range(i-1):
			if W_his[j] == W_his[i]:
				s_flag=0
				break

if s_flag==1:
	print("Yes")
else:
	print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
     
int main() {
    string s;
    string t;
    cin>>s>>t;
    // cout << s<<t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    int s_length =(int)(s.length());
    int t_length =(int)(t.length());
    string td=t;
       

    for(int i=0;i<t_length;i++){
        td.at(i)=t.at(t_length-i-1);
    }
    
    if(s<td){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}

Measured memory_bytes: 3604
<?php
$len = intval(trim(fgets(STDIN)));
$nums = explode(' ', trim(fgets(STDIN)));
$sads = [];
for ($i=0; $i < $len; $i++) {
  $sads[] = $nums[$i] - $i + 1;
}

$tar = median($sads);

$ans = 0;
for ($i=0; $i < $len; $i++) {
  $ans += abs($sads[$i] - $tar);
}

echo $ans."\n";

function median(array $values){
	sort($values);
	if (count($values) % 2 == 0){
		return (($values[(count($values)/2)-1]+$values[((count($values)/2))])/2);
	}else{
		return ($values[floor(count($values)/2)]);
	}
}


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


int main()
{
    string S;
    cin >> S;

    if (S.at(2) == S.at(3) && S.at(4) == S.at(5))
    {
        cout << "Yes";
    }

    else
    {
        cout << "No";
    }
    
       
}



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

int main() {
    int64_t a, b, c, d;
    cin >> a >> b >> c >> d;
    int64_t num_int = b-a+1;
    
    int64_t b_c = b/c;
    int64_t a_c = a/c;
    if(a%c != 0){
        a_c++;
    } 
    int64_t c_mul = b_c - a_c + 1;

    int64_t b_d = b/d;
    int64_t a_d = a/d;
    if(a%d != 0){
        a_d++;
    } 
    int64_t d_mul = b_d - a_d + 1;

    int64_t cd = c*d;
    if(c<d){
        int64_t tmp = c;
        c = d;
        d = tmp;
    }
    int64_t r = c % d;
    while(r!=0){
        c = d;
        d = r;
        r = c % d;
    }
    cd = cd/d;
    int64_t b_cd = b/cd;
    int64_t a_cd = a/cd;
    if(a%cd != 0){
        a_cd++;
    } 
    int64_t cd_mul = b_cd - a_cd + 1;

    cout << num_int - c_mul - d_mul + cd_mul << endl;

    return 0;
}

Measured memory_bytes: 256
# AOJ 0242: Input Candidates
# Python3 2018.6.25 bal4u

while 1:
	n = int(input())
	if n == 0: break
	idx = {}
	dict = {}
	for i in range(n):
		for j in list(input().split()):
			if j in dict: dict[j] += 1
			else:
				dict[j] = 1
				if j[0] not in idx:
					idx[j[0]] = []
				idx[j[0]].append(j)
	k = input()
	if k not in idx: print("NA")
	else:
		a = []
		for j in idx[k]: a.append((j, dict[j]))
		a = sorted(a, key=lambda x:(-x[1],x[0]))
		w = len(a)
		if w > 5: w = 5
		ans = []
		for j in range(w): ans.append(a[j][0])
		print(*ans)



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

double power( double a, int n )
{
  double r;
  int abs_n;

  r = 1; abs_n = n < 0 ? -n : n;
  while ( abs_n > 0 ) {
    if ( abs_n % 2 == 1 ) { r *= a; }
    a *= a;
    abs_n /= 2;
  }

  return n >= 0 ? r : 1/r;
}

double nthroot( double a, int n )
{
  double x, y;

  if ( a <= 0 || n < 0 ) { return 0; }
  if ( n == 0 ) { return 1; }

  y = (a > 1) ? a : 1;
  do {
    x = y;
    y = ((n-1)*x + a/power(x, n-1)) / n;
  } while ( y < x );

  return y;
}

int is_power( int a )
{
  int i; 

  if ( a == 1 ) { return 1; }

  for ( i = 2; i <= floor(log2(a)); i++ ) {
    if ( power(floor(nthroot(a, i)), i) == a ) { 
      return 1;
    }
  }

  return 0;
}

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

  for (int i = 0; i <= n; i++ ) {
    if ( is_power(n-i) ) {
      cout << n-i << endl;
      return 0;
    }
  }

  return 0;
}

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

using namespace std;

const int oo = { 1000000010 };
int ans = oo;

int solve(int middle, int *weights, int size) {
    int former = 0, latter = 0, temp = 0;

    for (int j = 0; j < middle; j++) {
        former += weights[j];
    }
    for (int i = middle; i < size; i++) {
        latter += weights[i];
    }

    temp = abs(former-latter);

    ans = min(temp, ans);

    return ans;
}

int main(int argc, char const *argv[])
{
    int n = 0, distance = 0, middle = 0, w[101];

    cin >> n;
    middle = n+1;

    for (int i = 0; i < n; i++) {
        scanf("%d", &w[i]);
    }

    while(middle--) {
        distance = solve(middle, w, n);
    }

    cout << distance << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

int main() {
	int a, b;
	char op;
	while (cin >> a >> op >> b) {
		if (op == '+')
			cout << a + b << endl;
		else if (op == '-')
			cout << a - b << endl;
		else if (op == '*')
			cout << a * b << endl;
		else if (op == '/')
			cout << a / b << endl;
		else if (op == '?')
			break;
	}
}

Measured memory_bytes: 3100
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}



int main(){
	
	int n;
	cin>>n;
	while(1){
		if(n%7==0){
			cout<<"Yes"<<endl;
			return 0;
		}
		n-=4;
		if(n<0){
			cout<<"No"<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  string S;
  cin >> S;

  vector<int> V(ABC.size(), 0);
  for (int i = 0; i < 4; i++)
  {
    for (int j = 0; j < ABC.size(); j++)
    {
      if(S.at(i) == ABC.at(j))
      {
        V.at(j)++;
        break;
      }
    }
  }

  string ans = "Yes";
  for (int i = 0; i < V.size(); i++)
  {
    if (V.at(i) != 0 && V.at(i) != 2)
    {
      ans = "No";
      break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define mod 1000000007
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define setA0(a) for(ull i =0;i<n;i++){a[i] = 0;}
#define aout(a) for(auto x : a){cout<<x<<' ';} 
#define ain(a) for(ull i =0;i<n;i++){cin>>a[i];}
#define NofSetBits(x) __builtin_popcount(x);
#define InpGrph(g,e) while(e--){ll x;ll y;cin>>x>>y ;g[x].pub(y);g[y].pub(x);}
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);








int main(){
  FastIO;
  bool x;
  cin>>x;
  cout<<(x^1);
  
  return 0;
}


Measured memory_bytes: 3644
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////

int main(){fastio
    ll n,k;cin>>n>>k;
    ll a[k];rep(i,0,k-1)cin>>a[i];
    ll sum=0;rep(i,0,k-1)sum+=a[i];
    if(n>sum)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
s = str(input())

Pattern = [['S', 'S'], ['S', 'W'], ['W', 'S'], ['W', 'W']]

def seigou(n, s, S):
    if s[0] == 'o':
        if S[0] == S[1]:
            if S[-1] == 'S':
                return True
            else:
                return False
        else:
            if S[-1] =='W':
                return True
            else:
                return False
    elif s[0] == 'x':
        if S[0] == S[1]:
            if S[-1] == 'W':
                return True
            else:
                return False
        else:
            if S[-1] =='S':
                return True
            else:
                return False

def seigou_minus(n, s, S):
    if s[-1] == 'o':
        if S[-1] == S[0]:
            if S[-2] == 'S':
                return True
            else:
                return False
        else:
            if S[-2] =='W':
                return True
            else:
                return False
    elif s[-1] == 'x':
        if S[-1] == S[0]:
            if S[-2] == 'W':
                return True
            else:
                return False
        else:
            if S[-2] =='S':
                return True
            else:
                return False



def check(n, s, S):
    for i in range(1, n-1):
        if s[i] == 'o':
            if S[i] == 'S':
                S.append(S[i-1])
            elif S[i] == 'W':
                if S[i-1] == 'W':
                    x = 'S'
                else:
                    x = 'W'
                S.append(x)
        elif s[i] == 'x':
            if S[i] == 'S':
                if S[i-1] == 'W':
                    x = 'S'
                else:
                    x = 'W'
                S.append(x)
            elif S[i] == 'W':
                S.append(S[i-1])
    # S[n-1], S[0]で整合が取れるかどうかを確認
    return S


ans = -1
for pattern in Pattern:
    check_pattern = check(n,s,pattern)
    if seigou(n,s,check_pattern) == True and seigou_minus(n,s,check_pattern) == True:
        ans = check_pattern
    else:
        pass

if ans != -1:
    ans = ''.join(ans)

print(ans)

Measured memory_bytes: 6672
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from itertools import combinations


def enum_sum_numbers(sets, s_range, r):
    for cmb in combinations(sets, r):
        yield sum(cmb)
    if r <= s_range:
        for s in enum_sum_numbers(sets, s_range, r+1):
            yield s


stdin.readline()
a = [int(s) for s in stdin.readline().split()]
stdin.readline()
ms = [int(s) for s in stdin.readline().split()]
sets = {s for s in enum_sum_numbers(a, len(a), 1)}

for m in ms:
    print('yes' if m in sets else 'no')

Measured memory_bytes: 4432
package main

import "fmt"

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)

	if n <= a+b {
		if n <= a {
			fmt.Println(n)
		} else {
			fmt.Println(a)
		}
	} else {
		if n%(a+b) <= a {
			fmt.Println(n/(a+b)*a + n%(a+b))
		} else {
			fmt.Println(n/(a+b)*a + a)
		}
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
using namespace std;
long long n,a,b,c,d;
int main(){
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
	for(int i=0;i<n;i++)
		if(c*(n-i-1)-d*i<=(b-a)&&d*(n-1-i)-c*i>=(b-a)){
			printf("YES\n");
			return 0;
		}
	printf("NO\n");
	return 0;
}

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

#define INF 1e9
#define MAX 100005
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define ull long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define nl '\n'
#define zai <<' '<<
#define all(a) a.begin(),a.end()
#define pc __builtin_popcount
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

long long x[3005];
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int r,D;
	cin >> r >> D >> x[0];
	for(int i=1;i<=10;i++){
		x[i]=r*x[i-1]-D;
		cout << x[i] << nl;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
inf = float("inf")

from itertools import accumulate
Accum = list(accumulate([0] + A))

dp = [ [inf]*(N+1) for _ in range(N+1)]

def dfs(l,r):
    if dp[l][r] != inf:
        return dp[l][r]
    if l == r: 
        return 0
    if l+1 == r: 
        dp[l][r] = A[l]
        return A[l]

    local_ans = inf
    for i in range(l+1, r): # 0 to 4, 0-1, 1-4
        local_ans = min(local_ans, dfs(l,i) + dfs(i,r))
    dp[l][r] = local_ans + Accum[r] - Accum[l]
    return dp[l][r]
print (dfs(0,N)- sum(A))


Measured memory_bytes: 46940
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
数値型から文字列に変換　to_string(number);これは簡単
文字列から数値型に変換　stoi(number)
文字列からllに変換　stoll(number)*/

//ここから書き始める

int main(){
    int n ; cin >>n;
    int m ; cin>> m;
    vector<pair<int,int>> P(n);
    rep(i,n){
        int a,b;
        cin >> a >> b; //a円でb本まで買える
        P[i]=make_pair(a,b);
    }
    SORT(P);
    int now = 0;//買った本数
    ll ans = 0;
    int check = 0;
    for(int i = 0 ; i < n ; i++){
        int a, b;
        tie (a,b) = P[i];
        //che(a,'a');che(b,'b');
        for(int j = 0 ; j < b ; j++){
            if(now==m){
                break;
                check = 1; 
            }
            ans +=a;
            now++;
        }
        if(check){
            break;
        }
    }
    cout<<ans<<endl;
    }


Measured memory_bytes: 1024
main :: IO ()
main = do
  n <- readLn
  if n == 0
    then return ()
    else do
      ls <- getLine
      putStrLn $ solve ((map read . words) ls)
      main

solve :: [Int] -> String
solve ls
  | all (1 >= ) ls = "NA"
  | otherwise = show (1 + length (filter (0 /=) ls))

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

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

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//main code

int main(int argc, char const* argv[])
{
	int h,w;
	cin >> h >> w;
	char grid[h+2][w+2];
	for (int i = 0; i <= h+1; i++) {
		for (int j = 0; j <= w+1; j++) {
			if (i == 0 or j == 0 or i == h+1 or j == w+1) {
				grid[i][j] = '#';
			}
			else {
				cin >> grid[i][j];
			}
		}
	}
	VVL yoko(h+2,VL(w+2,0));
	VVL tate(w+2,VL(h+2,0));
	// yoko
	for (int i = 1; i <= h+1; i++) {
		int start = 0, end = 0;
		int num = 0;
		for (int j = 1; j <= w+1; j++) {
			if (grid[i][j] == '#') {
				end = j;
				for (int k = start; k < end; k++) {
					yoko[i][k] = num;
				}
				start = j+1;
				num = 0;
			}
			else {
				num++;
			}
		}
	}
	// tate
	for (int i = 1; i <= w+1; i++) {
		int start = 0, end = 0;
		int num = 0;
		for (int j = 1; j <= h+1; j++) {
			if (grid[j][i] == '#') {
				end = j;
				for (int k = start; k < end; k++) {
					tate[i][k] = num;
				}
				start = j+1;
				num = 0;
			}
			else {
				num++;
			}
		}
	}

	LL ans = 0;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			ans = max(ans, yoko[i][j] + tate[j][i]);
		}
	}
	cout << ans-1 << endl;
	return 0;
}


Measured memory_bytes: 66944
K = int(input())
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


temp = []

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            temp.append(gcd(i,j,k))
print(sum(temp))

Measured memory_bytes: 209264
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int main() {
	string s;
	ll k;
	cin >> s >> k;

	for (int i = 0; i < min((ll)s.size(), k); i++) {
		if (s[i] >= '2') {
			cout << s[i] << endl;
			return 0;
		}
	}
	
	cout << 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdlib>
#include <cmath>

typedef long long ll;

#define reps(i, s, e) for (ll i = s; i < e; ++i)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, s, e) for (ll i = e-1; i >= s; --i)
#define rrep(i, n) rreps(i, 0, n)

// const ll LL_INF = 1LL<<60;

template <class T> inline void chmin(T& a, T b) {if (a > b) {a = b;}}
template <class T> inline void chmax(T& a, T b) {if (a < b) {a = b;}}

using namespace std;

inline bool is_prime(ll a) {
    if (a == 1) return false;
    if (a != 2 && a % 2 == 0) return false;

    ll sq = sqrt(a);
    for (ll i = 3; i <= sq; i+=2) {
        if (a % i == 0) return false;
    }
    return true;
}

int main() {
    ll n;
    cin >> n;

    ll res = 0;
    rep(i, n) {
        ll a;
        cin >> a;
        if (is_prime(a)) {
            res++;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3068
T = gets.to_i

def g(n, a, s)
  base = []

  (n - 1).downto(0) do |i|
    v = a[i]

    base.each do |b|
      if v ^ b < v
        v ^= b
      end
    end

    if v != 0
      if s[i] == '1'
        return 1
      end

      base << v
    end
  end

  0
end

T.times do |t|
  n = gets.to_i
  a = gets.split.map(&:to_i)
  s = gets.chomp

  puts g(n, a, s)
end


Measured memory_bytes: 14288
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define STRAIGHT 0
#define RIGHT 1
#define REV 2
#define LEFT 3
#define HALT 4

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

struct NODE{
	int x,y;
	int cost;
	int di;
};


bool operator>(const NODE &a,const NODE &b){
	return a.cost > b.cost;
}

int w,h;
bool check(const NODE &n){
	if(n.x<0 || n.x>=w)return false;
	if(n.y<0 || n.y>=h)return false;
	return true;
}
NODE move(int cmd,const NODE &src){
	int di = src.di;
	NODE ret;
	switch(cmd){
	case STRAIGHT:
		break;
	case RIGHT:
		di = (di+1)%4;
		break;
	case LEFT:
		di = (di+3)%4;
		break;
	case REV:
		di = (di+2)%4;
		break;
	}
	
	ret.x = src.x+dx[di];
	ret.y = src.y+dy[di];
	ret.di = di;
	
	return ret;
}
int main(){
	
	while(cin >> w >> h,w){
		int data[30][30] , c[4];
		rep(i,h)rep(j,w)cin >> data[i][j];
		rep(i,4)cin >> c[i];
		priority_queue<NODE,vector<NODE>,greater<NODE> > Q;
		int gx = w-1,gy = h-1;
		NODE t; t.x = 0, t.y = 0, t.cost = 0; t.di = 0;
		Q.push(t);
		int memo[30][30][4]; rep(i,30)rep(j,30)rep(k,4)memo[i][j][k] = (1<<21);
		while(Q.size()){
			NODE q = Q.top(); Q.pop();
			
			if(memo[q.y][q.x][q.di] <= q.cost)continue;
			memo[q.y][q.x][q.di] = q.cost;
			
			if(gx == q.x && gy == q.y){
				cout << q.cost << endl;
				break;
			}
			
			rep(i,4){
				NODE mv = move(i,q);
				mv.cost = q.cost + c[i];
				if(check(mv))Q.push(mv);
			}
			
			int fcmd = data[q.y][q.x];
			
			if(fcmd != HALT){
				NODE mv = move(fcmd,q);
				mv.cost = q.cost;
				if(check(mv))Q.push(mv);
			}
		}
	}
}
	

Measured memory_bytes: 1052
import sys
input = sys.stdin.readline
import numpy as np

MOD = 10 ** 9 + 7

N,C = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

# (i,j) に j^i を入れる
kth_pow = np.ones((C+1, 401), dtype=np.int64)
rng = np.arange(401, dtype=np.int64)
for i in range(1,C+1):
    kth_pow[i] = kth_pow[i-1] * rng % MOD
kth_pow_cum = kth_pow.cumsum(axis = 1) % MOD

dp = np.zeros((C+1), dtype=np.int64) # これまで配った個数、合計点
dp[0] = 1
for a,b in zip(A,B):
    arr = kth_pow_cum[:,b] - kth_pow_cum[:,a-1]
    prev = dp
    dp = np.zeros(C+1, dtype=np.int64)
    for n in range(C+1):
        dp[n:] += arr[n] * prev[:C+1-n] % MOD
    dp %= MOD

answer = dp[C]
print(answer)



Measured memory_bytes: 16220