akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = [int(i) for i in input().split()]

m_count = 0
p_count = 0

s = [0]*n
s[0] = a[0]

# // - start
if a[0] >= 0:
    tmp = -a[0] -1
    s[0] += tmp
    m_count += abs(tmp)

for i in range(1,n):
    s[i] = s[i-1] + a[i]

    if s[i] == 0:
        tmp = -s[i-1]//abs(s[i-1])
        s[i] += tmp
        m_count += abs(tmp)
    elif s[i] * s[i-1] > 0:
        tmp = (-s[i]) + (-s[i]//abs(s[i]))
        s[i] += tmp
        m_count += abs(tmp)

# // + start
s[0] = a[0]

if a[0] <= 0:
    tmp = -a[0] +1
    s[0] += tmp
    p_count += abs(tmp)

for i in range(1,n):
    s[i] = s[i-1] + a[i]

    if s[i] == 0:
        tmp = -s[i-1]//abs(s[i-1])
        s[i] += tmp
        p_count += abs(tmp)
    elif s[i] * s[i-1] > 0:
        tmp = (-s[i]) + (-s[i]//abs(s[i]))
        s[i] += tmp
        p_count += abs(tmp)

print(min(p_count,m_count))


Measured memory_bytes: 14332
n, m, x, y = map(int, input().split())

xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

maxX = max(xs)
minY = min(ys)

for tmpZ in range(maxX+1, minY+1):
	if x < tmpZ <= y:
		print("No War")
		break
else:
	print("War")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;

int n, m;
ll res = LLONG_MAX;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  vector<p> key;
  rep(i, m){
    int a, b;
    cin >> a >> b;
    int s = 0;
    rep(j, b){
      int c;
      cin >> c;
      c--;
      s |= (1<<c);
    }
    key.push_back({s, a});
  }
  vector<ll> dp(1<<n, INT_MAX);
  dp[0] = 0;
  rep(s, 1<<n){
    rep(i, m){
      int t = s | key[i].first;
      ll cost = dp[s] + key[i].second;
      dp[t] = min(dp[t], cost);
    }
  }


  // print(dp);
  if(dp[(1<<n)-1] == INT_MAX) cout << -1 << endl;
  else cout << dp.back() << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define nikal ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    long long a,b,n,x;
    cin>>a>>b>>n;
    x=min(b-1,n);
    cout<<floor(a*x/b);
    return 0;
}


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

int main()
{
  int n;
  ll k;
  cin >> n >> k;
  int bit_ctr[M] = {};
  ll a[n];
  rep(i, n) {
    cin >> a[i];
    rep(j, M) {
      bit_ctr[j] += (int)((a[i] >> j) & 1LL);
    }
  }
  ll x = 0;
  for (int i = M-1; i >= 0; --i) {
    if (bit_ctr[i] > n/2) continue;
    ll tmp = 1LL << i;
    if (x + tmp  <= k) {
      x += tmp;
    }
  }

  ll ans = 0;
  rep(i, n) {
    ans += x ^ a[i];
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
	int n,m;
	int a,b;
	scanf("%d %d", &n, &m);
	if(n != 0)
	{
		a = n * (n-1) * 0.5;
	}
	else
	{
		a = 0;
	}
	if(m != 0)
	{
		b = m * (m-1) * 0.5;
	}
	else
	{
		b = 0;
	}
	printf("%d", a + b);
}

Measured memory_bytes: 128
H, W = map(int, input().split(' '))
board = [input() for i in range(H)]
dx = [1, 0, -1, 0]
dy = [0, -1, 0, 1]
ans = True
for i in range(H):
    for j in range(W):
        if (board[i][j] == '#'):
            isFound = False
            for d in range(len(dx)):
                x = i + dx[d]
                y = j + dy[d]
                if (x < 0 or H <= x):
                    continue
                if (y < 0 or W <= y):
                    continue
                if (board[x][y] == '#'):
                    isFound = True
            if (isFound is False):
                ans = False
if (ans):
    print('Yes')
else:
    print('No')


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

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

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

#[allow(unused_macros)]
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

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

fn main() {
    input! {
        b: chars,
    }
    let result = match b[0] {
        'A' => 'T',
        'C' => 'G',
        'G' => 'C',
        'T' => 'A',
        _ => 'x'
    };
    println!("{}", result);
}


Measured memory_bytes: 4476
#include <stdio.h>

int check(int *n, int b){
  for(int i=0; i < 4;i++){
    if(n[i] == b)
      return 1;
  }
  return 0;
}

int main() {
  int n[4], i, flag=0;
  int b[4] = {1, 9, 7, 4};
  for(i=0; i < 4; i++){
    scanf("%d", &n[i]);
  }
  for(i=0; i < 4; i++){
    if(!check(n, b[i])){
      flag = 1;break;
    }
  }
  if(flag==1){
    printf("NO\n");
  }else
    printf("YES\n");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;

int main()
{
    set<int> s;
    int n; cin >> n;
    vector<int> pairs;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (s.find(a) != s.end()) {
            pairs.push_back(a);
            s.erase(a);
        } else {
            s.insert(a);
        }
    }
    if (pairs.size() < 2) {
        cout << 0 << endl;
    } else {
        sort(pairs.begin(), pairs.end(), greater<int>());
        cout << (long)pairs[0] * pairs[1] << endl;
    }
    return 0;
}

Measured memory_bytes: 4992
n = int(input())
ls = list(map(str, input().split()))

for i in range(n):
    v = ls[i]
    j = i - 1
    while j >= 0 and int(ls[j]) > int(v):
        ls[j+1] = ls[j]
        j -= 1
    ls[j+1] = v
    print(' '.join(ls))


Measured memory_bytes: 5596
#include "cstdio"
#include "cstring"
int max(int x,int y){
	return x>y?x:y;
}
int min(int x,int y){
	return x<y?x:y;
}
char s[100005];int ss=1e9;
int main(){
	scanf("%s",s);int x=strlen(s);
	for(int i=1;i<x;i++){
		if(s[i]!=s[i-1])ss=min(ss,max(i,x-i));
	}
	printf("%d\n",min(ss,x));
} 

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

int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  int cnt=0;
  bool odd=false;
  while(true){
    
  for (int i=0; i<n; i++){
    if(a[i] %2 != 0){
      odd =true;
    }
  }
    if(odd) break;
    
    
  for(int i=0; i<n; i++){
      a[i]/=2;
  }
    cnt++;
  }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int main(){
  int N;
  cin >> N;
  int prev = 0;
  LL ret = 0;
  REP(i, N) {
    int A;
    cin >> A;
    if(prev <= A) {
      prev = A;
    } else {
      ret += prev - A;
    }
  }
  cout << ret << endl;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li k;
    cin >> k;

    if (k < 10000000000000000) {
        puts("2");
        if (k % 3 != 1) {
            cout << "1 " << k << endl;
        } else {
            cout << "0 " << k + 1 << endl;
        }
        return 0;
    }

    puts("50");

    k += 50 * 49;
    li base = k / 50;
    li base2 = base;
    li amari = k % 50;

    li res[50];
    li idx = 0;
    while (amari > 0) {
        li num = min(20ll, amari);
        res[idx] = base + num * 50 - 49;
        base2 -= num;
        amari -= num;
        ++idx;
    }
    repp(i, idx, 50) {
        res[i] = base2;
    }

    rep(i, 50) {
        cout << res[i] << " ";
    } cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits//stdc++.h>
using namespace std;
int main(){
    int n, a, b, i; string s;
    map<string,int> v;
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> a >> s;
        if (a == 0) {
            cin >> b;
            v[s] = b;
        }
        else if (a == 1) {
            cout << v[s] << endl;
        }
        else {
            v[s] = 0;
        }
    }
}


Measured memory_bytes: 27848
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];


int main(){
    long long a,b;
    cin>>a>>b;
    while(a!=0&&b!=0){
        if(a>=b){
            long long tes=a;
            a=b;
            b=tes%b;
        }
        else{
            long long tes=b;
            b=a;
            a=tes%b;  
        }
    }
    if(a!=0){
        cout<<a<<endl;
    }
    else{
        cout<<b<<endl;
    }
    
}









Measured memory_bytes: 3108
#include<iostream>
#include<stdio.h>
#include<climits>

using namespace std;
#define inf INT_MAX
int main()
{
  int N;

  string a,b,c;
  cin>>N>>a>>b>>c;


  int dp[1000];
  for(int i = 0;i<100;i++) dp[i] = inf;
  dp[0] = 0;
  for(int i = 0;i<N;i++)
  {
      if(a[i] == b[i] && b[i] == c[i])
      {
        dp[i + 1] = dp[i];
      }
      else if(a[i] == b[i] ||b[i] == c[i] || c[i] == a[i])
      {
        dp[i + 1] = dp[i] + 1;
      }
      else
      {
        dp[i + 1] = dp[i] + 2;   
      }
  }
 
  cout<<dp[N]<<endl;
  
  

}

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



int main() {
	int A, B, C;
	int amari;
	cin >> A >> B >> C;

	amari = A % B;
	
	for (int i = 1; i <= B; i++) {
		if ((amari * i) % B == C) {
			cout << "YES" << endl;
			return 0;
		}
	}
	
	cout << "NO" << endl;
}

Measured memory_bytes: 256
s = input()
n = len(s)

mod = 2019

d = {}
d[0] = 1
t, p = 0, 1
for i in range(n-1, -1, -1):
	t = (t + p * int(s[i])) % mod
	d[t] = d.get(t, 0) + 1
	p = p * 10 % mod

print(sum(x * (x - 1) // 2 for x in d.values()))

Measured memory_bytes: 68584
def f(n):
    return (n//2)*(n%2==0) + (3*n+1)*(n%2==1)

def main():
    s = int(input())
    sets = set([])
    lists = []
    m = 0
    for _ in range(pow(10,5)):
        lists.append(s)
        sets.add(s)
        if len(sets) != len(lists):
            break
        s = f(s)
        m += 1
    print(m+1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n = 10;
  vector<int> a(n,0);
  vector<int> b(n,0);
  for(int i = 0;i < n;i++){
    cin >> a[i];
  }
  for(int i = 0;i < n;i++){
    cin >> b[i];
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  int sum_a = 0;
  int sum_b = 0;
  for(int i = n-1;i > n-4;i--){
    sum_a += a[i];
    sum_b += b[i];
  }
  cout << sum_a << " " << sum_b << endl;

  return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

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

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

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

int main() {

  int n, k;
  cin >> n >> k;

  int cnt = 0;
  while(n!=0) {
    n /= k;
    ++cnt;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
import sys


class DataUnit(object):

    def __init__(self, c, t):
        self.c = c
        self.t = t
        pass


def judging_TIME(t, max_T):
    if(t <= max_T): return True
    else: return False


def judging_COST(datali):

    if(len(datali)==0): return "TLE"

    min_cost = 10000
    for d in datali:
        if(d.c < min_cost):
            min_cost = d.c

    return min_cost


# get from std-I/O.
def loading_inputs():
    N, T = raw_input().split()
    N, T = int(N), int(T) 

    datalist = []
    for i in range(N):
        c_i, t_i = raw_input().split()
        c_i, t_i = int(c_i), int(t_i)

        if judging_TIME(t_i, T):
            obj = DataUnit(c_i, t_i)
            datalist.append(obj)

    return datalist



################################################
################################################
################################################
def main():

    ans = 0
    datali = loading_inputs()
    ans = judging_COST(datali)
    print ans


if __name__ == "__main__":
    main()





Measured memory_bytes: 2696
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

bool chk(ll N, ll A, ll B, std::vector<ll> h, ll T) {
  ll check = 0;
  REP(i, N) {
    if (h[i] - B * T <= 0)
      continue;
    check += (h[i] - B * T) / (A - B) + ((h[i] - B * T) % (A - B) == 0 ? 0 : 1);
  }
  // cout << T << " " << check << endl;
  return check <= T;
}

void solve(long long N, long long A, long long B, vector<long long> h) {
  ll left = 0;
  ll right = 1000000000;
  ll ans = right;

  //二分探索
  // binarySearch
  while (left < right) {
    ll mid = (left + right) / 2;
    if (chk(N, A, B, h, mid)) {
      ans = min(ans, mid);
      right = mid;
    } else {
      left = mid + 1;
    }
  }

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long A;
  long long N;
  long long B;
  cin >> N;
  vector<long long> h(N - 1 + 1);
  cin >> A;
  cin >> B;
  for (int i = 0; i <= N - 1; i++) {
    cin >> h[i];
  }
  solve(N, A, B, h);
  return 0;
}


Measured memory_bytes: 2672
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


S = _s()
T = _s()

ans = 0
for i in range(3):
    if S[i] == T[i]:
        ans += 1
print(ans)


Measured memory_bytes: 3064
import sys, random
input = sys.stdin.readline
def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    for _ in range(D):
        si = list(map(int, input().split()))
        s.append(si)
    last_list = [0] * 26
    minus_sat_list = [0] * 26
    for i in range(D):
        for j in range(26):
            minus_sat_list[j] += c[j] * (i+1-last_list[j])
        best_idx = 0
        worst_sat, worst_sat_idx  = 0, -1
        worst2_sat, worst2_sat_idx  = 0, -1
        worst3_sat, worst3_sat_idx  = 0, -1
        worst4_sat, worst4_sat_idx  = 0, -1
        worst5_sat, worst5_sat_idx  = 0, -1
        for j in range(26):
            if (minus_sat_list[j] > worst_sat) or (minus_sat_list[j] == worst_sat and s[i][j] > s[i][worst_sat_idx]):
                worst_sat = minus_sat_list[j]
                worst_sat_idx = j
            elif (minus_sat_list[j] > worst2_sat) or (minus_sat_list[j] == worst2_sat and s[i][j] > s[i][worst2_sat_idx]):
                worst2_sat = minus_sat_list[j]
                worst2_sat_idx = j
            elif (minus_sat_list[j] > worst3_sat) or (minus_sat_list[j] == worst3_sat and s[i][j] > s[i][worst3_sat_idx]):
                worst3_sat = minus_sat_list[j]
                worst3_sat_idx = j
            elif (minus_sat_list[j] > worst4_sat) or (minus_sat_list[j] == worst4_sat and s[i][j] > s[i][worst4_sat_idx]):
                worst4_sat = minus_sat_list[j]
                worst4_sat_idx = j
            elif (minus_sat_list[j] > worst5_sat) or (minus_sat_list[j] == worst5_sat and s[i][j] > s[i][worst5_sat_idx]):
                worst5_sat = minus_sat_list[j]
                worst5_sat_idx = j
        indices = [worst_sat_idx, worst2_sat_idx, worst3_sat_idx, worst4_sat_idx, worst5_sat_idx]
        best_idx = indices[random.randrange(5)]
        minus_sat_list[best_idx] = 0
        last_list[best_idx] = i + 1
        print(best_idx+1)
if __name__ == "__main__":
    main()

Measured memory_bytes: 78996
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n;
	cin>>n;
	ll an=(n/2)+n%2;
	cout<<an;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>

using namespace std;

string itos(int t){
	ostringstream oss; oss << t;
	return oss.str();
}

int stoi(string str){
	istringstream iss(str);
	int t; iss >> t;
	return t;
}

int getNext(int a, int L){
	string s = itos(a);
	while(s.size() < L) s += "0";
	sort(s.begin(), s.end());
	int m = stoi(s);
	reverse(s.begin(), s.end());
	int M = stoi(s);
	return M-m;
}

int main(){
	int a0, L;
	while(cin >> a0 >> L, L){
		vector<int> a; a.push_back(a0);
		bool end = false;
		while(true){
			int next = getNext(a.back(), L);
			for(int i=0;i<a.size();i++)
				if(a[i] == next){
					end = true;
					cout << i << " " << a[i] << " " << a.size()-i << endl;
					break;
				}
			if(end) break;
			a.push_back(next);
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;




////////////////////////////////////////////////////////

vector<vector<ll>> L;
map<pair<ll,ll>, ll> ma;
vector<bool> Seen;
map<ll, ll> pa;
ll N;

void dfs(){
    queue<ll> qu;
    Seen.resize(N+1);
    Rep(i, 1, N) Seen[i] = false;
    qu.push(1);
    Seen[1] = true;
    pa[1] = 0;
    while(!qu.empty()){
        ll u = qu.front(); qu.pop();
        ll col = 1;
        rep(i, 0, sz(L[u])){
            ll v = L[u][i];
            if(Seen[v]) continue;
            if(pa[u] == col) col++;
            qu.push(v);
            ma[{u, v}] = col;
            ma[{v, u}] = col;
            pa[v] = col;
            Seen[v] = true;
            col ++;
        }
    }
}

int main() {
    cin >> N;
    L.resize(N+1);
    Vl a(N-1), b(N-1);
    rep(i, 0, N-1){
        cin >> a[i] >> b[i];
        L[a[i]].push_back(b[i]);
        L[b[i]].push_back(a[i]);
    }
    ll M = 0;
    Rep(i, 1, N){
        chmax(M, sz(L[i]));
    }
    dfs();
    co(M);
    rep(i, 0, N-1){
        cout << ma[{a[i], b[i]}] << endl;
    }

    return 0;
}


Measured memory_bytes: 26880
let rec search x y m cd index ans = 
if cd = [] 
then 
    ans
else
    let (c,d) = (List.hd cd)  in
    let dis = abs(x-c) + abs(y-d) in
    if dis <= m 
    then
        search x y dis (List.tl cd) (index-1) index
    else
        search x y m (List.tl cd) (index-1) ans;;


let n,m = Scanf.scanf "%d %d " (fun a b -> a,b) in 
let rec loop i= 
    if i <= 0 
    then
         [] 
    else
        (Scanf.scanf "%d %d " (fun a b -> a,b)) :: loop (i-1) in
let ab = List.rev (loop n) in 
let cd = loop m in
let rec loop2 ls = 
    match ls with
        |[] -> () 
        |(a,b)::tail ->  Printf.printf "%d\n" (search a b 1000000000 cd m 0);loop2 tail in
loop2 ab;;


Measured memory_bytes: 512
//============================================================================
// Name        : alds1_3_b_queue.cpp
// Author      : lovesaemi
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <stdio.h>
#include <string.h>
#define LEN 100005
using namespace std;

typedef struct pp {
	char name[100];
	int t;
} P;

P Q[LEN];
int head, tail, n;
void enqueue(P x) {
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}
P dequeue() {
	P x = Q[head];
	head = (head + 1) % LEN;
	return x;
}

int min(int a, int b) {
	return a < b ? a : b;
}

int main() {
	int elaps = 0, c;
	int i, q;
	P u;
	scanf("%d %d", &n, &q);
	for (i = 1; i <= n; i++) {
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].t);
	}
	head = 1;
	tail = n + 1;
	while (head != tail) {
		u = dequeue();
		c = min(q, u.t);
		u.t -= c;
		elaps += c;
		if (u.t > 0) {
			enqueue(u);
		} else {
			printf("%s %d\n", u.name, elaps);
		}
	}

	return 0;
}



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

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

    int res = 1;
    for (int i=1; i<=n; i++) {
        int a; scanf("%d", &a);
        if (a % 2 == 0) {
            if (a % 3 != 0 && a % 5 != 0) {
                res = 0;
            }
        }
    }

    puts(res ? "APPROVED" : "DENIED");
    return 0;
}


Measured memory_bytes: 256
n=int(input())
w1=input()
detalist={w1}
last=w1
flag=True
for _ in [0]*(n-1):
    wi=input()
    if wi in detalist or wi[0] != last[-1]:
        flag=False
        break
    last=wi
    detalist.add(wi)
if flag:
    print("Yes")
else:
    print("No")

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

int	main() {
	int sx, sy, tx, ty;
	cin >>sx >>sy >>tx >>ty;
	tx -=sx;
	ty -=sy;
	string S;
	for (int i=0; i<tx; i++)
		S +='R';
	for (int i=0; i<ty; i++)
		S +='U';
	for (int i=0; i<tx; i++)
		S +='L';
	for (int i=0; i<ty; i++)
		S +='D';
	S +='D';
	for (int i=0; i<=tx; i++)
		S +='R';
	for (int i=0; i<=ty; i++)
		S +='U';
	S +='L';
	S +='U';
	for (int i=0; i<=tx; i++)
		S +='L';
	for (int i=0; i<=ty; i++)
		S +='D';
	S +='R';
	cout <<S <<endl;
	return 0;
};


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

long long MOD = 1000000007;

int main() {
    
    int A,B;
    string S;
    cin >> A >> B >> S;
   
   bool ans = true;
   for ( int i = 0; i < A; i++ ) {
       if ( !isdigit(S[i]) ) { ans = false; }
   }
   if ( S[A] != '-' ) { ans = false; }
   for ( int i = A+1; i < A+B+1; i++ ) {
       if ( !isdigit(S[i]) ) { ans = false; }
   }
   
   cout << ( ans ? "Yes" :  "No" ) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N=105;
int n,a[N];
int solve(int x)
{
    int ans=0;
    for(int i=1;i<=n;i++)
        ans+=(x-a[i])*(x-a[i]);
    return ans;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int ans=inf;
    for(int i=0;i<=100;i++)
        ans=min(ans,solve(i));
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1);
namespace {
  template <typename T> inline void read(T &x) {
    x = 0; T f = 1;char s = getchar();
    for(; !isdigit(s); s = getchar()) if(s == '-') f = -1;
    for(;  isdigit(s); s = getchar()) x = (x << 3) + (x << 1) + (s ^ 48);
    x *= f;
  }
}
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define lowbit(x) x & (-x)
#define pii pair<int,int>
#define fi first
#define se second
int m[] = {0 , 31,28,31,30,31,30,31,31,30,31,30,31};
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(m[a] == b) {
    cout << 1 << endl;
  }
  else cout << 0 << endl;
}

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

using namespace std;

int main(){
    long long N;
    cin >> N;
    long long num = N/2;
    vector<long long> v;

    for(int i = 1; i <= num; i++){
        if(N%i == 0){
            v.push_back(i);
            v.push_back(N/i);
        }else{
            num = N/i;
        }
    }

    if(v[v.size()-1] == 1){
        cout << v[v.size()-1] + v[v.size()-2] - 1 << endl;
    }else{
        cout << v[v.size()-1] + v[v.size()-2] - 2 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define PB push_back
#define MP make_pair
#define all(x) x.begin(),x.end()

int N;
LL a[400],wa[401],dp[400][401];
LL solve(int l, int r){
	if(r-l == 1) return 0;
	if(dp[l][r] != -1) return dp[l][r];
	LL ans = LLONG_MAX;
	for(int i=l+1; i<r; i++){
		ans = min(ans, solve(l,i)+solve(i,r));
	}
	return dp[l][r] = ans + wa[r] - wa[l];
}
int main(){
	cin >> N;
	wa[0] = 0;
	for(int i=0; i<N; i++){
		cin >> a[i];
		wa[i+1] = wa[i] + a[i];
		for(int j=0; j<N; j++) dp[i][j+1] = -1;
	}

	cout << solve(0,N) << endl;
	
	return 0;
}



Measured memory_bytes: 1536
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

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

signed main() {
    int n;
    cin>>n;
    vector<double> v(n);
    REP(i,n){
        cin>>v[i];
    }

    sort(v.begin(),v.end());
    
    REP(i,n-1){
        v[i+1] = (v[i]+v[i+1])/2;
        v[i] = 0;
    }
    cout<<v[n-1]<<endl;

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

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void solve() {
	int n;
	cin >> n;
	double dp[n+1];
	for (int i = 0; i <= n; i++)
		dp[i] = 0.0;
	dp[0] = 1;
	for (int i = 1; i <= n; i++) {
		double p;
		cin >> p;
		for (int j = i; j >= 0; j--) {
			dp[j] = (j==0? 0 : dp[j-1]*p) + dp[j]*(1-p);
		}
	}
	double cnt = 0;
	for (int i = 0; i <= n; i++) {
		int tails = n - i;
		if (i > tails)
			cnt += dp[i];
	}
	cout << fixed << setprecision(10) << cnt;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}

Measured memory_bytes: 3836
# -*- coding: utf-8 -*-

import re

def solve():
    S = input()
    k = 'keyence'
    res = any(re.fullmatch(k[:i]+'.*'+k[i:], S) for i in range(len(k)+1))
    if res:
        res = 'YES'
    else:
        res = 'NO'
    return str(res)

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

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define nn 65536*4
#define ll long long
map<ll,ll> cnt;ll a[nn];ll s[nn];
ll n;
int main()
{
	ll ans=0;cnt[0]=1;
	cin>>n;for(int i=1;i<=n;i++) 
		scanf("%lld",&a[i]),s[i]=s[i-1]+a[i],ans+=cnt[s[i]]++;
	cout<<ans;
    return 0;
}

Measured memory_bytes: 16384
mod = 10**9+7
def cmb(n, r):
    p, q = 1, 1
    for i in range(r):
        p = p * (n - i) % mod
        q = q * (i + 1) % mod
    return p * pow(q, mod - 2, mod) % mod

def __main():
    n,a,b = map(int, input().split())
    sum = pow(2,n,mod) - 1
    elm1 = cmb(n,a)
    elm2 = cmb(n,b)
    ans = (sum-(elm1+elm2))%mod
    print(ans)
__main()

Measured memory_bytes: 3188
s=input()

n=len(s)
n1=n//2
n2=n%2

if n2==0:
    k1="01"*n1
    k2="10"*n1
else:
    k1="01"*(n1)+"0"
    k2="10"*(n1)+"1"

count1=0
count2=0

for i in range(n):
    if k1[i]==s[i]:
        count1+=1
    if k2[i]==s[i]:
        count2+=1
        
print(min(count1,count2))

Measured memory_bytes: 3316
def next(x1,y1,x2,y2):
  xd = x2 - x1
  yd = y2 - y1
  nyd = xd
  nxd = -yd
  return [x2+nxd,y2+nyd]

x1,y1,x2,y2 = list(map(int,input().split()))
x3,y3 = next(x1,y1,x2,y2)
x4,y4 = next(x2,y2,x3,y3)
print(x3,y3,x4,y4)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int A[10],B[10];

double dis(int i, int j){
    double dx = A[i] - A[j];
    double dy = B[i] - B[j];
    return pow(dx * dx + dy * dy, 0.5);
}

int main(){
    int n;
    cin >> n;
    double sum = 0;
    for(int i = 1; i <= n; i++){
        cin >> A[i] >> B[i];
    }
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        p[i] = i+1;
    }
    do{
        for(int i = 0; i < n-1; i++){
            sum += dis(p[i], p[i+1]);
        }
    }while(next_permutation(p.begin(),p.end()));
    int fac = 1;
    for(int i = 2;i <= n; i++){
        fac *= i;
    }
    cout << fixed << setprecision(10) << sum / fac << endl;

    return 0;
}

Measured memory_bytes: 512
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
const long long INF = 1e18;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T>
inline void chmax(T &a, const T &b) {
    if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
    if ((a) > (b)) (a) = (b);
}

#define divceil(a, b) ((a) + (b)-1) / (b)
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x)    \
    sort(all(x)); \
    x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> iii;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
    }
} fast;
void check_input() {
    assert(cin.eof() == 0);
    int tmp;
    cin >> tmp;
    assert(cin.eof() == 1);
}

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"


int solve() {
    ll n,D;cin>>n>>D;
    vector<ll> a(n);
    rep(i, n) {
        cin>>a[i];
        a[i]--;
    }
    dump(a);


    const int V = 62;
    vvi db(V, vi(n));
    rep(i, n){
        db[0][i] = a[i];
    }

    rep(k, 1, V){
        rep(i, n){
            db[k][i] = db[k-1][db[k-1][i]];
        }
    }

    ll cur = 0;
    rep(k, V){
        if (D>>k&1){
            cur = db[k][cur];
        }
    }
    cout << cur+1 << endl;

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 103256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		
		int[] a = new int[1000001];
		
		a[1] = s;
		
		loop:
		for(int i = 2; i < 1000001; i++) {
			if(a[i - 1] % 2 == 0) {
				a[i] = a[i - 1] / 2;
			} else {
				a[i] = 3 * a[i - 1] + 1;
			}
			for(int j = 1; j < i; j++) {
				if(a[i] == a[j]) {
					System.out.println(i);
					break loop;
				}
			}	
		}
	}
}


Measured memory_bytes: 25940
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

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

    if(n>=m){
        cout << 0 << endl;
        return 0;
    }
    sort(x.begin(), x.end());

    vector<int> bet(m-1);
    rep(i, m-1){
        bet[i] = x[i+1] - x[i];
    }

    sort(bet.begin(), bet.end());

    int ans = 0;
    rep(i, m-n){
        ans += bet[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
m=b[0]
c=0
for i in range(n):
 t=k=0
 x=a.index(b[i])
 while x>i:
  y=a.index(b[x])
  a[x],a[y]=b[x],b[i]
  k+=1
  t+=b[x]+b[i]
  x=y
 if k:c+=min(t,(b[i]+m)*2+t-(b[i]-m)*k)
print(c)


Measured memory_bytes: 5628
#include <stdio.h>

int main(void) {
	int a;
	int b;
	int c;
	scanf("%d %d %d", &a, &b, &c);
	if (a + b > c && b + c > a && c + a > b && a == b && b == c) {
		printf("Yes");
	}
	else {
		printf("No");
	}
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
    int n, m, x;
    long long s = 0;
    cin >> n >> m;
    for(int i = 1; i <= m; i ++){
        cin >> x;
        s += x;
    }
    if(s <= n) cout << n - s;
    else cout << -1;
}

Measured memory_bytes: 3616
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define in(x, l, r) (ll)(l) <= (x) && (x) < (ll)(r)

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,0,N) cin >> A[i];

    ll m = 1000000007;
    ll sum = 0;
    rep(i,0,N) {
        sum += A[i];
    }
    sum %= m;

    ll ans = 0;
    rep(i,0,N-1) {
        sum = (sum - A[i]) % m;
        if (sum < 0) sum += m;
        ans = (ans + sum * A[i]) % m;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4820
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a,b,c;
  cin >> a >> b >> c;
  if (a == b) {
  	cout << c << endl;
  }else if (b == c) {
  	cout << a << endl;
  }else {
  	cout << b << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int sec;
	int hour;
	int min;
	
	scanf("%d",&sec);
	hour = sec/3600;
	min = (sec/60)%60;
	sec = sec%60;
	
	printf("%d:%d:%d\n",hour,min,sec);
}

Measured memory_bytes: 2704
/*B - Guidebook */
#include <bits/stdc++.h>
using namespace std;

inline bool comparador(const pair <string, int>&a, const pair <string, int>&b){
	if(a.first == b.first)
		return a.second > b.second;

	return a.first < b.first;
} 

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

	string city;
	int tam;
	int punts;
	
	cin >> tam;

	vector <pair <string, int> > score(tam);
	map < pair <string, int>, int> orden;


	for (int i = 0; i < tam; ++i){
	 	cin >> city >> punts; 
	 	score[i] = {city, punts};
	 	orden[{city, punts}] = i + 1;
	 }

	sort(score.begin(), score.end(), comparador);

	int num;
	string cad;
	int sc;

	for (int i = 0; i < tam; ++i)
	{
		cad = score[i].first;
		sc = score[i].second;

		cout << orden[{cad, sc}] << '\n';
	} 

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;
string s, t;
ll MOD = 1000000007;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n >> s >> t;
	vector<int> v;
	int pos = 0;
	while (pos < n) {
		if (pos < n-1 && s[pos] == s[pos+1]) {
			v.push_back(1);
			pos += 2;
		}
		else {
			v.push_back(0);
			pos++;
		}
	}

	ll ret = v[0] ? 6 : 3;
	for (int i = 1; i < v.size(); i++) {
		if (v[i-1] && v[i]) ret = ret * 3 % MOD;
		else if (!v[i-1]) ret = ret * 2 % MOD;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from bisect import bisect_left
from bisect import bisect_right
input = sys.stdin.readline
a,b,q = map(int, input().split())
INF = 10**20
ss = [-INF] + [int(input()) for i in range(a)] + [INF]
ts = [-INF] + [int(input()) for i in range(b)] + [INF]
xs = [int(input()) for i in range(q)] 

ans = INF
for x in xs:
    si = bisect_left(ss, x)
    ti = bisect_left(ts, x)

    dist1 = abs(x-ss[si-1]) + 2*abs(x-ts[ti])
    dist2 = 2*abs(x-ss[si-1]) + abs(x-ts[ti])
    dist3 = abs(x-ts[ti-1]) + 2*abs(x-ss[si])
    dist4 = 2*abs(x-ts[ti-1]) + abs(x-ss[si])
    dist5 = max(abs(x-ss[si-1]), abs(x-ts[ti-1]))
    dist6 = max(abs(x-ss[si]), abs(x-ts[ti]))
    dist = min(dist1,dist2,dist3,dist4,dist5,dist6)
    # print(dist,"du",x,dist1,dist2,dist3,dist4,dist5,dist6)
    print(dist)




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

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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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

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

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

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}


int n;
int n_max = 20;
vector<vector<int>> x(n_max, vector<int>(n_max));
vector<vector<int>> y(n_max, vector<int>(n_max));
vector<int> a(n_max);
int ans = 0;
vector<int> hone_or_unk(n_max);

void dfs(int now){
  bool flag = true;
  if (now == n){
    // check whether this vector satisfies the demand
    REP(i, n){
      if (hone_or_unk[i+1] == 1){
      int testify_num = a[i];
      REP(j, testify_num){
        if (hone_or_unk[x[i][j]] != y[i][j]){
          flag = false;
        }}
      }
    }
    if (flag){
      int tmp = 0;
//      cout << hone_or_unk << endl;
      REP(i, n+1){
        tmp += hone_or_unk[i];
        ans = max(ans, tmp);
      }
    }
  }
  else{
    for (int i=0; i<=1; i++){
      hone_or_unk[now+1] = i;
      dfs(now+1);
    }
  }
}




int main(void){
  ios::sync_with_stdio(false);
  cin >> n;
  REP(i, n){
    cin >> a[i];
    REP(j, a[i]){
      cin >> x[i][j];
      cin >> y[i][j];
    }
  }
  dfs(0);
  cout << ans << endl;
  return 0;
}



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

int main()
{
    char s[200001];
    scanf("%s",s);

    int len = strlen(s);
    long long i,ans = 0,cntW = 0;
    for (i = 0; i < len; i++)
    {
        if(s[i] == 'W')
        {
            ans += i - cntW;
            cntW++;
        }
    }
    
    
    printf("%lld",ans);
}

Measured memory_bytes: 384
function Main(input) {
  var s = input.split('\n')[0];
  var map = {};
  map['00'] = 0;
  map['01'] = 0;
  map['10'] = 0;
  map['11'] = 0;
  for (var i = 0; i < s.length; i = i + 2) {
    map[s[i] + s[i + 1]]++
  }
  var count = map['00'] + map['11'];
  var last;

  if (map['01'] === 0 && map['10'] === 0) {
    last = s[s.length - 2];
  } else if (map['01'] === map['10']) {
    count += map['01'] * 2;
  } else if (map['01'] < map['10']) {
    last = '1';
    count += map['01'] * 2;
  } else {
    last = '0';
    count += map['10'] * 2;
  }

  if (!!last && s.length % 2 === 1) {
    count += s[s.length - 1] === last ? 0 : 1;
  }

  console.log(count);



}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9036