akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

public class Hello{
    public static void Main(){
        var n = int.Parse(Console.ReadLine());
        List<string> list = new List<string>{};
        for(var i = 0; i < n; i++){
            list.Add(Console.ReadLine());
        }
        List<string> result = list.Distinct().ToList();
        Console.WriteLine(result.Count);
    }
}


Measured memory_bytes: 49304
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
int DP[11][2001],Maxes[11][2001];
int main() {
	int N,K=10,KK;
	vector<int> books[11];
	cin >> N >> KK;
	for(int i=0;i<N;i++){
		int C[2];
		cin >> C[0] >> C[1];
		books[C[1]].push_back(C[0]);
	}
	for(int i=1;i<=K;i++){
		sort(books[i].begin(),books[i].end(),greater<int>());
	}
	for(int i=1;i<=10;i++){
		int sum=0;
		for(int j=0;j<books[i].size();j++){
			sum+=books[i][j];
			DP[i][j+1]=sum+(j+1)*j;
			Maxes[i][j+1]=sum+(j+1)*j;
		
		}
	}
	//cout << Maxes[1][30]+
	for(int i=2;i<=10;i++){
		for(int j=1;j<=KK;j++){//全体の購入数
			for(int k=0;k<=j;k++){//今回のジャンルの購入数
				int l=0;
				if(books[i].size()>=k && k!=0){
					//cout <<Maxes[i][k-1]+DP[i-1][j-k] << endl ;// << j << " "  << endl;
					l=Maxes[i][k]+DP[i-1][j-k];
				}
				else if(k==0){
					l=DP[i-1][j-k];
				}
				DP[i][j]=max(DP[i][j],l);
			}
			//cout << DP[i][j] << " " << i << j<<endl;
		}
	}
	cout << DP[10][KK] <<endl;
}

Measured memory_bytes: 1352
def f(n, a):
    x = list(sorted(set(a)))
    n_sub_half = n * (n + 1) // 2 // 2
    n_plus_minus = n * 2 + 1
    Li = 0
    Ri = len(x)
    while Ri > Li + 1:
        i = (Li + Ri) // 2
        xi = x[i]
        cnt_sum = [0] * n_plus_minus
        cumsum = 0
        cnt_sum[cumsum] = 1
        judge = 0
        s = 0
        for ak in a:
            if ak >= xi:
                cumsum += 1
                s += cnt_sum[cumsum] + 1
            else:
                cumsum -= 1
                s -= cnt_sum[cumsum + 1] - 1
            cnt_sum[cumsum] += 1
            judge += s
            if judge >= n_sub_half:
                Li = i
                break
        else:
            Ri = i
    print(x[Li])


n = int(input())
a = list(map(int, input().split()))
f(n, a)


Measured memory_bytes: 14612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.lang.Math;
import java.util.Map;
import java.util.ArrayList;
import java.util.Collections;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        int[] ar = fs.readArray(n);


        int count = 0;
        ArrayList<Integer> forbidden = new ArrayList<>();
        Arrays.sort(ar);
        boolean[] xr = f(ar,ar[n-1]+1);
        for (int i = 0; i<n-1; i++) {
            if (ar[i] == ar[i+1]) {
                forbidden.add(ar[i]);
            }
        }
        int av = 0;
        for (int i : ar) {
            if (xr[i] == true) {
                for (int q = 0; q<forbidden.size(); q++) {
                    if (i == forbidden.get(q)) {
                        av =1;
                        break;
                    }
                }
                if (av == 0) {
                    count++;
                } else {
                    av=0;
                }
            }
        }
        System.out.println(count);

    }
    public static boolean[] f(int[] ar, int n) {

        boolean[] x = new boolean[n];
        for (int i = 0; i < n; i++) {
            x[i] = true;
        }
        for (int a : ar) {
            for (int i = 2*a; i < n; i += a) {
                x[i] = false;
            }
        }
        return x;


    }


    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");

        public String next() {
            while (!st.hasMoreElements())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
    }

}
 

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

const int maxN = 3005;

int n, mod;
int S[maxN + 1][maxN + 1], C[maxN + 1][maxN + 1];
int pw[maxN * maxN + 1];

inline int ADD(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }

inline int SUB(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }

inline int mpow(int a, int x, int mod)
{
	int ans = 1;
	while(x)
	{
		if(x & 1) ans = 1ll * ans * a % mod;
		a = 1ll * a * a % mod;
		x >>= 1;
	}
	return ans;
}

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

	S[0][0] = C[0][0] = 1;
	for(int i = 1; i <= n + 1; i++)
	{
		C[i][0] = 1;
		for(int j = 1; j <= i; j++)
			C[i][j] = ADD(C[i - 1][j], C[i - 1][j - 1]),
			S[i][j] = ADD(S[i - 1][j - 1], 1ll * j * S[i - 1][j] % mod);
	}

	pw[0] = 1;
	for(int i = 1; i <= n * n; i++)
		pw[i] = 2ll * pw[i - 1] % mod;

	int ans = 0;
	for(int i = 0; i <= n; i++)
	{
		int res = 0;
		for(int j = 0; j <= i; j++)
			res = ADD(res, 1ll * pw[j * (n - i)] * S[i + 1][j + 1] % mod);
		res = 1ll * res * C[n][i] % mod * mpow(2, mpow(2, n - i, mod - 1), mod) % mod;
		ans = (i & 1) ? SUB(ans, res) : ADD(ans, res);
	}

	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 106112
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int count[] = { 0, 0, 0, 0 };
    for (int i = 0; i < 6; i++) {
      int in = Integer.parseInt(sc.next());
      count[in - 1]++;
    }

    Arrays.sort(count);
    if (count[0] == 1 && count[1] == 1 && count[2] == 2 && count[3] == 2) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }

  }
}

Measured memory_bytes: 23892
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

class UnionFind{
public:
  vector<int> par;
  vector<int> rank;
  vector<int> sz;
  int N;

  UnionFind(int n){N = n;}

  //初期化
  void init(){
      for(int i = 0; i < N; i++){
          par.push_back(i);
          rank.push_back(0);
          sz.push_back(1);
      }
  }

  //木の根を求める
  int find(int x){
    if(par[x] == x) return x;
    else {
      par[x] = find(par[x]);
      return par[x];
    }
  }

  //xとyの集合の併合
  void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank[x] < rank[y]){
      par[x] = y;
      sz[y] += sz[x];
    }else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x] == rank[y]) rank[x]++;
    }
  }

  //x,yが同じ集合にあるか
  bool same(int x, int y){
      return find(x) == find(y);
  }

  //xの木のサイズ
  int size(int x){
      return sz[find(x)];
  }

  //ufの連結成分の数
  int cnt_connection(){
      int res = 0;
      bool ex[N];
      fill(ex, ex + N, false);
      for(int i = 0; i < N; i++){
          ex[find(i)] = true;
      }

      for(int i = 0; i < N; i++){
          if(ex[i]) res++;
      }

      return res;
  }
};


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

typedef pair<ll, int> P;
typedef priority_queue<ll, vector<ll>, greater<ll>> PQ;
#define fs first
#define sc second

int main(){
    int N, M;
    cin >> N >> M;
    ll a[N];
    for(int i = 0; i < N; i++) cin >> a[i];


    UnionFind uf = UnionFind(N);
    uf.init();

    for(int i = 0; i < M; i++){
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }

    map<int, PQ> mp;
    for(int i = 0; i < N; i++){
        mp[uf.find(i)].push(a[i]);
    }

    //コーナー
    if(M == N - 1){
        cout << 0 << endl;
        return 0;
    }

    if(2 * (N - M - 1) > N){
        cout << "Impossible" << endl;
        return 0;
    }

    //本命
    ll ans = 0;
    int cnt = 2 * (N - M - 1);
    for(auto it = mp.begin(); it != mp.end(); it++){
        ans += (it -> second).top();
        (it -> second).pop();
        cnt--;
    }

    PQ que2;
    for(auto it = mp.begin(); it != mp.end(); it++){
        PQ que = it -> second;
        while(!que.empty()){
            que2.push(que.top());
            que.pop();
        }
    }

    for(int i = 0; i < cnt; i++){
        ans += que2.top();
        que2.pop();
    }

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


Measured memory_bytes: 13164
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	uf := newUnionFind(n + 1)
	var a, b int
	for i := 0; i < m; i++ {
		fmt.Scan(&a, &b)
		uf.unite(a, b)
	}

	gs := make(map[int]bool)
	for i := 1; i <= n; i++ {
		gs[uf.root(i)] = true
	}
	fmt.Println(len(gs) - 1)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// UnionFind .
type UnionFind struct {
	par   []int
	rank  []int
	sizes []int
}

func newUnionFind(n int) UnionFind {
	u := UnionFind{}
	u.par = make([]int, n)
	u.rank = make([]int, n)
	u.sizes = make([]int, n)
	for i := 0; i < n; i++ {
		u.par[i] = i
		u.rank[i] = 0
		u.sizes[i] = 1
	}
	return u
}

func (u UnionFind) unite(x, y int) {
	x = u.root(x)
	y = u.root(y)
	if x == y {
		return
	}

	if u.rank[x] < u.rank[y] {
		u.par[x] = y
		u.sizes[y] += u.sizes[x]
	} else {
		u.par[y] = x
		u.sizes[x] += u.sizes[y]
		if u.rank[x] == u.rank[y] {
			u.rank[x]++
		}
	}
}

func (u UnionFind) root(x int) int {
	if u.par[x] == x {
		return x
	}
	u.par[x] = u.root(u.par[x])
	return u.par[x]
}

func (u UnionFind) same(x, y int) bool {
	return u.root(x) == u.root(y)
}

func (u UnionFind) size(x int) int {
	return u.sizes[u.root(x)]
}


Measured memory_bytes: 7520
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	// if c-a-b < 0 {
	// 	fmt.Println("No")
	// 	return
	// }
	condition := (c-a-b)*(c-a-b) - 4*a*b
	if condition > 0 && c > a+b {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  char S[16]; bool flg=true; int size=0;
  cin >> S;
  for(int i = 0; i<14; i++){
    if(S[i]=='\0'){ size = i; break;}
  }
  if(size%2==0){
  for(int i=0; i< size/2; i++){
    if(S[2*i]!='h' || S[2*i+1]!='i') flg = false;
  }
  }
  else{
    flg=false;
  }
  if(flg) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    tmp0 = input[0].split(" ");
    N = Number(tmp0[0])
    D = Number(tmp0[1])
    console.log(Math.ceil(N/(2*D+1)))
}
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main("14 3\n");

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

vector<int>to[100010],id[100010],ans;

void dfs(int v, int c=-1, int p=-1){
    int k=1;
    rep(i,to[v].size()){
        int u=to[v][i],ei=id[v][i];
        if(u==p)continue;
        if(k==c)k++;
        ans[ei]=k; k++;
        dfs(u,ans[ei],v);
    }
}

int main(){
    int n;
    cin>>n;
    ans.resize(n);
    rep(i,n-1){
        int a,b; cin>>a>>b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
        id[a].push_back(i);
        id[b].push_back(i);
    }
    dfs(0);
    int mx=0;
    rep(i,n-1)mx=max(mx,ans[i]);
    cout<<mx<<endl;
    rep(i,n-1)cout<<ans[i]<<endl;
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int d;
    cin >> d;

    int ans = 0;

    for (int i = 0; i < n; i++) {
        long long int x,y;
        cin >> x >> y;
        if (d >= sqrt(x*x + y*y)) {
            ans++;
         
        }
        
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
fn main() {
    let n = read::<usize>();
    let a = read_vec::<i64>();
    let all_xor = a.iter().fold(0, |x, s| x ^ s);
    let mut a = a.into_iter().map(|x| x & !all_xor).collect::<Vec<_>>();

    let mut r = 0;
    for di in 0..60 {
        let bit = 59 - di;
        let mut pivot = None;
        for i in r..n {
            if (a[i] >> bit) & 1 == 1 {
                pivot = Some(i);
            }
        }

        if let Some(j) = pivot {
            a.swap(r, j);
            for k in r + 1..n {
                if (a[k] >> bit) & 1 == 1 {
                    a[k] ^= a[r];
                }
            }
            r += 1;
        }
    }
    let mut temp = 0;
    for num in a {
        temp = std::cmp::max(temp, temp ^ num);
    }
    println!("{}", all_xor + 2 * temp);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 5888
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    ll n;
    cin >> n;

    string s;

    ll t = n, v = 1, w = 1;
    while (t) {
        ll u = (t & w) != 0;
        s.push_back('0' + u);
        t -= u * v;
        v *= -2;
        w *= 2;
    }

    if (s.empty()) s = "0";
    reverse(s.begin(), s.end());

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;


int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int H, W; cin >> H >> W;
  int h, w; cin >> h >> w;
  int res = (H - h) * (W - w);
  cout << res << '\n';
}

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

int main() {
    string s;
    cin >> s;
    bool a=false;
    for(int i=1;i<=4;i++){
      if(s[i-1]==s[i]) a=true;
    }
    if(a==true) cout << "Bad" << endl;
    else  cout << "Good" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define code                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(0);
#define int long long
#define MM(a, b) memset(a, b, sizeof(a))
const ll MOD = 1000000007;
using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	cout.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}

int32_t main()
{
	code;

	string s; cin>>s;
	for(int i=0;i<s.length();i++) cout<<'x';
}

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

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

struct city{
  string s;
  int point, num;
  const bool operator < (city b) const {
    if (s == b.s) {
      return point > b.point;
    } else return s < b.s;
  }
};

void solve() {
  int n;
  cin >> n;
  city a[n];
  REP(i,n) {
    cin >> a[i].s >> a[i].point;
    a[i].num = i+1;
  }
  sort(a,a+n);
  REP(i,n) cout << a[i].num << endl;
}

int main(int argc, char *argv[]){
  int case_num = 1;
  // while (1) if (solve()) break;
  if (argc > 1 && stoi(argv[1])) cin >> case_num;
  REP(case_no, case_num) {
    cerr << endl << "case " << case_no + 1 << endl;
    solve();
  }
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(P, Q, R):
    return sum(sorted([P, Q, R])[:2])


def main():
    P, Q, R = read_int_n()
    print(slv(P, Q, R))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7228
#include <iostream> 
#include <sstream> // istringstream
#include <string> // 文字列
#include <algorithm> // アルゴリズム
#include <cmath> // 
#include <vector> // vector
#include <set> // set
#include <map> // map

using namespace std;

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

    long long ans = 0;
    for(int i=0; i<N-1; ++i){
        int dis = A[i] - A[i+1];
        if (dis > 0) {
            ans += dis;
            A[i+1] = A[i];
        }
    }

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

Measured memory_bytes: 4328
using System;
using System.Numerics;
using System.Linq;

namespace AtCoder.Abc172
{
    class B
    {
        public static void Main()
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();

            int count = 0;
            for (int i = 0; i < s.Length; i++)
                if (s[i] != t[i])
                    count++;
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27448
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define erep(i, n) for(ll i = 1; i <= (n); i++)
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main(void) {
  int n;
  cin >> n;
  vector<int> w(n), s(n+1, 0);
  rep(i,n)cin >> w[i];
  rep(i,n)s[i+1] = s[i] + w[i];
  int ans = 1e9;
  rep(i,n){
    int left = s[i], right = s[n] - s[i];
    mins(ans, abs(right - left));
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3632
import sys

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))


a, b, c = rm()
if a == b == c:
  if a & 1:
    print(0)
  else:
    print(-1)
  exit()
cnt = 0
while a & 1 == 0 and b & 1 == 0 and c & 1 == 0:
  a, b, c = (b+c)//2, (a+c)//2, (a+b)//2
  cnt += 1
print(cnt)





Measured memory_bytes: 9112
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
// #define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#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 rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

bool b[7368792];

void run(){
    int m,n;
    cin>>m>>n;
    if(!m)return;
    MEMSET(b);
    int k=m;
    rep(i,n){
        while(b[k])k++;
        for(int j=k;j<=7368791;j+=k){
            b[j]=true;
        }
    }
    while(b[k])k++;
    cout<<k<<endl;
    run();
}


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

const int INF = 1e+9;
const int MAX_N = 1000001;
int s[MAX_N] = {0};

int sum(int i, int j){
	return s[i] - s[j];
}

int main(){
	int a, b, c, d, e, na, nb, nc;
	while( cin >> a >> b >> c >> d >> e >> na >> nb >> nc, a ){
		vector<int> v;
		for(int i = 0; i < na; i++) v.push_back(a);
		for(int i = 0; i < nb; i++) v.push_back(b);
		for(int i = 0; i < nc; i++) v.push_back(c);
		sort(v.rbegin(), v.rend());
		
		fill(s, s + MAX_N, 0);
		s[0] = a * na + b * nb + c * nc;
		for(int i = 0; i < v.size(); i++) s[i+1] = s[i] - v[i];
		
		//for(int i = 0; i < v.size(); i++) cout << s[i] << endl;
		
		int ans = s[0];
		for(int i = 0; i <= v.size(); i++){
			int res = 0;
			//cout << "k:" << i;
			if( d <= i ){
				int add = sum(0, i);
				if( i * e < add ) add = i * e;
				res += add;
				//cout << ", " << add;
			}else{
				int add = sum(0, i);
				if( d * e < add ) add = d * e;
				res += add;
				//cout << ", " << add;
			}
			res += s[i];
			//cout << " + " << s[i] << endl;
			ans = min(ans, res);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 9136
n, a, b = list(map(int, input().split(" ")))

if (a + b) % 2 == 0:
    print((b - a) // 2)
    exit()
else:
    if b - 1 < n - a:
        print(b - 1 - ((b - a) // 2))
    else:
        print(n - a - ((b - a) // 2))

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

struct Query {
  int index;
  int l, r;
};

// Supports two operations.
// - Updates a single element.
// - Returns a sum of a range.
// Verified: CF573Div1D
class BinaryIndexedTree {
 private:
  int n;
  vector<int64> xs;
 public:
  BinaryIndexedTree(int n) : n(n), xs(n) {}

  // Adds x to the i-th element.
  void Add(int i, int64 x) {
    int cur = i;
    while (cur < n) {
      xs[cur] += x;
      cur = cur | (cur + 1);
    }
  }

  // Returns a sum of a range [l, r).
  int64 SumRange(int l, int r) {
    if (l >= r) return 0;
    if (l > 0) {
      return SumRange(0, r) - SumRange(0, l);
    }
    int64 s = 0;
    int i = r - 1;
    while (i >= 0) {
      s += xs[i];
      i = (i & (i + 1)) - 1;
    }
    return s;
  }
};

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

  int n;
  int q;
  cin >> n >> q;
  vector<int> cs(n);
  for (int i = 0; i < n; i++) {
    cin >> cs[i];
    cs[i]--;
  }
  vector<vector<Query>> r_to_qs(n);
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    r_to_qs[r].push_back({i, l, r});
  }

  vector<int> last_pos_vector(n, -1);
  
  BinaryIndexedTree tree(n);
  
  vector<int64> ans(q);
  for (int r = 0; r < n; r++) {
    int c = cs[r];
    int p = last_pos_vector[c];
    last_pos_vector[c] = r;
    if (p >= 0) {
      tree.Add(p, -1);
    }
    tree.Add(r, 1);
    for (const auto& q : r_to_qs[r]) {
      int64 v = tree.SumRange(q.l, q.r + 1);
      ans[q.index] = v;
    }
  }
  for (int i = 0; i < q; i++) {
    cout << ans[i] << "\n";
  }
}


Measured memory_bytes: 38004
#include<iostream>
#include<vector>
#include<climits>
#include<cmath>

int main(){
  int N;
  std::cin >> N;
  std::vector<int> XVec(N);
  for(int i= 0; i < N;i++){
    std::cin >> XVec.at(i);
  }
  
  int minRes = INT_MAX;
  for(int s=1;s <= 100 ; s++){
    int curr = 0;
    for(auto x : XVec){
      curr += std::pow(x - s, 2);
    }
    if(curr < minRes){
      minRes = curr;
    }
  }
  
  std::cout << minRes;
  
  return 0;
  
  
  
  


}

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


#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll fact(ll n){
	
    ll res = 1; 
    for (ll i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 
  
int nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
 
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 


ll ston(string s) 
{ 
    stringstream geek(s); 
    ll x = 0; 
    geek >> x; 
    
  
    return x; 
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[0] < v2[0]; 
} 

 ll degit(ll n)
 {
 	ll t=0;
 	while(n>0)
 	{
 		t++;
 		n/=10; 	}
 		return t;
 }
 

void solve()
{
	ll n, a[114][514] = {0};
	cin>>n;
	string s;
	for(int i=0;i<n;i++)
	{
    	cin>>s;
    	for(int j=0;j<s.size();j++)
    		a[i][s[j]-97]++;
	}
	for(int j=0;j<26;j++)
	{
    	a[n][j]=810;
    	for(int i=0;i<n;i++)
    	{
    		a[n][j]=min(a[n][j],a[i][j]);
    	}
    	for(int i=0;i<a[n][j];i++)
    		cout<<(char)(97+j);
  }
  cout<<endl;
	
}
	

int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,pair<int,int>> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
const double EPS=1e-9;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
int main(){
    string s;cin>>s;
    int n=s.length();
    if(n%2&&s[0]==s[n-1]){
        cout<<"Second"<<endl;
    }else if(n%2==0&&s[0]==s[n-1]){
        cout<<"First"<<endl;
    }else if(n%2&&s[0]!=s[n-1]){
        cout<<"First"<<endl;
    }else{
        cout<<"Second"<<endl;
    }
}


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

int n;
char s[101];
int r = 0;
int b = 0;

int main(){
	cin >> n;
	cin >> s;
	
	for(int i=0; i<n; ++i){
		if(s[i]=='R'){
			++r;
		}else{
			++b;
		}
	}
	
	if(r > b){
		cout << "Yes";
	}else{
		cout << "No";
	}
	
	return 0;
} 


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

#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"

int solve(int x, int y) {
  if (x == y)
    return 0;
  if (x == 0)
    return y > 0 ? y : 1 + abs(y);
  if (y == 0)
    return x < 0 ? abs(x) : 1 + x;
  if (x < 0 && 0 < y) {
    if (-x > y)
      return 1 + -x - y;
    return 1 + y + x;
  }
  if (y < 0 && 0 < x) {
    if (x > -y)
      return 1 + solve(-x, y);
    return - y - x + 1;
  }
  if (x < y)
    return y - x;
  return 2 + x - y;
}
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  IN(x); IN(y);

  OUT(solve(x, y));

  return 0;
}


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

# define ll long long
# define mod 1000000007
# define MAX 100005
# define PI 3.141592653589793238                                                                                  //shortcut keys

# define pb push_back
# define mp make_pair
# define all(x) x.begin(),x.end()
# define fr(i,a,b) for(int i=a;i<=b;i++)

# define decimal(k) fixed<<setprecision(k)
# define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);        //---------------------------------------------------------------
using namespace std;

int main()
{
   int n;cin>>n;
   ll a[n+1];fr(i,1,n)cin>>a[i];
   ll ans=0;
   fr(i,1,n){
   	fr(j,i+1,n){
   		fr(k,j+1,n){
   			if(a[i]!=a[j]&&a[i]!=a[k]&&a[j]!=a[k]){
   				if(a[i]+a[j]>a[k]&&a[j]+a[k]>a[i]&&a[k]+a[i]>a[j])ans++;
			   }
		   }
	   }
   }
   cout<<ans<<'\n';
   return 0;
	 
}



Measured memory_bytes: 3640
//██████╗ ██╗   ██╗██╗      ██████╗ ███████╗
//██╔══██╗██║   ██║██║      ██╔══██╗██╔════╝
//██████╔╝██║   ██║██║█████╗██║  ██║█████╗
//██╔══██╗██║   ██║██║╚════╝██║  ██║██╔══╝
//██║  ██║╚██████╔╝██║      ██████╔╝███████╗
//╚═╝  ╚═╝ ╚═════╝ ╚═╝      ╚═════╝ ╚══════╝

#include <iostream>
#include <random>
#include <vector>
#include <set>
#include <algorithm>
#include <iomanip>
#include <chrono>
#include <cstdio>
#include <map>
#include <memory.h>


// #pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back

#define all(v) (v).begin(), (v).end()
#define sz(v) ((int)(v).size())
#define sqr(x) ((x) * (x))

typedef long long ll;
typedef  double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;

#define next ajksdslk
#define prev aklsfjk

mt19937_64 mt_rand(chrono::system_clock::now().time_since_epoch().count());

template<typename T1, typename T2> inline bool upmax(T1& a, T2 b) { return (a < b ? (a = b, true) : false); }
template<typename T1, typename T2> inline bool upmin(T1& a, T2 b) { return (b < a ? (a = b, true) : false); }

const int maxn = (int) 5e6 + 100;
const int maxlog = 21;
const int base = 998244353;
const ld eps = (ld) 1e-9;
const ld PI = acos(-1.);
//const int pp = 41;
const int inf = 2e9;
const ll llinf = 1e18;

int n, k;
int a[maxn];
int pref[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#ifdef LOCAL
  freopen ("input.txt", "r", stdin);
#endif
  cin >> n >> k;
  map<int,int> prf;
  int sum = 0;
  prf[sum] = 1;
  pref[0] = 0;
  ll ans = 0;
  for (int i = 1; i <= n; i ++) {
    cin >> a[i];
  }

  for (int i = 1; i <= n; i ++) {
    if (i - k >= 0) {
      prf[ pref[i - k] ] -= 1;
    }
    (sum += a[i] - 1) %= k;
    ans += prf[sum];
    prf[sum] += 1;
    pref[i] = sum;
//    cout << sum << ' ';


  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 12416
N, M = map(int, input().split())
a_b_list = [list(map(int, input().split())) for i in range(M)]

a_b_list.sort(key=lambda x: x[0])

max_a = a_b_list[0][0]
min_b = a_b_list[0][1]
count = 1
# print(a_b_list[0], a_b_list[0][0], min_b, count)
for a_b in a_b_list[1:]:
    # print(a_b, a_b[0], min_b, count)

    if a_b[0] < min_b:
        min_b = min(min_b, a_b[1])
    else:
        count += 1
        min_b = a_b[1]

print(count)

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool ans = false;
    for (int i = 0; i < 3; ++i) {
        if (s[i] == '7') ans = true;
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define fast ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define F(i,a,b) for(int i= (int)(a); i<(int)(b);i++)
#define FI(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define what_is(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
const int N = 1e6+7 ;
string s ;

int main(){fast ;
	int a, b ;
	cin >> a >>  b ;
	cout << max({a+b, 2*a-1, 2*b-1}) << endl ;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n,m;
    cin>>n>>m;
    REP(i,n){
        int t;
        cin>>t;
    }
    cout<<(n-1+m-2)/(m-1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define pic pair<ll,char>
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii > 
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll dp[3001][3001];
ll arr[3001];
signed main()
{
    fast;
    ll n,q,i,j;
    cin>>n>>q;
    ll tot = power(2,q);
    for(i=1;i<=n;i++)
        cin>>arr[i];
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            if(arr[i]>arr[j])
                dp[i][j] = tot;
        }
    }
    ll inv = power(2,mod-2);
    while(q--)
    {
        ll x,y;
        cin>>x>>y;
        for(i=1;i<=n;i++)
        {
            if(i!=x and i!=y)
            {
                dp[i][x] = inv*(dp[i][x]+dp[i][y])%mod;
                dp[i][y] = dp[i][x];
                dp[x][i] = inv*(dp[x][i]+dp[y][i])%mod;
                dp[y][i] = dp[x][i];
            }
        }
        dp[x][y] = inv*(dp[x][y]+dp[y][x])%mod;
        dp[y][x] = dp[x][y];
    }
    ll ans = 0;
    for(i=1;i<=n;i++)
        for(j=i+1;j<=n;j++)
            ans+=dp[i][j],ans%=mod;
    cout<<ans;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);

using namespace std;
const int N = 1e4 + 4;
const int mod = 1e9 + 7;
const long long INF = 1e18;
const int inf = 1e9;

pair <long long, long long> a[N];

long long dp[3020][N];

int main () {
	boost;
	int n, t;
	cin >> n >> t;
	for (int i = 1 ; i <= n ; ++ i) {
		cin >> a[i].first >> a[i].second;
	}
	sort (a + 1, a + 1 + n);
	long long mx = 0;
	for (int i = 1 ; i <= n ; ++ i) {
		for (int j = 0 ; j <= t * 2 ; ++ j) {
			dp[i][j] = max (dp[i][j], dp[i - 1][j]);
			mx = max (mx, dp[i][j]);
			if (j >= t)
				continue;
			dp[i][j + a[i].first] = max (dp[i][j + a[i].first], dp[i - 1][j] + a[i].second);
			mx = max (mx, dp[i][j + a[i].first]);
		}
	}
	cout << mx;
}

Measured memory_bytes: 235008
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int N;
  cin >> N;
  vector<ll> A(N);
  int flag=0;
  REP(i, N){
    cin >> A[i];
    if(A[i]==0){
      flag=1;
    }
  }
  if(flag==0){
    ll ans=1;
    REP(i,N){
      if(1000000000000000000/ans<A[i]||ans*A[i]>1000000000000000000){
        cout << -1 << endl;
        return 0;
      }
      ans*=A[i];
    }
    cout << ans << endl;
  }else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 3976
#include<iostream>
#include<map>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
using namespace std;
#define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
#define Rep(i,n) REP(i,0,n)
typedef long long ll;

struct Item{
    int value;
    int weight;
};
int N,W;
Item items[102];
int C[102][10003];
//C[i][j]:=items[0]~[i]までを使って重さjまでのうちの価値の最大値
int main(){
    cin>>N>>W;
    REP(i,1,N+1){
        cin>>items[i].value>>items[i].weight;
    }
    REP(i,1,N+1){
        REP(j,0,W+1){
            int w=items[i].weight;
            int v=items[i].value;
            if(w<=j){
                C[i][j]=max(C[i-1][j],C[i-1][j-w]+v);
            }
            else C[i][j]=C[i-1][j];
        }
    }
    cout<<C[N][W]<<endl;

    return 0;
}



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

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

    int n, c = 0;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a.at(i);
        if (a.at(i) % 2 == 0)
        {
            if (a.at(i) % 3 != 0 && a.at(i) % 5 != 0)
            {
                ++c;
            }
        }
    }
    if (c == 0)
        cout << "APPROVED" << endl;
    else
        cout << "DENIED" << endl;

    return 0;
}

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

#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--)

#define SIZE(x) ((ll)(x).size()) 
#define MAX(x) *max_element(ALL(x)) 
#define MIN(x) *min_element(ALL(x)) 
#define ALL(x) (x).begin(),(x).end() 

#define inf 1000000000000 
#define mod 1000000007 
#define MAXR 100000 

#define PB push_back 
#define MP make_pair 
#define F first 
#define S second 

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;}
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
    // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
bool is_prime(ll n){
    int a = sqrt(n);
    if(n == 1 || n == 2 || n == 3) return true;
    else{
        bool frag = true;
        FOR(i, 2, a+1){
            if(n % i == 0) frag = false;
        }
        return frag;
    }
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w, ans=0;
    cin >> h >> w;
    vector<vector<int>> mass(h, vector<int>(w)), c(10, vector<int>(10));
    REP(i, 10) REP(j, 10) cin >> c[i][j];
    REP(i, h) REP(j, w) cin >> mass[i][j];
    //ワーシャルフロイド法
    REP(k, 10) REP(i, 10) REP(j, 10){
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    }
    REP(i, h) REP(j, w){
        if(mass[i][j] > -1) ans += c[mass[i][j]][1];
    }
    cout << ans << endl;

}


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

static const int MAX = 200000;

int main() {
  int R[MAX], n;

  cin >> n;
  for (int i=0; i<n; i++)cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];

  for (int i=1; i < n; i++){
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}

Measured memory_bytes: 3864
from fractions import*
N,*A=map(int,open(0).read().split())
w,B=0,[0]
a=range(N)
for x in a[:]:B+=[gcd(B[-1],A[x])]
w=M=0
for x in a[::-1]:M,w=max(M,gcd(w,B[x])),gcd(w,A[x])
print(M)

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

#define endl '\n'
#define pi 3.1415926

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int R;
    cin >> R;
    cout << fixed << setprecision(6) << 2 * pi * R << endl;
    return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    cout << (e - a <= k ? "Yay!" : ":(") << endl;

}

Measured memory_bytes: 256
from functools import reduce
# リンゴN個から1個リンゴを抜いたときの和と抜かないときの和の差を最小にする、その時の値を求める
Input = input()

n, l = Input.split(' ')
n, l = int(n), int(l)

# i個目の味を出す関数
def ni_taste(i,l=l):
    return l+i-1

taste_list = [ni_taste(i) for i in range(1, n+1)] # リンゴは1, 2, 3, ...と数えられる
taste_abs_list = [abs(abs_taste) for abs_taste in taste_list]

print( reduce((lambda x, y: x + y), taste_list) - taste_list[taste_abs_list.index(min(taste_abs_list))] ,end='' )


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

using namespace std;

const int MaxN = 1001;
const int MaxM = 10001;

int N, M;

int main() {
  int count[MaxM];

  while(cin>>N>>M && !(N==0 && M==0)) {
    vector < vector< pair<int,int> > > logg(MaxM);
    int r;
    cin>>r;
    int t,n,m,s;
    for(int i=0; i<MaxM; i++) { // 初期化
      count[i] = 0;
    }
    for(int i=0; i<r; i++) {
      cin>>t>>n>>m>>s;
      if(s == 1) { // login
	count[m]++;
	if(count[m] == 1) {
	  logg[m].push_back(make_pair(t,t));
	}
      }
      else { // logout
	count[m]--;
	if(count[m] == 0) {
	  logg[m].back().second = t;
	}
      }
    }
    int q;
    cin>>q;
    for(int i=0; i<q; i++) {
      int ts, te, m, ans = 0;
      cin>>ts>>te>>m;
      for(int j=0; j<logg[m].size(); j++) {
	/*if(logg[m][j].first < te) {
	  ans += min(te, logg[m][j].second)-max(ts, logg[m][j].first);
	}*/
	ans += max(0, min(te,logg[m][j].second)-max(ts,logg[m][j].first));
      }
      cout<<ans<<endl;
    }
  }
}

Measured memory_bytes: 1476
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <random>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <complex>
#include <functional>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> int(a);)
#define all(v) v.begin(),v.end()
#define trav(x, v) for(auto &x : v)
#define sz(v) int((v).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vi as(n);
	rep(i,1,n) cin >> as[i], --as[i];
	vector<vi> vs(n);
	vi deg(n);
	rep(i,1,n) ++deg[as[i]];
	stack<int> lf;
	rep(i,0,n) if(deg[i] == 0) lf.push(i);
	while(!lf.empty()){
		int i = lf.top(); lf.pop();
		sort(all(vs[i]));
		reverse(all(vs[i]));
		int res = -1;
		rep(j,0,sz(vs[i]))
			res = max(res, j+vs[i][j]);
		++res;
		//cerr << i << ' ' << res << endl;
		if(i==0){
			cout << res << endl;
			return 0;
		} else {
			vs[as[i]].push_back(res);
			if(--deg[as[i]] == 0) lf.push(as[i]);
		}
	}
}

Measured memory_bytes: 6528
import sys
n=int(input())
a=[int(x) for x in input().rstrip().split()]
a.sort()
if a[0]==0:
  print(0)
else:
  ans=1
  for i in a:
    ans*=i
    if 10**18<ans:
      print(-1)
      sys.exit()
  print(ans)

Measured memory_bytes: 21788
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    int i,j,H,W,N,p,q;
    int a[10010],b[110][110];
    while(~scanf("%d %d",&H,&W))
    {
        scanf("%d",&N);
        for(i=0;i<N;++i)
        {
            scanf("%d",&a[i]);
        }
        p=0;q=0;
        for(i=0;i<N;++i)
        {
            for(j=0;j<a[i];++j)
            {
                switch(p%2)
                {
                case 0:
                    b[p][q]=i+1;
                    ++q;
                    if(q>=W){++p;q=W-1;}
                    break;
                case 1:
                    b[p][q]=i+1;
                    --q;
                    if(q<0){++p;q=0;}
                    break;
                }
            }
        }
        for(i=0;i<H-1;++i)
        {
            for(j=0;j<W;++j)
            {
                if(j!=W-1){printf("%d ",b[i][j]);}
                else{printf("%d \n",b[i][j]);}
            }
        }
        for(j=0;j<W;++j)
        {
            if(j!=W-1){printf("%d ",b[i][j]);}
            else{printf("%d\n",b[i][j]);}
        }
    }
    return 0;
}


Measured memory_bytes: 384