akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef vector<int> vi;

int main()
{
	int n;
	while(cin >> n, n){
		vector<string> field(n + 1);
		vector<vi> table(n + 1, vi(n + 1));
		int x, y, i, lim;
		field[0] = "*";
		for(int x=0;x<n;x++)
			field[0] += "*";
		for(y = 1; y <= n; y++){
			string line;
			cin >> line;
			field[y] = "*" + line;
		}
		
		for(y = 0; y <= n; y++)
			for(x = 0; x <= n; x++){
				if(y == 0 && x == 0)
					table[y][x] = field[y][x] == '*';
				else if(y == 0)
					table[y][x] = table[y][x-1] + (field[y][x] == '*');
				else if(x == 0)
					table[y][x] = table[y-1][x] + (field[y][x] == '*');
				else
					table[y][x] = table[y][x-1] + table[y-1][x] - table[y-1][x-1] + (field[y][x] == '*');
			}
		
		int res = 0;
		for(y = 0; y <= n; y++){
			for(x = 0; x <= n; x++){
				lim = min(n-y, n-x) + 1;
				for(int i=1;i<lim;i++){
					if(table[y + i][x + i] - table[y][x + i] - table[y + i][x] + table[y][x] == 0)
						res=max(res, i);
					else break;
				}
			}
		}
		cout << res << endl;
	}
}

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

int main() {
  int x, a, b, c, d;
  cin >> x;
  a = x / 1000;
  b = (x - a * 1000) / 100;
  c = (x - a * 1000 - b * 100) / 10;
  d = x - a * 1000 - b * 100 - c * 10;
  if (a + b + c + d == 7) {
    cout << a << '+' << b << '+' << c << '+' << d << "=7"
         << "\n";
  } else if (a - b + c + d == 7) {
    cout << a << '-' << b << '+' << c << '+' << d << "=7"
         << "\n";
  } else if (a + b - c + d == 7) {
    cout << a << '+' << b << '-' << c << '+' << d << "=7"
         << "\n";
  } else if (a + b + c - d == 7) {
    cout << a << '+' << b << '+' << c << '-' << d << "=7"
         << "\n";
  } else if (a + b - c - d == 7) {
    cout << a << '+' << b << '-' << c << '-' << d << "=7"
         << "\n";
  } else if (a - b + c - d == 7) {
    cout << a << '-' << b << '+' << c << '-' << d << "=7"
         << "\n";
  } else if (a - b - c + d == 7) {
    cout << a << '-' << b << '-' << c << '+' << d << "=7"
         << "\n";
  } else if (a - b - c - d == 7) {
    cout << a << '-' << b << '-' << c << '-' << d << "=7"
         << "\n";
  } else {
    cout << "impossible"
         << "\n";
  }
  return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;

int main(){
    ll N, K;
    cin >> N >> K;
    long double p;
    long double answer = 0;
    for(int i=1; i<=N; i++){
        int point = i;
        p = 1.0/(N*1.0);
        for(int j=1; j<50; j++){
            if(point >= K){
                answer += p;
                break;
            }
            point *= 2;
            p *= 0.5;
        }
    }
    
    DCOUT(answer,12);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int N, A[100], V;

int count(int first, int last){
    if(first > last){return 0;}

    int mid = (first + last) / 2;
    if(A[mid] == V){
        return 1;
    }else if(A[mid] > V){
        return 1 + count(first, mid-1);
    }else{
        return 1 + count(mid+1, last);
    }
}

int main(){
    while(std::cin >> N, N){
        REP(i, N){
            std::cin >> A[i];
        }

        std::cin >> V;
        std::cout << count(0, N-1) << std::endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 3005;

int r, c, k, a[sz][sz];
ll dp[sz][sz][4];

ll fnc(int x, int y, int d) {
   if(x == r && y == c) {
      if(d) return a[x][y];
      return 0;
   }
   ll &w = dp[x][y][d];
   if(w < 0) {
      w = 0;
      if(y < c) w = max(w, fnc(x, y+1, d));
      if(x < r) w = max(w, fnc(x+1, y, 3));
      if(d && a[x][y]) {
         if(y < c) w = max(w, a[x][y] + fnc(x, y+1, d-1));
         if(x < r) w = max(w, a[x][y] + fnc(x+1, y, 3));
      }
   }
   return w;
}

int main() {
   cin >> r >> c >> k;
   while(k--) {
      int x, y, v;
      scanf("%d %d %d", &x, &y, &v);
      a[x][y] = v;
   }
   memset(dp, -1, sizeof(dp));
   cout << fnc(1, 1, 3) << endl;
}


Measured memory_bytes: 321616
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<ll, ll> p;
 
#define MOD 1000000007
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

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

    while(a >= b) {
        b *= 2;
        k--;
    }

    while(b >= c) {
        c *= 2;
        k--;
    }

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

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(v) for (auto itr = v.begin(), itr != v.end(); ++itr)
#define LB(v, x) lower_bound(v.begin(), v.end(), x) - v.begin()
#define UB(v, x) upper_bound(v.begin(), v.end(), x) - v.begin()
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int R;
    cin >> R;
    cout << fixed << setprecision(10) << 2 * R * 3.1415926535 << endl;

    return 0;
}


Measured memory_bytes: 3800
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

void frip(int y, int x, int map[10][10]){
	if(y < 0 || x < 0 || y >= 10 || x >= 10){
		return;
	}else{
		map[y][x] = !map[y][x];
	}
}

void frips(int y, int x, int map[10][10]){
	frip(y - 1, x, map);
	frip(y + 1, x, map);
	frip(y, x, map);
	frip(y, x - 1, map);
	frip(y, x + 1, map);
}

int main(){
	
	int n;
	
	int origin[10][10];
	
	int f_point[10][10];
	
	int map[10][10];
	
	bool checker;
	
	cin >> n;
	
	int N = 10;

	for(int loop = 0; loop < n; loop++){
		
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				cin >> origin[i][j];
			}
		}
		
		for(int i = 0; i < (1 << N); i++){
			
			for(int x = 0; x < N; x++){
				for(int y = 0; y < N; y++){
					map[y][x] = origin[y][x];
					f_point[y][x] = 0;
				}
			}
			
			for (int x = 0; x < N; x++){
				if((i & (1 << (N - x - 1))) != 0){
					frips(0, x, map);
					f_point[0][x] = 1;
				}else{
				}
			}
			
			for(int y = 1; y < N; y++){
				for(int x = 0; x < N; x++){
					if(map[y - 1][x]){
						frips(y, x, map);
						f_point[y][x] = 1;
					}
				}
			}
			
			checker = true;
			
			for(int x = 0; x < N; x++){
				if(map[N - 1][x]){
					checker = false;
					break;
				}
			}
			
			if(checker){
				for(int y = 0; y < N; y++){
					if(f_point[y][0]){
						printf("1");
					}else{
						printf("0");
					}
					for(int x = 1; x < N; x++){
						if(f_point[y][x]){
							printf(" 1");
						}else{
							printf(" 0");
						}
					}
					printf("\n");
				}
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1132
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
typedef pair<int,int> P;
 
int main(){
  int n, m, q;
  cin >> n >> m;
  vector<int> g[n];
  rep(i,m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  cin >> q;
  vector<int> v(q), d(q), c(q);
  rep(i,q) {
    cin >> v[i] >> d[i] >> c[i];
    v[i]--;
  }
  reverse(v.begin(),v.end());
  reverse(d.begin(),d.end());
  reverse(c.begin(),c.end());
  
  vector<int> color(n,0);
  vector<int> dist(n,-1);
 
  rep(i,q){
    queue<P> que;
    que.push(P(v[i],d[i]));
    while(!que.empty()){
      P p = que.front();
      que.pop();
      if(color[p.first] == 0) color[p.first] = c[i];
      dist[p.first] = p.second;
      rep(j,g[p.first].size()){
        if(p.second-1 > dist[g[p.first][j]]) {
          que.push(P(g[p.first][j],p.second-1));
        }
      }
    }
  }
  rep(i,n) cout << color[i] << endl;
  return 0;
}

Measured memory_bytes: 8912
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())

    sunuke = [0] * n
    for _ in range(k):
        d = int(input())
        A = list(map(int, input().split()))
        for i in range(d):
            sunuke[A[i] - 1] += 1

    res = 0
    for i in sunuke:
        if i == 0:
            res += 1

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9200
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

#[allow(unused_macros)]
macro_rules! debug {
    ($var:expr) => {
        match &$var { v => eprintln!(concat!(stringify!($var), "={:?}"), v) }
    };
    ($var:expr, $($vars:expr),*) => {
        match &$var { v => eprint!(concat!(stringify!($var), "={:?} "), v) }
        debug!($($vars),*);
    };
}

fn main() {
    let n: usize = input();
    let m: i64 = input();
    let a: Vec<i64> = (0..n)
        .map(|_| {
            let a: i64 = input();
            a % m
        })
        .collect();

    let mut sum = vec![0; n + 1];
    for i in 0..n {
        sum[i + 1] = sum[i] + a[i];
        if sum[i + 1] >= m {
            sum[i + 1] -= m;
        }
    }

    let mut mp = std::collections::HashMap::new();
    let mut ans = 0i64;
    for i in 0..n + 1 {
        let e = mp.entry(sum[i]).or_insert(0);
        ans += *e;
        *e += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 14588
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  ll n,ans=0; cin>>n;
  for(ll i=1;i<=n;i++){
    if(i%3!=0 && i%5!=0){
      ans+=i;
    }
  }
  cout<<ans;
}


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

int main() {
  ll n,k,sum=0;
  cin>>n>>k;
  vector<ll> h;
  for(ll i=0; i<n; i++) {
  	ll x;
    cin>>x;
    h.push_back(x);
    sum += x;
  }
  sort(h.begin(),h.end());
  ll i=n-1;
  while(k>0) {
  	sum -= h[i];
    i--;
    k--;
    if(sum == 0) break;
  }
  cout << sum << endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
        a[i]--;
    }
    ll cnt=0;
    rep(i,n-1){
        if(a[i]==a[i+1]){
            cnt++;
            a[i+1]=-1;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)turn idx;
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

int main() {
  int a;
  string s;
  cin >> a;
  cin >> s;
  if (a >= 3200) {
    cout << s << endl;
  } else {
    cout << "red" << endl;
  }
};


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
using namespace std;

int main()
{
	double v = 0;
	double n = 0;
	double k = 0;
	double a, b;

	while (scanf("%lf,%lf", &a, &b) != -1)
	{
		v += a * b;
		n += b;
		k++;
	}
	printf("%d\n%d\n", (int)round(v), (int)round(n / k));

	return 0;
}

Measured memory_bytes: 1068
#include<stdio.h>

main(){
	int S, h, m, s;
	
	scanf("%d", &S);
	
	h = S/3600;
	m = S%3600/60;
	s = S%60;
	
	printf("%d:%d:%d\n", h, m, s);
	
	return 0;
}

Measured memory_bytes: 592
s = int(input())
cnt = 0
cnt4 = 0

if s == 1 or s == 2:
    print(4)
    exit()

while cnt4 < 2:
    cnt += 1
    if s == 4:
        cnt4 += 1
    if s % 2 == 0:
        s = s // 2
    else:
        s = 3 * s + 1
print(cnt)


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

const int MaxNum = 44;
int FibonacchiMemo[MaxNum + 1];
const int NullMemo = -1;

int fibonacci(int n) {
  if(FibonacchiMemo[n] != NullMemo) {
    return FibonacchiMemo[n];
  }

  int output;
  if (n == 0 || n == 1) {
    output = 1;
  } else {
    output = fibonacci(n - 1) + fibonacci(n - 2);
  }
  FibonacchiMemo[n] = output;
  return output;
}

void init_memo() {
  for(int i = 0; i <= MaxNum; i++) {
    FibonacchiMemo[i] = NullMemo;
  }
}

int main() {
  int n;
  init_memo();

  cin >> n;

  cout << fibonacci(n) << endl;
}



Measured memory_bytes: 3084
#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) begin(v),end(v)
#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; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	ll N, A, B;
	cin >> N >> A >> B;
	ll C = A + B;
	
	ll ans = N / C * A;
	N %= C;
	ans += min(N, A);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast", "unroll-loops")

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

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using ll = long long;
using ld = double;
using pii = pair<int, int>;
using uint = unsigned int;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
default_random_engine generator;

void solve();

int main() {
#ifdef LOCAL
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);  
#endif 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << setprecision(12) << fixed;
    cerr << setprecision(12) << fixed;  

    int tests = 1;
    // cin >> tests;

    while (tests--) {
        solve();
    }

#ifdef LOCAL
    cerr << "Time: " << double(clock()) / CLOCKS_PER_SEC << endl;
#endif
}

// -----------------------------------------------------------------------

void solve() {  
    ll n, m, v, p;
    cin >> n >> m >> v >> p;
    vector<ll> a(n);

    v -= p;
    v = max(v, 0ll);

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

    sort(all(a));

    int l = -1, r = n - p;
    while (r - l > 1) {
        int k = (l + r) / 2; 

        if (a[k] + m < a[n - p]) {
            l = k;
            continue;
        }

        if (k >= v) {
            r = k;
            continue;
        }

        ll initv = v;
        v -= k;

        vector<ll> vals; 
        ll sum = 0;

        for (int i = k + 1; i <= n - p; ++i) {
            ll x = a[k] + m - a[i];
            if (x > 0) {
                sum += x;
            }
        }

        if (sum < m * v) {
            l = k;
        } else {
            r = k;
        }

        v = initv;

    }

    cout << n - r << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
string s;
int n;
inline string solve(string s){
    int sam=0;
    int i=0;
    while(i<n){
        if(s[i]=='('){
            sam++;
        }else{
            sam--;
        }
        if(sam<0){
            s="("+s;
            sam=0;
            i++;
            n++;
        }
        i++;
    }
    //cout<<s<<endl;
    //cout<<sam<<endl;
    for(int j=0;j<sam;j++)s+=")";
    return s;
}
int main(){
    cin>>n;
    cin>>s;
    cout<<solve(s)<<endl;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int cnt = 0;
  rep(i,n) {
    if (s.substr(i,3) == "ABC") cnt++;
  }
  cout << cnt << endl;
}


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

using namespace std;
using ull = unsigned long long;
using ll = long long;
using lli = long long int;
using ld = long double;
using pa = pair<int, int>;
using ppa = pair<pa, int>;
#define SORT(v, n) sort(v, v + n);
#define ALL(v) v.begin(), v.end()
#define VSORT(v) sort(ALL(v))
#define GRESORT(v) sort(ALL(v), greater<ll>())
#define REVERSE(v) reverse(ALL(v))
#define overlap(v) v.erase(unique(ALL(v)), v.end())
#define debug(x) cout << #x << ": " << x << endl
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (b - 1); i >= a; i--)
#define rrep(i, n) RFOR(i, 0, n)
#define INF INT_MAX
#define SUP INT_MIN
#define mins(a, b) a = min(a, b)
#define maxs(a, b) a = max(a, b)

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

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

// const ll MOD = 1000000007;

ll pow_mod(ll a, ll b, ll mod) {
    ll tmp = 1;
    a %= mod;
    if (b > 0) {
        tmp = pow_mod(a, b / 2, mod);
        if (b % 2)
            tmp = (((tmp * tmp) % mod) * a) % mod;
        else
            tmp = (tmp * tmp) % mod;
    }
    return tmp;
}

ll gcd(ll x,ll y){
    if(x == 0) return y;
    return gcd(y%x,x);
}

void solve(){
    string a,b,c;
    cin >> a >> b >> c;
    cout << a[0] << b[0] << c[0] << endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i,a) for(ll i=a-1;i>=0;i--)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define printall(n,array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    print(a * b / 2);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<queue>
#include<cmath>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cout << '!' << endl;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	string str;
	
	cin >> str;
	
	if(str.size() < 4)
	{
		cout << "No" << endl;
		return 0;
	}
	
	//cout << str.substr(0,4).c_str() << endl;
	
	if(strcmp(str.substr(0,4).c_str(),"YAKI") == 0)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
 
#define UP 1
#define LEFT 2
#define SLANT 3
 
using namespace std;
 
string LCS(string a, string b)
{
  int t[a.size()+1][b.size()+1];
  int move[a.size()+1][b.size()+1];
  fill(&move[0][0], &move[a.size()][b.size()+1], 0);
  fill(&t[0][0], &t[0][b.size()+1], 0);
  for(int i=1; i<a.size()+1; i++){
    t[i][0] = 0;
  }
 
  for(int i=1; i<a.size()+1; i++){
    for(int j=1; j<b.size()+1; j++){
      if(a[i-1] == b[j-1]){
        t[i][j] = t[i-1][j-1] + 1;
        move[i][j] = SLANT;
      }
      else if(t[i-1][j] >= t[i][j-1]){
        t[i][j] = t[i-1][j];
        move[i][j] = UP;
      }
      else if(t[i-1][j] < t[i][j-1]){
        t[i][j] = t[i][j-1];
        move[i][j] = LEFT;
      }
    }
  }
 
  string result;
  int i = a.size(), j = b.size();
  while(i != 0 && j != 0){
    if(move[i][j] == SLANT){
      result += a[i-1];
      i--;
      j--;
    }
    else if(move[i][j] == UP)
      i--;
    else if(move[i][j] == LEFT)
      j--;
  }
  reverse(result.begin(), result.end());
  return result;
}
 
int main(void)
{
  while(true){
    string a, b, result;
    getline(cin, a);
    getline(cin, b);
    if(cin.eof() == true)
      break;
    result = LCS(a, b);
    cout << result << endl;
  }
  return 0;
}


Measured memory_bytes: 70656
while True:
    H,W = map(int,input().split())
    if H==W==0:
        break
    for i in range(H):
        for k in range(W):
            if (i+k)%2 == 0:
                print("#",end = "")
            else:
                print(".",end = "")
        print()
    print()


Measured memory_bytes: 7004
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
    int n, z, w; cin >> n >> z >> w;
    int a[n+1]; a[0] = w; for (int i = 1; i <= n; i++) cin >> a[i];
    int maxsc[n+1], minsc[n+1];
    for (int i = n; i >= 1; i--) {
        maxsc[i] = minsc[i] = abs(a[i-1]-a[n]);
        maxsc[i] = *max_element(&minsc[i], &minsc[n+1]);
        minsc[i] = *min_element(&maxsc[i], &maxsc[n+1]);
    }
    cout << maxsc[1] << endl;
}


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

int main() {
    int n; cin >> n;
    map<string, bool> has_key;

    vector<string> words(n);
    for (int i=0; i<n; ++i) {
        cin >> words[i];
        if (has_key.find(words[i]) == has_key.end()) {
            has_key[words[i]] = true;
        }
        else {
            cout << "No" << endl;
            return 0;
        }
    }

    char prev_char = words[0].back();
    for (int i=1; i<n; ++i) {
        if (prev_char != words[i][0]) {
            cout << "No" << endl;
            return 0;
        }
        prev_char = words[i].back();
    }

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

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

int main(){
  int a,b = 0;
  cin >> a;
  for(int i = 1;i < 10;i++){
    if(a/i < 10 && a%i == 0){
      b = 1;
      break;
    }
  }
  if(b == 1)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
c=[[0 for i in range(3)] for j in range(3)]

for i in range(3):
    c[i][0],c[i][1],c[i][2] = map(int,input().split())

Flag='No'

if c[1][0]-c[0][0] == c[1][1]-c[0][1] == c[1][2]-c[0][2]:
    if c[2][0]-c[0][0] == c[2][1]-c[0][1] == c[2][2]-c[0][2]:
        Flag='Yes'

print(Flag)

Measured memory_bytes: 3064
X,N=map(int,input().split())
List=[int(i) for i in input().split()]
A=X
B=X
C=X in List
if C == True:    
    p=True
    q=True
    while p==True:
        A=A-1
        p= A in List
    while q==True:
        B=B+1
        q= B in List
    if X-A <= B-X:
        print (A)
    else:
        print (B)
else:
    print(X)

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

int main()
{
    int n, k;
    cin >> n >> k;
    int p[1005];
    for(int i = 0; i < n; i++) cin >> p[i];
    sort(p, p + n);
    int ans = 0;
    for(int i = 0; i < k; i++){
        ans += p[i];
    }
    cout << ans << endl;
}


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

int main()
{
    const int MAX_M = 21;
    
    int N, M, C, b[MAX_M], ans = 0;
    
    cin >> N >> M >> C;
    
    for (int i = 0; i < M; i++)
        cin >> b[i];
        
    for (int i = 0; i < N; i++)
    {
        int new_a, sum = 0;
        bool ok = false;
        
        for (int j = 0; j < M; j++)
        {
            cin >> new_a;
            
            sum += new_a * b[j];
        }
        
        if (sum + C > 0)
            ok = true;
        
        if (ok)
            ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
for line in stdin:
    a, b = map(int, line.strip('\n').split(' '))
    if a == 0 and b == 0:
        break

    for i in range(a):
        for j in range(b):
            print(('.' if (i+j) % 2 else '#'), end='')
        print()
    print()


Measured memory_bytes: 7012
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	vector<int> nums(n); fore(e, nums) cin >> e;
	multiset<int> cur;
	fore(e, nums) {
		auto it = cur.lower_bound(e);
		if(it == cur.begin()) { cur.insert(e); continue; }
		it--;
		int val = *it;
		cur.erase(cur.find(val));
		cur.insert(e);
	}
	println(cur.size());
}


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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> l(N);
    for (int i = 0; i < N; i++)
    {
        cin >> l[i];
    }
    sort(l.begin(), l.end(), greater<int>());

    cout << accumulate(l.begin(), l.begin() + K, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-5;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

class Segment_Tree {
	vector<long long int>v;
	int num;
	long long int ret;
	bool is_min;
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		if (is_min) {
			v[place] = min(Update(place * 2), Update(place * 2 + 1));
			return v[place];
		}
		v[place] = max(Update(place * 2), Update(place * 2 + 1));
		return v[place];
	}
public:
	Segment_Tree(int n, bool min) {
		n++;
		num = 1;
		while (num < n * 2) {
			num *= 2;
		}
		is_min = min;
		if (min) {
			v.resize(num, MOD*MOD);
		}
		else v.resize(num, -MOD * MOD);
	}
	void Insert(int place, long long int num, bool update) {
		place += v.size() / 2;
		v[place] = num;
		if (!update)return;
		place /= 2;
		while (place) {
			if (is_min)v[place] = min(v[place * 2], v[place * 2 + 1]);
			else v[place] = max(v[place * 2], v[place * 2 + 1]);
			place /= 2;
		}
	}
	void TopDown() {
		Update(1);
	}
	long long int RMQ(int a, int b) {
		if (is_min)ret = LLONG_MAX;
		else ret = LLONG_MIN;
		if (is_min) {
			b++;
			for (a += num / 2, b += num / 2; a < b; a >>= 1, b >>= 1) {
				if (a & 1)ret = min(ret, v[a++]);
				if (b & 1)ret = min(ret, v[--b]);
			}
		}
		else {
			b++;
			for (a += num / 2, b += num / 2; a < b; a >>= 1, b >>= 1) {
				if (a & 1)ret = max(ret, v[a++]);
				if (b & 1)ret = max(ret, v[--b]);
			}
		}
		return ret;
	}
};

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

	cin >> N >> K;
	Segment_Tree sg(900001, false);
	while (N--) {
		cin >> M;
		M += 300000;
		int num = sg.RMQ(M - K, M + K);
		sg.Insert(M, max(num + 1, 1), true);
	}
	cout << sg.RMQ(0, 900000) << endl;
}

Measured memory_bytes: 19568
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

#define POS(i,j) ((i)*(b+1)+(j))

const int mod=1000000007;

int modPow(int r,int n){
  int t=1;
  int s=r;
  while(n>0){
    if(n&0x01) t=(int64)t*s%mod;
    s=(int64)s*s%mod;
    n>>=1;
  }
  return t;
}

int *fact=NULL;
int *iFact=NULL;
void init(const int n){
  fact=(int *)malloc(sizeof(int)*(n+1));
  iFact=(int *)malloc(sizeof(int)*(n+1));
  fact[0]=1;
  int i;
  for(i=1;i<=n;i++) fact[i]=(int64)i*fact[i-1]%mod;
  iFact[n]=modPow(fact[n],mod-2);
  for(i=n-1;i>=0;i--) iFact[i]=(int64)iFact[i+1]*(i+1)%mod;
  return;
}

int comb(int n,int k){
  if(!(0<=n && 0<=k && k<=n)) return 0;
  return (int64)fact[n]*iFact[k]%mod*iFact[n-k]%mod;
}

int n,a,b,c,d;
int *dp=NULL;

int calc(int x,int y){
  if(x==0) return 1;
  if(y<a) return 0;
  if(dp[POS(x,y)]>=0) return dp[POS(x,y)];
  int local=calc(x,y-1);
  int k;
  for(k=c;k<=d && k<=x/y;k++){
    int way=(int64)comb(x,k*y)*fact[k*y]%mod*modPow(iFact[y],k)%mod*iFact[k]%mod;
    local=(local+(int64)way*calc(x-k*y,y-1))%mod;
  }
  dp[POS(x,y)]=local;
  return local;
}

void run(void){
  scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
  init(n);
  dp=(int *)malloc(sizeof(int)*(n+1)*(b+1));
  int i;
  for(i=0;i<(n+1)*(b+1);i++) dp[i]=-1;
  int ans=calc(n,b);
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 4224
#include <iostream>
 
using namespace std;
 
int next(int now,int num){
    switch(now){
    case 0:
	return num ? 4 : 3;
    case 1:
	return num ? 3 : 4;
    case 2:
	return num ? 4 : 1;
    case 3:
	return num ? 5 : -1;
    case 4:
	return num ? -1 : 3;
    case 5:
	return num ? 1 : 2;
    }
    return -1;
}
 
int main(){
    string str;
 
    while(cin >> str ,str != "#"){
	int now = 0; 
	for(int i = 0 ; i < (int)str.size() ; i++){
	    now = next(now,str[i]-'0');
	    if(now == -1) break;
	}
 
	if(now == 1){
	    cout << "Yes" << endl;
	}
	else{
	    cout << "No" << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main(){
  string s,t,u;
  cin >> s;
  int a,b;
  rep(i,s.size()) cout << "x";
  cout << endl;
  return 0;
}




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

#define INF (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795


//vl a(1001);

ll powM(ll a,ll b, ll m)
{ 
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans%m;
}



//vl a(n+1);
ll ans(ll n,ll k)
{
   ll l=1,r=(ll)1e10,m;
    while(l<=r)
    {
      m=(l+r)/2;
     //  if(m%n==0&&m-m/n==k)return m+1;
       if(m-m/n<k)l=m+1;
      else r=m-1;
    }
    ll temp=m-m/n;
    if(temp==k)return m;
    else return m+(k-temp);
}
int main()
{

ll n;cin>>n;
vl a(n+1);
for(int i=1;i<=n;i++)cin>>a[i];
ll cur=1;
vector<bool>vis(n+1,false);
ll ans=0;
vis[cur]=true;
while(cur!=2)
{
   cur=a[cur];
   if(vis[cur])
   {
    ans=-1;
    break;
   }
   else 
   {
    vis[cur]=true;
    ans++;
   }
}
cout<<ans<<"\n";
  return 0;
}






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

using namespace std;

int a[20][20];
int n;
long long dp[1 << 16];

int main(){
	scanf("%d", &n);

	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			scanf("%d", &a[i][j]);

	for(int mask = 0; mask < (1 << n); mask++){
		for(int i = 0; i < n; i++){
			for(int j = i + 1; j < n; j++){
				if((mask & (1 << i)) && (mask & (1 << j))) dp[mask] += a[i][j];
			}
		}

		for(int sub1 = mask; sub1; sub1 = (sub1 - 1) & mask){
			dp[mask] = max(dp[mask], dp[sub1] + dp[sub1 ^ mask]);
		}
	}

	printf("%lld\n", dp[(1 << n) - 1]);
	
	return 0;
}

Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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

		int n = 0;
		int[] diffArray = null;
		try (BufferedReader br = new BufferedReader(new InputStreamReader(
				System.in))) {

			n = Integer.parseInt(br.readLine());

			String[] v = br.readLine().split("\\s");
			String[] c = br.readLine().split("\\s");

			diffArray = new int[n];
			for (int i = 0; i < n; i++) {
				int vi = Integer.parseInt(v[i]);
				int ci = Integer.parseInt(c[i]);

				int diff = vi - ci;
				if (0 < diff) {
					diffArray[i] = diff;
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}

		int sum = 0;
		for (int i = 0; i < diffArray.length; i++) {
			sum += diffArray[i];
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 23124
N = int(input())
S = list(input())

def get_ans(ans_,c):
    if c < 0:
        pass
    else:
        ans_ -= B_[c]
    return ans_

# N=4000
# S=[random.choice(['R','G','B']) for _ in range(N)]

S_dict={'R':set(),'G':set(),'B':set()}
for s_idx,s in enumerate(S):
    S_dict[s].add(s_idx+1)
    
# print(S_dict)
B_ = [0]*(2*N)
for s_b in S_dict['B']:
    B_[s_b]=1
    
S_R=S_dict['R']
S_G=S_dict['G']
    
ans=0
ans__=len(S_dict['B'])
for s_r in S_R:
    for s_g in S_G:
        ans_=ans__
        c_= abs(s_r-s_g)
        c_mean = 0
        if (s_r + s_g)%2 == 0:
            c_mean = (s_r + s_g)//2
            ans_ = get_ans(ans_,c_mean)
            
#         print('=====')
#         print(s_r,s_g,c_,c_mean)
        
        if s_r > s_g:
            ans_ = get_ans(ans_,s_r + c_)
            ans_ = get_ans(ans_,s_g - c_)
            
#             print(s_r + c_,s_g - c_)
            
        else:
            ans_=get_ans(ans_,s_r - c_)
            ans_=get_ans(ans_,s_g + c_)
            
#             print(s_r - c_,s_g + c_)
        
        ans+=ans_
        
#         print(ans_,ans)
        
print(ans)

Measured memory_bytes: 9712
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX=10;
int main(void)
{
	int N,M;
		cin >> N >> M;
	int A[MAX],B[MAX];
	for(int i=0;i<N;i++)
		cin >> A[i] >> B[i];
	
	int ans=(M+99)/100;
	for(int bit=0;bit<(1<<N);bit++){
		int sum=0,cnt=0,m;
		for(int i=0;i<N;i++){
			if(bit&(1<<i)){
				sum+=A[i]*100*(i+1)+B[i];
				cnt+=A[i];
			}
			else
				m=i;
		}
		
		if(sum<M){
			if(M-sum>A[m]*100*(m+1))
				continue;
			cnt+=(M-sum+((m+1)*100)-1)/((m+1)*100);
		}
		ans=min(ans,cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    string s, t;
    cin >> s >> t;
    ll ss = s.size();
    ll ts = t.size();
    vector<ll>sz(ss+1);
    vector<ll>tz(ts+1);
    for (int i = 1; i < ss+1; i++) {
        if (s[i-1] == 'A')sz[i] = (sz[i - 1] + 1) % 3;
        else sz[i] = (sz[i - 1] + 2) % 3;
    }
    for (int i = 1; i < ts+1; i++) {
        if (t[i-1] == 'A')tz[i] = (tz[i - 1] + 1) % 3;
        else tz[i] = (tz[i - 1] + 2) % 3;
    }
    ll q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        if ((sz[b] - sz[a - 1] - tz[d] + tz[c - 1] + 120) % 3 == 0)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, k;
	cin >> n >> k;
	vi a = { 0 }, b = { 0 };
	REP(i, n)
	{
		int x; cin >> x;
		if (x >= 0) a.push_back(x);
		else b.push_back(x);
	}
	sort(ALL(a));
	sort(b.rbegin(), b.rend());
	int ans = 1e9;
	REP(i, k + 1)
	{
		if (i < a.size() && k - i < b.size())
		{
			chmin(ans, a[i] * 2 - b[k - i]);
			chmin(ans, a[i] - b[k - i] * 2);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1020
#include<stdio.h>
#include<algorithm>
#include<iostream>
#define M 55
#define ll long long
using namespace std;
template <class T>
inline void Rd(T &res){
	char c;res=0;int k=1;
	while(c=getchar(),c<48&&c!='-');
	if(c=='-'){k=-1;c='0';}
	do{
		res=(res<<3)+(res<<1)+(c^48);
	}while(c=getchar(),c>=48);
	res*=k;
}
template <class T>
inline void Pt(T res){
	if(res<0){
		putchar('-');
		res=-res;
	}
	if(res>=10)Pt(res/10);
	putchar(res%10+48);
}
int a[M];
ll dp[2][2];
int main(){
	int n,p;
	scanf("%d %d",&n,&p);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	int cur=0;dp[cur][0]=1;
	for(int i=1;i<=n;i++){
		cur=!cur;
		dp[cur][0]=dp[cur][1]=0;
		dp[cur][a[i]&1]=dp[!cur][a[i]&1]+dp[!cur][0];
		dp[cur][(a[i]+1)&1]=dp[!cur][(a[i]+1)&1]+dp[!cur][1];
	}
	cout<<dp[cur][p]<<'\n';
	return 0;
	return 0;
}

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

int main() {
 int n;
  cin >> n;
  int arr[n];
  for (int i=0; i<n; i++) cin >> arr[i];
  sort(arr, arr+n);
  reverse(arr, arr+n);
  int a = 0;
  int b = 0;
  for (int i=0; i<n; i++) {
   if (i % 2 == 0) a += arr[i];
    else b += arr[i];
  }
  cout << a - b << endl;
}

Measured memory_bytes: 256
module Memoizable
	def memoize(name)
		original = "__original_#{name}__"
		([Class, Module].include?(self.class) ? self : self.class).class_eval {
			alias_method(original, name)
			private(original)
			cache = {}
			define_method(name){|*args|
				cache[args] ||= send(original, *args)
			}
		}
	end 

	#def memoize(name)
	#	original = "__original_#{name}__"
	#	klass = ([Class, Module].include?(self.class) ? self : self.class)
	#	klass.class_eval <<-"EOS"
	#		alias_method('#{original}', '#{name}')
	#		private('#{original}')
	#		@@cache_for_#{name} = {}
	#		def #{name}(*args)
	#			@@cache_for_#{name}[args] ||= send('#{original}', *args)
	#		end
	#	EOS
	#end 
end
include Memoizable

def f(s, k, min, max)
	if k == 1
		return min <= s && s <= max ? 1 : 0
	end

	count = 0
	(min..max-1).each{|x|
		count += f(s-x, k-1, x+1, max)
	}
	count 
end

memoize :f

loop {
	n, k, s = gets.split.map &:to_i
	break if n == 0
	p f(s, k, 1, n)
}

Measured memory_bytes: 11672
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
	vector<int> vec(1000000+1);
	int n,x; cin>>n;
	for(int i=1;i<=n;++i){
		cin>>x;
		++vec[x];
	}
	int cnt=0;
	for(int i=1;i<=1000000;++i){
		if(vec[i]==0) continue;
		if(vec[i]==1) ++cnt;
		for(int j=2*i;j<=1000000;j+=i){
			vec[j]=0;
		}
	}
	cout<<cnt<<"\n";
	return 0;
}


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

int main(){
    int n,x,t;
    cin >> n >> x >> t;
    if(n % x == 0){
        cout << n/x * t << endl;
    }else{
        cout << (n/x+1) * t << endl;
    }
    return 0;
}



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

using namespace std;

typedef long long llint;

int main() {
  int n, m;
  cin >> n >> m;
  vector<llint> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<vector<int>> g(n, vector<int>());
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }

  vector<bool> used(n, false);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (used[i]) continue;
    bool ok = true;
    for (auto &v : g[i]) {
      if (h[i] <= h[v]) ok = false;
    }
    if (ok) {
      for (auto &v : g[i]) {
        used[v] = true;
      }
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 9268
import java.util.*;
public class Main{
	public static void main(String[] args){
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String[] s = S.split("");
		
		int max = 0;
		int last = -1;
		for(int i=0; i<s.length; i++){
			if(!s[i].equals("A") && !s[i].equals("T") && !s[i].equals("C") && !s[i].equals("G")){
				int length = i-last-1;
				if(length > max){
					max = length;
				}
				last = i;
			}
		}
		int length = s.length-last-1;
		if(length > max){
			max = length;
		}
				
		System.out.println(max);
	}
}


Measured memory_bytes: 23124
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#ifdef on_linux
	#include <sys/resource.h>
#endif

#ifdef dobby_is_a_free_elf
	#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
	#define trace(...) 0;
#endif

using namespace std;
using namespace __gnu_pbds;


#define all(x)                  (x).begin(), (x).end()
#define between(i,x,y)          ((i) >= (x) && (i) <= (y))
#define DECIMAL(n)              cout << fixed << setprecision(n)
#define fi                      first
#define lbd                     lower_bound
#define mem0(x)                 memset(x, 0, sizeof (x))
#define mem1(x)                 memset(x, -1, sizeof (x))
#define mp                      make_pair
#define pb                      push_back
#define pf                      push_front
#define ppb                     pop_back
#define ppf                     pop_front
#define sc                      second
#define sqr(a)                  ((a) * (a))
#define sz(x)                   (int)((x).size())
#define ubd                     upper_bound

#define int                     long long

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <typename T>
using ordered_set = tree<T, null_type,
      less<T>,
      rb_tree_tag,
      tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0
// order_of_key(k) returns count of elements strictly smaller than k


const long double PI = 3.14159265358979323846264338;
const double eps = 1e-10;
#ifdef int
	const long long INF = 1e18;
#else
	const long long INF = 1e9;
#endif
const int32_t MOD = 998244353;
// const int32_t MOD = 1000000007;
const int32_t N = 1e5 + 10;
const int32_t NN = 1e6 + 10;



inline void elf_magic(int testcase)
{
	int n, k;
	cin >> n >> k;

	int l[n], r[n];
	for (int i = 0; i < k; ++i) {
		cin >> l[i] >> r[i];
	}

	int dp[n + 1] = {};
	dp[1] = 1;

	for (int i = 2; i <= n; ++i) {
		for (int j = 0; j < k; ++j) {
			int right = i - l[j];
			if (right < 1) { continue; }
			int left = max(1ll, i - r[j]);
			(dp[i] += (dp[right] - dp[left - 1])) %= MOD;
			// cout << left << ' ' << right << "!!\n";
		}
		// cout << i << ' ' << dp[i] << '\n';
		(dp[i] += dp[i - 1]) %= MOD;
	}
	cout << (dp[n] - dp[n - 1] + MOD) % MOD;

	return;
}

int32_t main()
{
	#ifdef on_linux
	rlimit cpu_time {.rlim_cur = 2, .rlim_max = RLIM_INFINITY};
	setrlimit(RLIMIT_CPU, &cpu_time);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int TESTS = 1;
	//cin >> TESTS;
	for (int i = 1; i <= TESTS; ++i) {
		// cout << "Case #" << i << ": ";
		elf_magic(i);
		if (i != TESTS)	{ cout << '\n'; }
	}
	return 0;
}

Measured memory_bytes: 5264
fun main(args: Array<String>) {
    val (n, p) = readLine()!!.split(' ').map { it.toInt() }
    val s = readLine()!!.reversed()

    val ans = if (10 % p == 0) {
        var ans = 0L
        for (i in 0 until n) {
            if ((s[i] - '0') % p == 0) ans += n - i
        }
        ans
    } else {
        val cnt = IntArray(p)
        var x = 0
        var b = 1
        var ans = 0L
        for (i in 0 until n) {
            cnt[x]++
            x += (s[i] - '0') * b
            x %= p
            ans += cnt[x]
            b = b * 10 % p
        }
        ans
    }

    println(ans)
}


Measured memory_bytes: 41644