akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

#define MAX 100000

typedef struct {
	char suit;
	int rank;
	int in;
} card;

int partition(card *, int, int);
void quickSort(card *, int, int);
void swap(card *, card *);

int main(void)
{
	int i, n, flag=1;
	card C[MAX];
	
	scanf("%d",&n);
	for (i=0; i<n; i++) {
		scanf(" %c %d", &C[i].suit, &C[i].rank);
		C[i].in = i;
	}
	
	quickSort(C, 0, n-1);
	
	for (i=0; i<n-1; i++) {
		if(C[i].rank == C[i+1].rank) {
			if(C[i].in > C[i+1].in) {
				flag = 0;
				break;
			}
		}
	}
	if(flag) printf("Stable\n");
	else printf("Not stable\n");
	for (i=0; i<n; i++) {
		printf("%c %d\n", C[i].suit, C[i].rank);
	}
	
	return 0;
}

int partition(card *C, int p, int r)
{
	int i, j, q, x;
	
	x = C[r].rank;
	i = p-1;
	for (j=p; j<r; j++) {
		if (C[j].rank <= x) {
			swap(&C[++i], &C[j]);
		}
	}
	swap(&C[++i], &C[r]);
	return i;
}

void quickSort(card *C, int p, int r)
{
	int q;
	
	if(p < r) {
		q = partition(C, p, r);
		quickSort(C, p, q-1);
		quickSort(C, q+1, r);
	}
}

void swap(card *a, card *b)
{
	card temp=*a;
	*a = *b;
	*b = temp;
}

Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  int H,W; cin >> H >> W;
  vector<vector<int>> c(10,vector<int>(10));
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) cin >> c[i][j];
  }
  vector<vector<int>> A(H,vector<int>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) cin >> A[i][j];
  }
  
  vector<vector<int>> dp(10,vector<int>(9));
  for (int j = 0; j < 9; j++) {//回数
    for (int i = 0; i < 10; i++) {//元の数字
      if (j == 0) dp[i][j] = c[i][1];
      else {
        dp[i][j] = dp[i][j-1];
        for (int k = 0; k < 10; k++) {
          dp[i][j] = min(dp[i][j],dp[k][j-1]+c[i][k]);
        }
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (A[i][j] == -1) continue;
      ans += dp[A[i][j]][8];
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

	int n;
	std::cin >> n;
	std::vector<ll> p(n);
	rep(i, n) std::cin >> p[i];

	std::multiset<ll> mset;
	std::vector<std::pair<ll, ll>> v;
	rep(i, n) {
		v.push_back({ p[i], i + 1 });
	}

	std::sort(allof(v), std::greater<std::pair<ll, ll>>());

	// 番兵投入
	mset.insert({ 0, 0, n + 1, n + 1 });

	// 大きいやつから処理する
	ll ans = 0;

	for (auto pi : v) {
		int id = pi.second;

		auto iter = mset.lower_bound(id);
		ll r1 = *iter;
		ll r2 = *std::next(iter);
		iter--;
		ll l1 = *iter;
		ll l2 = *(std::prev(iter));

		ans += pi.first * (r2 - r1) * (id - l1);
		ans += pi.first * (l1 - l2) * (r1 - id);
		mset.insert(id); // id投入
	}

	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 7280
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"a,b=map(int,input().split());c=0\n"
"while a<=b:s=str(a);c+=s==s[::-1];a+=1\n"
"print(c)\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 3280
import math
N,D=[int(x) for x in input().split()]
XX=[]
for i in range(N):
    XX.append([int(x) for x in input().split()])

count=0
for i,X in enumerate(XX):
    for j,Y in enumerate(XX):
        if i>=j:
            continue
        r=0
        for x,y in zip(X,Y):
            r+=(y-x)**2
        if math.sqrt(r)==int(math.sqrt(r)):
            count+=1

print(count)


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w;
    cin >> h >> w;

    int s_x, s_y, e_x, e_y;
    cin >> s_x >> s_y;
    cin >> e_x >> e_y;

    s_x -= 1;
    s_y -= 1;
    e_x -= 1;
    e_y -= 1;

    vector<vector<char>> s(h, vector<char>(w));
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            cin >> s[i][j];
   
    vector<int> dxx({-1, 0, 0, 1});
    vector<int> dyy({0, 1, -1, 0});
    vector<vector<bool>> vis(h, vector<bool>(w, false));
    deque<tuple<int, int, int>> deq;
    deq.push_back({0, s_x, s_y});
    int ans = -1;
    while (!deq.empty()){
        auto [dis, x, y] = deq.front(); deq.pop_front();

        if (vis[x][y])
            continue;
        
        if (x == e_x && y == e_y){
            ans = dis;
            break;
        }

        vis[x][y] = true;
        for (int i = 0; i < 4; i++){
            int new_x = x + dxx[i], new_y = y + dyy[i];

            if (new_x >= 0 && new_x < h && new_y >= 0 && new_y < w){
                if (s[new_x][new_y] == '.'){
                    deq.push_front({dis, new_x, new_y});
                }
            }
        }

        for (int dx = -2; dx <= 2; dx++){
            for (int dy = -2; dy <= 2; dy++){
                int new_x = x + dx, new_y = y + dy;

                if (new_x >= 0 && new_x < h && new_y >= 0 && new_y < w){
                    if (s[new_x][new_y] == '.')
                        deq.push_back({dis + 1, new_x, new_y});
                }
            }
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 6136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  int n,k;
  cin >> n >> k;
  int a[n] = {0};
  for(int i = 0;i<k;i++)
  {
      int d;
      cin >> d;
      for(int j=0;j<d;j++)
      {
          int b;
          cin >> b;
          a[b-1]++;
      }
  }
  int c = 0;
  for(int i = 0;i<n;i++)
  {
      if(a[i] == 0)c++;
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 3636
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        x: usize, 
        mat: [[usize; m+1]; n]
    }

    let mut ans = 10000000;
    for b in 0..2u32.pow(n as u32) {
        let mut score = vec![0; m+1];
        for i in (0..n).filter(|i| (b >> i) & 1 == 1) {
            for j in 0..m+1 {
                score[j] += mat[i][j];
            }

        }
        if (score[1..].iter().min() >= Some(&x)) & (ans > score[0]) { ans = score[0]; }
    }

    if ans == 10000000 { println!("-1"); } else { println!("{}",ans); }
}

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


int main(){
  int room[4][3][10]= {0};
  int b,n,f,r,v;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> b >> f >> r >> v;
    room[b-1][f-1][r-1] += v;
  }

  for(int i = 0;i < 4;i++){
    for(int j = 0;j < 3;j++){
      for(int k = 0; k < 10; k++){
        cout << " "<< room[i][j][k];
      }   
      cout << endl;
    }   
    if(i != 3){ 
      cout <<"####################"<<endl;
    }   
  }
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sidha(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int> 
#define pb push_back

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
	int r,d,x;cin>>r>>d>>x;
	ll arr[11];
	arr[0]=r*x-d;
	sidha(i,1,10){
		arr[i]=r*arr[i-1]-d;
	}
	sidha(i,0,10){
		cout<<arr[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3592
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {
	fmt.Println(answer(os.Stdin))
}

func answer(r io.Reader) string {
	sc := bufio.NewScanner(r)
	sc.Scan()
	ss := strings.Fields(sc.Text())
	n, _ := strconv.Atoi(ss[0])
	k, _ := strconv.Atoi(ss[1])

	T := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		T[i], _ = strconv.Atoi(sc.Text())
	}

	left, mid := 0, 0
	right := 100000 * 100000
	for right-left > 1 {
		mid = (left + right) / 2
		v := allocateCapacity(T, mid, k, n)
		if v >= n {
			right = mid
		} else {
			left = mid
		}
	}
	return strconv.Itoa(right)
}

// allocateCapacity assigns the capacity per unit
// form the max capacity "P", max number of containers "k", max number of balls "n"
func allocateCapacity(T []int, P, k, n int) int {
	i := 0
	for j := 0; j < k; j++ {
		s := 0
		for s+T[i] <= P {
			s += T[i]
			i++
			if i == n {
				return n
			}
		}
	}
	return i
}



Measured memory_bytes: 2328
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int main(){
  int s[4];
  rep(i, 4){
    cin >> s[i];
  }
  sort(s, s+4);
  int ans = (s[0] == 1 && s[1] == 4 && s[2] == 7 && s[3] == 9);
  puts(ans ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 256
<?php
  list($a, $b, $k) = explode(" ", trim(fgets(STDIN)));

  $count =0;
  for($i=100; $i>=0; $i--){
    if($a % $i == 0 && $b % $i == 0){
      $count++;
    }
    if($count == $k){
      echo $i;
      exit;
    }
  }

Measured memory_bytes: 16212
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
typedef long long lint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = 1e-9;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
lint mypow(lint a, lint b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	lint memo = mypow(a, b >> 1);
	return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	lint memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
std::string to_string(std::vector<int>& vec) {
	std::string res = "[";
	rep(i, vec.size() - 1)res += std::to_string(vec[i]) + ", ";
	res += std::to_string(vec.back()) + "]";
	return res;
}
int n;
std::string s;
std::vector<P> vec[2];
int main(){
	std::cin>>n;
	rep(i,n){
		std::cin>>s;
		int a=0,now=0;
		for(char c:s){
			if(c==')')a--;
			else a++;
			chmax(now,-a);
		}
		if(0<=a)vec[0].emplace_back(now,now+a);
		else vec[1].emplace_back(now+a,now);
	}
	std::sort(all(vec[0]));
	std::sort(all(vec[1]),std::greater<P>());
	int now=0;
	for(P i:vec[0]){
		now-=i.first;
		if(now<0){
			puts("No");
			return 0;
		}
		now+=i.second;
	}
	for(P i:vec[1]){
		now-=i.second;
		if(now<0){
			puts("No");
			return 0;
		}
		now+=i.first;
	}
	if(now)puts("No");
	else puts("Yes");
	return 0;
}


Measured memory_bytes: 18988
# import sys
# input = sys.stdin.readline

def main():
    n, k = input_list()
    a = input_list()
    d = {1: 0}
    pre = 1
    loop_start = 0
    loop_end = 0
    loop_pos = 0
    for i in range(1, n+1):
        new = a[pre - 1]
        if d.get(new):
            loop_start = d[new]
            loop_end = i
            loop_pos = new
            break
        if i == k:
            print(new)
            exit()
        d[new] = i
        pre = new
    k -= loop_start
    k %= loop_end - loop_start
    pre = loop_pos
    for i in range(k):
        pre = a[pre - 1]
    print(pre)

    # goto = [a[0]]
    # index = 0
    # looped = []
    # g = 0
    # for i in range(k):
    #     g = goto[index]
    #     # print(goto)
    #     if a[g-1] in goto:
    #         # print("goto!", a[g-1], goto)
    #         break
    #     goto.append(a[g-1])
    #     index += 1
    #
    # s = goto.index(a[g-1])
    # looped = goto[s:]
    #
    # if k % len(looped) == 0:
    #     print(goto[-1])
    # else:
    #     k -= len(goto) - len(looped)
    #     amari = k % len(looped)
    #     print(looped[amari-1])

#6 5 2 5 3 2
#1 2 3 4 5 6

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


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


if __name__ == "__main__":
    main()


Measured memory_bytes: 110604
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<tuple>
#include<algorithm>
#include<stack>
using namespace std;

int main(void)
{
	int K, N;
	cin >> N >> K;
	//cout << N << " " << K << endl;
	
	vector<vector<long long>> v(N, vector<long long>()); 
	for(int i=0; i<N; i++){
		long long t, d;
		cin >> t >> d;

		t--;
		v[t].push_back(d);
	}

	typedef tuple<long long, long long, bool> State;
	vector<State> vs;
	for(int i=0; i<N; i++){
		if(v[i].size() == 0)
			continue;

		sort(v[i].rbegin(), v[i].rend());
		//cout << i << " : ";
		//for(int j=0; j<v[i].size(); j++)
		//	cout << v[i][j] << " ";
		//cout << endl;

		vs.push_back(make_tuple(v[i][0], i, true));
		for(int j=1; j<v[i].size(); j++)
			vs.push_back(make_tuple(v[i][j], i, false));
	}
	sort(vs.rbegin(), vs.rend());
	//for(int i=0; i<N; i++){
	//	cout << get<0>(vs[i]) << " ";
	//}
	//cout << endl;

	long long del, type;
	del = type = 0;
	stack<long long> stcDel;
	for(int i=0; i<K; i++){
		long long d, t, f;
		tie(d, t, f) = vs[i];

		del += d;
		if(f == true)
			type++;
		else
			stcDel.push(d);
	}

	long long ans = del + type*type;
	for(int i=K; i<N; i++){
		if(stcDel.empty() == true)
			break;

		long long d, t, f;
		tie(d, t, f) = vs[i];

		if(f == false)
			continue;

		del += d;
		type++;

		del -= stcDel.top();
		stcDel.pop();

		ans = max(ans, del+type*type);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 9972
#include<stdio.h>
int main(void)
{
    int H,W,h,w;
    int s1,s2;
  
    scanf("%d%d",&H,&W);
    scanf("%d%d",&h,&w);
  
    s1=H*W-(W*h);
    s2=s1-(H-h)*w;
  
    printf("%d\n",s2);
   
    return 0;
}
  

Measured memory_bytes: 1736
n,p = map(int, input().split())
s = input()

if p%2 == 0:
    ans = 0
    for i, si in enumerate(s):
        if int(si)%2 == 0:
            ans += (i+1)
    print(ans)
    exit()

if p%5 == 0:
    ans = 0
    for i, si in enumerate(s):
        if int(si)%5 == 0:
            ans += (i+1)
    print(ans)
    exit()


prem = [0]*p
prem[0] = 1
curr_rem = 0
ans = 0
s = s[::-1]
for i,si in enumerate(s):
    sii = int(si)
    curr_rem = (sii*pow(10,i,p)+curr_rem)%p
    ans += prem[curr_rem]
    prem[curr_rem] += 1

print(ans)
    

Measured memory_bytes: 74272
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

map<pair<int, int>, char> mp;

i64 sum;
vi arms;

void printvec(vi& x, int size = 0) {
    if (x.size() == 0) {
        cout << endl;
        return;
    }
    cout << x.front();
    for (int i = 1; i < (size == 0 ? x.size() : size); i++) {
        cout << " " << x[i];
    }
    cout << endl;
}

vi make_use(i64 x) {
    vi ret(arms.size());
    i64 p = (x + sum) / 2;
    for (int i = arms.size() - 1; i >= 0; i--) {
        if (p >= arms[i]) {
            ret[i] = 1;
            p -= arms[i];
        }
    }
    assert(p == 0);
    return ret;
}

string make_string(i64 x, i64 y) {
    i64 xx = x - y, yy = x + y;
    string ret = "";

    vi usex = make_use(xx), usey = make_use(yy);
    for (int i = 0; i < arms.size(); i++) {
        ret += mp[make_pair(usex[i], usey[i])];
    }

    return ret;
}

int main() {
    int n;
    cin >> n;
    vi xs, ys;
    int ok = -1;
    for (int i = 0; i < n; i++) {
        i64 x, y;
        cin >> x >> y;
        if (ok == -1) {
            ok = ((x + y) % 2 + 2) % 2;
        } else {
            if (ok != ((x + y) % 2 + 2) % 2) {
                cout << -1 << endl;
                return 0;
            }
        }
        xs.push_back(x);
        ys.push_back(y);
    }

    for (i64 i = 1; i < i64(1) << 35; i <<= 1) {
        sum += i;
        arms.push_back(i);
    }

    if (ok == 0) {
        // 最初にD
        for (int i = 0; i < n; i++) {
            ys[i]++;
        }
        cout << 1 + arms.size() << endl;
        cout << 1 << " ";
    } else {
        cout << arms.size() << endl;
    }
    printvec(arms);
    
    mp[make_pair(1, 1)] = 'R';
    mp[make_pair(0, 0)] = 'L';
    mp[make_pair(0, 1)] = 'U';
    mp[make_pair(1, 0)] = 'D';
    
    for (int i = 0; i < n; i++) {
        if (ok == 0) {
            cout << "D";
        }
        cout << make_string(xs[i], ys[i]) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
static const int N = 2001;
using namespace std;
struct data{
  int correctcnt,time,tnum;
  bool operator<(const data& right)const{
    if(correctcnt!=right.correctcnt) return correctcnt>right.correctcnt;
    if(time!=right.time) return time<right.time;
    return tnum>right.tnum;
  }
};
int main(){
  int M,T,P,R,i,j,m[N],t[N],p[N],in_j[N],incorrectcnt;
  while(1){
    cin >> M >> T >> P >> R;
    vector<data> V(T);
    if(M==0&&T==0&&P==0&&R==0) break;
    for(i=0;i<R;i++){
      cin >> m[i] >> t[i] >> p[i] >> in_j[i];
    }
    for(i=0;i<T;i++){
      V[i].tnum=i+1;
      V[i].correctcnt=V[i].time=0;
    }
    for(i=0;i<R;i++){
      if(in_j[i]==0){
	V[t[i]-1].correctcnt++;
	incorrectcnt=0;
	for(j=0;j<i;j++){
	  if(t[i]==t[j]&&p[i]==p[j]) incorrectcnt++;
	}
	V[t[i]-1].time+=m[i]+20*incorrectcnt;
      }
    }
    sort(V.begin(),V.end());
    for(i=0;i<T-1;i++){
      cout << V[i].tnum;
      if(V[i].correctcnt==V[i+1].correctcnt&&V[i].time==V[i+1].time) cout << '=';
      else cout << ',';
    }
    cout << V[T-1].tnum << endl;
  }  
  return 0;
}

Measured memory_bytes: 1252
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,sum=0;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      sum+=a[i]*a[j];
    }
  }
  cout<<sum;
}


Measured memory_bytes: 256
# Atcode Frog B
import numpy as np
n, k = map(int, input().strip().split())
a = np.array(list(map(int, input().strip().split())))
dp = np.zeros(n, dtype=int)
dp[0]=0
for i in range(n):
	if i < k:
		dp[i]=abs(a[i]-a[0])
	else:
		dp[i] = min(abs(a[i-k:i]-a[i])+dp[i-k:i])
print(dp[-1])

Measured memory_bytes: 22908
#include <stdio.h>
#define REP(i,a,b) for (i=(a); i<(b); ++i)
#define rep(i,n) REP(i,0,n)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define EPS 1e-12
double a[101][101];
double memo[101][101][101];
int b[101];

double solve(int n, int m, int k, int p)
{
    double res;
    int i, j;
    if (m == 1) return 1;
    if (memo[p][m][k] > 0) return memo[p][m][k];
    res = 0;
    rep(i, n) res = MAX(res, solve(n, m-1, p, i) * a[p][i]);
    return memo[p][m][k] = res;
}

int main(void)
{
    int n, m, i, j, k;
    double res;
    while (scanf("%d%d",&n,&m),n|m) {
        rep(i, n) b[i] = 0;
        rep(i, 101) rep(j, 101) rep(k, 101) memo[i][j][k] = 0;
        rep(i, n) rep(j, n) {
            scanf("%lf", &a[i][j]);
            if (a[i][b[i]] < a[i][j]) b[i] = j;
        }
        res = 0;
        rep(i, n) rep(j, n) res = MAX(res, solve(n, m, i, j));
        printf("%.2f\n", res);
    }

    return 0;
}

Measured memory_bytes: 8596
X, K, D = map(int, input().split())
X = abs(X)
tmp_k = X // D

if K - tmp_k < 0:
    ans = abs(X - (D * K))
else:
    tmp = (K- tmp_k) % 2
    if tmp == 0:
        ans = abs(X - (D * tmp_k))
    else:
        ans = abs(X - D * (tmp_k + 1))
        
print(ans)

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

typedef long long ll;

const int N = 1e6 + 10;

ll a[N];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector <int> v;
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		v.push_back(s[i] - 'a');
	}
	v.resize(unique(v.begin(), v.end()) - v.begin());
	cout << v.size() << "\n";
}

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

int main() {
	// your code goes here
	int a, b, c, sum1, sum2;
	
	cin >> a >> b >> c;
	
	sum1 = min(a, min(b, c));
	if(sum1 == a) sum2 = min(b, c);
	else if(sum1 == b) sum2 = min(a, c);
	else sum2 = min(a, b);
	
	cout << sum1 + sum2 << endl;
	
	return 0;
}

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

int main() {
    int N, cnt = 0;
    string S;
    cin >> N >> S;

    rep(i, N) {
        if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
            cnt++;
        }
    }

    cout << cnt << endl;
}

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

ll pw(ll a,ll b){
    if(b==0) return 1;
    if(b%2==1) return pw(a,b-1)*a;
    ll temp=pw(a,b/2);
    return temp*temp;
}

ll kosuu(ll n,ll k){
    if(k%2==1) return 0;
    ll count=0;
    for(int i=1;i<=n;i++){
        if(i%k==k/2) count++;
    }
    return count;
}

ll kumi(ll n, ll k){
    return pw(n/k,3)+pw(kosuu(n,k),3);
}
int main(void){
    ll n,k;
    cin>>n>>k;
    cout<<kumi(n,k)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ll((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> V;
typedef vector< vector<ll> > VV;
typedef pair<ll, ll> P;
typedef map<string, ll> M;
typedef unordered_map<ll, ll> HM;
typedef set<ll> S;
typedef multiset<ll> MS;
typedef queue<ll> Q;

int main(){
    ll n,m; cin>>n>>m;
    ll g[n][n];
    for(ll i=0; i<m; i++){
        ll a,b; cin>>a>>b;
        a--; b--;
        g[a][b] = 1;
        g[b][a] = 1;
    }
    ll path[n];
    for(ll i=0; i<n; i++)
        path[i] = i;
    ll ans = 0;
    do{
        if(path[0] != 0)
            continue;
        bool flag = true;
        for(ll i=1; i<n; i++){
            if(!(g[path[i-1]][path[i]]==1))
                flag = false;
        }
        if(flag)
            ans++;
    }while(next_permutation(path, path+n));
    OUT(ans);
}

Measured memory_bytes: 256
N = int(input())
x = []
y = []
SUM = 0
for loop in range(N):
    tmp_x, tmp_y = map(int,input().split())
    x.append(tmp_x)
    y.append(tmp_y)
for i in range(N-1):
    for j in range(i+1,N):
        SUM += ((x[j]-x[i])**2+(y[j]-y[i])**2)**0.5
ans = 2*SUM/N
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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


int main() {

  long  N,K;

  std::cin >> N;
  std::cin >> K;
  
  if(K%N==0){
    cout <<K+N <<endl;
  }else{
    cout <<K-N <<endl;
  }
  return 0;
   
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


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

    int n = s.length();

    string ans = "";
    if (n == 26) {
        string tmp = s;
        next_permutation(all(tmp));
        rep(i, 26) {
            if (s[i] != tmp[i]) {
                ans = tmp.substr(0, i+1);
                break;
            }
        }
        if (ans == "a") ans = "-1";
    }
    else {
        vbool c(26, false);
        rep(i, n) c[s[i]-'a'] = true;
        ans = s;
        rep(i, 26) {
            if (!c[i]) {
                ans += i+'a';
                break;
            }
        }
    }

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

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    
    for (i in 1..9) {
        for (j in 1..9) {
            if (i * j == N) {
                println("Yes")
                return
            }
        }
    }
    
    println("No")
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 31640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n+1);
	vector<int> b(n+1);
	rep(i,n){
		cin >> a.at(i+1);
		a.at(i+1)+=a.at(i);
	}
	rep(i,n){
		cin >> b.at(i+1);
		b.at(i+1)+=b.at(i);
	}
	int ans=0;
	for(int i=1;i<=n;++i){
		ans=max(ans,a.at(i)+(b.at(n)-b.at(i-1)));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
        public static void main(String[] args){
                Scanner scanner=new Scanner(System.in);
                int a=scanner.nextInt();
                int b=scanner.nextInt();
                boolean b1=a%3==0;
                boolean b2=b%3==0;
                boolean b3=(a+b)%3==0;
                if(b1||b2||b3){
                        System.out.println("Possible");
                }else{
                        System.out.println("Impossible");
                }
        }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
using namespace std;

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

const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl
int sum[26],sum2[26];
int main() {
    //freopen(".in", "r", stdin);
    for(int i=0;i<26;i++) sum[i]=1000;
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        string str;
        cin>>str;
        for(int j=0;j<26;j++) sum2[j]=0;
        for(int j=0;j<str.length();j++)
        {
            sum2[str[j]-'a']++;
        }
        for(int j=0;j<26;j++) sum[j]=min(sum[j],sum2[j]);
    }
    for(int i=0;i<26;i++) for(int j=0;j<sum[i];j++) printf("%c",('a'+i));
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int a,A[50];
int solve(int,int);

int main(){
  int i,b,k,x;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&k);
    x=solve(0,k);
    if(x){
      printf("yes\n");
    }
      else printf("no\n");
  }
  return 0;
}

int solve(int i,int j)
{
  if(j==0) return 1;
  if(i>=a) return 0;
  int kekka = solve(i+1,j) || solve(i+1,j-A[i]);
  return kekka;
}





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

using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());
// map<int,int> mp;

int main() {
  int s;
  cin >> s;
  cout << s*s << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define fst first
#define snd second
using ll = long long;
using I = pair<int, int>;

int main() {
  int N, C;
  while (cin >> N >> C) {
    vector<vector<int>> D(C, vector<int>(C));
    for (int i = 0; i < C; i++) {
      for (int j = 0; j < C; j++) {
        cin >> D[i][j];
      }
    }
    vector<vector<int>> c(N, vector<int>(N));
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        cin >> c[i][j];
        --c[i][j];
      }
    }
    vector<vector<int>> cost(C, vector<int>(3, 0));
    for (int color = 0; color < C; color++) {
      for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
          cost[color][(i + j) % 3] += D[c[i][j]][color];
        }
      }
    }
    int best = 1ll << 30;
    for (int x = 0; x < C; x++) {
      for (int y = 0; y < C; y++) {
        for (int z = 0; z < C; z++) {
          if (x == y || x == z || y == z) continue;
          best = min(best, cost[x][0] + cost[y][1] + cost[z][2]);
        }
      }
    }
    cout << best << endl;
  }
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    string s[502];
    for(int i = 0; i < n; i++) cin >> s[i];
    int c[502]{0};
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(s[i][j] == '#') c[i]++;
        }
    }
    bool f = false;
    for(int i = 0; i < n; i++){
        if(c[i]) f = true;
    }
    if(!f){
        cout << -1 << endl;
        return 0;
    }
    int l = 0;
    for(int i = 0; i < n; i++) l = max(l, c[i] - 1);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(s[i][j] == '#') l = max(l, c[j]);
        }
    }
    for(int j = 0; j < n; j++){
        bool g = true;
        for(int i = 0; i < n; i++){
            if(s[i][j] == '.') g = false;
        }
        if(g) l++;
    }
    cout << n * 2 - l << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

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

const int INF = 1001001001;
const ll MOD = 1e9 + 7;

ll fact(ll n) {
    if (n == 0) return 1;
    if (n == 1) return 1;
    return ((n % MOD) * (fact(n - 1) % MOD) % MOD);
}

int main(){
    ll n, m;
    cin >> n >> m;
    if (n == m) cout << ((2 * fact(n) * fact(m)) % MOD) << endl;
    else if ( abs(n - m) == 1) cout << ((fact(n) * fact(m)) % MOD) << endl;
    else cout << (0) << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN = 55;
ll a[MAXN];
ll r[MAXN];

int main() {
	int N;
	scanf("%d", &N);
	for(int i = 0; i < N; i++)
		scanf("%lld", &a[i]);
	ll ans = 0;
	ll sum = 0;
	while(1) {
		for(int i = 0; i < N; i++) {
			sum -= r[i];
			a[i] += sum;
			r[i] = (a[i] - N) / N + 1;
			if(a[i] < N) r[i] = 0;
			a[i] -= N * r[i];
			ans += r[i];
			sum += r[i];
			debug("a[%d], r: %lld, %lld (%lld)\n", i, a[i], r[i], sum);
		}
		if(sum > 0) continue;
		bool fin = true;
		for(int i = 0; i < N; i++)
			if(a[i] >= N)
				fin = false;
		if(fin) break;
	}
	cout << ans << endl;
	return 0;
}


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

bool check (string s){
  int n = s.length();
  if (n%2==1){
    return false;
  }
  else {
    return (s.substr(0,n/2-1)==s.substr(n/2));
  }
}

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

  vector<int> vec(3*n+3);
  vec.at(0) = 0;
  vec.at(1) = 0;
  vec.at(2) = 0;
  for (int i=3; i<3*n+3; i++){
    cin >> vec.at(i);
  }

  for (int i=0; i<n; i+=3){
    int dt, dx, dy;
    dt = abs(vec.at(i+3)-vec.at(i));
    dx = abs(vec.at(i+4)-vec.at(i+1));
    dy = abs(vec.at(i+5)-vec.at(i+2));
    if (dt>=dx+dy && (dx+dy)%2==dt%2){
      continue;
    }
    else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
using namespace std;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;
// spring s; cin >> s;
// cout << res << endl;
// --------write my code!!!!!----------//

// I'm trying to ~~~
int main(){
    string s; cin>>s;
    bool flag=1;
    if(s[0]+s[1]+s[2]!=294) flag=0;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}



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

int main() {
  int w,h,x,y;
  cin >> w >> h >> x >> y;
  printf("%lf %d\n", double(w)*double(h)/2, x + x == w && y + y == h);
}


Measured memory_bytes: 3724
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

void divide(const string& s, string& s1, string& s2)
{
    int n = s.size();
    int brackets = 0;
    for(int i=1; ; ++i){
        if(s[i] == '(')
            ++ brackets;
        else if(s[i] == ')')
            -- brackets;
        else if(brackets == 0){
            s1 = s.substr(1, i-1);
            s2 = s.substr(i+1, n-i-2);
            return;
        }
    }
}

string solve(const string& ope, const string& s, const string& t)
{
    if(s == "" || t == ""){
        if(ope == "i")
            return "";
        else
            return max(s, t);
    }

    string s1, s2, t1, t2;
    divide(s, s1, s2);
    divide(t, t1, t2);

    return '(' + solve(ope, s1, t1) + ',' + solve(ope, s2, t2) + ')';
}

int main()
{
    for(;;){
        string ope, s, t;
        if(!(cin >> ope >> s >> t))
            return 0;

        cout << solve(ope, s, t) << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,w,n;
    cin>>h>>w>>n;
    map<pair<int,int>,int> D;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        for(int y=0;y<3;y++){
            for(int x=0;x<3;x++){
                if(a-y<0||b-x<0||a-y>=h-2||b-x>=w-2)continue;
                D[make_pair(a-y,b-x)]++;
            }
        }
    }
    int res[10];
    int s=(h-2)*(w-2);
    for(int i=0;i<10;i++)res[i]=0;
    for(auto it:D){
        res[it.second]++;
        s--;
    }
    res[0]=s;
    for(int i=0;i<10;i++){
        cout<<res[i]<<endl;
    }
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:
const int limit = 3010;
bool sugar[limit];
bool water[limit];

int main(void){
	int a,b,c,d,e,f;
	cin >> a >> b >> c >> d >> e >> f;

	sugar[0] = true;
	rep(i,limit){
		if(i-c >= 0 and sugar[i-c]) sugar[i]=true;
		if(i-d >= 0 and sugar[i-d]) sugar[i]=true;
	}

	water[0] = true;
	rep(i,limit){
		if(i-100*a >= 0 and water[i-100*a]) water[i]=true;
		if(i-100*b >= 0 and water[i-100*b]) water[i]=true;
	}

	ll num = 0, den = 100 * a;

	for(int w = 100*a; w <= f; w += 100){
		if(water[w]==false) continue;
		for(int i = 0; i <= w/100 * e;++i){
			if(sugar[i] and i+w <=f){
				ll cnum = i, cden = i + w;
				if(num*cden < cnum*den) num = cnum, den = cden;
			}
		}
	}

	cout << den << " " << num << endl;
	
	return 0;
}

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

int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  vector<int> a(n);
  int e = 0,w=0,i;
  for(i = 0;i<n;i++){
    if(s[i] == 'E'){
      e++;
    }else{
      w++;
    }
  }
  int lw = 0,re = e,ans;
  if(s[0] == 'E'){
      re--;
    }
  ans = re;
  for(i = 1;i<n;i++){
    if(s[i] == 'E'){
      re--;
    }
    if(s[i-1] == 'W'){
      lw++;
    }
    if(lw + re < ans){
      ans = lw + re; 
    }
  }
  cout << ans << endl;
}

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

long long MOD = 998244353;
int main()
{
    int n, k; cin >> n >> k;
    vector<pair<int, int> > seg;
    for (int i = 0; i < k; i++)
    {
        int l, r; cin >> l >> r;
        seg.push_back({l, r});
    }
    vector<long long> ans(n+1), sum(n+1);
    ans[1] = 1; sum[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        for (int j = 0; j < k; j++)
        {
            ans[i] += (MOD + sum[max(0, i-seg[j].first)] - sum[max(0, i-seg[j].second - 1)]) % MOD;
            ans[i] %= MOD;
        }
        sum[i] = sum[i-1] + ans[i]; sum[i] %= MOD;
    }
    cout << ans[n] << '\n';
}


Measured memory_bytes: 6432
#include <iostream>

using namespace std;

int main()
{
    int n, m, l;
    int A[100][100] = {};
    int B[100][100] = {};
    cin >> n >> m >> l;
    // read matrix A
    for (int row = 0; row < n; ++row)
    {
        for (int col = 0; col < m; ++col)
        {
            cin >> A[row][col];
        }
    }

    // read matrix B
    for (int row = 0; row < m; ++row)
    {
        for (int col = 0; col < l; ++col)
        {
            cin >> B[row][col];
        }
    }

    // calc prodct AB
    for (int row = 0; row < n; ++row)
    {
        for (int col = 0; col < l; ++col)
        {
            long long val = 0;
            for (int i = 0; i < m; ++i)
            {
                val += A[row][i] * B[i][col];
            }
            cout << (col == 0 ? "" : " ") << val;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3184
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

int main() {
	int d;
	double e,min = -1.0;
	for (;;) {
		cin >> d >> e;
		if (d == 0 && e == 0) break;

		for (int i = 0; i <= d; i++) {
			if (min == -1)  min = abs(e-sqrt(i*i + (d - i)*(d - i)));
			else if (min > abs(e-sqrt(i*i + (d - i)*(d - i)))) min = abs(e-sqrt(i*i + (d - i)*(d - i)));

		}

		cout << min << endl;
		min = -1;



	}
}

Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
bool kaibun(string x) {
  int count = 0;
  for (int i = 0; i < x.size()/2 + x.size()%2; i++) {
    if (x.at(i) != x.at(x.size() - i - 1))
      count++;
  }
  if (count == 0)
    return true;
  else
    return false;
    
  
}  
int main() {
  string S,T,U;
  cin >> S;
  
  T = S;
  for (int i = 0; i < (S.size() + 1)/2; i++)
    T.pop_back();
  U = S;
  reverse(U.begin(),U.end());
  for (int j = 0; j < (S.size() + 1)/2; j++)
    U.pop_back();
  if (kaibun(S) && kaibun(T) && kaibun(U))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
    
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	int c=0, d=0, e=0;
	c=a-b;
	d=a*b;
	e=a+b;
	if(max(c, d)>max(d, e))
	{
		cout << max(c, d) <<endl;
		return 0;
	}
	else
	{
		cout << max(d, e) <<endl;
		return 0;
	}
	cout << d <<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;

int a,b,x;

int main()
{
	scanf("%d%d%d",&x,&a,&b);
	if(abs(x - a) > abs(x - b))printf("B\n");
	else printf("A\n");
}

Measured memory_bytes: 128
#include <stdio.h>
#define STR_LENGTH (6)
int main(int argc, char* argv[])
{
	//ABC160 B
	int x;
	int u = 0;
	// X 円
	// なお、利用できる硬貨は 500円玉、100円玉、50円玉、10円玉、5円玉、1円玉の6種類とします。
	// 500円優先
	// 次に5円優先
	scanf("%d", &x);

	for (; x >= 500; x -= 500) {
		u += 1000;
	}

	for (; x >= 5; x -= 5) {
		u += 5;
	}

	printf("%d", u);

	return 0;
}

Measured memory_bytes: 128
import sys

def preorder_tree_walk(nid, route):
    left = nodes[nid][1]
    right = nodes[nid][2]
    route.append(nid)
    if left != -1: preorder_tree_walk(left, route)
    if right != -1: preorder_tree_walk(right, route)
    return route

def inorder_tree_walk(nid, route):
    left = nodes[nid][1]
    right = nodes[nid][2]
    if left != -1: inorder_tree_walk(left, route)
    route.append(nid)
    if right != -1: inorder_tree_walk(right, route)
    return route

def postorder_tree_walk(nid, route):
    left = nodes[nid][1]
    right = nodes[nid][2]
    if left != -1: postorder_tree_walk(left, route)
    if right != -1: postorder_tree_walk(right, route)
    route.append(nid)
    return route

n = int(input())
nodes = [[-1, -1, -1] for _ in range(n)]

for _ in range(n):
    nid, left, right = list(map(int, sys.stdin.readline().split()))
    nodes[nid][1] = left
    nodes[nid][2] = right

    if left != -1: nodes[left][0] = nid
    if right != -1: nodes[right][0] = nid

for nid, node in enumerate(nodes):
    root_nid = nid
    if node[0] == -1: break

preorder_route = preorder_tree_walk(root_nid, [])
inorder_route = inorder_tree_walk(root_nid, [])
postorder_route = postorder_tree_walk(root_nid, [])

print('Preorder')
print('', *preorder_route)
print('Inorder')
print('', *inorder_route)
print('Postorder')
print('', *postorder_route)


Measured memory_bytes: 5620
using System;
using System.Linq;


namespace AGC022
{
    class A
    {
        static void Main(string[] args)
        {
            //input
            string S = Console.ReadLine();

            //文字用の配列と、Sで使われている文字のカウント
            int[] C = new int[26];
            for (int i = 0; i < S.Length; i++)
            {
                C[S[i] - 'a']++;
            }

            int sum = C.Sum();

            //|S| < 26のとき
            ////使われていない文字で、一番最小のものを最後につける
            if (sum < 26)
            {
                for (int i = 0; i < C.Length; i++)
                {
                    if (C[i] == 0)
                    {
                        Console.WriteLine(S + (char)(i + (int)'a'));
                        return;
                    }
                }
            }
            else
            {
                int num = 0;
                for (int i = S.Length - 1; 0 < i; i--)
                {
                    if (S[i] > S[i - 1]) { num = i; break; }
                    if (i == 1) { Console.WriteLine(-1); return; }
                }

                int c = int.MaxValue;
                string s1 = "";
                for (int i = S.Length - 1; num <= i; i--)
                {
                    int temp = (int)S[num - 1] - (int)S[i];
                    int temp2 = Math.Abs(temp);
                    if (temp < 0 && temp2 < c)
                    {
                        c = temp;
                        s1 = S[i].ToString();
                    }
                }

                string sub = S.Substring(0, num - 1) + s1;
                Console.WriteLine(sub);
            }
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define fi first
#define se second
using ll = long long;
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int ans = 0;
    int m, d;
    cin >> m >> d;
    for(int i = 20; i <= d; ++i) {
        if(i % 10 < 2) continue;
        ans += (i / 10) * (i % 10) <= m;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256