akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

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

  constexpr ll MAX=1e5+10;

  std::vector<ll> cnt(MAX,0);

  ll n;
  std::cin>>n;

  ll sum=0;

  rep(i,0,n){
    ll a;
    std::cin>>a;
    sum+=a;
    cnt[a]++;
  }

  ll q;
  std::cin>>q;

  while(q--){
    ll b,c;
    std::cin>>b>>c;

    sum-=b*cnt[b];
    sum+=c*cnt[b];
    cnt[c]+=cnt[b];
    cnt[b]=0;
    std::cout<<sum<<"\n";
  }

  return 0;
}

Measured memory_bytes: 3928
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)



int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[2] * 10 + a[1] + a[0] << endl;
	getchar();
	getchar();
	return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;

namespace Tree
{
    class Rooted_Trees
    {
        struct Node
        {
            public int id;
            public int parent;
            public int depth;
            public int[] childlen;
            public string type;
        }
        static void Main(string[] args)
        {
            int size = int.Parse(Console.ReadLine());
            var nodes = new Node[size];

            for (int i = 0; i < size; i++)
                nodes[i].parent = -1;

            for (int i = 0; i < size; i++)
            {
                var token = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                var id = token[0];
                nodes[id].id = id;

                var k = token[1];
                if (k == 0) nodes[id].type = "leaf";
                else nodes[id].type = "internal node";
                nodes[id].childlen = new int[k];
                for (int j = 0; j < k; j++)
                {
                    nodes[id].childlen[j] = token[2 + j];
                    nodes[token[2 + j]].parent = id;
                }
            }

            for (int i = 0; i < size; i++)
                if (nodes[i].parent == -1)
                {
                    nodes[i].type = "root";
                    SetDepth(nodes, i, 0);
                    break;
                }

            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            for (int i = 0; i < size; i++)
            {
                Console.Write("node ");
                Console.Write(nodes[i].id);
                Console.Write(": parent = ");
                Console.Write(nodes[i].parent);
                Console.Write(", depth = ");
                Console.Write(nodes[i].depth);
                Console.Write(", ");
                Console.Write(nodes[i].type);
                Console.Write(", [");
                Console.Write(string.Join(", ", Array.ConvertAll(nodes[i].childlen, n => n.ToString())));
                Console.WriteLine("]");
            }

            Console.Out.Flush();
        }

        static void SetDepth(Node[] nodes, int id, int depth)
        {
            nodes[id].depth = depth;
            for (int i = 0; i < nodes[id].childlen.Length; i++)
                SetDepth(nodes, nodes[id].childlen[i], depth + 1);
        }
    }
}

Measured memory_bytes: 22916
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a;
    int count = 0;

    for(int i=0; i<n; i++){
      a = sc.nextInt();
      if(a==i+1){
        count += 1;
        }
      }
    if(n - count>=3){
      System.out.println("NO");
    }else{
      System.out.println("YES");
    }
  }
}


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

int main() {
    int N,M;
    cin >> N >> M;
    vector<int64_t> H(N);
    for (int i=0;i<N;i++) {
        cin >> H.at(i);
    }
    vector<int> A(M),B(M);
    
    for (int j=0;j<M;j++) {
        cin >> A.at(j) >> B.at(j);
    }
    
    vector<bool> higher(N,true);
    for(int j=0;j<M;j++) {
        if (H.at(A.at(j)-1)>=H.at(B.at(j)-1)) {
            higher.at(B.at(j)-1)=false;
        }
        if (H.at(A.at(j)-1)<=H.at(B.at(j)-1)) {
            higher.at(A.at(j)-1)=false;
        }
    }

    int count=0;
    for(int i=0;i<N;i++) {
        if (higher.at(i)) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 4844
//重複OKのナップサック問題

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


int main(){
  long N,W;
  long v[101],w[101];
  cin>>N>>W;
  for(long i=0;i<N;i++)cin>>v[i]>>w[i];
  
  long dp[101][10001]={};
  for(long i=1;i<=N;i++){
    for(long j=0;j<=W;j++)
      if(j-w[i-1]>=0)dp[i][j]=max(dp[i-1][j],dp[i][j-w[i-1]]+v[i-1]);
      else dp[i][j]=dp[i-1][j];
  }
  cout<<dp[N][W]<<endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> dp(N, vector<int>(3, 0)), abc(N, vector<int>(3, 0));
  for (int i=0;i<N;i++){
    for (int j=0;j<3;j++){
      cin >> abc[i][j];
      if (i==0){
        dp[i][j] = abc[i][j];
      }
    }
    
    if (i > 0){
      dp[i][0] = max(dp[i-1][1] + abc[i][0], dp[i-1][2] + abc[i][0]);
      dp[i][1] = max(dp[i-1][0] + abc[i][1], dp[i-1][2] + abc[i][1]);
      dp[i][2] = max(dp[i-1][0] + abc[i][2], dp[i-1][1] + abc[i][2]);
    }
  }
  cout << max({dp[N-1][0],dp[N-1][1],dp[N-1][2]}) << endl;
}

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

int triangles(int n, vector <int> l){
  sort(l.begin(), l.end());
  int s= 0;
  for (int i = 0; i < n; i++){
    int m = i + 2;
    for (int j = i+1; j < n; j++){
      while (m < n && l[i] + l[j] > l[m]) 
        ++m;  
        if (m > j) 
          s += m - j - 1;
    }
  }
  return s;
}

int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector <int> l (n);
  for (int i = 0 ; i < n; i++)
    cin >> l[i];
  cout << triangles(n, l) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int a,b;
char op;
do{
scanf("%d %[^ ] %d",&a,&op,&b);
if(0<=a&&a<=20000&&0<=b&&b<=20000){
if(op=='+')
printf("%d\n",a+b);
else if(op=='-')
printf("%d\n",a-b);
else if(op=='*')
printf("%d\n",a*b);
else if(op=='/'&&b!=0)
printf("%d\n",a/b);
}
}while(op!='?');
return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	double n,m,d;
	cin>>n>>m>>d;
	if(d==0)
		printf("%.10f\n",1/n*(m-1));
	else
		printf("%.10f\n",2.0*(n-d)/n/n*(m-1));
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define For(i,n) for(int i=0;i<n;i++)
#define Fre(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define READ freopen("in.txt", "r", stdin)
#define WRITE freopen("out.txt", "w", stdout)
#define sz size()
#define number_of_digit(n) __builtin_ffs(n);
#define ll long long
#define T int
#define ld long double
inline void print(T n)
{
	if (n == 0)
	{
		putchar('0');
		putchar('\n');
	}
	else if (n == -1)
	{
		putchar('-');
		putchar('1');
		putchar('\n');
	}
	else
	{
		char buf[11];
		buf[10] = '\n';
		int i = 9;
		while (n)
		{
			buf[i--] = n % 10 + '0';
			n /= 10;
		}
		while (buf[i] != '\n')
			putchar(buf[++i]);
	}
}
int read()
{
       int cc = getc(stdin);
       for (;cc < '0' || cc > '9';)  cc = getc(stdin);
       int ret = 0;
       for (;cc >= '0' && cc <= '9';)
       {
          ret = ret * 10 + cc - '0';
          cc = getc(stdin);
       }
      return ret;
}
ll power(ll num,ll g)
{
	if(g==0)return 1;

	if(g%2==1)return (num*power((num*num)%mod,g/2))%mod;
	return power((num*num)%mod,g/2);
}
bool visit[1000005];
int main()
{
	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  	cout.tie(NULL);

  	int n;
  	cin>>n;
  	int a[n],b[n],c[n],d[n][3];
  	For(i,n)cin>>a[i]>>b[i]>>c[i];
  	d[0][0]=a[0];
  	d[0][1]=b[0];
  	d[0][2]=c[0];
  	for(int i=1;i<n;i++)
  	{
  		d[i][0]=max(d[i-1][1],d[i-1][2])+a[i];
  		d[i][1]=max(d[i-1][0],d[i-1][2])+b[i];
  		d[i][2]=max(d[i-1][1],d[i-1][0])+c[i];
  	}
  	cout<<max(d[n-1][0],max(d[n-1][1],d[n-1][2]))<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 2e5 + 7;
int n, sz;
int a[N], b[N];
bool check(int mid) {
	rep(i, 1, sz) b[i] = a[i] <= mid;
	for(int i = 1; i + 2 <= sz; ++i) {
		if(b[i + 1] == b[i]) continue;
		if(b[i + 2] == b[i + 1]) continue;
		int j = i;
		while(j + 1 <= sz && b[j + 1] ^ b[j]) ++j;
		if(j - i + 1 & 1) {
			rep(k, i + 1, j - 1) b[k] = b[i];
		}else {
			rep(k, i + 1, j - 1) b[k] = k - i < j - k ? b[i] : b[j];
		}
		i = j;
	}
	return b[n];
}
int main() {
#ifdef fwat
#endif
	n = gi(), sz = n + n - 1;
	rep(i, 1, sz) a[i] = gi();
	int l = 1, r = sz, ret = 0;
	while(l <= r) {
		int mid = l + r >> 1;
		if(check(mid)) ret = mid, r = mid - 1;
		else l = mid + 1;
	}
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int calc(char x,int r,int s,int p){
  if(x=='r')return p;
  if(x=='s')return r;
  if(x=='p')return s;
}
int main(void){
  int n,k,sum=0;
  scanf("%d%d",&n,&k);
  int r,s,p;
  scanf("%d%d%d",&r,&s,&p);
  char t[n];
  scanf("%s",&t);
  int flag[k],count=0;
  for(int i=0;i<k;i++){
flag[i]=0;
  }
  for(int i=0;i<n;i++){
                       if(count==k)count=0;
    if(flag[count]==0||flag[count]==1&&t[i]!=t[i-k]){
      sum+=calc(t[i],r,s,p);
      flag[count]=1;
    }
    else flag[count]=0;
    count++;
    }
      
	printf("%d",sum);
                       return 0;
                      }

Measured memory_bytes: 640
#include <iostream>
#include <stdlib.h>
using namespace std;
#define thefor(i,end) for (i=0;i<=end;i++)
int main()
{    
	int n,a=0,b=0,c=0,d=0,end=9,con=0;
	while(cin>>n)
	{
		con=0;
		thefor(a,end)
		{
			thefor(b,end)
			{
				thefor(c,end)
				{
					thefor(d,end)
					{
						if(a+b+c+d==n)con++;
					}
				}
			}
		}
		cout<<con<<endl;
	}	
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
typedef long long lint;
using namespace std;

// input N


int main()
{

	int N,M,C;
	cin >> N >> M >> C;
	vector<int> B(M) ;
	for (int i = 0; i < M; i++) cin >> B[i];
	vector<vector<int> > A (N, vector<int>(M,0));
	for (int i = 0; i < N; i++)
		for (int j = 0; j < M; j++) cin>>A[i][j];
	

	int ans = 0;
	for (int i = 0; i < N; i++) {
		lint tmp = C;
		for (int j = 0; j < M; j++){
			tmp += A[i][j] * B[j];
		}
		if (tmp > 0){
			ans ++;
		}
	}

	cout << ans << endl;
	

	return 0;
}

Measured memory_bytes: 256
n = int(input())
A = []
bool = [True] * n
for i in range(n):
    a = int(input())
    a -= 1
    A.append(a)
j = A[0]
cnt = 1
for i in range(n):
    if j == 1:
        print(cnt)
        exit()
    if bool[A[j]] == True:
        bool[A[j]] = False        
        j = A[j]
        cnt += 1
    else :
        print(-1)
        exit()




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

using namespace std;

typedef pair<int, int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(), a.end()
#define SET(a, b) memset(a, b, sizeof(a))
#define si(n) scanf("%d", &n)
#define dout(n) printf("%d\n", n)
#define sll(n) scanf("%lld", &n)
#define lldout(n) printf("%lld\n", n)

#define TRACE

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

#define fast_io                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)

#define endl '\n'

constexpr int N = 11;
int mask[N], p[N];

int main() {
  fast_io;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      a -= 1;
      mask[i] |= 1 << a;
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  int ans = 0;
  for (int i = 0; i < (1 << n); ++i) {
    int cnt = 0;
    for (int j = 0; j < m; j++) {
      int msk = (mask[j] & i);
      int n_on = __builtin_popcount(msk);
      if ((n_on & 1) == p[j])
        cnt++;
    }
    if (cnt == m) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
    long long N, A, B;
    std::cin >> N >> A >> B;

    long long a, b;

    a = N / (A + B);
    b = N % (A + B);

    //std::cout << a << ", " << b << std::endl;

    long long num1, num2;
    
    num1 = a * A;
    if (b <= A)
        num2 = b;
    else
        num2 = A;

    long long ans = num1 + num2;
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
"use strict";

function main(input) {
  input = input.trim().split("\n");
  let ans = 0;
  const line1_arr = input[0].split("");
  const line2_arr = input[1].split("");

  for (let i = 0; i + line2_arr.length <= line1_arr.length; i++) {
    let tmp = 0;
    for (let j = 0; j < line2_arr.length; j++) {
      // console.log(line1_arr[j + i], line2_arr[j], i);
      if (line1_arr[j + i] == line2_arr[j]) {
        tmp++;
      }
    }
    // console.log(tmp);
    if (ans < tmp) {
      ans = tmp;
    }
  }
  console.log(line2_arr.length - ans);
}

function numberSort(array) {
  array.sort(f);
  return array;
}

var f = function (a, b) {
  return a - b;
};

main(require("fs").readFileSync("/dev/stdin", "utf-8"));


Measured memory_bytes: 32240
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

const int N = 100005;

int main()
{
	ios_base::sync_with_stdio(false);

	long long n, a, b;
	cin >> n >> a >> b;

	if ((b - a) % 2) {

		long long ans = min(n - a, b - 1);
		ans = min(ans, min(a - 1, n - b) + 1 + (b - a - 1) / 2);
		cout << ans << endl;
	}
	else
		cout << (b - a) / 2 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
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; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b;
	cin >> a >> b;
	ll tmpa = a, tmpb = b;
	rep(i, tmpa-1) {
		b += tmpb*pow(10, i+1);
	}
	rep(i, tmpb-1) {
		a += tmpa * pow(10, i+1);
	} 
	string s1 = to_string(a);
	string s2 = to_string(b);
	cout << min(s1,s2) << endl;
}


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

vector<vector<pair<int, int> > > e(1000);
vector<int> w(1000);

int f(int n, int cost){
	int ret = 0;
	if(e[n].size() == 0 && w[n] == 0) return 0;
	if(e[n].size() == 0) return cost;
	if(w[n] != 0) return cost;
	for(int i=0; i< e[n].size(); i++){
		ret += f(e[n][i].first, e[n][i].second);
	}
	return min(cost, ret);
}

int main(){
	int n;
	cin >> n;
	for(int i=0; i< n-1; i++) cin >> w[i+1];
	for(int i=0; i< n-1; i++){
		int a, b, c;
		cin >> a >> b >> c;
		e[a].push_back(make_pair(b, c));
	}
	cout << f(0, 10e8) << endl;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pi 3.14159265358979323846264
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vl vector <long long>
#define vpii vector <pair <int, int> >
#define ll long long
#define fi first
#define se second
int n, x, y;
string s, t;
int main() {
    cin >> n >> s;
    t = s;
    for (int i=0;i<n;i++) {
        if (s[i]=='(') x++;
        else {
            y++;
            if (y>x) t.insert(t.begin(), '('), x++;
        }
    }
    x = 0, y = 0;
    for (int i=n-1;i>=0;i--) {
        if (s[i]==')') y++;
        else {
            x++;
            if (x>y) t.insert(t.end(), ')'), y++; 
        }
    }
    cout << t << endl;
    return 0;
}

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

unsigned long min_cost(vector<int> cost)
{
  int n = cost.size();
  int i;
  //cout << n << endl;
  
  if(n <= 1)
    return 0;
  
  vector<unsigned long> min_cost_table(n);
  min_cost_table[0] = 0;
  min_cost_table[1] = abs(cost[1] - cost[0]);
  
  int cost_1, cost_2;
  
  for(i=2; i<n; i++)
  {
    cost_1 = min_cost_table[i-1] + abs( cost[i] - cost[i-1] );
    cost_2 = min_cost_table[i-2] + abs( cost[i] - cost[i-2] );
    
    min_cost_table[i] = min( cost_1, cost_2);
    
    //cout << i << " " << min_cost_table[i] << endl;
  }
  
  return min_cost_table[n-1];
}

int main()
{
  int i,n;
  cin >> n;
  
  vector<int> cost(n);
  for(i=0; i<n; i++)
  	cin  >> cost[i];
  
  cout << min_cost(cost) << endl; 
  
  return 0;
}

Measured memory_bytes: 1792
use whiteread::parse_line;

fn main() {
    let (n, m): (usize, usize) = parse_line().unwrap();
    let mut ab: Vec<(i64, i64)> = Vec::new();
    let mut cd: Vec<(i64, i64)> = Vec::new();

    for _ in 0..n {
        ab.push(parse_line().unwrap());
    }
    for _ in 0..m {
        cd.push(parse_line().unwrap());
    }

    for &(a, b) in &ab {
        let mut min = std::i64::MAX;
        let mut ans = 0;
        for (i, (c, d)) in cd.iter().enumerate() {
            let dist = (c - a).abs() + (d - b).abs();
            if dist < min {
                min = dist;
                ans = i + 1;
            }
        }
        println!("{}", ans);
    }
}


Measured memory_bytes: 2160
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

ans=0
bef=-10
for i in range(n):
    ans+=b[a[i]-1]
    if a[i]-1 == bef:
        ans+=c[a[i]-2]
    bef=a[i]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int gcd(int a, int b) {
    return b ? gcd(b, a%b) : a;
}

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

    const int MAXV = 1000000;
    const int SQMAXV = 1000;

    vector <int> A;
    vector <int> primes;
    vector <int> sqprimes;
    vector <bool> notPrime(MAXV+10);
    int g = -1;

    for (int v = 2; v <= MAXV; ++v) {
        if (!notPrime[v]) {
            primes.push_back(v);
            if (v <= SQMAXV) {
                sqprimes.push_back(v);
            }
        }

        for (int nv = v*2; nv <= MAXV; nv += v) {
            notPrime[nv] = true;
        }
    }

    for (int i = 0; i < N; ++i) {
        int val;
        cin >> val;

        if (g == -1) {
            g = val;
        } else {
            g = gcd(g, val);
        }

        if (val != 1) {
            A.push_back(val);
        }
    }

    if (g != 1) {
        cout << "not coprime" << endl;
    } else {
        // set or pairwise
        if (A.size() > primes.size()) {
            cout << "setwise coprime" << endl;
        } else {
            unordered_map <int, int> counter;

            for (int i = 0; i < A.size(); ++i) {
                int val = A[i];

                for (int j = 0; j < sqprimes.size() && sqprimes[j] <= val; ++j) {
                    int div = sqprimes[j];
                    if (val % div == 0) {
                        ++counter[div];
                        while (val % div == 0) {
                            val /= div;
                        }
                    }
                }

                if (val != 1) {
                    ++counter[val];
                }
            }

            bool failed = false;
            auto iter = counter.begin();

            while (iter != counter.end()) {
                if (iter->second >= 2) {
                    failed = true;
                    break;
                }
                ++iter;
            }

            if (failed) {
                cout << "setwise coprime" << endl;
            } else {
                cout << "pairwise coprime" << endl;
            }
        }
    }


    return 0;
}

Measured memory_bytes: 7788
#include<bits/stdc++.h>
#define ll long long int
#define mi map<int,int>
#define mcr map<char,int>
using namespace std;

int main()
{
    int k;
    string s;
    cin >> k;
    cin >> s;
    if(s.size() <= k){
        cout << s <<endl;
    }else{
        cout << s.substr(0, k) + "..." << endl;
    }

    return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N, K; cin >> N >> K;
    vector<char> d(K);
    for(int i=0; i<K; i++) cin >> d[i];

    for(int i=N; i<10*N; i++){
        bool flg = true;
        string s = to_string(i);
        for(int j=0; j<s.size(); j++){
            for(int k=0; k<K; k++) if(s[j] == d[k]) flg = false;
        }

        if(flg){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


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

    cout << fixed << setprecision(12) << (0.0+(N + 1)/2)/N << endl;

    return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl

typedef long long LL;

const int N = 200009;
int n, k, a[N], b[N];

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> k;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    LL tot = 0, mx = (LL)n*n;
    for(int i = 0; i < n; ++i) {
        b[i] = a[i];
        tot += b[i];
    }

    for(int i = 0; i < k && tot < mx; ++i) {
        vector<int> rg(n+1, 0);
        for(int j = 0; j < n; ++j) {
            int l = max(0, j-b[j]), r = min(n, j+b[j]+1);
            rg[l]++;
            rg[r]--;
        }

        int cur = 0;
        tot = 0LL;
        for(int j = 0; j < n; ++j) {
            cur += rg[j];
            b[j] = cur;
            tot += b[j];
        }
    }

    for(int i = 0; i < n; ++i) {
        cout << b[i] << ' ';
    }
    cout << '\n';
    
    return 0;
}


Measured memory_bytes: 5888
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}

int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	printf("%d\n",max(0,max(c-b-a,b-c-a)));
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n;
  std::cin >> n;
  vt<std::string> w(n);

  rep(i,n) {
    std::cin >> w[i];
    if(i > 0 && w[i-1][w[i-1].size()-1] != w[i][0]) {
      std::cout << "No" << '\n';
      return 0;
    }
    rep(j,w.size()) {
      if(i != j && w[i] == w[j]) {
        std::cout << "No" << '\n';
        return 0;
      }
    }
  }

  std::cout << "Yes" << '\n';
  return 0;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
minus = 0
plus = 0
zero = 0
ans_A = []
for a in A:
    if a < 0:
        minus += 1
    elif a > 0:
        plus += 1
    else:
        zero += 1
    ans_A.append(abs(a))

ans_A.sort()

if zero > 0:
    print(sum(ans_A))
    exit()
if minus % 2 == 0:
    print(sum(ans_A))
else:
    print(sum(ans_A[1:])-ans_A[0])




Measured memory_bytes: 21772
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>
#include <cctype>
#include <cmath>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int MAX = 100;
const int mod = 1000000007;
const double pi = 3.141592653589;

const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

/* global variables */
vector< vector<int> > Adj(MAX, vector<int>(MAX, INF));
vector<int> color(MAX, WHITE);
vector<int> d(MAX, INF);
vector<int> p(MAX, -1);
int n;
int total_cost = 0;

/* function */
void prim();

/* main */
int main() {
    
    cin >> n;
    for (int i = 0; i < n; i++) {
        int u, k; cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v, c;
            cin >> v >> c;
            Adj[u][v] = c;
        }
    }

    prim();

    for (int i = 0; i < n; i++ ) {
        cout << i << ' ' << d[i] << '\n';
    }
   

}

void prim() {

    int u;
    int min_cost = INF;
    d[0] = 0;
    p[0] = -1;

    while (1) {

        u = -1;
        min_cost = INF;
        for (int i = 0; i < n; i++) {
            if (color[i] != BLACK && d[i] < min_cost) {
                u = i;
                min_cost = d[i];
            }
        }
        if (min_cost == INF) {
            break;
        }

        color[u] = BLACK;

        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && Adj[u][v] != INF) {
                if (d[u] + Adj[u][v] < d[v]) {
                    p[v] = u;
                    d[v] = d[u] + Adj[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }

}



Measured memory_bytes: 3204
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <deque>

using namespace std;

int main() {
    long long h, w;
    cin >> h >> w;
    if (h == 1 || w == 1)
        cout << 1 << endl;
    else
        cout << (h * w + 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
# Author: cr4zjh0bp
# Created: Sun Mar 22 17:06:57 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

a, b, x = na()

print(b // x - (a - 1) // x)

Measured memory_bytes: 3064
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<iomanip>
#include<unordered_map>
#define deg(x) cerr<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;typedef long long LL;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=998244353;
const ll inf=1e9+7;
const double eps=1e-8;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return (r+m)%m;}
//const double pi=acos(-1);
 
ll jie[2030400];

int main()
{
    TB
	int n;
	cin>>n;
	ll a1,b1,a2,b2;
	a1=b1=inf,a2=b2=-inf;
	fd(n){
		ll x,y;
		cin>>x>>y;
		a1=min(a1,x+y),a2=max(a2,x+y);
        b1=min(b1,x-y),b2=max(b2,x-y);
	}
	ll ans=max(a2-a1,b2-b1);
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
const in mdl=1000000007;
VVI egs;
in n;
VVI wy;
in wys(in u, in pr, in dnlim, in rad){
  in& tp=wy[u][dnlim];
  if(tp!=-1)
    return tp;
  tp=1;
  in tw;
  forv(i,egs[u]){
    if(egs[u][i]==pr)
      continue;
    tw=0;
    if(dnlim)
      tw+=wys(egs[u][i],u,dnlim-1,rad-1);
    if(dnlim!=rad)
      tw+=wys(egs[u][i],u,dnlim,rad-1);
    tp=tp*tw%mdl;
  }
  return tp;
}
VI dglft;
VI act;
VI trn;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin>>n;
  egs.resize(n);
  dglft.resize(n);
  act.resize(n,1);
  trn.resize(n);
  in ta,tb;
  forn(z,n-1){
    cin>>ta>>tb;
    --ta;
    --tb;
    egs[ta].PB(tb);
    egs[tb].PB(ta);
    ++dglft[ta];
    ++dglft[tb];
  }
  VI trm;
  in ct=0;
  forn(i,n){
    if(dglft[i]==1){
      trn[i]=ct;
      trm.PB(i);
      act[i]=0;
    }
  }
  wy.resize(n,VI(n+2,-1));
  in cd;
  while(1){
    ++ct;
    VI ttrm;
    forv(i,trm){
      forv(j,egs[trm[i]]){
	cd=egs[trm[i]][j];
	if(act[cd]){
	  --dglft[cd];
	  if(dglft[cd]<=1){
	    act[cd]=0;
	    trn[cd]=ct;
	    ttrm.PB(cd);
	  }
	}
      }
    }
    trm=ttrm;
    if(trm.empty())
      break;
  }
  in mxd=-1;
  VI cent;
  forn(i,n){
    if(trn[i]>mxd){
      mxd=trn[i];
      cent.clear();
    }
    if(trn[i]==mxd)
      cent.PB(i);
  }
  in rad=mxd;
  bool centeg=(sz(cent)==2);
  assert(sz(cent)==1 || sz(cent)==2);
  in sm=0;
  if(centeg){
    forn(xx,2){
      forn(zz,2){
	forn(dnlim,rad+1){
	  in ls=wys(cent[0],cent[1],dnlim,rad);
	  in rs=wys(cent[1],cent[0],dnlim+zz,rad+1);
	  sm+=ls*rs;
	  sm%=mdl;
	}
      }
      forn(i,n){
	forv(j,wy[i])
	  wy[i][j]=-1;
      }
      swap(cent[0],cent[1]);
    }
    forn(xx,2){
      forn(dnlim,rad+1){
	for(in z=0;z<2 && dnlim+z<=rad;++z){
	  in ls=wys(cent[0],cent[1],dnlim,rad);
	  in rs=wys(cent[1],cent[0],dnlim+z,rad);
	  sm-=ls*rs;
	  sm%=mdl;
	}
      }
      forn(i,n){
	forv(j,wy[i])
	  wy[i][j]=-1;
      }
      swap(cent[0],cent[1]);
    }
    sm%=mdl;
    sm+=mdl;
    sm%=mdl;
  }
  else{
    forn(dnlim,rad+1){
      sm+=wys(cent[0],cent[0],dnlim,rad);
      sm%=mdl;
    }
  }
  cout<<sm<<endl;
  return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

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

  if(s=="RRR") cout << 3 << endl;
  else if(s=="RRS") cout << 2 << endl;
  else if(s=="RSR") cout << 1 << endl;
  else if(s=="RSS") cout << 1 << endl;
  else if(s=="SRR") cout << 2 << endl;
  else if(s=="SRS") cout << 1 << endl;
  else if(s=="SSR") cout << 1 << endl;
  else if(s=="SSS") cout << 0 << endl;



  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  vector<int> x(5);
 rep(i,5){
  cin >> x.at(i);
 }
rep(i,5){
if(x.at(i) == 0){
  cout << i+1 << endl;
return 0;
}
}

    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;

string s, t;

signed main() {
	cin >> s >> t;
	
	for (int i = 0; i < s.length(); i++) {
		int j;
		for (j = 0; j < s.length(); j++) {
			if (s[(i + j) % s.length()] != t[j]) break;
		}
		if (j == s.length()) { cout << "Yes" << endl; return 0; }
	}
	cout << "No" << endl;
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it = (c).begin(); it != (c).end(); it++)
#define X first
#define Y second

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int N = 1001;

int dp[N];
int cnt;

int main(void){
    for(int ww; cin >> ww, ww;){
        int n; cin >> n;
        rep(i, N) dp[i] = -1;
        dp[0] = 0;
        while(n--){
            int p, w;
            char c; cin >> p >> c >> w;

            COUNT(i, N){
                int cur = N - i;
                if(~dp[cur] && cur + w <= ww) dp[cur + w] = max(dp[cur + w], dp[cur] + p);
            }
        }
        int ind = max_element(dp, dp + N) - dp;
        cout << "Case " << ++cnt << ":" << endl << dp[ind] << endl << ind << endl;
    }

    return 0;
}

Measured memory_bytes: 1168
def main():
    A, B, C, D = map(int, input().split())
    n1 = (C + B - 1) // B
    n2 = (A + D - 1) // D
    if n1 <= n2:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9108
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	int *input = new int;
	float sum;

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> input[i];

	sort(input, input + n);

	for (int i = 0; i < n; i++)
	{
		if (i == 0)
			sum = input[i];
		else
			sum = (sum + input[i]) / 2;
	}

	cout << sum;

	return 0;
}


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

int main(){
	int a,b,c,x,y;
	cin >> a >> b >> c >> x >> y;
	c *= 2;
	ll sum = 0;
	int z = min(x,y);
	if(a+b > c){
		if(x > y){
			int cost1 = c*x;
			int cost2 = (x-y)*a + y*c;
			sum = min(cost1,cost2);
		}
		else{
			int cost1 = c*y;
			int cost2 = (y-x)*b + x*c;
			sum = min(cost1,cost2);
		}
	}
	else{
		sum = a*x + b*y;
	}
	cout << sum << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define MOD 998244353LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
string s;
ll cnt[3];
ll cnt2[3];

int main(void){
	scanf("%d",&n);
	cin >> s;
	int rest=0;
	ll ans=1;
	for(int i=1;i<=n;i++){
		ans=(ll)ans*i%MOD;
	}
	for(int i=0;i<n*3;i++){
		if(s[i]=='R'){
			if(cnt2[0]>0){
				ans=ans*cnt2[0]%MOD;
				cnt2[0]--;
			}else if(cnt[1]>0){
				ans=ans*cnt[1]%MOD;
				cnt2[2]++;
				cnt2[2]%=MOD;
				cnt[1]--;
			}else if(cnt[2]>0){
				ans=ans*cnt[2]%MOD;
				cnt2[1]++;
				cnt2[1]%=MOD;
				cnt[2]--;
			}else{
				cnt[0]++;
			}
		}
		if(s[i]=='G'){
			if(cnt2[1]>0){
				ans=ans*cnt2[1]%MOD;
				cnt2[1]--;
			}else if(cnt[0]>0){
				ans=ans*cnt[0]%MOD;
				cnt2[2]++;
				cnt2[2]%=MOD;
				cnt[0]--;
			}else if(cnt[2]>0){
				ans=ans*cnt[2]%MOD;
				cnt2[0]++;
				cnt2[0]%=MOD;
				cnt[2]--;
			}else{
				cnt[1]++;
			}
		}
		if(s[i]=='B'){
			if(cnt2[2]>0){
				ans=ans*cnt2[2]%MOD;
				cnt2[2]--;
			}else if(cnt[0]>0){
				ans=ans*cnt[0]%MOD;
				cnt2[1]++;
				cnt2[1]%=MOD;
				cnt[0]--;
			}else if(cnt[1]>0){
				ans=ans*cnt[1]%MOD;
				cnt2[0]++;
				cnt2[0]%=MOD;
				cnt[1]--;
			}else{
				cnt[2]++;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 900
#include<cstdio>
#include<iostream>
#include<cstring>
#include<map>
#define RG register
#define LL long long
using namespace std;
const int N=405; 
int n,c[4][N];
LL ans,id[N],re[4];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
map<LL,int> num;
inline LL getid(LL aa,LL bb,LL cc,LL dd){
	return aa<<30|bb<<20|cc<<10|dd;
}
inline void rot(LL st,int kk) {
	for(RG int i=0;i<4;i++) {
		st=((st>>10)|(st&1023)<<30);
		num[st]+=kk;
	}
}
int main()
{
//	freopen("Building Cubes with AtCoDeer.in","r",stdin);
	//freopen(".out","w",stdout);
	read(n);
	for(RG int i=1;i<=n;i++)
	{
		read(c[0][i],c[1][i],c[2][i],c[3][i]);
		id[i]=getid(c[0][i],c[1][i],c[2][i],c[3][i]);
		rot(id[i],1);
	}
	for(RG int i=1;i<n-4;i++)
	{
		rot(id[i],-1);
		for(RG int j=i+1;j<=n;j++)
		{
			rot(id[j],-1);
			for(RG int l=0;l<4;l++)
			{
				LL tt=1;
				re[0]=getid(c[1][i],c[0][i],c[(l+1)%4][j],c[(l)%4][j]); if(!num[re[0]]) continue;
				re[1]=getid(c[2][i],c[1][i],c[(l)%4][j],c[(l+3)%4][j]); if(!num[re[1]]) continue;
				re[2]=getid(c[3][i],c[2][i],c[(l+3)%4][j],c[(l+2)%4][j]); if(!num[re[2]]) continue;
				re[3]=getid(c[0][i],c[3][i],c[(l+2)%4][j],c[(l+1)%4][j]); if(!num[re[3]]) continue;
				for(RG int k=0;k<4;k++)
				{
					tt*=num[re[k]];
					rot(re[k],-1);
				}
				for(RG int k=0;k<4;k++) rot(re[k],1);
				ans+=tt;
			}
			rot(id[j],1);
		}
	}
	printf("%lld\n",ans);
	//fclose(stdin); fclose(stdout);
	return 0;
}

Measured memory_bytes: 20352
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int n,a[SZ];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=3*n;i++)
		scanf("%d",a+i);
	sort(a+1,a+1+3*n,greater<int>());
	ll ans=0;
	for(int i=2;i<=2*n;i+=2)
		ans+=a[i];
	cout<<ans<<"\n";
}


Measured memory_bytes: 1408
import java.util.Scanner;
 
public class Main{
    public static void main(String[] ss){
        int h,w,i,j;
        Scanner s = new Scanner(System.in);
        while(true){
        h = s.nextInt();
        w = s.nextInt();
        if(h*w==0)break;
        for(i=1;i<=h;i++){
            for(j=1;j<=w;j++){
                if((i+j)%2==0)System.out.print("#");
                else System.out.print(".");
            }
                System.out.println();
            }
            System.out.println();
        }
    }
}


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


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,a;
    cin>>h>>a;
    int ans;
    if(h%a==0)
    {
        ans=h/a;

    }
    else
    {

      ans=h/a+1;
    }
    cout<<ans<<'\n';


}



















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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
//#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)
#define SUM(v) accumulate((v).begin(),(v).end(),0ll)
#define range(i,left,right) (left<=i && i<right)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

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;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int iscount(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    int k;
    string s;
    cin>>k>>s;
    if(s.size()<=k) cout<<s<<endl;
    else{
        REP(i,0,k) cout<<s[i];
        cout<<"..."<<endl;
    }
    return 0;
}

Measured memory_bytes: 3564