akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace
-- trace _ = id

solve :: Int -> [Int] -> [Int] -> Int
solve bN as bs | sumA < sumB = -1
               | otherwise = (length needs) + theLen
  where
    sumA = sum as
    sumB = sum bs
    supply = zipWith f as bs
      where f a b | a > b = Just (a-b)
                  | otherwise = Nothing
    srtSupply = sortOn (* (-1)) (catMaybes supply)
    acc = scanl' (+) 0 srtSupply
    needs = catMaybes $ zipWith g as bs
      where g a b | b > a = Just (b-a)
                  | otherwise = Nothing
    sumNeeds = sum needs
    -- theLen = trace ("xx " ++ show (sumA, sumB, srtSupply, acc, needs, theLenA)) theLenA
    theLen = length $ takeWhile (< sumNeeds) acc
    

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_bN]:remLines1 = remLines0
      bN = readBInt bs_bN
      line2:remLines2 = remLines1
      as = map readBInt line2
      line3:remLines3 = remLines2
      bs = map readBInt line3
  in solve bN as bs

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents

-------------------------------------------------------------------------------

inp1 = "3\n2 3 5\n3 4 1\n"
inp2 = "3\n2 3 3\n2 2 1\n"
inp3 = "3\n17 7 1\n25 6 14\n"
inp4 = "12\n757232153 372327760 440075441 195848680 354974235 458054863 463477172 740174259 615762794 632963102 529866931 64991604\n74164189 98239366 465611891 362739947 147060907 118867039 63189252 78303147 501410831 110823640 122948912 572905212\n"
tv1 = tmain $ B.pack inp1
tv2 = tmain $ B.pack inp2
tv3 = tmain $ B.pack inp3
tv4 = tmain $ B.pack inp4
test1 = tv1 == 3
test2 = tv2 == 0
test3 = tv3 == -1
test4 = tv4 == 5
alltest = test1 && test2 && test3 && test4


Measured memory_bytes: 22908
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=100005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
vector <int> v[N], temp;
int ch[N],n;
void dfs(int u, int p)
{
    ch[u]=1;
    for(auto to:v[u])
    {
        if(to==p)
        continue;
        dfs(to, u);
        ch[u]+=ch[to];
        //cout<<u<<" "<<to<<" "<<ch[to]<<" "<<n-ch[to]<<"\n";
        temp.pb((ch[to]*(n-ch[to])));
    }
    return;
}
int32_t main()
{
    IOS;
    int h,w,m;
    cin>>h>>w>>m;
    int a[h+1],b[w+1];
    fill(a, 0);
    fill(b, 0);
    set <pii> s;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        s.insert({x, y});
        a[x]++;
        b[y]++;
    }
    vector <pii> v1,v2;
    for(int i=1;i<=h;i++)
    v1.pb({a[i], i});
    for(int i=1;i<=w;i++)
    v2.pb({b[i], i});
    sort(all(v1));
    reverse(all(v1));
    sort(all(v2));
    reverse(all(v2));
    int ans=0;
    for(int i=0;i<h;i++)
    {
        int ca=0;
        for(int j=0;j<w;j++)
        {
            int cur=v1[i].ff+v2[j].ff-1;
            if(cur<ca||cur<ans)
            break;
            else
            {
                if(s.find({v1[i].ss, v2[j].ss})==s.end())
                {
                    ca=cur+1;
                    //cout<<v1[i].ss<<" "<<v2[j].ss<<" "<<v1[i].ff<<" "<<v2[j].ff<<"\n";
                    break;
                }
                else
                ca=cur;
            }
        }
        ans=max(ans, ca);
    }
    cout<<ans;
}

Measured memory_bytes: 46048
N,M = map(int,input().split())
A = list(map(int,input().split()))
all_vote = sum(A)

cnt = 0
for i in range(N):
    if(A[i]>=all_vote/(4*M)):
        cnt += 1
if(cnt >= M):
    print("Yes")
else:
    print("No")

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N, M;
priority_queue<int> que;

signed main() {
    cin >> N >> M;
    rep(i, N) {
        int a;
        cin >> a;
        que.push(a);
    }
    rep(i, M) {
        int a = que.top();
        que.pop();
        que.push(a / 2);
    }
    int ans = 0;
    rep(i, N) {
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

A, B, X = get_ints

if X >= A && X <= A + B
  puts 'YES'
else
  puts 'NO'
end


Measured memory_bytes: 14260
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int cnt[100005];
signed main() {
    int N;
    cin >> N;
    vector<int>a(N);
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        cnt[a[i]]++;
        cnt[a[i]+1]++;
        cnt[a[i]+2]++;
    }
    int ans = 0;
    for(int i = 0; i < 100005; i++) {
        ans = max(ans,cnt[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4816
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    k: usize,
    point: [i64; 3],
    t: chars,
  }
  let t: Vec<usize> = t.into_iter().map(|c| match c {
    'r' => 2,
    's' => 0,
    _ => 1,
  }).collect();
  let mut sum = 0;
  for i in 0 .. k {
    let mut prev = None;
    let mut j = i;
    while j < n {
      match prev {
        Some(p) => {
          if p == t[j] {
            prev = None;
          } else {
            prev = Some(t[j]);
            sum += point[t[j]];
          }
        }
        None => {
          prev = Some(t[j]);
          sum += point[t[j]];
        }
      }
      j += k;
    }
  }

  puts!("{}\n", sum);
}


Measured memory_bytes: 6396
from collections import defaultdict
import sys
input = sys.stdin.readline

N = int(input())
S = input().rstrip()
ans = 0

cnt = defaultdict(int)
for bit in range(1 << N):
    a = b = ''
    for i in range(N):
        if bit >> i & 1:
            a += S[i]
        else:
            b += S[i]
    cnt[(a, b)] += 1
ans = 0
for bit in range(1 << N):
    a = b = ''
    for i in range(N):
        if bit >> i & 1:
            a += S[N+i]
        else:
            b += S[N+i]
    ans += cnt[(b[::-1], a[::-1])]
print(ans)



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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
    cin >> vec.at(i);
  int X = -1;
  int A = 0;
  for (int i = 0; i < N; i++){
    if (vec.at(A) == 2) {
      X = i + 1;
      break;
    }
    else {
      A = vec.at(A)-1;
    }
  }
  cout << X << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m,x;
cin >>n>>m>>x;
vector <int>num(n,0);
for(int i=0;i<n;i++){
int l;
cin >>l;
num.at(l-1)=1; 
}
int sum=0;
for(int i=0;i<x-1;i++){
sum += num.at(i);
}
int mi =0;
mi=min(sum,m-sum);
cout << mi <<endl; 
}



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

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()
#define what_is(x) #x << " is " << (x)
#define int ll

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = (int)1e6 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

int n, x, a[5000];
int b[3000][3000];

main() {
	cin >> n >> x;
	for(int i = 0; i < n; i ++)  {
		cin >> a[i];
		b[i][0] = a[i];
	}
	ll res = LLONG_MAX;	
	for(int k = 0; k < n; k ++) {	
		if(k > 0) {
			for(int i = 0; i < n; i ++) {
				int prv = (i - k + n) % n;
				b[i][k] = min(b[i][k - 1], a[prv]);
			}
		}
		ll sum = 0;
		for(int i = 0; i < n; i ++) 			
			sum += b[i][k];
		res = min(res, sum + k * x);		
	}
	cout << res;
	return 0;  
}


Measured memory_bytes: 46976
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;

vector<ll> daikus(vector<vector<mp> > &g,int s){
	ll v = g.size();
	vector<ll> res(v,inf);
	priority_queue<mp,vector<mp>,greater<mp> > q;
	q.push(mp(0,s) );
	while(!q.empty()){
		mp now = q.top();
		q.pop();
		ll nn = now.second;
		ll cost = now.first;
		if( res[nn] < cost) continue;
		res[nn] = cost;
		for(int i=0;i<g[nn].size();i++){
			ll next = g[nn][i].second;
			ll nc = cost + g[nn][i].first;
			if( res[next] < cost ) continue;
			q.push( mp(nc,next) );
		}
	}
	return res;
}



int main(){
 ll n,x,y;
 cin>>n>>x>>y;
 vector< vector< mp > > g( n );
 for(ll i=0;i<n-1;i++){
  g[i].push_back( mp(1,i+1) );
  g[i+1].push_back( mp(1,i) );
 }
 x--,y--;
 g[x].push_back( mp(1,y) );
 g[y].push_back( mp(1,x) );
 vector<ll> cost(n,0);
 for(ll i=0;i<n;i++){
  vector<ll> res = daikus( g , i );
  for(auto j:res ){
   cost[j]++;
  }
 }

 for(int i=1;i<n;i++)cout<<cost[i]/2<<endl;
    return 0;
}


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

typedef long long ll;
bool compare( pair<ll,ll> a ,pair<ll,ll> b )
{
    if( a.second == b.second )
        return a.first < b.first ;
    return a.second < b.second;
}
int main()
{
    ll n;
    cin>>n;
    auto* a = new pair<ll,ll>[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first >>a[i].second;
    }
    sort( a , a+n , compare );
    ll curr =0;
    bool ans = true;
    for( int i=0;i<n;i++)
    {
        if( curr + a[i].first > a[i].second )
        {
            ans = false;
            break;
        }
        curr = curr + a[i].first;
    }
    if( ans )
    {
        cout<<"Yes";
    }
    else cout<<"No";
}

Measured memory_bytes: 6768
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main()
{
   string S;
   cin >> S;
   int cnt = 0;
   int ans = 0;
   bool ok = false;
   for (int i = 0; i < 3; i++)
   {
      if (S[i] == 'R')
      {
         if (ok == true)
         {
            cnt++;
         }
         else
         {
            cnt = 1;
         }
         ok = true;
      }
      else
      {
         ok = false;
      }
      ans = max(ans, cnt);
   }

   cout << cnt << endl;
   return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using std::cin;
typedef long long ll;
const int INF=1e+9;
const ll INFLL=1e+17;
int A,B,T;
void solve(){
  int res=0,t=0;
  while(t<=T){
    res+=B;
    t+=A;
  }
  prin(res-B);
}
int main(){
  cin>>A>>B>>T;
  solve();
  return 0;
}


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

#define ll long long 
#define d  double 
#define endl "\n"

const ll int MOD=1e9+7;

void solve()
{
	int h1,h2,m1,m2,x,y,ans,k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	x = (h2-h1)*60;
	y = m2-m1;
	ans = x+y-k;
	cout << ans << endl;
}

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

	solve();
	return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  string abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for( int i = 0; i < S.size(); i++ ){
    for( int j = 0; j < abc.size(); j++ ){
      if( S.at(i) == abc.at(j) ){
        if( j+N >= abc.size() ){
          cout << abc.at(j+N-abc.size());
        }else{
          cout << abc.at(j+N);
        }
      }
    }
  }
  cout << endl;
      
}


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

using namespace std;


int main()
{
	int n,m,x;
	cin >> n >> m >> x;
	vector<vector<int>> arr(n, vector<int>(m));
	for(int i = 0; i < n; i++){
		cin >> arr[i][0];
		for(int j = 1; j <= m; j++) cin >> arr[i][j];
	}
	int ans = (int)1e9;
	for(int i = 0; i < (1<<n); i++){
		int price = 0;
		int temp[m];
		memset(temp,0,sizeof(temp));
		for(int j = 0; j < n; j++){
			if(i&(1<<j)){
				price += arr[j][0];
				for(int k = 1; k <= m; k++) temp[k-1] += arr[j][k];
			}
		}
		bool is_good = true;
		for(int mm : temp) is_good &= mm >= x;
		if(is_good) ans = min(ans, price);
	}
	if(ans == 1e9) ans = -1;
	cout << ans;
}


Measured memory_bytes: 3604
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N, M = MI()

    p = ["0"]*(M)
    S = ["0"]*(M)
    for i in range(M):
        p[i], S[i] = map(str,input().split())

    ans = [0]*(N+1)
    error = [0]*(N+1)
    e = [0]*(N+1)

    for i in range(M):
        if ans[int(p[i])] == 0:
            if S[i] == "WA":
                error[int(p[i])] += 1
            elif S[i] == "AC":
                ans[int(p[i])] = 1

    sum_ans = sum(ans)
    sum_error = 0
    for i in range(N+1):
        if ans[i] == 1:
            sum_error += error[i]
    print(sum_ans, sum_error)

if __name__ == "__main__":
	main()

Measured memory_bytes: 25288
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


Int valid(Int N, Int K, vector<Int> A, Int d){
  for(Int i=0;i<N;i++) A[i] %= d;
  sort(A.begin(), A.end());
  Int l = 0, r = N-1;
  Int cost = 0;
  while(l<r){
    if(A[l]%d == 0) {l++; continue;}
    if(A[r]%d == 0) {r--; continue;}
    Int a = A[l];
    Int b = d - A[r];
    A[l] -= min(a, b);
    A[r] += min(a, b);
    cost += min(a, b);
    if(cost > K) return 0;
  }
  return 1;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, K;
  cin>>N>>K;
  vector<Int> A(N);
  cin>>A;

  Int sum = 0;
  for(Int i=0;i<N;i++) sum += A[i];

  Int ans = 1;
  for(Int i=1;i*i<=sum;i++){
    if(sum % i) continue;
    if(valid(N, K, A, i)) ans = max(ans, i);
    if(valid(N, K, A, sum / i)) ans = max(ans, sum / i);
  }

  cout<<ans<<endl;


  return 0;
}


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

using namespace std;

struct Comb { int id, op[3]; };
const string ord = "+-*";

int func(int a, int b, int i) {
    switch (i) {
        case 0: return a + b;
        case 1: return a - b;
        case 2: return a * b;
    }
}

Comb treeRank3(int a[]) {
    Comb res;
    res.id = -1;

    for (int i = 0; i < 27; i++) {
        int calc = a[0], p = i;

        for (int j = 1; j <= 3; j++) {
            res.op[j - 1] = p % 3;
            calc = func(calc, a[j], res.op[j - 1]);
            p /= 3;
        }

        if (calc == 10) {
            res.id = i;
            return res;
        }
    }
    return res;
}

Comb treeRank2(int a[]) {
    Comb res;
    res.id = -1;

    for (int i = 0; i < 27; i++) {
        int p = i;
        for (int j = 0; j < 3; j++) {
            res.op[j] = p % 3;
            p /= 3;
        }

        int calc = func(func(a[0], a[1], res.op[0]),
                        func(a[2], a[3], res.op[1]), res.op[2]);
        if (calc == 10) {
            res.id = i;
            return res;
        }
    }
    return res;
}

void solve(int a[]) {
    sort(a, a + 4);

    do {
        Comb ans = treeRank3(a);
        if (ans.id != -1) {
            printf("(((%d %c %d) %c %d) %c %d)\n", a[0], ord[ans.op[0]],
                                                   a[1], ord[ans.op[1]],
                                                   a[2], ord[ans.op[2]], a[3]);
            return;
        }

        ans = treeRank2(a);
        if (ans.id != -1) {
            printf("((%d %c %d) %c (%d %c %d))\n", a[0], ord[ans.op[0]],
                                                   a[1], ord[ans.op[2]],
                                                   a[2], ord[ans.op[1]], a[3]);
            return;
        }
    } while (next_permutation(a, a + 4));

    puts("0");
}

int main() {
    int a[4];
    while (scanf("%d", &a[0]), a[0]) {
        for (int i = 1; i < 4; i++)
            scanf("%d", &a[i]);

        solve(a);
    }

    return 0;
}


Measured memory_bytes: 3120
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

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

using ll = long long;
using Pii = pair<int, int>;

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

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

using MIte = multimap<ll, ll, greater<ll> >::iterator;

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

	// long long?
	string S;
	ll K;
	cin >> S >> K;

	bool allsame = true;
	for (int i = 0; i != S.length() - 1; ++i) {
		if (S[i] != S[i + 1]) {
			allsame = false;
		}
	}


	ll chg = 0;
	bool prev = false;
	bool finchg = false;
	if (!allsame) {
		for (int i = 0; i != S.length() - 1; ++i) {
			if (prev) {
				prev = false;
			}
			else {
				if (S[i] == S[i + 1]) {
					chg++;
					prev = true;
					if (i == S.length() - 2) {
						finchg = true;
					}
				}
			}
		}
	}

	ll chg2 = 0;
	bool prev2 = false;
	bool finchg2 = false;
	if (!allsame) {
		if (!finchg && S[S.length() - 1] == S[0]) {
			chg2++;
			for (int i = 1; i != S.length() - 1; ++i) {
				if (prev2) {
					prev2 = false;
				}
				else {
					if (S[i] == S[i + 1]) {
						chg2++;
						prev2 = true;
						if (i == S.length() - 2) {
							finchg2 = true;
						}
					}
				}
			}
		}
	}

	//	ll chg3 = 0;
	//	if (S[0] == S[S.length() - 1] && !finchg) {
	//		chg3++;
	//	}

	ll ans = 0;
	if (allsame) {
		ans = S.length() * K / 2;
	}
	else {
		if (S[S.length() - 1] == S[0]) {
			if (finchg) {
				ans = chg * K;
			}
			else {
				ans = chg + chg2 * (K - 1);
			}
		}
		else {
			ans = chg * K;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;

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


int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<bool>>root(h, vector<bool>(w, false));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char c;
			cin >> c;
			if (c == '.')root[i][j] = true;
		}
	}
	vector<vector<ll>>dp(h, vector<ll>(w, 0));
	dp[0][0] = 1;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			for (int k = 0; k < 4; k++) {
				int ni = i + dx[k];
				int nj = j + dy[k];
				if (ni < 0 || nj < 0 || ni >= h || nj >= w)continue;
				if (root[ni][nj]) {
					dp[ni][nj] += dp[i][j];
					dp[ni][nj] %= mod;
				}
			}
		}
	}
	cout << dp[h - 1][w - 1] << endl;
	return 0;
}


Measured memory_bytes: 8320
n=int(input())
F=[[] for i in range(10)]
for i in range(n):
    for j,f in enumerate(list(map(int,input().split()))):
        if f:
            F[j].append(i)
P=[list(map(int,input().split())) for i in range(n)]
ans=-float("inf")
for i in range(1,1024):
    l=[0]*n
    for j in range(10):
        if i>>j&1:
            for k in F[j]:
                l[k]+=1
    t=0
    for j,k in enumerate(l):
        t+=P[j][k]
    ans=max(ans,t)
print(ans)

Measured memory_bytes: 3064
// AOJ 2018
#include<iostream>
#include<vector>
using namespace std;

int solve(int N, int M, int P, vector<int> Xs) {
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += Xs[i];
  }

  return (Xs[M-1] ? sum * (100 - P) / Xs[M-1]:0);
}

int main() {
  int n, m, p;
  while(cin >> n >> m >> p and n) {
    vector<int> xs(n);
    for (int i = 0; i < n; i++) {
      cin >> xs[i];
    }
    cout << solve(n, m, p, xs) << endl;
  }
}

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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
int INF = numeric_limits<int>::max();
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

/* if in function
template <class T>
bool contain(vector<T> &vec, T find_it) {
  auto it = find(vec.begin(), vec.end(), find_it);
  return it != vec.end();
}

bool contain(string &str, char c) {
  return str.find(c) != string::npos;
}
*/

int main() {
  int n, t;
  cin >> n >> t;
  int min_c = 1001;
  rep(i, n) {
    int ci, ti;
    cin >> ci >> ti;
    if (ti <= t) min_c = min(min_c, ci);
  }
  cout << (min_c < 1001 ? to_string(min_c) : "TLE") << endl;
}


Measured memory_bytes: 256
main :: IO()
main = do
    nums <- words <$> getLine
    let a = map read nums !! 0
    let b = map read nums !! 1
    let c = map read nums !! 2
    let d = map read nums !! 3
    putStrLn $ show $ max_ (0, (min_ (b,d) - max_ (a,c)))

max_ :: (Int,Int) -> Int
max_ (x,y) | x >= y = x
          | otherwise = y

min_ :: (Int,Int) -> Int
min_ (x,y) | x >= y = y
          | otherwise = x


Measured memory_bytes: 508
import java.util.Scanner;
import java.lang.*;
class Main{
      public static void main(String args[]){
	Scanner sc = new Scanner(System.in);
	String s = sc.next();
	if(Character.isLowerCase(s.charAt(0))){
	    System.out.println("a");
	}else{
	    System.out.println("A");
	}
	sc.close();
      }
}


Measured memory_bytes: 35688
N = int(input())
A = [int(input()) for _ in range(N)]

def iseven(a):
	return (a & 1) == 0

def isprime(a):
	if a == 0 or a == 1:
		return False
	if a == 2:
		return True
	if iseven(a):
		return False
	for n in range(3, int(a ** 0.5) + 1, 2):
		if a % n == 0:
			return False
	return True

count = 0
for a in A:
	count += isprime(a)

print(count)



Measured memory_bytes: 5992
#include<stdio.h>
int main()
{
    int n,t,temp,a[100],b[100],i,k,cnt=0,j=0,r;
    scanf("%d",&n);
    t=n;
    while(t!=0)
    {
        temp=t%10;
        a[cnt]=temp;
        t=t/10;
        cnt++;
    }
    t=n;
    while(t!=0)
 
    while(t!=0)
    {
        t=t/10;
        b[j]=t;
        t=t%10;
        j++;
    }
    b[j-1]=a[0];
    for(i=0;i<cnt;i++)
    {
        for(k=0;k<j;k++)
        {
            if(a[i]==b[k])
            {
                r=1;
            }
            else
            {
                r=0;
            }
        }
    }
    if(r==1)
    {
        printf("Yes\n");
    }
    else if(r==0)
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
long long binaryPow(long long a, long long b){
	long long ans = 1;
	while(b > 0){
		if(b & 1){
			ans = ans * a ;
		}
		a = a * a ;
		b >>= 1; 
	} 
	return ans;
}
int main(){
	long long h,ans=0,k=0;
	scanf("%lld",&h);
	while(h!=0){
		ans+=binaryPow(2,k);
		h=h/2;
		k++;
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

char s[100007];
int n;
int ansW, ansB;

int main() {
    cin >> s;
    int n = strlen(s);
    for(int i = 0; i <= n; ++i) {
        if(s[i] == 'B') {
            while(s[i] == 'B') {
                ++i;
            }
            ++ansB;
        }
    }
    for(int i = 0; i <= n; ++i) {
        if(s[i] == 'W') {
            while(s[i] == 'W') {
                ++i;
            }
            ++ansW;
        }
    }
    cout << ansW + ansB - 1;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;

using int64 = long long;

const int MOD = 1000000007;
int main () {
    int n;
    cin >> n;
    vector a(n, 0LL);
    for (int i=0; i<n; i++) cin >> a[i];

    vector csum(n, 0LL);
    for (int i=n-1; i>0; i--) {
        csum[i-1] = csum[i] + a[i];
        csum[i-1] %= MOD;
    }

    int64 ans = 0;
    for (int i=0; i<n; i++) {
        ans += csum[i] * a[i];
        ans %= MOD;
    }

    cout << ans << endl;
}

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

int main(){
	int n, a, b, i, ans = 0;
	cin >> n;
	vector<int> v(114514, 0);
	for (i = 0; i < n; i++){
		cin >> a >> b;
		a--;
		v[a]++;
		v[b]--;
	}
	for (i = 0; i <= n; i++){
		v[i + 1] = v[i] + v[i + 1];
		if (i <= v[i]) ans = max(i, ans);
	}
	cout << ans << endl;
}



Measured memory_bytes: 3348
#include <stdio.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int W, H;
int a[101][101];
int cnt[101][101];
typedef struct{int x; int y;} P;
P que[10101];
int qf, qb;

int solve() {
    int ans = 0;
    rep(i, H) rep(j, W) cnt[i][j] = -1;
    qb = 0; qf = 0;
    cnt[0][0] = 1;
    que[qb].x = 0, que[qb++].y = 0;
    while(qb-qf > 0) {
        int cx = que[qf].x, cy = que[qf++].y;
        int nx = cx + 1, ny = cy;
        if(nx < H) {
             if(cnt[nx][ny] == -1 && a[2*cx+1][cy] == 0) {
                cnt[nx][ny] = cnt[cx][cy] + 1;
                que[qb].x = nx; que[qb++].y = ny;
            }
        }
        nx = cx - 1, ny = cy;
        if(nx >= 0) {
             if(cnt[nx][ny] == -1 && a[2*cx-1][cy] == 0) {
                cnt[nx][ny] = cnt[cx][cy] + 1;
                que[qb].x = nx; que[qb++].y = ny;
            }
        }
        nx = cx, ny = cy + 1;
        if(ny < W) {
             if(cnt[nx][ny] == -1 && a[2*cx][cy] == 0) {
                cnt[nx][ny] = cnt[cx][cy] + 1;
                que[qb].x = nx; que[qb++].y = ny;
            }
        }
        nx = cx, ny = cy - 1;
        if(ny >= 0) {
             if(cnt[nx][ny] == -1 && a[2*cx][cy-1] == 0) {
                cnt[nx][ny] = cnt[cx][cy] + 1;
                que[qb].x = nx; que[qb++].y = ny;
            }
        }
    }
    ans = (cnt[H-1][W-1] != -1 ? cnt[H-1][W-1] : 0);
    return ans;
}

int main(){
    while(1) {
        scanf("%d%d", &W, &H);
        if(W == 0 && H == 0) break;
        rep(i, 2*H-1){
            rep(j, W - ((i+1)%2)) {
                scanf("%d", &a[i][j]);
            }
        }
        printf("%d\n", solve());
    }
}


Measured memory_bytes: 2036
#include<iostream>

using namespace std;

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

    int num[n];
    int m = 0;
    for(int i = n - 1; i >= 0; i--){
        int count = 0;
        for(int j = 2; (i + 1) * j - 1 < n; j++){
            if (num[(i+1)*j-1] == 1) {
                count++;
            }
        }
        if (count % 2 != a[i]) {
            num[i] = 1;
            m++;
        }else{
            num[i] = 0;
        }
    }

    cout << m << endl;
    for(int i = 0; i < n; i++){
        if (num[i] == 1) {
            cout << i + 1 << " ";
        }
    }
    if (m > 0) {
        cout << endl;
    }
    
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
long long n,m;
int ans=1;
int main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=2;1ll*i*i<=n;i++)
	if(n%i==0)
	{
		while(n%i==0)
		n/=i;
		if(m%i==0)
		ans++;
		while(m%i==0)
		m/=i;
	}
	if(n!=1)
	if(m%n==0)
	ans++;
	printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout deque
template<typename T> ostream& operator<<(ostream& s, const deque<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vi a(n);
  rep (i, n) {
    scanf("%d", &a[i]);
  }
  sort(all(a));
  auto lb = lower_bound(all(a), k);
  if (lb == a.begin()) {
    printf("0\n");
    return 0;
  }

  a.resize(lb - a.begin());
  int m = (int)a.size();
  int sum_under_k = 0;
  rep (i, m) {
    sum_under_k += a[i];
  }
  if (sum_under_k < k) {
    printf("%d\n", m);
    return 0;
  }

  reverse(all(a));
  int ans_lowest = k;
  vector<bool> dp(k, false);
  dp[0] = true;
  int possible_max = 0;
  rep (i, m) {
    if (k - a[i] <= possible_max) {
      ans_lowest = a[i];
    }

    for (int j = k - a[i] - 1; j >= 0; --j) {
      if (dp[j]) {
        dp[j + a[i]] = true;
        possible_max = max(possible_max, j + a[i]);
      }
    }
  }

  reverse(all(a));
  printf("%d\n", (int)(lower_bound(all(a), ans_lowest) - a.begin()));

  return 0;
}


Measured memory_bytes: 888
n,k = gets.split.map(&:to_i)
xs = gets.split.map(&:to_i)
ans = Float::INFINITY
n.times do |i|
  tmp = xs[i, k]
  break if tmp.size < k
  a = tmp[0]
  b = tmp[-1]
  base = (a - b).abs
  if a < 0 && b > 0
    extra = [a.abs, b.abs].min
  elsif a < 0 && b < 0
    extra = b.abs
  elsif a > 0
    extra = a.abs
  else
    extra = 0
  end
  ans = [ans, base + extra].min
end

puts ans


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(n+1,0);
  int l,r;
  rep(i,m){
    cin >> l >> r;
    a[l-1]++,a[r]--;
  }
  rep(i,n){
    a[i+1]+=a[i];
  }
  int ans=0;
  rep(i,n){
    if(a[i]==m) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll mod=1e9+7;

vector<ll>h(100);

bool ok(ll n) {
  for(ll i=0;i<n;i++) {
    if(h[i]!=0) {
      return false;
    }
  }
  return true;
}

int main() {
  ll n;
  cin >> n;
  for(ll i=0;i<n;i++) {
    cin >> h[i];
  }
  ll count=0;
  while(!ok(n)) {
    ll l=-1;
    bool flag=true;
    for(ll i=0;i<n;i++) {
      if(h[i]==0&&l>=0&&flag) {
        break;
      }
      if(h[i]!=0&&flag) {
        if(l<0) {
          l=i;
        }
        h[i]--;
      }
    }
    count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 384
h,w,a,b=[int(i) for i in input().split()]
ans=[[0]*w for _ in range(h)]

def printf(array):
    for v in array:
        print(*v, sep="")
    quit()

for i in range(h):
    for j in range(w):
        if (i<b and j<a) or (i>=b and j>=a):
            ans[i][j]=1

printf(ans)

Measured memory_bytes: 15348
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
signed main(){

	int N;
	cin>>N;
	vint A;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		A.pb(a);
	}

	int mini=INF;
	int ans=0;
	for(int i=0;i<N;i++){
		if(A[i]<mini){
			ans++;
			mini=A[i];
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1400
import sys

def solve():
    while True:
        n = int(raw_input())
	if n ==	0:
            return
	s = []
        for i in range(n):
            d =	map(int,raw_input().split())
            s.append(sum(d))
	print max(s),min(s)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 4224
import sys
n = int(input()) 
a = list(map(int,input().split()))
c = 1

for i in range(n):
    if(a[i] == 0):
        print("0")
        sys.exit()
else:        
    for i in range(n):
        c *= a[i]
        if (c > (10**18)):
            print("-1")
            sys.exit()

print(c)





Measured memory_bytes: 21772
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll max3(ll a,ll b,ll c){ return max( max(a,b),c ); }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}
const int N = 3005;
double dp[N][N];

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int n; cin>>n;
	double p[n+1];
	forn1(i,n) cin>>p[i];
	forn(i,n+1) forn(j,n+1) dp[i][j] = 0.0;
	dp[0][0] = 1.0;
	forn1(i,n)
	{
	    for(int j=0;j<=i;j++)
	    {
	        dp[i][j] = dp[i-1][j]*(1.0-p[i]);
	        if(j>0) dp[i][j] += dp[i-1][j-1]*p[i];
	        //cout<<dp[i][j]<<' '<<i<<' '<<j<<endl;
	    }
	}
	double ans = 0.0;
	for(int i=n/2+1;i<=n;i++) ans += dp[n][i];
	cout<<fixed<<setprecision(15)<<ans;
	
	return 0;
}


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

#define MAX 1000

void printArray(int a[], int size);

int main(void) {
  int n;
  int input[MAX + 1];

  cin >> n;

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

  for(int i = 1; i < n; i++) {
    int v = input[i];
    int j = i - 1;
    while(j >= 0 && input[j] > v) {
      input[j + 1] = input[j];
      j--;
    }
    input[j + 1] = v;
    printArray(input, n);
  }
  return 0;
}

void printArray(int a[], int size) {
  for(int k  = 0; k < size; k++) {
    if(k == 0) {
      cout << a[k];
    }
    else {
      cout << " " << a[k];
    }
  }
  cout << endl;
}

Measured memory_bytes: 1164
a, b, c, x, y = map(int, input().split())
ans = 10**10
ans = min(ans, a*x + b*y)
ans = min(ans, c*2*x + b*max(0, y - x))
ans = min(ans, c*2*y + a*max(0, x - y))
print(ans)

Measured memory_bytes: 3316
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();
        int l[] = new int[n];

        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
        }

        int index = 0;
        int state = 0;
        int count = 0;

        while (index < n && state <= x) {
            count++;
            state = state + l[index];
            index++;
        }

        if (state <= x) {
            count++;
        }

        System.out.println(count);
	}
}


Measured memory_bytes: 23892
my ($A,$B) =  split(' ', <>);

# 偶数 n について、
# n ^ (n-1) = 1

my $top;
my $end;
if ( $A % 2 != 0 ) {
    $top = $A;
}
if ( $B % 2 == 0 ) {
    $end = $B;
}

my $nums = $B - $A + 1;
$nums-- if $top;
$nums-- if $end;

if ( ($nums / 2) % 2 == 0 ) {
    print calc(0);
}
else {
    print calc(1);
}

sub calc {
    my $n = shift;

    my $result;
    if ( defined $top && defined $end ) {
        $result = $top ^ $n ^ $end;
    }
    elsif ( defined $top ) {
        $result = $top ^ $n;
    }
    elsif ( defined $end ) {
        $result = $n ^ $end;
    }
    else {
        $result = $n;
    }

    return $result;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());

		int totalVisitor = 0;
		for (int i = 0; i < n; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			totalVisitor += r - l + 1;
		}

		System.out.println(totalVisitor);

		sc.close();
	}
}

Measured memory_bytes: 25836
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());

		int count = 0;

		for (int i = 0; i < n; i++) {
			if (k <= Integer.parseInt(sc.next())) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 43556
D = int(input())
C = [int(i) for i in input().split()]
scores = [[int(i) for i in input().split()] for j in range(D)]
ans = [0]*D
S = 0
last = [0]*26
for d in range(1,D+1):
    m = -float("inf")
    index = -1
    for i,t in enumerate(scores[d-1]):
        st = S + t
        lt = [i for i in last]
        lt[i] = d
        for j in range(26):
            st -= C[j] * (d - lt[j])
        if m < st:
            m = st
            index = i
    S = m
    ans[d-1] = index+1
    last[index] = d
print("\n".join(map(str, ans)))

Measured memory_bytes: 9524
object Main extends App{

  val n = io.StdIn.readInt()
  
  for (i <- 1 to n) {
    val sideAry = io.StdIn.readLine().split(' ').map { _.toInt }.sorted

    if (sideAry(2) * sideAry(2) == (sideAry(0) * sideAry(0) + sideAry(1) * sideAry(1)))
      println("YES")
    else
      println("NO")
  }
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int

typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  int n, x;
  cin >> n >> x;
  vector<int> v(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  sort(all(v));

  int res = 0;
  int count = 0;

  if(v[0] > x)
  {
    cout << 0 << endl;
    return 0;
  }

  for (int i = 0; i < n; i++) {
    count += v[i];
    if(count == x)
    {
      res++;
      break;
    }
    else if(count > x) break;
    res++;
  }
  if(count < x) res--;

  cout << res << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
main(){
  int i=0,j,k,l;
  double x[1000],y[1000],a,b,c,d,e,f;
  while(1){
    scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f);
    if(feof(stdin))break;
    x[i]=(b*f-e*c)/(b*d-e*a)*1000;
    y[i]=(a*f-d*c)/(a*e-d*b)*1000;
    k=(int)x[i];
    l=(int)y[i];
    x[i]=(double)k/1000;
    y[i]=(double)l/1000;
    i++;
  }
  for(j=0;j<i;j++){
    printf("%.3lf %.3lf\n",x[j],y[j]);
  }
  return(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
signed main(){
	int n,m;
	string a[50],b[50];
	cin>>n>>m;
	rep(i,n)cin>>a[i];
	rep(i,m)cin>>b[i];
	rep(i,n-m+1){
		rep(j,n-m+1){
			rep(k,m){
				rep(h,m){
					if(a[i+k][j+h]!=b[k][h])goto ioi;
				}
			}
			cout<<"Yes"<<endl;
			return 0;
			ioi:;
		}
	}
	cout<<"No"<<endl;
}



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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;




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

	int n;cin>>n;

	multimap<ll,ll> mp;

	for(int i=0; i<n; i++){
		ll  a, b;cin>>a>>b;

		mp.insert(make_pair(b,a));
	}

	ll sum=0;
	ll t=0;
	for(auto e: mp){
		t += e.second;

		if(t >e.first){
			writeln("No");
			return 0;
		}
	}
	writeln("Yes");

}




Measured memory_bytes: 12800
package main

import "fmt"

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	var res = abc083B(n, a, b)
	fmt.Println(res)

}

func abc083B(n, a, b int) int {
	var res = 0

	for i := 1; i <= n; i++ {
		var wk = i
		var total = 0

		for wk > 0 {
			total += wk % 10
			wk /= 10
		}

		if total >= a && total <= b {
			res += i
		}

	}
	return res

}


Measured memory_bytes: 512
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,k=map(int,input().split());a=0\n"
"for i in range(1,n+1):\n"
" j=1/n\n"
" while i<k:i*=2;j/=2\n"
" a+=j\n"
"print(a)\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 7492