akhauriyash/Code-Regression huggingface dataset:
import java.util.*

fun main(args : Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val array = IntArray(n)
    for (i in 0..n-1) {
        array[i] = scanner.nextInt()
    }
    val sortedArray = array.sortedArrayDescending()

    var sum = 0
    var preMax = 0
    var preMiddle = 0
    var preMin = 0

    loop1@for (i in 0..n-3) {
        val max = sortedArray[i]
        val pmax = preMax
        preMax = max
//        if (pmax == max) continue@loop1
        val half = max / 2
        preMiddle = 0

        loop2@for (j in i+1..n-2) {
            val middle = sortedArray[j]
            val pmiddle = preMiddle
            preMiddle = middle
//            if (pmiddle == middle) continue@loop2
            if (middle <= half) break@loop2
            preMin = 0

            loop3@for (k in j+1..n-1) {
                val min = sortedArray[k]
                val pmin = preMin
                preMin = min
//                if (pmin == min) continue@loop3

                if (max < middle + min) {
                    sum += 1
                }
            }
        }
    }

    println(sum)
}

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

#define INPUT freopen("input.txt", "r", stdin);

#define ll long long
#define ld long double

#define len(s) s.size()

#define fl(st, en, in) for (int i = st; i < en; i += in)
#define rfl(st, en, de) for (int i = st; i < en; i -= de)
#define fll fl(0, n, 1)

#define cy cout << "Yes" << endl;
#define cn cout << "No" << endl;
#define ci(s) cin >> s
#define co(s) cout << s << endl

#define vl vector<ll>
#define pb(x) push_back(x)

#define ms(arr, x) memset(arr, x, sizeof(arr))

#define inf INT_MAX

void solve()
{
    ld d, t, s;
    cin >> d >> t >> s;
    ld tm = s * t;
    if (tm >= d)
    {
        cy;
    }
    else
    {
        cn;
    }
}

int main()
{
    // INPUT;
    // int t;
    // ci(t);
    // while (t--)
    solve();
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF      100000000
#define EPS      1e-10
#define MOD      1000000007
using namespace std;
typedef long long ll;

int h, w;
char a[8][8];
bool saw[8][8];

int main(){
    cin >> h >> w;
    rep(i,h){
        rep(j,w){
            cin >> a[i][j];
        }
    }
    int x = 0, y = 0;
    saw[y][x] = true;
    while(true){
        if(y == h-1 && x == w-1) break;
        if(y != h-1 && a[y+1][x] == '#'){
            y++;
            saw[y][x] = true;
            continue;
        }
        if(x != w-1 && a[y][x+1] == '#'){
            x++;
            saw[y][x] = true;
            continue;
        }
        cout << "Impossible" << endl;
        return 0;
    }
    rep(i,h) rep(j,w){
        if(a[i][j] == '#' && saw[i][j] == false){
            cout << "Impossible" << endl;
            return 0;
        }
    }
    cout << "Possible" << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;


public class Main {
//	入力値
	static Scanner scInputData = new Scanner(System.in);
//	配列
	static ArrayList<Integer> arrA = new ArrayList<Integer>();
	static ArrayList<Integer> arrB = new ArrayList<Integer>();
	
	public static void main(String[] args) {
		
//		必要なパラメータを用意する処理
//		配列Aを取得する処理
		getArr(arrA);
//		配列Bを取得する処理
		getArr(arrB);
//		配列の要素を辞書式順に比較する処理
		compareArr(arrA, arrB);

	}
	
	private static void compareArr(ArrayList<Integer> arrX,
			ArrayList<Integer> arrY) {
//		比較試行回数
		int indexToCompare = (arrX.size() <= arrY.size()) ? arrX.size() : arrY.size();
//		比較判定変数
		boolean compareCheck = false;
//		どちらかが要素取得できない場合、処理を終了
		for( int index=0; index < indexToCompare; index++) {
			compareCheck = compareVal(arrX.get(index), arrY.get(index));
//			引き分け以外は処理を終了
			if(compareCheck) {
				break;
			}
		}
//		最後まで引き分けの場合、配列が長いほうの勝利
		if(compareCheck == false) {
			if(arrX.size() < arrY.size()) {
				winB();
			}else {
				winA();
			}
		}
	}


	private static boolean compareVal(int valX, int valY) {
		if( valX == valY) {
			return false;
		}else if(valX < valY) {
			winB();
			return true;
		}else {
			winA();
			return true;
		}
	}


	private static void winA() {
		System.out.println(0);
	}
	
	private static void winB() {
		System.out.println(1);
	}


	private static void getArr(ArrayList<Integer> arr) {
//		 配列の要素数
		int iArrNum = 0;
		iArrNum = scInputData.nextInt();
		while(arr.size() < iArrNum) {
			arr.add(scInputData.nextInt());
		}
	}

}



Measured memory_bytes: 33436
#include<bits/stdc++.h>
using namespace std;
int n,a,b,c;
int main()
{
    cin>>n;
    a=n/100;
    b=n%100/10;
    c=n%10;
    if(a==7 || b==7 || c==7) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define all(cont) cont.begin(), cont.end()
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef set<int> si;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef pair<int, pair<int, int>> pipii;
 
const int INF = 1e9+1;
const int MAX_N = 3000;
const int mod = 1000000007;	

double dp [MAX_N][MAX_N];

void solve(){
	int N;
	cin >> N;
	
	vector<double> p(N+1, 0);
	for(int i = 1; i <= N; ++i){
		cin >> p[i];
	}
	
	dp[0][0] = 1;
	for(int i = 1 ; i <= N; ++i){
		for(int j = 0; j <= N; ++j){
			if(j == 0){
				dp[i][j] = dp[i-1][j]*(1-p[i]);
			} else {
				dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
			}
	
		}
	}
	double sum = 0;
	for(int i = N/2+1; i <= N; ++i){
		sum += dp[N][i];
	}
	
	cout << sum << "\n";
}
 
int main(){
	//freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cout << fixed << setprecision(10);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
 
	int i = 1, t = 1;
	//cin >> t;
	while(i <= t){
		//cout << "CASE #" << i << ": ";
		solve();
		i++;
	}	
	return 0;
}

Measured memory_bytes: 74088
function Main(input) {
  input=input.split("\n");
  const H=input[0].split(' ')[0]-0;
  const W=input[0].split(' ')[1]-0;
  var min=Infinity;
  if(H%3===0||W%3===0){
    console.log(0);
    return;
  }
  min=Math.min(H,W);
  if(H%2===0){
    min=Math.min(min,H/2);
  }else{
    min=Math.min(min,H/2+W/3-1/6);
  }
  if(W%2===0){
    min=Math.min(min,W/2);
  }else{
    min=Math.min(min,W/2+H/3-1/6);
  }
  console.log(Math.round(min));
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  
  


Measured memory_bytes: 30552
#include<stdio.h>
#define X 86400
int main(){
  int x,h,m,s;
  scanf("%d",&x);
  h=x/3600;
  m=(x%3600)/60;
  s=(x%3600)%60;
  printf("%d:%d:%d\n",h,m,s);
  return 0;
}

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

typedef long long ll;
typedef long double ld;

int main()
{

  int N,M;
  cin >> N >> M;
  int a[N];
  int ord=0;
  float total;

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

  rep(i,N)total+=a[i];

  sort(a, a + N,greater<>());

  rep(i,N){
    if(a[i] >= total/(4*M)){
      ord++;
    }
    if(ord == M){
      cout << "Yes" << endl;
      break;
    }else if(i == N-1){
      cout << "No" <<endl;
    }

  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector> // vectorを使うためにインクルードする
using namespace std;

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

	vector<int> vc;
	int i = 1;
	vc.push_back(n);
	while (true) {
		int u;
		if (vc[i - 1] % 2 == 1) {
			u=3 * vc[i-1] + 1;
		}
		else if (vc[i - 1] % 2 == 0) {
			u=vc[i-1] / 2;
		}
		for (int j = 0; j < i; j++) {
			if (u == vc[j]) {
				printf("%d", i+1);
				goto OUT;
			}
		}
		vc.push_back(u);
		i++;
	}
OUT:
	return 0;
}

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

int main() {
	int x,y,s;
	while (1) {
		cin >> x >> y;
		if (x == 0&& y== 0)break;
		if (x < y) {
			cout << x  <<" "<<   y << endl;
		}
		else {
			s = x;
			x = y;
			y = s;
			cout << x  <<" "<<   y << endl;
		}
	}
	return 0;
}


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

using namespace std;


void solve() {
    int n, d;
    cin >> n >> d;
    d = 2*d+1;
    cout << (n+d-1)/d;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

string s;

int main(void){
    cin >> s;
    if(s == "RRR") cout << 3 << endl;
    else if(s == "RRS" || s == "SRR") cout << 2 << endl;
    else if(s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR") cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

const int INF = 1001001001;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> g(H, vector<char>(W));
  rep(y, 0, H) rep(x, 0, W) cin >> g[y][x];

  rep(y, 0, H) {
    rep(i, 0, 2) {
      rep(x, 0, W) cout << g[y][x];
      cout << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3628
import Data.Array.IO
import Data.Array
import Text.Regex

data IOqueue a = IOq (IOArray Int a,Int,Int,Int)
--??´??°?????????????????????????????¬???????????????????????????????????????????????????????????????????????????

newqueue::Int -> a -> IO (IOqueue a)
newqueue n initial = do
        ar<-newArray (0,n-1) initial
        return (IOq (ar,0,0,n))

enqueue::IOqueue a -> a -> IO (IOqueue a)
enqueue (IOq (ar,hd,tl,sz)) x = do
        writeArray ar tl x
        return (IOq (ar,hd,(mod (tl+1) sz),sz))

dequeue::IOqueue a -> IO (a,IOqueue a)
dequeue (IOq (ar,hd,tl,sz)) = do
        dat <- readArray ar hd
        return (dat,IOq (ar,mod (hd+1) sz,tl,sz))

isfull::IOqueue a -> Bool
isfull (IOq (_,hd,tl,sz)) = (mod (tl+1) sz == hd)

isempty::IOqueue a -> Bool
isempty (IOq (_,hd,tl,_)) = (hd == tl)

--??\???IOArray??????????´???´???????£?

--utilities_with_list
list_enqueue::IOqueue a -> [a] -> IO (IOqueue a)
list_enqueue q []     = return q
list_enqueue q (x:xs) = (enqueue q x)>>=(\ q -> (list_enqueue q xs))

n_dequeue::IOqueue a -> Int -> IO ([a],IOqueue a)
n_dequeue q 0 = return ([],q)
n_dequeue q n = do
          (x,q)<-dequeue q
          (xs,q')<- n_dequeue q (n-1)
          return ((x:xs), q')


--for alds1_3_b_problem



main::IO()
main =do
  nqc<-getLine
  let n:quant:[]=map read (words nqc)::[Int]
  q'<-newqueue (n+1) ([],0)
  dat_ls<-get_proc n
  q''<-list_enqueue q' dat_ls
  do_proc q'' quant 0


get_proc::Int-> IO [(String,Int)]
get_proc 0 = return []
get_proc n = do
  name_time<-getLine
  let name:timec:[]= (words name_time)
  let time = read timec ::Int
  ls<-get_proc (n-1)
  return ((name,time):ls)

do_proc::IOqueue (String,Int) -> Int -> Int -> IO()
do_proc queue quant now = if isempty queue then return ()
                                           else do
                                              ((name,time),queue')<-dequeue queue
                                              if time>quant then do
                                                              queue''<-enqueue queue' (name,time-quant)
                                                              do_proc queue'' quant (now+quant)
                                                            else do
                                                              putStr (name++" "++(show (now+time)))
                                                              putStr "\n"
                                                              do_proc queue' quant (now+time)

Measured memory_bytes: 48036
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath> 
#include <queue>
#include <functional>

using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
//static const int dx[4] = {1, -1, 0, 0};
//static const int dy[4] = {0, 0, 1, -1};

vector<ll> A;
vector<ll> sum;

int main() {

    int N; cin >> N;
    int a;
    for (int i = 0; i < N; i++) {
        cin >> a;
        A.push_back(a);
    }

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


    sum.push_back(A[0]);

    for (int i = 1; i < N; i++) 
        sum.push_back(sum[i-1] + A[i]);

    int ans = 1;
    for (int i = N-2; i >= 0; i--) {
        if (A[i+1] <= 2 * sum[i])
            ans++;
        else break;
    }

    cout << ans << '\n';



}


Measured memory_bytes: 2548
use std::io::prelude::*;
fn main() {
    let field = read_field();
    for y in 0..field.h {
        for x in 0..field.w {
            print!("{}", field.show_at(x, y));
        }
        print!("\n");
    }
}

fn read_field() -> Field {
    let stdin = std::io::stdin();
    let mut input = stdin.lock();
    let mut l = String::new();
    let _ = input.read_line(&mut l);
    let hw: Vec<u32> = l
        .split_whitespace()
        .map(|n| n.parse().expect("readnumerror!"))
        .collect();
    let h = hw[0];
    let w = hw[1];
    let mut f: Vec<Cell> = Vec::with_capacity((h * w) as usize);
    for line in input.lines() {
        for c in line.expect("read line error").trim().chars() {
            match c {
                '.' => f.push(false),
                '#' => f.push(true),
                _ => panic!(format!("unexpected char {}", c)),
            }
        }
    }
    Field {
        h: h,
        w: w,
        field: f,
    }
}

struct Field {
    h: u32,
    w: u32,
    field: Vec<Cell>,
}

impl Field {
    fn at(&self, x: i32, y: i32) -> Option<Cell> {
        if 0 <= x && x < self.w as i32 && 0 <= y && y < self.h as i32 {
            self.field
                .get(x as usize + y as usize * (self.w as usize))
                .map(|&c| c)
        } else {
            None
        }
    }
    fn count_neighbour_incl_self(&self, x: u32, y: u32) -> u8 {
        let mut n: u8 = 0;
        for dx in &[-1, 0, 1] {
            for dy in &[-1, 0, 1] {
                n += self.at(x as i32 + dx, y as i32 + dy).unwrap_or(false) as u8;
            }
        }
        n
    }

    fn show_at(&self, x: u32, y: u32) -> String {
        if self.at(x as i32, y as i32).unwrap_or(false) {
            "#".to_string()
        } else {
            format!("{}", self.count_neighbour_incl_self(x, y))
        }
    }
}

type Cell = bool;


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

int main() {
  int N,K,S;
  cin>>N>>K>>S;
  if(S==1000000000){
    rep(i,K){
      cout<<1000000000<<" ";
    }
    rep(i,N-K){
      cout<<1000000000-1<<" ";
    }
    return 0;
  }
  rep(i,K){
    cout<<S<<" ";
  }
  rep(i,N-K){
    cout<<1000000000<<" ";
  }
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

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


Measured memory_bytes: 256
import math
n=int(input())
if n ==2:
  print(n)
  exit()

w=math.ceil(math.sqrt(n))
for k in range(n,1000000):
  f=False
  for i in range(2,w+1):
    if k%i==0:
      f=True
      break
  if not f:
    print(k)
    exit()


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
ll wight[101];
ll val[101];
ll dp[102][100010];
const ll INF = (1LL << 60);

int main(){
  int n,w;
  cin >> n >> w;
  rep(i,n){
    cin >> wight[i] >> val[i];
  }
  for (int i=0;i < 100001;i++) dp[0][i]=INF;
  dp[0][0]=0LL;
  for (int i=0;i < n;i++){
    for (int j=0;j < 100001;j++){
      if (j < val[i]) dp[i+1][j]=dp[i][j];
      else dp[i+1][j]=min(dp[i][j],dp[i][j-val[i]]+wight[i]);
    }
  }
  ll ans=0;
  for (int i=0;i <100001;i++){
      if (dp[n][i]<=w) ans=max(ans,(long long)i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 79232
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;

const double PI=3.14159265358979323846;

int main() {
  double R;
  cin >> R;
  cout << 2.0 * R * PI << endl;

  return 0;
}


Measured memory_bytes: 3812
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
int n;
int a[55], b[55];
bool dp[55];
bool toUse[55];
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  auto doDP = [&] (int bound, int idx) {
    fill(dp, dp + 55, false);
    dp[a[idx]] = true;
    for (int i = 50; i >= 1; i--) {
      if (bound >= i || toUse[i]) {
        for (int j = 50; j >= 0; j--) if (dp[j]) {
          dp[j % i] = true;
        }
      }
    }
    return dp[b[idx]];
  };
  auto mustUse = [&] (int num) {
    for (int i = 0; i < n; i++) if (!doDP(num - 1, i)) {
      return true;
    }
    return false;
  };
  for (int i = 50; i >= 1; i--) if (mustUse(i)) {
    toUse[i] = true;
  }
  long long ans = 0;
  for (int i = 1; i <= 50; i++) if (toUse[i]) ans |= 1LL << i;
  cout << (ans == 2251799813685246 ? -1 : ans) << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"container/heap"
	"fmt"
	"bufio"
	"os"
	"strconv"
)

type IntHeap []int

func (h IntHeap) Len() int {
	return len(h)
}

func (h IntHeap) Less(i, j int) bool {
	return h[i] > h[j]
}

func (h IntHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0:n-1]
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	h := &IntHeap{}
	heap.Init(h)

	LOOP:
	for {
		scanner.Scan()
		switch scanner.Text() {
		case "end":
			break LOOP
		case "insert":
			scanner.Scan()
			element, _ := strconv.Atoi(scanner.Text())
			heap.Push(h, element)
		case "extract":
			fmt.Printf("%d\n", heap.Pop(h))
		default:
			panic("No such operation.")
		}
	}
}



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

int main(){
 int n;
  cin >> n;
  vector <int> d(n);
  rep(i, n) cin >> d[i];
  int ans = 0;
  rep(i, n)
  {
    rep(j, n)
    { 
      if(i == j) continue;
      else
	    ans += d[i] * d[j];
  	}
  }
  cout << ans / 2 << endl;
}
	

Measured memory_bytes: 256
n,m = map(int,input().split())
a=[]
b=[]
res = 'No'
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())

for i in range(0,n-m+1):
    for j in range(0,n-m+1):
        if a[i][j:j+m] == b[0]:
            flag = 1
            for k in range(1,m):
                if a[i+k][j:j+m] != b[k]:
                    break
                flag += 1
            if flag == m:
                res = 'Yes'
        if res == 'Yes':
            break
    if res == 'Yes':
        break


print(res)


Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, m; cin >> n >> m;
	vector<vector<int>> g(n);
	rep(i, 1, m)
	{
		int u, v; cin >> u >> v;
		--u, --v;
		g[u].push_back(v);
	}
	vector<vector<ll>> dp(n, vector<ll>(3, -1));
	queue<pair<int, int>> q;
	int s, t; cin >> s >> t;
	--s, --t;
	dp[s][0] = 0;
	q.push({ s,0 });
	while (!q.empty())
	{
		int now = q.front().first;
		int x = q.front().second;
		q.pop();
		int lim = g[now].size() - 1;
		rep(i, 0, lim)
		{
			int next = g[now][i];
			if (dp[next][(x + 1) % 3] == -1 || dp[next][(x + 1) % 3] > dp[now][x] + 1)
			{
				dp[next][(x + 1) % 3] = dp[now][x] + 1;
				q.push({ next,(x + 1) % 3 });
			}
		}
	}
	cout << min(dp[t][0], dp[t][0] / 3) << endl;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;

const int N=2e5+5;
int pos;
struct segment
{
    int ST[4*N],lazy[4*N];
    void dolazy(int id,int l,int r)
    {
        if (lazy[id]==0)
            return;
        ST[id]=lazy[id];
        if (l!=r)
        {
            lazy[id*2]=lazy[id];
            lazy[id*2+1]=lazy[id];
        }
        lazy[id]=0;
    }

    void update(int id,int l,int r,int L,int R,int val)
    {
        dolazy(id,l,r);
        if (r<L||R<l)
            return;
        if(L<=l&&r<=R)
        {
            ST[id]=val;
            if (l!=r)
            {
                lazy[id*2]=val;
                lazy[id*2+1]=val;
            }
            return;
        }
        int mid=(l+r)/2;
        update(id*2,l,mid,L,R,val);
        update(id*2+1,mid+1,r,L,R,val);
        ST[id]=max(ST[id*2],ST[id*2+1]);
    }

    int get (int id,int l,int r,int L,int R)
    {
        dolazy(id,l,r);
        if (r<L||R<l)
            return -1e9;
        if (L<=l&&r<=R)
            return ST[id];
        int mid=(l+r)/2;
        return max (get (id*2,l,mid,L,R),get (id*2+1,mid+1,r,L,R));
    }
    void fin(int id,int l,int r,int u,int v,int val)
    {
        dolazy(id,l,r);
        if(u>r||v<l||ST[id]<=val||pos!=-1) return ;
        int mid=(l+r)/2;
        if(u<=l&&r<=v)
        {
            if(l==r)
            {
                pos=l;
                return ;
            }
        }
        fin(id*2,l,mid,u,v,val);
        fin(id*2+1,mid+1,r,u,v,val);
    }

} T[2];


main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,q;
    cin>>n>>q;
    int black=(n-2)*(n-2);
    T[0].update(1,1,n,1,n,n);
    T[1].update(1,1,n,1,n,n);
    while(q--)
    {
        int op,x;
        cin>>op>>x;
        op--;
        int drop=T[op].get(1,1,n,x,x);
        black-=drop-2;
        pos=-1;
        T[op^1].fin(1,1,n,1,drop,x);
        if(pos!=-1) T[op^1].update(1,1,n,pos,drop,x);
    }
    cout<<black;
}


Measured memory_bytes: 20032
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n;
	cin >> n;
	map<int,int> mp;
	for(int i = 0;i < n;i++){
		int a;
		cin >> a;
		mp[a]++;
	}

	int ans = 0;

	for(auto p:mp){
		if(p.second > p.first){
			ans += (p.second - p.first);
		}
		else if(p.second < p.first){
			ans += p.second;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 7876
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); }



void solve()
{
    string s;
    cin >> s;
    ll n = s.size();
    ll ans = inf;
    rep(i, 26)
    {
        char x = (char) (i+'a');
        ll l = 0, tmp = 0;
        rep(j, n)
        {
            if(s[j] == x)l = 0;
            else{
                l++; tmp = max(tmp, l);
            }
        }
        ans = min(ans, tmp);
    }
    cout << ans;
}

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  string s,t;
  cin>>s>>t;
  int num=stoi(s+t);
  for(int i=1;i<=1000;i++){
    if(i*i==num){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int N, M, ans = 0;
	scanf("%d %d", &N, &M);
	int H[N], h[N], A, B;
	fill_n(h, N, 0);
	for (int i = 0; i < N; ++i) scanf("%d", &H[i]);
	for (int i = 0; i < M; ++i) {
		scanf("%d %d", &A, &B);
		h[A - 1] = max(h[A - 1], H[B - 1]);
		h[B - 1] = max(h[B - 1], H[A - 1]);
	}
	for (int i = 0; i < N; ++i) {
		if (H[i] > h[i]) ++ans;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 2512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  long N;
  cin >> N;
  vector<int> A(N);
  for (int i = 1; i < N; i++)
  {
    int a;
    cin >> a;
    A[a-1] += 1;
  }
  rep(i,N)
  {
    cout << A[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3992
import sys
input = sys.stdin.readline

N = int(input().rstrip('\n'))
a = 0
check = 0
for _ in range(N):
  D1,D2 = (int(x) for x in input().rstrip('\n').split())
  if D1 == D2:
    a += 1
  else:
    a = 0
  if a ==3:
    check += 1
    break
if check > 0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;


// verified by: https://atcoder.jp/contests/abc141/tasks/abc141_e


struct RollingHash {
  using ui64 = uint64_t;
  // using ui128 = __uint128_t;
  static const ui64 mod = (1ull<<61) - 1;
  vector<ui64> hash, power;
  ui64 base;

  const ui64 MASK30 = (1UL << 30) - 1;
  const ui64 MASK31 = (1UL << 31) - 1;
  const ui64 MOD = (1UL << 61) - 1;
  const ui64 MASK61 = MOD;

  //a*b mod 2^61-1を返す関数(最後にModを取る)
  ui64 mul(ui64 a, ui64 b)
  {
      ui64 au = a >> 31;
      ui64 ad = a & MASK31;
      ui64 bu = b >> 31;
      ui64 bd = b & MASK31;
      ui64 mid = ad * bu + au * bd;
      ui64 midu = mid >> 30;
      ui64 midd = mid & MASK30;
      return CalcMod(au * bu * 2 + midu + (midd << 31) + ad * bd);
  }

  //mod 2^61-1を計算する関数
  ui64 CalcMod(ui64 x)
  {
      ui64 xu = x >> 61;
      ui64 xd = x & MASK61;
      ui64 res = xu + xd;
      if (res >= MOD) res -= MOD;
      return res;
  }

  static inline ui64 add(ui64 a, ui64 b) { if ((a += b) >= mod) a -= mod; return a; }
  // static inline ui64 mul(ui64 a, ui64 b) { ui128 c = ui128(a)*b; return add(c>>61, c&mod); }
  static inline ui64 generate_base() {
    mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<ui64> rand(2, mod-2);
    return rand(mt);
  }

  template<typename T>
  RollingHash(const T &s, ui64 b=0) : base(b) {
    if (base == 0) base = generate_base();
    int n = s.size();
    hash.assign(n+1, 0);
    power.assign(n+1, 1);
    rep(i, n) {
      power[i+1] = mul(power[i], base);
      hash[i+1] = add(mul(hash[i], base), s[i]);
    }
  }

  ui64 get(int l, int r) { return add(hash[r], mod - mul(hash[l], power[r-l])); }

// longest common prefix of s[l1:r1] and s[l2:r2]
  int lcp(int l1, int r1, int l2, int r2) {
    int len = min(r1-l1, r2-l2);
    int ok = 0, ng = len+1;
    while (ng-ok > 1) {
      int md = (ok+ng)>>1;
      if (get(l1, l1+md) == get(l2, l2+md)) ok = md;
      else ng = md;
    }
    return ok;
  }
  
// longest common prefix of s[l1:r1] and t[l2:r2]
  int lcp(RollingHash &rh, int l1, int r1, int l2, int r2) {
    int len = min(r1-l1, r2-l2);
    int ok = 0, ng = len+1;
    while (ng-ok > 1) {
      int md = (ok+ng)>>1;
      if (get(l1, l1+md) == rh.get(l2, l2+md)) ok = md;
      else ng = md;
    }
    return ok;
  }
};


int main() {
    int n; cin >> n;
    string s; cin >> s;
    RollingHash rh(s);

    int ans = 0;
    rep(i, n) rep2(j, i+1, n) {
      int lcp = rh.lcp(i, j, j, n);
      ans = max(ans, lcp);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3692
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
int main(void){
    // Your code here!
    long long int n,k;
    std::cin >> n >>k;
    pair<long long int,long long int> p[100000];
    for (int i = 0; i < n; i++) {
        std::cin >> p[i].first >>p[i].second;
    }
    sort(p,p+n);
    long long int x=0;
    for (int i = 0; i < n; i++) {
        if(x+p[i].second>=k){
           std::cout << p[i].first << std::endl;
           return 0;
        }
        x+=p[i].second;
    }
}


Measured memory_bytes: 1792
H,W = map(int,input().split())
col = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(H):
    s = list(map(str,input().split()))
    if "snuke" in s:
        j = s.index("snuke")
        ans = col[j] + str(i+1)
print(ans)

Measured memory_bytes: 2940
use proconio::input;
use proconio::fastout;
use std::collections::HashMap;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n],
        q: usize,
        bc: [(usize, usize); q],
    }

    let mut sum_list: HashMap<usize, usize> = HashMap::new();
    let mut sum_all = 0;
    for v in a {
        *sum_list.entry(v).or_insert(0) += v;
        sum_all += v;
    }

    for (b, c) in bc {
        if let Some(&sum_now) = sum_list.get(&b) {
            sum_list.remove(&b);
            let sum_new = sum_now / b * c;
            *sum_list.entry(c).or_insert(0) += sum_new;
            sum_all += sum_new - sum_now;
        }
        println!("{}", sum_all);
    }

}


Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
    int x;
    scanf("%d",&x);
    int ans=0;
    for(int b=1;b<=1000;++b){
        for(int p=2;p<=10;++p){//2^10>1000
            int temp=pow(b,p);
            if(temp<=x)
                ans=max(ans,temp);
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 384
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
         53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109]

d = {}
for i in range(26):
    d[chr(ord('a')+i)] = prime[i]

N = int(input())
L = []
nums = [input()[:-1] for _ in range(N)]
for n in nums:
    tmp = 1
    for c in n:
        tmp *= d[c]
    L.append(tmp)

L = Counter(L)

ans = 0
for k, v in L.items():
    ans += (v*(v-1))//2
print(ans)


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

int main(void){
    
    int N,M;
    cin >> N >> M;
    long long H[N+1];
    for(int i = 1; i <= N; i++)cin >> H[i];
    
    int A;
    int B;
    
    
    map<int,vector<int>> mp;
    
    for(int i = 0; i < M;i++){
        cin >> A >> B;
        mp[A].push_back(B);
        mp[B].push_back(A);
    }

    bool flag;
    int cont = 0;
    for(int i = 1; i <= N;i++){
        sort(mp[i].begin(),mp[i].end());
        mp[i].erase(unique(mp[i].begin(), mp[i].end()), mp[i].end());

        flag = true;
        for(auto u:mp[i]){
            //cout << u << " ";
            if(H[i] <= H[u])flag = false;
        }
        //cout << endl;
       
        
        if(flag){
            //cout << "break:" << i << endl; 
            cont++;
        }
        
         //cout << "-------------"<<endl;
    }
    
    cout << cont << endl;
    
    
    
}


Measured memory_bytes: 14940
# coding:utf-8

import sys
import math
import time
import numpy as np
import collections
from collections import deque
import queue
import copy

# 最大公約数
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" #探索した場所は探索できないようにする
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      #print(q)
  return mlength


#X = str(input()).split()
HW = str(input()).split()
H = int(HW[0])
W = int(HW[1])
S = [[0 for i in range(W)] for j in range(H)]
# SS = [[INF]*(W*H)]*(W*H)
mlength = 0


for i in range(H):
  temp = str(input())
  for j in range(W):
    S[i][j]=temp[j]


for i in range(H):
  for j in range(W):
    if(S[i][j] != "#"):
      TS = copy.deepcopy(S)
      mlength = max(mlength, bfs(TS, i, j, H, W))

print(mlength);


Measured memory_bytes: 12524
#include "bits/stdc++.h"
using namespace std;
#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 ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a,b;
    cin >> a >> b; 
    if((a+b)%3==0)
    cout << "Possible" << endl;
    else if(a%3==0)
    cout << "Possible" << endl;
    else if(b%3==0)
    cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int N;
	cin >> N;
	
	long answer = 0;
	
	for (int i = 0; i < N; i++)
	{
		long a;
		cin >> a;
		answer += a;
	}
	
	cout << answer - N << endl;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
numList = list(map(int, input().split()))
sortedList = sorted(numList)
center = N // 2
left_median = sortedList[center - 1]
right_median = sortedList[center]

answer = [str(left_median) if i >= right_median else str(right_median) for i in numList]
print("\n".join(answer))

Measured memory_bytes: 32576
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll x; cin >> x;
  for(ll a = -1000; a < 1000; a++){
    // ll b;
    // for(ll c = 1; c <= sqrt(x); c++){
    //   if(x % c == 0){
    //     b = a - c;
    //     if(a*a*a*a*a - b*b*b*b*b == x){
    //       cout << a << ' ' << b << endl;
    //       return 0;
    //     }
    //     b = a - x/c;
    //     if(a*a*a*a*a - b*b*b*b*b == x){
    //       cout << a << ' ' << b << endl;
    //       return 0;
    //     }
    //   }
    // }
    for(ll b = -1000; b < a; b++){
      if(a*a*a*a*a - b*b*b*b*b == x){
        cout << a << ' ' << b << endl;
        return 0;
      }
    }
  }

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


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

using namespace std;

#define ll long long

void solve() {
    string s;
    cin >> s;
    int n = (int) s.size();
    for (int i = 0; i < n; ++i) {
        if (i & 1) {
            if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
                cout << "No";
                return;
            }
        } else {
            if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
                cout << "No";
                return;
            }
        }
    }
    cout << "Yes";
}

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

    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}


Measured memory_bytes: 3664
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define MOD (1000000007ll)

int main(void){
	int i,n;
	ll a[123456],b[123456],c[123456],*p,cnt[123456],ans=0ll;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> a[i];
	}
	sort(a,a+n);
	for(i=0; i<n; i++){
		cin >> b[i];
	}
	sort(b,b+n);
	for(i=0; i<n; i++){
		cin >> c[i];
	}
	sort(c,c+n);
	for(i=0; i<n; i++){
		p = upper_bound(c,c+n,b[i]);
		cnt[i] = n-(int)(p-c);
	}
	for(i=(n-1); i>0; i--){
		cnt[i-1] += cnt[i];
	}
	for(i=0; i<n; i++){
		p = upper_bound(b,b+n,a[i]);
		ans += cnt[(int)(p-b)];
	}
	cout << ans << endl;
	return 0;
}


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

ll sol(int x){
	return 1LL*x*x*x;
}

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

	if(k&1) cout<<sol(n/k);
	else{
		k/=2;
	 cout<<sol(n/k/2)+sol((n+k)/k/2);
    }
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b)
{
    return b ? gcd(b, a % b) : a;
}
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

void func(std::string S)
{
    int acount = 0;
    int bcount = 0;
    rep(i, S.size())
    {
        if (S[i] == 'A')
        {
            acount++;
        }
        else if (S[i] == 'B')
        {
            bcount++;
        }
    }
    if (acount > 0 && bcount > 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

int main()
{
    // cout << fixed << setprecision(5);

    std::string S;
    std::cin >> S;
    func(S);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mod 1000000007LL
#define eps 0.0001

#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    
    int n;
    cin >> n ;

    int t[n];
    int i,j;
    rep(i,n){
        cin >> t[i] ;
    }

    int m;
    cin >> m;

    int p[m];
    int x[m];
    rep(i,m){
        cin >> p[i] >> x[i];
    }

    rep(i,m){
        int ans[n];
        memcpy(ans, t, sizeof(t));

        ans[p[i]-1]=x[i];
        int ans2=0;
        rep(j,n){
            ans2 += ans[j];
        }
        pri(ans2);
    }


    return 0;
}



Measured memory_bytes: 256
def cmb(n, r):
    if r > n: return 0
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

N = int(input())
A = list(map(int,input().split()))
import collections

c = collections.Counter(A)
keys = c.keys()
ans_dict = {}
ans_dict2 = {}
for key in keys:
    ans_dict[key] = cmb(c[key]-1,2)
    ans_dict2[key] = cmb(c[key],2)

SUM  = sum(ans_dict2.values())

# print(ans_dict)
# print(ans_dict2)

for key in A:
    print(SUM-ans_dict2[key]+ans_dict[key])

Measured memory_bytes: 39508
import math

a, b, C = map(int, input().split())
h = b * math.sin(math.radians(C))
S = a * h / 2
c = math.sqrt(h**2 + (a-b*math.cos(math.radians(C)))**2)
L = a + b + c

print(S)
print(L)
print(h)

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

// a<b<cを満たすときにYes

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a < b && b < c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
    int n,x=0,y=0,a=0,b=0;
    int p=0;
    cin>>x>>y>>a>>b;
    p=x*a+y*b;
    if(a>4 && b>1)p=p*4/5;
    for(int i=a;i<7;i++){
        for(int j=b;j<7;j++){
            int pp=0;
            pp=x*i+y*j;
            if(i>4 && j>1)pp=pp*4/5;
            if(p>pp)p=pp;
        }
    }
    cout<<p<<endl;
    }
        return 0;
    }

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

int h,w,c ;
int table[10][10] = {} ;
int dxy[] = {0,-1,0,1,0} ;

int MAX( int a , int b ){ return ( (a>b) ? a : b ) ; }

int cnt_search( int P[][10] , int nx , int ny , int color ){
	int ans = 1 ;
	P[ny][nx] = 0 ;
	for( int i=0 ; i<4 ; i++ ){
		if( color == P[ny+dxy[i]][nx+dxy[i+1]] ){
			ans += cnt_search( P , nx+dxy[i+1] , ny+dxy[i] , color ) ;
		}
	}
	return ans ;
}

int search( int P[][10] ){
	int ans = 0 , z ;
	for( int i=1 ; i<=h ; i++ ){
		for( int j=1 ; j<=w ; j++ ){
			if( P[i][j] = c ){
				ans = MAX( ans , cnt_search( P , j , i , c ) ) ;
			}
		}
	}
	return ans ;
}

void copy( int x[][10] , int p[][10] ){
	for( int i=0 ; i<=h+1 ; i++ )
		for( int j=0 ; j<=w+1 ; j++ )
			x[i][j] = p[i][j] ;
}

void change( int P[][10] , int nx , int ny , int P_color , int C_color ){
	P[ny][nx] = C_color ;
	for( int i=0 ; i<4 ; i++ ){
		if( P_color == P[ny+dxy[i]][nx+dxy[i+1]] ){
			change( P , nx+dxy[i+1] , ny+dxy[i] , P_color , C_color ) ;
		}
	}
}

int func( int P[][10] , int cnt ){
	int tmp[10][10] , ans = 0 ;
	copy( tmp , P ) ;
	/*
	char d ;
	for( int i=0 ; i<=h+1 ; i++ ){
		for( int j=0 ; j<=w+1 ; j++ ){
			cout << " " << P[i][j] ;
		}
		cout << endl ;
	}cin >> d ;*/
	
	if( cnt == 5 ) ans = search( P ) ;
	else {
		for( int i=1 ; i<=6 ; i++ ){
			if( P[1][1] != i ){
				change( P , 1 , 1 , P[1][1] , i ) ;
				ans = MAX( ans , func( P , cnt+1 ) ) ;
				copy( P , tmp ) ;
			}
		}
	}
	return ans ;
}

main(){
	
	while( cin >> h >> w >> c , h ){
		for( int i=0 ; i<=h+1 ; i++ ){
			for( int j=0 ; j<=w+1 ; j++ ){
				if( !i || !j || i==h+1 || j==w+1 ) table[i][j] = 0 ;
				else cin >> table[i][j] ;
			}
		}
		cout << func( table , 0 ) << endl ;
	}
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int x[n],y[n];
for (int i=1;i<n+1;i++){
cin>>x[i];
y[x[i]]=i;
}
for (int i=1;i<n+1;i++){
cout<<y[i]<<" ";
}
return 0;
}


Measured memory_bytes: 4308
#include <stdio.h>
#define NUMBER 5

int main() {
	int input[NUMBER];
	int temp;
	int last_ch = NUMBER - 1;
	int temp_ch;

	int i;

	for(i = 0; i < NUMBER; i++)
		scanf("%d", &input[i]);

	/* 左の方が小さかった場合には入れ替える。 */
	while(last_ch) {
		temp_ch = 0;
		for(i = 0; i < last_ch; i++) {
			if(input[i] < input[i + 1]) {
				temp = input[i];
				input[i] = input[i + 1];
				input[i + 1] = temp;
				temp_ch = i + 1;
			}
		}
		last_ch = temp_ch;
	}
	
	for(i = 0; i < NUMBER - 1; i++) 
		printf("%d ", input[i]);

	printf("%d\n", input[NUMBER - 1]);

	return 0;
}

Measured memory_bytes: 1024
N = int(input())
ls = list(map(int, input().split(' ')))
d = {}
for l in ls:
    if l in d:
        d[l] += 1
    else:
        d[l] = 1

m = 0
keys = sorted(d.keys())
for k in keys:
    c = d[k]
    if (k-1) in d:
        c += d[k-1]
    if (k+1) in d:
        c += d[k+1]
    m = max(m,c)
print(m)

Measured memory_bytes: 13964
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int H, W, D;
string pat = "RYGB";

signed main() {
    cin >> H >> W >> D;
    rep(i,0,H) {
        rep(j,0,W) {
            int p = D;
            int ni = i+j+W, nj = i-j+W;
            int c = ((ni/p) % 2) * 2 + ((nj/p) % 2);
            // printf("ni = %lld, nj = %lld, c = %lld\n", ni, nj, c);
            cout << pat[c];
        }
        cout << endl;
    }
    return 0;
}

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

long long gcd(long long x,long long y)
{
	if(!y) return x;
	return gcd(y,x%y);
}

int main()
{
	long long a,b,c,d;
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	long long e=c*d/gcd(c,d);a--;
	long long ans=(b-a)-b/c+a/c-b/d+a/d+b/e-a/e;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256