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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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


int solve(){
  int N;cin>>N;

  int res = 0;
  rep(n, 1, N+1){
    if (n%2==0) continue;
    int cnt=0;
    rep(j, 1, n+1){
      if (n%j==0) cnt++;
    }
    if (cnt==8){
      dump(n);
      res++;
    }
  }

  cout << res << endl;

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


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

using namespace std;

//State
//dp[i][j]: The minimum cost to merge the fruits between
//	A[i]...A[j]

//Initialization
//dp[i][i] = A[i]

//Transitions
//dp[i][j] = max(dp[i][k]+dp[k+1][j]) k E [i,j-1]

//Order of evaluation
//Diagonal or length of substring

//Answer
//dp[0][N-1]

//Time Complexity = O(n^3)

const long long INF = 1e18+7;
vector<vector<long long>> dp(405, vector<long long>(405, INF));
long long prefix[405];
int A[405];

int main(){
	int N;
	cin >> N;
	long long sum = 0;
	for(int i=0; i<N; i++){
		cin >> A[i];
		dp[i][i] = 0;
		sum = sum + A[i];
		prefix[i] = sum;
	}
	for(int rMinusl=1; rMinusl<N; rMinusl++){
		for(int l=0; l<N; l++){
			int r = l+rMinusl;
			if(r<N){
			    for(int k=l; k<=r-1; k++){
			        long long temp1 = prefix[k]-prefix[l]+A[l];
			        long long temp2 = prefix[r]-prefix[k+1]+A[k+1];
				    dp[l][r] = min(dp[l][r], dp[l][k]+dp[k+1][r]+temp1+temp2);
		    	}   
			}
		}
	}
	cout << dp[0][N-1];
}




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



Measured memory_bytes: 3080
import java.util.*;
            class Main{
              public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                long a = sc.nextLong();
                long b = sc.nextLong();
                long c = sc.nextLong();
                long d = sc.nextLong();
                
                long x = a * c;
                long y = a * d;
                long z = b * c;
                long w = b * d;
                long[] aa = new long[4];
                
                aa[0] = x;
                aa[1] = y;
                aa[2] = z;
                aa[3] = w;
                long max = x;
             
                for(int i = 0; i < 4; i++){
                  if(aa[i] > max){
                    max = aa[i];
                  }
                }
                System.out.println(max);
              }
            }

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

using ll = long long;
// #define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/

int dp[105][4][2];

signed main() {
  string s;
  int K;
  cin >> s;
  cin >> K;
  int n = s.size();
  dp[0][0][0] = 1;
  REP(i,n) REP(j,K+1) REP(k,2) {
    int cur_digit = s[i] - '0';
    REP(pot_digit, 10) {
      int next_i = i+1, next_j = j, next_k = k;
      if(pot_digit) ++next_j;
      if(next_j > K) continue;
      if(next_k == 0) {
        if(pot_digit > cur_digit) continue;
        if(pot_digit < cur_digit) next_k = 1;
      }

      dp[next_i][next_j][next_k] += dp[i][j][k];
    }
  }
  cout << dp[n][K][0] + dp[n][K][1];
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from fractions import gcd

class SegmentTree:
    def __init__(self, N, func, I):
        self.sz = N
        self.func = func
        self.I = I
        self.seg = [I]*(N*2)
 
    def assign(self, k, x):
        self.seg[k + self.sz] = x
 
    def build(self):
        for i in range(self.sz - 1, 0, -1):
            self.seg[i] = self.func(self.seg[i + i], self.seg[i + i + 1])
 
    def update(self, k, x):
        k += self.sz
        self.seg[k] = x
        while k > 1:
            k >>= 1
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])
 
    def query(self, a, b):
        L = self.I
        R = self.I
        a += self.sz
        b += self.sz
        while a < b:
            if a & 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b & 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a >>= 1
            b >>= 1
        return self.func(L, R)

def main():
    N = int(readline())
    m = map(int,read().split())
    seg = SegmentTree(N , gcd , 0)
    for i in range(N):
        seg.assign(i , next(m))
    seg.build()
    ans = 1
    for i in range(N):
        ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N)))
    print(ans)

main()


Measured memory_bytes: 81340
import scala.io.StdIn

object Main{
  def main(args: Array[String]){
    var list = List[Int]()

    for(in <- StdIn.readLine.split(" ").map(_.toInt)){
      list = in :: list
    }

    list = list.sortWith((s,t: Int) => s < t)
    println(list.mkString(" "))
  }
}

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

int main(){
    int n, d;
    cin >> n >> d;
    cout << (n-1)/(2*d+1) + 1 << endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

VI adj[112345];
int visited[112345] = {};
int cnt[112345] = {};
LL N,K;
LL ans;
bool flag = 0;

void dfs(int v, int pre){
    visited[v] = 1;
    dump(pre)
    dump(v)
    if(K-1-cnt[pre] < 0){
        flag = 1;
    }
    ans *= K - 1 - cnt[pre];
    ans %= MOD;
    dump(K- 1- cnt[pre])
    dump(ans)

    for(int p : adj[v]){
        if(visited[p] == 0){
            cnt[v]++;
            dfs(p, v);
        }
    }
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    REP(i,112345) cnt[i] = 0;
    int deg[112345] = {};
    cin >> N >> K;
    REP(i,N-1){
        int a,b; cin >> a >> b;
        a--; b--;
        adj[a].eb(b);
        adj[b].eb(a);
        deg[a]++;
        deg[b]++;
    }
    dump("ok")

    if(N == 1){
        cout << K << endl;
        return 0;
    }
    int start;
    REP(i,N){
        if(deg[i] == 1){
            start = i;
            break;
        }
    }
    int nex = adj[start][0];
    ans = K;
    //ans = 1;
    dump(start)
    dump(nex)
    visited[start] = 1;
    dfs(nex,start);
    //dfs(start,112344);

    if(flag){
        cout << 0 << endl;
        return 0;
    }

    cout << ans << endl;





}

Measured memory_bytes: 12032
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{
  int H,A;
  cin >> H >> A;

  int i = 0;
  while(1){
    i++;
    H -= A;

    if(H<=0){
      break;
    }
  }

  cout << i << endl;

  return 0;
}


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

int main(){
	int x,y;
	while(true){
		cin >> x;
		cin >> y;
		if(x == 0&&y ==0){
			break;
		}
		if(x > y){
			swap(x,y);
		}
		cout << x << " " << y << endl;
	}
	return 0;
}

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

int main() {
    // input
    int N;
    cin >> N;

    // solve
    bool flag = false;
    int ans = 0;
    int dig;
    int tmp = N;
    while (tmp) {
        dig = tmp % 10;
        ans += dig;
        tmp /= 10;
    }
    if (N % ans == 0) flag = true;

    // output
    cout << (flag ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	int N, M; cin >> N >> M;
	
	priority_queue<pair<ll, pl> > q;
	
	ll sum = 0;
	
	F0R(i, N) {
		ll cur; cin >> cur;
		sum += cur;
		q.push(mp(cur-cur/2, mp(cur, 1)));
	}
	
	F0R(i, M) {
		if (q.empty()) break;
		pair<ll, pl> cur = q.top(); q.pop();
		
		sum -= cur.f;
		
		ll val = cur.s.f;
		ll num = cur.s.s;
		
		if (num != 30) { pair<ll, pl> nxt = mp(val/(1<<num) - val/(1<<(num+1)), mp(val, num+1)); q.push(nxt); }
		
	}
	
	cout << sum << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 4952
def main():
    n = int(input())
    lucas = [0 for _ in range(n+1)]

    for i in range(n+1):
        if i == 0:
            lucas[i] = 2
        elif i == 1:
            lucas[i] = 1
        else:
            lucas[i] = lucas[i-1] + lucas[i-2]

    ans = lucas[-1]
    print(ans)


if __name__ == "__main__":
    main()


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

const ll INF = 1e18;

int main() {
  ll N, X;
  cin >> N >> X;
  vector<ll> x(N);
  for (int i = 0; i < N; ++i) cin >> x[i];
  vector<ll> a(N + 1, 0);
  for (int i = 0; i < N; ++i) a[i + 1] = a[i] + x[i];

  ll ans = INF;
  auto F = [](ll x, ll y) { return (INF / x < y) ? INF : x * y; };
  auto E = [F](ll i, ll x) { return (i == 1) ? F(5, x) : F((2 * i + 1), x); };
  for (ll k = 1; k <= N; ++k) {
    ll sum = (N + k) * X;
    for (ll i = 1; i <= (N + k - 1) / k; ++i) {
      sum += E(i, a[N - k * (i - 1)] - a[max(0LL, N - k * i)]);
      sum = min(sum, INF);
    }
    ans = min(ans, sum);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;

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

	int cnt = 1;
	int i=0, j=0;

	for (int i = 1; i < n; i++)
	{
		for (j = 0; j < i; j++)
		{
			if (h[i] < h[j])
			{
				break;
			}
		}
		if (i == j)
		{
			cnt++;
		}
	}

	cout << cnt << endl;
}


Measured memory_bytes: 384
import java.util.*;

class Main{
 	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);  
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int X = sc.nextInt();
	int count = 0;
    for(int ca = 0 ; ca < A+1 ; ++ca){
    	for(int cb = 0 ; cb < B+1 ; ++cb){ 
  		   for(int cc = 0 ; cc < C+1 ; ++cc){
             if( (ca*500 + cb*100 + cc *50) == X){
               ++count;
             }
           }
        }
    }
      
      
    System.out.println(count);
    }	
      
  
  
}

Measured memory_bytes: 23124
import scala.annotation.tailrec

object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val p = Array.fill(n)(sc.nextInt())
  println(calc(p, 0, p(0), 0))
  
  @tailrec
  def calc(p: Array[Int], i: Int, max: Int, acc: Int): Int = {
    if (p.length == i) {
      acc
    } else if (p(i) <= max) {
      calc(p, i+1, p(i), acc+1)
    } else {
      calc(p, i+1, max, acc)
    }
  }
}

Measured memory_bytes: 60152
N, A = map(int,input().split())
X = [int(x) for x in input().split()]

dp = [[0]*(N*A+1) for _ in range(N+1)] #dp[i][j]:i枚の和がjとなるようなカードの選び方
dp[0][0] = 1  
for x in X:
    for i in reversed(range(1,N+1)):
        for j in reversed(range(N*A+1)):
            if j < x:
                continue
            dp[i][j] += dp[i-1][j-x]
ans = sum(dp[k][k*A] for k in range(1,N+1)) 
print(ans) 

Measured memory_bytes: 10368
S=input()
if int(S[0]+S[1])>0 and int(S[0]+S[1])<13:
  if int(S[2]+S[3])>0 and int(S[2]+S[3])<13:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if int(S[2]+S[3])>0 and int(S[2]+S[3])<13:
    print("YYMM")
  else:
    print("NA")
 

Measured memory_bytes: 8948
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-02 22:49:12
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<(x)>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l) {
    if (l > 0) return gcd(l, k%l);
    else return k;
}

ostringstream oss_global;
string s_global = oss_global.str();

LL s(LL n) {
    LL m = n % 10;
    n /= 10;

    if (n <= 0) return m;
    else return m + s(n);
}

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

    LL x = s(n);
    if (n % x == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
//gauravsinghh
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(int i = a; i <= b; i++)
#define ffo(i, a, b) for(int i = a; i >= b; i--)
#define MAX 100005
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

bool comp(const pair < ll, ll >&a, const pair < ll, ll >&b){
    return ((a.ss < b.ss) || (a.ss == b.ss && a.ff < b.ff));
}

signed main(){ 
    IOS
    //io_set();
    ll n;
    cin >> n;
    vector < ll > a(n+1), l(n+1), r(n+1);
    fo(i, 1, n){
        cin >> a[i];
    }
    l[1] = 0, r[n] = 0;
    fo(i, 2, n){
        l[i] = __gcd(l[i-1], a[i-1]);
    }
    ffo(i, n-1, 1){
        r[i] = __gcd(r[i+1], a[i+1]);
    }
    ll m = INT_MIN;
    fo(i, 1, n){
        //cout << l[i] << " " << r[i] << "\n ";
        ll x = __gcd(l[i], r[i]);
        m = max(m, x);
    }
    cout << m << endl;
    return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main (){
  int i,h,n,a;
  cin>>h>>n;
  for(i=0;i<n;i++){
    cin>>a;
    h-=a;
  }
  if(h<=0)
  cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
int main(void) {
	int N;
	std::cin >> N;
	if (100 <= N && N <= 111) {
		std::cout << 111;
	} else if (112 <= N && N <= 222) {
		std::cout << 222;
	} else if (112 <= N && N <= 333) {
		std::cout << 333;
	} else if (334 <= N && N <= 444) {
		std::cout << 444;
	} else if (445 <= N && N <= 555) {
		std::cout << 555;
	} else if (556 <= N && N <= 666) {
		std::cout << 666;
	} else if (667 <= N && N <= 777) {
		std::cout << 777;
	} else if (778 <= N && N <= 888) {
		std::cout << 888;
	} else if (889 <= N && N <= 999) {
		std::cout << 999;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
absA = [abs(i) for i in A]
minusA = [i for i in A if i<0]
mina = min(absA)
if (0 in A) or (len(minusA)%2 == 0):
    print(sum(absA))
else:
    print(sum(absA) -2*mina)

Measured memory_bytes: 14412
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

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

    string S,T;
    cin >> S >> T;
    for(int i=0; i<S.size(); i++){
        bool tmp = true;
        for(int j=0; j<S.size(); j++){
            tmp = tmp && (S[(i+j)%S.size()] == T[j]);
        }
        if(tmp){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "vector"
using namespace std;

void dp(long long N, vector<int> arr, int subscript, int *result){
    int num = 0;
    //arrをintに変換
    for (int i = 8; i >= 0; i--)
        num = num * 10 + arr[i];

    if (subscript > 9 || num > N)
        return;

    vector<bool> flag(3);

    //3,5,7が使われてるか調べる
    for (int i = 0; i < 9; i++){
        switch(arr[i]){
        case 3:
            flag[0] = true;
            break;
        case 5:
            flag[1] = true;
            break;
        case 7:
            flag[2] = true;
            break;
        }
    }

    //3,5,7全て使われてたらカウントx
    if(flag[0] && flag[1] && flag[2]){
        (*result)++;
    }

    vector<int> tmp = arr;
    tmp[subscript] = 3;
    dp(N, tmp, subscript + 1, result);
    tmp[subscript] = 5;
    dp(N, tmp, subscript + 1, result);
    tmp[subscript] = 7;
    dp(N, tmp, subscript + 1, result);

}

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

    long long int N;
    int result = 0;
    cin >> N;

    vector<int> arr(9);
    vector<bool> flag(3);

    dp(N, arr, 0, &result);

    cout << result << "\n";
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <string>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<char> & p, ll a){
    rep(i, a){
        char input;
        cin >> input;
        p . push_back(input);
    }
}

int main(int argc, const char * argv[]) {

    // source code
    ll n,a,b,c,d;
    vector<char> s;
    n=inputValue();
    a=inputValue()-1;
    b=inputValue()-1;
    c=inputValue()-1;
    d=inputValue()-1;

    inputVector(s,n);
    auto itr_a = next(s.begin(),a);
    auto itr_b = next(s.begin(),b);
    auto itr_c = next(s.begin(),c);
    auto itr_d = next(s.begin(),d);

    for(auto i=itr_b;itr_d-1 != i; i++){
        if(*(i)=='#' && *(i+1)=='#'){
            cout << "No"<< endl;
            return 0;
        }
    }

    for(auto i=itr_a;itr_c-1 != i; i++){
        if(*(i)=='#' && *(i+1)=='#'){
            cout << "No"<<endl;
            return 0;
        }
    }

    if(d < c)//追い越しの必要がある
    {
        for(auto i=itr_b; i!=itr_d+1;i++){
            if (   *(i-1)=='.' 
                && *(i+1)=='.' 
                && *(i)=='.'){
                cout << "Yes" << endl;
                return 0;
            }    
        }
        cout << "No"<<endl;
        return 0;
    }


    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(){
  string a;
  cin >> a;
  if(a.at(0)==a.at(1)&&a.at(1)==a.at(2)) cout << "No";
  else if(a.at(0)==a.at(1)&&a.at(2)==a.at(3)) cout << "Yes";
  else if(a.at(0)==a.at(2)&&a.at(1)==a.at(3)) cout << "Yes";
  else if(a.at(0)==a.at(3)&&a.at(1)==a.at(2)) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 3612
def solve():
    s=input()
    K=int(input())
    words = set()
    ls = len(s)
    for i in range(ls):
        for j in range(i+1,min(i+6,ls+1)):
            words.add(s[i:j])
    words = sorted(list(words))
    return words[K-1]

print(solve())


Measured memory_bytes: 40432
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;



bool enough( long long T, int A, int B, vector<int>& h )
{
    long long numNecessaryAtacks = 0;
    for( int i = 0; i < h.size(); ++i )
    {
        numNecessaryAtacks += max( 0LL, (h[i] - B*T + (A-B-1)) / (A - B) );
        
    }
    return numNecessaryAtacks <= T;
}



int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    vector<int> h(N);
    for( int i = 0; i < N; ++i ) cin >> h[i];


    // 二分探索
    int l = 0, r = 1e+9;
    while( r-l > 1 )
    {
        int c = ( l + r ) / 2;
        if( enough(c, A, B, h) ) r = c;
        else l = c; 
    }
    cout << r << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

typedef pair<int, int> Pii;

const int N_MAX = 500;

vector<Pii> v(N_MAX+1, Pii(0, 0));
 
bool check(int n) {
    // それぞれ [1, i], [i, n] に含まれるべきことが確定している要素の数
    vector<int> cnt_l(n*n+1, 0), cnt_r(n*n+2, 0);
    for(int i=1;i<=n;++i) {
        cnt_l[v[i].first] += i;
        cnt_r[v[i].first] += n-i+1;
    }
    for(int i=1;i<=n*n;++i) cnt_l[i] += cnt_l[i-1];
    for(int i=n*n;i>=1;--i) cnt_r[i] += cnt_r[i+1];

    for(int i=1;i<=n*n;++i) {
        if(i < cnt_l[i] || n*n-i+1 < cnt_r[i]) {
            return false;
        }
    }
    return true;
}

vector<int> construct(int n) {
    vector<int> ret(n*n+1, 0);
    sort(v.begin(), v.begin()+n+1);

    // x_i にしたがって数値を入れる
    for(int j=1;j<=n;++j) {
        int idx = v[j].first;
        int num = v[j].second;
        ret[idx] = num;
    }

    // x_i で指定されたインデックスより前の部分を埋める
    int j = 1;
    int num = v[j].second;
    int num_cnt = num - 1;
    for(int i=1;i<=n*n;++i) {
        if(ret[i]) continue;
        while(j < n && !num_cnt) {
            ++j;
            num = v[j].second;
            num_cnt = num - 1;
        }
        if(j == n && !num_cnt) break;
        ret[i] = num;
        --num_cnt;
    }
    
    // x_i で指定されたインデックスより後の部分を埋める
    j = 1;
    num = v[j].second;
    num_cnt = n - num;
    for(int i=1;i<=n*n;++i) {
        if(ret[i]) continue;
        while(j < n && !num_cnt) {
            ++j;
            num = v[j].second;
            num_cnt = n - num;
        }
        if(j == n && !num_cnt) break;
        ret[i] = num;
        --num_cnt;
    }

    return ret;
}

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

    if(check(n)) {
        cout << "Yes" << endl;
        vector<int> ans = construct(n);
        for(int i=1;i<=n*n;++i) {
            cout << ans[i] << " ";
        }
        cout << endl;
    } else {
        cout << "No" << endl;
    }

}


Measured memory_bytes: 2176
#define ll long long int

#include <bits/stdc++.h>

using namespace std;

int main() {

    int N;
    cin >> N;
    map<ll, int> mp;

    for (int x = 1; x * x <= N; x++) {

        for (int y = 1; y * y <= N - (x * x); y++) {

            for (int z = 1; z * z <= N - ((x * x) + (y * y)); z++) {

                mp[((x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x))]++;
            }
        }
    }
    for (int i = 1; i <= N; i++)cout << mp[i] << endl;


    return 0;
}

Measured memory_bytes: 4712
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    K = read_int()
    X = read_int()
    Y = read_int()
    if K >= N:
        return X*N
    cost = X*K
    N -= K
    cost += N*Y
    return cost


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 61988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define repb(bit,n,init) for(ll bit=init;bit<(1<<n);++bit)

vector<ll> fact, invfact;
ll modpower(ll x, ll n, ll mod){
    ll res = 1;
    while(n){
        if(n&1)res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
ll inv(ll n){
    return modpower(n,MOD-2,MOD);
}
void COMinit(ll k){ //空っぽの配列を二つ
   k++;
   fact.resize(k, 0);
   invfact.resize(k, 0);
   fact[0] = 1;
   repi(i, k, 1)
   {
       fact[i] = fact[i - 1] * i % MOD;
   }
   invfact[k - 1] = inv(fact[k - 1]);
   repd(i, k - 2, 0)
   {
       invfact[i] = invfact[i + 1] * (i + 1) % MOD;
   }
   return;
}
ll nCk(vector<ll> &fact,vector<ll> &invfact,ll n, ll k){ //この関数を使う前にCOMinit
   if (k < 0 || n < k)
       return 0LL;
   return fact[n] * invfact[k] % MOD * invfact[n - k] % MOD;
}
ll com(ll n, ll k)
{
    ll iv = 1;
    ll fa = 1;
    repi(i, k, 0)
    {
        fa *= (n - i);
        fa %= MOD;
    }
    repi(i, k + 1, 1)
    {
        iv *= inv(i);
        iv %= MOD;
    }
    return fa * iv % MOD;
}

//---------main function----------

int main()
{
    int x,y;
    cin >> x >> y;
    if(y - 2 * x < 0 || (y - 2 * x)%2){
        cout << "No" << endl;
    }else if(4 * x - y < 0 || (4 * x - y)%2){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
   return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
using namespace std;
const int maxn=505;
char b[maxn][maxn],c[maxn][maxn];
int h,w,a[maxn][maxn];
inline void init(){
	scanf("%d%d",&h,&w);
	for (int i=1;i<=h;i++){
		char s[maxn];
		scanf("%s",s+1);
		for (int j=1;j<=w;j++){
			if (s[j]=='.') a[i][j]=0;
				else a[i][j]=1;
		}
	}
	for (int i=1;i<=h;i++){
		for (int j=1;j<=w;j++) b[i][j]='.',c[i][j]='.';
	}
	for (int i=1;i<=w;i++){
		b[1][i]='#';
		c[h][i]='#';
	}
	for (int j=1;j<=w;j++){
		int l=1,r=h;
		if (j&1) r--;
			else l++;
		for (int i=l;i<=r;i++){
			if (j&1) b[i][j]='#';
				else c[i][j]='#';
		}
	}
	for (int i=1;i<=h;i++){
		for (int j=1;j<=w;j++){
			if ((a[i][j]==1)&&b[i][j]=='.'){
				b[i][j]='#';
			}
			if ((a[i][j]==1)&&c[i][j]=='.'){
				c[i][j]='#';
			}
		}
	}
	for (int i=1;i<=h;i++){
		for (int j=1;j<=w;j++){
			putchar(b[i][j]);
		}
		puts("");
	}
	puts("");
	for (int i=1;i<=h;i++){
		for (int j=1;j<=w;j++){
			putchar(c[i][j]);
		}
		puts("");
	}
}
int main(){
	init();
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

#define INF 1e9
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int dev4 = 0;
    int odd = 0;
    rep(i, n) {
        cin >> a.at(i);
        if (a.at(i) % 2 != 0) odd++;
        if (a.at(i) % 4 == 0) dev4++;
    }
    if (odd + dev4 == n && odd > dev4 + 1) cout << "No" << endl;
     else if (odd + dev4 != n && odd > dev4) cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

int main(){
    /*入力*/
    int n;
    cin >> n;
    vector<int> b(n - 1),a(n);
    for(int i = 0;i < n - 1;i++){
        cin >> b.at(i);
    }
    /**/
    a.at(0) = b.at(0);
    int sum = a.at(0);
    
    for(int i = 1;i < n - 1;i++){
        a.at(i) = min(b.at(i),b.at(i - 1));
        //cout << a.at(i) << endl;
        sum += a.at(i);
    }

    sum +=  b.at(n - 2);
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 888
def solve(X, Y, Z, V, E, A):
    dp = [[0.0] * 6001 for _ in range(Y + 11)]
    dp[0][0] = 1.0
    for i in range(Y):
        for j in range(5001):
            if dp[i][j] <= 0.0:
                continue
            for k in V:
                t = i + k
                if t > Y:
                    dp[Y][j] += dp[i][j]/X
                elif E[t] == 1:
                    dp[min(Y, t+A[t])][j] += dp[i][j]/X
                else:
                    dp[t][max(0, j+A[t])] += dp[i][j]/X

    s = 0
    for i in range(5001):
        s += i * dp[Y][i]
    print(int(s))

if __name__ == "__main__":

    while True:
        X, Y, Z = map(int, input().split())
        if X | Y | Z == 0:
            break
        V = list(map(int, input().split()))
        E = [0] * 100
        A = [0] * 100
        for _ in range(Z):
            n, e, a = map(int, input().split())
            E[n] = e
            if e == 3:
                A[n] = -a
            else:
                A[n] = a
        solve(X, Y, Z, V, E, A)

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

int main(int argc, char* argv[])
{
    int input_time = 0;
    int hour = 0;
    int minite = 0;
    int second = 0;

    cin >> input_time;

    hour = input_time / 3600;
    minite = input_time / 60 - (hour * 60);
    second = input_time - (hour * 3600 + minite * 60);

    cout << hour << ":" << minite << ":" << second << endl;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; i++) cin >> h[i];
    vector<int> dp(N+2, INF);
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
    }
    cout << dp[N-1] << '\n';
}


Measured memory_bytes: 4056
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>

#define mod 1000000007


int main() {
    long long n, m; std::cin >> n >> m;

    long long ans;
    if(m < 2*n) {
        ans = m/2;
    } else {
        ans = n + ((m - 2LL * n) / 4LL);
    }


    std::cout << ans << std::endl;
}

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

using namespace std;
using i64 = long long;

i64 MOD = 1000000007LL;

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

    vector<i64> a(n);
    for (auto &&ai : a) cin >> ai;

    i64 sum = 0;
    for (int d = 0; d < 60; d++)
    {
        i64 k = 0;
        for (auto &&ai : a)
            if (ai & (1LL << d)) k++;
        sum += (((k * (n - k)) % MOD) * ((i64)pow(2LL, d) % MOD)) % MOD;
        sum %= MOD;
    }

    cout << sum << endl;

    return 0;
}

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

int main() {
  int A, B, C;

  cin >> A >> B >> C;

  if (A > B) {
    cout << 0;
  }
  else if (C < B / A) {
    cout << C;
  }
  else {
    cout << B / A;
  }

  return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;

bool ok() {
  int N;
  cin >> N;
  vector<int> A(N);
  long long sum = 0;
  for (int i=0; i<N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  long long tot = 1LL * N * (N+1) / 2;
  if (sum % tot) return false;

  for (int i=0; i<N; i++) {
    long long diff = A[i] - A[(i+N-1)%N];
    diff -= sum / tot;
    diff *= -1;
    if (diff < 0) return false;
    if (diff % N) return false;
//    diff /= N;
  }
  return true;
}

int main()
{
  if (ok()) printf("YES\n"); else printf("NO\n");
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define fr(i,a,b) for(ll i=a;i < b;i++)
#define fe(i,a,b) for(ll i=a;i <= b;i++)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fir first
#define sec second
#define tr(it,x) for(auto it = x.begin();it != x.end();it++)
#define mp make_pair
#define sz(x) (ll)x.size()
#define rep(i,n) for(ll i=0;i<n;i++)
#define double long double
#define accuracy ll precision = numeric_limits<double>::digits10
#define pll pair<ll,ll>
#define MAXN 100005
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define case(x) cout<<"Case #"<<x+1<<": "
#define endl "\n"
#define preturn(X) cout<<(X)<<endl; return 0
const int MOD = 1e9+7;
ll powmod(ll a,ll b,ll m=MOD){ll r=1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}
ll power(ll a,ll b){ll r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
ll gcd(ll a,ll b){if(!b)return a;return gcd(b,a%b);}
ll inv(ll a, ll m = MOD){return powmod(a,m-2,m);}
ll lcm(ll a,ll b){return(a*b)/gcd(a,b);}

int32_t main(){
    accuracy;
    cout.precision(precision);
    int n;
    cin >> n;
    int k = (n - 1) / 2;
    vector<double> p(n);
    rep(i,n)cin>>p[i];
    vector<double> hprob(n+1); // probability of getting i heads = hprob[i]
    hprob[0] = 1 - p[0];
    hprob[1] = p[0];
    // if n == 1 we have the answer above
    for(int i = 1; i < n; i++){
        // prob h = p[i], probabilities of previous i coins have already been computed
        vector<double> h2(i+2);
        h2[i+1] = hprob[i] * p[i];
        h2[0] = hprob[0] * (1 - p[i]);
        for(int j = 1; j <= i; j++){
            h2[j] = hprob[j-1] * p[i] + hprob[j] * (1 - p[i]);
        }
        copy(h2.begin(),h2.end(),hprob.begin());
    }
    double ans = 0;
    for(int i = k+1; i <= n; i++){
        ans += hprob[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
def selection_sort(List):
	cnt = 0
	l=len(List)
	for i in range(l):
		num_index=i
		for j in range(i,l):
			if List[num_index]>List[j]:
				num_index=j
		if num_index != i:
			temp=List[num_index]
			List[num_index]=List[i]
			List[i]=temp
			cnt+=1
	return cnt
N=input()
N_List=map(int,raw_input().split())
cnt=selection_sort(N_List)
print(" ".join(map(str,N_List)))
print(cnt)

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



int main(){
     int A1, A2, A3;
     int s = 0;

     cin >> A1 >> A2 >> A3;

     s =A1+A2 + A3;
     if (s > 21){
         cout << "bust";
     }
     else{
         cout << "win";
     }




}

Measured memory_bytes: 256
h, w, m = list(map(int, input().split()))
count_row = [0 for _ in range(h)]
count_col = [0 for _ in range(w)]
# X = [[0 for i in range(w)] for _ in range(h)]
max_col = 0
max_row = 0
max_row_index = []
max_col_index = []
M = set()
for i in range(m):
    mh, mw = list(map(int, input().split()))
    # X[mh-1][mw-1] = 1
    M.add((mh-1, mw-1))
    count_row[mh-1] += 1
    count_col[mw-1] += 1
    if count_row[mh-1] > max_row:
        max_row = count_row[mh-1]
        max_row_index = [mh-1]
    elif count_row[mh-1] == max_row:
        max_row_index.append(mh-1)
    
    if count_col[mw-1] > max_col:
        max_col = count_col[mw-1]
        max_col_index = [mw-1]
    elif count_col[mw-1] == max_col:
        max_col_index.append(mw-1)
# max_row_index = [i for i, v in enumerate(count_row) if v == max(count_row)]
# max_col_index = [i for i, v in enumerate(count_col) if v == max(count_col)]
# ans = max(count_row) + max(count_col) -1
ans = max_col + max_row -1

if len(max_col_index)*len(max_row_index) > m:
    ans += 1
else:
    flag = False
    for i in max_row_index:
        for j in max_col_index:
            if (i, j) not in M:
                ans += 1
                flag = True
                break
        if flag:
            break
print(ans)

Measured memory_bytes: 84220
#include<stdio.h>
int main(){
	int n,i,c=0;
	char s[100001];
	scanf("%d%s",&n,s);
	for(i=1;i<n;i++)if(s[i-1]=='O'&&s[i]=='X'||s[i-1]=='X'&&s[i]=='O')c++,i++;
	printf("%d\n",c);
	return 0;
}


Measured memory_bytes: 2024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {if (a < b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmin(A &a, B b) {if (a > b) {a = b; return 1;} return 0;}
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const bool debug = 0;
/****************************/

// dp[k桁目][先頭の数字(0:leading-zero)][leading-zeroを除く先頭が同じ数であるかどうか] := k桁以降での場合の数
ll dp[201][10][2];

ll func(int k, int num, int same) {
	if (k == -1) return !same;
	ll &res = dp[k][num][same];
	if (~res) return res;
	
	res = 0;
	
	if (same) {
		REP(i, 10) {
			res += func(k - 1, num == 0 ? i : num, num == 0 || (num != 0 && num == i));
			if (res >= INFL) return res = INFL;
		}
	}
	else {
		res += func(k - 1, num, same) * 2;
		if (res >= INFL) return res = INFL;
	}
	
	return res;
}

int main() {
	memset(dp, -1, sizeof(dp));
	ll N;
	while (cin >> N, N) {
		int num = 0, same = 1;
		pii p(-1, -1);
		string ans;
		
		for (int k = 200; k >= 0; k--) {
			
			if (same) {
				REP(i, 10) {
					ll cur = func(k - 1, num == 0 ? i : num, num == 0 || (num != 0 && num == i));
					if (N > cur) N -= cur;
					else {
						if (num == 0 && i) p.fi = i;
						if (num != 0 && num != i) {
							p.se = i;
							if (p.fi > p.se) swap(p.fi, p.se);
						}
						
						num = num == 0 ? i : num;
						same = num == 0 || (num != 0 && num == i);
						ans += i + '0';
						break;
					}
				}
			}
			else {
				ll cur = func(k - 1, num, same);
				if (N > cur) {
					N -= cur;
					ans += p.se + '0';
				}
				else {
					ans += p.fi + '0';
				}
			}
		}
		
		int zp = -1;
		REP(i, ans.size()) if (ans[i] != '0') { zp = i; break; }
		ans = ans.substr(zp);
		
		if (debug) printf("@ ");
		cout << ans << endl;
	}
}



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

ll solve() {
    ll N, P, a, odd = 0;
    cin >> N >> P;
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        if ( a & 1 ) odd++;
    }
    ll ans = 0;
    if ( P == 0 ) {
        ll n1 = 1LL << (N-odd);
        ll n2 = 1LL;
        if ( odd > 0 ) n2 = 1LL << (odd-1);
        return n1 * n2;
    } else {
        if ( odd == 0 ) return 0;
        ll n1 = 1LL << (N-odd);
        ll n2 = 1LL;
        if ( odd > 0 ) n2 = 1LL << (odd-1);
        return n1 * n2;
    }
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

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


int n, m;
int k = 0;


int calc(vi v){
	/*rep(i, v.size()){
		printf("%2d ", v[i]);
	}
	cout << endl;*/
	if (v.size() == 1)return v[0];
	vi v2;
	rep(i, v.size() - 1){
		v2.pb(v[(m + i) % v.size()]);
	}
	return calc(v2);
}

int main(){
	while (cin >> n >> m){
		if (n == 0 && m == 0)break;
		vi v(n);
		rep(i, n){
			v[i] = i + 1;
		}
		cout << calc(v) << endl;
	}
}

Measured memory_bytes: 5944
/**
 * Created by hiramekun at 20:52 on 2019-08-24.
 */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}


template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */
ll factorial(ll n) {
    ll ans = 1;
    while (n > 1) {
        ans *= n;
        ans %= mod;
        n--;
    }
    return ans;
}


void solve() {
    ll n;
    cin >> n;
    string s;
    cin >> s;

    n *= 2;

    vector<bool> is_right(n);
    rep(i, n) {
        if (i % 2 == 0 && s[i] == 'W') is_right[i] = true;
        if (i % 2 == 1 && s[i] == 'B') is_right[i] = true;
    }
    ll ans = 1;
    ll left_sum = 0;
    rep(i, n) {
        if (is_right[i]) {
            if (left_sum == 0) {
                cout << 0 << '\n';
                return;
            }
            ans *= left_sum;
            ans %= mod;
            left_sum--;
        } else {
            left_sum++;
        }
    }
    if (left_sum > 0) cout << 0 << '\n';
    else cout << ans * factorial(n / 2) % mod << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<(int)N;i++)
int main()
{
  int N,M,a=0,x,y;
  cin>>N>>M;
  vector<int> used(3,0);
  rep(i,M)
  {
    cin>>x>>y;
    if(N>1&&x==1&&y==0){cout<<-1<<endl;return 0;}
    if(used.at(x-1)!=0&&used.at(x-1)!=y){cout<<-1<<endl;return 0;}
    if(used.at(x-1)==0)a+=pow(10,N-x)*y;
    used.at(x-1)=y;
  }
  if(N>1&&pow(10,N-1)>a)a+=pow(10,N-1);
  cout<<a<<endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

h = 0
for i in b:
    h += i


for i in range(n-1):
    if(a[i]==a[i+1]-1):
        h += c[a[i]-1]
    else:
        pass

print(h)

Measured memory_bytes: 38384
times = []
5.times { times << gets.to_i}
ceils = times.map do |time|
  if time % 10 != 0
    time += 10- time % 10
  else
    time
  end
end
lastdif = [times, ceils].transpose.map{|a| a.inject(:-) }.min
ans = ceils.inject(:+) + lastdif
puts ans

Measured memory_bytes: 1788