akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define ZP(a, len) setfill('0') << setw(len) << right << a
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
const ll LINF = 1e11;

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

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


void solve() {
    int H, W;
    cin >> H >> W;
    vs field;
    for (int i = 0; i < H; ++i) {
        string s;
        cin >> s;
        field.push_back(s);
    }

    // 横の空きマスを数える
    auto horizontalLights = vector<vector<int>>();
    horizontalLights.assign(H, vector<int>(W, 0));
    for (int y = 0; y < H; ++y) {
        for (int x = 0; x < W; ++x) {
            if (field[y][x] == '.') {
                // 右方向の空きを数える
                int rEnd = x + 1;
                while (rEnd < W && field[y][rEnd] != '#') {
                    rEnd++;
                }
                int lightCnt = rEnd - x;
                for (int wx = x; wx < rEnd; ++wx) {
                    horizontalLights[y][wx] = lightCnt;
                }
                x = rEnd;
            }
        }
    }

    // 縦の空きマスを数える
    auto verticalLights = vector<vector<int>>();
    verticalLights.assign(H, vector<int>(W, 0));
    for (int x = 0; x < W; ++x) {
        for (int y = 0; y < H; ++y) {
            if (field[y][x] == '.') {
                // 下方向の空きを数える
                int downEnd = y + 1;
                while (downEnd < H && field[downEnd][x] != '#') {
                    downEnd++;
                }
                int lightCnt = downEnd - y;
                for (int wy = y; wy < downEnd; ++wy) {
                    verticalLights[wy][x] = lightCnt;
                }
                y = downEnd;
            }
        }
    }

    int ans = 0;
    for (int y = 0; y < H; ++y) {
        for (int x = 0; x < W; ++x) {
            ans = max(horizontalLights[y][x] + verticalLights[y][x] - 1, ans);
        }
    }

    cout << ans << "\n";
}


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

    solve();
    return 0;
}


Measured memory_bytes: 35968
use proconio::*;

fn run() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut ans = 0;
    for (i, a) in a.iter().enumerate() {
        if i % 2 == 0 && *a % 2 == 1 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 2064
using System;
using static System.Console;

class _99 {
  int a, b;
  
  public _99(int a, int b) {
    this.a = a;
    this.b = b;
  }
  
  public int Judge() {
    int ans;
    
    if(10 <= a || 10 <= b) {
      ans = -1;
    } else {
      ans = a * b;
    }
      
    return ans;
  }
}
  
class _99Main {
  static void Main() {
    string[] str = ReadLine().Split(' ');
    int a = int.Parse(str[0]);
    int b = int.Parse(str[1]);
    
    _99 multiply = new _99(a, b);
    
    WriteLine(multiply.Judge());
  }
}

Measured memory_bytes: 11092
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include <wchar.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
*/

ll n,k,h[100010],dp[100010];

int main(void){
	cin>>n>>k;
	reg(i,2,n)dp[i]=1e18;
	dp[1]=0;
	reg(i,1,n)cin>>h[i];
	reg(i,2,n){
		ll next=1e18;
		reg(j,1,k){
			if(i-j<1)break;
			next=min(next,dp[i-j]+abs(h[i]-h[i-j]));
		}
		dp[i]=next;
	}
	cout<<dp[n]<<endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  bool answer = false;
  if (N <= 999 && N >= 100) {
  if (N % 10 == 7 || (N % 100) / 10 == 7 || N / 100 == 7) {
    answer = true;
    if (answer) {
      cout << "Yes" << endl;
    }
  }
    else {
      cout << "No" << endl;
    }
  }
  else {
    cout << "No" << endl;
  }
}
  

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m; cin >> n >> m;
  vector<int> p(m), y(m);
  map<int, vector<int> > meh;
  for(int i = 0; i < m; i++){
    cin >> p[i] >> y[i];
    meh[p[i]].push_back(y[i]);
  }
  for(auto nd : meh) sort(meh[nd.first].begin(), meh[nd.first].end());
  for(int i = 0; i < m; i++){
  	int pt = lower_bound(meh[p[i]].begin(), meh[p[i]].end(), y[i] + 1) - meh[p[i]].begin();
    printf("%06d%06d\n", p[i], pt);
  }
  return 0;
}


Measured memory_bytes: 13184
import sys
readline = sys.stdin.readline

def solve():
    N = int(readline())
    L = list(map(int, readline().split()))

    if N <= 2:
        print(0)
        return

    L.sort()
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(j + 1, N):
                if len(set((L[i], L[j], L[k]))) == 3 and L[k] < L[i] + L[j]:
                    ans += 1
    
    print(ans)
                

solve()

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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   //最大値を求める
#define MIN(x) *min_element(ALL(x))   //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007      //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

signed main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> H(N);
    vector<ll> A(M);
    vector<ll> B(M);
    vector<ll> Good(N);
    REP(i, N)
    {
        Good.at(i) = 1;
    }
    REP(i, N)
    {
        cin >> H.at(i);
    }
    REP(i, M)
    {
        cin >> A.at(i) >> B.at(i);
        if (H.at(A.at(i) - 1) < H.at(B.at(i) - 1))
        {
            Good.at(A.at(i) - 1) = 0;
        }
        else if (H.at(A.at(i) - 1) == H.at(B.at(i) - 1))
        {
            Good.at(A.at(i) - 1) = 0;
            Good.at(B.at(i) - 1) = 0;
        }
        else if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1))
        {
            Good.at(B.at(i) - 1) = 0;
        }
    }
    ll count = 0;
    REP(i, N)
    {
        if (Good.at(i) != 0)
        {
            count++;
        }
        // count += Good.at(i);
    }
    cout << count << endl;
}


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

int main(void) {
    int64_t N,x;
    int64_t cnt=0,tmp;
    int64_t bef,aft;

    cin >> N >> x;

    cin >> bef;
    for(int i=1;i<N;i++) {
        cin >> aft;
        if((bef + aft) > x) {
            cnt += (bef + aft- x);
            bef = aft - ((bef + aft) - x);
            if(bef < 0) {
               bef = 0;
            }
        } else {
            bef = aft;
        }
    }

    cout << cnt << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    int ll = 0, rr = n;
    for (int i = 0; i < m; ++i) {
        int l, r;
        cin >> l >> r;
        ll = max(ll, l);
        rr = min(rr, r);
    }
    cout << (ll <= rr ? rr - ll + 1 : 0) << endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int[] a = new int[n + 1];
            for (int i = 1; i < n + 1; i++) {
                a[i] = Integer.parseInt(in.next());
            }
            int ans = 0;

            for (int i = 1; i < n + 1; i++) {
                if (i % 2 != 0 && a[i] % 2 != 0) ans++;
            }
            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 35624
#include<bits/stdc++.h>
using namespace std;
long long n,a[200005],dp[200005],k;
long long solve(long long i,long long k)
{
    if(i>n)
    return 2000000000;
    if(i==n)
    return 0;
    if(dp[i]!=2000000000)
    return dp[i];
    for(int l=1;l<=k;l++)
    dp[i]=min(dp[i],solve(i+l,k)+abs(a[i]-a[i+l]));
    return dp[i];
}
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    dp[i]=2000000000;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    cout<<solve(1,k);
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
string s;
int flg[26];

int main(){
  cin >> s;
  if (s.size()<26){
    for(int i=0;i<s.size();i++) flg[s[i]-'a']++;
    for(int i=0;i<26;i++){
      if (flg[i]==0){
        cout << s << (char)('a'+i) << endl;
        return 0;
      }
    }
  }else{
    for(int i=s.size()-1;i>0;i--){
      flg[s[i]-'a']++;
      if (s[i-1] < s[i]){
        for(int j=(s[i-1]-'a')+1;j<26;j++){
          if (flg[j]){
            cout << s.substr(0, i-1) << (char)('a'+j) << endl;
            return 0;
          }
        }
      }
    }
    cout << -1 << endl;
  }
  return 0;
}

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

int main(){
    int N, L, sum, max;
    cin >> N >> L;
    max = L + N - 1;
    sum = (max * (max + 1) - L * (L - 1)) / 2;
    if(L>0){
        cout << sum - L << endl;
    }else{
        if(max<0){
            cout << sum - max << endl;
        }else{
            cout << sum << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    ab <- replicateM n $ do
        [a,b] <- getIntList
        return (a,b)
    print $ foldr solve 0 ab

solve (a,b) k = k + ((-a-k) `mod` b)

Measured memory_bytes: 39548
a = []
b = []
for i in range(3):
    x1,y1=[int(i) for i in input().split()]
    a.append(x1)
    b.append(y1)

path=a+b

import collections
c=collections.Counter(path)

values,counts =zip(*c.most_common())

if counts==(2,2,1,1):
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  rep(i, N) cin >> S[i];
  int cnt = 0;
  rep(k, N) {
    bool ok = true;
    rep(i, N) rep(j, N) {
      if(S[(N+i-k)%N][j] != S[(N+j-k)%N][i]) ok = false;
    }
    if(ok) cnt++;
  }
  cout << cnt * N << endl;
  return 0;
}


Measured memory_bytes: 384
use std::collections::BTreeMap;

const MOD: usize = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();

    let mut dp = BTreeMap::new();
    println!("{}", rec(n, n, &mut dp));
}

fn rec(xor: usize, sum: usize, dp: &mut BTreeMap<(usize, usize), usize>) -> usize {
    if sum == 0 {
        return 1;
    }
    if dp.contains_key(&(xor, sum)) {
        return dp[&(xor, sum)];
    }

    // odd & odd
    let mut result = if sum >= 2 {
        rec(xor >> 1, (sum - 2) >> 1, dp)
    } else {
        0
    };

    // odd & even
    result += rec((xor - 1) >> 1, (sum - 1) >> 1, dp);

    // even & even
    result += rec(xor >> 1, sum >> 1, dp);
    result %= MOD;

    dp.insert((xor, sum), result);
    return result;
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 4352
n, x = map(int, input().split())
li_a = list(map(int, input().split()))

answer = 0
id = -1

for idx, a in enumerate(sorted(li_a)):
    if x >= a:
        answer += 1
        x -= a
        id = idx
    else:
        break
if answer == 0:
    print(answer)
elif x == 0:
    print(answer)
else:
    if id == (n -1):
        print(answer - 1)
    else:
        print(answer)



Measured memory_bytes: 3060
// editorial. https://img.atcoder.jp/abc146/editorial.pdf

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
  }
  vector<ll> s(n+1); // s[i] .. The sum of a[j] in [0, i)
  rep(i, n) {
    s[i+1] = s[i] + a[i];
  }
  // cout << "s: "; printvec(s);

  vector<ll> d(n+1); // d[i] .. (s[i] - i)%k. d[0] = 0.
  rep(i, n) {
    d[i+1] = (s[i+1] - (i+1))%k;
  }
  // cout << "d: "; printvec(d);

  // we want to calculate the count of all pairs (i,j) where d[i] == d[j] and i<j and j-i<k.
  // (s[j]-s[i])%k == j-i <=> d[j] == d[i]

  ll ans = 0;
  map<ll, ll> cnts;
  rep(i, n+1) {
    if (i >= k) {
      --cnts[d[i-k]];
    }
    // Now, cnts contains d[i-k+1]..d[i-1]. k-2 elements.
    ans += cnts[d[i]];

    ++cnts[d[i]];
  }

  cout << ans << endl;
}


Measured memory_bytes: 17408
using System;
using System.Collections.Generic;
using System.Linq;

class D
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		var n = h[0];
		var pq = new int[h[1]].Select(_ => Read()).ToArray();
		var rs = new int[h[2]].Select(_ => Read()).ToArray();

		var uf1 = new UF(n);
		var uf2 = new UF(n);
		foreach (var x in pq) uf1.Unite(x[0], x[1]);
		foreach (var x in rs) uf2.Unite(x[0], x[1]);

		var d = new Dictionary<(int, int), List<int>>();
		for (int i = 1; i <= n; i++)
		{
			var key = (uf1.GetRoot(i), uf2.GetRoot(i));
			if (!d.ContainsKey(key)) d[key] = new List<int>();
			d[key].Add(i);
		}

		var r = new int[n + 1];
		foreach (var p in d)
			foreach (var i in p.Value)
				r[i] = p.Value.Count;
		Console.WriteLine(string.Join(" ", r.Skip(1)));
	}
}

class UF
{
	int[] p;
	public UF(int n) { p = Enumerable.Range(0, n + 1).ToArray(); }

	public void Unite(int a, int b) { if (!AreUnited(a, b)) p[p[b]] = p[a]; }
	public bool AreUnited(int a, int b) => GetRoot(a) == GetRoot(b);
	public int GetRoot(int a) => p[a] == a ? a : p[a] = GetRoot(p[a]);
	public int[][] ToGroups() => Enumerable.Range(0, p.Length).GroupBy(GetRoot).Select(g => g.ToArray()).ToArray();
}


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

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


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

ans = 0
cnt = 0

for i in range(1, max(h) + 1)[::-1]:
    cnt = 0
    for j in range(n):
        if h[j] == i:
            h[j] -= 1
            cnt += 1
            if j + 1 < n:
                if h[j + 1] == i:
                    cnt -= 1
    ans += cnt

print(ans)

Measured memory_bytes: 3064
/*input
2
ABCXYZ
*/
#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define MAX 100005
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define ff first
#define ss second
#define T int t;cin>>t;while(t--)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define umi unordered_map<int,int>
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int> >
#define inp(n) for(int i=0;i<n;i++)
#define N 2000005

using namespace std;
using namespace std::chrono;


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

	int x;
	cin >> x; 
	string s;
	cin >> s;
	for(int i=0;s[i];i++){
		for(int j=0;j<x;j++){
			if(s[i] == 'Z')
				s[i] = 'A';
			else
				s[i]++;
		}
	}
	cout << s << '\n';

}

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

using namespace std;
int main(void){
    string S, C;
    cin >> S >> C;
    
    int count = 0;
    for (int i = 0; i < 3; i++)
        if (S[i] == C[i])
            count++;
            
    cout << count << endl;
}

Measured memory_bytes: 256
s = input()


flag = 1
for i in range(0,len(s)):
    if i % 2 == 0:
        if s[i] == "L":
            flag = 0
            break
    else:
        if s[i] == "R":
            flag = 0
            break

if flag:
    print('Yes')
else:
    print("No")


Measured memory_bytes: 2940
import numpy as n;i=n.int32;p=input;q=n.searchsorted;N=int(p());A=i(p().split());B=i(p().split());c=0;
for k in range(1,30):
  a,b=n.sort(n.hstack((A%(1<<k),A%(1<<k)-2**k))),B%(1<<k);c+=(n.sum(q(a,2**k-b)-q(a,2**(k-1)-b)))%2*2**(k-1)
print(c)


Measured memory_bytes: 35888
package main

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

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

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	for {
		h, w := nextInt(), nextInt()
		if w == 0 && h == 0 {
			break
		}
		for i := 0; i < h; i++ {
			for j := 0; j < w; j++ {
				fmt.Fprint(out, "#")
			}
			fmt.Fprintf(out, "\n")
		}
		fmt.Fprintf(out, "\n")
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}



Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int n=s.size();
    if(t.size()>s.size() && t.size()==s.size()+1)
    {
        string temp=t.substr(0,n);
       // cout<<temp<<endl;
        if(temp==s)
            cout<<"Yes";
        else
            cout<<"No";
    }
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;



int main()
{

    
    int k, x;
    cin >> k >> x;
    k *= 500;
    if (k >= x)cout << "Yes" << endl;
    else cout << "No" << endl;



    return 0;

}

Measured memory_bytes: 3628
# include <bits/stdc++.h>
using namespace std;
const int maxn=100000+50;
int  s[maxn];
double t[maxn];
int main ()
{
	int n,ans=1;
	int T,A;
	cin>>n>>T>>A;
	for (int i=1;i<=n;++i)
	{
	 cin>>s[i];
	 t[i]=T-s[i]*0.006;
     if(fabs(t[i]-A)<fabs(t[ans]-A))
	   {
			ans=i;
	   } 
	}
	printf ("%d\n",ans);
return 0;	  
}

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

int main(){
    int N,v=0,sea=0;
    cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A.at(i);
    }
    for(int i=0;i<N;i++){
        if(v<=A.at(i)){
            v=A.at(i);
            sea++;
        }
    }
    cout<<sea<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int n = sc.nextInt();
	static int a = sc.nextInt();
	static int b = sc.nextInt(); // set_x
	static int c = sc.nextInt();
	static int d = sc.nextInt(); // set_y
	public static void main(String[] args) {
		pencil();

	}
	private static void pencil() {
		int[] num = new int[] {a, c};
		int[] price = new int[] {b, d};
		int[] total = new int[2] ;

			for(int i = 0; i < 2; i++) {
				if (n % num[i] == 0) {
					total[i] = price[i] * (n / num[i]);
				} else {
					total[i] = price[i] * ((n / num[i]) + 1);
				}
			}
		System.out.println(Math.min(total[0], total[1]));
	}

}


Measured memory_bytes: 26348
#include <algorithm>
#include<bits/stdc++.h>
#include <ios>
#include <iterator>
using namespace std;
#define ll long long
#define f(n)  for(int i=0;i<n;i++) 
#define pb push_back
#define take(t) int t;cin>>t
#define np nake_pair
#define vi vector<int>
#define all(v)   v.begin(),v.end()  
#define w(t)   while(t--)
void speed (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
  
 speed();
ll int n,m;
cin>>n>>m;
vector<ll int>v(n);
ll int sum=0;
for(ll int i=0;i<n;i++){
    cin>>v[i];
    sum+=v[i];
}
sort(all(v));
double c=(double)(sum)/(double)(4*m);
ll int flag=0;
int f=0;
for(ll int i=0;i<n;i++){
    if(v[i]>=c){
        flag++;
    } 
}
if(flag>=m){
    cout<<"Yes";
}
else{
    cout<<"No";
}
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct compare
{
    bool operator()(const string& first, const string& second)
    {
        return first.size()>second.size();
    }
};
void solve()
{
    double n;
    cin>>n;
    vector<double>v(n); double sum = 0;
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
        sum+= (1/v[i]);
    }
    cout<<1/sum<<endl;
}

int main()
{
    int t;
    t=1;
    while(t--)
    {
        solve();

    }
}


Measured memory_bytes: 256
#include <stdio.h>

#define DATA 100

int main(void)
{
	int h[DATA], w[DATA];
	int i, j, k;

	for(i = 0;i < DATA;i++)
	{
		scanf("%d %d", &h[i], &w[i]);
		if((h[i] == 0) && (w[i] == 0))
			break;
	}

	for(i = 0;(h[i] != 0) || (w[i] != 0);i++)
	{
		for(j = 0;j < h[i];j++)
		{
			for(k = 0;k < w[i];k++)
			{
				if(j % 2 == 0)
				{
					if(k % 2 == 0)
						printf("#");
					else
						printf(".");
				}
				else
				{
					if(k % 2 == 0)
						printf(".");
					else
						printf("#");
				}
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 572
def solve():
    N,L = map(int, input().split())
    a = [abs(L+i) for i in range(N)]
    b = [L+i for i in range(N)]
    [a.index(min(a))]
    print(L*N+sum(range(N))-b[a.index(min(a))])
    

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	P := sc.NextIntArray()

	cnt := 0
	for i := 1; i < N-1; i++ {
		if P[i-1] < P[i] && P[i] < P[i+1] || P[i-1] > P[i] && P[i] > P[i+1] {
			cnt++
		}
	}
	fmt.Println(cnt)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
import scala.collection.mutable
import scala.io.StdIn._

object Main extends App {
  val Array(n, m) = readLine().split(" ").map(_.toInt)
  val group: mutable.Seq[Int] = mutable.Seq.fill(n)(-1)
  var graph: mutable.Seq[Seq[Int]] = mutable.Seq.fill(n)(Seq())

  for (i <- 1 to m) {
    val Array(v1, v2) = readLine().split(" ").map(_.toInt)
    graph(v1) :+= v2
    graph(v2) :+= v1
  }

  var id = 0
  for (i <- 0 until n) {
    val queue: mutable.Queue[Int] = mutable.Queue()
    if (group(i) == -1) queue.enqueue(i)

    while (queue.nonEmpty) {
      val x = queue.dequeue()
      group(x) = id
      for (j <- graph(x).indices) {
        if (group(graph(x)(j)) == -1) queue.enqueue(graph(x)(j))
      }
    }

    id += 1
  }

  for (i <- 1 to readInt()) {
    val Array(v1, v2) = readLine().split(" ").map(_.toInt)
    if (group(v1) != -1 && group(v1) == group(v2)) println("yes") else println("no")
  }

}

Measured memory_bytes: 211192
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int A[200010];
    rep(i, N) cin >> A[i];
    rep(i, N) A[i]--;
    int c = 0;
    if(K < 1000000) {
        while(K--) {
            c = A[c];
        }
        cout << c + 1 << endl;
        return 0;
    }
    rep(i, 500000) {
        c = A[c];
    }
    K -= 500000;
    int len = 1;
    int S = c;
    c = A[c];
    while(S != c) {
        c = A[c];
        len++;
    }
    K %= len;
    while(K--) {
        c = A[c];
    }
    cout << c + 1 << endl;

    return 0;
}


Measured memory_bytes: 5216
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
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();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
    vi four;
    int n = 1;
    while(true) {
        int num = n*(n+1)*(n+2)/6;
        if(num > 1000000) {
            break; 
        } else {
            four.push_back(num);
            n++;
        }
    }
    int fsize = four.size();

    vi dp(1000000+1, INF);
    vi dpk(1000000+1, INF);
    dp[0] = dpk[0] = 0;
 
    FOR(i, 1, 1000000) {
        REP(j, fsize) {
            if(i-four[j] >= 0) {
                dp[i] = min(dp[i-four[j]]+1, dp[i]);
                if(four[j]%2) {
                    dpk[i] = min(dpk[i-four[j]]+1, dpk[i]);
                }
            } else {
                break;
            }
        }
    }

    while(cin >> n, n) {
        cout << dp[n] << " " << dpk[n] << endl;
    }
 
    return 0;
}

Measured memory_bytes: 8792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 100001
#define INF 1000000009
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int H, W;
  scanf("%d %d", &H, &W);

  int c[10][10];
  rep(i, 10) rep(j, 10) scanf("%d", &c[i][j]);
    
  int A[201][201];
  rep(h, H) rep(w,W) scanf("%d", &A[h][w]);

  rep(k, 10) rep(i, 10) rep(j, 10) 
    c[i][j] = min(c[i][j], c[i][k] + c[k][j]);

  int ans = 0;
  rep(h, H) rep(w, W) 
    if (A[h][w] >= 0) ans += c[A[h][w]][1];
  
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

S = input()
T = input()
L = len(S)

cnt = 0
for i in range(L):
    if S[i] != T[i]:
        cnt += 1
print(cnt)

Measured memory_bytes: 84184
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <numeric>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair <int,int> P;

int main(){
	int A,B;
	cin >> A >> B;
	int C = max(A,B);
	cout << max(C+C-1,A+B) << endl;
}



Measured memory_bytes: 256
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    H, W = map(int, input().split())
    C = [input() for i in range(H)]
    D = [[c for c in C[i//2]] for i in range(2*H)]

    for i in range(2*H):
        print(''.join(D[i]))


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        String s1=in.nextLine();
        String s2=in.nextLine();
        StringBuilder sb=new StringBuilder(s1);
        sb.append(s2.charAt(s2.length()-1));
        if(s2.contains(sb)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 27012
#include <stdio.h>

int main(){
    int l, r, d;
    scanf("%d%d%d", &l, &r, &d);
    int a = r / d - l / d;
    if((l%d)==0){
        printf("%d", a + 1);
    }else{
        printf("%d", a);
    }
    return 0;
}

Measured memory_bytes: 1724
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int n, m;
vector<int> G[100005];
bool used[100005];
int dp[100005];
vector<int> topo;
 
void tpsort(int v)
{
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		if(!used[G[v][i]]) tpsort(G[v][i]);
	}
	topo.push_back(v);
}
 
int main(void)
{
	cin >> n >> m;
	int u, v;
	for(int i = 0; i < m; i++){
		cin >> u >> v;
		G[u].push_back(v);
	}
	
	for(int i = 1; i <= n; i++) if(!used[i]) tpsort(i);
	reverse(topo.begin(), topo.end());
	
	for(int i = 0; i < topo.size(); i++){
		int v = topo[i];
		for(int j = 0; j < G[v].size(); j++){
			dp[G[v][j]] = max(dp[G[v][j]], dp[v]+1);
		}
	}
	
	int ans = 0;
	for(int i = 1; i <= n; i++) ans = max(ans, dp[i]);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 8056
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local function lower_bound(ary, x, num)
  if num == 0 then return 1 end
  if(x <= ary[1].val) then return 1 end
  if(ary[num].val < x) then return num + 1 end
  local min, max = 1, num
  while(1 < max - min) do
    local mid = mfl((min + max) / 2)
    if(ary[mid].val < x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound(ary, x, num)
  if num == 0 then return 1 end
  if(x < ary[1].val) then return 1 end
  if(ary[num].val <= x) then return num + 1 end
  local min, max = 1, num
  while(1 < max - min) do
    local mid = mfl((min + max) / 2)
    if(ary[mid].val <= x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local n = io.read("*n", "*l")
local t = {}
local str = io.read()
for v in str:gmatch("%d+") do
  local tmp = {}
  tmp.val = tonumber(v)
  tmp.used = false
  table.insert(t, tmp)
end
table.sort(t, function(x, y) return x.val < y.val end)
local cnt = 0
for i = n, 2, -1 do
  if not t[i].used then
    t[i].used = true
    local v = t[i].val
    local mul = 2
    while mul <= v do
      mul = mul * 2
    end
    v = mul - v
    local lb, ub = lower_bound(t, v, i - 1), upper_bound(t, v, i - 1)
    for j = ub - 1, lb, -1 do
      if not t[j].used then
        cnt = cnt + 1
        t[j].used = true
        break
      end
    end
  end
end
print(cnt)


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

using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    string str;
    int i,k,n;

    cin>>k>>str;
    n = str.size();

    if(n<=k){
        cout<<str<<endl;
    }
    else{
        for(i = 0; i<k; i++){
            cout<<str[i];
        }
        cout<<"..."<<endl;
    }
    return 0;
}


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

int main(){
  int n, s, t;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  s = 0;
  t = 0;
  for(int i = 0; i < n; i += 2)
    s += a[i];
  for(int i = 1; i < n; i += 2)
    t += a[i];
 cout << s - t << endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_vec<T: FromStr>(n: usize) -> Vec<T> {
    return (0..n).map(|_| read()).collect();
}

fn main() {
    let n: usize = read();
    let ai: Vec<usize> = read_vec(n-1);

    let mut map = HashMap::new();
    for a in ai.iter() {
        if map.contains_key(a) {
            if let Some(x) = map.get_mut(a) {
                *x += 1;
            }
        } else {
            map.insert(a, 1);
        }
    }

    for i in 1..n+1 {
        if map.contains_key(&i) {
            println!("{}", map[&i]);
        } else {
            println!("{}", 0);
        }
    }
}


Measured memory_bytes: 10200
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int  A = sc.nextInt();
      int B = sc.nextInt();
      if(A==1&&B==2||A==2&&B==1){
        System.out.println("3");
      }else if(A==2&&B==3||A==3&&B==2){
        System.out.println("1");
      }else if(A==3&&B==1||A==1&&B==3){
        System.out.println("2");
      }
    }
}

Measured memory_bytes: 35676
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    AB = []
    for _ in range(N):
        A, B = read_ints()
        AB.append((A+B, A, B))
    AB.sort()
    scores = [0, 0]
    p = 0
    while AB:
        _, *s = AB.pop()
        scores[p] += s[p]
        p ^= 1
    return scores[0]-scores[1]


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


Measured memory_bytes: 91788
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
int n,a[555];
int main()
{
	cin>>n; vector<pii> qs;
	for(int i=1;i<=n;++i) cin>>a[i];
	int soz=0,sof=0;
	for(int i=1;i<=n;++i)
		if(a[i]>=0) soz+=a[i];
		else sof-=a[i];
	if(soz>=sof)
	{
		int ls=-1;
		for(int i=1;i<=n;++i) if(a[i]>=0)
		{
			if(ls==-1) ls=i;
			else a[ls]+=a[i],qs.pb(pii(i,ls));
		}
		for(int i=1;i<=n;++i) if(a[i]<0)
			a[i]+=a[ls],qs.pb(pii(ls,i));
		for(int i=2;i<=n;++i)
			a[i]+=a[i-1],qs.pb(pii(i-1,i));
	}
	else
	{
		int ls=-1;
		for(int i=1;i<=n;++i) if(a[i]<0)
		{
			if(ls==-1) ls=i;
			else a[ls]+=a[i],qs.pb(pii(i,ls));
		}
		for(int i=1;i<=n;++i) if(a[i]>=0)
			a[i]+=a[ls],qs.pb(pii(ls,i));
		for(int i=n;i>=2;--i) 
			a[i-1]+=a[i],qs.pb(pii(i,i-1));
	}
	printf("%d\n",int(qs.size()));
	for(auto q:qs) printf("%d %d\n",q.fi,q.se);
}


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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n=5,x,ans;
        for(int i=0;i<n;i++){cin>>x;if(!x)ans=i;}
        cout<<ans+1<<endl;
    }
    return 0;
}


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

int main(){
    string s,t;
    cin >> s >> t;
    int ans = 0;
    for(int i=0;i<3;i++){
        if(s[i] == t[i]) ans++;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
    long long N, D, A;
    cin >> N >> D >> A;
    vector<pair<long long, long long>> v;
    for (int i = 0; i < N; i++) {
        long long x, h;
        cin >> x >> h;
        long long k = ((h + A - 1) / A);
        v.push_back(make_pair(x, k));
    }
    sort(v.begin(), v.end());
    vector<pair<long long, long long>> a;
    long long ans = 0;
    a.push_back(make_pair(-1LL, 0LL));
    for (int i = 0; i < N; i++) {
        auto l = lower_bound(a.begin(), a.end(), make_pair(v[i].first, 0LL));
        l--;
        long long p = a.back().second - (*l).second;
        long long r = max(0LL, v[i].second - p);
        ans += r;
        a.push_back(make_pair(v[i].first + 2 * D, a.back().second + r));
    }
    cout << ans << endl;
}

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

int d[105][105], a[105];
vector<int> v;
int main()
{
	int h, w, n, x;
	cin >> h >> w >> n;
	for(int i=1; i<=n; i++)
	{
		cin >> x;
		while(x--)
		{
			v.push_back(i);
		}
	}
	for(int i=1; i<=h; i++)
	{
		if(i%2 == 1)
		{
			for(int j=1; j<=w; j++)
			{
				if(v.empty()) break;
				d[i][j] = v.front();
				v.erase(v.begin());
			}
		}
		else
		{
			for(int j=w; j>=1; j--)
			{
				if(v.empty()) break;
				d[i][j] = v.front();
				v.erase(v.begin());
			}
		}
	}
	for(int i=1; i<=h; i++)
	{
		int z = 0;
		for(int j=1; j<=w; j++)
		{
			if(z) cout << " ";
			cout << d[i][j];
			z = 1;
		}
		cout << endl;
	}
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

int n, m;

int main() {
#ifdef isLOCAL
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif 

    cin >> m, n = (m - 1 >> 2) + 1 << 1;
    if (m <= 500) {
        cout << m << endl;
        for (int i = 1; i <= m; ++i)
            for (int j = 1; j <= m; ++j)
                printf("%d%c", (i + j - 2) % m + 1, " \n"[j == m]);
        return 0;
    }
    cout << n << endl;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j) {
            int tmp = (i + j - 2) % n + 1;
            if (i % 2 == 0 && tmp + n <= m) tmp += n;
            printf("%d%c", tmp, " \n"[j == n]);
        }
    return 0;
}


Measured memory_bytes: 1152
#include<iostream>

using namespace std;
int main()
{
    int n,m,a[10001];
    cin>>n>>m;int sub,sum=0;
    for(int i=0;i<m;i+=1){
        cin>>a[i];
        sum = sum+a[i];
    }
    sub = (n-sum);
    if(sub<0){
        cout<<"-1"<<endl;
    }
    else{
        cout<<sub<<endl;
    }


    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
using Graph = vector<vector<int>>;

int main(){
	int n, sum = 0; cin >> n;
	string s; cin >> s;
	char c = '#';
	rep(i, n){
		if(c != s[i]) sum++;
		c = s[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 512
N = int(input())

WL = []
for _ in range(N):
    WL.append(input())

WS = set(WL)

R = 'Yes'
if len(WL) == len(WS):
    for w1, w2 in zip(WL[:-1], WL[1:]):
        if w1[-1] != w2[0]:
            R = 'No'
            break
else:
    R = 'No'

print(R)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
"""
Created on Sun Sep  6 12:21:24 2020

@author: liang
"""
import math
pi = 3.141592653589793238
h, m, H, M = map(int,input().split())

print(math.sqrt(h**2+m**2-2*h*m*math.cos(2*pi*(30*H-5.5*M)/360)))

Measured memory_bytes: 9388
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i< (int) n; i++)
#define PI  3.14159265358979323846264338327950
 
 
int main () {
    int x,a,b;

    cin >> x >> a >> b;

    if(abs(x-a) > abs(x-b))cout << "B" << endl;
    else cout << "A" << endl;
}


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

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
#define rep(i,n) for(ll i = 0;i<(ll)n;i++)
using namespace std;
typedef long long ll;
static const int MAX = 50;
static const long long INFTYL = 9223372036854775807;
ll mod = 1000000007;

int main()
{
	ll N;
	cin >> N;
	ll A[100000];
	map<ll, ll> mp;
	rep(i, N) {
		cin >> A[i];
		mp[A[i]]++;
	}

	int count = 0;
	for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++)
	{
		if (it->second % 2 == 0) {
			count++;
		}
	}

	cout << ((count % 2 == 0) ? mp.size() : mp.size() - 1) << endl;
	return 0;
}

Measured memory_bytes: 7296