akhauriyash/Code-Regression huggingface dataset:
open Batteries
open Printf
open Scanf

let ($) g f x = g (f x)
let nil = ()

module MyList = struct
  include List
  let foldl = fold_left
  let foldr = fold_right
  
  let flatmap f ls = concat @@ map f ls

  let zipf = map2
  let zipfi = map2i
end

module L = MyList

let atoi = int_of_string
let itoa = string_of_int
let atof = float_of_string
let ftoa = string_of_float
let ctoi = int_of_char
let itoc = char_of_int

let stocl = String.to_list
let cltos = String.of_list
let spsp s = String.split_on_char ' ' s

module MyString = struct
  include String

  let map' f s = L.map f (stocl s)
  let mapi' f s = L.map f (stocl s)

  let zipf f a b = L.zipf f (stocl a) (stocl b)
  let zipfi f a b = L.zipfi f (stocl a) (stocl b)

  let mkstr f sep ls =
    L.foldl (fun acc x -> acc ^ sep ^ (f x)) (f @@ L.hd ls) (List.tl ls)
end

module S = MyString

let tup2 a b = (a, b)
let tup3 a b c = (a, b, c)
let tup4 a b c d = (a, b, c, d)

let rds () = read_line ()
let rds2 () = scanf "%s %s\n" tup2

let rdi () = atoi @@ rds ()
let rdi2 () = scanf "%d %d\n" tup2
let rdi3 () = scanf "%d %d %d\n" tup3
let rdi4 () = scanf "%d %d %d %d\n" tup4

let rdhs () = spsp @@ rds ()
let rdhi () = rdhs () |> L.map atoi

let rdvs n rdf = L.init n (fun _ -> rdf ())

let rdvi n = rdvs n rdi
let rdvi2 n = rdvs n rdi2
let rdvi3 n = rdvs n rdi3
let rdvi4 n = rdvs n rdi4

let puts s = print_endline s

let _ =
  let (s, t) = scanf "%s\n%s\n" tup2 in
  puts (if S.starts_with t s then "Yes" else "No");;



Measured memory_bytes: 5404
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
int N;
char T[200000+2];
int main(){
  int i;
  N = rd(T);
  for(i=(0);i<(N);i++){
    if(T[i]=='?'){
      T[i] = 'D';
    }
  }
  wt_L(T);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// int N;
// char T[2d5+2];
// {
//   rd(T@N);
//   rep(i,N) if(T[i]=='?') T[i] = 'D';
//   wt(T);
// }


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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a;
  cin >> a;
  string b;
  cin >> b;
  int b1 = b[0]-'0';
  int b2 = (b[2]-'0')*10+b[3]-'0';
  ll ans = a*b1;
  ans += (b2*a)/100;
  cout << ans << endl;

  
  return 0;
    

}


Measured memory_bytes: 3652
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		int[] t = new int[n];
		for(int i=0;i<n;i++){
			s[i] = sc.next();
			t[i] = sc.nextInt();
		}
		String x = sc.next();
		sc.close();

		int idx = 0;
		for(int i=0;i<n;i++){
			if(x.equals(s[i])){
				idx = i;
			}
		}

		int r = 0;
		for(int i=idx+1;i<n;i++){
			r+=t[i];
		}
		System.out.println(r);
	}
}


Measured memory_bytes: 23380
#include <stdio.h>

int main(void)
{
	int n,k,min=1,i;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)
		{
		if(min<=k)
			{min*=2;}
		else
			{min+=k;}
		}
	printf("%d",min);
return 0;
}




Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> PP;
typedef bitset<60> Bitset;
const ll INFL = 1LL << 60;
const int INF = INT_MAX;
const int MAX = 300000;
const int MOD = 1000000007;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
//------------------------------------------------------------------------------------------------------------------------------

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    cout<<1000*((n+999)/1000)-n<<endl;
}


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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;

    vector<vector<int>> x(n, vector<int>());
    vector<vector<int>> y(n, vector<int>());
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        for(int j=0; j<a; j++){
            int xx, yy;
            cin >> xx >> yy;
            x[i].push_back(xx-1);
            y[i].push_back(yy);
        }
    }

    int max_pop = 0;
    for(int i=0; i<(1<<n); i++){
        bool flag = true;
        for(int j=0; j<n; j++){
            if((i & (1<<j)) == (1<<j)){
                // j が正直者のとき
                for(int k=0; k<x[j].size(); k++){
                    if((i & (1<<x[j][k])) != y[j][k] * (1<<x[j][k])){
                        // 証言と違う
                        flag = false;
                    }
                }
            }
        }
        if(flag && max_pop < __builtin_popcount(i)){
            max_pop = __builtin_popcount(i);
        }
    }
    cout << max_pop << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n;
vector<int> vec;
bool check(int a, int b, int c) {
  bool va = a < b + c;
  bool vb = b < c + a;
  bool vc = c < a + b;
  return va && vb && vc;
}

int main()
{
  cin >> n;
  vec.resize(n);
  rep(i,n) cin >> vec.at(i);
  sort(vec.begin(), vec.end());
  int ans = 0;
  rep(i, n)reps(j, i+1, n) {
    auto it = lower_bound(vec.begin()+ j + 1, vec.end(), vec.at(j) + vec.at(i));
    int d = it - (vec.begin() + j) - 1;
    ans += d;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
int main(){
  
  int a,b;
  int d,r;
  double f;
  
  scanf("%d %d",&a,&b);
  
  d = a/b;
  r = a%b;
  f = 1.0*a/b;
  
  printf("%d ",d);
  printf("%d ",r);
  printf("%.5lf\n",f);
  
  return(0);
  
}



Measured memory_bytes: 2080
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

const int Maxn = 100005;

int n;
vector <int> neigh[Maxn];
int dp[Maxn];

void Solve(int v)
{
    vector <int> seq;
    for (int i = 0; i < neigh[v].size(); i++) {
        int u = neigh[v][i];
        Solve(u);
        seq.push_back(dp[u]);
    }
    sort(seq.begin(), seq.end());
    for (int i = 0; i < seq.size(); i++)
        dp[v] = max(dp[v], seq[i]) + 1;
}

int main()
{
    scanf("%d", &n);
    for (int i = 2; i <= n; i++) {
        int p; scanf("%d", &p);
        neigh[p].push_back(i);
    }
    Solve(1);
    printf("%d\n", dp[1]);
    return 0;
}


Measured memory_bytes: 13952
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int h = sc.nextInt();
      int w = sc.nextInt();
      char[][] grid = new char[h][w];
      for(int i = 0; i < h; i++)
        grid[i] = sc.next().toCharArray();
      int[][] cnt = new int[h][w];
      if(grid[0][0] == '#')
        cnt[0][0] = 1;
      for(int i = 1; i < w; i++) {
        if(grid[0][i] == '.')
          cnt[0][i] = cnt[0][i-1];
        else {
          if(grid[0][i-1] == '#')
            cnt[0][i] = cnt[0][i-1];
          else
            cnt[0][i] = cnt[0][i-1] + 1;
        }
      }

      for(int i = 1; i < h; i++) {
        if(grid[i][0] == '.')
          cnt[i][0] = cnt[i-1][0];
        else {
          if(grid[i-1][0] == '#')
            cnt[i][0] = cnt[i-1][0];
          else
            cnt[i][0] = cnt[i-1][0] + 1;
        }
      }

      for(int i = 1; i < h; i++) {
        for(int j = 1; j < w; j++) {
          if(grid[i][j] == '.') {
            cnt[i][j] = Math.min(cnt[i-1][j], cnt[i][j-1]);
          } else {
            int up = cnt[i-1][j];
            if(grid[i-1][j] == '.')
              up++;
            int left = cnt[i][j-1];
            if(grid[i][j-1] == '.')
              left++;
            cnt[i][j] = Math.min(up, left);
          }
        }
      }

      System.out.println(cnt[h-1][w-1]);
  }
}

Measured memory_bytes: 23636
#include<iostream>
#include<vector>
#include<algorithm>
#include <string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>

#define ok printf("ok\n");
#define MAX 1000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define pb push_back

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

int main()
{
	int a,b,c=0;
	string s,t;
	vi v;
	cin>>a;
	rep(i,a)
	{
	cin>>b;
	v.push_back(b);
}
	rep(i,a){
	rep(j,a)
		if(v[j]%2==1){cout<<c;return 0;}	
		else{v[j]=v[j]/2;}
		c++;
	i=0;
	}
	return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll h,w,n; cin>>h>>w>>n;
  ll sy,sx; cin>>sy>>sx; sy--,sx--;
  string s,t; cin>>s>>t;
  
  ll l=0, r=w;
  if(s[n-1]=='L') l++;
  if(s[n-1]=='R') r--;
  for(ll i=n-2; i>=0; i--){
    if(t[i]=='L') r=min(r+1,w);
    else if(t[i]=='R') l=max(l-1,0LL);
    if(s[i]=='L') l++;
    else if(s[i]=='R') r--;
    if(l>=r){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  if(sx<l || r<=sx){
    cout<<"NO"<<endl;
    return 0;
  }
  
  l=0, r=h;
  if(s[n-1]=='U') l++;
  if(s[n-1]=='D') r--;
  for(ll i=n-2; i>=0; i--){
    if(t[i]=='U') r=min(r+1,h);
    else if(t[i]=='D') l=max(l-1,0LL);
    if(s[i]=='U') l++;
    else if(s[i]=='D') r--;
    if(l>=r){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  if(sy<l || r<=sy){
    cout<<"NO"<<endl;
    return 0;
  }
  cout<<"YES"<<endl;
}


Measured memory_bytes: 920
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=(ll)1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    for(ll i=0;i<N;++i)cin>>A[i];
    ll ans=0;
    for(ll i=0;i<N;++i){
        if(i%2==0&&A[i]%2==1)ans++;
    }
    prt(ans);fl

    return 0;
}



Measured memory_bytes: 3644
import java.util.*;

public class Main{
	
	int [] vx = {0,1,0,-1,1,1,-1,-1};
	int [] vy = {1,0,-1,0,1,-1,-1,1};
	int n;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			n = sc.nextInt();
			if(n == 0) break;
			char [][] data = new char[n][n];
			for(int i = 0; i < n; i++){
				data[i] = sc.next().toCharArray();
			}
			
			int max = 0;
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					if(data[i][j] == '0')continue;
					for(int k = 0; k < vx.length; k++){
						int now = 1;
						int yy = i, xx = j;
						while(true){
							xx = xx + vx[k];
							yy = yy + vy[k];
							if(! isOK(xx,yy)) break;
							if(data[yy][xx] == '0') break;
							now++;
						}
						max = Math.max(max, now);
					}
				}
			}
			System.out.println(max);
		}
	}

	private boolean isOK(int xx, int yy) {
		if(0<= xx && xx < n && 0<= yy && yy < n){
			return true;
		}
		return false;
	}

	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 25952
// たなこふ先生の input マクロ (´･_･`)
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[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)*}
    };
}

#[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, usize1) => {
        read_value!($iter, usize) - 1
    };

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

use std::collections::BTreeSet;

fn main() {
    input! {
        n: usize,
        reds: [(usize, usize); n],
        blues: [(usize, usize); n],
    }

    let reds: BTreeSet<_> = reds.iter().collect();
    let mut blues: BTreeSet<_> = blues.iter().collect();

    let mut ans = 0;

    for &(a, b) in reds.into_iter().rev() {
        let mut tail = blues.split_off(&(a, 0));
        let mut min = (a, 2*n+1);

        for &&(c, d) in &tail {
            if b < d && d < min.1 {
                min = (c, d);
            }
        }

        if tail.remove(&min) {
            ans += 1;
        }
        blues.append(&mut tail);
    }

    println!("{}", ans);
}


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

using namespace std;


int main()
{
    int N;
    int a,b;
    int res = 0;
    scanf("%d",&N);

    vector<pair<int, int> > red(N);
    vector<pair<int, int> > blue(N);

    for(int i=0;i<N;i++)
    {
        scanf("%d%d",&a,&b);
        red[i] = make_pair(a,b);
    }

    for(int i=0;i<N;i++)
    {
        scanf("%d%d",&a,&b);
        blue[i] = make_pair(a,b);
    }
    
    sort(red.begin(),red.end());
    sort(blue.begin(),blue.end());
    
    
    int rj,rmax;
    bool flag;
    for(int i=0;i<N;i++){
        flag = false;
        rj=0;
        rmax=-1;
        for(int j=0;j<N;j++){
            if(red[j].first == -1)
                continue;
            if(blue[i].first>red[j].first && blue[i].second>red[j].second)
            {
                if(red[j].second>rmax)
                {
                    flag = true;
                    rj = j;
                    rmax = red[j].second;
                }
            }
            if(blue[i].first<=red[j].first)
                break;
        }
        if(flag){
            res++;
            red[rj].first = -1;
        }
    }
    
    printf("%d\n",res);

    return 0;
    
    
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    char ch;
    int counts[26]={0};
    int i;
    for(i=0;i<26;i++) counts[i]=0;
    while(scanf("%c",&ch)!=EOF){
        if(ch==EOF)break;
        if('A'<=ch&&ch<='Z'){
            counts[ch-'A']++;}
        if('a'<=ch&&ch<='z'){
            counts[ch-'a']++;}
    }
    for(i=0;i<26;i++){
        printf("%c : %d\n",'a'+i,counts[i]);
    }
    return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,ans=1;cin>>n;

  V<PL> v(n);
  rep(i,0,n){
    ll x,l;cin>>x>>l;
    v[i]={x+l,x-l};
  }
  sort(all(v));

  ll r=v[0].fs;
  rep(i,1,n){
    if(r<=v[i].sc){
      r=v[i].fs;
      ans++;
    }
  }
  cout<<ans<<ENDL;


}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 1792
//
// Created by yuu on 2019-07-27.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>

using namespace std;

int A[100010];
int B[100010];
int main(void){
    int N;
    cin >>N;

    for (int i = 0; i <= N; ++i) {
        cin>>A[i];

    }

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

    long long e_count = 0;

    for (int i = 0; i < N; ++i) {
        if(B[i]>=A[i]){
            e_count += A[i];
            B[i] -= A[i];
            if(B[i]>=A[i+1]){
                e_count += A[i+1];
                A[i+1] = 0;
            }else{
                e_count += B[i];
                A[i+1] -= B[i];
            }
        }else{
            e_count += B[i];
        }
    }


    cout<<e_count<<endl;

    return 0;
}

Measured memory_bytes: 1024
/// e.cpp

# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < __typeof(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("YES")
# define no puts("NO")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < ll >
# define pb push_back
# define pdd pair < db , db >
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    static char str[1 << 20];
    static int s[1 << 20];
    fi>>(str + 1);
    int n = strlen(str + 1);
    reverse(str + 1,str + 1 + n);
    for (int i = 1;i <= n;++i)
        s[i] = str[i] - '0';
    int add = 0;
    for (int i = 1;i <= n || add;++i)
    {
        add += s[i] * 9;
        s[i] = add % 10;
        add /= 10;
        smax(n,i);
    }
    int sum = accumulate(s + 1,s + 1 + n,0);
    int ans = 0;
    for (ans = 0;9 * ans < sum;++ans)
    {
        int add = 9;
        for (int i = 1;add;++i)
        {
            add += s[i];
            sum -= s[i];
            s[i] = add % 10;
            sum += s[i];
            add /= 10;
            smax(n,i);
        }
    }
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


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

int main() {
	int a,b;
	cin>>a>>b;
	if (a>b){
		cout<<"a > b"<<endl;
	}else{if (a<b){
		cout<<"a < b"<<endl;
		}else{
		cout<<"a == b"<<endl;
		}
	}
}

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;
const int MOD = 1000000007;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

int N;

int func(string &s1, string &s2){
   for(int k=0; k<s1.length(); k++){
        bool ok = true;
        for(int l=k; l<s1.length(); l++)
            if(s1[l] != s2[l-k])
                ok = false;
        if(ok)
            return s2.length() - (s1.length() - k);
    }
    return s2.length();
}

bool cmp(const string& s1, const string& s2){
    return s1.length() > s2.length();
}

void solve(){
    vector<string> inputs(N);
    for(int i=0; i<N; i++)
        cin >> inputs[i];
    sort(inputs.begin(), inputs.end(), cmp);
    
    vector<string> cities;
    for(int i=0; i<N; i++){
        string s = inputs[i];
        bool updated = true;
        for(int j=0; j<cities.size(); j++){
            if(cities[j].find(s) != string::npos){
                updated = false;
            }
        }
        if(updated)
            cities.push_back(s);
    }
    
    N = cities.size();
    
    vector<vector<int>> path(N, vector<int>(N));
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            string s1 = cities[i];
            string s2 = cities[j];
            
            path[i][j] = func(s1, s2);
        }
    }
    
    vector<vector<int>> dp(1<<N, vector<int>(N, INF));
    for(int i=0; i<N; i++)
        dp[1<<i][i] = cities[i].length();
    
    for(int i=0; i<1<<N; i++){
        for(int j=0; j<N; j++) if(i>>j&1){
            for(int k=0; k<N; k++) if(i>>k&1 && j != k){
                dp[i][j] = min(dp[i][j], dp[i-(1<<j)][k] + path[k][j]);
            }
        }
    }
    
    int ans = INF;
    for(int i=0; i<N; i++)
        ans = min(ans, dp[(1<<N)-1][i]);
    cout << ans << endl;
}

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);
    
    while(cin>>N, N){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 2580
#include <cstdio>
#include <algorithm>

typedef long long ll;

const int MaxN = 200005;

int n;
ll A[MaxN]; int B[MaxN]; ll d[MaxN];

inline bool check(int a, int b, int c) {
	return (A[b] - A[a]) * (c - b) > (A[c] - A[b]) * (b - a);
}

int main() {
	scanf("%d", &n);
	int mx = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%lld", A + i);
		if (A[i] > A[mx]) mx = i;
	}
	for (int i = 0; i < n; ++i) scanf("%d", B + i);
	
	std::rotate(A, A + mx, A + n);
	std::rotate(B, B + mx, B + n);
	A[n] = A[0];
	
	d[0] = 233; d[1] = 666;
	for (int i = 1; i < n; ++i) d[i + 1] = 2 * (B[i] + d[i]) - d[i - 1];
	for (int i = 0; i <= n; ++i) A[i] -= d[i];
	
	static int stk[MaxN]; int top = 0;
	stk[top] = 0;
	for (int i = 1; i <= n; ++i) {
		while (top && !check(stk[top - 1], stk[top], i)) --top;
		stk[++top] = i;
	}
	
	ll sum = 0;
	for (int i = 0; i < top; ++i) {
		int u = stk[i], v = stk[i + 1];
		sum += (A[u] + A[v]) * (v - u + 1) - 2 * A[v];
	}
	for (int i = 0; i < n; ++i) sum += 2 * d[i];
	printf("%.12lf\n", (double)sum / (2 * n));
	return 0;
}

Measured memory_bytes: 6364
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

start_1 = set([])
goal_N = set([])

for i in range(M):
    if ab[i][0] == 1:
        start_1.add(ab[i][1])
    if ab[i][1] == N:
        goal_N.add(ab[i][0])

ans = start_1 & goal_N
if len(ans) > 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')






Measured memory_bytes: 58896
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        char[] s = scanner.next().toCharArray();
        int k = scanner.nextInt(), l = s.length - 1;
        StringBuilder ans = new StringBuilder(String.valueOf(s));
        for (int i = 0; i < l; i++) {
            if (s[i] != 'a' && k >= '{' - s[i]) {
                k -= '{' - s[i];
                ans.setCharAt(i, 'a');
            }
        }
        ans.setCharAt(l, (char)((s[l] - 'a' + k % 26) % 26 + 'a'));
        System.out.println(ans);
    }
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define int long long
typedef vector<int> vi;
#define all(x) x.begin(),x.end()
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define OO 1e9
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
typedef long long ll;
#define in_range(x, y, r, c) ((x >= 0 && x < r && y >= 0 && y < c))

const double eps=1e-9;
const  int MOD=1e10;
const int N=1e5+9;
const int inf = 1LL<<32;

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template <typename T> T exp(T b, T p){T x = 1;while(p){if(p&1)x=(x*b);b=(b*b);p=p>>1;}return x;}
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
int32_t main() {
    IOS;
int n,m;
cin>>n>>m;
vi arr(m);
    for (int i = 0; i < m; ++i) {
        cin>>arr[i];
    }
    vi ans;
    sort(all(arr));
    for (int i = 0; i < m - 1; ++i) {
        ans.emplace_back(abs(arr[i]-arr[i+1]));
    }
 sort(ans.rbegin(),ans.rend());
    int sum=0;
while(n<m){
    sum+=ans.back();
    ans.pop_back();
    n++;
}
    cout<<sum;

}

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

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

  string ans = "WA";
  if (S[0] == 'A') {
    if ('a' <= S[1] && S[1] <= 'z') {
      if ('a' <= S[S.size()-1] && S[S.size()-1] <= 'z') {
        int cnt = 0;
        for (int i=2; i<S.size()-1; i++) {
          if (S[i] == 'C') {
            cnt++;
          } else {
            if ('A' <= S[i] && S[i] <= 'Z') {
              cnt = 0;
              break;
            }
          }
        }

        if (cnt == 1) ans = "AC";
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;



typedef long double ld;
ll n, k;
ll a[200005];
ll f[200005];
bool ok(ll x, vector< pll > &v)
{
        ll ret = 0;
        for(auto &i : v) {
                ll X = i.first;
                ll Y = i.second;
                if(X <= x) continue;
                ret += (X-x+Y-1)/Y;
        }
        return (ret <= k);
}
int main()
{
        cin >> n >> k;
        for(ll i=1;i<=n;i++) cin >> a[i];
        for(ll i=1;i<=n;i++) {
                cin >> f[i];
        }
        sort(a+1, a+n+1);
        sort(f+1, f+n+1);
        vector< pll > v;
        for(ll i=n;i >=1 ; i--) {
                ll x = a[i] * f[n-i+1];
                v.pb(make_pair(x , f[n-i+1]));
        }
        ll lo = 0;
        ll hi = a[n] * f[n] + 4;
        while(hi  >  lo) {

                ll mid = lo + (hi - lo)/2;
                if(ok(mid, v)) hi=mid;
                else lo = mid + 1;
        }
        cout << lo << endl;
        return 0;
}


Measured memory_bytes: 9328
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        sc.close();
        if (Judge(S) == 2) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
    public static int Judge(String S) {
        if (S.length() < 2) {
            return 0;
        }
        int num = 0;
        String remain = "";
        for (int i = 1; i < S.length(); i++) {
            if (S.charAt(0) == S.charAt(i)) {
                num = 1;
            }
            else {
                remain += S.charAt(i);
            }
        }
        if (remain.length() != 0) {
            return num + Judge(remain);
        }
        return num;
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

int bfs(vector<string> &s, int x, int y) {
    int h = s.size(), w = s[0].size();
    vector<vector<int>> dist(h, vector<int>(w, -1));
    queue<pair<int, int>> que;

    int result = 0;
    que.push({x, y});
    dist[x][y] = 0;
    while(!que.empty()) {
        int x = que.front().first, y = que.front().second;
        que.pop();
        result = max(result, dist[x][y]);
        for (int dir = 0; dir < 4; dir++) {
            int nx = x + dx[dir], ny = y + dy[dir];
            if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
            if (s[nx][ny] == '#') continue;
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[x][y] + 1;
                que.push({nx, ny});
            }
        }
    }
    return result;
}


int main() {
    int h, w; cin >> h >> w;
    vector<string> s(h);
    REP(i, h) cin >> s[i];

    int result = 0;
    REP(x, h) {
        REP(y, w) {
            if (s[x][y] == '#') continue;
            result = max(result, bfs(s, x, y));
        }
    }
    cout << result << endl;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H,vector<char>(W));
  rep(i,H){
      rep(j,W){
          cin>>A[i][j];
      }
  }
  vector<bool> wx(W,false);
  vector<bool> hx(H,false);
  rep(i,H){
      rep(j,W){
          if(A[i][j]=='#'){
              hx[i]=true;
          }
      }
  }
  rep(j,W){
      rep(i,H){
          if(A[i][j]=='#'){
              wx[j]=true;
          }
      }
  }
  rep(i,H){
      if(hx[i]==false) continue;
      rep(j,W){
          if(wx[j]==true){
              cout<<A[i][j];
          }
      }
      cout<<endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

#define INF 334334334334
const int MAX_V=100005;

struct edge{int to, cost;};
typedef pair<int,int> P;//first:???????????¢???second:???????????????
vector<edge> G[MAX_V];
long long int d[MAX_V];
int V,E,s;

void dijkstra(int s){
  priority_queue<P,vector<P>,greater<P> > que;//
  fill(d,d+V,INF);
  d[s]=0;
  que.push(P(0,s));

  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if(d[v]< p.first) continue;
    for(int i=0; i<G[v].size(); i++){
      edge e = G[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        que.push(P(d[e.to],e.to));
      }
    }
  }
}

int main(){
  scanf("%d%d%d",&V,&E,&s);
  for (int i=0; i<E; i++) {
      int from, to, cost;
      scanf("%d", &from);
      scanf("%d", &to);
      scanf("%d", &cost);
      edge e;
      e.to = to;
      e.cost = cost;
      G[from].push_back(e);
    }

  dijkstra(s);

  for(int i=0; i<V;i++){
    if(d[i]==INF)printf("INF\n");
    else printf("%lld\n",d[i]);
  }
  return 0;
}

Measured memory_bytes: 12912
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

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

    string fr{s.front()};
    string ba{s.back()};
    int num = s.size() - 2;


    cout << fr + to_string(num) + ba << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const int MOD=1e9+7;
const int INF=1e9;
const double PI=acos(-1);



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

    char a;
    cin >> a;
    if (a-'a'>=0 && a-'a'<26) cout << 'a' << endl;
    else cout << 'A' << endl;
     

    return 0;
}


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

int binary_search(const vector<int>& ls, int v, int first, int last) {
  auto value = v - 0.5;
  int f = first;
  int l = last;
  while(l - f > 1) {
    int mid = (f + l) / 2;
    int vm = ls[mid];
    if(vm > value) {
      l = mid;
    } else {
      f = mid;
    }
  }
  return f;
}

int main() {
  int N;
  vector<int> Ls;
  cin >> N;
  int tmp;
  for(int i = 0; i < N; ++i) {
    cin >> tmp;
    Ls.push_back(tmp);
  }
  sort(Ls.begin(), Ls.end());

  int total = 0;
  for(int i = 0; i < Ls.size() - 2; ++i) {
    for(int j = i + 1; j < Ls.size() - 1; ++j) {

      int v = Ls[i] + Ls[j];
      if(v <= Ls[j + 1]) {
        continue;
      }

      if(Ls.back() < v) {
        // cout << Ls[i] << " - " << Ls[j] << " - " << Ls.back() << endl;
        total += (Ls.size() - 1 - j);
        continue;
      }

      int ib = binary_search(Ls, v, j + 1, Ls.size() - 1);
      // cout << Ls[i] << " - " << Ls[j] << " - " << Ls[ib] << endl;
      total += max(0, ib - j);
    }
  }
  cout << total << endl;

  return 0;
}

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

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

    string s,ans="";
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!='B')
            ans+=s[i];
        else
        {
            if(ans.size()>0)ans.pop_back();
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3628
n = int(input())
t_all, a_all = 0, 0
for i in range(n):
    t, a = map(int, input().split())
    if i == 0:
        t_all = t
        a_all = a
    else:
        if t >= t_all and a >= a_all:
            t_all, a_all = t, a
        else:
            diff1, diff2 = 0, 0
            diff1 = t_all // t if t_all % t == 0 else t_all // t + 1
            diff2 = a_all // a if a_all % a == 0 else a_all // a + 1
            max_diff = max(diff1, diff2)
            t_all = t * max_diff
            a_all = a * max_diff
print(t_all + a_all)
        


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

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

int kaizyou(int N){
  int num=1;
  for(int i=1;i<=N;i++){
  num*=i;
  }
  return num;
}

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


signed main() {
  int k;
  cin >> k;
  int ans=0;
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int l=1;l<=k;l++){
        ans+=gcd(i,gcd(j,l));
      }
    }
  }
  cout << ans << endl;
}

  
  
  

Measured memory_bytes: 3620
n = input()

if int(n)<10:
    print(n)
    exit()

matubi=int(n[-1])
sentou=int(n[0])
keta=len(n)

if n[1:keta-1]=="":
    aida=0
else:
    aida=int(n[1:keta-1])

n=int(n)
def cnt(saisyo,saigo):
    kotae=(10**(keta-2)-1)/9
    if saisyo<sentou:
        kotae+=10**(keta-2)
    elif saisyo==sentou:
        tmp=saisyo*10**(keta-1)+saigo
        while True:
            if str(tmp)[0]==str(saisyo) and tmp<=n:
                kotae+=1
            else:
                break
            tmp+=10
    if saisyo==saigo:
        kotae+=1
    return kotae

ans=0

import itertools
for seq in itertools.product(range(1,10),range(1,10)):
    ans+=cnt(seq[0],seq[1])*cnt(seq[1],seq[0])

print(int(ans))

Measured memory_bytes: 71820
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
constexpr int MX = 200005, MOD = 1e9+7;
int n;
ll c[MX], ans;
ll exp(ll ret, ll n){
	for(ll b = 2; n; n/=2,(b*=b)%=MOD) if(n%2) (ret *= b) %= MOD;
	return ret;
}
int main(){
	scanf("%d", &n);
	rep(i,n) scanf("%lld", c+i);
	sort(c,c+n,greater<ll>());
	rep(i,n) (ans += c[i] * (i+2)) %= MOD;
	printf("%lld\n", exp(ans,n*2-2));
}

Measured memory_bytes: 1792
n,m = map(int,input().split())
low = 1
high = n
for i in range(m):
    l,r = map(int,input().split())
    if l > low:
        low = l
    if r < high :
        high = r
if low > high:
    print(0)
else:
    print(high - low +1)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

int a[200];

int main(){
	int n;
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }

    int ans = 0;
    for(ans=0; true; ans++){
        rep(i,n){
            if(a[i] % 2 != 0){
                cout << ans << endl;
                return 0;
            }
        }

        rep(i,n){
            a[i] /= 2;
        }
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define llu unsigned long long
#define ll long long
#define INF 0x3f3f3f3f
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;

int main()	
{
	#ifdef SANS
		freopen("C:\\Users\\ASUS\\Documents\\Sublime\\input_output\\inputf.txt","r",stdin);
		freopen("C:\\Users\\ASUS\\Documents\\Sublime\\input_output\\outputf.txt","w",stdout);
	#endif
	fast
	int t=1;
	// cin>>t;
	while(t--)
	{
		ll s, w;
		cin>>s>>w;
		if(s<=w)
			cout<<"unsafe\n";
		else
			cout<<"safe\n";
	}
	#ifdef SANS
		cout<<"\nTime Elapsed:"<<1.0*clock()/CLOCKS_PER_SEC <<"sec\n";
	#endif
}

Measured memory_bytes: 3648
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;

struct state{
	int pos;
	int ticket;
	int sum;
	
	bool operator< (const state &s) const{
		return s.sum < sum;
	}
};

struct edge{
	int to;
	int fee;
};

int c, n, m, s, d;
vector<vector<edge> > G;

int solve(){
	vector<vector<int> > v(n + 1, vector<int>(c + 1, 1000000000));

	priority_queue<state> pq;
	pq.push((state){s, c, 0});
	v[s][c] = 0;

	while(!pq.empty()){
		state st = pq.top();
		pq.pop();

		if(v[st.pos][st.ticket] != st.sum){ continue; }
		if(st.pos == d) return st.sum;

		for(int i = 0; i < G[st.pos].size(); ++i){
			int t = G[st.pos][i].to;
			int f = G[st.pos][i].fee + st.sum;
			if(v[t][st.ticket] > f){
				v[t][st.ticket] = f;
				pq.push((state){t, st.ticket, f});
			}
			
			if(st.ticket > 0){
				f = G[st.pos][i].fee / 2 + st.sum;
				if(v[t][st.ticket - 1] > f){
					v[t][st.ticket - 1] = f;
					pq.push((state){t, st.ticket - 1, f});
				}
			}
		}
	}
	return -1;
}

int main(){
	int a, b, f;
	while(scanf("%d%d%d%d%d", &c, &n, &m, &s, &d), n){
		G.assign(n + 1, vector<edge>());
		for(int i = 0; i < m; ++i){
			scanf("%d%d%d", &a, &b, &f);
			G[a].push_back((edge){b, f});
			G[b].push_back((edge){a, f});
		}
		
		printf("%d\n", solve());
	}
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

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

const int MAXN = 2e5 + 5;

int v[MAXN];

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, n) {
		scanf("%d", &v[i]);
		v[i] -= i;
	}
	sort(v, v + n);
	int b = v[n / 2];
	ll ans = 0ll;
	REP(i, 0, n) {
		ans += abs(v[i] - b);
	}
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 1024
n,m = map(int,input().split())
h = list(map(int,input().split()))

ab = [map(int,input().split()) for _ in range(m)]
a,b = [list(i) for i in zip(*ab)]

ans=[]

for i in range(n):
    ans.append(1)

for i in range(m):
    if h[a[i]-1]>=h[b[i]-1]:
        ans[b[i]-1]=ans[b[i]-1]-1
    if h[a[i]-1]<=h[b[i]-1]:
        ans[a[i]-1]=ans[a[i]-1]-1


count=0
for i in range(n):
    if ans[i]==1:
        count=count+1

print(count)


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

#define en "\n"
#define INF (int) 9e18
#define HELL 998244353LL
#define int long long
#define double long double
#define uint unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fs first
#define sc second
#define size(a) (int) a.size()
#define deb(x) cerr << #x << " => " << x << en
#define debp(a) cerr << #a << " => " <<"("<<a.fs<<", "<<a.sc<<") " << en;
#define deba(x) cerr << #x << en; for (auto a : x) cerr << a << " "; cerr << en;
#define debpa(x) cerr << #x << en; for (auto a : x)cerr<<"("<<a.fs<<", "<<a.sc<<") "; cerr << en;
#define debm(x) cerr << #x << en; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << en;}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m = HELL) { int res = 1; a %= m;
while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2)
#define mul(a, b) ((a % HELL) * (b % HELL)) % HELL

int n, s;
const int maxN = 3e3 + 5;
int arr[maxN];
int dp[maxN][maxN];

int res(int pos, int sum) {
	if (sum > s) {
		return 0;
	}
	if (pos == n) {
		return sum == s;
	}
	int &ans = dp[pos][sum];
	if (ans == -1) {
		ans = 0;
		int x = res(pos + 1, sum);
		if (x)
			ans = mul(2, x);
		ans = (ans + res(pos + 1, sum + arr[pos])) % HELL;
	}
	return ans;
}

int32_t main() { fastio;
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	memset(dp, -1, sizeof dp);
	cout << res(0, 0) << endl;
	return 0;
}


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

bool IsEven(int x){
    if(x%2==0){
        return true;
    }
    else{
        return false;
    }
}
bool IsImmigration(int x){
    if(x%3==0){
        return true;
    }
    else if(x%5==0){
        return true;
    }
    else{
        return false;
    }
}

int main(){
    int n; cin >> n;
    bool flg = true;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        if(IsEven(x)==true){
            if(IsImmigration(x)==true){
                flg = true;
            }
            else{
                flg = false;
                break;
            }
        }
    }
    if(flg==true){
        cout << "APPROVED" << endl;
    }
    else{
        cout << "DENIED" << endl;
    }
}

Measured memory_bytes: 384
using System;

class MyClass
{
    public static void Main(string[] args)
    {
        bool first = true;
        string str;
        while ((str = Console.ReadLine()) != "0 0")
        {
            if (!first)
            {
                Console.WriteLine();
            }
            first = false;
            string[] str2 = str.Split(' ');
            int a = int.Parse(str2[0]);
            int b = int.Parse(str2[1]);
            bool na = true;
            for (int i = a; i <= b; i++)
            {
                if (i % 4 == 0 && (i % 100 != 0 || i % 400 == 0))
                {
                    Console.WriteLine(i);
                    na = false;
                }
            }
            if (na)
            {
                Console.WriteLine("NA");
            }
        }
    }
}


Measured memory_bytes: 5640