akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<set>

using namespace std;

static const int MAX = 100000;

vector<int> G[MAX];
int N;
bool visited[MAX];
int prenum[MAX], parent[MAX], lowest[MAX], timer;

void dfs(int current, int prev) {
  prenum[current] = lowest[current] = timer;
  timer++;

  visited[current] = true;

  int next;

  for (int i = 0; i < G[current].size(); i++) {
    next = G[current][i];
    if (!visited[next]) {
      parent[next] = current;

      dfs(next, current);
      lowest[current] = min(lowest[current], lowest[next]);
    } else if (next != prev) {
      lowest[current] = min(lowest[current], prenum[next]);
    }
  }
}

void articulation_points() {
  for (int i = 0; i < N; i++) {
    visited[i] = false;
  }

  timer = 1;
  dfs(0, -1);

  set<int> ap;
  int np = 0;
  for (int i = 1; i < N; i++) {
    int p = parent[i];
    if (p == 0) {
      np++;
    } else if (prenum[p] <= lowest[i]) {
      ap.insert(p);
    }
  }
  if (np > 1) {
    ap.insert(0);
  }
  for (set<int>::iterator it = ap.begin(); it != ap.end(); it++) {
    cout << *it << endl;
  }
}

int main() {
  int m;
  cin >> N >> m;

  for (int i = 0; i < m; i++) {
    int s, t;
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  articulation_points();

  return 0;
}



Measured memory_bytes: 6904
#include <stdio.h>


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

    if(W < x + r ||  0 > x -r){
        printf("No\n");
    }
    else if(H < y+r ||  0 > y-r){
        printf("No\n");
    }
    else{
        printf("Yes\n");
    }
    
    return 0;
}


Measured memory_bytes: 2140
#include<stdio.h>
#include<string.h>
#include<math.h>
int ofs=21;

int B[50],R,N,r,l,h,i,j,P[150][2],p;
double ans;

void ins(int y,int x)
{
	P[p][0]=y;
	P[p][1]=x;
	p++;
}

double dis(int y,int x)
{
	double h=sqrt(1.0*R*R-x*x);
	h=R-h+y;
	return h;
}

int main()
{
	for(;scanf("%d%d",&R,&N),R;)
	{
		ans=10000000;
		memset(B,0,sizeof(B));
		for(i=0;i<N;i++)
		{
			scanf("%d%d%d",&r,&l,&h);
			for(j=r+ofs;j<l+ofs;j++)
				B[j]=B[j]>h?B[j]:h;
		}
		for(i=1,p=0;i<41;i++)
		{
			if(B[i]!=B[i-1])
			{
				ins(B[i-1],i-ofs);
				ins(B[i],i-ofs);
			}
		}
		ins(B[ofs],0);
		for(i=0;i<p;i++)
		{
			if(R>abs(P[i][1]))
			{
				double t=dis(P[i][0],P[i][1]);
				ans=ans<t?ans:t;
			}
		}
		printf("%lf\n",ans);
	}
	return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if ( a + b > c + d ) {
    cout << "Left" << endl;
  }
  else if ( a + b == c + d ) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
import sys
from itertools import product

_, _, _, k = [int(v) for v in sys.stdin.readline().split(" ")]
xs = [int(v) for v in sys.stdin.readline().split(" ")]
ys = [int(v) for v in sys.stdin.readline().split(" ")]
zs = [int(v) for v in sys.stdin.readline().split(" ")]


xys = sorted([x + y for x, y in product(xs, ys)], reverse=True)
zs = sorted(zs, reverse=True)
ret = [a + b for a, b in zip([zs[0]] * k, xys)]
for z in zs[1:]:
    rr = ret[:]
    r2 = [a + b for a, b in zip([z] * k, xys)]
    ret = sorted(ret + r2, reverse=True)[:k]
    if ret == rr:
        break
print('\n'.join([str(v) for v in ret]))

Measured memory_bytes: 63200
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 2002;

int dp[MAX_N][MAX_N][2];
int m,n;

int main()
{
	scanf("%d%d",&m,&n);
	string s1,s2;
	cin >> s1 >> s2;
	dp[0][0][0] = dp[0][0][1] = 0;
	rep(i,m){
		if(s1[m-i-1]=='I'){
			dp[i+1][0][0] = dp[i][0][1]+1;
			dp[i+1][0][1] = 0;
		}else{
			dp[i+1][0][0] = 0;
			dp[i+1][0][1] = dp[i][0][0]+1;
		}
	}
	rep(j,n){
		if(s2[n-j-1]=='I'){
			dp[0][j+1][0] = dp[0][j][1]+1;
			dp[0][j+1][1] = 0;
		}else{
			dp[0][j+1][0] = 0;
			dp[0][j+1][1] = dp[0][j][0]+1;
		}
	}
	rep(i,m){
		rep(j,n){
			if(s1[m-i-1]=='I' && s2[n-j-1]=='I'){
				dp[i+1][j+1][0] = max(dp[i+1][j][1]+1,dp[i][j+1][1]+1);
				dp[i+1][j+1][1] = 0;
			}else if(s1[m-i-1]=='O' && s2[n-j-1]=='O'){
				dp[i+1][j+1][0] = 0;
				dp[i+1][j+1][1] = max(dp[i+1][j][0]+1,dp[i][j+1][0]+1);
			}else if(s1[m-i-1]=='I' && s2[n-j-1]=='O'){
				dp[i+1][j+1][0] = dp[i][j+1][1] + 1;
				dp[i+1][j+1][1] = dp[i+1][j][0] + 1;
			}else{
				dp[i+1][j+1][0] = dp[i+1][j][1] + 1;
				dp[i+1][j+1][1] = dp[i][j+1][0] + 1;
			}
		}
	}
	int ans = 0;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			if(dp[i][j][0] != 0){
				ans = max(ans,((dp[i][j][0]-1)/2)*2+1);
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 34572
from collections import Counter
import numpy as np

n = int(input())
a = list(map(int, input().split()))
MAX = 10 ** 6

c = Counter(a)
arr = np.zeros(MAX + 1, np.int64)
st = set()
for k, v in c.items():
    if v != 1:
        st.add(k)
    arr[k] = 1

for i in range(MAX + 1):
    if arr[i]:
        arr[i*2::i] = 0

    if i in st:
        arr[i] = 0

print(arr.sum())


Measured memory_bytes: 55512
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map(String::toLong)
    var maxNum = 0L
    for(i in 0 until n){
        if(aList[i]==maxNum+1){
            maxNum++
        }
    }

    if (aList.contains(1).not()) {
        println(-1)
    } else {
        println(n-maxNum)
    }
}

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

int main() {
  int a=0,b=0,c=0,d=0;
  cin >> a >> b >> c;
  for(int i=0;i<2;i++){
  if(a>b){
    swap(a,b);
  }
  if(b>c){
    swap(b,c);
  }
  }
  cout << a << ' '  << b << ' ' << c << endl;
  return 0;
}



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

typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N, K;
double p[200000], res, d;

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> p[i];
		p[i] = (p[i] + 1) / 2;
	}
	for (int i = 0; i < K; i++) {
		d += p[i];
	}
	res = d;
	for (int i = 0; i < N - K; i++) {
		d -= p[i];
		d += p[i + K];
		res = max(d, res);
	}
	printf("%.10f\n", res);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 1e9+1;

auto ToplogicalSort (vector<vector<int>>& g, int n, int v_size){

  int res = 0;    

  vector<int> dp(n,0);
  vector<int> check(n,0);

  auto dfs = [&](auto& f, int u) -> int {

    if (dp[u] != 0) {
      if (!check[u]) return -1;
      return dp[u];
    }

    dp[u] = 1;

    for (auto v : g[u]) {
      int res = f(f, v);
      if (res == -1) return -1;
      dp[u] = max(dp[u], res + 1);
    }

    check[u] = 1;
    return dp[u];
  };
  
  for (int i = 0; i < v_size; i++) {
    int d = dfs(dfs, i);
    if (d == -1) {
      return -1;
    }
    res = max(res, d);
  }
  return res;
}

int main(){
  int n, m;
  cin >> n;
  m = n-1;
  
  vector<vector<int>> aa(n, vector<int>(m));

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> aa[i][j];
      aa[i][j]--;
    }
  }

  vector<vector<int>> id(n, vector<int>(n));
  int v = 0;
  for (int i = 0; i < n; i++) 
    for (int j = 0; j < n; j++) if (i < j) id[i][j] = v++; 

  vector<vector<int>> g(v);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m -1 ; j++) {
      int a = i, b = aa[i][j], c = i, d = aa[i][j + 1];
      if (a > b) swap(a, b);
      if (c > d) swap(c, d);
      g[id[a][b]].emplace_back(id[c][d]);
    }
  }
  int k = n * (n - 1) / 2;

  cout << ToplogicalSort(g, k, v) << endl;

  return 0;
} 

Measured memory_bytes: 39424
const Main = input => {
    input = input.split("\n");
    const nk = input[0].split(" ").map(value => parseInt(value, 10));

    const n = nk[0];
    const k = nk[1];
    const p = input[1].split(" ").map(value => parseInt(value, 10));

    //pを昇順でソート
    p.sort((a, b) => {
        return a - b;
    });

    let minTotal = 0;
    for(let i = 0; i < k; i++) {
        minTotal += p[i];
    }
    
    console.log(minTotal);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int x,y;

int main(){
	cin>>x>>y;
	if((x == 4 || x ==6 ||x == 9||x == 11) && (y == 4||y == 6||y == 9||y == 11)){
	cout<<"Yes"<<endl;}
	else if ((x == 1||x == 3||x == 5||x == 7||x == 8||x == 10||x == 12) && (y == 1||y == 3||y == 5||y == 7||y == 8||y == 10||y == 12)){
	cout<<"Yes"<<endl;}
	else {
	cout<<"No"<<endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
	int N,M;
	cin>>N>>M;
	int Lmax=0;
	int Rmin=N;
	int l,r;
	for(int i=0;i<M;i++){
		cin>>l>>r;
		Lmax=max(Lmax,l);
		Rmin=min(Rmin,r);
	}
	cout<<max(0,Rmin-Lmax+1)<<endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <map> // map


using namespace std;

int main(){
  int n;
  cin>>n;
  vector<int> p(n),q(n);

  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  for(int i=0;i<n;i++){
    cin>>q[i];
  }
  vector<int> a(n);
  for(int i=0;i<n;i++){
    a[i]=i+1;
  }
  map<vector<int>, int> mp;
  do{
    mp[a]=mp.size();
  }while(next_permutation(a.begin(),a.end()));
  
  int ans=abs(mp[p]-mp[q]);
  cout<<ans<<endl;
  return 0;
}
    
    
    
  
  
  
  
  
  
  
  
  
  
  


Measured memory_bytes: 5248
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>

using ll = long long;
typedef std::pair<int, int>p;

ll min(ll a, ll b) {
	if (a >= b)return b;
	else return a;
}
ll max(ll a, ll b) {
	if (a >= b)return a;
	else return b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);

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

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool flag = true;
bool fl = true;
struct edge { int to, cost; };
std::vector<edge>v[100];
bool used[210];

int main() {
	ll n, f[110][15], p[110][15];
	std::cin >> n;
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < 10;j++) {
			std::cin >> f[i][j];
		}
	}
	for (int i = 0;i < n;i++) {
		for (int j = 0;j <= 10;j++) {
			std::cin >> p[i][j];
		}
	}
	ll ans = INF2*(-1);
	for (int b = 1;b < 1024;b++) {
		ll cc = 0;
		for (int i = 0;i < n;i++) {
			ll c = 0;
			for (int j = 0;j < 10;j++) {
				if ((b >> j & 1) && f[i][j])c++;
			}
			cc += p[i][c];
		}
		if (ans < cc)ans = cc;
	}
	std::cout << ans << std::endl;
}

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

#define ll long long 

int main() {
    ios::sync_with_stdio(0); 

    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int ans = 0;
    ans += min(a, k);
    k -= min(a, k);
    if (k) k -= min(b, k);
    if (k) ans -= k;

    cout << ans << endl;


    return 0; 
}



Measured memory_bytes: 3608
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        n:usize,m:usize,
        a:[usize;m]
    }
    const MOD: i64 = 1000000007;
    let mut dp = vec![0; n + 4];
    let mut ok = vec![true; n + 4];
    for &x in a.iter() {
        ok[x] = false;
    }
    dp[0] = 1;

    for i in 0..n {
        if ok[i + 1] {
            dp[i + 1] += dp[i];
            dp[i + 1] %= MOD;
        }
        if ok[i + 2] {
            dp[i + 2] += dp[i];
            dp[i + 2] %= MOD;
        }
    }
    println!("{}", dp[n]);
}


Measured memory_bytes: 3868
#include <stdio.h>
int main(void){
int H,W,i,j;

while(1){scanf("%d %d", &H,&W);
    if(H==0 && W==0) break;
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            printf("#");
        }
        printf("\n");
    }
    printf("\n");
}
return 0;
}



Measured memory_bytes: 2128
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

int keta(int x) {
	int y = 0;
	while (x > 0) {
		y++;
		x /= 10;
	}
	return y;
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll dp[1010][1010];
ll a[101][101];

//long longしか使わない
int main() {
	ll n, m, x;
	cin >> n >> m >> x;
	vector<ll>c(n);
	rep(i, n) {
		cin >> c[i];
		rep(j, m) {
			cin >> a[i][j];
		}
	}
	ll ans = INF;
	for (ll bit = 0;bit < (1 << n);++bit) {
		ll total = 0;
		vector<ll>skill(m);
		for (ll i = 0;i < n;++i) {
			if (bit & (1 << i)) {
				total += c[i];
				rep(j, m) {
					skill[j] += a[i][j];
				}
			}
		}
		
		bool flag = true;
		rep(j, m) {
			if (skill[j] < x)flag = false;
		}
		if (flag) {
			ans = min(ans, total);
		}
	}
	if (ans == INF)cout << -1 << endl;
	else {
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	double a,b; cin>>a>>b;
	cout<<a/b;
	
	return 0;
}

Measured memory_bytes: 3756
import java.util.*;

class Main {
    private static final Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        // ??\????????????
        // ??¬??\??§????????°???????????§????????´???????????????????????°???????????°?????????????????\????????????
        int[] a = new int[3];
        for (int i = 0;i < 3;i++) {
            a[i] = sc.nextInt();
        }
        // ?????????
        Arrays.sort(a);
        // ??????
        for (int i = 0;i < 3;i++) {
            // ?????????
            System.out.print(a[i]);
            // ?????????????°???????????§??????????????????\?????????
            if (i==2) break;
            // ????§???????????????\??????
            System.out.print(" ");
        }
        // ???????????????
        System.out.println("");
    }
}

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

// A B C
// 1 2 3
// 2 1 3
// 3 1 2

// A B C
// B A C
// C A B

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << c << " " << a << " " << b;
}


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

int main()
{
    // input
    int N, T;
    std::vector<int> c, t;

    std::cin >> N >> T;

    for (int i = 0; i < N; i++)
    {
        int c_tmp, t_tmp;
        std::cin >> c_tmp >> t_tmp;

        c.push_back(c_tmp);
        t.push_back(t_tmp);
    }


    // ans
    int ans = 1000000000;

    for (int i = 0; i < N; i++)
    {
        if (t[i] <= T)
        {
            ans = std::min(ans, c[i]);
        }
    }

    if (ans == 1000000000)
    {
        std::cout << "TLE" << std::endl;
    }
    else
    {
        std::cout << ans << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
n = int(input())
listA = list(map(int, input().split()))
listA.sort()
listA.reverse()

i = 0
indexer = 0
flag = 0
count = 0
while i < len(listA):
    if i == 0:
        count+= 0
        i+=1
    elif i == 1:
        count+=listA[indexer]
        indexer+=1
        i+=1
    else:
        count+=listA[indexer]
        if flag:
            indexer+=1
            flag = 0
        else:
            flag = 1
        i+=1
print(count)

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

int n,len,ball[20],used[20];

int f()
{
	int t = -1;
	for (int i=1;i<=10;++i)
		if (!used[i])
		{
			if (ball[i] < t) return 0;
			t = ball[i];
		}
	t = -1;
	for (int i=1;i<=10;++i)
		if (used[i])
		{
			if (ball[i] < t) return 0;
			t = ball[i];	
		}
	return 1;
}

int dfs(int x,int l)
{
	if (l == len) return f();
	for (int i=x+1;i<=10;++i)
		if (!used[i])
		{
			used[i] = 1;
			if (dfs(i,l+1)) return 1;
			used[i] = 0;
		}
	return 0;
}

int main()
{
//	freopen("in.txt","r",stdin);
	cin>>n; 
	while (n--)
	{
		int flag = 0;
		for (int i=1;i<=10;++i) cin>>ball[i];
		for (int i=0;i<=5;++i)
		{
			memset(used,0,sizeof(used));
			len = i;
			if (dfs(0,0)) 
			{
				flag = 1;
				break;
			}
		}
		if (flag) cout<<"YES";
		else cout<<"NO";
		cout<<'\n';
	}
	return 0;
}


Measured memory_bytes: 2928
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll N, M;
  cin >> N >> M;

  ll base = 100*(N-M) + 1900*M;

  ll p = 1;
  rep(i,M){
    p *= 2;
  }

  cout << base * p << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll M=1e9+7, Mf[200002];
void Mfi(){
    Mf[0]=Mf[1]=1;
    for(int i=2;i<200002;i++)Mf[i]=(Mf[i-1]*i)%M;
}
ll Mp(ll a, ll b){
    if(b==0)return 1;
    else if(b%2==0)return Mp((a*a)%M, b/2)%M;
    return (a*Mp(a, b-1))%M;
}
ll Mc(ll a, ll b){
    if(a<b)return 0;
    ll c = (Mf[a]*Mp(Mf[a-b], M-2))%M;
    return (c*Mp(Mf[b], M-2))%M;
}
int main(void){
    ll n, m, k, u=0, t;
    cin >> n >> m >> k;
    Mfi();
    t = Mc(n*m-2, k-2);
    for(ll i=1;i<n;i++){
        for(ll j=1;j<m;j++){
            u += (n-i)*(m-j)*(i+j);
            u %= M;
        }
    }
    u *= 2;
    for(ll i=1;i<n;i++){
        u += (n-i)*m*i;
        u %= M;
    }
    for(ll j=1;j<m;j++){
        u += n*(m-j)*j;
        u %= M;
    }
    cout << (t*u)%M <<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<bitset>
#include<unordered_map> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include "boost/algorithm/string.hpp"
#define fio ios_base::sync_with_stdio(false)
#define mod 1000000007
#define mod1 mod
#define mod2 1000000007
#define li long long int
#define ll li
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define readi(x) scanf("%d",&x)
#define  reads(x)  scanf("%s", x)
#define readl(x) scanf("%I64d",&x)
#define rep(i,n) for(i=0;i<n;i++)
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define myrep1(i,a,b) for(i=a;i<=b;i++)
#define myrep2(i,a,b) for(i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 1000000000000000005
#define MINN -1000000000000000000
#define INTMAX 1000001000
#define pii pair<ll,ll> 
#define pdd pair<double,double>
#define pic pair<int,char>
#define N 400000
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 3.1415926535
#define lgn 20
 
 
// #define INTMAX 200000000 
 
// using namespace boost;
// #define si short int
 
using namespace std;
using namespace __gnu_pbds;             
typedef priority_queue<ll, vector<ll > > max_pq;
typedef priority_queue<ll, vector<ll> , greater<ll >  > min_pq;
ll toint(const string &s) {stringstream ss; ss << s; ll x; ss >> x; return x;}
string tostring ( ll number ){stringstream ss; ss<< number; return ss.str();}
 
// using namespace __gnu_pbds;         
// typedef priority_queue<pair<ll,char> , vector<pair<ll , char> > > max_pq;
// typedef priority_queue<pii , vector<pii > ,greater<pii > > min_pq;
typedef tree<pii , null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> OST;
// typedef priority_queue<pair < ll , pair < pii , ll > >  , vector<pair < ll , pair < pii , ll > >  > ,greater<pair < ll , pair < pii , ll > >  > > min_pq;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
        //use cerr if u want to display at the bottom
    }
    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 trace(...)
#endif
#define nn 2000005
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ll x,y;
    cin >> x >> y;
    cout <<(x+y/2);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var b = Read();
            switch (b)
            {
                case "A":
                    WriteLine("T");
                    break;
                case "T":
                    WriteLine("A");
                    break;
                case "C":
                    WriteLine("G");
                    break;
                case "G":
                    WriteLine("C");
                    break;

                default:
                    break;
            }
        }


        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
# -*- coding: utf-8 -*-
import math

# import copy


# 引数が一つだけのやつ
n = int(input())
# 引数が複数あるやつ（全部数字）
target_1 = [int(x) for x in input().split()]

# 引数が複数あるやつ（そうじゃないの）
# target = [int(x) for x in input().split()]

# number = int(input())
# 複数行を受け取って処理するやつ
# target = [list(input()) for i in range(H)]

# 関数
def count_sharp(target):
    return sum([x.count("#") for x in target])


def bin_code(value, keta):
    return list(("{:0" + str(keta) + "b}").format(value))


# 初期
target_1.sort()
point = 0
for idx, ins in enumerate(target_1):
    if idx != len(target_1) - 1:
        point += target_1[-1 - math.ceil(idx / 2)]

# 出力
print(point)


Measured memory_bytes: 33160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string S;
  cin >> S;
  if(S[0]==S[1]&&S[2]==S[3]&&S[0]!=S[2]){
    cout << "Yes" << endl;
  }else if(S[0]==S[2]&&S[1]==S[3]&&S[0]!=S[1]){
    cout << "Yes" << endl;
  }else if(S[0]==S[3]&&S[1]==S[2]&&S[0]!=S[1]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long

typedef pair<int, pair<int, int> > P;

bool comp(P a, P b) {
  return a.second.second < b.second.second;
}

string my_itos(int n) {
  string s;
  while (n) {
    int res = n % 10;
    res += '0';
    string t;
    t.push_back(res);
    s = t + s;
    n /= 10;
  }
  while (s.size() < 6) {
    s = "0" + s;
  }
  return s;
}

signed main() {
  int n, m;
  cin >> n >> m;
  P p[m];
  for (int i = 0; i < m; i++) {
    p[i].first = i + 1;
    cin >> p[i].second.first >> p[i].second.second;
  }
  sort(p, p + m, comp);
  string ans[m];
  int count[n + 1];
  fill(count, count + n + 1, 0);
  for (int i = 0; i < m; i++) {
    string res = my_itos(p[i].second.first);
    res += my_itos(++count[p[i].second.first]);
    ans[p[i].first - 1] = res;
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}


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

using ll = long long;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)

int main()
{
    int n = 0;
    cin >> n;
    VEC(ll, n, vec, 0);
    REP(i, n) cin >> vec[i];

    VEC(ll, n, dp, 0);
    BREP(i, n)
    {
        if( i == n - 1 ) dp[i] = 0;
        else if( i == n - 2 ) dp[i] = abs( vec[i] - vec[i + 1] );
        else
        dp[i] = min( dp[i+1] + abs( vec[i] - vec[i + 1] ), dp[i+2] + abs( vec[i] - vec[i + 2] ) );
    }
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int  min1 = 1e9;
	int a[105];
	int  b[105] = {0};
	for(int i = 1; i <= n; i++){
		cin>>a[i];
	}
	sort(a + 1, a + n + 1);
	for(int i = a[1];i <= a[n]; i++){
		for(int j = 1; j <= n; j++){
			b[i] += (a[j] - i) * (a[j] - i);
		}
		min1 = min(min1,b[i]);
	} 
	cout<<min1;
	
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define vci vector<ll>
#define vcs vector<string>
#define vcp vector<pair<ll, ll>>
#define vct vector<tuple<ll, ll, ll>>
using namespace std;
//vector<vector<ll>> vv(n, vector<ll>(n));

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

int main()
{
	ll n;
	cin >> n;
	ll ans = 1;
	while(ans<=n)
	{
		ans *= 2;
	}
	cout << ans/2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
 
int main(){
    int a,b;
    cin >> a >> b;
    int tmp1;
    if(b-a<0){
        for(int i=0;i<a;i++){
            cout << b ;
        }
    }
    else{
        for(int i=0;i<b;i++){
        cout << a ;
        }
    }
    cout << endl;
 
}

Measured memory_bytes: 256
X,Y=map(int,input().split())

def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

m=(2*X-Y)/3
n=(2*Y-X)/3

if m<0 or n<0:
    print(0)
elif m.is_integer()==False or n.is_integer==False:
    print(0)
else:
    print(combination(int(n+m),int(n)))

Measured memory_bytes: 3064
#pragma optimize GCC("Ofast")
#pragma comment(linker, "/STACK:1073741824")

#include<iostream>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<deque>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<fstream>
#include<iterator>
#include<functional>
#include<bitset>
#include<memory>
#include<sstream>
#include<new>
#include<cassert>
#include<iomanip>

using namespace std;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<bool, bool> pbb;
typedef pair<ld, ld> pdd;

const int inf = (int)1e9 + 9;
const ll linf = (ll) 1e18;
const ld eps = 1e-7;
const int mod = (int) 1e9 + 7;

#define it(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define scn second
#define sgn(x) (x > 0 ? 1 : (x == 0 ? 0 : -1))

signed main()
{
	ios_base::sync_with_stdio(false);
	srand(time(0));
	cin.tie(0);
	cout.tie(0);
	ll n, m;
	cin >> n >> m;
	if (n == 1)
	{
		if (m == 1)
		{
			cout << 1;
			return 0;
		}
		cout << max(0LL, m - 2);
		return 0;
	}
	if (m == 1)
	{
		cout << max(0LL, n - 2);
		return 0;
	}
	cout << max(0LL, (m - 2) * (n - 2));
}

Measured memory_bytes: 256
function Main(input) {
    var args = input.trim().split(' ').map(Number);
    if (args[0] >= 10 || args[1] >= 10) {
      console.log(-1)
    } else {
      console.log(args[0] * args[1])
    }
 }
 
/* var input = `9 9`;
Main(input);
 */ 
 Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll r,d,x; cin >>  r >> d >> x;
  rep(i,10){
      x = r*x - d;
      cout << x << endl;
  }

}

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

bool solve(long long a, long long b, long long c, long long d){
    if(a < b) return false;
    if(d < b) return false;
    if(d == b){
        if(c < (a%b)) return false;
        else return true;
    }
    long long gcd = __gcd(b, d);
    long long mod = a % gcd;
    long long oc;
    if(mod > c){
        oc = mod;
    }else{
        oc = (c - mod) / gcd + 1;
        oc = (oc * gcd) + mod;
    }
    if(oc >= b) return true;
    else return false;
}

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        long long a, b, c, d;
        scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
        if(solve(a, b, c, d)) printf("Yes\n");
        else printf("No\n");
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;

using namespace std;

int main()
{
  ll N, K;
  cin >> N >> K;
  for (auto i = 0; i < N; i++) {
    ll x;
    cin >> x;
  }
  cout << (N + K - 3) / (K - 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
#define FOR(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n,a,b,c;
	cin>>n;
	rep(i,n){
		cin>>a>>b>>c;
		cout<<(a*a==b*b+c*c||b*b==a*a+c*c||c*c==a*a+b*b?"YES":"NO")<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	long long n, q;
	cin >> n >> q;
	vector<stack<long long> >res(n);
	while (q--)
	{
		int op;
		cin >> op;
		if (op == 0)
		{
			long long t, x;
			cin >> t >> x;
			res[t].push(x);
		}
		else if (op == 1)
		{
			long long t;
			cin >> t;
			if (!res[t].empty())
			cout << res[t].top() << endl;
		}
		else if (op == 2)
		{
			long long t;
			cin >> t;
			if(!res[t].empty())
			res[t].pop();
		}
	}
	return 0;
}


Measured memory_bytes: 5048
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;

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

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))
#define INF (1<<28)
#define pb push_back
#define fs first
#define sc second

const char dx[]={0,1,0,-1},dy[]={1,0,-1,0};
template<class T>
ostream &operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()) out << v[i] << ", " ;
	return out << "}" << endl;
}
template<class S,class T>
ostream &operator<<(ostream &out, const pair<S,T> p){
	return out << "(" << p.fs << ", " << p.sc << ")";
}
/*cpp_int sum( cpp_int N )
{
	if( N == 0 ) return 1;
	else return N * sum( N - 1 );
}*/
int main(){
	int n;
	cin >> n;
	vector<pii> a(n);
	rep(i,n){
		int t;
		cin >> t;
		a[i] = pii(i%2==1 ^ n%2 ? -i : i, t);
	}
	sort(a.begin(), a.end());
	rep(i,n) cout << a[i].sc << endl;
	return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>
int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a==1){
        a=a+13;
    }
    if(b==1){
        b=b+13;
    }

    if(a>b){
        printf("Alice\n");
    }
    else if(a<b){
        printf("Bob\n");
    }
    else if(a==b){
        printf("Draw\n");
    }
    return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int id(string s){
    if(s=="AB") return 2;
    if(s=="BC") return 0;
    return 1;
}

int main(){
    int n; cin>>n;
    lint a[3]; cin>>a[0]>>a[1]>>a[2];
    vector<int> s(n);
    rep(i, n){
        string str; cin>>str; s[i]=id(str);
    }
    vector<int> ans(n);
    rep(i, n){
        int c = 0; rep(j, 3) if(a[j]==0) c++;
        if(c==0){
            rep(j,3){
                if(j==(s[i]+1)%3){
                    a[j]++; ans[i]=j;
                }
                if(j==(s[i]+2)%3) a[j]--;
            }
        }
        else if(c==1){
            int z; rep(j, 3) if(a[j]==0) z=j;
            if(s[i]==z){
                if(i==n-1){
                    ans[i]=(z+1)%3;
                }else{
                    if(s[i+1]==z || s[i+1]==(z+2)%3){
                        a[(z+1)%3]++; a[(z+2)%3]--;
                        ans[i]=(z+1)%3;
                    }else{
                        a[(z+1)%3]--; a[(z+2)%3]++;
                        ans[i]=(z+2)%3;
                    }
                }
            }
            else if(s[i]==(z+1)%3){
                a[z]++; a[(z+2)%3]--; ans[i]=z;
            }
            else{
                a[z]++; a[(z+1)%3]--; ans[i]=z;
            }
        }
        else if(c==2){
            int nz; rep(j, 3) if(a[j]!=0) nz=j;
            if(s[i]==nz){
                out("No"); return 0;
            }
            else if(s[i]==(nz+1)%3){
                a[nz]--; a[(nz+2)%3]++; ans[i]=(nz+2)%3;
            }else{
                a[nz]--; a[(nz+1)%3]++; ans[i]=(nz+1)%3;
            }
        }
        else{
            out("No"); return 0;
        }
    }
    out("Yes");
    rep(i,n) out("ABC"[ans[i]]);
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int main()
{
    fast();

    int m;
    cin >> m;
    while (m--)
    {
        string s;
        cin >> s;
        set<string> st;
        int N = s.size();

        for (int i = 1; i + 1 <= N; i++)
        {
            string pre = s.substr(0, i), suf = s.substr(i, N - i);
            st.insert(suf + pre);
            reverse(pre.begin(), pre.end());
            st.insert(pre + suf);
            st.insert(suf + pre);
            reverse(suf.begin(), suf.end());
            st.insert(pre + suf);
            st.insert(suf + pre);
            reverse(pre.begin(), pre.end());
            st.insert(pre + suf);
            st.insert(suf + pre);
        }

        cout << st.size() << "\n";
    }
}


Measured memory_bytes: 3200
import math
def comb(n, k):
    if n < 0 or k < 0 or n < k: return 0
    return math.factorial(n) // math.factorial(n-k) // math.factorial(k)



n,k = map(int, input().split())
MOD = 10 ** 9 + 7
print(comb(n-1, k-1) % MOD)


Measured memory_bytes: 5668
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back

template<class T>
class segment_tree{
    typedef function<T(T,T)> F;
private:
    int num_of_elm_;
    vector<T> dat_;
    F f_;
    T ident_;
public:
    segment_tree(int n, F f, T ident):f_(f), ident_(ident){
        num_of_elm_ = 1;
        while(num_of_elm_<n)num_of_elm_*=2;
        dat_.resize(2*num_of_elm_,ident);
    }
    
    void update(int pos,T val){
        int p = num_of_elm_ + pos;
        dat_[p] = val;
        while(p!=1){
            p/=2;
            dat_[p] = f_(dat_[p*2], dat_[p*2+1]);
        }
    }
    
    T query(int L, int R,int l=0,int r=0, int k=1){
        if(k==1)r = num_of_elm_;
        if(r<=L || R<=l)return ident_;
        else if(L<=l && r<=R){
            return dat_[k];
        }
        else{
            return f_(query(L,R,l,(l+r)/2,k*2), query(L,R,(l+r)/2,r,k*2+1));
        }
    }
};


int main(){
    int n,q;
    cin>>n>>q;
    auto  f = [](int a, int b){
        return min(a,b);
    };
    segment_tree<int> st(n,f,(1LL<<31)-1);

    rep(i,q){
        int com,x,y;
        cin>>com>>x>>y;
        if(com==0){
            st.update(x,y);
        }else{
            cout<<st.query(x,y+1)<<endl;
        }
        
    }
}



Measured memory_bytes: 3904
(defun get-input-array-string (n)
  (let ((input-array (make-array n)))
    (dotimes (i n)
      (setf (aref input-array i) (read-line)))
    input-array))

(defun main (h w)
  (let* ((rst 0)
         (input-array (get-input-array-string h)))
    (loop for x from 0 to (- h 1)
          do (loop for y from 0 to (- w 1)
                   do (setf rst 0)
                   if (string= (aref (aref input-array x) y) #\.)
                   do (progn (loop for dx from (- x 1) to (+ x 1)
                                   do (loop for dy from (- y 1) to (+ y 1)
                                            if (and (>= dx 0) (<= dx (- h 1)) (>= dy 0) (<= dy (- w 1)))
                                            do (progn (if (string= (aref (aref input-array dx) dy) #\#)
                                                          (incf rst)))))
                        (setf (aref (aref input-array x) y) 
                              (aref (write-to-string rst) 0)))
                   ))
    input-array))

  (let* ((h (read))
         (result (main h (read))))
    (dotimes (i h)
      (format t "~A~%" (aref result i))))


Measured memory_bytes: 19296
#include <iostream>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

vector<vector<int>> adj;
vector<vector<int>> inc;
vector<short> visited;
vector<int> stk;
vector<int> dp;

void toposort(int v){
    visited[v] = 1;

    for(auto child : adj[v]){
        if(!visited[child])
            toposort(child);
    }

    stk.push_back(v);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while(t--){
        int n,m;
        cin >> n >> m;
        adj = vector<vector<int>> (n+1);
        inc = vector<vector<int>> (n+1);
        visited = vector<short> (n+1,0);
        dp = vector<int> (n+1,0);

        for(int i=0 ; i<m ; i++){
            int x,y;
            cin >> x >> y;
            adj[x].push_back(y);
            inc[y].push_back(x);
        }

        for(int i=1 ; i<=n ; i++){
            if(!visited[i])
                toposort(i);
        }
        
        reverse(stk.begin(),stk.end());
        long long int output = 0;
        for(auto i : stk){
            int temp = 0;
            if(inc[i].size()==0){
                dp[i] = temp;
                continue;
            }
            for(auto parent : inc[i]){
                if(dp[parent] > temp)
                    temp = dp[parent];
            }
            dp[i] = temp+1;
            if(dp[i] > output) output = dp[i];
        }
        /*for(int i=1 ; i<=n ; i++) cout << dp[i] << " ";*/
        /*cout << "\n";*/
        cout << output << "\n";
    }
    return 0;
}



Measured memory_bytes: 17476
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    long len = s.length();
    long[] a = new long[26];
    for(int i = 0; i < s.length(); i++) {
      a[s.charAt(i) - 'a']++;
    }
    long ans = (len * (len - 1)) / 2;
    ans++;
    for(int i = 0; i < 26; i++) {
      ans -= ((a[i] * (a[i] - 1)) / 2);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 27500
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    vector<int>t(N+1);
    vector<int>x(N+1);
    vector<int>y(N+1);
    for(int i = 1; i <= N; i++) {
        cin >> t[i] >> x[i] >> y[i];
    }
    for(int i = 1; i <= N; i++) {
        int X = abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
        if(t[i]-t[i-1] < X) {
            cout << "No" << endl;
            return 0;
        }
        if((t[i]-t[i-1])%2 != X%2) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 5584
n = int(input())

S = [0]*13
H = [0]*13
C = [0]*13
D = [0]*13


for i in range(n):
    c, d= input().split()
    x = int(d)

    if c == 'S':
        S[x-1] = 1

    elif c == 'H':
        H[x-1] = 1

    elif c == 'C':
        C[x-1] = 1

    elif c == 'D':
        D[x-1] = 1

for i in range(13):
    if S[i] == 0:
        print("S", i+1)

for i in range(13):
    if H[i] == 0:
        print("H", i+1)

for i in range(13):
    if C[i] == 0:
        print("C", i+1)

for i in range(13):
    if D[i] == 0:
        print("D", i+1)



Measured memory_bytes: 5616
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 


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

int K, N; cin >> K >> N;
VI A(N); invec(A);

i64 ans = min({A[N-1] - A[0], A[0] + K - A[1], K - A[N-1] + A[N-2]});
rep(i, 1, N-1){
    ans = min({ans, A[N-1] - A[i] + K - A[N-1] + A[i-1], A[i] + K - A [i+1]});
}

cout << ans << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


struct UnionFind{

	std::vector<int> data;
	// dataの各要素について
	// 負の値:その集合のルートであること示す。また、その絶対値は集合の要素数となっている。
	// 正の値:親ノードの番号(dataのインデックス)。root()を呼び出すたびに集合のルートを指すように書きなおされるので木はそんなに深くならない

	//初期化 size:最大要素数
	UnionFind(int size): data(size, -1) {}

	// 集合を併合する
	// すでに同じ集合だった場合は、falseが返る
	bool unite(int x, int y){
		x=root(x);
		y=root(y);
		if( x != y ){
			// 要素数の大きな方へ合併するためのswap
			if( data[y] < data[x] ) std::swap(x, y);
			// 要素数を加算する
			data[x] += data[y];
			// yの属する集合のルートをxに変更
			data[y] = x;
		}
		return x!=y;
	}

	// 同じ集合かどうか判定
	bool find(int x, int y){
		return root(x) == root(y);
	}

	// 集合の識別番号を返す
	int root(int x){
		// 負の値を持つものがその集合のルート
		// 正の値は同じ集合に属するものを指す(辿ればいずれルートへ着く)
		return (data[x] < 0)? x : data[x]=root(data[x]);
	}

	// 集合の要素数を返す
	int size(int x){
		return -data[ root(x) ];
	}
};

int main(){
	ios_base::sync_with_stdio(false);
	int N, M, ans=0;
	int p[100005], x[100005], y[100005];

	cin >> N >> M;
	rep(i,N) cin >> p[i];
	rep(i,M){
		cin >> x[i] >> y[i];
	}

	UnionFind uf(N+1);
	rep(i,M) uf.unite(x[i], y[i]);

	rep(i,N){
		if( uf.find(p[i], i+1) ) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792