akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
double pi = 3.1415926535897932384646433;
typedef long long ll;
typedef pair<ll, ll>pii;
ll ccw(pii a, pii b, pii c)
{
  return (b.first - a.first)*(c.second - b.second) - (b.second - a.second)*(c.first - b.first);
}
double dist(pii a, pii b)
{
  return sqrt(double((b.first - a.first)*(b.first - a.first) + (b.second - a.second)*(b.second - a.second)));
}
double dot(pii a, pii b)
{
  return double(a.first*b.first + a.second*b.second);
}
double ans[111];
int main()
{
  fill(ans, ans + 111, 0);
  int num;
  scanf("%d", &num);
  vector<pii>v;
  map<pii, int>ma;
  for (int i = 0; i < num; i++)
  {
    ll a, b;
    scanf("%lld%lld", &a, &b);
    v.push_back(make_pair(a, b));
    ma[make_pair(a, b)] = i;
  }
  sort(v.begin(), v.end());
  vector<pii>v1, v2;
  for (int i = 0; i < num; i++)
  {
    for (;;)
    {
      if (v1.size() <= 1)break;
      pii a = v1[v1.size() - 2], b = v1[v1.size() - 1];
      if (ccw(a, b, v[i])<0)v1.pop_back();
      else break;
    }
    v1.push_back(v[i]);
  }
  for (int i = 0; i < num; i++)
  {
    for (;;)
    {
      if (v2.size() <= 1)break;
      pii a = v2[v2.size() - 2], b = v2[v2.size() - 1];
      if (ccw(a, b, v[i])>0)v2.pop_back();
      else break;
    }
    v2.push_back(v[i]);
  }
  for (int i = int(v2.size()) - 2; i >= 1; i--)v1.push_back(v2[i]);
  for (int i = 0; i < v1.size(); i++)
  {
    pii s = v1[(i + v1.size() - 1) % v1.size()];
    pii t = v1[i];
    pii u = v1[(i + 1) % v1.size()];
    //printf("%lld %lld  %lld %lld  %lld %lld\n", s.first, s.second, t.first, t.second, u.first, u.second);
    double x = acos(dot(make_pair(u.first - t.first, u.second - t.second), make_pair(s.first - t.first, s.second - t.second)) / dist(s, t) / dist(t, u));
    ans[ma[v1[i]]] = (pi - x) / (2 * pi);
  }
  for (int i = 0; i < num; i++)printf("%.6lf\n", ans[i]);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N = 0;
    int K = 0;
    int num = 1;
    cin >> N;
    cin >> K;
    for(int i = 0; i < N; i++){
        if(num < K)
            num *= 2;
        else
            num += K;
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              ((double)3.14159265358979323844)
#define DECIMAL(n)      cout << fixed << setprecision(n);
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

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

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

ll n;
ll can[25][25];
ll dp[25][1<<22];

ll calc(ll x,ll mask){
	if (mask==0)return 1;
	if (dp[x][mask]!=-1)return dp[x][mask];
	dp[x][mask]=0;
	rep(i,0,n){
		if ((mask & (1<<i)) && can[x-1][i]){
			dp[x][mask]=(dp[x][mask]%hell+calc(x-1,(mask & ~(1<<i)))%hell)%hell;
		}
	}
	return dp[x][mask];
}

void solve() {
    cin>>n;
    rep(i,0,n){
    	rep(j,0,n)cin>>can[i][j];
    }
    memset(dp,-1,sizeof dp);
    cout<<calc(n,(1<<n)-1)<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 819456
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	string in;
	cin >> in;
	int ans = 0;
	for (int i = 0; i < 3; ++i)
	{
		ans += (in[i] == '1');
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){
	string s;
	map<string, int> counter;
	string maxnum;
	string maxlen;
	while(cin >> s){
		int c = ++counter[s];
		if(c > counter[maxnum]){ maxnum = s; }
		if(s.size() > maxlen.size()){ maxlen = s; }
	}
	cout << maxnum << " " << maxlen << endl;
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define lli long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

lli f[N];

void solve()
{
    lli n;
    cin>>n;
    lli a[n];
    for(int i = 0; i  < n ; i ++)  cin>>a[i];

    for(int i = 0; i < n; i ++) {
        f[a[i]] ++;
    }
    lli ans = 0;
    for(int i = 1; i <= n; i ++) {
        ans += (f[i] * (f[i] - 1)) / 2;
    }
    for(int i = 0; i < n; i ++) {
        lli x = a[i];
//        cout<<f[x]<<endl;
        lli s = (f[x] * (f[x] - 1)) / 2;
        ans -= s;
        lli add = ((f[x] - 1) * (f[x] - 2)) / 2;
        if(add < 0)
            add = 0;
        ans += add;
        cout<<ans<<endl;
        ans -= add;
        ans += s;
    }
    cout<<'\n';
    return ;
}



/*
*/

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

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


Measured memory_bytes: 4736
#include <iostream>
#include <cmath>
using namespace std;
int main (void) {
    int x;
    int a;
    int b;

    cin >> x >> a >> b;

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;
#define int long long
 
signed main() {
  int n, k;
  cin >> n >> k;
  int x[n], y[n];
  int xcpy[n], ycpy[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    xcpy[i] = x[i];
    ycpy[i] = y[i];
  }
  sort(x, x + n);
  sort(y, y + n);
  int ans = LLONG_MAX;
  for (int xl = 0; xl < n; xl++) {
    for (int xr = xl + 1; xr < n; xr++) {
      for (int yl = 0; yl < n; yl++) {
        for (int yr = yl + 1; yr < n; yr++) {
          int count = 0;
          for (int i = 0; i < n; i++) {
            if (x[xl] <= xcpy[i] && xcpy[i] <= x[xr] && y[yl] <= ycpy[i] && ycpy[i] <= y[yr]) {
              count++;
            }
          }
          if (count >= k) {
            int res = (x[xr] - x[xl]) * (y[yr] - y[yl]);
            ans = min(ans, res);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
import bisect
from scipy.misc import comb
 
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
b = a.pop()
ind = bisect.bisect_left(a, b/2)

if ind == n-1:
    c = a.pop()
elif ind == 0:
    c = a[0]
else:
    if b/2 - a[ind-1] < a[ind] - b/2:
        c = a[ind-1]
    else:
        c = a[ind]

print(b, c)

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

typedef long long ll;
using namespace std;

int main() {
    int n, x;
    cin >> n >> x;
    int sum = 0;
    int ans = n;
    for(int i = 0; i < n; i++) {
        int e; cin >> e;
        sum += e;
        if(sum > x) {
            ans = i;
            break;
        }
    }
    cout << ans + 1<< endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
data = [list(map(int, input().split())) + [_] for _ in range(M)]
data = sorted(data, key=lambda x: (x[0], x[1]))

order = 1
for i in range(M):
    if not i == 0 and not data[i][0] == data[i-1][0]:
        order = 1
    data[i].append(str(data[i][0]).zfill(6) + str(order).zfill(6))
    order += 1

data = sorted(data, key=lambda x: (x[2]))
for x in data:
    print(x[3])


Measured memory_bytes: 43680
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;

int main(){
    int H,W;cin >> H >> W;
    vector<pair<int,int>> vec_h,vec_w;
    for(int i = 0;i < H;i++){
        string s;
        cin >> s;
        for(int j = 0;j < W;j++){
            if(s.at(j) == 'B'){
                vec_h.push_back({i, j});
                vec_w.push_back({j, i});
            }
        }
    }
    int ans = 0;
    for(int i = 0;i < vec_h.size()-1;i++){
        for(int j = i+1;j < vec_h.size();j++){
            ans = max(ans, abs(vec_h.at(i).first-vec_h.at(j).first) + abs(vec_h.at(i).second-vec_h.at(j).second));
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3244
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
#include <climits>
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 pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

class state{
public:
	int foot,x,y,cost;
	state(int _f, int _x, int _y, int _c){
		foot=_f; x=_x; y=_y; cost=_c;
	}
	bool operator<(const state& tmp)const{
		return cost>tmp.cost;
	}
};

int dx[2][9];
int dy[2][9];

void init(){
	int k=0;
	for(int i=1; i<=3; i++){
		for(int j=-2; j<=2; j++)if( i+abs(j)<=3 ){
			dx[0][k] = i; dy[0][k] = j;
			dx[1][k] = -i; dy[1][k] = j;
			k++;
		}
	}
}

int atai(char c){
	if( '0'<=c && c<='9' ) return c-'0';
	return 0;
}
int main(){
	int w,h;
	char field[64][64];
	int memo[2][64][64];
	init();
	// 0 = right foot  , 1 = left foot
	
	while(scanf(" %d%d ",&w,&h),w|h){
		rep(i,64)rep(j,64)memo[0][i][j]=memo[1][i][j]=INT_MAX;
		rep(i,h)rep(j,w){
			scanf(" %c ",&field[i][j]);
		}
		priority_queue<state> q;
		rep(i,w)if( field[h-1][i]=='S' ){
			q.push(state(0,i,h-1,0));
			q.push(state(1,i,h-1,0));
			memo[1][h-1][i] = memo[0][h-1][i] = 0;
		}
		int karikari = INT_MAX;
		while( !q.empty() ){
			int nx = q.top().x;
			int ny = q.top().y;
			int nf = q.top().foot;
			int nc = q.top().cost;
			if( karikari<nc ) break;
			//printf("nc:%d\n",nc);
			q.pop();
			rep(k,9){
				int tx = nx + dx[nf][k];
				int ty = ny + dy[nf][k];
				int next = (nf+1)%2;
				if( tx<0 || ty<0 || tx>=w || ty>=h || field[ty][tx]=='X' )continue;
				if( memo[next][ty][tx] > nc + atai(field[ty][tx]) ){
					memo[next][ty][tx] = nc + atai(field[ty][tx]);
					q.push(state(next, tx, ty, nc+atai(field[ty][tx])));
					if( field[ty][tx]=='T' ){
						karikari = min(karikari,memo[next][ty][tx]);
						//printf("karikari:%d\n",karikari);
					}
				}
			}
		}
		int ans = INT_MAX;
		rep(i,w)if( field[0][i]=='T' ){
			ans = min(ans, min(memo[0][0][i],memo[1][0][i]));
		}
		printf("%d\n",ans==INT_MAX?-1:ans);
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i_len=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back
#define mp make_pair

int main()
{
    ll A;
    string B;
    cin >> A >> B;
    ll C = A * ((B[0]-'0') * 100 + (B[2]-'0') * 10 + (B[3]-'0')) / 100;
    PR(C);

    return 0;
}

/*



*/

Measured memory_bytes: 3596
#include <iostream>
 
using namespace std;
 
int main(int argc, const char *argv[]) {
  long long x, a, count;
  long long interest = 1;
  cin >> x;
  a = 100;
  count = 0;

  while(1){
    a += interest;
    interest = a / 100;
    count++;
    if(a >= x){
      break;
    }
  }
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 3648
n = int(input())
fg = list(range(n+1))
fg.pop(0)
total = 0
for i in range(n):
    if fg[i] % 15 == 0:
        fg[i] = 'FizzBuzz'
    elif fg[i] % 3 == 0:
        fg[i] ='Fizz'
    elif fg[i] % 5 == 0:
       fg[i] = 'Buzz'

for i in range(n):
    if not (fg[i] == 'FizzBuzz' or fg[i] == 'Fizz' or fg[i] == 'Buzz'):
        total += fg[i]

print(total)

Measured memory_bytes: 48396
program kadai
implicit none
integer  ::  n
integer,allocatable  ::  a(:)
real(8),allocatable  ::  b(:)
integer  ::  i


read(*,*) n
allocate(a(n))
allocate(b(n))
read(*,*) a

call qsort(a)

b=real(a,8)
do i=1,n-1
    b(i+1)=(b(i)+b(i+1))/2.0_8
end do

write(*,*) b(n)

stop
contains
subroutine swap(a,b)
implicit none
integer,intent(inout)  ::  a,b
integer  ::  c
c=a
a=b
b=c
end subroutine swap

subroutine qsort(x)
implicit none
integer, intent(inout)  ::  x(:)
integer  ::  first,last
first=1
last=size(x)
call q2sort(x,first,last)
return
end subroutine qsort

recursive subroutine q2sort(x,first,last)
implicit none
integer, intent(inout)  ::  x(:)
integer, intent(inout) ::  first,last
integer  ::  fir, las
integer  ::  i,j
integer  ::  n
n=x((first+last)/2)
i=first
j=last
do
do while (x(i)<n)
i=i+1
end do
do while(x(j)>n)
j=j-1
end do
if (i>j .or. i==j) then
exit
end if
call swap(x(i),x(j))
i=i+1
j=j-1
end do
if (first<i-1) then
las=i-1
call q2sort(x,first,las)
end if
if (last>j+1) then
fir=j+1
call q2sort(x,fir,last)
end if
end subroutine q2sort

end program kadai


Measured memory_bytes: 640
n, k = map(int, input().split())
s = input()
x = None
count = 0
u = []
for c in s:
    if x != c and count > 0:
        if x == '0':
            u.append(count * -1)
        else:
            u.append(count)
        count = 0
    x = c
    count = count + 1
if x == '0':
    u.append(count * -1)
else:
    u.append(count)

x = 0
st = 0
ans = []
num = 0
for i in range(len(u)):
    if u[i] < 0:
        if x + 1 > k:
            #print("i({}), st({}), num({})".format(i, st, num))
            x = x - 1
            ans.append(num)
            while True: 
                num = num - abs(u[st])
                st = st + 1
                if u[st - 1] < 0:
                    break
        x = x + 1
    num = num + abs(u[i])
if num > 0:
    ans.append(num)
#print(ans)
print(max(ans))

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define fst first
#define snd second

int main() {
  std::ios_base::sync_with_stdio(false);
  set<string> dict;
  int N;
  cin >> N;

  REP(i, N) {
    string c, str;
    cin >> c >> str;
    if (c == "insert") {
      dict.insert(str);
    } else if (c == "find") {
      cout << (dict.find(str) != dict.end() ? "yes" : "no") << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 27056
use std::io::Read;

fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let length: usize = iter.next().unwrap().parse().unwrap();
    let inquiries: usize = iter.next().unwrap().parse().unwrap();
    let s: String = iter.next().unwrap().parse().unwrap();
    let ranges: Vec<(usize, usize)> = (0..inquiries)
        .map(|_| {
            (
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
            )
        })
        .collect();

    let mut cumulative_sum: Vec<usize> = (0..length).map(|_| 0).collect();
    //let chars = s.chars().collect::<Vec<char>>();
    for n in 1..length {
        if &s[n - 1..n + 1] == "AC" {
            cumulative_sum[n] = cumulative_sum[n - 1] + 1;
        } else {
            cumulative_sum[n] = cumulative_sum[n - 1];
        }
    }

    for range in ranges {
        println!(
            "{}",
            cumulative_sum[range.1 - 1] - cumulative_sum[range.0 - 1]
        );
    }
}


Measured memory_bytes: 8956
package main

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

func exec(stdin *Stdin, stdout *Stdout) {
	n := stdin.ReadInt()
	k := stdin.ReadInt()
	h := []int{}
	for i := 0; i < n; i++ {
		h = append(h, stdin.ReadInt())
	}

	sort.Sort(sort.Reverse(sort.IntSlice(h)))

	if n <= k {
		stdout.Println(0)
	} else {
		ans := 0
		for i := k; i < n; i++ {
			ans += h[i]
		}
		stdout.Println(ans)
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}


Measured memory_bytes: 7680
//============================================================================
// Name        : aoj2503.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;

int vford(int n,int c[400][400]){
	int d[400];
	fill(d,d + 400,-1);
	d[0] = 0;
	while(1){
		bool update = false;
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(c[i][j] != -1 && d[j] < d[i] + c[i][j]){
					d[j] = d[i] + c[i][j];
					update = true;
				}
			}
		}
		if(!update){
			break;
		}
	}
	return d[n - 1];
}


int main() {
	int n, m, a, b, c, cost[400][400], d[400];
	bool used[400];
	fill(used,used + 400,false);
	for(int i = 0;i < 400;i++){
		fill(cost[i],cost[i] + 400,-1);
	}
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		cin >> a >> b >> c;
		cost[a][b] = c;
	}

	cout << vford(n,cost) << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 306;


int h;
int w;
int n;
int ar[N*N];

int grid[N][N];


int main(){
    cin >> h >> w >> n;
    for(int i = 1; i <= n; i++){
        cin >> ar[i];
    }
    int idx = 1;
    for(int i = 1; i <= h; i++){
        if(i & 1){
                for(int j = 1; j <= w; j++){
                    grid[i][j] = idx;
                    ar[idx]--;
                    if(ar[idx] == 0)
                        idx++;
                }
        } else {
                for(int j = w; j >= 1; j--){
                    grid[i][j] = idx;
                    ar[idx]--;
                    if(ar[idx] == 0)
                        idx++;
                }
        }
    }
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cout << grid[i][j] << " ";
        }
        cout << "\n";
    }
}


Measured memory_bytes: 3744
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <list>

using namespace std;

int main()
{
    vector<int> rank;
    int n;
    int t[101];
    int l;
    int a,b,c,d;
    cin >> n;
    l = n*(n-1)/2;
    for(int i=0;i<101;++i) t[i] = 0;
    for(int i=0;i<l;++i)
    {
        cin >> a >> b >> c >> d;
        if(c > d) t[a] += 3;
        else if(c == d) t[a] += 1, t[b] += 1;
        else t[b] += 3;
    }
    for(int i=1;i<=n;++i) rank.push_back(t[i]);
    sort(rank.begin(), rank.end(), greater<int>());
    for(int i=1;i<=n;++i){
        for(int j=0;j<rank.size();++j){
            if(t[i] == rank[j])
            {
                cout << j+1 << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 1220
n=int(input())
f=[list(map(int,input().split())) for i in range(n)]
p=[list(map(int,input().split())) for i in range(n)]
ans=-float("inf")
for i in range(1,1<<10):
    tot=0
    for k in range(n):
        bit=0
        for j in range(10):
            if i&(1<<j) and f[k][j]==1: bit+=1
        tot+=p[k][bit]
    ans=max(ans,tot)
print(ans)

Measured memory_bytes: 3064
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt()
  val e = List.fill(m)((sc.nextInt()-1, sc.nextInt()-1, sc.nextInt()))

  def shortestPath(n: Int, edges: Seq[(Int, Int, Int)]): Array[Array[Int]] = {
    val ans = Array.tabulate(n,n)((i,j) => if (i == j) 0 else -1)
    for ((u, v, l) <- edges) {
      ans(u)(v) = l
      ans(v)(u) = l
    }

    for {
      k <- 0 until n
      i <- 0 until n
      j <- 0 until n
      if ans(i)(k) != -1 && ans(k)(j) != -1 &&
        (ans(i)(j) == -1 || ans(i)(k) + ans(k)(j) < ans(i)(j))
    } {
      ans(i)(j) = ans(i)(k) + ans(k)(j)
    }
    ans
  }

  val sp = shortestPath(n, e)
  val ans = e.count{ case (a, b, c) =>
    sp(a)(b) < c
  }
  println(ans)
}

Measured memory_bytes: 57932
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

vector<ll> divisor(ll x){
    vector<ll> res;
    for(ll i = 1; i * i <= x; ++i){
        if(x % i == 0){
            res.push_back(i);
        }
    }
    return res;
}

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

    ll n;
    cin >> n;
    vector<ll> div = divisor(n);
    int ans = 100;
    int sz = div.size();
    for(int i = 0; i < sz; ++i){
        ll foo = div[i], bar = n / div[i];
        string s = to_string(foo);
        string t = to_string(bar);
        int ns = s.length();
        int nt = t.length();
        chmin(ans, max(ns, nt));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// Problem : D - Face Produces Unhappiness
// Contest : AtCoder - AtCoder Beginner Contest 140
// URL : https://atcoder.jp/contests/abc140/tasks/abc140_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
const ll MOD = 1e9 + 7;
#define fir first
#define sec second
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(c,a,b) for(ll c=a;c<b;c++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define min_heap priority_queue<pll,vector<pll>,greater<pll> >
ll dx4[]={-1,1,0,0};
ll dy4[]={0,0,-1,1};
ll dx8[]={-1,-1,-1,0,1,1,1,0};
ll dy8[]={-1,0,1,1,1,0,-1,-1};
bool isvalid(ll x,ll y,ll n,ll m)
{
    return (x>=0 and y>=0 and x<n and y<m);
}
ll isprime[1000];
vector<ll> prime;
void sievetoprime(ll n)
{
    mem(isprime,true);
    for(ll p=2;p*p<=n;p++)
    {
        if(isprime[p]==true)
        {
            for(ll i=p*p;i<=n;i+=p)
                isprime[i]=false;
        }
    }
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
void solve()
{
    ll n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    ll cnt=0;
    rep(i,0,n-1)
    {
    	if(s[i]==s[i+1])
    		cnt++;
    }
    cout<<min(n-1,2*k + cnt);
}
int main()
{
    ll inpoup = 0;
    if(inpoup==1)
    {
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
    }
    IOS
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
int compare(const void *a,const void *b){
    if(*(int *)a<*(int *)b)return 1;
    return -1;
}
int main()
{   int n;
    scanf("%d",&n);
    int l[n];
    for(int i=0;i<n;i++){
    scanf("%d",&l[i]);
    }
    qsort(l,n,sizeof(int),compare);
    int ans=0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            for(int k=j+1;k<n;k++){
                if(l[i]<l[j]+l[k]){
                    ans++;
                }
            }
        }
    }
    printf("%d",ans);

    return 0;
}


Measured memory_bytes: 128
k, a, b = gets.chomp.split.map(&:to_i)

if b - a <= 2
  puts k + 1
elsif a >= k
  puts k + 1
else
  r = k - a + 1
  c = r / 2

  if r.even?
    puts (c - 1) * (b - a) + b
  else
    puts (c - 1) * (b - a) + b + 1
  end
end


Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int ans[n] = {0};
    repi(ri, 2, 0)
    {
        { //solve
            int cnt = 0;
            repi(i, n, 0)
            {
                if (s[i] == 'R')
                    cnt++;
                else
                {
                    ans[i] += cnt / 2;
                    ans[i - 1] += (cnt + 1) / 2;
                    cnt = 0;
                }
            }
        }
        reverse(ans, ans + n);
        reverse(s.begin(), s.end());
        repi(i, n, 0)
        {
            if (s[i] == 'L')
                s[i] = 'R';
            else
                s[i] = 'L';
        }
    }

    repi(i, n, 0)
    {
        cout << ans[i] <<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
console.log(function(args){
  let [A,B,C,K] = args.trim().split(' ').map(BigInt);
  if ( K <= A ) return K.toString();
  if ( K <= A + B ) return A.toString();
  return ( A - ( K - A - B ) ).toString();
}(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 29408
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<double, double> P;
int n;
double cos60 = cos(60.0 / 180.0 * M_PI);
double sin60 = sin(60.0 / 180.0 * M_PI);
void koch(int n, P p1, P p2) {
    if ( n == 0 ) {
	printf("%lf %lf\n", p1.first, p1.second);
//	printf("%lf %lf\n", p2.first, p2.second);    
    }
    else {
	P d = make_pair(p2.first - p1.first, p2.second - p1.second);
	P e = make_pair(d.first / 3.0, d.second / 3.0);
	P s = make_pair(p1.first + e.first, p1.second + e.second);

	P r = make_pair(cos60 * e.first - sin60 * e.second, sin60 * e.first + cos60 * e.second);

	P t = make_pair(s.first + r.first, s.second + r.second);
	P u = make_pair(s.first + e.first, s.second + e.second);
    
	koch(n - 1, p1, s);
	koch(n - 1, s, t);
	koch(n - 1, t, u);
	koch(n - 1, u, p2);
    }
    return;
}

int main()
{
    P l = make_pair(0.0, 0.0);
    P r = make_pair(100.0, 0.0);

    scanf("%d", &n);
    koch(n, l, r);
    printf("%lf %lf\n", r.first, r.second);
    return 0;
}

Measured memory_bytes: 3216
def main():
  _, *h=map(int, open(0).read().split())
  x=h[-1]
  for y in h[-2::-1]:
    if x<y-1:
      return 'No'
    x=y-(x<y)    
  return 'Yes'

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

Measured memory_bytes: 14108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
#define INF 10000000010
#define endl '\n'

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    // ll t;
    ll t=1;
    // cin >> t;
    while(t--){
        ll n,m,l; cin >> n >> m >> l;
        ll a[n][n];
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                a[i][j]=(i==j)? 0 :INF;
            }
        }
        for(int i=0;i<m;i++){
            ll u,v,c; cin >> u >> v >> c;
            --u,--v;
            a[u][v]=c; a[v][u]=c;
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                for(int k=0;k<n;k++){
                    a[j][k] = min(a[j][k],a[j][i]+a[i][k]);
                }
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                a[i][j] = a[i][j]<=l ? 1 : INF;
            }
        }
       for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                for(int k=0;k<n;k++){
                    a[j][k] = min(a[j][k],a[j][i]+a[i][k]);
                }
            }
        }
        ll q; cin >> q;
        // cout << "hi: ";
        while(q--){

            ll s,t; cin >> s >> t;
            --s,--t;
            ll ans = (a[s][t]==INF) ? -1 : a[s][t]-1;
            cout << ans <<endl ;

        }

    }

}


Measured memory_bytes: 1280
#include <stdio.h>
int main(void){

int a,op,b,i;

    for(i=0;i<=20000;i++){

    scanf("%d %c %d",&a, &op, &b);
    if(0<=a&&a<=20000&&0<=b&&b<=20000){
    
        if(op=='+'){
            printf("%d\n",a + b);
            }
        if(op=='-'){
            printf("%d\n",a - b);
        }
        if(op=='*'){
            printf("%d\n",a * b);
        }
        if(op=='/'){
            printf("%d\n",a / b);
        }
        if(op=='?') break;
    }
    }
    return 0;
}



Measured memory_bytes: 2048
N = int(input())
ans = 10**9+7
def divisore(n):
    divisors=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            if i!=n//i:
                divisors.append(n//i)
    divisors.sort(reverse=True)
    return divisors
li = divisore(N)
n = len(li)
if n % 2 == 0:
    for i in range(n//2):
        j = i+1
        j = j * (-1)
        left = len(str(li[i]))
        right = len(str(li[j]))
        k = max(left,right)
        if k <= ans:
            ans = k
    print(ans)
    exit()
else:
    l = int(N**(1/2))
    print(len(str(l)))

Measured memory_bytes: 3188
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = [b for a, b in sorted([(s*m+t, i) for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Measured memory_bytes: 130948
z='abcdefghijklmnopqrstuvwxyz'
def f(x):
 for i in range(1,26,2):
  for j in range(26):
   a=''.join(z[(z.index(c)*i+j)%26]if c in z else c for c in x)
   if'that'in a or'this'in a:return a
for _ in[0]*int(input()):print(f(input()))


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

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

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

const int INF = 1e18;
const int MOD = 1e9 + 7;

signed main(){
    string s; cin >> s;

    set<char> st;
    REP( i, s.size() ){
        st.insert( s[i] );
    }

    if( st.size() == s.size() ){
        cout << "yes" << endl;
    }else{
        cout << "no" << endl;
    }
}


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

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

distSquare :: [Int] -> [Int] -> Int
distSquare _ [] = 0
distSquare [] _ = 0
distSquare (a : as) (b : bs) = (b - a) ^ 2 + distSquare as bs

comb :: Int -> [a] -> [[a]]
comb 0 xs = [[]]
comb _ [] = []
comb n (x : xs) = [x : y | y <- comb (n -1) xs] ++ comb n xs

calc :: [[[Int]]] -> Int
calc [] = 0
calc (p : ps) = k + calc ps
  where
    [as, bs] = p
    ds2 = distSquare as bs
    k =
      if ds2 - (floor (sqrt (fromIntegral ds2))) ^ 2 == 0
        then 1
        else 0

main = do
  [n, d] <- getIntList
  xss <- getIntNList n
  let pairs = comb 2 xss
  print $ calc pairs


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

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


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tommy6073
 */

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

class BCoins {
public:
    void solve(std::istream& in, std::ostream& out) {
        int A, B, C, X;
        in >> A >> B >> C >> X;

        int cnt = 0;
        for (int a = 0; a <= A; ++a) {
            for (int b = 0; b <= B; ++b) {
                for (int c = 0; c <= C; ++c) {
                    if ((500 * a + 100 * b + 50 * c) == X) {
                        ++cnt;
                    }
                }
            }
        }

        out << cnt;
    }
};


int main() {
	BCoins solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
	bool operator<(const B& b) const { return cost < b.cost; }
	bool operator>(const B& b) const { return cost > b.cost; }
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, l;
signed main() {
	cin >> n >> l;
	int ans = 0, res = Inf, k = 0;
	for (int i = 0; i < n; i++) {
		k += l + i;
	}
	for (int i = 0; i < n; i++) {
		int sum = 0;
		for (int j = 0; j < n; j++) {
			if (i != j) sum += l + j;
		}
		if (res > abs(sum - k)) {
			res = abs(sum - k);
			ans = sum;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SQ(a) (a)*(a)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define ll long long int 
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);	cout.tie(NULL);
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int digits = 0;
        int cur = i;
        while (cur)
        {
            cur /= 10;
            digits++;
        }
        if (digits & 1)
            ans++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
/*
ID: yzshang1
LANG: C++11
TASK:
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int (i) = 1; (i) <= (int)n; (i)++)
#define rep(i, n) for (int (i) = 0; (i) < (int)n; (i)++)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
const int N = 100010;
int main() {
	int h, n;
	cin >> h >> n;
	int sum = 0;
	rep(i, n) {
		int x;
		cin >> x;
		sum += x;
	}
	if (sum < h) puts("No"); else puts("Yes");
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 3e3 + 11;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int n, m, a[N], b[N], c[N], d[N], e[N], f[N], ans, x, y;
bool wasx[N][N], wasy[N][N], was[N][N];
queue < pii > q;
vi valx, valy;

int getx (int x) {
	return upper_bound(all(valx), x) - valx.begin();
}

int gety (int y) {
	return upper_bound(all(valy), y) - valy.begin();
}

main () {
	cin >> n >> m;	
	for (int i = 1; i <= n; ++i) {
		cin >> a[i] >> b[i] >> c[i];
		valx.pb(a[i]);
		valx.pb(b[i]);
		valy.pb(c[i]);
	}

	for (int i = 1; i <= m; ++i) {
		cin >> d[i] >> e[i] >> f[i];
		valx.pb(d[i]);
		valy.pb(e[i]);
		valy.pb(f[i]);
	}

	for (int i = -1; i <= 1; i += 2) {
		valx.pb(2*i*inf); 
		valy.pb(2*i*inf); 
	}

	sort(all(valx));
	valx.resize(unique(all(valx)) - valx.begin());

	sort(all(valy));
	valy.resize(unique(all(valy)) - valy.begin());

	for (int i = 1; i <= n; ++i) {
		y = gety(c[i]) - 1; 		
		int xl = getx(a[i]), xr = getx(b[i]);
		for (int x = xl; x < xr; ++x)
			wasx[x][y] = 1;
	}

	for (int i = 1; i <= m; ++i) {
		x = getx(d[i]) - 1;
		int yl = gety(e[i]), yr = gety(f[i]);
		for (int y = yl; y < yr; ++y)
			wasy[x][y] = 1;
	}

	x = getx(0);
	y = gety(0);

	q.push({x, y});
	was[x][y] = 1;
	
	while (sz(q)) {
		int x = q.front().f, y = q.front().s;
		ans += (valx[x] - valx[x - 1]) * (valy[y] - valy[y - 1]);
		q.pop();

		if (x == 1 || y == 1 || x == sz(valx) - 1 || y == sz(valy) - 1) {
			cout << "INF";
			return 0;
		}

		if (!was[x][y + 1] && !wasx[x][y]) {
			was[x][y + 1] = 1;
			q.push({x, y + 1});
		}

		if (!was[x][y - 1] && !wasx[x][y - 1]) {
			was[x][y - 1] = 1;
			q.push({x, y - 1});
		}

		if (!was[x + 1][y] && !wasy[x][y]) {
			was[x + 1][y] = 1;
			q.push({x + 1, y});
		}

		if (!was[x - 1][y] && !wasy[x - 1][y]) {
			was[x - 1][y] = 1;
			q.push({x - 1, y});			   
		}		
	}

	cout << ans << endl;
}


Measured memory_bytes: 26912
// 優先度付きキュー
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

#define MAX_H 2000000
// 無効な値の定義
const int INV = -1;

int parent(int i);
int leftNode(int i);
int rightNode(int i);

void buildPriorityQueue(int queue[], int size, int addElement);
int MaxPriorityQueue(int queue[], int size);

int main(void)
{
    char order[10];
    int size = 0, number;
    int priorityQueue[MAX_H];

    for(int i = 0; i < MAX_H; i++)
    {
        priorityQueue[i] = INV;
    }

    while( 1 )
    {
        cin >> order;

        if( strncmp("insert", &order[0] , 6) == 0 )
        {
            cin >> number;
            // キューを構築する
            buildPriorityQueue(&priorityQueue[0], size, number);
            size++;
        }
        else if( strncmp("extract", &order[0] , 7) == 0 )
        {
            // 最大値を返して, キューを再構築する
            cout << MaxPriorityQueue(&priorityQueue[0], size) << endl;
            size--;
        }
        else
        {
            break;
        }
    }

    return 0;
}

// 節点の親のNo.を返す関数
int parent(int i)
{
    return i / 2;
}

// 節点の左の子のNo.を返す関数
int leftNode(int i)
{
    return 2 * i;
}

// 節点の右の子のNo.を返す関数
int rightNode(int i)
{
    return ( 2 * i ) + 1;
}

// 優先度付きキューを構築する関数
void buildPriorityQueue(int queue[], int lastNo, int addElement)
{
    bool cmpFlag = true;
    int parentNo;

    if( lastNo == 0 )
    {
        queue[1] = addElement;

        return;
    }

    // キューの最後に要素を追加して, 上に上がっていく
    lastNo++;
    queue[lastNo] = addElement;

    while( cmpFlag == true )
    {
        cmpFlag = false;

        parentNo = parent(lastNo);

        if( parentNo <= 0 )
        {
            // ルートの要素まで来たら, 処理は終了
            break;
        }

        if( queue[lastNo] > queue[parentNo] )
        {
            // 親の値よりも大きければ交換する
            swap(queue[lastNo], queue[parentNo]);
            lastNo = parentNo;

            cmpFlag = true;
        }
    }

    return;
}

// 最大値を返して, 優先度付きキューを再構築する関数
int MaxPriorityQueue(int queue[], int lastNo)
{
    bool cmpFlag = true;
    int eleNum = 0, leftNo = 0, rightNo = 0;
    int cmpNo;

    int max = queue[1];

    if( lastNo < 0 )
    {
        // 要素が存在しない時は, 無効値を返す
        return INV;
    }

    // 最後の要素を先頭に持ってくる
    queue[1] = queue[lastNo];
    queue[lastNo] = INV;
    eleNum = 1;

    while( cmpFlag == true )
    {
        cmpFlag = false;

        leftNo = leftNode(eleNum);
        rightNo = rightNode(eleNum);

        if( queue[leftNo] >= queue[rightNo] )
        {
            cmpNo = leftNo;
        }
        else
        {
            cmpNo = rightNo;
        }

        if( cmpNo < lastNo
            && queue[cmpNo] > queue[eleNum] )
        {
            cmpFlag = true;
            // 左の要素と比較
            swap(queue[cmpNo], queue[eleNum]);
            eleNum = cmpNo;
        }
    }

    return max;
}



Measured memory_bytes: 10884
s = input()

c = 0
dp = [0] * (len(s) + 1)
for i in range(len(s)):
    if s[i] == '<':
        c += 1
        dp[i + 1] = c
    else:
        c = 0
c = 0
for i in range(len(s))[::-1]:
    if s[i] == '>':
        c += 1
        dp[i] = max(dp[i], c)
    else:
        c = 0
ans = sum(dp)
print(ans)

Measured memory_bytes: 46536
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    while(1) {
        cin >> n;
        if (n == 0) return 0;
        vector <int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        sort(a.begin(), a.end());
        int sum = 0;
        for (int i = 1; i < n-1; i++) {
            sum += a[i];
        }
        cout << (int)sum/(a.size()-2) << endl;
    }
}

Measured memory_bytes: 3048
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double pi = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

int main(){
    string s;
    cin >> s;
    int mini = 1e9;
    for(int i = 0; i < s.size() - 2; i++){
        string temp = s.substr(i,3);
        int itemp = stoi(temp);
        mini = min(mini,abs(itemp-753));
    }
    cout << mini << endl;
    return 0;
}

Measured memory_bytes: 256
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
map<string,int>m;
int n,top;
string s[200005];
char ch[105];
int main(){
	in(n);
    for(int i=1;i<=n;i++){
        scanf("%s",ch);
        string ss=ch;
        if(!m[ss]){
            s[++top]=ss;
            m[ss]=1;
        }
        else m[ss]++;
    }
    sort(s+1,s+1+top);
    int ans=0;
    for(int i=1;i<=top;i++)ans=max(ans,m[s[i]]);
    for(int i=1;i<=top;i++){
        if(m[s[i]]==ans){
            int len=s[i].size();
            for(int j=0;j<len;j++){
                char cc=s[i][j];
                printf("%c",cc);
            }
            puts("");
        }
    }
	return 0;
}


Measured memory_bytes: 34816