akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <sstream>
#include <math.h>
using namespace std;

const int N_MAX = 1000000;

int is_prime(int n){
  if(n==1) return 0;
  int new_n = sqrt(n);
  for(int i=2; i<=new_n; i++){
    if(n%i == 0) return 0;
    
  }
  return 1; 
}

int main(){
  int n;
  cin >> n;
  int x;
  int ans=0;
  for(int i=0; i<n; i++){
    cin >> x;
    ans += is_prime(x);
  }
  cout << ans << endl;
  return 0;
}



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

int main(){
    int N;
    cin>>N;
    vector<int>line1;
    vector<int>line2;
    int sum=0;
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        sum+=a;
        line1.push_back(sum);
    }
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        line2.push_back(a);
    }
    for(int i=N-2;i>=0;i--){
        line2[i]+=line2[i+1];
    }
    int max=0;
    for(int i=0;i<N;i++){
        if(max < line1[i]+line2[i])max=line1[i]+line2[i];
    }
    cout<<max<<endl;
    return 0;
}


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

int main() {
    int x;
    cin >> x;
    int ans = 10 - x / 200;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
while True:

    n,m = [int(x) for x in input().split()]
    if n == m == 0:
        break
    a = [int(x) for x in input().split()]

    ans = -1

    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            if ans < a[i]+a[j] and a[i]+a[j] <= m:
                ans = a[i]+a[j]

    if ans == -1:
        print("NONE")
    else:
        print(ans)



Measured memory_bytes: 5632
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
using namespace std;
typedef long long longlong;
typedef long long LL;
typedef pair<int, pair<int, int>> Trio;
typedef pair<int, int> Pair;

int main(void) {
	LL x, a, b;
	cin >> x >> a >> b;
	if (a >= b) {
		cout << "delicious" << endl;
	}
	else if (a + x >= b) {
		cout << "safe" << endl;
	}
	else {
		cout << "dangerous" << endl;
	}
	

	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

void solve() {
    int a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, k, ans = 0;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        int h;
        cin >> h;
        if(h >= k) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define scan(n)     scanf("%lld", &n);
#define print(n)    printf("%lld\n", n);
#define fd(n)       fixed<<setprecision(n)
#define MAX         1000000000000000000
#define MAXN        100005
#define LOG         19
#define mod         1000000007
using namespace std;
// good approach
// yes

// ll fun(ll n,ll w){
//     if(n<0){
//         return 0;
//     }
//     if(w>=we[n]){
//         return max(val[n]+fun(n-1,w-we[n]),fun(n-1,w));
//     }
//     else{
//         return fun(n-1,w);
//     }
// }

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w,i,j;
    cin>>n>>w;
    ll we[n+1],val[n+1];
    we[0]=0;
    val[0]=0;
    for(i=1;i<=n;i++){
        cin>>we[i]>>val[i];
    }
    // cout<<fun(n-1,w);
    ll dp[n+1][w+1];
    memset(dp,0,sizeof(dp));
    for(i=1;i<=n;i++){
        for(j=0;j<=w;j++){
            if(j-we[i]>=0){
                dp[i][j]=max(val[i]+dp[i-1][j-we[i]],dp[i-1][j]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][w];
}

Measured memory_bytes: 82392
def count(a,h,w):
    for i in range(h):
        if a[i][0]==0:
            a[i][0]=1
        else:
            break
    for i in range(1,w):
        if a[0][i]==0:
            a[0][i]=1
        else:
            break
    for i in range(1,h):
        for j in range(1,w):
            if a[i][j]==-1:
                continue
            if a[i-1][j]>0:
                a[i][j]=a[i][j]+a[i-1][j]
            if a[i][j-1]>0:
                a[i][j]=a[i][j]+a[i][j-1]
    if a[h-1][w-1]>0:
        return a[h-1][w-1]
    else:
        return 0

h,w = list(map(int,input().split()))
a = [list(input()) for _ in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j]==".":
            a[i][j] = 0
        else:
            a[i][j] = -1
print(count(a,h,w)%(10**9+7))

Measured memory_bytes: 208048
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL<<60;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  while(1){
  ll N,M;
  cin >> N >> M;
  if(N==0 && M==0){
    break;
  }
  ll ans = -1;
  vector<ll> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  for(int i=0; i<N ;i++){
    for(int j=i+1; j<N; j++){
      ll sum = A[i] + A[j];
      if(sum <= M){
        chmax(ans,sum);
      }
    }
  }
  if(ans == -1){
    cout << "NONE" << endl;
  }else{
    cout << ans << endl;
  }
  }
  return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int SZ = 1000100;
int dp[SZ][2];

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  vector<int> n(s.size());
  rep(i, n.size())
    n[i] = s[i]-'0';
  rep(i, SZ) rep(j, 2) dp[i][j] = INF;
  dp[0][0] = 0;
  dp[0][1] = 1;
  rep(i, n.size()) {
    chmin(dp[i+1][0], min(dp[i][0]+n[i], dp[i][1]+10-n[i]));
    chmin(dp[i+1][1], min(dp[i][0]+n[i]+1, dp[i][1]+10-(n[i]+1)));
  }
  cout << dp[n.size()][0] << endl;
  return 0;
}

Measured memory_bytes: 13084
#include<iostream>
using namespace std;
int N;
long A[1<<17];
const long LIM=1e18;
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		if(A[i]==0)
		{
			cout<<0<<endl;
			return 0;
		}
	}
	long now=1;
	for(int i=0;i<N;i++)
	{
		if(now>LIM/A[i])
		{
			cout<<-1<<endl;
			return 0;
		}
		now*=A[i];
	}
	if(now>LIM)now=-1;
	cout<<now<<endl;
}


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

const int MAX = 300001;

template<class M, class F = std::function<M(M, M)>>
class SegmentTree{
private:
  std::vector<M> data;
  F op;
  M e;
  int length;

public:
  SegmentTree(int n, const F op, const M& e) : op(op), e(e){
    length = 1;
    while(length < n) length <<= 1;
    data = std::vector<M>((length << 1) - 1, e);
  }

  void update(int index, const M& x){
    index += length - 1;
    data[index] = x;

    while(index){
      (--index) >>= 1;
      data[index] = op(data[(index << 1) + 1], data[(index << 1) + 2]);
    }
  }

  M query(int left, int right){
    M l = e, r = e;

    for(left += length - 1, right += length - 1; left < right; (--left) >>= 1, (--right) >>= 1){
      if(!(left & 1)) l = op(data[left++], l);
      if(!(right & 1)) r = op(data[--right], r);
    }

    return op(l, r);
  }
};

using namespace std;

int main(){
  int H, W, M;
  cin >> H >> W >> M;
  
  vector<pair<int, int>> targets(M);
  for(int i = 0; i < M; i++){
    int h, w;
    cin >> h >> w;
    targets[i] = {h, w};
  }
  sort(targets.begin(), targets.end());
  
  SegmentTree<int> segTree(W + 10, [](int a, int b){
    return max(a, b);
  }, 0);
  
  for(int i = 0; i < M; i++){
    segTree.update(targets[i].second, segTree.query(targets[i].second, targets[i].second + 1) + 1);
  }
  
  int max_exp = 0;
  int pos = 0;
  queue<int> q;
  for(int i = 1; i <= H; i++){
    while(pos < M && targets[pos].first == i){
      segTree.update(targets[pos].second, segTree.query(targets[pos].second, targets[pos].second + 1) - 1);
      q.push(targets[pos].second);
      ++pos;
    }
    
    max_exp = max(segTree.query(0, W + 1) + (int)q.size(), max_exp);
    
    while(q.size()){
      segTree.update(q.front(), segTree.query(q.front(), q.front() + 1) + 1);
      q.pop();
    }
  }
  
  cout << max_exp << endl;
  
  return 0;
}

Measured memory_bytes: 10912
#include<iostream>

using namespace std;

int main()
{
	int num = 0;
	int a[10000] = { };
	long int max = -1000000, min = 1000000, sum = 0;
	
	cin >> num;
	
	for(int i = 0; i < num; i++){
		cin >> a[i];
		
		if(max < a[i])
			max = a[i];
		if(min > a[i])
			min = a[i];
	
	    sum += a[i];
	}
	
	cout << min << " " << max << " " << sum << endl;
	
	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  string s;
  cin >> s;
  s[5] = ' ';
  s[13] = ' ';
  cout << s << endl;
}

Measured memory_bytes: 256
//-- Araz Jabrayilov --
//-- araz17 - zuna#1041 --

#include <bits/stdc++.h>

#define ll long long
#define endl '\n'

using namespace std;

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

    int n = 0;

    cin >> n;

    cout << 2 * 3.14159265359 * n << endl;

    return 0;
}



Measured memory_bytes: 3752
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll mod=1e9+7;
vector<ll> d(51);
vector<ll> memo(51);

ll rec(ll n,ll x){
    if(n==0) return x;
    if(x<=1) return 0;
    if(2<=x && x<=d[n-1]+1) return rec(n-1,x-1);
    if(d[n-1]+2<=x && x<=2*d[n-1]+2) return rec(n-1,x-d[n-1]-2)+memo[n-1]+1;
    if(x==d[n]) return memo[n];
}
int main()
{
    ll n,x;
    cin >> n >> x;
    
    d[0]=1;
    for(ll i=1;i<51;i++){
        d[i]=d[i-1]*2+3;
    }
    memo[0]=1;
    for(ll i=1;i<51;i++){
        memo[i]=2*memo[i-1]+1;
    }
    cout << rec(n,x) << endl;
    return 0;
} 


Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {
r#""# => r#""#,
}

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        a: usize,
        b: usize,
    }

    if a == b {
        "Yes"
    } else {
        "No"
    }.to_string()
}

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

vector<int> d;

int main(){
  int N;
  int x;
  cin >>N;
  for(int i=0; i<N; i++){
    cin >> x;
    d.push_back(x);
  }
  sort(d.begin(),d.end());
  cout << d[N/2]-d[N/2-1] << endl;
  return 0;
}

Measured memory_bytes: 892
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace abc110_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = ReadLine().Split().Select(int.Parse).ToArray();
            int x = input[2];
            int y = input[3];

            int[] tmp1 = ReadLine().Split().Select(int.Parse).ToArray();
            int[] tmp2 = ReadLine().Split().Select(int.Parse).ToArray();

            Array.Sort(tmp1);
            Array.Sort(tmp2);

            for (int i = x+1; i <= y; i++)
            {
                if(i>tmp1[tmp1.Length-1] && i<=tmp2[0]){
                    WriteLine("No War");
                    return;
                }
            }
            WriteLine("War");
        }
    }
}

Measured memory_bytes: 13396
#include <stdio.h> 
 
 int main(){ 
 int a, b, c; 
     int tmp; 
     scanf("%d %d %d", &a, &b, &c); 
     if(a>b){ 
         tmp=a; 
         a=b; 
         b=tmp; 
     } 
     if(b>c){ 
         tmp=b; 
         b=c; 
         c=tmp; 
     } 
     if(a>b){ 
         tmp=a; 
         a=b; 
         b=tmp; 
     } 
     printf("%d %d %d\n", a, b, c); 
     return 0; 
}

Measured memory_bytes: 596
#include <cstdio>


int main(){
    int K,A,B;
    scanf("%d%d%d",&K,&A,&B);
    bool can=false;
    for(int i=A;i<=B;i++) {
        if (i%K==0) {
            can=true;
            break;
        }
    }

    if (can) puts("OK"); else puts("NG");

    return 0;
}

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

int N, M, pref[305][305], cnt[305], curpref[305];
set< pair<int, int> > S;
vector<int> peoples[305];
bool removed[305];

int main() {
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) scanf("%d", &pref[i][j]);
	for (int i = 0; i < N; i++) {
		cnt[pref[i][0]]++;
		peoples[pref[i][0]].push_back(i);
	}
	for (int i = 1; i <= M; i++) {
		S.insert(make_pair(cnt[i], i));
		//printf("added %d %d\n", cnt[i], i);
	}
	int ans = 1000000000;
	for (int i = 0; i < M - 1; i++) {
		ans = min(ans, S.rbegin()->first);
		int rem = S.rbegin()->second;
		removed[rem] = 1;
		//printf("removing %d\n", rem);
		S.erase(--S.end());
		for (int j = 0; j < peoples[rem].size(); j++) {
			int person = peoples[rem][j];
			while (removed[pref[person][curpref[person]]]) curpref[person]++;
			peoples[pref[person][curpref[person]]].push_back(person);
			//printf("person %d assigned to %d\n", person, pref[person][curpref[person]]);
			S.erase(S.find(make_pair(peoples[pref[person][curpref[person]]].size() - 1, pref[person][curpref[person]])));
			S.insert(make_pair(peoples[pref[person][curpref[person]]].size(), pref[person][curpref[person]]));
		}
	}
	ans = min(ans, S.rbegin()->first);
	printf("%d\n", ans);
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

void YesNo(bool x) {
    cout << (x ? "Yes" : "No") << endl;
}

int main() {
    int a, b;
    cin >> a >> b;
    if (a <= 9 && b <= 9)cout << a * b << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_B() {}


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    vi a(N); REP(i, N) cin >> a[i];

    sort(a.begin(), a.end(), greater<int>());

    int alice = 0, bob = 0;
    REP(i,N){
        if (i % 2 == 0) alice += a[i];
        else bob += a[i];
    }

    int ans = alice - bob;
    cout << ans << endl;  

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define N (1000 + 10)

#define max(a, b) (a < b ? b : a)

int dp[N][N];
char a[N],b[N];

int LCS(void)
{
  const int a_size = strlen(a) - 1;
  const int b_size = strlen(b) - 1;
  int i, j;

  memset(dp,0,sizeof(dp));

  for (i = 1 ; i < a_size + 1 ; ++i) {
    for (j = 1 ; j < b_size + 1 ; ++j) {
      int mx = max(dp[i][j - 1], dp[i - 1][j]);
      if (a[i - 1] == b[j - 1]) {
        mx = max(mx, dp[i - 1][j - 1] + 1);
      }
      dp[i][j] = mx;
    }
  }

  return dp[a_size][b_size];
}

int main(void)
{
  int n, i;
  scanf("%d\n",&n);
  for ( i = 0 ; i < n ; i++ ){
    fgets(a,N,stdin);
    fgets(b,N,stdin);
    printf("%d\n",LCS());
  }
  return 0;
}


Measured memory_bytes: 5700
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n = ni()
i = 1
ans = 10*10
while i*i <= n:
    if n%i == 0:
        f = max(len(str(i)), len(str(n//i)))        
        ans = min(ans, f)
        
    i += 1
    
print(ans)

Measured memory_bytes: 3064
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();

        int stNum = 0;
        int sNum = 0;
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == 'S') {
                sNum++;
            } else {
                if (sNum > 0) {
                    sNum--;
                    stNum++;
                }
            }
        }
        out.println(str.length() - stNum * 2);
    }
}

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

ll gcd(ll a, ll b) {
  if (b==0) return a;
  return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  return a/gcd(a,b)*b;
}

int main() {
  int n;
  cin>>n;
  vector<ll> T(n);
  rep(i, n) cin>>T[i];

  ll x=T[0];
  rep(i, n) x = lcm(x, T[i]);
  cout << x << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int i,j,n,a[210][5],b[110],ans[210];
scanf("%d\n",&n);
for(i=0;i<n;i++){
for(j=0;j<3;j++){
scanf("%d",&a[i][j]);
}
scanf("\n");
}
for(i=0;i<205;i++){
ans[i]=0;
}
for(i=0;i<3;i++){
for(j=0;j<105;j++){
b[j]=0;
}
for(j=0;j<n;j++){
b[a[j][i]]++;
}
for(j=0;j<n;j++){
if(b[a[j][i]]==1){
ans[j]=ans[j]+a[j][i];
}
}
}
for(i=0;i<n;i++){
printf("%d\n",ans[i]);
}
return 0;
}


Measured memory_bytes: 2092
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
vector<int>v[5];
bool visit[5];
inline bool check()
{
	if(visit[0]&&visit[1]&&visit[2]&&visit[3])
		return true;
	else
		return false;
}
bool dfs(int now)
{
	if(check())return true;
	for(int i=0;i<v[now].size();i++)
	{
		int to=v[now][i];
		if(!visit[to])
		{
			visit[to]=true;
			bool judge=dfs(to);
			visit[to]=false;
			if(judge)return true;
		}
	}
	return false;
}
int main()
{
	for(int i=0;i<3;i++)
	{
		v[4].pb(i);
		int a,b;
		cin>>a>>b;
		a--,b--;
		v[a].pb(b);
		v[b].pb(a);
	}
	v[4].pb(3);
	if(dfs(4))
		cout<<"YES\n";
	else
		cout<<"NO\n";
	return 0;
}

Measured memory_bytes: 256
D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
  s.append(list(map(int, input().split())))
  
sdictlist = []
sdictlistsorted = []
for i in range(D):
  onedict = {}
  for j in range(26):
    onedict[j] = s[i][j]
  sdictlist.append(onedict)
  onesorteddict = sorted(onedict.items(), key=lambda x:x[1], reverse=True)
  sdictlistsorted.append(onesorteddict)

cignorelen = 3
csorted = sorted(c)
csorted = csorted[:cignorelen]
ignorelist = []
for i in range(26):
  if(c[i] in csorted):
    ignorelist.append(i+1)
    
lenpastmax = 16 #26まで設定できる
#26 -> 145419
#25 -> 18657778
#24 -> 40796238
#23 -> 54875726
#22 -> 63195752
#21 -> 66843963
#20 -> 67734290, ign=5 -> 3733319, ign=3 -> 41602078
#18                                ign=3 -> 50909415
pastlist = []
for i in range(D):
  j = 0
  while(sdictlistsorted[i][j][0] in pastlist or sdictlistsorted[i][j][0]+1 in ignorelist):
    j += 1
  print(sdictlistsorted[i][j][0]+1)
  pastlist.append(sdictlistsorted[i][j][0])
  if(len(pastlist)==lenpastmax):
    pastlist.pop(0)

Measured memory_bytes: 10376
from collections import defaultdict

def main():
    n = int(input())
    d = defaultdict(int)
    res = 0
    for a in input().split():
        aa = int(a)
        d[int(aa)] += 1
        res += aa

    nq = int(input())
    for q in range(nq): 
        b, c = [int(i) for i in input().split()]
        res += (c - b) * d[b]
        d[c] += d[b]
        d[b] = 0
        print(res)

if __name__ == '__main__':
    main()



Measured memory_bytes: 22152
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (ll i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (register int i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((int)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long double ldb ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int maxn = 3e3 + 100 ;
const int inf = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int mod = 1e9 + 7 ;
const db eps = 1e-10 ;
template <class T = int> T read()
{
	T f = 1, a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	return a * f ;
}

ll n, q;

ll a[maxn], x[maxn], y[maxn];

ll f[maxn][maxn], ans;

ll inv = 5e8 + 4;

signed main()
{
	scanf("%lld %lld", &n, &q);
	rep(i, 1, n) scanf("%lld", &a[i]);
	rep(i, 1, q) scanf("%lld %lld", &x[i], &y[i]);
	rep(i, 1, n) rep(j, 1, n) f[i][j] = a[i] > a[j];
	rep(i, 1, q)
	{
		ll u = x[i], v = y[i];
		f[v][u] = f[u][v] = inv * (f[u][v] + f[v][u]) % mod;
		rep(j, 1, n)
		{
			if(j == u || j == v)  continue;
			f[v][j] = f[u][j] = inv * (f[u][j] + f[v][j]) % mod;
			f[j][v] = f[j][u] = inv * (f[j][u] + f[j][v]) % mod;
		}
	}
	rep(i, 1, n) rep(j, i + 1, n) (ans += f[i][j]) %= mod;
	rep(i, 1, q) (ans *= 2) %= mod;
	printf("%lld\n", ans);
	return 0;
}

/*

*/

Measured memory_bytes: 73984
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
A = []
B = []

i = 1
try:
    while True:
        a = int(inputs[i])
        A.append(a)
        B.append([tuple(map(int, inputs[j].split())) for j in range(i+1, i+a+1)])
        i += a+1        
except IndexError:
    pass

C = set()
for i in range(2 ** n):
    flag = True
    for j in range(n):
        if((i >> j) & 1):
            flag &= all((i >> (x-1)) & 1 == y for x, y in B[j])
    if flag:
        C.add(i)

print(max([sum([int(bit == '1') for bit in str(bin(c))]) for c in C]))

Measured memory_bytes: 6280
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



// 各連結成分のサイズが例えば2,3,5のとき答えは8*2 + 5*3 = 31
// 一番最初の答えは必ずn(n-1)/2
// サイズa,bの連結成分同士が連結されるとき答えはabだけ減る

struct UF {
	vector<int> p;
	UF(int n) : p(n, -1) {};
	bool unite(int u, int v) {
		if ((u = find(u)) == (v = find(v))) return false;
		if (p[u] > p[v]) swap(u, v);
		p[u] += p[v]; p[v] = u;
		return true;
	}
	bool same(int u, int v) { return find(u) == find(v); }
	int find(int u) { return p[u] < 0 ? u : p[u] = find(p[u]); }
	int usize(int u) { return -p[find(u)]; }
};

int n, m, a[100100], b[100100], s;
UF uf(100100);
vector<int> res;

signed main() {
	cin >> n >> m;
	rep(i,m) {
		cin >> a[i] >> b[i];
		a[i]--, b[i]--;
	}
	reverse(a,a+m), reverse(b,b+m);
	s = n*(n-1)/2;
	res.push_back(s);
	rep(i,m-1) {
		if (!uf.same(a[i],b[i])) s -= uf.usize(a[i]) * uf.usize(b[i]);
		uf.unite(a[i], b[i]);
		res.push_back(s);
	}
	reverse(all(res));
	each(i,res) cout << i << endl;
}

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std; 
//using Graph = vector< <vector<int> >;
using Graph = vector <vector<int> >;
int main(){
    int n; cin >> n;
    Graph G(n);
    for(int i=1;i<n;++i){
        int a; cin >> a;
        a--;
        G[a].push_back(i);
    }
    for(int i=0;i<n;++i){
        cout << G[i].size() << endl;
    }
    return 0;
}

Measured memory_bytes: 13924
from collections import deque
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
ship = [[] for i in range(N)]
for i in range(M):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  ship[a].append(b)
visited = []
for i in ship[0]:
  visited.append(i)
  for j in ship[i]:
    visited.append(j)

if N-1 in visited:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Measured memory_bytes: 30320
S = int(input())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
N = 3*10**3
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0

for i in range(S//3):
    group = i+1
    SUM = S-group*3
    ans += cmb(SUM+i,i,mod)
    
ans %= mod
    
print(ans)

Measured memory_bytes: 9428
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cassert>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1LL<<63)
#define MAX 70
#define deb(a) cout << #a << " " << a << endl

using namespace std;

typedef long long ll;

ll N,M;
ll C[MAX][MAX];

void makeC()
{
  C[0][0] = 1;
  rep(i,MAX-1)rep(j,i+1)
    {
      C[i+1][j] += C[i][j];
      if(j+1<MAX)C[i+1][j+1] += C[i][j];
    }
}

void compute()
{
  M--;
  if(M == 0)
    {
      cout << string(N,'0') << endl;
      return;
    }
  string ans = "";
  int NumberOfBits = 1;
  ll sum = 0;
  while(true)
    {
      sum += C[N][NumberOfBits]; 
      if(sum >= M)break;
      NumberOfBits++;
    }
  sum -= C[N][NumberOfBits];
  sum = M - sum;
  //deb(sum);
  //deb(NumberOfBits);

  for(int i=N;i>=1;i--)
    {
      ll cost = sum - C[i-1][NumberOfBits];
      if(cost >  0)
	{
	  ans += "1";
	  sum -= C[i-1][NumberOfBits];
	  NumberOfBits--;
	}
      else
	{
	  ans += "0";
	}
      //cout << "cur : " << i << " " << ans << " sum = " << sum << " NumberOfBits = " << NumberOfBits << endl;
    }

  cout << ans << endl;
}

int main()
{
  makeC();

   while(cin >> N >> M,N|M)compute();

  return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){
    
    ll N;cin>>N;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    
    bool ok=true;
    ll ans=0;
    
    while(ok){
        ok=false;
        ll cnt=0;
        vector<ll> B(N,0);
        for(int i=0;i<N;i++){
            cnt+=A[i]/N;
            B[i]=A[i]/N;
            
            A[i]=A[i]%N;
        }
        
        for(int i=0;i<N;i++){
            A[i]+=(cnt-B[i]);
            if(A[i]>=N) ok=true;
        }
        
        ans+=cnt;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(M)]
es = [[] for _ in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

class UnionFind:
    def __init__(self,N):
        self.parent = [i for i in range(N)]
        self.rank = [0] * N
        self.count = 0
    def root(self,a):
        if self.parent[a] == a:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]
    def is_same(self,a,b):
        return self.root(a) == self.root(b)
    def unite(self,a,b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return
        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
        else:
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
        self.count += 1

ans = 0
for a,b in AB:
    a,b = a-1,b-1
    uf = UnionFind(N)
    for u,v in AB:
        u,v = u-1,v-1
        if u==a and v==b: continue
        if uf.is_same(u,v): continue
        uf.unite(u,v)
    if not uf.is_same(a,b):
        ans += 1
print(ans)

Measured memory_bytes: 3064
N, K = map(int, input().split())
X = list(map(int, input().split()))
ans = 10**9
for i in range(N-K+1):
    l = i
    r = i+K-1
    ans = min(ans, abs(X[r])+abs(X[l]-X[r]), abs(X[l])+abs(X[r]-X[l]))
print(ans)


Measured memory_bytes: 14384
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
#define INF 1000000000000000000
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) { // nCr の計算
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

int main() {
	int h, a;
	cin >> h >> a;
	double ans = (h + (a-1)) / a;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//Equal Cut
//by ACMonster

#include<bits/stdc++.h>

#define N 200000+5
#define INF 200000000000000

using namespace std;

int n,i,j,k,a[N];
long long ans,pre[N],s1,s2,s3,s4;

int main(){
	scanf("%d",&n);
	for (i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		pre[i]=pre[i-1]+a[i];
	}
	ans=INF;	
	for (i=1,j=2,k=3;j<=n-2;j++) {
		while (abs(pre[j]-2*pre[i+1])<abs(pre[j]-2*pre[i])) i++;
		while (abs(pre[n]+pre[j]-2*pre[k+1])<abs(pre[n]+pre[j]-2*pre[k])) k++;
		s1=pre[i];
		s2=pre[j]-pre[i];
		s3=pre[k]-pre[j];
		s4=pre[n]-pre[k];	
		ans=min(ans,max( max(abs(s2-s3),max(abs(s2-s4),abs(s3-s4))),max( abs(s1-s3) ,max(abs(s1-s4),abs(s1-s2) ) ) ) );
	}
	printf("%lld",ans);
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pb push_back

using namespace std;

int main() {
	//freopen("0511.inp", "r", stdin);
	bool b[31]; memset(b, false, sizeof(b));
	loop(i, 0, 28) {
		int n; cin >> n;
		b[n] = true;
	}
	loop(i, 1, 31) if (!b[i]) cout << i << endl;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double w,h,x,y;
    cin >> w >> h >> x >> y;
    int ans;
    if(x == w/2 && y == h/2){
        ans = 1;
    }else{
        ans = 0;
    }
    double a = w*(h/2);
    cout << a << " " << ans << endl;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
L = [int(v) for v in input().split()]

s = {}
for i in reversed(range(N)):
    c = i + 1

    p = 0
    for v in range(c, N + 1, c):
        if s.get(v) == 1:
            p += 1

    if p % 2 != L[i]:
        s[c] = 1

t = list(s.keys())

print(len(t))
print(" ".join(map(str, t)))


Measured memory_bytes: 24556
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


int main(){
    int n;
    cin>>n;
    vector<P>job(n);
    rep(i,n){
        int a,b;
        cin>>a>>b;
        if(a>b){
            cout<<"No"<<endl;
            return 0;
        }
        job[i]=P(b,a);
    }
    sort(job.begin(),job.end());
    int time=0;
    bool ok=true;
    rep(i,n){
        time+=job[i].second;
        if(job[i].first<time){
            ok=false;
        }
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#define mp(x,y) make_pair(x,y)
using namespace std;

typedef pair<int,int> pi;

const int N=100005;

int n,f[N];
set<int> se[N];
map<pi,int> ma;
queue<pi> que;

int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int find(int x)
{
    if (f[x]==x) return x;
    else return f[x]=find(f[x]);
}

int main()
{
    n=read();
    for (int i=1;i<=n*2-2;i++)
    {
        int x=read(),y=read();
        se[x].insert(y);se[y].insert(x);
        ma[mp(x,y)]++;ma[mp(y,x)]++;
        if (ma[mp(x,y)]==2) que.push(mp(x,y));
    }
    for (int i=1;i<=n;i++) f[i]=i;
    set<int>::iterator it;
    while (!que.empty())
    {
        int x=que.front().first,y=que.front().second;que.pop();
        x=find(x);y=find(y);
        se[x].erase(y);se[y].erase(x);
        if (se[x].size()<se[y].size()) swap(x,y);
        for (it=se[y].begin();it!=se[y].end();it++)
        {
            int to=(*it);
            se[to].erase(y);se[to].insert(x);
            ma[mp(to,x)]++;ma[mp(x,to)]++;
            if (ma[mp(to,x)]==2) que.push(mp(to,x));
            se[x].insert(to);
        }
        f[y]=x;
        se[y].clear();
    }
    int s=0;
    for (int i=1;i<=n;i++) s+=f[i]==i;
    if (s==1) puts("YES");
    else puts("NO");
    return 0;
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define llong long long
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

void solve()
{
  string ans = "";

  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  int dx = tx - sx;
  int dy = ty - sy;

  REP(i,dy) ans.push_back('U');
  REP(i,dx) ans.push_back('R');
  REP(i,dy) ans.push_back('D');
  REP(i,dx) ans.push_back('L');

  ans.push_back('L');
  REP(i,dy+1) ans.push_back('U');
  REP(i,dx+1) ans.push_back('R');
  ans.push_back('D');
  ans.push_back('R');
  REP(i,dy+1) ans.push_back('D');
  REP(i,dx+1) ans.push_back('L');
  ans.push_back('U');

  cout << ans << endl;
}

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


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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  char before_c = ' ';
  int count = 0;
  for(int i=0;i<N;i++){
    if(before_c != S[i]){
      before_c = S[i];
      count++;
    }
  }

  cout << count << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;
long long le, ri;

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int solve(int a, int b) {
    if (a > b)
        return gcd(a, b);
    else
        return gcd(b, a);
}

void sans(int z, int m) {
    int temp = solve(z, m);
    z /= temp;
    m /= temp;
    long long tempz , tempm;
    long long cs = max(le/z,ri/m);
    if(cs==0)
        cs=1;
    for (long long i = cs; i < 1e18; ++i) {
        tempz = z * i;
        tempm = m * i;
        if (tempz >= le && tempm >= ri) {
            break;
        }
    }
    le = tempz;
    ri = tempm;
}

int main() {
    int n;
    while (cin >> n) {
        int a, b;
        for (int i = 0; i < n; ++i) {
            cin >> a >> b;
            sans(a, b);
        }
        cout << le+ri << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    int n; cin >> n;
    std::vector<int> v(n); rep(i,n)  cin >> v[i];

    int x = 0;

    rep(i,n) for(int j=i+1; j<n; ++j){
        x += v[i]*v[j];
    }
    cout << x << endl;

    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int H, W;
string S[105];

bool solve(){
  
  map<char,int> memo;
  rep(i,H){
    rep(j,W){
      memo[S[i][j]]++;
    }
  }

  map<int,int> memo2;
  FOR(it,memo){
    int num = it->second;
    while(num-4 >= 0){
      memo2[4]++;
      num -= 4;
    }
    while(num-2 >= 0){
      memo2[2]++;
      num -= 2;
    }
    if(num > 0) memo2[num]++;
  }
  
  if(H%2==0 && W%2==0){
    int x = (H/2)*(W/2);
    if(memo2[4] == x) return true;
    return false;
  }
  if(H%2==0 && W%2==1){
    int x = (H/2)*((W-1)/2);
    if(memo2[4] >= x){
      memo2[2] += (memo2[4]-x)*2;
      if(memo2[2] == H/2) return true;
    }
    return false;
  }
  if(H%2==1 && W%2==0){
    int x = ((H-1)/2)*(W/2);
    if(memo2[4] >= x){
      memo2[2] += (memo2[4]-x)*2;
      if(memo2[2] == W/2) return true;
    }
    return false;
  }
  if(H%2==1 && W%2==1){
    int x = ((H-1)/2)*((W-1)/2);
    if(memo2[4] >= x){
      memo2[2] += (memo2[4]-x)*2;
      int y = (H-1)/2 + (W-1)/2;
      if(memo2[2] == y && memo2[1] == 1) return true;
    }
    return false;    
  }
  
  return false;
}


int main(){
  cin >> H >> W;
  rep(i,H){
    cin >> S[i];
  }

  if(solve()){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
    
  return 0;
}



Measured memory_bytes: 256