akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	nums := scanNums(N)
	searchList := make([]int, len(nums))
	copy(searchList, nums)
	sort.Ints(searchList)
	left := binarySearch(N, searchList, nums)
  fmt.Println(searchList[left])
}

type BinaryIndexTree struct { BIT []int }
func (b *BinaryIndexTree) add(idx int, val int){
	for x :=idx; x <= len(b.BIT); x+=x&-x {
		b.BIT[x-1] += val
	}
}

func (b *BinaryIndexTree) sum(idx int) int {
  res := 0
	for x := idx; 0 < x; x-=x&-x{
		res += b.BIT[x-1]
	}
	return res
}

func (b *BinaryIndexTree) renderValue(){
	fmt.Println(b.BIT)
}

func cusum(key int, arr []int) ([]int, int, int, int) {
	newArr := make([]int, len(arr))
	_sum := 0
	_nega := 0
	_min := len(arr)
	_max := -1 * len(arr)
	for i, v := range arr {
		if v < key { 
			_sum -= 1 
		} else {
			_sum += 1 
		}

		newArr[i] = _sum
		if _sum > _max { _max = _sum }
		if _sum < _min { _min = _sum }
		if _sum < 0    { _nega += 1 }
	}
	return newArr, _min, _max, _nega
}


func countFallNumber(arr []int, key int) int {
	ans := 0
	newArr, _min, _max, _nega := cusum(key, arr)
	n := _max - _min + 1
	b := BinaryIndexTree{BIT: make([]int, n)}
	for _, v := range newArr{
		ans += b.sum(n) - b.sum(v-_min+1)
		b.add(v-_min+1, 1)
	}
	return ans + _nega
}

func binarySearch(N int, searchList []int, nums []int) int {
	th := float32(N * (N+1) / 4)
	right := len(searchList)
	left := -1
	for (right - left) > 1 {
		mid := (right + left) / 2
		if float32(countFallNumber(nums, searchList[mid])) > th { 
			right = mid 
		} else {
			left  = mid 
		}
	}
	return left
}

func scanNums(len int) (nums []int){
	var num int
	for i := 0; i < len; i++{
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N, M; cin >> N >> M;
    vi p(M);
    vs s(M); REP(i, M) cin >> p[i] >> s[i];
    vi AC(N+1, 0), WA(N+1, 0);
    int correct = 0, penaltie = 0;
    REP(i, M)
    {
        if(s[i] == "AC")
        {
            if(AC[p[i]] != 1)
            {
                correct++;
                penaltie += WA[p[i]];
                AC[p[i]] = 1;
            }
        }
        else if(s[i] == "WA")
        {
            WA[p[i]]++;
        }
    }
    cout << correct << " " << penaltie << endl;
}
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int test;
	set<string> se;
	string s;
	cin>>test;
	while(test--)
	
	{
			cin>>s;
			se.insert(s);
	
	}
		cout<<se.size()<<endl;
	return 0;
}

Measured memory_bytes: 19200
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
 *
 * @author Silviase
 */
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);
    ABC151C solver = new ABC151C();
    solver.solve(1, in, out);
    out.close();
  }

  static class ABC151C {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      int m = in.nextInt();
      boolean[] ac = new boolean[n];
      int[] waCnt = new int[n];
      int acNum = 0;
      int waNum = 0;

      for (int i = 0; i < m; i++) {
        // 提出
        int num = in.nextInt() - 1;
        String s = in.next();
        if (s.equals("AC")) {
          ac[num] = true;
        } else {
          if (ac[num]) {
            // nop
          } else {
            waCnt[num]++;
          }
        }
      }

      for (int i = 0; i < n; i++) {
        if (ac[i]) {
          acNum++;
          waNum += waCnt[i];
        }
      }

      out.println(acNum + " " + waNum);

    }

  }
}



Measured memory_bytes: 63244
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		long[] A = new long[N+1];
		for(int i = 0;i < N;i++) {
			A[i+1] = A[i] + scn.nextLong();
		}

		long ans = Long.MAX_VALUE;
		for(int i = 1;i < N;i++) {
			ans = Math.min(ans, Math.abs( A[N] -2* A[i]));
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 85328
import sys
from collections import Counter
from copy import copy
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()
    D = in_nl() + [0]

    cnt = Counter(D)

    det = []
    non_det = []

    # 0 and 12
    for i in (0, 12):
        if cnt[i] >= 2:
            print(0)
            exit()
        elif cnt[i] == 1:
            det.append(i)

    # 1 - 11
    for i in range(1, 12):
        if cnt[i] >= 3:
            print(0)
            exit()
        elif cnt[i] >= 2:
            det.append(i)
            det.append(24 - i)
        elif cnt[i] == 1:
            non_det.append(i)

    # print(det)
    # print(non_det)

    non_det_len = len(non_det)
    comb = itertools.product([0, 1], repeat=non_det_len)

    ans = 0

    def solve(city):

        comb = itertools.combinations(city, 2)

        ret = 12
        for c in comb:
            t1, t2 = c[0], c[1]
            diff = abs(t2 - t1)
            ret = min(ret, min(diff, 24 - diff))

        return ret

    for com in comb:

        city = copy(det)
        for i in range(non_det_len):
            if com[i] == 0:
                city.append(non_det[i])
            else:
                city.append(24 - non_det[i])

        ans = max(ans, solve(city))

    print(ans)


if __name__ == '__main__':
    main()


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

int n, k;
llong T[1000000];

// 最大積載量Pのトラックk台でどれくらいの荷物を積めるか返す
int check(llong P) {
    int i=0;
    for (int j=0; j<k; j++) {
        llong s=0;
        while (s+T[i] <= P) {
            s += T[i];
            i++;
            if (i==n) return n;
        }
    }
    return i;
}

int solve() {
    llong left = 0;
    llong right = 100000 * 10000;  // 荷物の個数 × 1個辺りの最大重量
    llong mid;
    while (right - left > 1) {
        mid = (left + right) / 2;
        int v = check(mid);  // mid==P を決めて何個積めるかチェック
        if (v>=n) {
            right = mid;
        } else {
            left = mid;
        }
    }
    return right;
}

main() {
    cin >> n >> k;
    for (int i=0; i<n; i++) {
        cin >> T[i];
    }
    llong ans = solve();
    cout << ans << endl;
}


Measured memory_bytes: 3880
def p_c():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    l = [-1] * N

    for i in range(N):
        l[i] = B[i - 1] + B[(i + 1) % N]

    ans = 0

    while 1:
        f = False
        for i in range(N):
            if A[i] <= B[i] - l[i]:
                f = True
                n = (B[i] - A[i]) // l[i]
                ans += n
                B[i] -= n * l[i]
                l[i - 1] -= n * l[i]
                l[(i + 1) % N] -= n * l[i]
        if not f:
            break

    if A != B:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    p_c()

Measured memory_bytes: 118904
/*******************************
 * written by Koki Riho
 * Rih0z https://github.com/Rih0z
 * https://agc023.contest.atcoder.jp/submissions/2426301 
 * Kazune Takahashi さんのものを参考にしました
 *******************************/

#include<iostream>
#include<map>

#define DEBUG false

typedef long long ll;
using namespace std;

int scanN(void );
void readA(ll *a , int n);
void intPrintf(int p);
void llPrintN(ll *a,int n);
void perSum(ll *a , ll *sum ,int n);
ll countSumX( std::map<ll,ll> m,ll *sum,int n );

int N ;
ll A[200010];
ll SUM[200010];
std::map<ll,ll> M ;

int main(){
  if (DEBUG){
    std::printf("******debug mode********\n");
  }
  int i,j ;

  N  = scanN();
  readA(A,N);
  perSum(A,SUM,N);
  M[0] = 1;

  if (DEBUG){
    std::printf("******debug********\n");
    std::printf("a[] = ");
    llPrintN(A,N);
    std::printf("sum[] = ");
    llPrintN(SUM,N);
    std::printf("count = \n");
    std::printf("******debug********\n");
  }
  cout << countSumX( M , SUM, N) << endl;
  return 0 ;
}
//和がxになるところの数を数える
ll countSumX( std::map<ll,ll> m,ll *sum,int n ){
  static ll count;
  for(int i = 0 ; i < N ; i++){
    if ( m.find(sum[i]) == m.end()){
      //見つからなかった
      m[sum[i]] = 1;
    }else{
      //見つかった
      m[sum[i]]++;
    }
  }
  for (auto x : m){
    ll c = x.second;
    count += c * (c-1)/2;
  }
  return count;
}
//各地点までの部分和を計算する
void perSum(ll *a , ll *sum ,int n){
  int i ;
  sum[0] = a[0];
  for(i = 1 ; i < n ; i++){
    sum[i] = a[i] + sum[i-1];
  }

}
int scanN(void ){
  static int n ;

  if(std::scanf("%d",&n)){
  }else{
    std::printf("scanN error\n");
    std::exit(1);
  }

  return n ;
}
void readA(ll *a , int n){
  int ireadA ; 
  for (ireadA =  0 ; ireadA < n ; ireadA++){
    if(std::scanf("%lld",&a[ireadA])){
    }else{
      std::printf("readA error\n");
      std::exit(1);
    }
  }
}

void intPrintf(int p){
  if(std::printf("%d\n",p)){
  }else{
    std::printf("intPrintf Error\n");
    std::exit(1);
  }
}

void llPrintN(ll *a,int n){
  int i ;
  for(i = 0 ; i < n ; i++){
    if(std::printf("%lld ",a[i] )){
    }else{
      std::printf("intPrintN Error i = %d stopped \n",i);
      std::exit(1);
    }
  }
  std::printf("\n");
}

Measured memory_bytes: 15872
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), x.end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
int p[N], val[N];
int ans = 0;

int add(int x, int y) { return x+y < mod ? x+y : x+y-mod; }
int sub(int x, int y) { return x-y < 0 ? x-y+mod : x-y; }
int mul(int x, int y) { return x * 1ll * y % mod; }
template<class T, class... O> int add(T x, O... y) { return add(x, add(y...)); }
template<class T, class... O> int mul(T x, O... y) { return mul(x, mul(y...)); }
int sq(int x) { return mul(x, x); }

int pw(int x, int y) {
  int r = 1;
  for (; y; y /= 2, x = mul(x, x))
    if (y & 1)
      r = mul(r, x);
  return r;
}

int g(int i) {
  int r = 1;
  while (i > 1)
    r = r * 1ll * i % mod, i /= 2;
  return r;
}

int l, h;
int L[N], R[N], vis[N];
int vL[N], vR[N];
vector<int> arr;

void solve(int r) {
  if (2*r >= 2*l) {
    L[r] = R[r] = r;
    return;
  }
  solve(2*r); solve(2*r+1);
  L[r] = L[2*r], R[r] = R[2*r+1];
  for (int i = L[r]; i <= R[2*r]; i++) {
    int j = p[i-l]+l-1;
    int v = mul(val[i], pw(val[r], mod-2), j);
    vL[j] = add(vL[j], v);
    while (j > 1) {
      j /= 2;
      v = mul(v, j);
      vL[j] = add(vL[j], v);
      arr.push_back(j);
    }
  }
  for (int i = L[2*r+1]; i <= R[r]; i++) {
    int j = p[i-l]+l-1;
    int v = mul(val[i], pw(val[r], mod-2), j);
    vR[j] = add(vR[j], v);
    while (j > 1) {
      j /= 2;
      v = mul(v, j);
      vR[j] = add(vR[j], v);
      arr.push_back(j);
    }
  }
  trav(x, arr) if (!vis[x]) {
    int v = mul(r, x);
    ans = add(ans, mul(vL[2*x], vR[2*x+1], v), mul(vR[2*x], vL[2*x+1], v));
    vis[x] = 1;
  }
  trav(x, arr)
    vis[x] = vL[x] = vR[x] = 0;
  for (int i = L[r]; i <= R[r]; i++)
    vL[p[i-l]+l-1] = vR[p[i-l]+l-1] = 0;
  arr.clear();
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cin >> h;
  l = 1 << (h-1);
  for (int i = 0; i < l; i++)
    cin >> p[i];
  for (int i = 1; i < 2*l; i++)
    val[i] = g(i);
  solve(1);
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 25916
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
long long n,m,a[maxn],ans=0;
map<long long,long long> dict;
int main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		a[i]=(a[i]+a[i-1])%m;
		if(dict.count(a[i]))dict[a[i]]++;
		else dict[a[i]]=1;
	}
	for(map<long long,long long>::iterator it =dict.begin();it!=dict.end();it++)
	{
		ans+=(it->second-1)*it->second>>1;
		if(it->first==0)ans+=it->second;
	}
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 4992
#include <algorithm>
#include <stdio.h>
#include <string>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long ll;

int main(void){
  ll n;
  scanf("%lld",&n);
  string s;
  while(n!=0){
    s+=n%2?'1':'0';
    n-=n%2?1:0;
    n/=-2;
  }
  if(!s.size())s="0";
  reverse(s.begin(),s.end());
  printf("%s\n",s.c_str());
}


Measured memory_bytes: 256
N, K = map(int, input().split())


def tell_power_number(number):
    i = 0
    while number * (2 ** i) < K:
        i += 1
    return i


ans = 0
if N <= K - 1:
    for k in range(1, N + 1):
        ans += 1 / N * (1 / 2) ** tell_power_number(k)
else:
    for k in range(1, K):
        ans += 1 / N * (1 / 2) ** tell_power_number(k)
    ans += (N - K + 1) / N

print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    int N,K;
    cin >> N >> K;
    int X[N];
    rep(i,N) cin >> X[i];
    int ans=0;
    rep(i,N) ans+=min(2*X[i],2*abs(K-X[i]));
    cout << ans << endl;
}

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

Ps = [(int(input()), i) for i in range(N)]
Ps.sort()

num = 0
ans = 0
for i in range(N - 1):
    if Ps[i][1] < Ps[i + 1][1]:
        num += 1
    else:
        ans = max(ans, num)
        num = 0
    
ans = max(ans, num)
print(N - ans - 1)


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

#define _BIGNUM_ 100000000

using namespace std;
typedef long long ll;

const ll mod = 1e9+7;

ll f(ll n) {
  if (n % 2 == 0) {
    return n / 2;
  } else {
    return 3 * n + 1;
  }
}

int main() {
  int m[1000001];
  ll s;
  cin >> s;
  m[s] = 1;
  for (ll i = 2; i <= 1000000; ++i) {
    s = f(s);
    if (m[s] != 0) {
      cout << i << endl;
      break;
    }
    m[s] = i;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <set>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;

const int CMax = 100002;

int n, d, ats;
long long sum;

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

    for (int i = 1; i <= n; i += 2) {
        d = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) d++;
        }
        if (d == 8) ats++;
    }

    printf("%d\n", ats);
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





int main() {
    ull n, X;
    cin >> n >> X;
    vector<ull> x(5 * n);
    REP(i, n){
        cin >> x[n - i];
    }
    REP(i, 5 * n - 1){
        x[i + 1] += x[i];
    }
    ull ans = numeric_limits<ull>::max();
    for(ull k = 1; k <= n; k++){
        ull sum = 0;
        for(ull i = 1; i <= n; i += k){
            ull t = (i % k == 0)? i / k : i / k + 1;
            sum += (t == 1)? 5 * (x[i + k - 1] - x[i - 1]) : (2 * t + 1) * (x[i + k - 1] - x[i - 1]);
        }
        ans = min(ans, (n + k) * X + sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 8064
#include<stdio.h>
int main()
{
	int i,len_a=0,len_b=0;
	char a[11],b[11],c[11];
	scanf("%s %s %s",a,b,c);
	for(i=0;a[i];i++)
	  {len_a++;}
	for(i=0;b[i];i++)
	  {len_b++;}
	if(a[len_a-1]==b[0]&&b[len_b-1]==c[0])
	  printf("YES\n");
	else
	  printf("NO\n");
	
	return 0;
	
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void){
  int P,Q,R;

  int ans;
  
  scanf("%d",&P);
  scanf("%d",&Q);
  scanf("%d",&R);
 
  if(P>=Q && P>=R){
    ans = Q+R;
  }else if(Q>=P && Q>=R){
    ans = P+R;
  }else if(R>=P && R>=Q){
    ans = P+Q;
  }
  printf("%d",ans);
  
  return 0;
}

Measured memory_bytes: 128
def c():
    N, M = map(int, input().split())
    # H がグラフの頂点 0, 1, 2, 3, ..., N-1
    H = list(map(int, input().split()))

    # A,B が辺
    G = {}
    for i in range(M):
        A, B = map(int, input().split())
        G[A-1] = max(G.get(A-1, 0), H[B-1])
        G[B-1] = max(G.get(B-1, 0), H[A-1])
    cnt = 0
    for j in range(N):
        if j in G.keys() and H[j] > G[j]:
            cnt += 1
        elif j not in G.keys():
            cnt += 1
    print(cnt)


##########
if __name__ == "__main__":
    c()


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

using namespace std;

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

    for (int i = 0; i < n; i++) {
        string min, max;
        cin >> min;

        sort(min.begin(), min.end());
        max = min;
        reverse(max.begin(), max.end());

        cout << atoi(max.c_str()) - atoi(min.c_str()) << endl;
    }

    return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}


int main()
{
    int n;
    cin >> n;
    vector<int> a(n);

    rep(i,n) cin >> a[i];

    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int alice, bob;
    alice = bob = 0;
    rep(i,n) {
        if (i % 2 == 0) {
            alice += a[i];
        } else {
            bob += a[i];
        }
    }

    cout << alice - bob << endl;
    return 0;
}


Measured memory_bytes: 256
s = int(input())
a = [s]

for i in range(0,1000000):
  if a[i]%2 ==0:
    a.append(a[i]/2)
  else:
    a.append(3*a[i] +1)
  if a[i] in a[:i]:
    print(i+1)
    exit()


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

int main() {
  int A,B,C,K;
  int res = 0;
  cin >> A >> B >> C >> K;
  if(K - A >= 0){
    res += A;
    K -= A;
  }
  else if (K - A < 0){
    res += K;
    K = 0;
  }
  if(K - B >= 0){
    K -= B;
  }
  else if (K - B < 0){
    K = 0;
  }
  
  if(K - C >= 0){
    res -= C;
    K -= C;
  }
  else if (K - C < 0){
    res -= K;
    K = 0;
  }
  
  cout << res << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using ld=long double;
using namespace std;
int main(){
    ld n,m,d,z=2;
    cin>>n>>m>>d;
    if(d==0)z=1;
    cout<<fixed<<setprecision(12)<<(m-1)*z*(n-d-d)/n/n+(m-1)*z*d/n/n;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cill(n);
    cill(k);
    LL m = 1;
    int ans = 0;
    while(n >= m){
        m *= k;
        ans++;
    }
    co(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
   float a;
   cin >> a;
   float pi = 3.14159;
   float ans = a * 2 * pi;
   cout << ans << endl;
}


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


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


    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &it : a) cin >> it;
    
    vector<vector<lli>> dp(n,vector<lli> (n));

    for(int i = n - 1 ; i >= 0 ; --i){
        for(int j = 0 ; j < n ; ++j){
            if(i == j) dp[i][j] = a[i];
            else if(j > i){
                dp[i][j] = max(a[i]-dp[i+1][j],a[j] - dp[i][j-1]);
            }
        }
    }
    cout << dp[0][n-1] << endl;


    return 0;
}

Measured memory_bytes: 70784
#include <iostream>

using namespace std;

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

    if (n % 10 == 3)
    {
        cout << "bon" << endl;
    }
    else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8)
    {
        cout << "pon" << endl;
    }
    else
        cout << "hon" << endl;
}

Measured memory_bytes: 3636
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	counter := make([]int, n)
	for i := 0; i < n; i++ {
		a := getNextInt(scanner) - 1
		counter[a]++
	}
	sort.Ints(counter)
	for i := 0; i < n/2; i++ {
		counter[i], counter[n-i-1] = counter[n-i-1], counter[i]
	}
	ss := make([]int, n+1)
	for i := 0; i < n; i++ {
		ss[i+1] = ss[i] + counter[i]
	}

	for k := 1; k <= n; k++ {
		l := -1
		r := n + 1
		for l+1 < r {
			m := (l + r) >> 1
			ll := -1
			rr := n
			for ll+1 < rr {
				mm := (ll + rr) >> 1
				if counter[mm] < m {
					rr = mm
					continue
				}
				ll = mm
			}

			if rr*m+ss[n]-ss[rr] < m*k {
				r = m
				continue
			}

			l = m
		}
		fmt.Println(l)
	}
	writer.Flush()
}


Measured memory_bytes: 9472
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 100005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); //cout.tie(0);
#define pi 3.1415926535897L
#define db long double  /* print with %Lf */
#define EPS 1e-9
#define flu fflush(stdout)
#define imp {cout<<"No\n"; return 0;}
#define yup {cout<<"Yes\n"; return 0;}
#define debug_vec(vec,n) {rep(idxi,n) cout<<vec[idxi]<<" "; cout<<"\n";}
#define debug_pvec(vec,n) {rep(idxi,n) cout<<vec[idxi].fi<<"-"<<vec[idxi].se<<"  "; cout<<"\n";}
#define debug_set(seta) {cout<<seta.size()<<"\n"; for(auto idxi:seta) cout<<idxi<<" "; cout<<"\n";}
#define debug_map(mappa) {cout<<mappa.size()<<"\n";for(auto idxi:mappa) cout<<idxi.fi<<"-"<<idxi.se<<"  "; cout<<"\n";}
#define debug_vecvec(vec,n) {rep(idxi,n) {for(auto idxi2:vec[idxi]) cout<<idxi2<<" "; cout<<"\n";}}
 
// LOOK AT THESE BEFORE SUBMISSION
// LOOK AT THESE BEFORE SUBMISSION
// ============================================================
// Nmax value and is index access offset taking it beyond Nmax.
// Precision error in case of real numbers.
// N vs N2 chosen correctly.
// Modulo applied everywhere.
// Flush in case of interactive.
// Don't erase value in multiset.
// Check for array indices out of bound (in pre or suff sums).
// Correct return value for functions.
// Confirm the letter case of yes and no.
// Dont paste code two times in the text file.
// ============================================================

int main() {


    get2(n,m);
    ll ans = n*(n-1)/2;
    ans += m*(m-1)/2;
    printf("%lld\n", ans);

    return 0;  
}   


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	A, B, K = MAP()
	if K >= A:
		rest = K-A
		A = 0
		if rest >= B:
			B = 0
		else:
			B -= rest
	else:
		A -= K
	print(A, B)

if __name__ == '__main__':
	main()

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

int main() {
	int n = ri();
	std::pair<int, int> a[n];
	for (int i = 0; i < n; i++) a[i] = {ri(), i};
	std::sort(a, a + n);
	int res = 0;
	for (int i = 0; i < n; i++)
		if ((a[i].second - i) % 2) res++;
	std::cout << res / 2 << std::endl;
	
	return 0;
}


Measured memory_bytes: 1024
import numpy as np
h, w = map(int, input().split())
table = np.array([list(input())for _ in range(h)]) == '.'

d = np.zeros((h, w), dtype = int)
u = np.zeros((h, w), dtype = int)
r = np.zeros((h, w), dtype = int)
l = np.zeros((h, w), dtype = int)

for i in range(h):
    d[i] = (d[i-1]+1) * table[i]
    u[-i-1] = (u[-i]+1) * table[-i-1]
for i in range(w):
    r[:, i] = (r[:, i-1]+1) * table[:, i]
    l[:, -i-1] = (l[:, -i]+1) * table[:, -i-1]
print(np.max(d+u+r+l)-3)


Measured memory_bytes: 219748
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define repj(begin, end) for (j=begin;j<end;j++)
#define init(arr, end, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
int i, n, m, k, ans;
int a[1000];

int main() {
    string s;
    cin >> s;
    if (s == "SSS") printf("%d\n", 0);
    else if (s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR") printf("%d\n", 1);
    else if (s == "RRS" || s == "SRR") printf("%d\n", 2);
    else if (s == "RRR" ) printf("%d\n", 3);
}

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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O2")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);
#ifdef VAMP
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cout << name << " = " << arg1 << std::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...);
}
#else
#define debug(...)
#endif

const int N = 1000005;
int fac[N];
int main()
{
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    for(int i = 1;i < N;i++){
        for(int j = i;j < N;j += i){
            fac[j]++;
        }
    }
    int n;
    cin >> n;
    LL ans = 0;
    for(int c = 1;c < n;c++){
        ans += fac[n - c];
    }
    cout << ans << "\n";
    #ifdef VAMP
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (long double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
}



Measured memory_bytes: 7536
n, m = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
c = [0] * m
d = [0] * m
for j in range(m):
    c[j], d[j] = map(int, input().split())
for i in range(n):
    e = []
    for j in range(m):
        e.append(abs(a[i] - c[j]) + abs(b[i] - d[j]))
    f = e.index(min(e))
    print(f + 1)

Measured memory_bytes: 9224
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll V, E;
        cin >> V >> E;

        vllvll dp(1<<V, vll(V, inf));
        vllvll dist(V, vll(V, inf));

        rep(i, 0, E) {
            ll s, t, d;
            cin >> s >> t >> d;
            dist[s][t] = d;
        }

        dp[0][0] = 0;

        rep(bit, 0, (1LL<<V)) {
            rep(from, 0, V) {
                if (dp[bit][from] == inf) continue;
                rep(to, 0, V) {
                    if (bit & (1LL<<to)) continue;
                    chmin(dp[bit + (1LL<<to)][to], dp[bit][from] + dist[from][to]);
                }
            }
        }

        if (dp.back()[0] < big) {
            cout << dp.back()[0] << endl;
        } else {
            cout << -1 << endl;
        }
}





Measured memory_bytes: 7576
#include <queue>
#include <vector>
#include <iostream>

using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::priority_queue;

int main() {
	int n,q;
	cin >> n >> q;
	vector< priority_queue<int> > pqv(n);
	while (q--) {
		int op,t,x;
		cin >> op >> t;
		switch (op) {
			case 0:
				cin >> x;
				pqv[t].push(x);
				break;
			case 1:
				if (!pqv[t].empty()) {
					cout << pqv[t].top() << endl;
				}
				break;
			default:
				if (!pqv[t].empty()) {
					pqv[t].pop();
				}
		}
	}
}


Measured memory_bytes: 4076
parseInt(x) = parse(Int,x)

parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    mod = 10^9 + 7
    function calc(n,mod)
        ans = 1
        for i in 1:n
            ans = (ans*i)%mod
        end
        return ans
    end
    N,M = readline() |> split |> parseMap
    n = max(N,M)
    m = min(N,M)
    if n-m>1
        print(0)
    elseif n==m
        println((2*(calc(n,mod)^2))%mod)
    else
        println(((calc(n,mod)*calc(m,mod)))%mod)
    end
end

main()


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


#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
#define  nl "\n";

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



template <class T> inline T biton(T n, T pos)
{
    return n | ((T)1 << pos);
}
template <class T> inline T bitoff(T n, T pos)
{
    return n & ~((T)1 << pos);
}
template <class T> inline T ison(T n, T pos)
{
    return (bool)(n & ((T)1 << pos));
}
template <class T> inline T gcd(T a, T b)
{
    while (b)
    {
        a = a % b;
        swap(a, b);
    }
    return a;
}
template <class T> inline T bigmod(T p, T e, T m)
{
    T ret = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            ret = (ret * p) % m;
        p = (p * p) % m;
    }
    return (T)ret;
};

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " is " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif


void solve()
{
    string s1,s2;
    cin>>s1>>s2;

    int a,b;
    cin>>a>>b;

    string u;
    cin>>u;

    if(s1==u){
        a--;
    }
    else{
        b--;
    }
    cout<<a<<" "<<b<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int t = 1;

    while (t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 256
implicit none
character(50) :: sp, t
integer :: nsp, nt
integer :: i,j,k
logical :: flg

read *,sp
read *,t

nsp = len_trim(sp)
nt = len_trim(t)

k = 0
do i = 1, nsp-nt+1
   flg = .true.
   do j = 1, nt
      if (sp(i+j-1:i+j-1) == '?') cycle
      if (sp(i+j-1:i+j-1) /= t(j:j)) then
         flg = .false.
         exit
      endif
   enddo
   if (flg) then
      k = i
   endif
enddo

if (k == 0) then
   print '(a)','UNRESTORABLE'
   stop
endif

i = 1
do while (i <= nsp)
   if (i == k) then
      write(6,'(a)',advance='no') trim(t)
      i = i + nt
      cycle
   endif
   if (sp(i:i) == '?') then
      write(6,'(a)',advance='no') 'a'
   else
      write(6,'(a)',advance='no') sp(i:i)
   endif
   i = i + 1
enddo
write(6,'(a)') ''
stop
end

Measured memory_bytes: 256
<?php
	$data = explode(" ", trim(fgets(STDIN)));
	$n = $data[0];
	$x = $data[1];
	for($i=1; $i<=$n*2-1; $i++) $c[$i] = 0;
	$c[1] = 1; $c[2] = 1;
	if($x == 2){
	    $a = array(4,2,1,3);
	    $c[3] = 1;
	    $c[4] = 1;
	} else {
	    $a = array(1, $x, $x+1, 2);
	    $c[$x] = 1;
	    $c[$x+1] = 1;
	}
	
	$m = 1;
	if($x == $n*2-1 || $x == 1){
	    echo "No";
	} elseif($n == 2){
	    echo "Yes\n";
	    echo "1\n";
	    echo "2\n";
	    echo "3\n";
	} else {
	    echo "Yes\n";
	    $i = 1;
	    while($i<=$n*2-1){
	        if($i == $n-1){
	            echo $a[0]."\n";
	            echo $a[1]."\n";
	            echo $a[2]."\n";
	            echo $a[3]."\n";
	            $i = $n+2;
	        } else {
	            while($c[$m] == 1) $m++;
    	        echo $m."\n";
    	        $c[$m] = 1;
	        }
	        $i++;
	     }
	}
?>

Measured memory_bytes: 14068
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
    int n,m;
    char befor[1000],after[1000],pu;
    while(1){
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            cin>>befor[i]>>after[i];
        }
        cin>>m;
        for(int i=0;i<m;i++){
            cin>>pu;
            for(int j=0;j<n;j++){
                if(befor[j]==pu){
                        pu=after[j];
                        break;
                }
            }
            cout<<pu;
        }
        cout<<endl;
    }
}

Measured memory_bytes: 1152
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1000


void calc(int n){
  int h[SIZE];
  int h2[SIZE];

  for(int i=0;i<n+1;i++){
    scanf("%d",h+i);
  }
  
  for(int i=0;i<n+1;i++){
    for(int j=0;j<n+1;j++){
      if(j < i){
        h2[j] = h[j];
      }else if(j > i){
        h2[j-1] = h[j];
      }
    }

    //check
    bool flag = true;
    int d = h2[1]-h2[0];

    for(int j=0;j<n-1;j++){
      if(h2[j+1]-h2[j] != d){
        flag = false;
      }
    }

    if(flag){
      printf("%d\n",h[i]);
      return;
    }
  }
  
  assert(false);  
}
  
int main(){

  int n;

  while(scanf("%d",&n)!=EOF){
    if(n==0) break;
    calc(n);
  }
  
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0, cont = 0;
    rep(i, (int)s.size()) {
        if(s[i] == 'R') cont++;
        else cont = 0;
        chmax(ans,cont);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

# random_denseがTLE, 他はAC
"""
from bisect import bisect_left, bisect_right  # 二分探索
def main():
    N, Q = i2nn()
    STX = ii2nnn(N) # 座標 X で時刻 [S, T) が工事
    D = ii2nn(Q)    # 昇順ソート済み
    E = [-1] * Q
    STX.sort(key=lambda v: v[2])
    for s, t, x in STX:
        a = bisect_left(D, s-x)
        b = bisect_left(D, t-x)
        for i in range(a, b):
            if E[i] == -1:
                E[i] = x
    for e in E:
        print(e)
"""

def main():
    N, Q = i2nn()
    STX = ii2nnn(N) # 座標 X で時刻 [S, T) が工事
    D = ii2nn(Q)    # 昇順ソート済み

    events = []
    for s, t, x in STX:
        events.append(('S', s-x-0.25, x))
        events.append(('T', t-x-0.75, x))  # 0.5 同士だと [1, 2), [0, 1) で吹き飛ぶ
    for i, d in enumerate(D):
        events.append(('D', d, i))
    
    ans = [-1] * Q
    events.sort(key=lambda v: v[1])
    xset = set()
    #xmin = None
    xmin = 1e+10
    xb = False
    for event, time, xi in events:
        if event == 'S':
            xset.add(xi)
            #if xmin is None or xmin > xi:
            if xmin > xi:
                xmin = xi
                xb = True
        elif event == 'T':
            xset.remove(xi)
            if xmin == xi:
                #xmin = None
                xb = False
        elif event == 'D' and xset:
            #if xmin is None:
            if not xb:
                xmin = min(xset)
                xb = True
            ans[xi] = xmin

    for n in ans:
        print(n)

main()


Measured memory_bytes: 144032
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
typedef pair<double, double> P;
typedef complex<double> Point;
typedef pair<Point, Point> Line;
const double EPS = 1e-10;

/*使い方
Point P(-2, 1), Q;
Q = {2, -1};
cout<< P.real() << " " << P.imag() <<endl;
Q = P + Point(5, -2);
Q += Point(cos(a), sin(a));
cout << abs(P) <<endl;	//opの長さ
cout << norm(P) <<endl;	//abs((P)^2)
*/

// 内積 |a||b|cosθ
double dot(Point a, Point b){
	// return a.real() * b.real() + a.imag() * b.imag();
	return (conj(a) * b).real();
}
// 外積、符号付面積の２倍　|a||b|sinθ
double cross(Point a, Point b){
	// return a.real() * b.imag() - a.imag() * b.real();
	return (conj(a) * b).imag();
}
// 点の位置関係　2点a,bから見た点cの位置関係
int ccw(Point a, Point b, Point c){
    // COUNTER_CLOCKWISE
    if(cross(b - a, c - a) > EPS) return 1;
    // CLOCKWISE
    if(cross(b - a, c - a) < -EPS) return -1;
    // ONLINE_BACK
    if(dot(b - a, c - a) < -EPS) return 2;
    // ONLINE_FRONT
    if(abs(b - a) + EPS < abs(c - a)) return -2;
    // ON_SEGMENT
    return 0;
}
// 線分の交差判定
bool is_cross(Line a, Line b){
    if(ccw(a.first, a.second, b.first) * ccw(a.first, a.second, b.second) <= 0 && ccw(b.first, b.second, a.first) * ccw(b.first, b.second, a.second) <= 0){
        return true;
    }
    return false;
}
// 直線の交点
Point cross_point(Line a, Line b){
    double d1 = cross(b.second - b.first, b.first - a.first);
    double d2 = cross(b.second - b.first, a.second - a.first);
    return a.first + (a.second - a.first) * d1 / d2;
}

int main(){
    int ts;
    cin >> ts;
    rep(it, 0, ts){
        double xa, ya, xb, yb;
        cin >> xa >> ya >> xb >> yb;
        Point a = {xa, ya};
        Point b = {xb, yb};
        Line h = {a, b};
        int n;
        cin >> n;
        vector<Line> ls; 
        vector<int> owner(n), l(n);
        rep(i, 0, n){
            double xs, ys, xt, yt;
            cin >> xs >> ys >> xt >> yt >> owner[i] >> l[i];
            Point s = {xs, ys};
            Point t = {xt, yt};
            ls.push_back({s, t});
        }
        vector<pair<P, int> > crossPnt;
        rep(i, 0, n){
            if(is_cross(h, ls[i])){
                Point tmp = cross_point(h, ls[i]);
                int tmpl = l[i];
                if(owner[i] == 0) tmpl = (tmpl + 1) % 2;
                crossPnt.push_back({P(tmp.real(), tmp.imag()), tmpl});
            }
        }
        int ans = 0;
        sort(crossPnt.begin(), crossPnt.end());
        rep(i, 1, crossPnt.size()){
            if(crossPnt[i - 1].second != crossPnt[i].second){
                ans++;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3136
//Code by Ritik Agarwal
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
#define int long long int
#define loop(i,a,b) for(int i=a;i<b;i++)
#define scan(arr,n) for (int i = 0; i < n; ++i) cin >> arr[i]
#define vi vector<int>
#define si set<int>
#define pii pair <int, int>
#define sii set<pii>
#define vii vector<pii>
#define mii map <int, int>
#define pb push_back
#define ff first
#define ss second
#define all(aa) aa.begin(), aa.end()
#define rall(a) a.rbegin() , a.rend()
#define read(a,b) int a,b;	cin>>a>>b
#define readt(a,b,c) int a,b,c;	cin>>a>>b>>c
#define readf(a,b,c,d) int a,b,c,d;	cin>>a>>b>>c>>d;
#define print(v) for(auto x:v) cout<<x<<" ";cout<<endl
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
//**************  Constants  ************
const int mod = 1000000007; /* 1e9 + 7*/
const int MAXN = 1000005; /*1e6 +5 */
const int mod1= 998244353;
 
int fac[300001];
void fact(int m){fac[0]=1;for(int i=1;i<=300000;i++) fac[i]=(fac[i-1]%m * i%m)%m;}
/* Iterative Function to calculate (x^y)%p in O(log y)*/
 long long power( long long x,  int y, int p){   long long res = 1;  
 x = x % p; while (y > 0) { if (y & 1)  res = (res * x) % p;  y = y >> 1; x = (x * x) % p;} return res;}
// Returns n^(-1) mod p 
 long long modInverse( long long n, int p) {  return power(n, p - 2, p); }
 long long nCr( long long n,int r, int p) { if (r == 0) return 1; if(n<r) return 0;
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } 


  const int N=1E5+5;
 vi adj[N];
int vis[N]={0};

void dfs(int u)
{
	
	vis[u]=1;
	for(auto x:adj[u])
	{
		if(vis[x]==0)
		dfs(x);
	}
}

void solve()
{
	read(n,m);
	loop(i,0,m)
	{
		read(x,y);
		adj[x].pb(y);
		adj[y].pb(x);
	}
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(vis[i]==0)
		{
			dfs(i);
			cnt++;
		}
	}
	cout<<cnt-1<<endl;
	
}



int32_t main()
{
	solve();
}


Measured memory_bytes: 11088