akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;

int main(){

   int h, w, k;
   string c[6];
   int ans = 0;

   cin >> h >> w >> k;

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

   int num = 0;
   // for(int i = 0; i < h; i++){
   //    for(int j = 0; j < w; j++){
   //       if(c[i][j] == "#"){
   //          num++;
   //       }
   //    }
   // }

   // if(num == k){
   //    ans++;
   // }

   for(int i = 0; i < (1 << h); i++){
      for(int j = 0; j < (1 << w); j++){
         
         num = 0;
         for(int ii = 0; ii < h; ii++){
            if(i & (1 << ii)){
               continue;
            }
            for(int jj = 0; jj < w; jj++){
               if(!(j & (1 << jj))){
                  if(c[ii][jj] == '#'){
                     num++;
                  }
               }
            }
         }

         if(num == k){
            ans++;
            // cout << i << " " << j << endl;
         }

      }
   }

   cout << ans << endl;

   return 0;
}

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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long llint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double pi = 3.14159265358979323846;

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  int n;
  cin >> n;
  vector<llint> x(n);
  rep(i, n) cin >> x[i];

  llint ans = 1e18;
  for (llint p = 0; p <= 100; p++) {
    llint sum = 0;
    for (int j = 0; j < n; j++) {
      sum += (x[j] - p) * (x[j] - p);
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;

  return 0;
}

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

int main(){
    ll h,w;
    cin>>h>>w;
    bool g[w][h];
    ll wn=0;
    rep(i,h){
        string s;
        cin>>s;
        rep(j,w){
            if(s[j]=='.'){
                g[j][i]=true;
                wn++;
            }else{
                g[j][i]=false;
            }
        }
    }
    queue<tuple<ll,ll,ll>> que;
    vector<vector<bool>> used(w,vector<bool>(h,false));
    rep(i,w){
        rep(j,h){
            if(!g[i][j]){
                que.push(make_tuple(i,j,0));
            }
        }
    }
    ll cnt=0;
    ll ma=0;
    while(que.size()){
        tuple<ll,ll,ll> p=que.front();
        que.pop();
        ll x=get<0>(p);
        ll y=get<1>(p);
        ll n=get<2>(p);
        if(cnt==wn){
            cout<<ma<<endl;
            return 0;
        }
        if(x>0&&!used[x-1][y]&&g[x-1][y]){
            que.push(make_tuple(x-1,y,n+1));
            used[x-1][y]=true;
            cnt++;
            ma=max(ma,n+1);
        }
        if(y>0&&!used[x][y-1]&&g[x][y-1]){
            que.push(make_tuple(x,y-1,n+1));
            used[x][y-1]=true;
            cnt++;
            ma=max(ma,n+1);
        }
        if(x<w-1&&!used[x+1][y]&&g[x+1][y]){
            que.push(make_tuple(x+1,y,n+1));
            used[x+1][y]=true;
            cnt++;
            ma=max(ma,n+1);
        }
        if(y<h-1&&!used[x][y+1]&&g[x][y+1]){
            que.push(make_tuple(x,y+1,n+1));
            used[x][y+1]=true;
            cnt++;
            ma=max(ma,n+1);
        }
    }
}


Measured memory_bytes: 25652
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dp[2005][2005];
signed main() {
    int N,M;
    cin >> N >> M;
    vector<int>S(N+1),T(M+1);
    for(int i = 1; i <= N; i++) {
        cin >> S[i];
    }
    for(int i = 1; i <= M; i++) {
        cin >> T[i];
    }
    for(int i = 0; i <= N; i++) {
        dp[i][0] = 1;
    }
    for(int i = 0; i <= M; i++) {
        dp[0][i] = 1;
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= M; j++) {
            if(S[i] == T[j]) {
                dp[i][j] = dp[i][j-1]+dp[i-1][j];
            }
            else {
                dp[i][j] = dp[i][j-1]+dp[i-1][j]+mod-dp[i-1][j-1];
            }
            dp[i][j]%=mod;
        }
    }
    cout << dp[N][M] << endl;
}

Measured memory_bytes: 34780
#include <iostream>
#include <vector>
using namespace std;
int p, out;
int main(){
  int t;
  cin >> t;
  vector<int> v;
  string s;
  while(cin >> s){
    if(s == "HIT"){
      if(v.size()<3)v.push_back(0);
      else p++;
    }else if(s == "OUT"){
      out++;
      if(out == 3){
	cout << p << endl;
	p = out = 0;
	v.clear();
      }
    }else{
      p += v.size() + 1;
      v.clear();
    }
  }
  return 0;
}

Measured memory_bytes: 1228
import scala.io.StdIn._
object Main extends App {
  val n = readInt
  val ss = Array.fill(n)(readLine.sorted)
  def roundRobin(n: Int): Long = n.toLong * (n - 1) / 2
  println(ss.groupBy(identity).mapValues(s => roundRobin(s.size)).values.sum)
}

Measured memory_bytes: 103336
#include<iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <functional>

#define PI 3.14159265358979
#define MOD 1000000007

using namespace std;

int main(void) {
	long long int a, b, l, m, n;
	int x[100000], y[100000];
	string s, t;
	char u;
	int i, j, k;
	bool flag = true;
	cin >> n >> m;
	for (i = 0; i < m; i++) {
		cin >> l;
		n -= l;
		if (n < 0)break;
	}
	if (n < 0)n = -1;
	cout << n << endl;
		/*if(flag)cout << "Yes" << endl;
			else cout << "No" << endl;*/
	return 0;
}

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

const int MAX_N = 2e5;
lint ps[MAX_N+5];

int main(){
  int n; cin >> n;
  
  for(int i=0;i<n;i++){
    lint a; cin >> a;
    ps[i+1] = ps[i] + a;
  }
  
  lint ans = 1e30;
  for(int i=0;i<n-1;i++)
    ans = min(ans, abs(ps[n]-2*ps[i+1]));
    
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#define N 1000

typedef struct cell{
	int data;
	struct cell *next;
}cell;

typedef struct List{
	cell *front;
	cell *rear;
}List;

List L[N];

void dump(int t){
	cell *p=L[t].front;
	
	if(p==NULL)printf("\n");
	else {
		while(p->next!=NULL){
			printf("%d ",p->data);
			p=p->next;
		}
		printf("%d\n",p->data);
	}
	
	return;
}


void insert(int t,int x){
	cell *new=malloc(sizeof(cell));
	new->data=x; new->next=NULL;
	
	if(L[t].front==NULL){
		L[t].front=new;
		L[t].rear=new;
	}
	
	else {
		L[t].rear->next=new;
		L[t].rear=new;
	}
	
	return;	
}


int main(){
	int n,q,com,i,x,y;

	
	scanf("%d %d",&n,&q);
	
	for(i=0;i<n;i++){
		L[i].front=NULL;
		L[i].rear=NULL;
	}
	
	for(i=0;i<q;i++){
		scanf("%d",&com);
		
		if(com==0){
			scanf("%d %d",&x,&y);
			insert(x,y);
			
		}
		
		if(com==1){
			scanf("%d",&x);
			dump(x);
		}
		
		if(com==2){
			scanf("%d %d",&x,&y);
			if(L[y].rear==NULL){
				L[y].front=L[x].front;
				L[y].rear=L[x].rear;
			}
			else {
				L[y].rear->next=L[x].front;
				L[y].rear=L[x].rear;
			}
				L[x].front=NULL;
				L[x].rear=NULL;
		}
		
	}
	
	return 0;
	
}


Measured memory_bytes: 17496
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize
    }

    let mut sum = 1000;

    while sum < n {
        sum += 1000;
    }

    println!("{}", sum - n);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 2264
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

nums=[]

num=0
pow10=1

# add a few possible answers
for i in range(16):
    t="9"*i
    if t!="": nums.append(int(t))
    for j in range(1,1000):
        t=str(j)+"9"*i
        if len(t)>15: continue
        nums.append(int(t))

def dsum(x):
    t=0
    while x:
        t+=x%10
        x//=10
    return t

# remove some bad numbers
out=[]
rat=[]
for i in sorted(set(nums)):
    j=i/dsum(i)
    while rat and rat[-1]>j:
        out.pop(-1)
        rat.pop(-1)
    out.append(i)
    rat.append(j)

#print(len(out))

#for i in range(len(out)): print(i,out[i],rat[i])

#for i in range(len(nums)):
#    print(i,dsum(nums[i]),nums[i]/dsum(nums[i]))

k=int(input())
for i in range(k):
    print(out[i])


Measured memory_bytes: 42348
n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
    xl[i].append(xl[i][0]+xl[i][1])
    if xl[i][0]-xl[i][1]>0: xl[i].append(xl[i][0]-xl[i][1])
    else: xl[i].append(0)
xl = sorted(xl, key=lambda x:x[2])
res = xl[0][2]
count = 1
for i in range(1, n):
    if res <= xl[i][3]:
        count += 1
        res = xl[i][2]
print(count)

Measured memory_bytes: 66392
#include <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
    long long n, m;
    scanf("%lld %lld", &n, &m);
    if(n == 2 || m == 2) printf("0");
    else if(min(n, m) == 1){
        int maximum = max(n, m);
        printf("%lld", maximum == 1 ? 1 : maximum - 2);
    } else 
        printf("%lld", (m-2)*(n-2));
    
    return 0;
}

Measured memory_bytes: 128
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = lc()

print("".join([s[0] , str(len(s[1:-1])) , s[-1]]))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

int main() {
  int t, x;
  cin >> t >> x;

  // x:1 = t:?
  // x*? = t
  // ? = t/x

  cout << t / (double)x << endl;

  return 0;
}

Measured memory_bytes: 256
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 07/17/20 22:14:12
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

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

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

  int a,b; cin>>a>>b;
  cout << lcm(a,b) << endl;

  return 0;
}


Measured memory_bytes: 3624
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
def main():
    T = int(input())
    for _ in range(T):
        N, A, B, C, D = map(int, input().split())
        memo = {}

        def f(n):
            if n == 0:return 0
            if n == 1:return D
            if n in memo:return memo[n]

            ret = min(
                D * n,
                D * (n%2) + A + f(n//2),
                D * abs(n - (n+1)//2*2) + A + f((n+1)//2),
                D * (n%3) + B + f(n//3),
                D * abs(n - (n+2)//3*3) + B + f((n+2)//3),
                D * (n%5) + C + f(n//5),
                D * abs(n - (n+4)//5*5) + C + f((n+4)//5)
            )

            memo[n] = ret
            return ret
        print(f(N))
if __name__ == "__main__":
    main()

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

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


Measured memory_bytes: 3100
#include "bits/stdc++.h"

using namespace std;
using ll = long long int;

template<typename T>
T Gcd(T a, T b)
{
    while (b != 0)
    {
        T next = a % b;
        a = b;
        b = next;
    }

    return a;
}

template<typename T>
std::vector<T> GetDivisors(T n)
{
    std::vector<T> vec;

    for (T i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            vec.push_back(i);
            if (n / i != i)
            {
                vec.push_back(n / i);
            }
        }
    }

    return vec;
}

template<typename T>
bool IsPrime(T n)
{
    if (n <= 1)
    {
        return false;
    }

    T max = static_cast<T>(sqrt(n));

    for (T i = 2; i <= max; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
    }

    return true;
}

int main()
{
    ll a, b;
    cin >> a >> b;

    int ans = 1;
    for (auto &d : GetDivisors(Gcd(a, b)))
    {
        if (IsPrime(d))
        {
            ans++;
        }
    }

    cout << ans << endl;
}

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

using namespace std;

int main()
{
  string s;	cin >> s;
  int ans = 0;
  
  if (s[0] == '1')	++ans;
  if (s[1] == '1')	++ans;
  if (s[2] == '1')	++ans;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        string S = cin.next;
        int N = cin.nextint;
        for (int i = 0; i < S.Length; i++)
        {
            if (i % N == 0)
            {
                Write(S[i]);
            }
        }
        WriteLine();
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int N, R;
  std::cin >> N >> R;

  if(N >= 10) {
    std::cout << R << '\n';
  } else {
    std::cout << R + 100 * (10 - N) << '\n';
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				3.14159265358979
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     sz              size()
#define     len             length()
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define     UB              upper_bound
#define     LB              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define     sqr(a)          ((a)*(a))
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }

bool compare_float(double x, double y){
    return fabs(x - y) < DBL_EPSILON;
}

double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
vll pwx(32);
void cal(ll x){ pwx[0] = 1; rep(i, 1, 32)pwx[i] = x*pwx[i-1]; }
 
/* ################################################################ */

#define space 200005

void solve()
{
    ll a, b; cin>>a>>b;
    cout<<a*b<<nl;
} 
 
int main(){
    // boost;
    // cal(2);
    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}

Measured memory_bytes: 3624
#include <iostream>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;

using namespace std;



int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    rep(i,s.size()-2) {
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3608
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;} 
int main(void)
{
  int k,sl;
  char s[100];
  
  scanf("%d",&k);
  scanf("%s",s);
  
  sl=strlen(s);
  if(k>=sl)
    printf("%s",s);
  if(k<sl)
  {for(int i=0;i<k;i++)
      printf("%c",s[i]);
  printf("...");}
    
    
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	long double n;
	cin>>n;
	long double cnt=0;
	for(ll i=1;i<=n;i++){
		if(i%2!=0){
			cnt++;
		}
	}
	printf("%.9Lf",cnt/n);
	// your code goes here
	return 0;
}

Measured memory_bytes: 384
N = int(input())
A = list(map(int,input().split()))
ans = 0
         
while True:
    flag = True
    for a in A:
        if a % 2 != 0:
            flag = False
    if flag == False:
        break
    for i in range(len(A)):
        A[i] /= 2
    ans += 1
print(ans)


    

Measured memory_bytes: 2940
from collections import defaultdict
n,m=map(int,input().split())
graph = defaultdict(list)
for i in range(m):
  a,b=map(int, input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)

for i in range(0,n):
  if i not in graph:
    print(0)
  else:
    print(len(graph[i]))

Measured memory_bytes: 3316
N=int(input())
Llist=list(map(int,input().split(' ')))
count=0
Llist_sorted=sorted(Llist)
for i in range(N):
    tri=[]
    tri_i=tri+[Llist_sorted[i]]
    for j in range(i+1,N):
        tri=tri_i
        tri_ij=tri+[Llist_sorted[j]]
        for k in range(j+1,N):
            tri=tri_ij
            tri_ijk=tri+[Llist_sorted[k]]
            if tri_ijk[0]<tri_ijk[1]<tri_ijk[2] and tri_ijk[0]+tri_ijk[1]>tri_ijk[2]:
                count+=1
print(count)

Measured memory_bytes: 9208
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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=1e18;

int main()
{
    ll n,k;
    cin >> n >> k;
    vector<ll> p,q;
    rep(i,n){
        ll x;
        cin >> x;
        if(x>=0) p.push_back(x);
        else q.push_back(-x);
    }
    sort(p.begin(),p.end());
    sort(q.begin(),q.end());
    ll r=p.size();
    ll s=q.size();
    ll ans=INF;
    rep(i,r){
        if(0<=k-i-2 && k-i-2<=s-1){
            ans=min(ans,p[i]*2+q[k-i-2]);
        }
        if(i==k-1){
            ans=min(ans,p[i]);
        }
    }
    rep(i,s){
        if(0<=k-i-2 && k-i-2<=r-1){
            ans=min(ans,q[i]*2+p[k-i-2]);
        }
        if(i==k-1){
            ans=min(ans,q[i]);
        }
    }
    cout << ans << endl;
    return 0;
} 


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    string s; cin >> s;

    if (s == "AAA" || s == "BBB") {
        puts("No");
    } else {
        puts("Yes");
    }
}

Measured memory_bytes: 256
class Main{public static void main(String[]z){java.util.Scanner s=new java.util.Scanner(System.in);for(int n,i,j,b,k,r,g[],p,f[]={1,20,-20,-1};(i=r=n=s.nextInt())>0;System.out.println(r>0?"No":"Yes")){for(g=new int[n],p=210;i-->0;)g[i]=s.nextInt()+20*s.nextInt();for(i=s.nextInt();i-->0;)for(k=f["ENSW".indexOf(s.next().charAt(0))],b=s.nextInt();b-->0;)for(p+=k,j=n;j-->0;)if(p==g[j])r+=g[j]=-1;}}}

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

k = gets.chomp.split(' ').map(&:to_i)

if k[0] == k[2] * 2 && k[1] == k[3] * 2
  puts "#{k[0] * k[1] /2.0} 1"
else
  puts "#{k[0] * k[1] /2.0} 0"
end


# k = gets.chomp.split.map(&:to_i)
# l = gets.chomp.split.map(&:to_i)

# len = 0
# count = 1
# l.each do |v|
#   len += v
#   break if len > k[1]
#   count += 1
# end

# puts count

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

int main() {
  long long D, p = 300, q = 0, mon = 1000;
  cin >> D;
  bool b = true;
  for (int i = 0; i < D; i++) {
    int x;
    cin >> x;
    if (b) {
      if (p > x) p = x;
      if (p < x) {
        b = !b;
        q = x;
      }
    }
    else {
      if (q < x) q = x;
      if (q > x) {
        b = !b;
        mon = mon/p*q + (mon%p);
        p = x;
        q = 0;
      }
    }
  }
  if (p < q) mon = mon/p*q + (mon%p);
  cout << mon << endl;
}

Measured memory_bytes: 3580
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){
   int n;
   cin >> n;
   vector<int> p(n);
   rep(i,n) cin >> p[i];
   int k=0;
   rep(i,n) if(p[i] != i+1) k++;
   if(k<=2) cout << "YES" << endl;
   else cout << "NO" << endl;


   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100
void dep(int);
int G[N+1][N+1],s[N+1],de[N+1],f[N+1],n,w=1;
int  main(){
  int i, j, u, v;
  scanf("%d", &n);
  for(i=1;i<=n;i++){
    de[i]=0;
    f[i] = 0;
    scanf("%d", &u);
    scanf("%d", &s[u]);
    for(j=1;j<=s[u];j++) scanf("%d", &G[u][j]);
  }
  for(i=1;i<=n;i++) {
    if(!de[i]) dep(i);
  }
  for(i=1;i<=n;i++) {
    printf("%d %d %d\n", i, de[i], f[i]);
  }
  return 0;
}
void dep(int p){
  int i;
  de[p] = w++;
  for(i=1;i<=s[p];i++) {
    if(!de[G[p][i]]) dep(G[p][i]);
  }
  f[p] = w++;
}


Measured memory_bytes: 2112
#include <algorithm>
#include <iostream>
#include <string>

void process(int s)
{
    // 数値を文字列に変換する。
    std::string str = std::to_string(s);

    // '1' の要素数を数える。
    int count = std::count_if(str.begin(), str.end(), [](char c) { return c == '1'; });

    std::cout << count << std::endl;
}

int main()
{
    int s;
    std::cin >> s;

    process(s);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(LL i=0;i<(LL)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pll pair<LL,LL>

using namespace std;


int main(){

    LL W,H;cin>>W>>H;
    LL p[W],q[H];
    REP(i,W)cin>>p[i];
    REP(i,H)cin>>q[i];
    priority_queue<LL,vector<LL>,greater<LL> > quep;
    priority_queue<LL,vector<LL>,greater<LL> > queq;
    REP(i,W)quep.push(p[i]);
    REP(i,H)queq.push(q[i]);
    int cntp=0,cntq=0;

    LL ans=0;

    while(cntp<W||cntq<H){
        int nextp=1000000000;
        int nextq=1000000000;
        if(cntp<W){
            nextp=quep.top();
        }
        if(cntq<H){
            nextq=queq.top();
        }

        if(nextp<nextq){
            ans+=nextp*(H-cntq+1);
            cntp++;
            quep.pop();
        }else{
            ans+=nextq*(W-cntp+1);
            cntq++;
            queq.pop();
        }
    }
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 4212
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>

using namespace std;

int main()
{

	long N, M;
	cin >> N >> M;
	long H[N];
	long A[M], B[M];
	int good[N];
	int ans = 0;
	for(int i = 0; i < N; i++){
		cin >> H[i];
		good[i] = 1;
	}	
	for(int i = 0; i < M; i++){
		cin >> A[i] >> B[i];
		if(H[A[i] - 1] <= H[B[i] - 1]) good[A[i] - 1] = 0;
		if(H[A[i] - 1] >= H[B[i] - 1]) good[B[i] - 1] = 0;
	}
		
	for(int i = 0;i < N; i++){
		if(good[i] == 1) ans++;
	}

	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 6316
process.stdin.resume();
process.stdin.setEncoding('utf8');
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  var n = parseInt(lines[0]);
  if(n == 0){
    n = 1;
  }else if(n == 1){
    n = 0;
  }
  console.log(n);
});

Measured memory_bytes: 30128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define MAXN 200010
long long A[MAXN << 2], B[MAXN << 2], T[MAXN << 2];
inline void pushDown(int x) {
	if (!T[x])return;
	A[x << 1] += T[x]; A[x << 1 | 1] += T[x];
	B[x << 1] += T[x]; B[x << 1 | 1] += T[x];
	T[x << 1] += T[x]; T[x << 1 | 1] += T[x];
	T[x] = 0;
}
inline void pushUp(int x) {
	A[x] = std::min(A[x << 1], A[x << 1 | 1]);
	B[x] = std::min(B[x << 1], B[x << 1 | 1]);
}
void Insert(int n, int l, int r, int x, long long v) {
	if (l == r) {
		A[n] = std::min(A[n], v - x); B[n] = std::min(B[n], v + x); return;
	}
	pushDown(n); int mid = (l + r) >> 1;
	if (x <= mid)Insert(n << 1, l, mid, x, v);
	else Insert(n << 1 | 1, mid + 1, r, x, v);
	pushUp(n);
}
void Insert(int n, int l, int r, int L, int R, long long v) {
	if (l == L && r == R) {
		A[n] += v; B[n] += v; T[n] += v; return;
	}
	pushDown(n); int mid = (l + r) >> 1;
	if (R <= mid)Insert(n << 1, l, mid, L, R, v);
	else if (L > mid)Insert(n << 1 | 1, mid + 1, r, L, R, v);
	else Insert(n << 1, l, mid, L, mid, v), Insert(n << 1 | 1, mid + 1, r, mid + 1, R, v);
	pushUp(n);
}
long long a(int n, int l, int r, int L, int R) {
	if (l == L && r == R)return A[n];
	pushDown(n); int mid = (l + r) >> 1;
	if (R <= mid)return a(n << 1, l, mid, L, R);
	else if (L > mid)return a(n << 1 | 1, mid + 1, r, L, R);
	return std::min(a(n << 1, l, mid, L, mid), a(n << 1 | 1, mid + 1, r, mid + 1, R));
}
long long b(int n, int l, int r, int L, int R) {
	if (l == L && r == R)return B[n];
	pushDown(n); int mid = (l + r) >> 1;
	if (R <= mid)return b(n << 1, l, mid, L, R);
	else if (L > mid)return b(n << 1 | 1, mid + 1, r, L, R);
	return std::min(b(n << 1, l, mid, L, mid), b(n << 1 | 1, mid + 1, r, mid + 1, R));
}
int n, q, p[MAXN], x;
int main() {
	scanf("%d%d%d", &n, &q, &x);
	for (int i = 0; i <= q; i++)scanf("%d", &p[i]);
	memset(A, 0x3F, sizeof(A)); memset(B, 0x3F, sizeof(B));
	Insert(1, 1, n, x, 0);
	for (int i = 1; i <= q; i++) {
		long long now = std::min(a(1, 1, n, 1, p[i]) + p[i], b(1, 1, n, p[i], n) - p[i]);
		Insert(1, 1, n, 1, n, std::abs(p[i] - p[i - 1]));
		Insert(1, 1, n, p[i - 1], now);
	}
	long long ans = 0x7FFFFFFFFFFFFFFF;
	for (int i = 1; i <= n; i++) {
		ans = std::min(ans, a(1, 1, n, i, i) + i);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 19840
import java.awt.*;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int arr[][]=new int[n][3];
        for (int i=0;i<n;i++){
            for (int j=0;j<3;j++){
                arr[i][j]=sc.nextInt();
            }
        }
        int dp[][]=new int[n][3];
        dp[0]=arr[0];
        for (int i=1;i<n;i++){
            dp[i][0]=Math.max(dp[i-1][1],dp[i-1][2])+arr[i][0];
            dp[i][1]=Math.max(dp[i-1][0],dp[i-1][2])+arr[i][1];
            dp[i][2]=Math.max(dp[i-1][1],dp[i-1][0])+arr[i][2];
        }
        System.out.println(Math.max(Math.max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]));
    }
}

Measured memory_bytes: 98544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define LINY "YES\n"
#define Liny "Yes\n"
#define LINN "NO\n"
#define Linn "No\n"
#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"

ll min(ll x,ll y){return (x<y ? x:y);}
ll max(ll x,ll y){return (x>y ? x:y);}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}

ld func(ld i,ld K){
  int temp = i;
  int count = 0;
  while(temp<K){
    temp *= 2;
    ++count;
  }
  return (ld)1./(ld)pow(2,count);
}

int main(){
  ld N,K; cin>>N>>K;
  ld r = 0;
  for(int i=1;i<=N;i++){
    r += func(i,K);
  }
  r /= N;
  printf("%.12Lf",r);
}

Measured memory_bytes: 512
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void printArray(List<Integer> array) {
		StringBuilder sb = new StringBuilder();
		sb.append(array.get(0));
		for (int j = 1; j < array.size(); j++) {
			sb.append(" ").append(array.get(j));
		}
		System.out.println(sb.toString());
	}
	public static List<Integer> insertSort (List<Integer> baseArray) {
		printArray(baseArray);
		for (int i = 1; i < baseArray.size(); i++) {
			int key = baseArray.get(i);
			int j = i - 1;
			while (j >= 0 && baseArray.get(j) > key) {
				baseArray.set(j + 1, baseArray.get(j));
				j--;
			}
			baseArray.set(j + 1, key);
			//System.out.println("Processing array=" + baseArray);
			printArray(baseArray);
		}
		return baseArray;
	}

	public static void solve (InputStream ins) {
		Scanner sc = new Scanner(ins);
		int num = sc.nextInt();
		List<Integer> baseArray = new ArrayList<Integer>();
		for (int i = 0; i  < num; i++) {
			baseArray.add(sc.nextInt());
		}
		insertSort(baseArray);
	}

	public static void main (String[] args) {
		solve(System.in);
	}
}

Measured memory_bytes: 22592
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main(int argc, char **argv)
{
	int n, tmp;
	int *array;
	
	while(cin >> n){
		array = (int *)calloc(n, sizeof(int));
		
		for(int i = 0; i < n; i++){
			cin >> array[i];
		}
		sort(array, array+n);
		
		tmp = array[0];
		for(int i = 1; i < (n); i++){
			array[i] += array[i-1];
			tmp += array[i];
		}
		
		cout << tmp << endl;
		free(array);
	}
	
	return 0;
}

Measured memory_bytes: 0
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n = int(input())
a = [int(i) for i in readline().split()]

ans = [0]*n

for i in range(n-1,-1,-1):
    ai = a[i]
    j = i+1
    while i < n:
        if ans[i]: ai ^= 1
        i += j
    ans[j-1] = ai

#print(ans)

res = [i+1 for i,c in enumerate(ans) if c]

print(len(res))
print(*res)











Measured memory_bytes: 14108
# ABC103 C /\/\/\/

from collections import Counter
import sys
N = int(input())
v = [int(i) for i in input().split()]
A = []
B = []
for i in range(N):
    if i % 2 == 0:
        A.append(v[i])
    else:
        B.append(v[i])
S = Counter(A).most_common(2) + [(0,0)]
T = Counter(B).most_common(2) + [(0,0)]
if S[0][0] != T[0][0]:
    print(N - S[0][1] - T[0][1])
    sys.exit()
a = S[0][1] + T[1][1]
b = S[1][1] + T[0][1]
x = max(a, b)
print(N - x)

Measured memory_bytes: 63724
# int(input()) # 入力が1つ
from collections import defaultdict
n, k = map(int, input().split()) # 入力が複数
nums = [int(i) for i in input().split()] # 配列で数字

nums = [0] + nums
for i in range(n):
    nums[i + 1] = (nums[i] + nums[i + 1] + k - 1) % k
ans = 0
d = defaultdict(int)
for i in range(n + 1):
    ans += d[nums[i]]
    d[nums[i]] += 1
    if i - (k - 1) >= 0:
        d[nums[i - (k - 1)]] -= 1
print(ans)


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

int main(void){
  int n;
  while(cin >> n,n){
  vector<vector<char> > c(n,vector<char>(2));
  const int first = 0;
  const int second = 1;
  while(n--){
    cin>>c[n][first]>>c[n][second];
  }
  cin>>n;
  char in;
  string ans;
  while(n--){
    cin>>in;
    for(int i = 0 ; i < c.size() ; i ++){
      if(in == c[i][first]){
        in = c[i][second];
        break;
      }
    }
    ans+=in;
  }
  cout<<ans<<endl;
  }
}

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

int main ()
{
    int n;
    cin >> n;
    long long a[n], b[n];
    for (int i = 0; i<n; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    sort (b, b+n);
    long long x, y;
    x = b[n/2-1];
    y = b[n/2];
    for (int i = 0; i<n; i++){
        if (a[i] <= x)
            cout << y << endl;
        else
            cout << x << endl;
    }
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    ll gap;
    int i;
    bool flag = true;
    for(i = n-1; i >=1; i--){
        gap = h[i]-h[i-1];
        if(gap == -1) {h[i-1]--;}
        else if(gap < -1) flag = false;
    }

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

    return 0;
}

Measured memory_bytes: 1024
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
// ------ Classes ------ //
class Point {
public:
	long double px, py;
	Point() : px(0), py(0) {};
	Point(long double px_, long double py_) : px(px_), py(py_) {};
	friend bool operator==(const Point& p1, const Point& p2) { return p1.px == p2.px && p1.py == p2.py; }
	friend bool operator!=(const Point& p1, const Point& p2) { return p1.px != p2.px || p1.py != p2.py; }
	friend bool operator<(const Point& p1, const Point& p2) { return p1.px < p2.px ? true : (p1.px == p2.px && p1.py < p2.py); }
	friend bool operator>(const Point& p1, const Point& p2) { return p1.px > p2.px ? true : (p1.px == p2.px && p1.py > p2.py); }
	friend bool operator<=(const Point& p1, const Point& p2) { return !(p1 > p2); }
	friend bool operator>=(const Point& p1, const Point& p2) { return !(p1 < p2); }
	friend Point operator+(const Point& p1, const Point& p2) { return Point(p1.px + p2.px, p1.py + p2.py); }
	friend Point operator-(const Point& p1, const Point& p2) { return Point(p1.px - p2.px, p1.py - p2.py); }
	friend Point operator*(const Point& p1, long double d) { return Point(p1.px * d, p1.py + d); }
	friend Point operator*(long double d, const Point& p1) { return p1 * d; }
	friend Point operator/(const Point& p1, long double d) { return Point(p1.px / d, p1.py / d); }
	Point& operator+=(const Point& p1) { px += p1.px; py += p1.py; return *this; }
	Point& operator-=(const Point& p1) { px -= p1.px; py -= p1.py; return *this; }
	Point& operator*=(long double d) { px *= d; py *= d; return *this; }
	Point& operator/=(long double d) { px /= d; py /= d; return *this; }
};
// ------ Functions ------ //
long double norm(const Point& a) { return a.px * a.px + a.py * a.py; }
long double abs(const Point& a) { return sqrtl(norm(a)); }
long double dot(const Point& a, const Point& b) { return a.px * b.px + a.py * b.py; }
long double crs(const Point& a, const Point& b) { return a.px * b.py - a.py * b.px; }
long double area(vector<Point> v) {
	long double ret = 0.0L;
	for (int i = 0; i < v.size(); i++) ret += crs(v[i], v[(i + 1) % v.size()]);
	return ret / 2;
}
// ------ Main ------ //
int n; vector<Point> v;
int main() {
	cin >> n; v.resize(n);
	for (int i = 0; i < n; i++) cin >> v[i].px >> v[i].py;
	printf("%.1Lf\n", area(v));
	return 0;
}

Measured memory_bytes: 3296
word=''
com = ""
a = 0
b = 0
word=str(raw_input())
num=int(raw_input())
for i in range(num):
    add= raw_input().split()
    com = add[0]
    a = int(add[1])
    b = int(add[2])
    if com == 'replace':
        word = word[0:a] + add[3] + word[b+1:]
       # word = word.replace(word[a:b+1],add[3])
    elif com == 'reverse':
        tmp = word[a:b+1]
        word = word[0:a] + tmp[::-1] + word[b+1:]
    elif com == 'print':
        print word[a:b+1]
    else :
        break

Measured memory_bytes: 6452
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<list>
#define LL long long
#define FF(i,a,b) for(int i=a;i<=b;++i)
#define RR(i,a,b) for(int i=a;i>=b;--i)
#define SC(x) scanf("%d",&x)
#define SCC(x,y) scanf("%d%d",&x,&y)
#define SCCC(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define SS(x) scanf("%s",x)
#define PR(x) printf("%d\n",x)
#define CL(a,b) memset(a,b,sizeof(a))
#define ll rt<<1
#define rr rt<<1|1
#define mid int m=(x+((y-x)>>1))
#define lson x,m,rt<<1
#define rson m+1,y,rt<<1|1
#define lowbit(x) (x&-x)
#define PB push_back
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define fi freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
using namespace std;

const int N = 1e5 + 10;
const int inf = 1e9;

int n, m;
int a[N], R[N], L[N];
LL f[N], val[N];
int main()
{


    SCC(n, m);
    FF(i, 1, n) SC(a[i]);
    f[1] = 0;
    int cnt = 0;
    LL sum = 0;
    FF(i, 1, n-1)
    {
        int l = a[i], r = a[i+1];
        if(r - l < 0) sum += m + r - l, val[r] += m + r - l - 1;
        else sum += r - l, val[r] += r - l - 1;
        ///
        ++L[l]; ++R[r];

        if(r > l) continue;
        ++cnt;
        f[1] += m+1 - l - 1;
    }
    LL mx = f[1];
    FF(i, 2, m)
    {
        cnt -= R[i-1];
        f[i-1] -= val[i-1];
        f[i] = f[i-1] + cnt;
        cnt += L[i-1];
        mx = max(mx, f[i]);
    }
    printf("%lld\n", sum-mx);
    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <string>
using namespace std;
int main(){
int n, p;
cin >> n;
int min = n;
int count = 0;  
for (int i=0; i<n; i++){
  	
	cin >> p;
	if (p <= min){
      count++;
      min = p;        
    }
	}
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long a,b,x;
  cin >> a >> b >>x;
  long A = (a%x == 0? a/x:a/x +1);
  long B = b/x;
  cout << ( B-A >= 0 ? (B-A)+ 1:0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int a[11] = {}, num;
    for(int i=0;i<4;i++){
        cin >> num;
        a[num] = 1; 
    }
    
    if(a[1] == 1 && a[9] == 1 && a[7] == 1 && a[4] == 1)    
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

int main()
{
  uint64_t N, X;
  cin >> N >> X;
  vector<uint64_t> v {X};
  for (auto i = 0; i < N; i++) {
    uint64_t x;
    cin >> x;
    v.push_back(x);
  }
  sort(begin(v), end(v));
  vector<uint64_t> distance;
  for (auto i = 1; i < v.size(); i++) {
    distance.push_back(v[i] - v[i - 1]);
  }
  sort(begin(distance), end(distance));
  uint64_t n {distance[0]};
  for (auto i = 0; i < distance.size(); i++) {
    n = __gcd(n, distance[i]);
  }
  cout << n << endl;
}


Measured memory_bytes: 2548
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, a, b, c := scanInt(), scanInt(), scanInt(), scanInt()

	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = scanString()
	}

	ans := make([]string, n)
	for i := 0; i < n; i++ {
		if s[i] == "AB" {
			if a < b || a == b && (i+1 == n || s[i+1] == "AB" || s[i+1] == "AC") {
				a++
				b--
				ans[i] = "A"
			} else {
				a--
				b++
				ans[i] = "B"
			}
		} else if s[i] == "BC" {
			if b < c || b == c && (i+1 == n || s[i+1] == "BC" || s[i+1] == "AB") {
				b++
				c--
				ans[i] = "B"
			} else {
				b--
				c++
				ans[i] = "C"
			}
		} else {
			if a < c || a == c && (i+1 == n || s[i+1] == "AC" || s[i+1] == "AB") {
				a++
				c--
				ans[i] = "A"
			} else {
				a--
				c++
				ans[i] = "C"
			}
		}

		if a < 0 || b < 0 || c < 0 {
			fmt.Fprintln(wr, "No")
			return
		}
	}

	fmt.Fprintln(wr, "Yes")
	for i := 0; i < n; i++ {
		fmt.Fprintln(wr, ans[i])
	}
}


Measured memory_bytes: 6980
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	int sum = 0;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	int use = n * (n + 1) / 2;
	if (sum%use) {
		cout << "NO" << endl;
		return 0;
	}
	sum /= use;
	int s = 0;
	int cnt = 0;
	rep(i, n) {
		int x = a[i] + sum;
		int y = a[(i + 1) % n];
		if ((x - y) % n || x < y) {
			cout << "NO" << endl;
			return 0;
		}
		cnt = (x - y) / n;
		s += cnt;
	}
	cout << (sum == s ? "YES" : "NO") << endl;
}

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

struct Node{
	int x, y;
};

const int N = 1e5 + 10;

Node a[N];
int rec[N], pos[N], used[N];

int main(){
	int n, cnt, now;
	scanf("%d",&n);
	for (int i = 1; i <= n; i++){
		scanf("%d",&a[i].x);
		rec[i] = a[i].x;
	}
	for (int i = 1; i <= n; i++) scanf("%d",&a[i].y);
	sort(a + 1, a + n + 1, [&](Node x, Node y){return x.y < y.y;});
	sort(rec + 1, rec + n + 1);
	for (int i = n; i >= 1; i--){
		if (rec[i] > a[i].y){
			printf("No\n");
			return 0;
		}
		if (i > 1 && rec[i] <= a[i - 1].y){
			printf("Yes\n");
			return 0;
		}
	}
	for (int i = 1, d; i <= n; i++){
		d = lower_bound(rec + 1, rec + n + 1, a[i].x) - rec;
		pos[d] = i;
	}
	cnt = 0; now = 1;
	while (!used[now]){
		used[now] = 1;
		cnt++;
		now = pos[now];
	}
	if (cnt == n) printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>

using namespace std;

int main(){
	long long s,c;
	cin >> s >> c;
	if(s>=(c/2))
		cout << c/2;
	else{
		c/=2;
		c-=s;
		s+=(c/2);
		cout << s;
	}
	return 0;
}

Measured memory_bytes: 256